dsh-paper-workbench 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +65 -449
- package/assets/app/app.js +311 -147
- package/assets/app/style.css +21 -10
- package/assets/pdf_tool.py +37 -8
- package/docs/guide.md +43 -0
- package/docs/v4-layout.md +9 -0
- package/docs/v6-zhpdf.md +13 -12
- package/docs/v7-quality.md +3 -1
- package/lib/arxiv.js +398 -34
- package/lib/doc.js +145 -48
- package/lib/history.js +76 -0
- package/lib/index.js +93 -72
- package/lib/layout-ir.js +96 -1
- package/lib/layout.js +1 -1
- package/lib/paper-context.js +3 -0
- package/lib/pdf.js +12 -1
- package/lib/server.js +17 -2
- package/lib/translate-jobs.js +3 -0
- package/lib/zhpdf-jobs.js +198 -0
- package/lib/zhpdf.js +248 -63
- package/package.json +7 -2
- package/scripts/audit-library.mjs +348 -0
- package/scripts/batch-layout.mjs +201 -0
- package/scripts/quality/rebuild-layout.mjs +7 -2
package/assets/app/app.js
CHANGED
|
@@ -39,6 +39,7 @@ const state = {
|
|
|
39
39
|
topics: [],
|
|
40
40
|
filter: '',
|
|
41
41
|
picked: new Set(),
|
|
42
|
+
categoryEditor: null,
|
|
42
43
|
expanded: loadTree(), // 已展开的专题(默认空 = 全部收起)
|
|
43
44
|
tempCollapsed: new Set(), // 搜索期间的临时收起,不写 localStorage
|
|
44
45
|
current: null, // library.get: { meta, outline, notes, zhChars, ocr }
|
|
@@ -85,8 +86,10 @@ const state = {
|
|
|
85
86
|
// 环境自检(设置页):旧宿主没有 doctor.run,静默降级成一行提示
|
|
86
87
|
doctor: { loading: false, report: null, error: '', unsupported: false },
|
|
87
88
|
busy: '',
|
|
88
|
-
online: { q: '', source: 'both', items: [], warnings: [], loading: false, error: '' },
|
|
89
|
-
latestFeed: { loading: false, loaded: false, mode: 'subs', topicFilter: 'all', domainId: '', category: '', items: [], topics: [], domains: [], error: '', partialErrors: [] },
|
|
89
|
+
online: { q: '', source: 'both', items: [], warnings: [], loading: false, error: '', page: 0, nextCursor: null, hasMore: false, seq: 0, queried: false, abort: null },
|
|
90
|
+
latestFeed: { loading: false, loaded: false, mode: 'subs', topicFilter: 'all', domainId: '', category: '', items: [], topics: [], domains: [], error: '', partialErrors: [], warnings: [], page: 0, nextCursor: null, hasMore: false, seq: 0, abort: null },
|
|
91
|
+
onlineNavCollapsed: false,
|
|
92
|
+
browseHistory: { open: false, items: [], q: '', loading: false, error: '' },
|
|
90
93
|
dbTestResult: null,
|
|
91
94
|
dbBusy: '',
|
|
92
95
|
netTestResult: null,
|
|
@@ -316,11 +319,12 @@ function h(tag, props, ...children) {
|
|
|
316
319
|
return node
|
|
317
320
|
}
|
|
318
321
|
|
|
319
|
-
async function rpc(method, args = {}) {
|
|
322
|
+
async function rpc(method, args = {}, options = {}) {
|
|
320
323
|
const response = await fetch(API + method, {
|
|
321
324
|
method: 'POST',
|
|
322
325
|
headers: { 'Content-Type': 'application/json' },
|
|
323
326
|
body: JSON.stringify(args),
|
|
327
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
324
328
|
})
|
|
325
329
|
const data = await response.json().catch(() => ({ ok: false, error: 'HTTP ' + response.status }))
|
|
326
330
|
if (!data.ok) throw new Error(data.error || '请求失败(HTTP ' + response.status + ')')
|
|
@@ -671,6 +675,7 @@ function saveSession(patch = {}, opts = {}) {
|
|
|
671
675
|
expanded: [...state.expanded],
|
|
672
676
|
readerAi: { ...state.ai },
|
|
673
677
|
dark: state.dark,
|
|
678
|
+
onlineNavCollapsed: state.onlineNavCollapsed,
|
|
674
679
|
...patch,
|
|
675
680
|
}
|
|
676
681
|
try {
|
|
@@ -680,7 +685,7 @@ function saveSession(patch = {}, opts = {}) {
|
|
|
680
685
|
}
|
|
681
686
|
// 同时写一份到插件自己的数据目录:桌面端重启后端口会变,localStorage 按站点隔离会丢,
|
|
682
687
|
// 服务端这份能让「退出再进」跨重启也回到原处。
|
|
683
|
-
const hasPrefPatch = ['paperId', 'layout', 'expanded', 'readerAi', 'dark'].some((k) => Object.hasOwn(patch, k))
|
|
688
|
+
const hasPrefPatch = ['paperId', 'layout', 'expanded', 'readerAi', 'dark', 'onlineNavCollapsed'].some((k) => Object.hasOwn(patch, k))
|
|
684
689
|
if (state.current || hasPrefPatch) {
|
|
685
690
|
const remoteState = {
|
|
686
691
|
paperId: next.paperId,
|
|
@@ -692,6 +697,7 @@ function saveSession(patch = {}, opts = {}) {
|
|
|
692
697
|
expanded: next.expanded,
|
|
693
698
|
readerAi: next.readerAi,
|
|
694
699
|
dark: next.dark,
|
|
700
|
+
onlineNavCollapsed: next.onlineNavCollapsed,
|
|
695
701
|
}
|
|
696
702
|
if (opts && opts.keepalive && typeof fetch === 'function') {
|
|
697
703
|
fetch(API + 'ui.set', {
|
|
@@ -1268,6 +1274,7 @@ async function runTranslate(body, job) {
|
|
|
1268
1274
|
state.translateJob = {
|
|
1269
1275
|
paperId: pid,
|
|
1270
1276
|
status: 'running',
|
|
1277
|
+
...(body.purpose ? { purpose: body.purpose } : {}),
|
|
1271
1278
|
concurrency,
|
|
1272
1279
|
completed: Math.max(prevDone, job.done ? job.done.size : 0),
|
|
1273
1280
|
total: job.totalParagraphs || 0,
|
|
@@ -1455,7 +1462,7 @@ function confirmTranslateAll() {
|
|
|
1455
1462
|
}
|
|
1456
1463
|
|
|
1457
1464
|
function translateTitles() {
|
|
1458
|
-
const sections = sectionsOf().filter((section) => section.hash)
|
|
1465
|
+
const sections = sectionsOf().filter((section) => section.hash && !section.synthetic)
|
|
1459
1466
|
if (!state.doc || sections.length === 0) {
|
|
1460
1467
|
toast('没有可翻译的目录标题(需要文档模型)')
|
|
1461
1468
|
return
|
|
@@ -1969,6 +1976,8 @@ async function openPaper(id, options = {}) {
|
|
|
1969
1976
|
state.layoutBusy = false
|
|
1970
1977
|
state.zhMode = false
|
|
1971
1978
|
state.zhStatus = null
|
|
1979
|
+
state.zhBusy = false
|
|
1980
|
+
if (hostReady()) void followZhPdf(id, seq, false)
|
|
1972
1981
|
await Promise.all([loadPage(state.page, seq), loadDoc(id, seq), loadChat(id, seq), loadAi(), loadFigures(seq)])
|
|
1973
1982
|
if (seq !== state.openSeq) return
|
|
1974
1983
|
buildFiguresByKey()
|
|
@@ -2007,6 +2016,7 @@ async function openPaper(id, options = {}) {
|
|
|
2007
2016
|
if (scroller) scroller.scrollTop = Number(restore.scrollTop)
|
|
2008
2017
|
}
|
|
2009
2018
|
saveSession({ paperId: id, tab: state.tab, page: state.page, sectionId: state.sectionId })
|
|
2019
|
+
if (!restore) void rememberPaper({ ...state.current.meta, paperId: id })
|
|
2010
2020
|
if (state.session.available && state.layout.chatOpen) startSessionStream(true)
|
|
2011
2021
|
}
|
|
2012
2022
|
}
|
|
@@ -2374,6 +2384,10 @@ function renderSide() {
|
|
|
2374
2384
|
'div',
|
|
2375
2385
|
{ class: 'tree-toolbar' },
|
|
2376
2386
|
h('span', { class: 'hint' }, searching ? '搜索:命中分组临时展开' : '展开 ' + topicKeys.filter((topic) => state.expanded.has(topic)).length + ' / ' + topicKeys.length + ' 组'),
|
|
2387
|
+
h('span', { class: 'library-state-legend', 'aria-label': '阅读状态图例:灰色未读,橙黄色阅读中,绿色已读' },
|
|
2388
|
+
h('span', { class: 'legend-item' }, h('i', { class: 'dot unread', title: '未读' }), '未读'),
|
|
2389
|
+
h('span', { class: 'legend-item' }, h('i', { class: 'dot reading', title: '阅读中' }), '阅读中'),
|
|
2390
|
+
h('span', { class: 'legend-item' }, h('i', { class: 'dot read', title: '已读' }), '已读')),
|
|
2377
2391
|
h('span', { class: 'spacer' }),
|
|
2378
2392
|
h('button', { class: 'ghost', title: '展开所有分组', onclick: () => expandAllGroups(topicKeys, searching) }, '全部展开'),
|
|
2379
2393
|
h('button', { class: 'ghost', title: '收起所有分组', onclick: () => collapseAllGroups(topicKeys, searching) }, '全部收起'),
|
|
@@ -2441,13 +2455,14 @@ function renderSide() {
|
|
|
2441
2455
|
},
|
|
2442
2456
|
}),
|
|
2443
2457
|
),
|
|
2444
|
-
h('span', { class: ['dot', paper.status || '', paper.notesCount ? 'note' : ''].filter(Boolean).join(' ') }),
|
|
2458
|
+
h('span', { class: ['dot', paper.status || '', paper.notesCount ? 'note' : ''].filter(Boolean).join(' '), role: 'img', title: ({ unread: '未读', reading: '阅读中', read: '已读' }[paper.status] || '未读') + (paper.notesCount ? ' · 有笔记' : ''), 'aria-label': ({ unread: '未读', reading: '阅读中', read: '已读' }[paper.status] || '未读') }),
|
|
2445
2459
|
h(
|
|
2446
2460
|
'span',
|
|
2447
2461
|
{},
|
|
2448
2462
|
h('div', { class: 'paper-title' }, paper.title),
|
|
2449
2463
|
h('div', { class: 'paper-meta' }, [paper.year, fmtAuthors(paper.authors), paper.pageCount ? paper.pageCount + ' 页' : ''].filter(Boolean).join(' · ')),
|
|
2450
2464
|
),
|
|
2465
|
+
h('button', { class: 'ghost paper-category', 'data-classify-paper': paper.id, title: '移入已有或新建分类', onclick: event => { event.stopPropagation(); state.categoryEditor = { id: paper.id, value: paper.topics?.[0] || '', error: '', busy: false }; render() } }, '分类'),
|
|
2451
2466
|
(() => {
|
|
2452
2467
|
const liveJob =
|
|
2453
2468
|
state.current && state.current.meta.id === paper.id && state.translateJob
|
|
@@ -2490,6 +2505,37 @@ function renderSide() {
|
|
|
2490
2505
|
)
|
|
2491
2506
|
}
|
|
2492
2507
|
|
|
2508
|
+
function renderCategoryEditor() {
|
|
2509
|
+
const editor = state.categoryEditor
|
|
2510
|
+
const names = [...new Set(state.papers.flatMap(paper => paper.topics || []))].sort()
|
|
2511
|
+
const close = () => { if (!editor.busy) { state.categoryEditor = null; render() } }
|
|
2512
|
+
const save = async value => {
|
|
2513
|
+
const category = String(value || '').trim()
|
|
2514
|
+
if (category.length > 100) { editor.error = '分类名称最多 100 个字符'; render(); return }
|
|
2515
|
+
editor.busy = true
|
|
2516
|
+
editor.error = ''
|
|
2517
|
+
render()
|
|
2518
|
+
try {
|
|
2519
|
+
await rpc('library.update', { id: editor.id, patch: { topics: category ? [category] : [] } })
|
|
2520
|
+
if (category) state.expanded.add(category)
|
|
2521
|
+
else state.expanded.add('未分类')
|
|
2522
|
+
saveTree()
|
|
2523
|
+
await loadLibrary()
|
|
2524
|
+
if (state.categoryEditor === editor) state.categoryEditor = null
|
|
2525
|
+
} catch (error) { editor.error = error.message }
|
|
2526
|
+
finally { editor.busy = false; render() }
|
|
2527
|
+
}
|
|
2528
|
+
return h('div', { class: 'overlay', onclick: event => { if (event.target === event.currentTarget) close() } },
|
|
2529
|
+
h('div', { class: 'modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': '论文分类' },
|
|
2530
|
+
h('div', { class: 'modal-head' }, h('strong', {}, '移动论文分类'), h('span', { class: 'spacer' }), h('button', { onclick: close, disabled: editor.busy }, '关闭')),
|
|
2531
|
+
h('div', { class: 'field' }, h('label', { for: 'paper-category-input' }, '选择已有分类或输入新分类;留空为未分类'),
|
|
2532
|
+
h('input', { id: 'paper-category-input', list: 'paper-category-existing', value: editor.value, disabled: editor.busy, oninput: event => { editor.value = event.target.value } }),
|
|
2533
|
+
h('datalist', { id: 'paper-category-existing' }, names.map(name => h('option', { value: name }, name)))),
|
|
2534
|
+
editor.error ? h('div', { class: 'error', role: 'alert' }, editor.error) : null,
|
|
2535
|
+
h('div', { class: 'row' }, h('button', { id: 'paper-category-save', class: 'primary', disabled: editor.busy, onclick: () => save(editor.value) }, editor.busy ? '保存中…' : '保存分类'),
|
|
2536
|
+
h('button', { id: 'paper-category-clear', disabled: editor.busy, onclick: () => save('') }, '移至未分类'))))
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2493
2539
|
function toggleGroup(topic, searching) {
|
|
2494
2540
|
if (searching) {
|
|
2495
2541
|
if (state.tempCollapsed.has(topic)) state.tempCollapsed.delete(topic)
|
|
@@ -2534,6 +2580,7 @@ function renderMain() {
|
|
|
2534
2580
|
if (state.trash.open) overlays.push(renderTrashModal())
|
|
2535
2581
|
if (state.convPicker.open) overlays.push(renderConvPicker())
|
|
2536
2582
|
if (state.layoutReport) overlays.push(renderLayoutReport())
|
|
2583
|
+
if (state.categoryEditor) overlays.push(renderCategoryEditor())
|
|
2537
2584
|
if (state.showSettings) return h('section', { class: 'main' }, renderTopbar(), h('div', { class: 'content' }, renderSettings()), ...overlays)
|
|
2538
2585
|
const isOnline = state.tab === 'online' || (!state.current && state.online.items.length > 0)
|
|
2539
2586
|
const content = isOnline ? renderOnline() : !state.current ? renderEmpty() : renderReader()
|
|
@@ -2758,7 +2805,7 @@ function renderOutline(sections) {
|
|
|
2758
2805
|
h('div', { class: 'outline-title' }, section.title),
|
|
2759
2806
|
titleKey ? h('div', { class: 'outline-zh', 'data-zh': titleKey }) : null,
|
|
2760
2807
|
),
|
|
2761
|
-
h(
|
|
2808
|
+
section.synthetic ? null : h(
|
|
2762
2809
|
'div',
|
|
2763
2810
|
{ class: 'outline-actions' },
|
|
2764
2811
|
h('button', { class: 'link', title: '翻译本节', onclick: (event) => { event.stopPropagation(); translateSection(section.id) } }, '译'),
|
|
@@ -3853,8 +3900,9 @@ function renderParagraph(paragraph) {
|
|
|
3853
3900
|
const para = h(
|
|
3854
3901
|
'div',
|
|
3855
3902
|
{
|
|
3856
|
-
class: 'para kind-' + kind + (entry ? ' has-zh' : '') + (collapseClasses ? ' ' + collapseClasses : ''),
|
|
3903
|
+
class: 'para kind-' + kind + (paragraph.role === 'toc-entry' ? ' toc-entry' : '') + (entry ? ' has-zh' : '') + (collapseClasses ? ' ' + collapseClasses : ''),
|
|
3857
3904
|
id,
|
|
3905
|
+
'data-toc-level': paragraph.role === 'toc-entry' ? paragraph.tocLevel || 1 : null,
|
|
3858
3906
|
'data-key': key,
|
|
3859
3907
|
'data-section': paragraph.section || '',
|
|
3860
3908
|
'data-page': paragraph.page || 1,
|
|
@@ -3997,6 +4045,7 @@ function renderCompareToolbar() {
|
|
|
3997
4045
|
'div',
|
|
3998
4046
|
{ class: 'toolbar-group trans-group', role: 'group', 'aria-label': '全文与章节翻译' },
|
|
3999
4047
|
h('button', { id: 'translate-section', disabled: !docReady || running, title: '翻译当前阅读章节的全部未译段落(存入存储后端,不进对话历史)', onclick: () => translateSection(state.sectionId || (sectionsOf()[0] && sectionsOf()[0].id)) }, '译本节'),
|
|
4048
|
+
h('button', { id: 'translate-titles', class: 'primary-soft', disabled: !docReady || running, title: '一键翻译全部真实目录标题,结果保存后显示中英对照', onclick: translateTitles }, '翻译全部目录'),
|
|
4000
4049
|
h('button', { id: 'translate-all', class: 'primary-soft', disabled: !docReady || running, onclick: confirmTranslateAll }, '整篇翻译'),
|
|
4001
4050
|
h('button', { id: 'translate-stop', class: 'btn-pause-trans', hidden: !running, disabled: !running, title: '显式暂停当前后台翻译(切走界面不会中断翻译)', onclick: pauseTranslate }, '⏸ 暂停翻译' + countSuffix),
|
|
4002
4051
|
h('button', { id: 'translate-resume', class: 'btn-resume-trans', hidden: !paused, disabled: !docReady || running, title: '从上次暂停断点继续翻译剩余未译段落', onclick: resumeTranslate }, '▶ 继续翻译' + countSuffix),
|
|
@@ -4023,7 +4072,6 @@ function renderCompareToolbar() {
|
|
|
4023
4072
|
h(
|
|
4024
4073
|
'div',
|
|
4025
4074
|
{ class: 'more-tools-menu' },
|
|
4026
|
-
h('button', { id: 'translate-titles', disabled: !docReady || state.translateBusy, title: '批量翻译节标题,目录显示英文/中文两行', onclick: translateTitles }, '目录翻译'),
|
|
4027
4075
|
h('button', { id: 'review-run', disabled: !docReady || !hostReady() || state.reviewBusy, title: hostReady() ? '检查空译文、截断、残留英文、公式残留等可疑段落' : '重启桌面端后可用', onclick: () => runReview('static') }, state.reviewBusy ? '自检中…' : '译文自检'),
|
|
4028
4076
|
h('button', {
|
|
4029
4077
|
id: 'layout-run',
|
|
@@ -4072,53 +4120,84 @@ function pageRatio(page) {
|
|
|
4072
4120
|
return PAGE_DEFAULT_RATIO
|
|
4073
4121
|
}
|
|
4074
4122
|
|
|
4075
|
-
|
|
4123
|
+
let zhWatch = 0
|
|
4124
|
+
|
|
4125
|
+
async function followZhPdf(id, seq, requested) {
|
|
4126
|
+
const watch = ++zhWatch
|
|
4127
|
+
const current = () => watch === zhWatch && seq === state.openSeq && state.current?.meta?.id === id
|
|
4128
|
+
try {
|
|
4129
|
+
while (current()) {
|
|
4130
|
+
const status = await rpc('zhpdf.status', { id })
|
|
4131
|
+
if (!current()) return
|
|
4132
|
+
state.zhStatus = status
|
|
4133
|
+
const job = status.job
|
|
4134
|
+
if (job?.status !== 'running') {
|
|
4135
|
+
if (requested && state.tab === 'page' && status.exists && !status.stale && job?.status === 'done') {
|
|
4136
|
+
state.zhMode = true
|
|
4137
|
+
state.pendingPage = state.page
|
|
4138
|
+
toast('中文版已生成,写入 ' + status.blocks + ' 块')
|
|
4139
|
+
}
|
|
4140
|
+
if (requested && job?.status === 'error') toast(job.error, 6000)
|
|
4141
|
+
if (job) render()
|
|
4142
|
+
return
|
|
4143
|
+
}
|
|
4144
|
+
requested = true
|
|
4145
|
+
if (state.tab === 'page') render()
|
|
4146
|
+
await new Promise(resolve => setTimeout(resolve, 1500))
|
|
4147
|
+
}
|
|
4148
|
+
} catch (error) {
|
|
4149
|
+
if (requested && current()) toast(error.message, 6000)
|
|
4150
|
+
}
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4153
|
+
function zhProgress(job) {
|
|
4154
|
+
if (!job || job.status === 'done') return ''
|
|
4155
|
+
if (job.error) return job.error
|
|
4156
|
+
const phase = { checking: '检查覆盖', translating: '补译中', generating: '生成 PDF 中' }[job.phase] || ''
|
|
4157
|
+
return [phase, job.missingCount != null && '待补译 ' + job.missingCount, job.total > 0 && job.completed + '/' + job.total, job.model].filter(Boolean).join(' · ')
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4076
4160
|
async function toggleZhPdf() {
|
|
4077
|
-
const
|
|
4078
|
-
if (!
|
|
4079
|
-
if (state.zhBusy) return
|
|
4161
|
+
const id = state.current?.meta?.id
|
|
4162
|
+
if (!id || state.zhBusy || state.busy === 'open') return
|
|
4080
4163
|
if (state.zhMode) {
|
|
4081
4164
|
state.zhMode = false
|
|
4082
4165
|
render()
|
|
4083
4166
|
return
|
|
4084
4167
|
}
|
|
4085
|
-
if (!hostReady())
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
const id = meta.id
|
|
4090
|
-
const stillHere = () => Boolean(state.current && state.current.meta.id === id)
|
|
4168
|
+
if (!hostReady()) return needRestart()
|
|
4169
|
+
|
|
4170
|
+
const seq = state.openSeq
|
|
4171
|
+
const stillHere = () => seq === state.openSeq && state.current?.meta?.id === id && state.tab === 'page'
|
|
4091
4172
|
state.zhBusy = true
|
|
4173
|
+
render()
|
|
4092
4174
|
try {
|
|
4093
|
-
|
|
4094
|
-
if (!status) status = await rpc('zhpdf.status', { id })
|
|
4175
|
+
const status = await rpc('zhpdf.status', { id })
|
|
4095
4176
|
if (!stillHere()) return
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4177
|
+
state.zhStatus = status
|
|
4178
|
+
if (status.job?.status === 'running') {
|
|
4179
|
+
await rpc('zhpdf.pause', { id })
|
|
4180
|
+
} else if (status.job?.status === 'paused') {
|
|
4181
|
+
await rpc('zhpdf.resume', { id })
|
|
4182
|
+
} else if (status.exists && !status.stale) {
|
|
4183
|
+
state.zhMode = true
|
|
4184
|
+
state.pendingPage = state.page
|
|
4185
|
+
return
|
|
4186
|
+
} else {
|
|
4187
|
+
const check = await rpc('zhpdf.inspect', { id })
|
|
4103
4188
|
if (!stillHere()) return
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
const result = await rpc('zhpdf.build', { id })
|
|
4108
|
-
if (!stillHere()) return
|
|
4109
|
-
toast('中文版已更新:' + result.blocks + ' 段')
|
|
4110
|
-
status = await rpc('zhpdf.status', { id })
|
|
4111
|
-
if (!stillHere()) return
|
|
4112
|
-
}
|
|
4189
|
+
if (check.issues?.length) throw new Error(check.issues.slice(0, 5).map(issue => '第 ' + (issue.page || '?') + ' 页 ' + issue.reason).join(','))
|
|
4190
|
+
if (!window.confirm((check.missingKeys.length ? '将通过翻译模型补齐 ' + check.missingKeys.length + ' 项,可能产生模型费用。' : '译文已齐。') + '继续生成中文版 PDF?')) return
|
|
4191
|
+
await rpc('zhpdf.prepare', { id })
|
|
4113
4192
|
}
|
|
4114
|
-
|
|
4115
|
-
state.zhMode = true
|
|
4116
|
-
render()
|
|
4193
|
+
if (stillHere()) void followZhPdf(id, seq, true)
|
|
4117
4194
|
} catch (error) {
|
|
4118
|
-
toast(error.message)
|
|
4195
|
+
if (stillHere()) toast(error.message, 6000)
|
|
4119
4196
|
} finally {
|
|
4120
|
-
|
|
4121
|
-
|
|
4197
|
+
if (seq === state.openSeq) {
|
|
4198
|
+
state.zhBusy = false
|
|
4199
|
+
render()
|
|
4200
|
+
}
|
|
4122
4201
|
}
|
|
4123
4202
|
}
|
|
4124
4203
|
|
|
@@ -4456,12 +4535,15 @@ function renderPagePane() {
|
|
|
4456
4535
|
state.cropMode ? '✕ 退出框选' : '⬚ 框选讲解',
|
|
4457
4536
|
),
|
|
4458
4537
|
h('button', {
|
|
4538
|
+
id: 'page-zhpdf',
|
|
4459
4539
|
class: state.zhMode ? 'on' : 'ghost',
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
: '把已有译文写回原版面,生成一份中文版 PDF(纯本地,不上传)',
|
|
4540
|
+
disabled: state.zhBusy,
|
|
4541
|
+
title: '先通过独立任务补齐缺失译文,再本地生成并切换中文版;跨页或无法安全定位的文字会明确提示',
|
|
4463
4542
|
onclick: toggleZhPdf,
|
|
4464
|
-
}, state.zhMode ? '中文版 ✓' : '中文版'),
|
|
4543
|
+
}, state.zhBusy ? '请稍候…' : state.zhMode ? '中文版 ✓' : state.zhStatus?.job?.status === 'running' ? '暂停生成中文版' : state.zhStatus?.job?.status === 'paused' ? '继续生成中文版' : '中文版'),
|
|
4544
|
+
h('span', { role: 'status', class: 'translate-status' }, zhProgress(state.zhStatus?.job)),
|
|
4545
|
+
h('button', { id: 'translate-stop', class: 'btn-pause-trans', hidden: !state.translateBusy, onclick: pauseTranslate }, '暂停翻译'),
|
|
4546
|
+
h('span', { id: 'translate-status', class: 'translate-status', role: 'status' }, state.translateError || progressText()),
|
|
4465
4547
|
h('span', { class: 'spacer' }),
|
|
4466
4548
|
state.current.meta.hasText === false || (state.ocr && state.ocr.pages > 0)
|
|
4467
4549
|
? h('button', { class: 'ghost', onclick: runOcr, disabled: !!state.ocrBusy, title: '扫描件:调用 PaddleOCR 识别全文' }, state.ocrBusy ? 'OCR 中…' : state.ocr && state.ocr.pages > 0 ? '重新 OCR' : 'OCR 识别')
|
|
@@ -4787,6 +4869,9 @@ function renderNotesPane() {
|
|
|
4787
4869
|
{ class: 'row' },
|
|
4788
4870
|
h('span', { class: 'ann-kind-tag' }, ANN_KIND_LABELS[ann.kind] || ann.kind),
|
|
4789
4871
|
h('span', { class: 'muted' }, 'p.' + (ann.page || 1) + (ann.target === 'zh' ? ' · 译文' : ' · 原文')),
|
|
4872
|
+
state.doc?.annotationReview?.some(item => item.id === ann.id)
|
|
4873
|
+
? h('span', { class: 'muted' }, '需复核 · 原文定位已变化 · 旧 revision ' + (state.doc.annotationReview.find(item => item.id === ann.id).revision || '未知'))
|
|
4874
|
+
: null,
|
|
4790
4875
|
ann.note ? h('span', {}, ann.note) : null,
|
|
4791
4876
|
),
|
|
4792
4877
|
h(
|
|
@@ -6083,34 +6168,134 @@ function renderSettings() {
|
|
|
6083
6168
|
|
|
6084
6169
|
// ---------------------------------------------------------------- 在线检索
|
|
6085
6170
|
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6171
|
+
function onlineResultKey(item) {
|
|
6172
|
+
if (item.doi) return 'doi:' + String(item.doi).replace(/^https?:\/\/(?:dx\.)?doi\.org\//i, '').toLowerCase()
|
|
6173
|
+
if (item.arxivId) return 'arxiv:' + String(item.arxivId).replace(/v\d+$/i, '').toLowerCase()
|
|
6174
|
+
return String(item.url || item.absUrl || item.title || '').toLowerCase()
|
|
6175
|
+
}
|
|
6176
|
+
|
|
6177
|
+
async function loadOnlineBatch(kind, append = false) {
|
|
6178
|
+
const model = kind === 'online' ? state.online : state.latestFeed
|
|
6179
|
+
if (append && (model.loading || !model.hasMore)) return
|
|
6180
|
+
model.abort?.abort()
|
|
6181
|
+
const controller = new AbortController()
|
|
6182
|
+
model.abort = controller
|
|
6183
|
+
const seq = ++model.seq
|
|
6184
|
+
if (!append) {
|
|
6185
|
+
model.items = []
|
|
6186
|
+
model.page = 0
|
|
6187
|
+
model.nextCursor = null
|
|
6188
|
+
model.hasMore = false
|
|
6189
|
+
model.requestArgs = kind === 'online'
|
|
6190
|
+
? { query: String(model.q || '').trim(), source: model.source }
|
|
6191
|
+
: model.mode === 'domain'
|
|
6192
|
+
? model.category ? { category: model.category } : { domainId: model.domainId }
|
|
6193
|
+
: model.topicFilter && model.topicFilter !== 'all' ? { topicId: model.topicFilter } : {}
|
|
6194
|
+
if (kind === 'online') model.queried = true
|
|
6195
|
+
}
|
|
6196
|
+
model.loading = true
|
|
6197
|
+
model.error = ''
|
|
6090
6198
|
render()
|
|
6091
6199
|
try {
|
|
6092
|
-
const
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6200
|
+
const result = await rpc(kind === 'online' ? 'search.online' : 'search.latest', {
|
|
6201
|
+
...model.requestArgs, limit: 100, ...(append ? { cursor: model.nextCursor } : {}),
|
|
6202
|
+
}, { signal: controller.signal })
|
|
6203
|
+
if (seq !== model.seq) return
|
|
6204
|
+
const seen = new Set(model.items.map(onlineResultKey))
|
|
6205
|
+
for (const item of Array.isArray(result.items) ? result.items : []) {
|
|
6206
|
+
const key = onlineResultKey(item)
|
|
6207
|
+
if (key && !seen.has(key)) { seen.add(key); model.items.push(item) }
|
|
6208
|
+
}
|
|
6209
|
+
model.nextCursor = result.nextCursor || null
|
|
6210
|
+
model.hasMore = Boolean(result.hasMore && model.nextCursor)
|
|
6211
|
+
model.warnings = Array.isArray(result.warnings) ? result.warnings : []
|
|
6212
|
+
model.partialErrors = Array.isArray(result.partialErrors) ? result.partialErrors : []
|
|
6213
|
+
if (kind !== 'online' && Array.isArray(result.topics)) model.topics = result.topics
|
|
6214
|
+
model.loaded = true
|
|
6106
6215
|
} catch (error) {
|
|
6107
|
-
|
|
6216
|
+
if (seq === model.seq && error.name !== 'AbortError') model.error = error.message
|
|
6108
6217
|
} finally {
|
|
6109
|
-
|
|
6110
|
-
render()
|
|
6218
|
+
if (seq === model.seq) { model.loading = false; render() }
|
|
6111
6219
|
}
|
|
6112
6220
|
}
|
|
6113
6221
|
|
|
6222
|
+
async function loadLatestFeed(force = false) {
|
|
6223
|
+
return loadOnlineBatch('feed')
|
|
6224
|
+
}
|
|
6225
|
+
|
|
6226
|
+
async function changeOnlinePage(kind, direction) {
|
|
6227
|
+
const model = kind === 'online' ? state.online : state.latestFeed
|
|
6228
|
+
const target = model.page + direction
|
|
6229
|
+
if (target < 0 || model.loading) return
|
|
6230
|
+
const seq = model.seq
|
|
6231
|
+
if (target * 10 >= model.items.length) {
|
|
6232
|
+
if (!model.hasMore) return
|
|
6233
|
+
await loadOnlineBatch(kind, true)
|
|
6234
|
+
if (model.seq !== seq + 1) return
|
|
6235
|
+
} else if (model.seq !== seq) return
|
|
6236
|
+
if (target * 10 < model.items.length) model.page = target
|
|
6237
|
+
render()
|
|
6238
|
+
const results = document.querySelector('.online-results')
|
|
6239
|
+
if (results) results.scrollTop = 0
|
|
6240
|
+
}
|
|
6241
|
+
|
|
6242
|
+
function renderOnlinePagination(kind, model) {
|
|
6243
|
+
const pages = Math.max(1, Math.ceil(model.items.length / 10))
|
|
6244
|
+
return h('div', { class: 'online-pagination', 'aria-label': '论文结果分页' },
|
|
6245
|
+
h('button', { 'data-page-prev': kind, disabled: model.loading || model.page === 0, onclick: () => changeOnlinePage(kind, -1) }, '上一页'),
|
|
6246
|
+
h('span', { class: 'hint', 'aria-live': 'polite' }, '第 ' + (model.page + 1) + ' / ' + pages + ' 页 · 已加载 ' + model.items.length + ' 篇 · 每页 10 篇'),
|
|
6247
|
+
h('button', { 'data-page-next': kind, disabled: model.loading || ((model.page + 1) * 10 >= model.items.length && !model.hasMore), onclick: () => changeOnlinePage(kind, 1) }, model.loading ? '加载中…' : (model.page + 1) * 10 >= model.items.length && model.hasMore ? '下一批 / 下一页' : '下一页'))
|
|
6248
|
+
}
|
|
6249
|
+
|
|
6250
|
+
async function openOriginalPaper(item) {
|
|
6251
|
+
let url
|
|
6252
|
+
try { url = new URL(item.url || item.absUrl) } catch { return toast('原文链接无效') }
|
|
6253
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) return toast('原文链接不受支持')
|
|
6254
|
+
window.open(url.href, '_blank', 'noopener')
|
|
6255
|
+
await rememberPaper(item)
|
|
6256
|
+
if (state.browseHistory.open) render()
|
|
6257
|
+
}
|
|
6258
|
+
|
|
6259
|
+
async function rememberPaper(item) {
|
|
6260
|
+
const { title, source, doi, arxivId, url, absUrl, paperId } = item
|
|
6261
|
+
try {
|
|
6262
|
+
const result = await rpc('history.record', { item: { title, source, doi, arxivId, url: url || absUrl, paperId } })
|
|
6263
|
+
state.browseHistory.items = result.items || state.browseHistory.items
|
|
6264
|
+
} catch (error) { toast('浏览历史保存失败:' + error.message) }
|
|
6265
|
+
}
|
|
6266
|
+
|
|
6267
|
+
async function toggleBrowseHistory() {
|
|
6268
|
+
const history = state.browseHistory
|
|
6269
|
+
history.open = !history.open
|
|
6270
|
+
if (!history.open) { render(); return }
|
|
6271
|
+
history.loading = true
|
|
6272
|
+
history.error = ''
|
|
6273
|
+
render()
|
|
6274
|
+
try { history.items = (await rpc('history.list')).items || [] }
|
|
6275
|
+
catch (error) { history.error = error.message }
|
|
6276
|
+
finally { history.loading = false; render() }
|
|
6277
|
+
}
|
|
6278
|
+
|
|
6279
|
+
function renderBrowseHistory() {
|
|
6280
|
+
const history = state.browseHistory
|
|
6281
|
+
const items = history.items.filter(item => item.title.toLowerCase().includes(history.q.toLowerCase()))
|
|
6282
|
+
return h('div', { class: 'browse-history' },
|
|
6283
|
+
h('div', { class: 'row' }, h('strong', {}, '论文浏览历史'), h('span', { class: 'hint' }, '仅保存最近 200 篇的题名和原文链接'),
|
|
6284
|
+
h('button', { onclick: async () => { try { await rpc('history.clear'); history.items = []; history.error = '' } catch (error) { history.error = error.message } render() } }, '清空历史')),
|
|
6285
|
+
h('input', { type: 'search', placeholder: '筛选历史题名', value: history.q, oninput: event => { history.q = event.target.value; render(); document.querySelector('.browse-history input')?.focus() } }),
|
|
6286
|
+
history.error ? h('div', { class: 'error' }, history.error) : null,
|
|
6287
|
+
history.loading ? h('div', { class: 'hint' }, '正在加载…') : null,
|
|
6288
|
+
h('div', { class: 'online-results' }, items.map(item => h('div', { class: 'history-item' },
|
|
6289
|
+
h('button', { class: 'history-title', onclick: async () => {
|
|
6290
|
+
if (item.paperId && state.papers.some(paper => paper.id === item.paperId)) { history.open = false; await openPaper(item.paperId) }
|
|
6291
|
+
else if (item.url) await openOriginalPaper(item)
|
|
6292
|
+
else toast('原论文已不在文库,记录中没有原文链接')
|
|
6293
|
+
} }, item.title),
|
|
6294
|
+
h('span', { class: 'hint' }, item.lastViewedAt.slice(0, 10)),
|
|
6295
|
+
h('button', { 'aria-label': '删除浏览记录:' + item.title, onclick: async () => { history.items = (await rpc('history.remove', { id: item.id })).items || []; render() } }, '删除')))),
|
|
6296
|
+
!history.loading && !items.length ? h('div', { class: 'hint' }, '暂无浏览记录。打开原文或进入论文阅读后会自动记录。') : null)
|
|
6297
|
+
}
|
|
6298
|
+
|
|
6114
6299
|
async function quickSubscribeArxivTarget(label, domainId, categoryCode) {
|
|
6115
6300
|
try {
|
|
6116
6301
|
const settingsRes = await rpc('settings.get')
|
|
@@ -6166,30 +6351,26 @@ function renderOnlineResultCard(item) {
|
|
|
6166
6351
|
h(
|
|
6167
6352
|
'div',
|
|
6168
6353
|
{ class: 'row' },
|
|
6169
|
-
h(
|
|
6170
|
-
'
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6354
|
+
h('button', {
|
|
6355
|
+
class: 'primary',
|
|
6356
|
+
disabled: !item.pdfUrl || state.busy === 'import:' + item.title,
|
|
6357
|
+
onclick: async () => {
|
|
6358
|
+
state.busy = 'import:' + item.title
|
|
6359
|
+
render()
|
|
6360
|
+
try {
|
|
6361
|
+
const value = await rpc('search.import', { item })
|
|
6362
|
+
toast('已入库:' + value.meta.title)
|
|
6363
|
+
await loadLibrary()
|
|
6364
|
+
await openPaper(value.meta.id)
|
|
6365
|
+
} catch (error) {
|
|
6366
|
+
toast('入库失败:' + error.message)
|
|
6367
|
+
} finally {
|
|
6368
|
+
state.busy = ''
|
|
6176
6369
|
render()
|
|
6177
|
-
|
|
6178
|
-
const value = await rpc('search.import', { item })
|
|
6179
|
-
toast('已入库:' + value.meta.title)
|
|
6180
|
-
await loadLibrary()
|
|
6181
|
-
if (value.meta) openPaper(value.meta.id)
|
|
6182
|
-
} catch (error) {
|
|
6183
|
-
toast('入库失败:' + error.message)
|
|
6184
|
-
} finally {
|
|
6185
|
-
state.busy = ''
|
|
6186
|
-
render()
|
|
6187
|
-
}
|
|
6188
|
-
},
|
|
6370
|
+
}
|
|
6189
6371
|
},
|
|
6190
|
-
|
|
6191
|
-
),
|
|
6192
|
-
item.url || item.absUrl ? h('button', { onclick: () => window.open(item.url || item.absUrl, '_blank', 'noopener') }, '打开原文页') : null,
|
|
6372
|
+
}, item.pdfUrl ? '下载并入库' : '无开放 PDF'),
|
|
6373
|
+
item.url || item.absUrl ? h('button', { onclick: () => openOriginalPaper(item) }, '打开原文页') : null,
|
|
6193
6374
|
h('button', { onclick: () => insertGeneralPrompt('帮我查找并研读这篇论文:' + item.title + (item.doi ? '(DOI ' + item.doi + ')' : '') + ',提炼研究动机、方法设计与核心结论。') }, '让 agent 读'),
|
|
6194
6375
|
),
|
|
6195
6376
|
)
|
|
@@ -6224,23 +6405,20 @@ function renderOnline() {
|
|
|
6224
6405
|
h('option', { value: 'openalex', selected: state.online.source === 'openalex' }, '仅 OpenAlex'),
|
|
6225
6406
|
),
|
|
6226
6407
|
h('button', { class: 'primary', onclick: doSearch, disabled: state.online.loading }, state.online.loading ? '检索中…' : '检索'),
|
|
6227
|
-
state.
|
|
6228
|
-
|
|
6408
|
+
h('button', { id: 'browse-history-toggle', 'aria-expanded': String(state.browseHistory.open), onclick: toggleBrowseHistory }, state.browseHistory.open ? '返回检索' : '浏览历史'),
|
|
6409
|
+
state.online.queried
|
|
6410
|
+
? h('button', { class: 'ghost', onclick: () => { clearOnlineSearch(); render() } }, '返回学科与订阅流')
|
|
6229
6411
|
: null,
|
|
6230
6412
|
obsidianEnabled()
|
|
6231
6413
|
? h('button', { onclick: () => insertGeneralPrompt(P.vaultSearch(state.online.q || '论文')) }, '问笔记库')
|
|
6232
6414
|
: h('button', { onclick: () => insertGeneralPrompt('请在当前工作台文献库中梳理与「' + (state.online.q || '论文') + '」相关的已有工作、方法差异与研究空白。') }, '问文献库'),
|
|
6233
6415
|
),
|
|
6234
6416
|
)
|
|
6235
|
-
if (state.
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
box.append(renderOnlineResultCard(item))
|
|
6241
|
-
}
|
|
6242
|
-
|
|
6243
|
-
if (state.online.items.length === 0) {
|
|
6417
|
+
if (state.browseHistory.open) {
|
|
6418
|
+
box.append(renderBrowseHistory())
|
|
6419
|
+
} else if (state.online.queried) {
|
|
6420
|
+
box.append(renderOnlineResults('online', state.online))
|
|
6421
|
+
} else {
|
|
6244
6422
|
const lf = state.latestFeed
|
|
6245
6423
|
const domainsCatalog = lf.domains && lf.domains.length ? lf.domains : FALLBACK_ARXIV_DOMAINS
|
|
6246
6424
|
const cfgItems = state.fullConfig && state.fullConfig.topics && Array.isArray(state.fullConfig.topics.items) ? state.fullConfig.topics.items : null
|
|
@@ -6260,9 +6438,18 @@ function renderOnline() {
|
|
|
6260
6438
|
h('span', { class: 'hint' }, '按发布时间倒序'),
|
|
6261
6439
|
h('span', { class: 'spacer' }),
|
|
6262
6440
|
h('button', { class: 'ghost', disabled: lf.loading, onclick: () => loadLatestFeed(true) }, lf.loading ? '刷新中…' : '↻ 刷新最新'),
|
|
6441
|
+
h('button', {
|
|
6442
|
+
id: 'domain-nav-toggle', 'aria-expanded': String(!state.onlineNavCollapsed),
|
|
6443
|
+
onclick: () => {
|
|
6444
|
+
state.onlineNavCollapsed = !state.onlineNavCollapsed
|
|
6445
|
+
saveSession({ onlineNavCollapsed: state.onlineNavCollapsed })
|
|
6446
|
+
render()
|
|
6447
|
+
document.getElementById('domain-nav-toggle')?.focus()
|
|
6448
|
+
},
|
|
6449
|
+
}, state.onlineNavCollapsed ? '展开学科导航' : '收起学科导航'),
|
|
6263
6450
|
h('button', { class: 'ghost', onclick: openSettings }, '⚙ 订阅与代理设置'),
|
|
6264
6451
|
),
|
|
6265
|
-
h(
|
|
6452
|
+
state.onlineNavCollapsed ? null : h(
|
|
6266
6453
|
'div',
|
|
6267
6454
|
{ class: 'domain-nav' },
|
|
6268
6455
|
h(
|
|
@@ -6385,56 +6572,32 @@ function renderOnline() {
|
|
|
6385
6572
|
),
|
|
6386
6573
|
),
|
|
6387
6574
|
)
|
|
6388
|
-
|
|
6389
|
-
feedPanel.append(
|
|
6390
|
-
h(
|
|
6391
|
-
'div',
|
|
6392
|
-
{ class: 'error' },
|
|
6393
|
-
'最新论文拉取失败:' + lf.error + '(若本机需走代理访问 arXiv,请点右上角「⚙ 订阅与代理设置」配置代理并测试连通性)',
|
|
6394
|
-
),
|
|
6395
|
-
)
|
|
6396
|
-
} else if (Array.isArray(lf.partialErrors) && lf.partialErrors.length > 0 && lf.items.length === 0) {
|
|
6397
|
-
feedPanel.append(
|
|
6398
|
-
h(
|
|
6399
|
-
'div',
|
|
6400
|
-
{ class: 'error' },
|
|
6401
|
-
'拉取受阻:' + lf.partialErrors[0].message + '(请点「⚙ 订阅与代理设置 → 网络与代理」检查代理端口并测试网络连通)',
|
|
6402
|
-
),
|
|
6403
|
-
)
|
|
6404
|
-
}
|
|
6405
|
-
const feedItems = lf.items.filter((item) => {
|
|
6406
|
-
if (lf.mode === 'domain' || !lf.topicFilter || lf.topicFilter === 'all') return true
|
|
6407
|
-
if (Array.isArray(item.topics) && item.topics.includes(lf.topicFilter)) return true
|
|
6408
|
-
if (Array.isArray(item.topicIds) && item.topicIds.includes(lf.topicFilter)) return true
|
|
6409
|
-
if (Array.isArray(item.matchedTopics) && item.matchedTopics.includes(lf.topicFilter)) return true
|
|
6410
|
-
return true
|
|
6411
|
-
})
|
|
6412
|
-
for (const item of feedItems) feedPanel.append(renderOnlineResultCard(item))
|
|
6413
|
-
if (!lf.loading && feedItems.length === 0 && !lf.error && !(lf.partialErrors && lf.partialErrors.length > 0)) {
|
|
6414
|
-
feedPanel.append(h('div', { class: 'hint' }, lf.loaded ? '当前筛选方向暂无最新论文,可切换上方 8 大学科标签或点「↻ 刷新最新」。' : '正在准备订阅流,也可直接点击上方 8 大学科浏览最新 arXiv 预印本。'))
|
|
6415
|
-
}
|
|
6575
|
+
feedPanel.append(renderOnlineResults('feed', lf))
|
|
6416
6576
|
box.append(feedPanel)
|
|
6417
6577
|
}
|
|
6418
|
-
return h('div', { class: 'content' }, box)
|
|
6578
|
+
return h('div', { class: 'content online-content' }, box)
|
|
6579
|
+
}
|
|
6580
|
+
|
|
6581
|
+
function renderOnlineResults(kind, model) {
|
|
6582
|
+
const messages = [model.error, ...(model.warnings || []), ...(model.partialErrors || []).map(error => error.message)].filter(Boolean)
|
|
6583
|
+
return h('div', { class: 'online-result-panel' },
|
|
6584
|
+
messages.length ? h('div', { class: model.error ? 'error' : 'hint', role: 'status' }, [...new Set(messages)].join(';')) : null,
|
|
6585
|
+
h('div', { class: 'online-results', tabindex: '0', 'aria-label': '论文结果' },
|
|
6586
|
+
model.items.slice(model.page * 10, (model.page + 1) * 10).map(renderOnlineResultCard),
|
|
6587
|
+
!model.items.length && !messages.length ? h('div', { class: 'hint' }, model.loading ? '正在拉取论文…' : '当前没有论文结果。') : null),
|
|
6588
|
+
renderOnlinePagination(kind, model))
|
|
6589
|
+
}
|
|
6590
|
+
|
|
6591
|
+
function clearOnlineSearch() {
|
|
6592
|
+
const model = state.online
|
|
6593
|
+
model.abort?.abort()
|
|
6594
|
+
model.seq += 1
|
|
6595
|
+
Object.assign(model, { queried: false, loading: false, items: [], page: 0, error: '', hasMore: false, nextCursor: null })
|
|
6419
6596
|
}
|
|
6420
6597
|
|
|
6421
6598
|
async function doSearch() {
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
state.online.loading = true
|
|
6425
|
-
state.online.error = ''
|
|
6426
|
-
state.online.warnings = []
|
|
6427
|
-
render()
|
|
6428
|
-
try {
|
|
6429
|
-
const value = await rpc('search.online', { query, source: state.online.source, limit: 10 })
|
|
6430
|
-
state.online.items = value.items || []
|
|
6431
|
-
state.online.warnings = Array.isArray(value.warnings) ? value.warnings : []
|
|
6432
|
-
} catch (error) {
|
|
6433
|
-
state.online.error = '检索失败:' + error.message
|
|
6434
|
-
} finally {
|
|
6435
|
-
state.online.loading = false
|
|
6436
|
-
render()
|
|
6437
|
-
}
|
|
6599
|
+
if (!String(state.online.q || '').trim()) return
|
|
6600
|
+
await loadOnlineBatch('online')
|
|
6438
6601
|
}
|
|
6439
6602
|
|
|
6440
6603
|
function comparePicked() {
|
|
@@ -8574,6 +8737,7 @@ async function bootInner() {
|
|
|
8574
8737
|
// 本地一份(同端口刷新快)+ 服务端一份(桌面端重启换端口也不丢),取较新的。
|
|
8575
8738
|
const session = pickSession(loadSession(), await loadSessionRemote())
|
|
8576
8739
|
if (session && typeof session === 'object') {
|
|
8740
|
+
state.onlineNavCollapsed = session.onlineNavCollapsed === true
|
|
8577
8741
|
let localHasLayout = false
|
|
8578
8742
|
let localHasTree = false
|
|
8579
8743
|
let localHasAi = false
|