dsh-rank-scan 0.2.3 → 0.3.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/README.md +30 -27
- package/lib/client.js +1814 -676
- package/lib/index.js +674 -120
- package/lib/index.js.map +1 -1
- package/lib/scan/daily.js +93 -0
- package/lib/scan/daily.js.map +1 -0
- package/lib/scan/diff.js +9 -1
- package/lib/scan/diff.js.map +1 -1
- package/lib/scan/freshness.js +67 -0
- package/lib/scan/freshness.js.map +1 -0
- package/lib/scan/run.js +33 -5
- package/lib/scan/run.js.map +1 -1
- package/lib/scan/schedule.js +10 -4
- package/lib/scan/schedule.js.map +1 -1
- package/lib/scan/store.js +95 -1
- package/lib/scan/store.js.map +1 -1
- package/lib/scan/types.js.map +1 -1
- package/lib/sites/qidiantu.js +9 -1
- package/lib/sites/qidiantu.js.map +1 -1
- package/lib/types/scan/daily.d.ts +89 -0
- package/lib/types/scan/diff.d.ts +6 -0
- package/lib/types/scan/freshness.d.ts +42 -0
- package/lib/types/scan/run.d.ts +8 -0
- package/lib/types/scan/schedule.d.ts +6 -0
- package/lib/types/scan/store.d.ts +44 -0
- package/lib/types/scan/types.d.ts +42 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -14,36 +14,117 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
// ★ 2026-10-16(使用者口径 B):入口 id 恢复成审计前的独立值 —— 不复用浮窗 id,
|
|
15
15
|
// 免得宿主把侧栏这一行当成「面板页」去 selectPanel 切主区域。
|
|
16
16
|
const ENTRY_ID = 'rank-scan-entry'
|
|
17
|
-
const
|
|
17
|
+
const readResponse = async (response) => {
|
|
18
|
+
const data = await response.json()
|
|
19
|
+
if (response.ok === false || (data && (data.ok === false || data.error))) {
|
|
20
|
+
throw new Error((data && (data.error || data.note)) || ('请求失败:' + response.status))
|
|
21
|
+
}
|
|
22
|
+
return data
|
|
23
|
+
}
|
|
24
|
+
const jget = (p) => fetch(API + p, { headers: { Accept: 'application/json' } }).then(readResponse)
|
|
25
|
+
const readOverview = async function () {
|
|
26
|
+
const controller = new AbortController()
|
|
27
|
+
let timer
|
|
28
|
+
try {
|
|
29
|
+
return await Promise.race([
|
|
30
|
+
fetch(API + '/overview', { headers: { Accept: 'application/json' }, signal: controller.signal }).then(readResponse),
|
|
31
|
+
new Promise(function (_, reject) {
|
|
32
|
+
timer = setTimeout(function () { controller.abort(); reject(new Error('概览读取超时,请重试')) }, 10000)
|
|
33
|
+
}),
|
|
34
|
+
])
|
|
35
|
+
} finally { clearTimeout(timer) }
|
|
36
|
+
}
|
|
18
37
|
// ⚠️ 之前这里**丢掉了 body**(调用方写的 {captures:…} 全被忽略)⇒ 面板里所有「保存」实际都没带参数:
|
|
19
38
|
// 抓取集保存不动、每榜深度存不进去。现在统一带 JSON body。
|
|
20
39
|
const jpost = (p, body) => fetch(API + p, {
|
|
21
40
|
method: 'POST',
|
|
22
41
|
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
23
42
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
24
|
-
}).then(
|
|
43
|
+
}).then(readResponse)
|
|
25
44
|
|
|
26
45
|
const LS_POS = 'rank-scan-panel:rect:v1'
|
|
27
46
|
// 面板开关的本地记忆:v1 = 用户最后一次的开/关;auto = 「首次安装已自动弹过」
|
|
28
47
|
// 需求(2026-10-15 使用方口径):安装成功后第一次打开 DSH 自动弹一次,之后用户关掉就不再自动弹。
|
|
29
48
|
const LS_SEL = 'rank-scan-panel:sel:v1'
|
|
30
|
-
/** 面板 UI 选择(tab + 站 +
|
|
49
|
+
/** 面板 UI 选择(tab + 站 + 榜 + 每榜日期/排序):模块级共享,收起面板/刷新页面都回到原界面 */
|
|
31
50
|
const sel = (function () {
|
|
32
|
-
let s = { tab: 'ov', site: null, board: null }
|
|
51
|
+
let s = { tab: 'ov', site: null, board: null, dates: {}, sorts: {} }
|
|
33
52
|
try {
|
|
34
53
|
const raw = localStorage.getItem(LS_SEL)
|
|
35
|
-
if (raw) {
|
|
54
|
+
if (raw) {
|
|
55
|
+
const o = JSON.parse(raw)
|
|
56
|
+
s = {
|
|
57
|
+
tab: o.tab || 'ov', site: o.site || null, board: o.board || null,
|
|
58
|
+
/**
|
|
59
|
+
* ★ 2026-10-22(易用性 B):日期/排序**按榜各记各的**。
|
|
60
|
+
* 以前这两个是组件内 state,收起面板/换榜就丢 ⇒ 每天都要重新选一次日期。
|
|
61
|
+
* 换成按 boardId 存:换榜回来还是上次那个视图,但不会把上一榜的日期带过去。
|
|
62
|
+
*/
|
|
63
|
+
dates: o.dates && typeof o.dates === 'object' ? o.dates : {},
|
|
64
|
+
sorts: o.sorts && typeof o.sorts === 'object' ? o.sorts : {},
|
|
65
|
+
}
|
|
66
|
+
}
|
|
36
67
|
} catch (e) {}
|
|
37
|
-
|
|
68
|
+
const store = {
|
|
38
69
|
get: function () { return s },
|
|
39
70
|
set: function (patch) {
|
|
40
71
|
s = { ...s, ...patch }
|
|
41
72
|
try { localStorage.setItem(LS_SEL, JSON.stringify(s)) } catch (e) {}
|
|
42
73
|
},
|
|
74
|
+
/** 读某榜记住的日期('' = 最新)/ 排序('' = 默认) */
|
|
75
|
+
pref: function (boardId, kind) {
|
|
76
|
+
if (!boardId) return ''
|
|
77
|
+
const m = kind === 'sort' ? s.sorts : s.dates
|
|
78
|
+
return (m && m[boardId]) || ''
|
|
79
|
+
},
|
|
80
|
+
/** 写某榜的日期/排序;空串 = 清掉,回到默认 */
|
|
81
|
+
setPref: function (boardId, kind, value) {
|
|
82
|
+
if (!boardId) return
|
|
83
|
+
const key = kind === 'sort' ? 'sorts' : 'dates'
|
|
84
|
+
const m = { ...(s[key] || {}) }
|
|
85
|
+
if (value) m[boardId] = value
|
|
86
|
+
else delete m[boardId]
|
|
87
|
+
const patch = {}
|
|
88
|
+
patch[key] = m
|
|
89
|
+
store.set(patch)
|
|
90
|
+
},
|
|
43
91
|
}
|
|
92
|
+
return store
|
|
44
93
|
})()
|
|
45
94
|
// 模块级单例锚:即使 loader 把 factory 跑两遍(本会话确实见到重复入口),两个实例也共用同一份状态
|
|
46
95
|
const SHARED = (window.__rankScanShared = window.__rankScanShared || {})
|
|
96
|
+
/**
|
|
97
|
+
* ★ 2026-10-22(离开保护):未保存草稿**放在组件外**,切页/收起/重载把组件卸了也不丢。
|
|
98
|
+
* bm = 书签备注/夹草稿;settings = 抓取范围 + 计划时刻草稿。
|
|
99
|
+
*/
|
|
100
|
+
const DRAFT_KEY = 'rank-scan-panel:drafts:v1'
|
|
101
|
+
let restoredDrafts = { bm: null, settings: null }
|
|
102
|
+
try {
|
|
103
|
+
const saved = JSON.parse(sessionStorage.getItem(DRAFT_KEY) || 'null')
|
|
104
|
+
if (saved && typeof saved === 'object') restoredDrafts = saved
|
|
105
|
+
} catch (e) {}
|
|
106
|
+
const draftTarget = window.__rankScanDrafts || restoredDrafts
|
|
107
|
+
const DRAFTS = (window.__rankScanDrafts = new Proxy(draftTarget, {
|
|
108
|
+
set: function (target, key, value) {
|
|
109
|
+
target[key] = value
|
|
110
|
+
try { sessionStorage.setItem(DRAFT_KEY, JSON.stringify(target)) } catch (e) {}
|
|
111
|
+
return true
|
|
112
|
+
},
|
|
113
|
+
}))
|
|
114
|
+
/** 脏状态登记:面板在切页/收起前据此拦一下(只提示,不替用户保存) */
|
|
115
|
+
const dirtyGuard = (function () {
|
|
116
|
+
const m = { bm: !!(DRAFTS.bm && DRAFTS.bm.dirty), settings: !!DRAFTS.settings }
|
|
117
|
+
return {
|
|
118
|
+
set: function (k, v) {
|
|
119
|
+
const on = !!v
|
|
120
|
+
if (!!m[k] === on) return
|
|
121
|
+
m[k] = on
|
|
122
|
+
try { window.dispatchEvent(new Event('rank-scan:dirty')) } catch (e) {}
|
|
123
|
+
},
|
|
124
|
+
any: function () { return Object.keys(m).some(function (k) { return m[k] }) },
|
|
125
|
+
list: function () { return Object.keys(m).filter(function (k) { return m[k] }) },
|
|
126
|
+
}
|
|
127
|
+
})()
|
|
47
128
|
const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
48
129
|
const LS_AUTOOPENED = 'rank-scan-panel:autoopened:v1'
|
|
49
130
|
/** 用户上次的开/关(纯读,无副作用) */
|
|
@@ -81,8 +162,18 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
81
162
|
tab: (on) => ({ padding: '3px 9px', cursor: 'pointer', border: 'none', background: 'transparent', color: 'inherit',
|
|
82
163
|
borderBottom: on ? '2px solid currentColor' : '2px solid transparent', fontWeight: on ? 600 : 400 }),
|
|
83
164
|
table: { width: '100%', borderCollapse: 'collapse', fontSize: '12px' },
|
|
84
|
-
th: { textAlign: 'left', padding: '2px 5px', borderBottom: '1px solid rgba(128,128,128,.3)', whiteSpace: 'nowrap', fontWeight: 600 },
|
|
165
|
+
th: { textAlign: 'left', padding: '2px 5px', borderBottom: '1px solid rgba(128,128,128,.3)', whiteSpace: 'nowrap', fontWeight: 600, position: 'sticky', top: 0, zIndex: 3, background: 'var(--dsh-surface, #fff)' },
|
|
85
166
|
td: { padding: '2px 5px', borderBottom: '1px solid rgba(128,128,128,.1)', verticalAlign: 'top' },
|
|
167
|
+
/**
|
|
168
|
+
* ★ 2026-10-17(易用性 P0):数字列以前会折行(「退 1」被拆成两行、20 个榜的表拉高一倍)。
|
|
169
|
+
* num 给数字列用(不折行 + 等宽数字,扫一眼就能对齐比大小)。
|
|
170
|
+
*/
|
|
171
|
+
num: { whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' },
|
|
172
|
+
/* 涨跌配色:绿涨红跌,与 dot('ok'/'bad') 同一套语义;符号仍然保留,不靠颜色单打 */
|
|
173
|
+
up: { color: '#3f9b4f', whiteSpace: 'nowrap' },
|
|
174
|
+
down: { color: '#d9534f', whiteSpace: 'nowrap' },
|
|
175
|
+
/* 长榜名单行省略(全名放 title 里)——避免「签约榜 × 轻小说(移动端口径)」撑成两行 */
|
|
176
|
+
ellip: { display: 'inline-block', maxWidth: '232px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', verticalAlign: 'bottom' },
|
|
86
177
|
muted: { opacity: 0.7, fontSize: '11.5px' },
|
|
87
178
|
siteBar: { marginTop: '8px', fontWeight: 600, fontSize: '12.5px', display: 'flex', gap: '6px', alignItems: 'center' },
|
|
88
179
|
dot: (tone) => ({ display: 'inline-block', width: '7px', height: '7px', borderRadius: '50%',
|
|
@@ -98,7 +189,36 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
98
189
|
chip: { display: 'inline-block', marginRight: '4px', padding: '0 5px', borderRadius: '8px', background: 'rgba(128,128,128,.18)', fontSize: '11px' },
|
|
99
190
|
input: { padding: '3px 6px', fontSize: '12px', borderRadius: '6px', border: '1px solid rgba(128,128,128,.4)', background: 'transparent', color: 'inherit' },
|
|
100
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* ★ 2026-10-17(易用性 P0):哪些列算「数字列」—— 只有它们套 C.num(不折行 + 等宽数字)。
|
|
194
|
+
* 书名/作者/分类这类文本列仍允许换行,否则长书名会把整张表撑宽。
|
|
195
|
+
*/
|
|
196
|
+
const NUM_COL_RE = /^(rank|delta|words|collect|collectBase|value|ratio|fans|read|readDelta|periodTotal|periodDelta|score|days|buyNumRaw|daily\d*|pday\d*)$/
|
|
197
|
+
const isNumCol = (key) => NUM_COL_RE.test(String(key || ''))
|
|
101
198
|
const dash = (v) => (v === null || v === undefined || v === '' ? '—' : v)
|
|
199
|
+
/**
|
|
200
|
+
* ★ 2026-10-17(使用者问「跨天怎么算」):两个数据日期之间隔了几天(YYYY-MM-DD,本地口径)。
|
|
201
|
+
* 变化列的基准是「上一个**有数据**的日期」,隔天时它就不是昨天了 —— 界面上必须写清楚隔了几天,
|
|
202
|
+
* 否则「今日涨幅」看着像单日,其实跨了 2~N 天。
|
|
203
|
+
*/
|
|
204
|
+
const dayGap = (a, b) => {
|
|
205
|
+
const x = Date.parse(String(a) + 'T00:00:00')
|
|
206
|
+
const y = Date.parse(String(b) + 'T00:00:00')
|
|
207
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return null
|
|
208
|
+
return Math.round((y - x) / 86400000)
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* ★ 2026-10-22(历史日期映射修正):上架日 ↔ 数据日期。
|
|
212
|
+
* 首订榜锚 **n-1**:数据日期 X 的榜面属于 X-1(适配器 contentDateFor 就是这么声明的)。
|
|
213
|
+
* 所以「上架日 X」要请求的是「数据日期 X+1」,页面内容日期仍是 X;落盘也记在 X+1 名下。
|
|
214
|
+
*/
|
|
215
|
+
const addDaysStr = (d, n) => {
|
|
216
|
+
const parts = String(d || '').split('-').map(Number)
|
|
217
|
+
if (parts.length !== 3 || !parts.every(function (x) { return Number.isFinite(x) })) return null
|
|
218
|
+
const dt = new Date(parts[0], parts[1] - 1, parts[2] + n)
|
|
219
|
+
const p = function (x) { return String(x).padStart(2, '0') }
|
|
220
|
+
return dt.getFullYear() + '-' + p(dt.getMonth() + 1) + '-' + p(dt.getDate())
|
|
221
|
+
}
|
|
102
222
|
/**
|
|
103
223
|
* ★ 2026-10-17(发布前修):请求间隔已可配置(默认 1000ms)⇒ 所有「1 请求/秒」「1s 限速」
|
|
104
224
|
* 的文案必须跟着**当前生效值**走,否则使用者把它调成 500ms 后,面板说的和做的不一致。
|
|
@@ -157,13 +277,311 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
157
277
|
const vh = Math.max(240, Number(window.innerHeight) || 800)
|
|
158
278
|
const num = (v, fb) => (Number.isFinite(Number(v)) ? Number(v) : fb)
|
|
159
279
|
const r = raw && typeof raw === 'object' ? raw : {}
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
280
|
+
const M = 8
|
|
281
|
+
const w = Math.min(Math.max(420, num(r.w, 660)), Math.max(320, vw - 2 * M))
|
|
282
|
+
const h = Math.min(Math.max(240, num(r.h, 480)), Math.max(240, vh - 2 * M))
|
|
283
|
+
/**
|
|
284
|
+
* ★ 2026-10-23(面板跑到屏幕外):旧写法只夹 x <= vw-80、y <= vh-48,
|
|
285
|
+
* 于是 x + w 可以远超视口宽 —— 换小屏/浏览器缩放后整块面板挂在右边外面,
|
|
286
|
+
* 表头与「收起」按钮全在屏幕外(使用者现场:右侧整片被切掉、收不回来)。
|
|
287
|
+
* 现在按**右下边界**夹:保证 x + w <= vw - 8、y + h <= vh - 8。
|
|
288
|
+
*/
|
|
289
|
+
const x = Math.min(Math.max(M, num(r.x, Math.max(M, vw - w - 24))), Math.max(M, vw - w - M))
|
|
290
|
+
const y = Math.min(Math.max(M, num(r.y, 64)), Math.max(M, vh - h - M))
|
|
164
291
|
return { x: x, y: y, w: w, h: h }
|
|
165
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* ★ 2026-10-23(使用者口径):「最大化」整块去掉 —— 它跟宿主界面必然重叠(铺满就把
|
|
295
|
+
* DSH 自己的顶栏夹在下面),拖到哪、缩到多大本来就能自己决定,多一个会打架的按钮不值得。
|
|
296
|
+
* 面板只剩:拖动标题栏 + 右下角拖拽缩放,位置尺寸照旧记在 LS_POS 里。
|
|
297
|
+
*/
|
|
166
298
|
|
|
299
|
+
/* ────────────────────────────────────────────────────────────────────────
|
|
300
|
+
* ★ 2026-10-22(简明性 / 易用性,工作包 B·C·D)共用小件
|
|
301
|
+
* · revOf 同一天重扫也要刷新视图(宿主暂未下发 revision ⇒ 用可见状态拼一个安全的)
|
|
302
|
+
* · PopMenu 低频操作统一收进「更多」菜单(键盘可达、Esc/点外面关闭、焦点归还)
|
|
303
|
+
* · Section 设置页的四组折叠块
|
|
304
|
+
* · useEscLayer Esc 的层级关闭(菜单 → 详情 → 面板),编辑中不关面板
|
|
305
|
+
* ──────────────────────────────────────────────────────────────────────── */
|
|
306
|
+
/** 2026-10-22:'2026-10-22' → '10-22'(状态带里省宽度,年份放 title) */
|
|
307
|
+
// ★ 2026-10-23:以前是 s.slice(5)(切到末尾)⇒ 书签卡上显示「截止 10-17T04:00:00.000Z」。只取 5..10。
|
|
308
|
+
const mdOf = function (v) { const s = String(v == null ? '' : v); return s.length >= 10 ? s.slice(5, 10) : s }
|
|
309
|
+
/**
|
|
310
|
+
* 数据修订号:**同一天再扫一次**也要让概览/榜单重读(以前只盯 dataDate,当天不变就永远不刷)。
|
|
311
|
+
* 宿主目前不下发 revision ⇒ 用「扫描记录 + 计数 + 存储缓存时间」拼一个安全的替代值:
|
|
312
|
+
* 扫描结束会主动刷新占用缓存(storage.cachedAt 必变),所以它能反映「又跑了一轮」。
|
|
313
|
+
* 将来宿主给了 ov.revision 就优先用它,不改调用方。
|
|
314
|
+
*/
|
|
315
|
+
const revOf = function (ov) {
|
|
316
|
+
if (!ov) return ''
|
|
317
|
+
if (ov.revision != null) return String(ov.revision)
|
|
318
|
+
const s = ov.scan || {}
|
|
319
|
+
const c = ov.counts || {}
|
|
320
|
+
const pr = s.progress || {}
|
|
321
|
+
return [ov.dataDate, ov.baselineDate, s.outcome, s.trigger, s.attempt, pr.done, pr.total,
|
|
322
|
+
c.ok, c.missing, c.stale, c.login_required, c.truncated, ov.hiddenCount,
|
|
323
|
+
(ov.storage && ov.storage.cachedAt) || ''].join('|')
|
|
324
|
+
}
|
|
325
|
+
/** 内部五态 → 人话(内部口径不变;界面不直接暴露 ok/missing/truncated) */
|
|
326
|
+
const STATUS_TEXT = { ok: '已采集', missing: '没抓到', stale: '数据待核对', login_required: '需要登录', truncated: '没抓完' }
|
|
327
|
+
const statusText = function (s) { return STATUS_TEXT[s] || (s ? String(s) : '—') }
|
|
328
|
+
/**
|
|
329
|
+
* 扫描结果 → 人话(Spec E / Standards 2026-10-24)。
|
|
330
|
+
* 以前只映射 completed/cancelled/failed,而域类型里真正会出现的是
|
|
331
|
+
* running / over_budget / aborted_stalled ⇒ 概览会直接显示英文枚举。
|
|
332
|
+
* inFlight=false 的 running 是「上一轮进程没走完」留下的落盘记录,不能冒充「正在跑」。
|
|
333
|
+
*/
|
|
334
|
+
const SCAN_OUTCOME_TEXT = {
|
|
335
|
+
running: '扫描中',
|
|
336
|
+
completed: '已完成',
|
|
337
|
+
cancelled: '已取消',
|
|
338
|
+
over_budget: '超出本次预算,已停',
|
|
339
|
+
aborted_stalled: '长时间没有进展,已中止',
|
|
340
|
+
failed: '失败',
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* 轮询节奏(纯函数,便于单测):运行中 2s,空闲 20s。
|
|
344
|
+
* scanActBusy = 刚点完扫描/重试/停止、POST 还没回来的那段时间 ——
|
|
345
|
+
* 那时 overview 里仍是上一轮的 completed,若只看 scanLive 会退回 20s,
|
|
346
|
+
* 用户点完「扫描已选榜」要等很久才看到 0/N。
|
|
347
|
+
*/
|
|
348
|
+
const pollDelay = function (scanLive, scanActBusy) {
|
|
349
|
+
return (scanLive || scanActBusy) ? 2000 : 20000
|
|
350
|
+
}
|
|
351
|
+
const scanLabel = function (scan) {
|
|
352
|
+
if (!scan) return '还没扫描过'
|
|
353
|
+
let out = SCAN_OUTCOME_TEXT[scan.outcome] || String(scan.outcome || '')
|
|
354
|
+
if (scan.outcome === 'running' && scan.inFlight === false) out = '未完成(进程已退出)'
|
|
355
|
+
const by = scan.trigger === 'timer' ? '定时' : scan.trigger === 'manual' ? '手动' : String(scan.trigger || '')
|
|
356
|
+
return by ? by + ' · ' + out : out
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* 按日期回看的能力**按榜声明**(能力驱动入口,而不是先给按钮再说「会被拒绝」)。
|
|
360
|
+
* 目前只有起点图首订榜能核对内容日期(宿主用适配器的 contentDateFor 判定)。
|
|
361
|
+
*/
|
|
362
|
+
const DAY_QUERY_BOARDS = { 'qidiantu.shouding': 'n-1' }
|
|
363
|
+
const canDayQuery = function (boardId) { return !!DAY_QUERY_BOARDS[String(boardId || '')] }
|
|
364
|
+
/** Esc 层级栈:后开的层先关(菜单 → 详情 → 面板);编辑中不关面板 */
|
|
365
|
+
const escLayers = (window.__rankScanEscLayers = window.__rankScanEscLayers || [])
|
|
366
|
+
const isEditableTarget = function (t) {
|
|
367
|
+
if (!t) return false
|
|
368
|
+
const tag = String(t.tagName || '').toLowerCase()
|
|
369
|
+
return tag === 'input' || tag === 'textarea' || tag === 'select' || t.isContentEditable === true
|
|
370
|
+
}
|
|
371
|
+
const installEsc = function () {
|
|
372
|
+
if (typeof document === 'undefined' || !document.addEventListener || window.__rankScanEscHooked) return
|
|
373
|
+
window.__rankScanEscHooked = true
|
|
374
|
+
document.addEventListener('keydown', function (e) {
|
|
375
|
+
if (!e || e.key !== 'Escape') return
|
|
376
|
+
// 编辑中:Esc 只退出编辑焦点(草稿留着),不关菜单/详情/面板
|
|
377
|
+
if (isEditableTarget(document.activeElement)) { try { document.activeElement.blur() } catch (err) {} return }
|
|
378
|
+
for (let i = escLayers.length - 1; i >= 0; i--) {
|
|
379
|
+
try { if (escLayers[i].close()) return } catch (err) {}
|
|
380
|
+
}
|
|
381
|
+
}, true)
|
|
382
|
+
}
|
|
383
|
+
/** 把「关掉我这一层」挂进栈;close() 返回 true = 已处理(不再往外层传) */
|
|
384
|
+
const useEscLayer = function (close) {
|
|
385
|
+
React.useEffect(function () {
|
|
386
|
+
if (typeof close !== 'function') return undefined
|
|
387
|
+
installEsc()
|
|
388
|
+
const layer = { close: close }
|
|
389
|
+
escLayers.push(layer)
|
|
390
|
+
return function () { const i = escLayers.indexOf(layer); if (i >= 0) escLayers.splice(i, 1) }
|
|
391
|
+
}, [close])
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* 「更多」菜单:低频操作(扫描本榜/条数/补全/历史/导出/回收站…)都收进来。
|
|
395
|
+
* items: {label,onClick,disabled,title} | {sep:true} | {rows:节点}
|
|
396
|
+
*/
|
|
397
|
+
function PopMenu(props) {
|
|
398
|
+
const [open, setOpen] = React.useState(false)
|
|
399
|
+
const [pos, setPos] = React.useState(null)
|
|
400
|
+
const wrapRef = React.useRef(null)
|
|
401
|
+
const btnRef = React.useRef(null)
|
|
402
|
+
const menuRef = React.useRef(null)
|
|
403
|
+
const close = React.useCallback(function () {
|
|
404
|
+
setOpen(false)
|
|
405
|
+
const b = btnRef.current
|
|
406
|
+
if (b && typeof b.focus === 'function') { try { b.focus() } catch (e) {} }
|
|
407
|
+
}, [])
|
|
408
|
+
/**
|
|
409
|
+
* ★ 2026-10-23(菜单超出面板 / 屏幕外,使用者:「当前面板显示不了这个更多,画面超出界面了」):
|
|
410
|
+
* 旧写法是 position:absolute + right:0,锚在按钮那一小块 span 上 ——
|
|
411
|
+
* ① 书签卡里的「更多」在**左边**,right:0 让菜单整体往左溢出面板,被浮窗的 overflow:hidden 裁掉(只剩一条);
|
|
412
|
+
* ② 往下开时菜单一旦超过面板底边也直接被裁,面板小一点就什么都点不到。
|
|
413
|
+
* 改成**相对视口**定位:按按钮实际位置量一遍,下方放不下翻到上方,左右夹在视口里,
|
|
414
|
+
* 高度放不下就在菜单内滚动。浮窗上没有 transform/filter ⇒ fixed 子元素不会被它的 overflow 裁。
|
|
415
|
+
*/
|
|
416
|
+
const place = React.useCallback(function () {
|
|
417
|
+
const btn = btnRef.current
|
|
418
|
+
const el = menuRef.current
|
|
419
|
+
if (!btn || !el) return
|
|
420
|
+
const vw = Math.max(280, Number(window.innerWidth) || 1200)
|
|
421
|
+
const vh = Math.max(200, Number(window.innerHeight) || 800)
|
|
422
|
+
const M = 6
|
|
423
|
+
const b = btn.getBoundingClientRect()
|
|
424
|
+
const mw = el.offsetWidth
|
|
425
|
+
const mh = el.offsetHeight
|
|
426
|
+
let left = b.left
|
|
427
|
+
if (left + mw > vw - M) left = vw - M - mw
|
|
428
|
+
if (left < M) left = M
|
|
429
|
+
let top = b.bottom + 4
|
|
430
|
+
if (top + mh > vh - M) {
|
|
431
|
+
const up = b.top - 4 - mh
|
|
432
|
+
top = up >= M ? up : Math.max(M, vh - M - mh)
|
|
433
|
+
}
|
|
434
|
+
setPos({ left: Math.round(left), top: Math.round(top), maxH: Math.max(120, vh - 2 * M) })
|
|
435
|
+
}, [])
|
|
436
|
+
React.useLayoutEffect(function () {
|
|
437
|
+
if (!open) { setPos(null); return undefined }
|
|
438
|
+
place()
|
|
439
|
+
// 面板滚动 / 窗口缩放:菜单跟着按钮重新定位(别悬在一个已经滚走的位置上)
|
|
440
|
+
const onMove = function () { place() }
|
|
441
|
+
if (typeof window !== 'undefined' && window.addEventListener) window.addEventListener('resize', onMove)
|
|
442
|
+
if (typeof document !== 'undefined' && document.addEventListener) document.addEventListener('scroll', onMove, true)
|
|
443
|
+
return function () {
|
|
444
|
+
if (typeof window !== 'undefined' && window.removeEventListener) window.removeEventListener('resize', onMove)
|
|
445
|
+
if (typeof document !== 'undefined' && document.removeEventListener) document.removeEventListener('scroll', onMove, true)
|
|
446
|
+
}
|
|
447
|
+
}, [open, place])
|
|
448
|
+
useEscLayer(open ? function () { close(); return true } : null)
|
|
449
|
+
React.useEffect(function () {
|
|
450
|
+
if (!open) return undefined
|
|
451
|
+
const onDoc = function (e) {
|
|
452
|
+
const w = wrapRef.current
|
|
453
|
+
if (w && e && e.target && typeof w.contains === 'function' && w.contains(e.target)) return
|
|
454
|
+
setOpen(false)
|
|
455
|
+
}
|
|
456
|
+
if (typeof document !== 'undefined' && document.addEventListener) document.addEventListener('mousedown', onDoc, true)
|
|
457
|
+
return function () { if (typeof document !== 'undefined' && document.removeEventListener) document.removeEventListener('mousedown', onDoc, true) }
|
|
458
|
+
}, [open])
|
|
459
|
+
React.useEffect(function () {
|
|
460
|
+
if (!open) return undefined
|
|
461
|
+
const w = wrapRef.current
|
|
462
|
+
const first = w && typeof w.querySelector === 'function' ? w.querySelector('[role="menuitem"]') : null
|
|
463
|
+
if (first && typeof first.focus === 'function') { try { first.focus() } catch (e) {} }
|
|
464
|
+
return undefined
|
|
465
|
+
}, [open])
|
|
466
|
+
const onKey = function (e) {
|
|
467
|
+
if (!open || !e) return
|
|
468
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
|
|
469
|
+
const w = wrapRef.current
|
|
470
|
+
const nodes = w && typeof w.querySelectorAll === 'function' ? Array.prototype.slice.call(w.querySelectorAll('[role="menuitem"]')) : []
|
|
471
|
+
if (!nodes.length) return
|
|
472
|
+
const at = nodes.indexOf(document.activeElement)
|
|
473
|
+
const next = e.key === 'ArrowDown' ? (at + 1) % nodes.length : (at <= 0 ? nodes.length - 1 : at - 1)
|
|
474
|
+
if (nodes[next] && typeof nodes[next].focus === 'function') nodes[next].focus()
|
|
475
|
+
e.preventDefault()
|
|
476
|
+
}
|
|
477
|
+
const items = props.items || []
|
|
478
|
+
return h('span', { ref: wrapRef, style: { position: 'relative', display: 'inline-block' }, onKeyDown: onKey },
|
|
479
|
+
h('button', {
|
|
480
|
+
ref: btnRef,
|
|
481
|
+
style: open ? C.btnOn : C.btn,
|
|
482
|
+
title: props.title || '',
|
|
483
|
+
'aria-haspopup': 'menu',
|
|
484
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
485
|
+
onClick: function () { setOpen(!open) },
|
|
486
|
+
}, (props.label || '更多') + (open ? ' ▴' : ' ▾')),
|
|
487
|
+
open ? h('div', {
|
|
488
|
+
ref: menuRef,
|
|
489
|
+
role: 'menu',
|
|
490
|
+
style: { position: 'fixed', zIndex: 90, left: (pos ? pos.left : 0) + 'px', top: (pos ? pos.top : 0) + 'px',
|
|
491
|
+
// 先量后放:没量到之前先占位不可见,避免闪一下再跳位置
|
|
492
|
+
visibility: pos ? 'visible' : 'hidden',
|
|
493
|
+
minWidth: (props.width || 230) + 'px', maxWidth: 'min(420px, calc(100vw - 12px))',
|
|
494
|
+
maxHeight: (pos ? pos.maxH : 420) + 'px', overflowY: 'auto', overflowX: 'hidden',
|
|
495
|
+
padding: '5px', borderRadius: '8px', border: '1px solid rgba(128,128,128,.35)', background: 'var(--dsh-surface, #fff)',
|
|
496
|
+
boxShadow: '0 8px 20px rgba(0,0,0,.18)', display: 'flex', flexDirection: 'column', gap: '4px' },
|
|
497
|
+
}, items.map(function (it, i) {
|
|
498
|
+
if (!it) return null
|
|
499
|
+
if (it && it.sep) return h('div', { key: 's' + i, style: { height: '1px', background: 'rgba(128,128,128,.25)', margin: '3px 0' } })
|
|
500
|
+
if (it && it.rows) return h('div', { key: 'r' + i, style: { padding: '2px 2px 4px' } }, it.rows)
|
|
501
|
+
return h('button', {
|
|
502
|
+
key: 'i' + i,
|
|
503
|
+
role: 'menuitem',
|
|
504
|
+
disabled: !!it.disabled,
|
|
505
|
+
title: it.title || '',
|
|
506
|
+
style: { ...C.btn, textAlign: 'left', border: '1px solid transparent', opacity: it.disabled ? 0.45 : 1 },
|
|
507
|
+
onClick: function () { if (it.disabled) return; close(); if (it.onClick) it.onClick() },
|
|
508
|
+
}, it.label)
|
|
509
|
+
})) : null)
|
|
510
|
+
}
|
|
511
|
+
/** 设置页的分组块(默认展开第一组;其余收起,需要时再展开) */
|
|
512
|
+
function Section(props) {
|
|
513
|
+
const st = React.useState(props.defaultOpen !== false)
|
|
514
|
+
const open = st[0]
|
|
515
|
+
const setOpen = st[1]
|
|
516
|
+
return h('div', { style: { margin: '8px 0', padding: '6px 8px', border: '1px solid rgba(128,128,128,.28)', borderRadius: '8px', background: 'rgba(128,128,128,.04)' } },
|
|
517
|
+
h('button', {
|
|
518
|
+
style: { ...C.btn, border: 'none', background: 'transparent', padding: '0', fontWeight: 600, fontSize: '12.5px', width: '100%', textAlign: 'left' },
|
|
519
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
520
|
+
onClick: function () { setOpen(!open) },
|
|
521
|
+
}, (open ? '▾ ' : '▸ ') + (props.title || '')),
|
|
522
|
+
open ? h('div', { style: { marginTop: '4px' } }, props.children)
|
|
523
|
+
: (props.summary ? h('div', { style: { ...C.muted, marginTop: '2px' } }, props.summary) : null))
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* ★ 2026-10-23(使用者:「要拉到很大才显示全」):
|
|
527
|
+
* 以前是**固定阈值删列**:<720px 一口气把作者/分类/字数/收藏…全删掉(只剩名次/书名/主指标,
|
|
528
|
+
* 中间一大片空白),≥720px 又把**全部**列铺开 —— 首订榜 10 列、三江 15 列,得拉到 1000px 以上
|
|
529
|
+
* 才装得下,中间宽度只能横向滚动。
|
|
530
|
+
* 现在**按可用宽度装列**:先估算每列要占多少,超了就从「最不重要」的那列开始一列一列丢,
|
|
531
|
+
* 列序不变;名次 / 变化 / 书名 / 该榜主指标**永不丢**。宽度再小(<560)才整体换成卡片行。
|
|
532
|
+
*/
|
|
533
|
+
const COL_PRIO = {
|
|
534
|
+
value: 1, read: 1, collectBase: 1, periodTotal: 1, dailyDelta: 1,
|
|
535
|
+
collect: 2, ratio: 2, words: 2, readDelta: 2, buyNumRaw: 2,
|
|
536
|
+
days: 3, author: 4, fans: 4,
|
|
537
|
+
cat: 5, score: 5,
|
|
538
|
+
subCat: 6, settledDays: 6,
|
|
539
|
+
updated: 7,
|
|
540
|
+
}
|
|
541
|
+
/** 优先级数字越大越先被丢;7 天增量的 daily0..6 排最后 */
|
|
542
|
+
const colPrio = function (c) {
|
|
543
|
+
const k = String((c && c.key) || '')
|
|
544
|
+
if (/^daily\d+$/.test(k)) return 8
|
|
545
|
+
return COL_PRIO[k] != null ? COL_PRIO[k] : 3
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* 列宽估算:**刻意估宽一点**(实测浏览器给数字列的宽度比字面宽)。
|
|
549
|
+
* 估窄了的后果是真的横向滚动 / 书名被挤成两行,比早收一列难看得多。
|
|
550
|
+
*/
|
|
551
|
+
const colEst = function (c) {
|
|
552
|
+
const k = String((c && c.key) || '')
|
|
553
|
+
if (k === 'title') return 200
|
|
554
|
+
if (k === 'updated') return 124
|
|
555
|
+
if (k === 'rank') return 36
|
|
556
|
+
if (k === 'delta') return 50
|
|
557
|
+
if (/^daily\d+$/.test(k)) return 46
|
|
558
|
+
const label = String((c && c.label) || '')
|
|
559
|
+
return Math.max(64, label.length * 12 + 34)
|
|
560
|
+
}
|
|
561
|
+
const mustCol = function (c) {
|
|
562
|
+
const k = String((c && c.key) || '')
|
|
563
|
+
return k === 'title' || k === 'rank' || k === 'delta' || colPrio(c) === 1
|
|
564
|
+
}
|
|
565
|
+
/** 把列装进 width:永不丢 must 列;同优先级从后往前丢 */
|
|
566
|
+
const fitColumns = function (columns, width) {
|
|
567
|
+
const list = (columns || []).slice()
|
|
568
|
+
if (!list.length) return list
|
|
569
|
+
const budget = Math.max(320, Number(width) || 320)
|
|
570
|
+
let sum = list.reduce(function (acc, c) { return acc + colEst(c) }, 0)
|
|
571
|
+
for (let guard = 0; sum > budget && guard < 80; guard++) {
|
|
572
|
+
let at = -1
|
|
573
|
+
let worst = -1
|
|
574
|
+
for (let i = 0; i < list.length; i++) {
|
|
575
|
+
if (mustCol(list[i])) continue
|
|
576
|
+
const pr = colPrio(list[i])
|
|
577
|
+
if (pr >= worst) { worst = pr; at = i }
|
|
578
|
+
}
|
|
579
|
+
if (at < 0) break
|
|
580
|
+
sum -= colEst(list[at])
|
|
581
|
+
list.splice(at, 1)
|
|
582
|
+
}
|
|
583
|
+
return list
|
|
584
|
+
}
|
|
167
585
|
function useRect() {
|
|
168
586
|
const st = React.useState(() => {
|
|
169
587
|
let raw = null
|
|
@@ -384,7 +802,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
384
802
|
const beginDrag = useWindowDrag()
|
|
385
803
|
const start = (e) => {
|
|
386
804
|
if (e.button !== undefined && e.button !== 0) return
|
|
387
|
-
|
|
805
|
+
// 标题栏只承担拖动:按钮/输入框/链接上的按下不拖窗(否则点输入框会把窗拖走)
|
|
806
|
+
if (e.target && e.target.closest && e.target.closest('button, input, select, textarea, a')) return
|
|
388
807
|
const r0 = props.rect
|
|
389
808
|
const sx = e.clientX
|
|
390
809
|
const sy = e.clientY
|
|
@@ -396,7 +815,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
396
815
|
return h('div', { style: C.titlebar, onMouseDown: start },
|
|
397
816
|
h('span', { style: C.title }, '扫榜面板'),
|
|
398
817
|
h('span', { style: { flex: 1 } }),
|
|
399
|
-
h('button', { style: C.btn, onClick: props.onCollapse }, '收起'))
|
|
818
|
+
h('button', { style: C.btn, onClick: props.onCollapse, title: '收起面板(Esc 也可以)' }, '收起'))
|
|
400
819
|
}
|
|
401
820
|
|
|
402
821
|
function ResizeHandle(props) {
|
|
@@ -445,50 +864,63 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
445
864
|
return (i === 0 ? String(Math.round(v)) : v.toFixed(1)) + ' ' + u[i]
|
|
446
865
|
}
|
|
447
866
|
|
|
448
|
-
/**
|
|
867
|
+
/**
|
|
868
|
+
* 概览:先回答「今天有什么需要看」——
|
|
869
|
+
* ① 需要处理(**仅有问题时出现**:榜名 + 影响 + 可执行动作)
|
|
870
|
+
* ② 今天的变化(可按分组筛:新入榜/回榜/上升/下降/退榜)
|
|
871
|
+
* ③ 全部榜单(可折叠;逐榜状态 + 涨/新/退;同站抓取时刻一致时只写一次)
|
|
872
|
+
* ★ 2026-10-22(简明性 B):存储/保留/诊断移到「设置」页 —— 采集管理不再占首屏。
|
|
873
|
+
*/
|
|
449
874
|
function Overview(props) {
|
|
450
875
|
const ov = props.ov
|
|
451
876
|
/**
|
|
452
|
-
* ★ 2026-10-
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* ★ 2026-10-17(发布前修):以前只留 enrichRun ⇒ 顶部横幅分不清「还能续跑」和「当日已试满」,
|
|
458
|
-
* 也拿不到当前请求间隔。现在整份 /enrich-status 都留着(retryable / requestIntervalMs)。
|
|
877
|
+
* ★ 2026-10-23(窄面板版式):概览两张表以前一律四列铺开 —— 420px 时「分组/榜/书名/变化」
|
|
878
|
+
* 互相挤成一条,备注列更会被压成一字一行。这里按面板宽度决定:
|
|
879
|
+
* 变化列表 <620 换成卡片行(分组 chip + 书名 + 变化,榜名放第二行);
|
|
880
|
+
* 全部榜单 <620 不显示备注列,备注改到榜名下面一行。
|
|
459
881
|
*/
|
|
882
|
+
const avail = Math.max(320, Number(props.width) || (props.narrow ? 420 : 900))
|
|
883
|
+
const chgNarrow = avail < 620
|
|
460
884
|
const enrichS = React.useState(null)
|
|
461
885
|
const enrichStatus = enrichS[0]
|
|
462
886
|
const enrichRun = enrichStatus && enrichStatus.enrichRun ? enrichStatus.enrichRun : null
|
|
463
887
|
const setEnrichStatus = enrichS[1]
|
|
464
888
|
const chgS = React.useState(null)
|
|
889
|
+
const chg = chgS[0]
|
|
465
890
|
const setChg = chgS[1]
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
891
|
+
const filtS = React.useState('')
|
|
892
|
+
const chgFilter = filtS[0]
|
|
893
|
+
const setChgFilter = filtS[1]
|
|
894
|
+
const allS = React.useState(true)
|
|
895
|
+
const showAll = allS[0]
|
|
896
|
+
const setShowAll = allS[1]
|
|
897
|
+
const rev = props.rev || revOf(ov)
|
|
898
|
+
/**
|
|
899
|
+
* ★ 2026-10-22(同日刷新):依赖**修订号**而不是 dataDate。
|
|
900
|
+
* 以前同一天再扫一次(或点「扫描已选榜」)时,上面计数会变、下面「今天的变化」还是旧列表。
|
|
901
|
+
*/
|
|
902
|
+
React.useEffect(function () {
|
|
903
|
+
if (!ov || !ov.dataDate) return undefined
|
|
904
|
+
let alive = true
|
|
905
|
+
jget('/changes').then(function (r) { if (alive) setChg(r) }).catch(function () { if (alive) setChg(null) })
|
|
906
|
+
return function () { alive = false }
|
|
907
|
+
}, [rev])
|
|
474
908
|
// 补全进行中:5 秒一次盯进度;跑完后自动刷新一次,让补上的字段出现
|
|
475
909
|
React.useEffect(function () {
|
|
476
910
|
let alive = true
|
|
477
911
|
let id = null
|
|
478
912
|
let wasActive = false
|
|
479
913
|
const tick = function () {
|
|
480
|
-
//
|
|
914
|
+
// 页面不可见时不轮询(概览页开着一天会白打上万次请求)
|
|
481
915
|
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
|
|
482
916
|
jget('/enrich-status').then(function (r) {
|
|
483
917
|
if (!alive) return
|
|
484
918
|
const er = (r && r.enrichRun) || null
|
|
485
919
|
setEnrichStatus(r || null)
|
|
486
920
|
noteRequestInterval(r && r.requestIntervalMs)
|
|
487
|
-
// ★ 审查(非阻塞 5):active 由宿体现算;重启后旧记录可能没有这个字段 ⇒ 只认真的工人标志
|
|
488
921
|
const active = !!(er && er.active === true)
|
|
489
922
|
if (wasActive && !active) props.reload()
|
|
490
923
|
wasActive = active
|
|
491
|
-
// 没工人、也没待办 ⇒ 没有可看的变化,停轮询(下次扫描会重新挂载)
|
|
492
924
|
if (!active && !(r && r.pending > 0)) { alive = false; if (id) clearInterval(id) }
|
|
493
925
|
}).catch(function () { /* 读不到进度不影响面板 */ })
|
|
494
926
|
}
|
|
@@ -499,175 +931,310 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
499
931
|
if (!ov) return h('div', { style: C.muted }, '加载中…')
|
|
500
932
|
const c = ov.counts || {}
|
|
501
933
|
const total = (c.ok || 0) + (c.missing || 0) + (c.stale || 0) + (c.login_required || 0) + (c.truncated || 0)
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
const badRows = rows.filter((b) => b.status !== 'ok')
|
|
934
|
+
const rows = (ov.sites || []).flatMap(function (s) { return (s.boards || []).map(function (b) { return { ...b, siteName: s.siteName } }) })
|
|
935
|
+
|
|
505
936
|
const scan = ov.scan || null
|
|
937
|
+
const plan = (ov.services && ov.services.schedule) || null
|
|
938
|
+
const staleIds = plan && plan.staleFlag
|
|
939
|
+
? Object.keys(plan.staleFlag).filter(function (k) { return plan.staleFlag[k] && plan.staleFlag[k].date === ov.dataDate })
|
|
940
|
+
: []
|
|
941
|
+
/**
|
|
942
|
+
* ★ Spec S3(2026-10-22):「未到计划」和「待补跑」不是失败。
|
|
943
|
+
* 按站分时抓取(起点 01:30 / 番茄 08:30 / 菠萝包 09:30 / 刺猬猫 10:40 / 起点图 12:40)⇒
|
|
944
|
+
* 每天中午之前打开概览,没到点的站本来就该是空的。旧实现把它们算成 missing,于是出现
|
|
945
|
+
* 「已采集 0/20 · 待处理 18 项 · 重试失败 18 个榜」的假警报(Spec S3 / 方案 3.3)。
|
|
946
|
+
* 口径:后端逐榜给 scheduleState=waiting|due(含 plannedTime)就用它;
|
|
947
|
+
* 没给(旧宿主/旧数据)就退回 timer-plan 的站级 waiting/due 队列;两者都没有才当失败。
|
|
948
|
+
*/
|
|
949
|
+
const siteOfBoardId = function (id) { return String(id || '').split('.')[0] }
|
|
950
|
+
const scheduleStateOf = function (b) {
|
|
951
|
+
if (b.scheduleState === 'waiting' || b.scheduleState === 'due') return b.scheduleState
|
|
952
|
+
if (b.scheduleState === null) return null
|
|
953
|
+
if (b.status === 'ok') return null
|
|
954
|
+
const site = siteOfBoardId(b.boardId)
|
|
955
|
+
if (((plan && plan.due) || []).indexOf(site) >= 0) return 'due'
|
|
956
|
+
if (((plan && plan.waiting) || []).indexOf(site) >= 0) return 'waiting'
|
|
957
|
+
return null
|
|
958
|
+
}
|
|
959
|
+
const plannedTimeOf = function (b) {
|
|
960
|
+
if (b.plannedTime) return String(b.plannedTime)
|
|
961
|
+
const times = (plan && plan.siteTimes) || (ov.defaults && ov.defaults.siteTimes) || {}
|
|
962
|
+
return times[siteOfBoardId(b.boardId)] || ''
|
|
963
|
+
}
|
|
964
|
+
const waitingRows = rows.filter(function (b) { return scheduleStateOf(b) === 'waiting' })
|
|
965
|
+
const dueRows = rows.filter(function (b) { return scheduleStateOf(b) === 'due' })
|
|
966
|
+
// 「失败/待修」= 既不是 ok,也不是「还没到点」「等到兜底补跑」
|
|
967
|
+
const badRows = rows.filter(function (b) { return b.status !== 'ok' && !scheduleStateOf(b) })
|
|
968
|
+
rememberBoardNames(rows)
|
|
969
|
+
const enrichPending = enrichStatus && typeof enrichStatus.pending === 'number' ? enrichStatus.pending : 0
|
|
970
|
+
/** 「需要处理」= 状态异常 + 内容待核对 + 字段待补(**没有问题就整块不出现**) */
|
|
971
|
+
const issues = []
|
|
972
|
+
badRows.forEach(function (b) {
|
|
973
|
+
const why = b.status === 'missing' ? '这次没抓到(当天没有快照)'
|
|
974
|
+
: b.status === 'login_required' ? '起点 cookie 失效:导出 cookie 后上传即可恢复'
|
|
975
|
+
: b.status === 'truncated' ? '没抓完(预算用尽或被取消)'
|
|
976
|
+
: b.status === 'stale' ? '抓到的内容不可信(疑似未刷新或换榜)' : '状态异常'
|
|
977
|
+
issues.push({
|
|
978
|
+
key: 'b-' + b.boardId,
|
|
979
|
+
name: b.siteName + ' · ' + b.name,
|
|
980
|
+
why: why,
|
|
981
|
+
detail: b.note || '',
|
|
982
|
+
status: b.status,
|
|
983
|
+
boardId: b.boardId,
|
|
984
|
+
// Spec S5:问题要带**发生时间**(day-index 的 lastAttempt.at 早已具备),否则看不出是哪次尝试失败的
|
|
985
|
+
at: (b.attempt && b.attempt.at) || b.lastCapture || null,
|
|
986
|
+
})
|
|
987
|
+
})
|
|
988
|
+
staleIds.forEach(function (id) {
|
|
989
|
+
if (badRows.some(function (b) { return b.boardId === id })) return
|
|
990
|
+
const b = rows.filter(function (x) { return x.boardId === id })[0] || { name: id, siteName: '' }
|
|
991
|
+
issues.push({ key: 's-' + id, name: (b.siteName ? b.siteName + ' · ' : '') + b.name, why: '与上一数据日整榜一致:站点可能还没换榜(内容待核对)', detail: '', status: 'stale', boardId: id, at: b.lastCapture || null })
|
|
992
|
+
})
|
|
993
|
+
if (enrichPending > 0) {
|
|
994
|
+
issues.push({ key: 'enrich', name: '字段补全', why: enrichPending + ' 个榜还缺字段(进榜页点「补全缺失字段」,或等定时续跑)', detail: '', status: 'enrich', boardId: null, at: null })
|
|
995
|
+
}
|
|
996
|
+
const hasNoteCol = rows.some(function (b) { return !!b.note })
|
|
997
|
+
/**
|
|
998
|
+
* 今天的变化:按**站**分组展示(Spec S6),行可点进榜保上下文。
|
|
999
|
+
* ★ 条数必须用后端给的真实总数:diffFor 每类只回前 20 条预览,
|
|
1000
|
+
* 旧实现拿「预览条数」当「总条数」,首订换批那天会写成「今天的变化(20 条)」而实际 100+。
|
|
1001
|
+
*/
|
|
1002
|
+
const chgEntries = []
|
|
1003
|
+
const chgTotals = {}
|
|
1004
|
+
let chgSum = 0
|
|
1005
|
+
if (chg && chg.sites) {
|
|
1006
|
+
chg.sites.forEach(function (s) {
|
|
1007
|
+
(s.groups || []).forEach(function (g) {
|
|
1008
|
+
const items = g.items || []
|
|
1009
|
+
const n = typeof g.count === 'number' ? g.count : items.length
|
|
1010
|
+
chgTotals[g.group] = (chgTotals[g.group] || 0) + n
|
|
1011
|
+
chgSum += n
|
|
1012
|
+
items.forEach(function (it) { chgEntries.push({ site: s.site, siteName: s.siteName, group: g.group, it: it }) })
|
|
1013
|
+
})
|
|
1014
|
+
})
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* ★ Spec E(2026-10-24 审查):运行中主按钮要变成「进度 + 取消」。
|
|
1018
|
+
* done/total 只在宿主确实写了 running 记录时才有;没数字就老实说「扫描中…」,
|
|
1019
|
+
* 不编百分比。扫描进度只在这一处出现,补全进度仍走它自己那条横幅,两块不混。
|
|
1020
|
+
*/
|
|
1021
|
+
const scanProg = (scan && scan.progress) || {}
|
|
1022
|
+
const scanTotal = typeof scanProg.total === 'number' ? scanProg.total : 0
|
|
1023
|
+
const scanDoneN = typeof scanProg.done === 'number' ? scanProg.done : 0
|
|
1024
|
+
/**
|
|
1025
|
+
* Spec E:运行态以**宿主记录**为准 —— 定时扫描不是本面板发起的,props.busy 永远是 false,
|
|
1026
|
+
* 旧实现因此在定时跑的时候仍显示「扫描已选榜」且没有取消入口。
|
|
1027
|
+
* inFlight === false 的 running 是上次进程退出留下的落盘记录,不算在跑。
|
|
1028
|
+
* props.busy 仍单独表示「本面板的请求还在路上」(保存/补全/取消),两者不互相冒充。
|
|
1029
|
+
*/
|
|
1030
|
+
const scanRunning = !!(scan && scan.outcome === 'running' && scan.inFlight !== false)
|
|
1031
|
+
const scanHasProg = scanRunning && scanTotal > 0
|
|
1032
|
+
const scanBusy = scanRunning || !!props.busy
|
|
1033
|
+
const scanBtnText = scanHasProg
|
|
1034
|
+
? '扫描中 ' + Math.min(scanDoneN, scanTotal) + '/' + scanTotal
|
|
1035
|
+
: scanRunning || props.scanStarting ? '扫描中…' : props.busy ? '处理中…' : '扫描已选榜'
|
|
1036
|
+
const groupNames = []
|
|
1037
|
+
chgEntries.forEach(function (e) { if (groupNames.indexOf(e.group) < 0) groupNames.push(e.group) })
|
|
1038
|
+
const groupCount = function (g) { return chgTotals[g] || 0 }
|
|
1039
|
+
const shownEntries = chgFilter ? chgEntries.filter(function (e) { return e.group === chgFilter }) : chgEntries
|
|
1040
|
+
const chgRealTotal = typeof (chg && chg.count) === 'number' && chg.count > chgSum ? chg.count : chgSum
|
|
1041
|
+
const previewLimited = chgRealTotal > chgEntries.length
|
|
1042
|
+
/** 首订榜每天整批换新(上架作品),叫「新入榜」会被读成榜单竞争意义的新入榜(Spec S7) */
|
|
1043
|
+
const changesGroupLabel = function (group, boardId) {
|
|
1044
|
+
return String(boardId || '').indexOf('qidiantu.shouding') === 0 && group === '新入榜' ? '本批上架' : group
|
|
1045
|
+
}
|
|
1046
|
+
/** 按站分组:同站的变化连在一起,行上不必再重复站名 */
|
|
1047
|
+
const shownBySite = []
|
|
1048
|
+
shownEntries.forEach(function (e) {
|
|
1049
|
+
const last = shownBySite[shownBySite.length - 1]
|
|
1050
|
+
if (last && last.site === e.site) last.items.push(e)
|
|
1051
|
+
else shownBySite.push({ site: e.site, siteName: e.siteName, items: [e] })
|
|
1052
|
+
})
|
|
506
1053
|
return h('div', null,
|
|
507
|
-
|
|
1054
|
+
/* ① 摘要带:日期 + 采集/待处理(文字,不靠颜色) */
|
|
508
1055
|
h('div', { style: C.row },
|
|
509
|
-
h('span',
|
|
510
|
-
h('span', { style: C.muted }, '·'),
|
|
511
|
-
h('span', null, '基期 ' + dash(ov.baselineDate)),
|
|
1056
|
+
h('span', { title: '扫描开始时刻的本地自然日', style: { fontWeight: 600 } }, '数据日期 ' + dash(ov.dataDate)),
|
|
512
1057
|
h('span', { style: C.muted }, '·'),
|
|
513
|
-
h('span', null,
|
|
514
|
-
h('span',
|
|
515
|
-
h('span', { style:
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const active = !!enrichRun.active
|
|
521
|
-
const total = enrichRun.total || 0
|
|
522
|
-
const done = enrichRun.done || 0
|
|
523
|
-
const left = Math.max(0, total - done)
|
|
524
|
-
/**
|
|
525
|
-
* ★ 2026-10-17(发布前修):能不能再续跑,看的是宿主现算的「tried < 每榜每日上限」的待办数,
|
|
526
|
-
* 不是上一轮记录的 total - done —— 否则「当日已试满、今天不再跑」的榜会永远显示
|
|
527
|
-
* 「等下一次续跑」(实测就是这样挂着不走)。
|
|
528
|
-
*/
|
|
529
|
-
const retryable = enrichStatus && typeof enrichStatus.retryable === 'number' ? enrichStatus.retryable : left
|
|
530
|
-
if (!active && retryable <= 0 && left <= 0) return null
|
|
531
|
-
const cadence = fmtIntervalText(enrichStatus && enrichStatus.requestIntervalMs)
|
|
532
|
-
const label = active
|
|
533
|
-
? '补全中 ' + done + '/' + total + ' 个榜(' + cadence + ',抓榜数据已可用)'
|
|
534
|
-
: retryable > 0
|
|
535
|
-
? '补全待续跑:还剩 ' + retryable + ' 个榜(' + cadence + ')'
|
|
536
|
-
: '补全已尽力:' + left + ' 个榜当日试满(明天自动再续;也可点「补全本榜」手动再试)'
|
|
537
|
-
const mark = active ? '⏳ ' : retryable > 0 ? '⏸ ' : '⏹ '
|
|
538
|
-
const bg = active ? 'rgba(33,150,243,0.10)' : retryable > 0 ? 'rgba(255,152,0,0.10)' : 'rgba(128,128,128,0.10)'
|
|
539
|
-
const bd = active ? 'rgba(33,150,243,0.40)' : retryable > 0 ? 'rgba(255,152,0,0.45)' : 'rgba(128,128,128,0.40)'
|
|
540
|
-
return h('div', {
|
|
541
|
-
style: { ...C.row, padding: '4px 7px', marginTop: '2px', borderRadius: '6px', background: bg, border: '1px solid ' + bd },
|
|
542
|
-
}, h('span', { style: { fontWeight: 600 } }, mark), h('span', null, label))
|
|
543
|
-
})(),
|
|
1058
|
+
h('span', null, '已采集 ' + (c.ok || 0) + '/' + total),
|
|
1059
|
+
waitingRows.length ? h('span', { style: C.muted, title: '这些站今天还没到自己的抓取时刻:不是失败' }, '· 未到计划 ' + waitingRows.length) : null,
|
|
1060
|
+
dueRows.length ? h('span', { style: { color: '#d9a441' }, title: '已过计划时刻但还没抓到:等兜底,或点「扫描已选榜」马上跑' }, '· 待补跑 ' + dueRows.length) : null,
|
|
1061
|
+
h('span', { style: issues.length ? { color: '#d9a441', fontWeight: 600 } : { color: '#3f9b4f' } },
|
|
1062
|
+
issues.length ? '待处理 ' + issues.length + ' 项' : '无待处理'),
|
|
1063
|
+
ov.hiddenCount ? h('span', { style: C.muted }, '· 未显示 ' + ov.hiddenCount + ' 个榜') : null),
|
|
1064
|
+
/* ② 主动作:扫描(联网)与重新载入(只读本地)分开写清 */
|
|
544
1065
|
h('div', { style: C.row },
|
|
545
|
-
h('button', {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
h('
|
|
552
|
-
h('
|
|
553
|
-
h('
|
|
554
|
-
|
|
555
|
-
h('span',
|
|
556
|
-
|
|
557
|
-
h('span', { style: C.muted }, '·'),
|
|
558
|
-
h('span', null, ov.storage.dates + ' 天(' + dash(ov.storage.oldest) + ' 起)'),
|
|
559
|
-
h('span', { style: C.muted }, '·'),
|
|
560
|
-
h('span', { style: C.muted }, '保留'),
|
|
561
|
-
h('select', {
|
|
562
|
-
style: { ...C.input, width: 'auto', padding: '1px 4px' },
|
|
563
|
-
value: String(ov.storage.retentionDays),
|
|
564
|
-
title: '只影响数据日期目录(快照/报告);state/ 里的配置、书签、书页缓存永不删',
|
|
565
|
-
onChange: function (e) {
|
|
566
|
-
const v = e.target.value === 'forever' ? 'forever' : Number(e.target.value)
|
|
567
|
-
props.post('/retention', { days: v })
|
|
568
|
-
.then(function (r) { setRetMsg(r && r.note ? r.note : '已更新'); return props.reload() })
|
|
569
|
-
.catch(function (e2) { setRetMsg('设置失败:' + e2) })
|
|
570
|
-
},
|
|
571
|
-
},
|
|
572
|
-
[30, 90, 180, 365].map(function (n) { return h('option', { key: n, value: String(n) }, n + ' 天') }),
|
|
573
|
-
h('option', { key: 'forever', value: 'forever' }, '永久保留')),
|
|
574
|
-
retMsg ? h('span', { style: { color: '#2e7d32' } }, String(retMsg).slice(0, 60)) : null,
|
|
575
|
-
h('span', { style: C.muted }, '·'),
|
|
576
|
-
h('span', null, '书签 ' + ov.storage.bookmarks + ' 条')) : null,
|
|
577
|
-
// ★ 票 26:诊断栏 —— 服务可见性 / 定时接线 / 占用缓存时间。缺能力时这里一眼能看出来,
|
|
578
|
-
// 而不是「面板打不开、什么都不知道」(配合票 21 的 README 一节)。
|
|
1066
|
+
h('button', {
|
|
1067
|
+
style: scanBusy ? C.btnOn : C.btn,
|
|
1068
|
+
disabled: scanBusy,
|
|
1069
|
+
title: '按「设置 → 抓取范围」里勾选的榜逐个扫描(会联网)',
|
|
1070
|
+
onClick: function () { props.act('/scan') },
|
|
1071
|
+
}, scanBtnText),
|
|
1072
|
+
scanBusy ? h('button', { style: C.btn, onClick: function () { props.act('/cancel') } }, '停止本次(保留已完成)') : null,
|
|
1073
|
+
badRows.length ? h('button', { style: C.btn, disabled: scanBusy, onClick: function () { props.act('/retry') } }, '重试失败 ' + badRows.length + ' 个榜') : null,
|
|
1074
|
+
h('button', { style: C.btn, onClick: props.reload, title: '只重新读取本地数据:不联网、不采集' }, '重新载入'),
|
|
1075
|
+
// 运行中不显示「上次 …」:那一轮还没结束,进度只放在主按钮一处(否则会同时出现两条「扫描中」)
|
|
1076
|
+
scanRunning ? null : h('span', { style: C.muted }, '上次 ' + scanLabel(scan))),
|
|
1077
|
+
/* 补全进度:面板顶部只有这一条(三态:跑着 / 还能续跑 / 当日已试满) */
|
|
579
1078
|
(function () {
|
|
580
|
-
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1079
|
+
if (!enrichStatus) return null
|
|
1080
|
+
const run = enrichStatus.enrichRun
|
|
1081
|
+
const active = !!(run && run.active === true)
|
|
1082
|
+
const left = typeof enrichStatus.pending === 'number' ? enrichStatus.pending : 0
|
|
1083
|
+
if (!active && !left) return null
|
|
1084
|
+
// 「还能不能续跑」用宿主的 retryable 判(0 = 当日已试满),前端不自己猜
|
|
1085
|
+
const retryable = typeof enrichStatus.retryable === 'number' ? enrichStatus.retryable : null
|
|
1086
|
+
const label = active
|
|
1087
|
+
? '补全中 ' + ((run && run.done) || 0) + '/' + ((run && run.total) || 0) + ' 个榜(可以先浏览,不用等)'
|
|
1088
|
+
: retryable === 0
|
|
1089
|
+
? '补全已尽力:还缺 ' + left + ' 个榜(当日已试满,明天自动续跑)'
|
|
1090
|
+
: '补全未完成:还缺 ' + left + ' 个榜(后台会继续补,也可进榜点「补全缺失字段」)'
|
|
1091
|
+
return h('div', { style: { margin: '4px 0', padding: '4px 7px', borderRadius: '6px', background: 'rgba(255,152,0,0.12)', border: '1px solid rgba(255,152,0,0.45)' } }, label)
|
|
593
1092
|
})(),
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
h('
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
h('
|
|
604
|
-
h('
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
1093
|
+
/* ③ 需要处理:仅有问题时出现 */
|
|
1094
|
+
issues.length ? h('div', { style: { margin: '6px 0', padding: '6px 8px', borderRadius: '8px', border: '1px solid rgba(217,164,65,.55)', background: 'rgba(217,164,65,.10)' } },
|
|
1095
|
+
h('div', { style: { fontWeight: 600, marginBottom: '2px' } }, '需要处理'),
|
|
1096
|
+
issues.map(function (it) {
|
|
1097
|
+
/**
|
|
1098
|
+
* Spec S5:一条问题要给「榜名 + 发生时间 + 影响 + 可执行动作」。
|
|
1099
|
+
* 以前只有一个泛化「重试失败 N 个榜」,看不出是哪次尝试、也没法直接进榜看。
|
|
1100
|
+
*/
|
|
1101
|
+
return h('div', { key: it.key, style: { ...C.row, alignItems: 'baseline' } },
|
|
1102
|
+
h('span', { style: C.dot(it.status === 'stale' || it.status === 'enrich' ? 'warn' : 'bad') }),
|
|
1103
|
+
h('span', { style: { fontWeight: 600 } }, it.name),
|
|
1104
|
+
it.at ? h('span', { style: C.muted }, fmtLocalHM(it.at)) : null,
|
|
1105
|
+
h('span', null, it.why),
|
|
1106
|
+
it.detail ? h('span', { style: C.muted }, '(' + String(it.detail).slice(0, 80) + ')') : null,
|
|
1107
|
+
it.boardId ? h('button', { style: C.btn, disabled: props.busy, onClick: function () { props.onOpenBoard && props.onOpenBoard(it.boardId) }, title: '在「榜单」页打开这一榜(保上下文)' }, '查看本榜') : null,
|
|
1108
|
+
it.boardId ? h('button', { style: C.btn, disabled: props.busy, onClick: function () { props.onRescanBoard && props.onRescanBoard(it.boardId) }, title: '只重扫这一榜(会联网)' }, '重扫本榜') : null)
|
|
1109
|
+
})) : null,
|
|
1110
|
+
/* ④ 今天的变化 */
|
|
1111
|
+
h('div', { style: C.siteBar }, '今天的变化' + (chgRealTotal ? '(' + chgRealTotal + ' 条)' : '')),
|
|
1112
|
+
chg && chg.note ? h('div', { style: C.muted }, chg.note) : null,
|
|
1113
|
+
previewLimited ? h('div', { style: C.muted }, '下表每榜每类最多列 20 条(本次 ' + chgEntries.length + ' 条,共 ' + chgRealTotal + ' 条);点行到榜页看全部。') : null,
|
|
1114
|
+
chg && chg.count === 0 ? h('div', { style: C.muted }, '没有变化条目(或还没有可比基准)') : null,
|
|
1115
|
+
chgEntries.length ? h('div', { style: C.row },
|
|
1116
|
+
[{ label: '全部', value: '' }].concat(groupNames.map(function (g) { return { label: g, value: g } })).map(function (o) {
|
|
1117
|
+
return h('button', {
|
|
1118
|
+
key: 'f-' + (o.value || 'all'),
|
|
1119
|
+
style: chgFilter === o.value ? C.btnOn : C.btn,
|
|
1120
|
+
onClick: function () { setChgFilter(o.value) },
|
|
1121
|
+
}, o.label + ' ' + (o.value ? groupCount(o.value) : chgRealTotal))
|
|
1122
|
+
})) : null,
|
|
1123
|
+
/**
|
|
1124
|
+
* 变化列表:宽的时候是表格(分组 / 榜 / 书名 / 变化),窄的时候换卡片行 ——
|
|
1125
|
+
* 420px 下四列表格会把「分组/榜/书名/变化」挤成一条,书名被折成两行、星标掉到下一行。
|
|
1126
|
+
* 卡片行:第一行 分组 chip + 书名 + 星标 + 变化,第二行 榜名(次要信息,省略号)。
|
|
1127
|
+
*/
|
|
1128
|
+
shownEntries.length ? (chgNarrow
|
|
1129
|
+
? h('div', null, shownBySite.map(function (g) {
|
|
1130
|
+
return h('div', { key: 'nc-' + g.site },
|
|
1131
|
+
h('div', { style: { ...C.muted, marginTop: '6px', fontWeight: 600 } }, g.siteName + ' · ' + g.items.length + ' 条'),
|
|
1132
|
+
g.items.map(function (e, i) {
|
|
1133
|
+
return h('div', {
|
|
1134
|
+
key: 'nci-' + g.site + i,
|
|
1135
|
+
tabIndex: 0,
|
|
1136
|
+
title: '在「榜单」页打开:' + boardLabel(e.it.boardId),
|
|
1137
|
+
style: { ...C.card, padding: '4px 7px', margin: '4px 0', cursor: 'pointer' },
|
|
1138
|
+
onClick: function () { props.onOpenBoard && props.onOpenBoard(e.it.boardId) },
|
|
1139
|
+
onKeyDown: function (ev) { if (ev && (ev.key === 'Enter' || ev.key === ' ')) { ev.preventDefault(); props.onOpenBoard && props.onOpenBoard(e.it.boardId) } },
|
|
1140
|
+
},
|
|
1141
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '5px', minWidth: 0 } },
|
|
1142
|
+
h('span', { style: { ...C.chip, flex: '0 0 auto', margin: 0 } }, changesGroupLabel(e.group, e.it.boardId)),
|
|
1143
|
+
h('span', { style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: e.it.title }, e.it.title),
|
|
1144
|
+
h('span', { style: { flex: '0 0 auto' }, onClick: function (ev) { ev.stopPropagation() } },
|
|
1145
|
+
h(BookmarkStar, { bookKey: bookKeyOf(e.it.boardId, e.it.title), boardId: e.it.boardId, row: null, title: e.it.title })),
|
|
1146
|
+
h('span', { style: { ...C.num, flex: '0 0 auto' }, title: '名次变化' }, dash(e.it.delta))),
|
|
1147
|
+
h('div', { style: { ...C.muted, marginTop: '1px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, e.it.boardName))
|
|
1148
|
+
}))
|
|
1149
|
+
}))
|
|
1150
|
+
: h('table', { style: C.table },
|
|
1151
|
+
h('thead', null, h('tr', null, ['分组', '榜', '书名', '变化'].map(function (t) { return h('th', { key: t, style: C.th }, t) }))),
|
|
1152
|
+
h('tbody', null, shownBySite.flatMap(function (g) {
|
|
1153
|
+
const head = h('tr', { key: 'ch-' + g.site },
|
|
1154
|
+
h('td', { style: { ...C.td, paddingTop: '7px', fontWeight: 600, color: 'rgba(128,128,128,.95)' }, colSpan: 4 },
|
|
1155
|
+
g.siteName + ' · ' + g.items.length + ' 条'))
|
|
1156
|
+
const body = g.items.map(function (e, i) {
|
|
1157
|
+
return h('tr', {
|
|
1158
|
+
key: 'c-' + g.site + i,
|
|
1159
|
+
style: { cursor: 'pointer' },
|
|
1160
|
+
title: '在「榜单」页打开:' + boardLabel(e.it.boardId),
|
|
1161
|
+
onClick: function () { props.onOpenBoard && props.onOpenBoard(e.it.boardId) },
|
|
1162
|
+
},
|
|
1163
|
+
h('td', { style: { ...C.td, whiteSpace: 'nowrap' } }, changesGroupLabel(e.group, e.it.boardId)),
|
|
1164
|
+
h('td', { style: { ...C.td, maxWidth: '160px' } }, h('span', { style: { ...C.ellip, maxWidth: Math.max(90, Math.round(avail * 0.2)) + 'px' }, title: e.it.boardName }, e.it.boardName)),
|
|
1165
|
+
h('td', { style: { ...C.td, minWidth: '140px' } }, e.it.title, ' ',
|
|
1166
|
+
h('span', { onClick: function (ev) { ev.stopPropagation() } },
|
|
1167
|
+
h(BookmarkStar, { bookKey: bookKeyOf(e.it.boardId, e.it.title), boardId: e.it.boardId, row: null, title: e.it.title }))),
|
|
1168
|
+
h('td', { style: { ...C.td, ...C.num } }, dash(e.it.delta)))
|
|
1169
|
+
})
|
|
1170
|
+
return [head].concat(body)
|
|
1171
|
+
})))) : null,
|
|
1172
|
+
/* ⑤ 全部榜单(可折叠) */
|
|
1173
|
+
h('div', { style: { ...C.row, marginTop: '8px' } },
|
|
1174
|
+
h('button', {
|
|
1175
|
+
style: C.btn,
|
|
1176
|
+
'aria-expanded': showAll ? 'true' : 'false',
|
|
1177
|
+
onClick: function () { setShowAll(!showAll) },
|
|
1178
|
+
}, (showAll ? '▾ ' : '▸ ') + '全部榜单(' + total + ')')),
|
|
1179
|
+
showAll ? h('table', { style: C.table },
|
|
1180
|
+
h('thead', null, h('tr', null, ['榜(按站)', '涨 / 新 / 退', '状态'].concat(hasNoteCol && !chgNarrow ? ['备注'] : []).map(function (t) { return h('th', { key: t, style: C.th }, t) }))),
|
|
608
1181
|
h('tbody', null, (ov.sites || []).flatMap(function (s) {
|
|
609
1182
|
const okN = s.boards.filter(function (b) { return b.status === 'ok' }).length
|
|
1183
|
+
const times = s.boards.map(function (b) { return b.lastCapture ? fmtLocalHM(b.lastCapture) : '' })
|
|
1184
|
+
const sameTime = times.length > 0 && times.every(function (t) { return t === times[0] })
|
|
1185
|
+
const headTime = sameTime ? times[0] : ''
|
|
610
1186
|
const head = h('tr', { key: 'h-' + s.site },
|
|
611
|
-
h('td', { style: { ...C.td, paddingTop: '7px', fontWeight: 600 }, colSpan: 3 },
|
|
1187
|
+
h('td', { style: { ...C.td, paddingTop: '7px', fontWeight: 600 }, colSpan: hasNoteCol && !chgNarrow ? 4 : 3 },
|
|
612
1188
|
h('span', { style: C.dot(okN === s.boards.length ? 'ok' : 'bad') }),
|
|
613
1189
|
' ' + s.siteName,
|
|
614
|
-
h('span', { style: C.muted }, ' ' + s.boards.length + ' 个榜 ·
|
|
615
|
-
const
|
|
1190
|
+
h('span', { style: C.muted }, ' ' + s.boards.length + ' 个榜 · 已采集 ' + okN + (headTime ? ' · 抓取 ' + headTime : ''))))
|
|
1191
|
+
const rowsOut = s.boards.map(function (b) {
|
|
616
1192
|
const noBase = b.up === null && b.newCount === null && b.out === null
|
|
1193
|
+
const label = b.name + (b.derived ? ' · 本地派生' : b.displayed ? '' : ' · 未显示')
|
|
617
1194
|
return h('tr', { key: b.boardId },
|
|
618
|
-
h('td', { style: { ...C.td, paddingLeft: '16px'
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
1195
|
+
h('td', { style: { ...C.td, paddingLeft: '16px', maxWidth: Math.max(140, Math.round(avail * 0.5)) } },
|
|
1196
|
+
h('span', { style: { ...C.ellip, maxWidth: Math.max(120, Math.round(avail * 0.46)) + 'px' }, title: label }, label),
|
|
1197
|
+
// 窄面板不单开「备注」列(会被压成一字一行),备注改到榜名下面
|
|
1198
|
+
hasNoteCol && chgNarrow && b.note ? h('div', { style: { ...C.muted, whiteSpace: 'normal' } }, dash(b.note)) : null),
|
|
1199
|
+
h('td', { style: { ...C.td, ...C.num } }, noBase ? '—' : h('span', { style: { whiteSpace: 'nowrap' } },
|
|
1200
|
+
'涨 ', h('span', { style: b.up > 0 ? C.up : null }, dash(b.up)), ' / ',
|
|
1201
|
+
'新 ', h('span', { style: { fontWeight: 600 } }, dash(b.newCount)), ' / ',
|
|
1202
|
+
'退 ', h('span', { style: b.out > 0 ? C.down : null }, dash(b.out)))),
|
|
1203
|
+
h('td', { style: C.td }, b.status === 'ok'
|
|
1204
|
+
? (headTime ? h('span', { style: C.muted }, '—') : (b.lastCapture ? fmtLocalHM(b.lastCapture) : '—'))
|
|
1205
|
+
: h('span', { style: { color: b.status === 'stale' ? '#d9a441' : '#d9534f' } }, statusText(b.status))),
|
|
1206
|
+
hasNoteCol && !chgNarrow ? h('td', { style: C.td }, dash(b.note)) : null)
|
|
622
1207
|
})
|
|
623
|
-
return [head].concat(
|
|
624
|
-
})))
|
|
625
|
-
h('div', { style: C.siteBar }, '今天的变化'),
|
|
626
|
-
chgS[0] && chgS[0].note ? h('div', { style: C.muted }, chgS[0].note) : null,
|
|
627
|
-
chgS[0] && chgS[0].count === 0 ? h('div', { style: C.muted }, '没有变化条目') : null,
|
|
628
|
-
chgS[0] && chgS[0].sites ? chgS[0].sites.map(function (s) {
|
|
629
|
-
return h('div', { key: 'chg-' + s.site },
|
|
630
|
-
h('div', { style: C.siteBar }, s.siteName),
|
|
631
|
-
h('table', { style: C.table },
|
|
632
|
-
h('thead', null, h('tr', null, ['分组', '榜', '书名', '变化'].map(function (t) { return h('th', { key: t, style: C.th }, t) }))),
|
|
633
|
-
h('tbody', null, s.groups.flatMap(function (g) {
|
|
634
|
-
return g.items.map(function (it, i) {
|
|
635
|
-
return h('tr', { key: g.group + i },
|
|
636
|
-
h('td', { style: C.td }, i === 0 ? g.group : ''),
|
|
637
|
-
h('td', { style: C.td }, it.boardName),
|
|
638
|
-
h('td', { style: C.td }, it.title, ' ', h(BookmarkStar, { bookKey: bookKeyOf(it.boardId, it.title), boardId: it.boardId, row: null, title: it.title })),
|
|
639
|
-
h('td', { style: C.td }, dash(it.delta)))
|
|
640
|
-
})
|
|
641
|
-
}))))
|
|
642
|
-
}) : null)
|
|
1208
|
+
return [head].concat(rowsOut)
|
|
1209
|
+
}))) : null)
|
|
643
1210
|
}
|
|
644
1211
|
|
|
645
|
-
/**
|
|
646
|
-
|
|
1212
|
+
/**
|
|
1213
|
+
* 设置:四组 —— ① 抓取范围 ② 扫描计划 ③ 数据与性能 ④ 关于与诊断。
|
|
1214
|
+
* · 勾选改动进**草稿**:底部常驻「未保存 / 放弃改动 / 保存设置」,离开前看得见
|
|
1215
|
+
* · 扫描计划:开关即时生效(旁边写明开/关;失败回退),时刻改动走「保存计划」
|
|
1216
|
+
* · 全站补全从榜单页挪到这里(按站「更多」),榜单页只保留「补全缺失字段」
|
|
1217
|
+
*/
|
|
1218
|
+
function SettingsTab(props) {
|
|
1219
|
+
const ov = props.ov
|
|
647
1220
|
const [cat, setCat] = React.useState(null)
|
|
648
1221
|
const [picked, setPicked] = React.useState(null)
|
|
649
1222
|
const [note, setNote] = React.useState(null)
|
|
650
1223
|
const [busy, setBusy] = React.useState(false)
|
|
651
1224
|
const [dirty, setDirty] = React.useState(false)
|
|
652
1225
|
const [autoEnrich, setAutoEnrich] = React.useState(true)
|
|
653
|
-
// 起点书页补全(收藏/精确字数):默认关;缓存规模用来给用户看「要不要真打请求」
|
|
654
1226
|
const [qdEnrich, setQdEnrich] = React.useState(false)
|
|
655
1227
|
const [qdCache, setQdCache] = React.useState(null)
|
|
656
|
-
/**
|
|
657
|
-
* ★ 2026-10-17(3):真实请求之间的最小间隔(毫秒)。
|
|
658
|
-
* 那个 1s 是本项目自设的保守值(不是站点要求);这里做成可见可改,默认不动它。
|
|
659
|
-
*/
|
|
660
1228
|
const [intervalMs, setIntervalMs] = React.useState(1000)
|
|
661
|
-
// 定时扫描设置(默认关;新安装不自动抓)
|
|
662
1229
|
const [tOn, setTOn] = React.useState(false)
|
|
663
|
-
const [tTime, setTTime] = React.useState('01:30')
|
|
664
|
-
const [tNote, setTNote] = React.useState(null)
|
|
665
|
-
const [tLast, setTLast] = React.useState(null)
|
|
666
|
-
// ★ 2026-10-16:按站分时抓取(每站一个时刻 + 一个兜底时刻)
|
|
667
1230
|
const [tTimes, setTTimes] = React.useState({})
|
|
668
1231
|
const [tFall, setTFall] = React.useState('22:30')
|
|
669
|
-
|
|
1232
|
+
const [tNote, setTNote] = React.useState(null)
|
|
1233
|
+
const [tLast, setTLast] = React.useState(null)
|
|
670
1234
|
const [planLive, setPlanLive] = React.useState(null)
|
|
1235
|
+
const [retMsg, setRetMsg] = React.useState(null)
|
|
1236
|
+
/** 站分组默认展开(含已勾选榜的站更该展开);只记「被收起」的,避免新站默认藏着 */
|
|
1237
|
+
const [closedGroups, setClosedGroups] = React.useState({})
|
|
671
1238
|
const load = React.useCallback(function () {
|
|
672
1239
|
jget('/catalog').then(function (c) {
|
|
673
1240
|
setCat(c)
|
|
@@ -675,46 +1242,60 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
675
1242
|
setAutoEnrich(c.autoEnrich !== false)
|
|
676
1243
|
setQdEnrich(!!(c.qidian && c.qidian.enrich))
|
|
677
1244
|
setQdCache(c.qidian || null)
|
|
678
|
-
// ★ 2026-10-17(3):全局请求间隔(默认 1000ms)
|
|
679
1245
|
setIntervalMs(typeof c.requestIntervalMs === 'number' ? c.requestIntervalMs : 1000)
|
|
680
1246
|
noteRequestInterval(c.requestIntervalMs)
|
|
681
1247
|
const t = c.timer || {}
|
|
682
1248
|
setTOn(t.enabled === true)
|
|
683
|
-
setTTime(t.scanTime || '01:30')
|
|
684
1249
|
setTTimes(t.siteTimes || {})
|
|
685
1250
|
setTFall(t.fallbackTime || '22:30')
|
|
686
1251
|
setTLast(t)
|
|
687
|
-
|
|
1252
|
+
// ★ 组件被卸载过:草稿优先(不拿服务端值盖掉用户没保存的选择)
|
|
1253
|
+
const d = DRAFTS.settings
|
|
1254
|
+
if (d && Array.isArray(d.picked)) {
|
|
1255
|
+
setPicked(d.picked.slice())
|
|
1256
|
+
if (typeof d.autoEnrich === 'boolean') setAutoEnrich(d.autoEnrich)
|
|
1257
|
+
if (typeof d.qdEnrich === 'boolean') setQdEnrich(d.qdEnrich)
|
|
1258
|
+
if (d.times && typeof d.times === 'object') setTTimes(d.times)
|
|
1259
|
+
if (typeof d.fall === 'string') setTFall(d.fall)
|
|
1260
|
+
setDirty(!!d.dirty)
|
|
1261
|
+
setNote('已恢复未保存的改动(还没保存)')
|
|
1262
|
+
} else setDirty(false)
|
|
688
1263
|
}).catch(function (e) { setNote(String(e)) })
|
|
689
1264
|
}, [])
|
|
690
|
-
const saveTimer = function (enabled, times, fall) {
|
|
691
|
-
setTNote('保存中…')
|
|
692
|
-
jpost('/timer', { enabled: enabled, siteTimes: times, fallbackTime: fall }).then(function (r) {
|
|
693
|
-
setTNote(r && r.note ? r.note : '已保存')
|
|
694
|
-
return jget('/catalog').then(function (c) { setTLast(c.timer || null) })
|
|
695
|
-
}).catch(function (e) { setTNote(String(e)) })
|
|
696
|
-
}
|
|
697
1265
|
React.useEffect(function () { load() }, [load])
|
|
1266
|
+
// 只读的实时调度状态(3 分钟;有站到点待跑时 30 秒)——**不重载 /catalog**,免得冲掉草稿
|
|
698
1267
|
React.useEffect(function () {
|
|
699
1268
|
let alive = true
|
|
700
1269
|
let id = null
|
|
701
|
-
// ★ 2026-10-16 审计:卸载后不许再排下一轮。旧写法在 catch 分支里无条件 every(180000),
|
|
702
|
-
// 组件已经卸载、cleanup 也跑过了,它又挂上一个新 interval 永久残留(每 3 分钟打一次接口)。
|
|
703
1270
|
const every = function (ms) { if (!alive) return; if (id) clearInterval(id); id = setInterval(tick, ms) }
|
|
704
1271
|
const tick = function () {
|
|
705
1272
|
jget('/timer-plan').then(function (r) {
|
|
706
1273
|
if (!alive) return
|
|
707
1274
|
const pl = (r && r.plan) || null
|
|
708
1275
|
if (pl) setPlanLive(pl)
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
const busy = !!(pl && ((pl.due || []).length > 0 || (pl.fallback || []).length > 0))
|
|
712
|
-
every(busy ? 30000 : 180000)
|
|
1276
|
+
const hot = !!(pl && ((pl.due || []).length > 0 || (pl.fallback || []).length > 0))
|
|
1277
|
+
every(hot ? 30000 : 180000)
|
|
713
1278
|
}).catch(function () { if (alive) every(180000) })
|
|
714
1279
|
}
|
|
715
1280
|
tick()
|
|
716
1281
|
return function () { alive = false; if (id) clearInterval(id) }
|
|
717
1282
|
}, [])
|
|
1283
|
+
/** 计划时刻有没有未保存的改动(提前算:离开保护要用,且必须早于任何 return) */
|
|
1284
|
+
const timesDirty = !!tLast && (function () {
|
|
1285
|
+
const a0 = tTimes || {}
|
|
1286
|
+
const b0 = tLast.siteTimes || {}
|
|
1287
|
+
const keys = Object.keys({ ...a0, ...b0 })
|
|
1288
|
+
for (let i = 0; i < keys.length; i++) { if (String(a0[keys[i]] || '') !== String(b0[keys[i]] || '')) return true }
|
|
1289
|
+
return String(tFall || '') !== String(tLast.fallbackTime || '')
|
|
1290
|
+
})()
|
|
1291
|
+
/** 草稿写回组件外 + 登记脏状态(**含计划时刻**;面板切页/收起前据此拦一下) */
|
|
1292
|
+
React.useEffect(function () {
|
|
1293
|
+
if (!cat || !picked) return
|
|
1294
|
+
const anyDirty = dirty || timesDirty
|
|
1295
|
+
if (!anyDirty) { DRAFTS.settings = null; dirtyGuard.set('settings', false); return }
|
|
1296
|
+
DRAFTS.settings = { picked: (picked || []).slice(), autoEnrich: !!autoEnrich, qdEnrich: !!qdEnrich, times: tTimes || {}, fall: tFall || '', dirty: !!dirty }
|
|
1297
|
+
dirtyGuard.set('settings', true)
|
|
1298
|
+
}, [dirty, timesDirty, picked, autoEnrich, qdEnrich, tTimes, tFall])
|
|
718
1299
|
if (!cat || !picked) return h('div', { style: C.muted }, note || '加载中…')
|
|
719
1300
|
const has = function (id) { return picked.indexOf(id) >= 0 }
|
|
720
1301
|
const toggle = function (id, on) {
|
|
@@ -731,15 +1312,39 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
731
1312
|
setPicked(on ? picked.concat(ids.filter(function (i) { return picked.indexOf(i) < 0 })) : picked.filter(function (i) { return ids.indexOf(i) < 0 }))
|
|
732
1313
|
setDirty(true)
|
|
733
1314
|
}
|
|
1315
|
+
/**
|
|
1316
|
+
* ★ Spec S4「恢复默认」:只改**草稿**,并说清将新增/移除多少 —— 保存后才生效。
|
|
1317
|
+
* 默认集来自 catalog 的 defaultCaptures(宿主 defaultState().boards,唯一权威);
|
|
1318
|
+
* 宿主没给就明确拒绝,不自己猜一套默认集(猜出来的东西会让「恢复默认」变成另一种事故)。
|
|
1319
|
+
*/
|
|
1320
|
+
const restoreDefaults = function () {
|
|
1321
|
+
const def = cat && Array.isArray(cat.defaultCaptures) ? cat.defaultCaptures.slice() : null
|
|
1322
|
+
if (!def || !def.length) {
|
|
1323
|
+
setNote('这台宿主没有提供默认抓取集(catalog.defaultCaptures 缺失),只能手动勾选')
|
|
1324
|
+
return
|
|
1325
|
+
}
|
|
1326
|
+
const add = def.filter(function (id) { return picked.indexOf(id) < 0 })
|
|
1327
|
+
const del = picked.filter(function (id) { return def.indexOf(id) < 0 })
|
|
1328
|
+
setPicked(def)
|
|
1329
|
+
setDirty(true)
|
|
1330
|
+
setNote('已恢复默认抓取:将新增 ' + add.length + ' 个、移除 ' + del.length + ' 个(点「保存设置」才落盘)')
|
|
1331
|
+
}
|
|
1332
|
+
const toggleGroup = function (key) {
|
|
1333
|
+
const nx = Object.assign({}, closedGroups)
|
|
1334
|
+
nx[key] = !nx[key]
|
|
1335
|
+
setClosedGroups(nx)
|
|
1336
|
+
}
|
|
734
1337
|
const save = function () {
|
|
735
1338
|
setBusy(true)
|
|
736
1339
|
jpost('/select', { captures: picked, autoEnrich: !!autoEnrich, qidianEnrich: !!qdEnrich }).then(function (r) {
|
|
737
|
-
setNote((r && r.note ? r.note : '已保存:' + picked.length + ' 个榜') + '
|
|
1340
|
+
setNote((r && r.note ? r.note : '已保存:' + picked.length + ' 个榜') + '(下次扫描生效)')
|
|
738
1341
|
setDirty(false)
|
|
1342
|
+
DRAFTS.settings = timesDirty ? { picked: picked.slice(), autoEnrich: !!autoEnrich, qdEnrich: !!qdEnrich, times: tTimes, fall: tFall, dirty: false } : null
|
|
1343
|
+
dirtyGuard.set('settings', timesDirty)
|
|
739
1344
|
if (props.onSaved) props.onSaved()
|
|
740
1345
|
try { window.dispatchEvent(new Event('rank-scan:saved')) } catch (e) {}
|
|
741
1346
|
return load()
|
|
742
|
-
}).catch(function (e) { setNote(
|
|
1347
|
+
}).catch(function (e) { setNote('保存失败:' + e) }).then(function () { setBusy(false) })
|
|
743
1348
|
}
|
|
744
1349
|
const groups = []
|
|
745
1350
|
const seenG = {}
|
|
@@ -751,159 +1356,193 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
751
1356
|
const sites = []
|
|
752
1357
|
groups.forEach(function (g) { if (sites.indexOf(g.site) < 0) sites.push(g.site) })
|
|
753
1358
|
const siteNameOf = function (s) { const g = groups.filter(function (x) { return x.site === s })[0]; return g ? g.siteName : s }
|
|
754
|
-
|
|
755
|
-
|
|
1359
|
+
const pickedOf = function (site) {
|
|
1360
|
+
const ids = cat.boards.filter(function (b) { return b.site === site }).map(function (b) { return b.boardId })
|
|
1361
|
+
return picked.filter(function (i) { return ids.indexOf(i) >= 0 }).length
|
|
1362
|
+
}
|
|
1363
|
+
const siteTotal = function (site) { return cat.boards.filter(function (b) { return b.site === site }).length }
|
|
1364
|
+
/** 开关即时生效:乐观置位,失败**回退 UI** 并说明(不让界面说一套、服务端做另一套) */
|
|
1365
|
+
const toggleTimer = function (next) {
|
|
1366
|
+
const prev = tOn
|
|
1367
|
+
setTOn(next)
|
|
1368
|
+
setTNote(next ? '正在开启…' : '正在关闭…')
|
|
1369
|
+
jpost('/timer', { enabled: next }).then(function (r) {
|
|
1370
|
+
setTNote((r && r.note ? r.note : '已' + (next ? '开启' : '关闭')) + '(立即生效)')
|
|
1371
|
+
return jget('/catalog').then(function (c) { setTLast(c.timer || null) })
|
|
1372
|
+
}).catch(function (e) {
|
|
1373
|
+
setTOn(prev)
|
|
1374
|
+
setTNote('没能' + (next ? '开启' : '关闭') + ':' + e + '(已恢复原状态)')
|
|
1375
|
+
})
|
|
1376
|
+
}
|
|
1377
|
+
const savePlan = function () {
|
|
1378
|
+
setTNote('保存计划中…')
|
|
1379
|
+
jpost('/timer', { enabled: tOn, siteTimes: tTimes, fallbackTime: tFall }).then(function (r) {
|
|
1380
|
+
setTNote(r && r.note ? r.note : '计划已保存')
|
|
1381
|
+
return jget('/catalog').then(function (c) { setTLast(c.timer || null) })
|
|
1382
|
+
}).catch(function (e) { setTNote('保存失败:' + e) })
|
|
1383
|
+
}
|
|
1384
|
+
/** 全站补全:按站把抓取集里的榜逐个补(逐本 1 请求 + 当前间隔,会很慢) */
|
|
1385
|
+
const enrichSite = function (site) {
|
|
1386
|
+
const ids = (cat.captures || []).filter(function (id) { return String(id).split('.')[0] === site })
|
|
1387
|
+
if (!ids.length) { setNote('该站当前没有勾选任何榜'); return }
|
|
1388
|
+
setBusy(true)
|
|
1389
|
+
let done = 0
|
|
1390
|
+
let filled = 0
|
|
1391
|
+
let seq = Promise.resolve()
|
|
1392
|
+
ids.forEach(function (id) {
|
|
1393
|
+
seq = seq.then(function () {
|
|
1394
|
+
setNote('补全 ' + siteNameOf(site) + ' ' + done + '/' + ids.length + ' 个榜…')
|
|
1395
|
+
return jpost('/enrich?boardId=' + encodeURIComponent(id)).then(function (r) {
|
|
1396
|
+
done += 1
|
|
1397
|
+
filled += (r && r.filled) || 0
|
|
1398
|
+
}).catch(function () { done += 1 })
|
|
1399
|
+
})
|
|
1400
|
+
})
|
|
1401
|
+
seq.then(function () { setNote(siteNameOf(site) + ' 补全完成:' + ids.length + ' 个榜,共补 ' + filled + ' 条') })
|
|
1402
|
+
.catch(function (e) { setNote('补全失败:' + e) })
|
|
1403
|
+
.then(function () { setBusy(false) })
|
|
1404
|
+
}
|
|
1405
|
+
const retention = ov && ov.storage ? ov.storage.retentionDays : 180
|
|
1406
|
+
const sv = (ov && ov.services) || {}
|
|
1407
|
+
const diag = function () {
|
|
1408
|
+
const lines = []
|
|
1409
|
+
lines.push('dsh-rank-scan 诊断')
|
|
1410
|
+
lines.push('数据日期: ' + ((ov && ov.dataDate) || '—'))
|
|
1411
|
+
lines.push('已采集/总数: ' + (ov ? ((ov.counts || {}).ok || 0) + '/' + Object.keys(ov.counts || {}).reduce(function (s, k) { return s + ((ov.counts || {})[k] || 0) }, 0) : '—'))
|
|
1412
|
+
lines.push('服务: webServer=' + !!sv.webServer + ' timerService=' + !!sv.timerService + ' timerArmed=' + !!sv.timerArmed)
|
|
1413
|
+
lines.push('定时: enabled=' + tOn + ' 时刻=' + JSON.stringify(tTimes) + ' 兜底=' + tFall)
|
|
1414
|
+
lines.push('抓取集: ' + picked.length + ' 个榜')
|
|
1415
|
+
lines.push('上次扫描: ' + scanLabel(ov && ov.scan))
|
|
1416
|
+
return lines.join('\n')
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* ★ Spec E(2026-10-24 审查):保存/未保存条属于**整个设置层**,不是「抓取范围」分组的附属。
|
|
1420
|
+
* 旧实现把它放在抓取范围里 ⇒ 这个分组一折叠,改「自动补全 / 起点收藏补全」时就看不到
|
|
1421
|
+
* 「有未保存的改动」和保存按钮(改了半天以为已经生效)。
|
|
1422
|
+
* 保持原语义:保存只落抓取集 + 两个补全开关,计划时刻仍由「保存计划」单独保存。
|
|
1423
|
+
*/
|
|
1424
|
+
const saveBar = h('div', { style: { position: 'sticky', bottom: '0', zIndex: 4, marginTop: '6px', padding: '5px 7px',
|
|
1425
|
+
border: '1px solid ' + (dirty ? 'rgba(217,164,65,.6)' : 'rgba(128,128,128,.28)') + '', borderRadius: '6px',
|
|
1426
|
+
background: 'var(--dsh-surface, #fff)',
|
|
1427
|
+
backgroundImage: dirty ? 'linear-gradient(rgba(217,164,65,.16), rgba(217,164,65,.16))' : 'linear-gradient(rgba(128,128,128,.06), rgba(128,128,128,.06))',
|
|
1428
|
+
boxShadow: '0 -8px 12px -8px rgba(0,0,0,.28)' } },
|
|
756
1429
|
h('div', { style: C.row },
|
|
757
|
-
h('button', { style: dirty ? C.btnOn : C.btn, disabled: busy || !dirty, onClick: save }, dirty ? '
|
|
758
|
-
|
|
759
|
-
h('button', { style: C.btn, onClick: load }, '放弃改动
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
h('
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
},
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
' · 有效期 ' + (cat.bookCache.ttlDays || 7) + ' 天') : null,
|
|
794
|
-
h('div', { style: { margin: '8px 0', padding: '7px 9px', border: '1px solid rgba(128,128,128,.3)', borderRadius: '8px', background: 'rgba(128,128,128,.05)' } },
|
|
795
|
-
h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, '定时扫描'),
|
|
1430
|
+
h('button', { style: dirty ? C.btnOn : C.btn, disabled: busy || !dirty, onClick: save }, dirty ? '保存设置(' + picked.length + ' 个榜)' : '已保存(' + picked.length + ' 个榜)'),
|
|
1431
|
+
// 放弃改动 = 真的丢掉草稿(否则 load 会按草稿再恢复一遍,等于没放弃)
|
|
1432
|
+
dirty ? h('button', { style: C.btn, disabled: busy, onClick: function () { DRAFTS.settings = null; dirtyGuard.set('settings', false); setNote('已放弃改动'); load() } }, '放弃改动') : null,
|
|
1433
|
+
dirty ? h('span', { style: { color: '#d9a441' } }, '有未保存的改动') : null,
|
|
1434
|
+
h('button', { style: C.btn, disabled: busy, onClick: restoreDefaults, title: '把勾选恢复成插件默认抓取集(只改草稿,保存后生效)' }, '恢复默认'),
|
|
1435
|
+
note ? h('span', { style: C.muted }, String(note).slice(0, 100)) : null))
|
|
1436
|
+
return h('div', null,
|
|
1437
|
+
h(Section, { title: '抓取范围(' + picked.length + ' 个榜)', defaultOpen: true },
|
|
1438
|
+
h('div', { style: C.muted }, '勾选 = 抓什么;改动进草稿,点下面的「保存设置」才落盘(下次扫描生效)。抓到的榜就会显示。'),
|
|
1439
|
+
h('div', { style: C.row }, sites.map(function (s) {
|
|
1440
|
+
return h('span', { key: s, style: { ...C.row, margin: 0 } },
|
|
1441
|
+
h('span', { style: C.muted }, siteNameOf(s) + ' ' + pickedOf(s) + '/' + siteTotal(s)),
|
|
1442
|
+
h('button', { style: C.btn, onClick: function () { setAll(s, true) } }, '全选'),
|
|
1443
|
+
h('button', { style: C.btn, onClick: function () { setAll(s, false) } }, '全不选'),
|
|
1444
|
+
h(PopMenu, { label: '更多', width: 190, items: [
|
|
1445
|
+
{ label: '补齐该站缺失字段', onClick: function () { enrichSite(s) }, title: '把该站已勾选的榜逐个补全(逐本 1 请求,很慢)' },
|
|
1446
|
+
] }))
|
|
1447
|
+
})),
|
|
1448
|
+
groups.map(function (g) {
|
|
1449
|
+
const derived = g.items.length > 0 && String(g.items[0].boardId).indexOf('fanqie.derived.') === 0
|
|
1450
|
+
const gkey = g.site + '|' + g.group
|
|
1451
|
+
const closed = !!closedGroups[gkey]
|
|
1452
|
+
// Spec 4.4:站分组可折叠(20 个榜全铺开时找不到想改的那个)
|
|
1453
|
+
return h('div', { key: gkey },
|
|
1454
|
+
h('div', { style: { ...C.siteBar, cursor: 'pointer' }, onClick: function () { toggleGroup(gkey) }, title: '点一下折叠/展开这一组' },
|
|
1455
|
+
(closed ? '▸ ' : '▾ ') + g.siteName + ' · ' + g.group + '(' + g.items.length + ')'),
|
|
1456
|
+
derived ? h('div', { style: { ...C.muted, margin: '0 0 4px 2px' } }, '本地派生榜:不发请求,总是显示;不计入「未显示 N 个」。') : null,
|
|
1457
|
+
closed ? null : h('table', { style: C.table },
|
|
1458
|
+
h('tbody', null, g.items.map(function (b) {
|
|
1459
|
+
return h('tr', { key: b.boardId },
|
|
1460
|
+
h('td', { style: { ...C.td, width: '22px' } }, h('input', { type: 'checkbox', checked: has(b.boardId), onChange: function (e) { toggle(b.boardId, e.target.checked) } })),
|
|
1461
|
+
h('td', { style: C.td }, b.label))
|
|
1462
|
+
}))))
|
|
1463
|
+
}),
|
|
1464
|
+
),
|
|
1465
|
+
h(Section, { title: '扫描计划', defaultOpen: false, summary: (tOn ? '已开启' : '已关闭') + ' · 兜底 ' + (tFall || '') + ' · ' + (tLast && tLast.wired ? '自动扫描已生效' : '自动扫描未生效') },
|
|
796
1466
|
h('label', { style: C.row },
|
|
797
|
-
h('input', {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
? '今天已抓(' + (hit.by === 'timer' ? '定时' : hit.by === 'manual' ? '手动' : hit.by || '扫描') + (hhmmss ? ' ' + hhmmss : '') + ')'
|
|
814
|
-
: slr[key] === today ? '今天已跑(定时)' : '今天已抓'
|
|
815
|
-
const why = (pl.done || []).indexOf(key) >= 0 ? doneTag
|
|
816
|
-
: (pl.due || []).indexOf(key) >= 0 ? '到点待跑'
|
|
817
|
-
: (pl.waiting || []).indexOf(key) >= 0 ? '等到点'
|
|
818
|
-
: (pl.fallback || []).indexOf(key) >= 0 ? '漏了 → 兜底补' : '—'
|
|
819
|
-
const sf = pl.staleFlag || {}
|
|
820
|
-
const sb = Object.keys(sf).find(function (b) { return b.split('.')[0] === key && sf[b] && sf[b].date === pl.today })
|
|
821
|
-
const isStale = (pl.staleSites || []).indexOf(key) >= 0
|
|
822
|
-
return h('div', { key: key, style: { ...C.row, marginTop: '2px' } },
|
|
823
|
-
h('span', { style: { width: '48px', flex: '0 0 auto' } }, s[1]),
|
|
824
|
-
h('input', {
|
|
825
|
-
type: 'time', style: { ...C.btn, width: '96px' }, value: (tTimes || {})[key] || '',
|
|
826
|
-
onChange: function (e) { const nx = Object.assign({}, tTimes); nx[key] = e.target.value; setTTimes(nx) },
|
|
827
|
-
onBlur: function (e) { if (e.target.value !== ((tLast && tLast.siteTimes && tLast.siteTimes[key]) || '')) { const nx = Object.assign({}, tTimes); nx[key] = e.target.value; saveTimer(tOn, nx, tFall) } },
|
|
828
|
-
}),
|
|
829
|
-
h('span', { style: C.muted }, why),
|
|
830
|
-
isStale ? h('span', { style: { color: '#d9534f' }, title: '与上一数据日整榜完全一致 ⇒ 站点很可能还没换榜;到兜底时刻会自动补抓一次,也可以现在手动重抓' },
|
|
831
|
-
'⚠ 疑似未刷新(与 ' + ((sb && sf[sb] && sf[sb].prevDate) || '上一日') + ' 完全一致)') : null,
|
|
832
|
-
isStale ? h('button', {
|
|
833
|
-
style: C.btn,
|
|
834
|
-
onClick: function () {
|
|
835
|
-
const ids = (cat.boards || []).filter(function (b) { return b.site === key }).map(function (b) { return b.boardId })
|
|
836
|
-
jpost('/scan', { boards: ids }).then(function () { setTNote('已重抓 ' + s[1] + '(' + ids.length + ' 个榜)') })
|
|
837
|
-
.catch(function (e) { setTNote('重抓失败:' + e) })
|
|
838
|
-
},
|
|
839
|
-
}, '重抓该站') : null)
|
|
840
|
-
}),
|
|
841
|
-
h('div', { style: { ...C.row, marginTop: '2px' } },
|
|
842
|
-
h('span', { style: { width: '48px', flex: '0 0 auto' } }, '兜底'),
|
|
1467
|
+
h('input', { type: 'checkbox', checked: tOn, onChange: function (e) { toggleTimer(e.target.checked) } }),
|
|
1468
|
+
h('span', null, tOn ? '已开启(立即生效)' : '已关闭(立即生效)'),
|
|
1469
|
+
h('span', { style: C.muted }, '按站分时:每站放它自己的刷新点之后抓一次,一次只跑一个站')),
|
|
1470
|
+
h('div', null, [['qidian', '起点'], ['sfacg', '菠萝包'], ['fanqie', '番茄'], ['ciweimao', '刺猬猫'], ['qidiantu', '起点图']].map(function (s) {
|
|
1471
|
+
const key = s[0]
|
|
1472
|
+
const pl = planLive || (tLast && tLast.plan) || {}
|
|
1473
|
+
const hit = (pl.siteLastScan || (tLast && tLast.siteLastScan) || {})[key] || null
|
|
1474
|
+
const hhmmss = hit && hit.at ? fmtLocalHM(hit.at) : ''
|
|
1475
|
+
const timerHM = (tLast && tLast.siteLastTimerAt && tLast.siteLastTimerAt[key]) ? fmtLocalHM(tLast.siteLastTimerAt[key]) : ''
|
|
1476
|
+
const why = timerHM ? '已跑(定时 ' + timerHM + ')'
|
|
1477
|
+
: (pl.fallback || []).indexOf(key) >= 0 ? '失败/待核对 → 兜底 ' + (tFall || '') + ' 补一次'
|
|
1478
|
+
: (pl.due || []).indexOf(key) >= 0 ? '已过计划时刻,待补跑'
|
|
1479
|
+
: hit ? '手动已抓 ' + hhmmss
|
|
1480
|
+
: (pl.waiting || []).indexOf(key) >= 0 ? '等到点' : '今天还没抓'
|
|
1481
|
+
return h('div', { key: key, style: { ...C.row, marginTop: '2px' } },
|
|
1482
|
+
h('span', { style: { width: '46px', flex: '0 0 auto' } }, s[1]),
|
|
843
1483
|
h('input', {
|
|
844
|
-
type: 'time', style: { ...C.btn, width: '
|
|
845
|
-
onChange: function (e) {
|
|
846
|
-
onBlur: function (e) { if (e.target.value !== ((tLast && tLast.fallbackTime) || '')) saveTimer(tOn, tTimes, e.target.value) },
|
|
1484
|
+
type: 'time', style: { ...C.btn, width: '92px' }, value: (tTimes || {})[key] || '',
|
|
1485
|
+
onChange: function (e) { const nx = Object.assign({}, tTimes); nx[key] = e.target.value; setTTimes(nx) },
|
|
847
1486
|
}),
|
|
848
|
-
h('span', { style: C.muted },
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
(
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
h('div', { style: C.
|
|
855
|
-
(
|
|
856
|
-
'
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
tNote ? h('div', { style: C.muted }, tNote) : null),
|
|
861
|
-
h('div', { style: { margin: '8px 0', padding: '7px 9px', border: '1px solid rgba(128,128,128,.3)', borderRadius: '8px', background: 'rgba(128,128,128,.05)' } },
|
|
862
|
-
h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, '起点收藏(书页补全)'),
|
|
863
|
-
h('label', { style: C.row },
|
|
864
|
-
h('input', { type: 'checkbox', checked: qdEnrich, onChange: function (e) { setQdEnrich(e.target.checked); setDirty(true) } }),
|
|
865
|
-
h('span', null, qdEnrich ? '已开启' : '已关闭(默认关)'),
|
|
866
|
-
h('span', { style: C.muted }, '起点任何榜单页都没有收藏,只能逐本进作品页(约 103 KB/本)。开启后靠书页缓存跳过重复的书,只有新入榜/缓存过期的才真打请求。')),
|
|
867
|
-
h('div', { style: C.muted },
|
|
868
|
-
'缓存:' + (qdCache && qdCache.cache ? qdCache.cache.books : 0) + ' 本' +
|
|
869
|
-
(qdCache && qdCache.cache && qdCache.cache.newest ? '(最近 ' + (fmtLocalStamp(qdCache.cache.newest) || qdCache.cache.newest.slice(0, 16)) + ')' : '') +
|
|
870
|
-
' · 有效期 ' + ((qdCache && qdCache.ttlDays) || 7) + ' 天'),
|
|
1487
|
+
h('span', { style: C.muted }, why))
|
|
1488
|
+
})),
|
|
1489
|
+
h('div', { style: { ...C.row, marginTop: '2px' } },
|
|
1490
|
+
h('span', { style: { width: '46px', flex: '0 0 auto' } }, '兜底'),
|
|
1491
|
+
h('input', { type: 'time', style: { ...C.btn, width: '92px' }, value: tFall, onChange: function (e) { setTFall(e.target.value) } }),
|
|
1492
|
+
h('span', { style: C.muted }, '当天失败或内容待核对的站,到这个点再补一次(每站每天一次)')),
|
|
1493
|
+
timesDirty ? h('div', { style: C.row },
|
|
1494
|
+
h('button', { style: C.btnOn, onClick: savePlan }, '保存计划'),
|
|
1495
|
+
h('span', { style: { color: '#d9a441' } }, '时刻有改动,未保存')) : null,
|
|
1496
|
+
h('div', { style: C.muted }, '状态更新于 ' + ((planLive && planLive.now) || '—') + (planLive && planLive.installedToday ? ' · 今天刚安装:安装当天不自动跑,明天起按上面的时刻执行' : '')),
|
|
1497
|
+
tNote ? h('div', { style: C.muted }, String(tNote).slice(0, 140)) : null),
|
|
1498
|
+
h(Section, { title: '数据与性能', defaultOpen: false, summary: (ov && ov.storage ? '数据目录 ' + fmtBytes(ov.storage.totalBytes) + ' · 保留 ' + retention + ' 天' : '') },
|
|
871
1499
|
h('div', { style: C.row },
|
|
872
|
-
h('
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
1500
|
+
h('span', { style: C.muted }, '保留'),
|
|
1501
|
+
h('select', {
|
|
1502
|
+
style: { ...C.input, width: 'auto', padding: '1px 4px' },
|
|
1503
|
+
value: String(retention),
|
|
1504
|
+
title: '只影响数据日期目录(快照/报告);配置、书签、书页缓存永不删',
|
|
1505
|
+
onChange: function (e) {
|
|
1506
|
+
const v = e.target.value === 'forever' ? 'forever' : Number(e.target.value)
|
|
1507
|
+
jpost('/retention', { days: v }).then(function (r) { setRetMsg((r && r.note) || '已更新'); if (props.onSaved) props.onSaved() })
|
|
1508
|
+
.catch(function (e2) { setRetMsg('设置失败:' + e2) })
|
|
878
1509
|
},
|
|
879
|
-
},
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1510
|
+
},
|
|
1511
|
+
[30, 90, 180, 365].map(function (n) { return h('option', { key: n, value: String(n) }, n + ' 天') }),
|
|
1512
|
+
h('option', { key: 'forever', value: 'forever' }, '永久保留')),
|
|
1513
|
+
retMsg ? h('span', { style: C.muted }, String(retMsg).slice(0, 80)) : null),
|
|
1514
|
+
ov && ov.storage ? h('div', { style: C.muted },
|
|
1515
|
+
'快照 ' + fmtBytes(ov.storage.snapshotBytes) + ' · state ' + fmtBytes(ov.storage.stateBytes) +
|
|
1516
|
+
' · ' + ov.storage.dates + ' 天(' + dash(ov.storage.oldest) + ' 起)· 书签 ' + ov.storage.bookmarks + ' 条') : null,
|
|
1517
|
+
h('label', { style: C.row },
|
|
1518
|
+
h('input', { type: 'checkbox', checked: autoEnrich, onChange: function (e) { setAutoEnrich(e.target.checked); setDirty(true) } }),
|
|
1519
|
+
h('span', null, '扫描后自动补全缺失字段'),
|
|
1520
|
+
h('span', { style: C.muted }, '(榜页没有收藏/字数时要进书页取;补全在后台跑,抓榜先返回)')),
|
|
1521
|
+
h('div', { style: { ...C.row, marginTop: '4px' } },
|
|
1522
|
+
h('span', { style: C.muted }, '起点收藏补全'),
|
|
1523
|
+
h('input', { type: 'checkbox', checked: qdEnrich, onChange: function (e) { setQdEnrich(e.target.checked); setDirty(true) } }),
|
|
1524
|
+
h('span', { style: C.muted }, qdEnrich ? '已开启' : '已关闭(默认关)'),
|
|
1525
|
+
h('button', { style: C.btn, disabled: busy, onClick: function () { setBusy(true); jpost('/qidianEnrich').then(function (r) { setNote((r && r.note) || '起点补全完成'); return load() }).catch(function (e) { setNote(String(e)) }).then(function () { setBusy(false) }) } }, '补全起点收藏'),
|
|
1526
|
+
h('button', { style: C.btn, disabled: busy, onClick: function () { setBusy(true); jpost('/qidianCache', { clear: true }).then(function (r) { setNote((r && r.note) || '缓存已清'); return load() }).catch(function (e) { setNote(String(e)) }).then(function () { setBusy(false) }) } }, '清空书页缓存')),
|
|
1527
|
+
h('div', { style: C.muted }, '起点书页缓存 ' + (qdCache && qdCache.cache ? qdCache.cache.books : 0) + ' 本 · 有效期 ' + ((qdCache && qdCache.ttlDays) || 7) + ' 天' +
|
|
1528
|
+
(cat.bookCache ? ' · 通用书页缓存 ' + ((cat.bookCache.stat && cat.bookCache.stat.entries) || 0) + ' 本 · 有效期 ' + (cat.bookCache.ttlDays || 7) + ' 天' : '')),
|
|
1529
|
+
h(Section, { title: '高级:请求间隔', defaultOpen: false, summary: '当前 ' + fmtIntervalText(intervalMs) },
|
|
1530
|
+
h('div', { style: C.row },
|
|
1531
|
+
h('select', {
|
|
1532
|
+
style: { ...C.input, width: 'auto', padding: '1px 4px' },
|
|
1533
|
+
value: String(intervalMs),
|
|
1534
|
+
onChange: function (e) { setIntervalMs(Number(e.target.value)) },
|
|
886
1535
|
},
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
return h('div', { key: g.site + g.group },
|
|
898
|
-
h('div', { style: C.siteBar }, g.siteName + ' · ' + g.group),
|
|
899
|
-
derived ? h('div', { style: { ...C.muted, margin: '0 0 4px 2px' } }, '本地派生榜:不发请求(0 请求),总是显示在面板里 —— 它不走「显示集」,所以概览里的「隐藏 N 个」不包含它。') : null,
|
|
900
|
-
h('table', { style: C.table },
|
|
901
|
-
h('tbody', null, g.items.map(function (b) {
|
|
902
|
-
return h('tr', { key: b.boardId },
|
|
903
|
-
h('td', { style: { ...C.td, width: '22px' } }, h('input', { type: 'checkbox', checked: has(b.boardId), onChange: function (e) { toggle(b.boardId, e.target.checked) } })),
|
|
904
|
-
h('td', { style: C.td }, b.label))
|
|
905
|
-
}))))
|
|
906
|
-
}))
|
|
1536
|
+
[200, 500, 1000, 2000, 5000].map(function (v) { return h('option', { key: v, value: String(v) }, v + ' ms' + (v === 1000 ? '(默认)' : '')) }),
|
|
1537
|
+
h('option', { key: 0, value: '0' }, '不限速(仅本地测试)')),
|
|
1538
|
+
h('button', { style: C.btn, disabled: busy, onClick: function () { setBusy(true); jpost('/select', { requestIntervalMs: intervalMs }).then(function () { setNote('请求间隔已改为 ' + (intervalMs === 0 ? '不限速' : intervalMs + 'ms')); return load() }).catch(function (e) { setNote(String(e)) }).then(function () { setBusy(false) }) } }, '应用'),
|
|
1539
|
+
h('span', { style: C.muted }, '1s 是本项目自定的保守值(不是站点要求);调小更快,也更容易被站点注意到')))),
|
|
1540
|
+
h(Section, { title: '关于与诊断', defaultOpen: false, summary: (sv.webServer ? '服务正常' : 'webServer 未注册') + ' · 自动扫描' + (sv.timerArmed ? '已生效' : '未生效') },
|
|
1541
|
+
h(VersionRow, { setNote: setNote }),
|
|
1542
|
+
h('div', { style: C.muted }, '服务:webServer ' + (sv.webServer ? '✓' : '✗') + ' · timer ' + (sv.timerService ? '✓' : '✗') + ' · 定时任务' + (sv.timerArmed ? '已启用' : '未启用')),
|
|
1543
|
+
note ? h('div', { style: C.muted }, '最近提示:' + String(note).slice(0, 160)) : null,
|
|
1544
|
+
h('div', { style: C.row },
|
|
1545
|
+
h('button', { style: C.btn, onClick: function () { try { navigator.clipboard.writeText(diag()); setNote('诊断信息已复制(不含凭证)') } catch (e) { setNote('复制失败:' + e) } } }, '复制诊断信息'))), saveBar)
|
|
907
1546
|
}
|
|
908
1547
|
/**
|
|
909
1548
|
* ★ 版本区(2026-10-16):显示当前版本 + 「一键更新」。
|
|
@@ -1011,7 +1650,16 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1011
1650
|
}
|
|
1012
1651
|
// 名次变化:0 显示「0」(持平),不要显示「—」(— 留给「算不出来」:无基准/新入榜)
|
|
1013
1652
|
// ★ 2026-10-16 跨期不可比(周期榜换期当天):变化列显示「新期」,不显示一个跨期的假变化
|
|
1014
|
-
|
|
1653
|
+
// ★ 2026-10-17(配色):delta 是「名次前进为正」的口径 ⇒ >0 上升=绿、<0 下滑=红;0/新期/回榜 不上色
|
|
1654
|
+
if (k === 'delta') {
|
|
1655
|
+
if (ex.periodChanged === true) return '新期'
|
|
1656
|
+
if (r.deltaGroup === 'new') return '+ 新'
|
|
1657
|
+
if (r.deltaGroup === 'rebound') return '回榜'
|
|
1658
|
+
if (r.delta === null || r.delta === undefined) return '—'
|
|
1659
|
+
if (r.delta > 0) return h('span', { style: C.up }, '↑ ' + r.delta)
|
|
1660
|
+
if (r.delta < 0) return h('span', { style: C.down }, '↓ ' + Math.abs(r.delta))
|
|
1661
|
+
return '0'
|
|
1662
|
+
}
|
|
1015
1663
|
if (k === 'read') return fmtRead(ex.read !== undefined ? ex.read : r.value)
|
|
1016
1664
|
if (k === 'value') return fmtRead(r.value)
|
|
1017
1665
|
if (k === 'baseRead') return fmtRead(ex.baseRead !== undefined ? ex.baseRead : ex.prevRead)
|
|
@@ -1024,9 +1672,16 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1024
1672
|
if (k === 'readDelta') {
|
|
1025
1673
|
const vd = ex.valueDelta != null ? ex.valueDelta
|
|
1026
1674
|
: (typeof r.value === 'number' && typeof ex.prevRead === 'number' ? r.value - ex.prevRead : null)
|
|
1027
|
-
|
|
1675
|
+
if (vd == null) return '—'
|
|
1676
|
+
if (vd > 0) return h('span', { style: C.up }, '+' + fmtRead(vd))
|
|
1677
|
+
if (vd < 0) return h('span', { style: C.down }, String(vd))
|
|
1678
|
+
return '0'
|
|
1679
|
+
}
|
|
1680
|
+
if (k === 'dailyDelta') {
|
|
1681
|
+
if (ex.dailyDelta == null) return '—'
|
|
1682
|
+
return h('span', { style: ex.dailyDelta > 0 ? C.up : ex.dailyDelta < 0 ? C.down : null },
|
|
1683
|
+
(ex.dailyDelta > 0 ? '+' : '') + ex.dailyDelta)
|
|
1028
1684
|
}
|
|
1029
|
-
if (k === 'dailyDelta') return ex.dailyDelta == null ? '—' : (ex.dailyDelta > 0 ? '+' : '') + ex.dailyDelta
|
|
1030
1685
|
// 每日增量已拆成 daily0..daily6 七列(见 view.ts),单元格只取那一天
|
|
1031
1686
|
if (/^daily\d+$/.test(k)) {
|
|
1032
1687
|
const d = (ex.daily || [])[Number(k.slice(5))]
|
|
@@ -1065,6 +1720,24 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1065
1720
|
}
|
|
1066
1721
|
|
|
1067
1722
|
/** 榜 + 站内书号 ⇒ bookKey(与 host 端同一套命名空间规则;起点图归并到 qidian) */
|
|
1723
|
+
/**
|
|
1724
|
+
* 榜名注册表:概览/目录任一处拿到 name 就记下来。
|
|
1725
|
+
* 书签详情、导出提示等处用它把 boardId 换成「站 · 榜名」(以前直接把 `qidiantu.shouding` 这种内部 id 甩给使用者)。
|
|
1726
|
+
*/
|
|
1727
|
+
const BOARD_NAMES = (window.__rankScanBoardNames = window.__rankScanBoardNames || {})
|
|
1728
|
+
const rememberBoardNames = function (list) {
|
|
1729
|
+
(list || []).forEach(function (b) {
|
|
1730
|
+
if (!b || !b.boardId) return
|
|
1731
|
+
const label = b.name || b.label
|
|
1732
|
+
if (!label) return
|
|
1733
|
+
BOARD_NAMES[b.boardId] = b.siteName ? b.siteName + ' · ' + label : label
|
|
1734
|
+
})
|
|
1735
|
+
}
|
|
1736
|
+
const boardLabel = function (boardId) {
|
|
1737
|
+
const id = String(boardId || '')
|
|
1738
|
+
return BOARD_NAMES[id] || (id || '—')
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1068
1741
|
function bookKeyOf(boardId, key) {
|
|
1069
1742
|
const id = String(key == null ? '' : key).trim()
|
|
1070
1743
|
if (!id) return ''
|
|
@@ -1073,13 +1746,14 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1073
1746
|
return ns ? ns + ':' + id : ''
|
|
1074
1747
|
}
|
|
1075
1748
|
|
|
1076
|
-
/**
|
|
1749
|
+
/** 行详情卡里的书签编辑:备注 + 夹一起**显式保存**(失败保留草稿) */
|
|
1077
1750
|
function DetailBookmarkEditor(props) {
|
|
1078
1751
|
const store = bmStore.use()
|
|
1079
1752
|
const bk = props.bookKey
|
|
1080
1753
|
const [note, setNote] = React.useState('')
|
|
1081
1754
|
const [folders, setFolders] = React.useState('')
|
|
1082
1755
|
const [msg, setMsg] = React.useState(null)
|
|
1756
|
+
const [busy, setBusy] = React.useState(false)
|
|
1083
1757
|
const [loaded, setLoaded] = React.useState(false)
|
|
1084
1758
|
React.useEffect(function () {
|
|
1085
1759
|
if (!bk) return
|
|
@@ -1091,22 +1765,30 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1091
1765
|
}, [bk, store.total])
|
|
1092
1766
|
if (!bk || !store.has(bk)) return null
|
|
1093
1767
|
const save = function () {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1768
|
+
setBusy(true)
|
|
1769
|
+
setMsg(null)
|
|
1770
|
+
store.act({ action: 'update', bookKey: bk, note: note, folders: String(folders || '').split(/[\s,,]+/).filter(Boolean) })
|
|
1771
|
+
.then(function () { setBusy(false); setMsg('已保存'); return store.refreshList() })
|
|
1772
|
+
.catch(function (e) { setBusy(false); setMsg('保存失败:' + e + '(草稿还在)') })
|
|
1097
1773
|
}
|
|
1098
1774
|
return h('div', { style: { ...C.detail, marginTop: '6px' } },
|
|
1099
1775
|
h('div', { style: C.row },
|
|
1100
1776
|
h('span', { style: C.muted }, '备注'),
|
|
1101
|
-
h('input', { style: { ...C.input, flex: 1, minWidth: '160px' }, value: note, placeholder: '写点什么,可用 #标签', onChange: function (e) { setNote(e.target.value) }
|
|
1777
|
+
h('input', { style: { ...C.input, flex: 1, minWidth: '160px' }, value: note, placeholder: '写点什么,可用 #标签', onChange: function (e) { setNote(e.target.value) } })),
|
|
1102
1778
|
h('div', { style: C.row },
|
|
1103
1779
|
h('span', { style: C.muted }, '书签夹'),
|
|
1104
|
-
h('input', { style: { ...C.input, flex: 1, minWidth: '120px' }, value: folders, placeholder: '空格分隔,可属于多个夹', onChange: function (e) { setFolders(e.target.value) }
|
|
1105
|
-
h('
|
|
1106
|
-
msg ? h('div', { style: C.muted }, msg) : null)
|
|
1780
|
+
h('input', { style: { ...C.input, flex: 1, minWidth: '120px' }, value: folders, placeholder: '空格分隔,可属于多个夹', onChange: function (e) { setFolders(e.target.value) } }),
|
|
1781
|
+
h('button', { style: C.btnOn, disabled: busy || !loaded, onClick: save }, busy ? '保存中…' : '保存')),
|
|
1782
|
+
msg ? h('div', { style: { ...C.muted, color: String(msg).indexOf('失败') >= 0 ? '#d9534f' : null } }, msg) : null)
|
|
1107
1783
|
}
|
|
1108
1784
|
|
|
1109
|
-
/**
|
|
1785
|
+
/**
|
|
1786
|
+
* 「我的书签」:**默认读,按需编辑**。
|
|
1787
|
+
* · 紧凑卡:书名/作者/站 + 核心指标 + 数据截止 + 备注摘要/标签/夹
|
|
1788
|
+
* · 备注与夹进同一个编辑面板,**显式保存/取消**;失败保留草稿(不再失焦即存)
|
|
1789
|
+
* · 批量选择才出现复选框;导出先选范围(已选 / 当前筛选 / 全部)并写出条数
|
|
1790
|
+
* · 添加作品、回收站、导出都收进「更多」;删除仍可撤销
|
|
1791
|
+
*/
|
|
1110
1792
|
function BookmarksTab(props) {
|
|
1111
1793
|
const store = bmStore.use()
|
|
1112
1794
|
const [, force] = React.useState(0)
|
|
@@ -1115,17 +1797,35 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1115
1797
|
const [slide, setSlide] = React.useState(0)
|
|
1116
1798
|
const [trash, setTrash] = React.useState([])
|
|
1117
1799
|
const [showTrash, setShowTrash] = React.useState(false)
|
|
1800
|
+
const [confirmPurge, setConfirmPurge] = React.useState(false)
|
|
1118
1801
|
const [manual, setManual] = React.useState('')
|
|
1119
1802
|
const [manualSite, setManualSite] = React.useState('')
|
|
1120
|
-
const [
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
const
|
|
1125
|
-
const
|
|
1803
|
+
const [addOpen, setAddOpen] = React.useState(false)
|
|
1804
|
+
const [filtersOpen, setFiltersOpen] = React.useState(false)
|
|
1805
|
+
// 编辑态:草稿只活在本地 state;保存成功才清,失败保留并就地报错
|
|
1806
|
+
// ★ 草稿从组件外恢复:切页/收起把本组件卸了,回来还在(不丢用户写了一半的备注)
|
|
1807
|
+
const [editKey, setEditKey] = React.useState(function () { return DRAFTS.bm ? DRAFTS.bm.bookKey : null })
|
|
1808
|
+
const [draft, setDraft] = React.useState(function () { return DRAFTS.bm ? { note: DRAFTS.bm.note || '', folders: DRAFTS.bm.folders || '' } : { note: '', folders: '' } })
|
|
1809
|
+
const editBaseRef = React.useRef(DRAFTS.bm && DRAFTS.bm.base ? DRAFTS.bm.base : null)
|
|
1810
|
+
const [editErr, setEditErr] = React.useState(null)
|
|
1811
|
+
const [editBusy, setEditBusy] = React.useState(false)
|
|
1812
|
+
const [discardAsk, setDiscardAsk] = React.useState(false)
|
|
1813
|
+
/**
|
|
1814
|
+
* ★ Spec D(2026-10-24 审查):A 还有未保存草稿时点 B 的备注,
|
|
1815
|
+
* 旧实现直接覆盖 A 的草稿(连 sessionStorage 一起换掉)。
|
|
1816
|
+
* 现在先问:「继续编辑」保 A,「放弃并切换」才换 B。
|
|
1817
|
+
*/
|
|
1818
|
+
const [switchAsk, setSwitchAsk] = React.useState(null)
|
|
1819
|
+
const [detailKey, setDetailKey] = React.useState(null)
|
|
1820
|
+
const [selectMode, setSelectMode] = React.useState(false)
|
|
1821
|
+
const [sel, setSel] = React.useState([])
|
|
1822
|
+
const [exportOpen, setExportOpen] = React.useState(false)
|
|
1823
|
+
const [scope, setScope] = React.useState('filtered')
|
|
1824
|
+
const [exporting, setExporting] = React.useState(false)
|
|
1825
|
+
const fmtS = React.useState(function () { try { return localStorage.getItem('rank-scan-panel:export:fmt:v1') || 'csv' } catch (e) { return 'csv' } })
|
|
1126
1826
|
const fmt = fmtS[0]
|
|
1127
1827
|
const setFmt = fmtS[1]
|
|
1128
|
-
const destS = React.useState('')
|
|
1828
|
+
const destS = React.useState(function () { try { return localStorage.getItem('rank-scan-panel:export:dest:v1') || '' } catch (e) { return '' } })
|
|
1129
1829
|
const dest = destS[0]
|
|
1130
1830
|
const setDest = destS[1]
|
|
1131
1831
|
const exS = React.useState(null)
|
|
@@ -1137,403 +1837,723 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1137
1837
|
const load = function () {
|
|
1138
1838
|
healStore(store)
|
|
1139
1839
|
if (typeof store.refreshList === 'function') store.refreshList().then(bump).catch(function () { bump() })
|
|
1140
|
-
if (typeof store.trashList === 'function') store.trashList().then(function (t) { setTrash(t)
|
|
1840
|
+
if (typeof store.trashList === 'function') store.trashList().then(function (t) { setTrash(t) })
|
|
1141
1841
|
}
|
|
1142
|
-
// 依赖数组里也不能直接摸 store.filters(旧闭包 + 新 store 的组合下它就是 undefined)
|
|
1143
1842
|
const flt = healStore(store).filters
|
|
1144
1843
|
React.useEffect(function () { load() }, [flt.q, flt.site, flt.folder, flt.tag])
|
|
1145
|
-
// 撤销:5 秒窗口(只在这里给;刷新页面后就靠回收站)
|
|
1146
1844
|
React.useEffect(function () {
|
|
1147
|
-
if (!undo) return
|
|
1148
|
-
// 撤销窗口 8 秒(★ 实测:5 秒在下拉/看快照的间隙里就过期了,太紧;回收站仍是兜底)
|
|
1845
|
+
if (!undo) return undefined
|
|
1149
1846
|
const t = setTimeout(function () { setUndo(null) }, 8000)
|
|
1150
1847
|
const id = setInterval(function () { setSlide(function (s) { return s >= 100 ? 100 : s + 2 }) }, 100)
|
|
1151
1848
|
return function () { clearTimeout(t); clearInterval(id) }
|
|
1152
1849
|
}, [undo])
|
|
1850
|
+
const SITE_NAME = { qidian: '起点', qidiantu: '起点图', ciweimao: '刺猬猫', sfacg: '菠萝包', fanqie: '番茄' }
|
|
1851
|
+
const siteLabel = function (s) { return SITE_NAME[s] || s }
|
|
1852
|
+
const f = flt
|
|
1853
|
+
const setF = function (patch) { healStore(store); store.filters = { ...store.filters, ...patch }; bump() }
|
|
1854
|
+
const list = (store.list && store.list.bookmarks) || []
|
|
1855
|
+
const sites = []
|
|
1856
|
+
list.forEach(function (b) { if (sites.indexOf(b.site) < 0) sites.push(b.site) })
|
|
1857
|
+
const dirtyOf = function (b) {
|
|
1858
|
+
const note0 = String(b.note || '')
|
|
1859
|
+
const fold0 = (b.folders || []).join(' ')
|
|
1860
|
+
return String(draft.note || '') !== note0 || String(draft.folders || '').replace(/\s+/g, ' ').trim() !== fold0.replace(/\s+/g, ' ').trim()
|
|
1861
|
+
}
|
|
1862
|
+
// Keep the edit baseline independent of filtered search results.
|
|
1863
|
+
const editingBook = function () {
|
|
1864
|
+
return editKey ? editBaseRef.current || list.filter(function (x) { return x.bookKey === editKey })[0] : null
|
|
1865
|
+
}
|
|
1866
|
+
const editDirty = function () {
|
|
1867
|
+
const b = editingBook()
|
|
1868
|
+
return b ? dirtyOf(b) : !!(editKey && DRAFTS.bm && DRAFTS.bm.dirty)
|
|
1869
|
+
}
|
|
1870
|
+
/** 草稿写回组件外 + 登记脏状态(面板切页/收起前据此拦一下) */
|
|
1871
|
+
React.useEffect(function () {
|
|
1872
|
+
if (!editKey) { DRAFTS.bm = null; dirtyGuard.set('bm', false); return }
|
|
1873
|
+
const b = editingBook()
|
|
1874
|
+
if (b && !editBaseRef.current) editBaseRef.current = b
|
|
1875
|
+
const dirty = editDirty()
|
|
1876
|
+
DRAFTS.bm = { bookKey: editKey, note: draft.note, folders: draft.folders, dirty: dirty, base: b || null }
|
|
1877
|
+
dirtyGuard.set('bm', dirty)
|
|
1878
|
+
}, [editKey, draft.note, draft.folders, store.total])
|
|
1879
|
+
/** 保存回调要知道「现在还在编辑哪一本」,否则会连另一本的草稿一起清掉 */
|
|
1880
|
+
const editKeyRef = React.useRef(editKey)
|
|
1881
|
+
React.useEffect(function () { editKeyRef.current = editKey }, [editKey])
|
|
1882
|
+
const applyEdit = function (b) {
|
|
1883
|
+
editBaseRef.current = { bookKey: b.bookKey, note: b.note, folders: (b.folders || []).slice() }
|
|
1884
|
+
setEditKey(b.bookKey)
|
|
1885
|
+
setDraft({ note: String(b.note || ''), folders: (b.folders || []).join(' ') })
|
|
1886
|
+
setEditErr(null)
|
|
1887
|
+
setDiscardAsk(false)
|
|
1888
|
+
setSwitchAsk(null)
|
|
1889
|
+
}
|
|
1890
|
+
const startEdit = function (b) {
|
|
1891
|
+
// 同一条重复点:保留正在写的草稿(不要用库里旧值把它清回去)
|
|
1892
|
+
if (editKey === b.bookKey) return
|
|
1893
|
+
if (editDirty()) { setDiscardAsk(false); setSwitchAsk(b); return }
|
|
1894
|
+
applyEdit(b)
|
|
1895
|
+
}
|
|
1896
|
+
const closeEdit = function () { setEditKey(null); setDraft({ note: '', folders: '' }); setEditErr(null); setDiscardAsk(false); setSwitchAsk(null) }
|
|
1897
|
+
const cancelEdit = function (b) {
|
|
1898
|
+
if (dirtyOf(b)) { setDiscardAsk(true); return }
|
|
1899
|
+
closeEdit()
|
|
1900
|
+
}
|
|
1901
|
+
const saveEdit = function (b) {
|
|
1902
|
+
const note = String(draft.note || '')
|
|
1903
|
+
const folders = String(draft.folders || '').split(/[\s,,]+/).filter(Boolean)
|
|
1904
|
+
setEditBusy(true)
|
|
1905
|
+
setEditErr(null)
|
|
1906
|
+
store.act({ action: 'update', bookKey: b.bookKey, note: note, folders: folders })
|
|
1907
|
+
.then(function () { return store.refreshList() })
|
|
1908
|
+
.then(function () {
|
|
1909
|
+
setEditBusy(false)
|
|
1910
|
+
/**
|
|
1911
|
+
* ★ Spec D:保存期间用户可能已经切到另一本书签 —— 这时只能收掉**这一本**的编辑态;
|
|
1912
|
+
* 旧实现无条件 closeEdit(),会把刚打开的 B 连同它的草稿一起清掉。
|
|
1913
|
+
*/
|
|
1914
|
+
if (editKeyRef.current === b.bookKey) closeEdit()
|
|
1915
|
+
bump()
|
|
1916
|
+
})
|
|
1917
|
+
.catch(function (e) {
|
|
1918
|
+
setEditBusy(false)
|
|
1919
|
+
if (editKeyRef.current === b.bookKey) setEditErr('保存失败:' + e + ' (草稿还在,可再试一次)')
|
|
1920
|
+
else { store.msg = '「' + (b.label || b.bookKey) + '」保存失败:' + e; bump() }
|
|
1921
|
+
})
|
|
1922
|
+
}
|
|
1153
1923
|
const doRemove = function (b) {
|
|
1154
1924
|
setSlide(0)
|
|
1925
|
+
if (editKey === b.bookKey) closeEdit()
|
|
1155
1926
|
store.act({ action: 'remove', bookKey: b.bookKey }).then(function () { setUndo(b); load() }).catch(function () {})
|
|
1156
1927
|
}
|
|
1157
1928
|
const doUndo = function () {
|
|
1158
1929
|
if (!undo) return
|
|
1159
1930
|
store.act({ action: 'restore', bookKey: undo.bookKey }).then(function () { setUndo(null); load() }).catch(function () {})
|
|
1160
1931
|
}
|
|
1161
|
-
const saveNote = function (b, note, folders) {
|
|
1162
|
-
store.act({ action: 'update', bookKey: b.bookKey, note: note, folders: folders })
|
|
1163
|
-
.then(function () { return store.refreshList() }).then(function () { setLocal({}); bump() }).catch(function () {})
|
|
1164
|
-
}
|
|
1165
1932
|
const doRefresh = function (keys) {
|
|
1166
|
-
store.msg = '
|
|
1933
|
+
store.msg = '更新中(每本 1 请求,逐本 ' + fmtIntervalText() + ')…'; bump()
|
|
1167
1934
|
jpost('/bookmark/refresh', { bookKeys: keys }).then(function (r) {
|
|
1168
|
-
store.msg = (r && r.note) || '
|
|
1935
|
+
store.msg = (r && r.note) || '已更新'
|
|
1169
1936
|
return store.refreshList()
|
|
1170
|
-
}).then(function () { bump() }).catch(function (e) { store.msg = '
|
|
1937
|
+
}).then(function () { bump() }).catch(function (e) { store.msg = '更新失败:' + e; bump() })
|
|
1171
1938
|
}
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1939
|
+
const scopeCount = function () {
|
|
1940
|
+
if (scope === 'selected') return sel.length
|
|
1941
|
+
if (scope === 'all') return store.total || list.length
|
|
1942
|
+
return list.length
|
|
1943
|
+
}
|
|
1944
|
+
const doExport = function () {
|
|
1945
|
+
const fmtV = fmt
|
|
1946
|
+
const destV = String(dest || '').trim()
|
|
1947
|
+
setExporting(true)
|
|
1948
|
+
setExMsg('导出中…')
|
|
1949
|
+
const keysP = scope === 'all'
|
|
1950
|
+
? jget('/bookmarks').then(function (r) { return ((r && r.bookmarks) || []).map(function (x) { return x.bookKey }) })
|
|
1951
|
+
: Promise.resolve(scope === 'selected' ? sel.slice() : list.map(function (b) { return b.bookKey }))
|
|
1952
|
+
keysP.then(function (keys) {
|
|
1953
|
+
if (!keys || !keys.length) { setExMsg('这个范围没有可导出的条目'); return null }
|
|
1954
|
+
try {
|
|
1955
|
+
localStorage.setItem('rank-scan-panel:export:fmt:v1', fmtV)
|
|
1956
|
+
localStorage.setItem('rank-scan-panel:export:dest:v1', destV)
|
|
1957
|
+
} catch (e) {}
|
|
1958
|
+
return jpost('/bookmark/export-file', { format: fmtV, bookKeys: keys, dest: destV || undefined })
|
|
1959
|
+
.then(function (r) { setExMsg((r && r.note) || ('已导出 ' + keys.length + ' 条')) })
|
|
1960
|
+
}).catch(function (e) { setExMsg('导出失败:' + e) }).then(function () { setExporting(false) })
|
|
1961
|
+
}
|
|
1962
|
+
const addManual = function () {
|
|
1963
|
+
jpost('/bookmark/add-manual', { input: String(manual || '').trim(), site: manualSite || undefined }).then(function (r) {
|
|
1964
|
+
store.msg = (r && r.note) || '已添加'
|
|
1965
|
+
setManual('')
|
|
1966
|
+
return store.refreshList()
|
|
1967
|
+
}).then(function () { bump() }).catch(function (e) { store.msg = '添加失败:' + e; bump() })
|
|
1968
|
+
}
|
|
1969
|
+
const collectTitle = function (b, lab) {
|
|
1970
|
+
const src = b.collectFrom === 'qidian-book-cache' ? '来自起点书页缓存(扫描后补全回填)'
|
|
1971
|
+
: b.collectFrom === 'book-page' ? '来自书页刷新'
|
|
1972
|
+
: b.collectFrom === 'snapshot' ? '来自当天榜单行'
|
|
1973
|
+
: '这个榜的榜单行里没有该数据;点「更新本书数据」可按书页取一次'
|
|
1974
|
+
return lab + ':' + fmtRead(b.collect) + ' · ' + src
|
|
1975
|
+
}
|
|
1976
|
+
const moreItems = [
|
|
1977
|
+
{ label: '批量选择', onClick: function () { setSelectMode(true) } },
|
|
1978
|
+
{ label: '导出…', onClick: function () { setExportOpen(true) } },
|
|
1979
|
+
{ label: '添加作品…', onClick: function () { setAddOpen(true) } },
|
|
1980
|
+
{ label: '刷新列表', onClick: load },
|
|
1981
|
+
{ sep: true },
|
|
1982
|
+
{ label: (showTrash ? '收起' : '打开') + '回收站(' + trash.length + ')', onClick: function () { setShowTrash(!showTrash); store.trashList().then(function (t) { setTrash(t) }) } },
|
|
1983
|
+
]
|
|
1182
1984
|
return h('div', null,
|
|
1183
1985
|
h('div', { style: C.row },
|
|
1184
|
-
h('input', { style: { ...C.input, flex: 1, minWidth: '
|
|
1986
|
+
h('input', { style: { ...C.input, flex: 1, minWidth: '130px' }, placeholder: '搜书名/作者/备注', value: f.q, onChange: function (e) { setF({ q: e.target.value }) } }),
|
|
1185
1987
|
h('select', { style: C.input, value: f.site, onChange: function (e) { setF({ site: e.target.value }) } },
|
|
1186
1988
|
h('option', { value: '' }, '全部站'), sites.map(function (s) { return h('option', { key: s, value: s }, siteLabel(s)) })),
|
|
1187
1989
|
h('select', { style: C.input, value: f.folder, onChange: function (e) { setF({ folder: e.target.value }) } },
|
|
1188
1990
|
h('option', { value: '' }, '全部夹'), (store.folders || []).map(function (x) { return h('option', { key: x, value: x }, x) })),
|
|
1189
|
-
h('button', { style: C.btn, onClick:
|
|
1190
|
-
|
|
1991
|
+
h('button', { style: filtersOpen ? C.btnOn : C.btn, onClick: function () { setFiltersOpen(!filtersOpen) }, 'aria-expanded': filtersOpen ? 'true' : 'false' }, '筛选'),
|
|
1992
|
+
h(PopMenu, { label: '更多', items: moreItems, width: 200 })),
|
|
1993
|
+
filtersOpen ? h('div', { style: { ...C.row, padding: '4px 6px', border: '1px solid rgba(128,128,128,.28)', borderRadius: '6px' } },
|
|
1994
|
+
h('span', { style: C.muted }, '标签'),
|
|
1995
|
+
h('input', { style: { ...C.input, width: '120px' }, placeholder: '#标签', value: f.tag || '', onChange: function (e) { setF({ tag: String(e.target.value).replace(/^#/, '') }) } }),
|
|
1996
|
+
(f.q || f.site || f.folder || f.tag) ? h('button', { style: C.btn, onClick: function () { setF({ q: '', site: '', folder: '', tag: '' }) } }, '清除筛选') : null,
|
|
1997
|
+
h('span', { style: C.muted }, '备注里写的 #标签 会自动出现在这里')) : null,
|
|
1998
|
+
addOpen ? h('div', { style: { ...C.card, marginTop: '4px' } },
|
|
1999
|
+
h('div', { style: C.row },
|
|
2000
|
+
h('span', { style: C.muted }, '添加作品'),
|
|
2001
|
+
h('input', { style: { ...C.input, flex: 1, minWidth: '150px' }, placeholder: '贴书页 URL 或 qidian:<书号>(纯书号请选站)', value: manual, onChange: function (e) { setManual(e.target.value) } }),
|
|
2002
|
+
h('select', { style: C.input, value: manualSite, onChange: function (e) { setManualSite(e.target.value) } },
|
|
2003
|
+
h('option', { value: '' }, '(URL 可自动识别)'),
|
|
2004
|
+
h('option', { value: 'qidian' }, '起点'), h('option', { value: 'qidiantu' }, '起点图'), h('option', { value: 'ciweimao' }, '刺猬猫'), h('option', { value: 'sfacg' }, '菠萝包'), h('option', { value: 'fanqie' }, '番茄')),
|
|
2005
|
+
h('button', { style: C.btn, disabled: !String(manual || '').trim(), onClick: addManual }, '加入书签'),
|
|
2006
|
+
h('button', { style: C.btn, onClick: function () { setAddOpen(false) } }, '收起'))) : null,
|
|
2007
|
+
switchAsk ? h('div', { style: { ...C.card, marginTop: '4px', borderColor: 'rgba(217,164,65,.55)', background: 'rgba(217,164,65,.10)' } },
|
|
2008
|
+
h('div', { style: { fontWeight: 600 } }, '「' + (switchAsk.label || switchAsk.bookKey) + '」还开着没保存的备注/夹'),
|
|
2009
|
+
h('div', { style: C.row },
|
|
2010
|
+
h('button', { style: C.btnOn, onClick: function () { setSwitchAsk(null) } }, '继续编辑'),
|
|
2011
|
+
h('button', { style: C.btn, onClick: function () { applyEdit(switchAsk) } }, '放弃并切换')),
|
|
2012
|
+
h('div', { style: C.muted }, '继续编辑:刚才写的内容还在。放弃并切换:只丢当前这条的未保存改动。')) : null,
|
|
2013
|
+
h('div', { style: C.muted }, (store.list === null ? '加载中…' : '共 ' + list.length + ' 条' + (store.total && store.total !== list.length ? '(全部 ' + store.total + ' 条,已按筛选)' : '') + ' · 不含回收站')),
|
|
1191
2014
|
store.health && store.health.error ? h('div', { style: { ...C.muted, color: '#d9534f' } }, '⚠ ' + store.health.error) : null,
|
|
1192
|
-
|
|
2015
|
+
selectMode ? h('div', { style: { ...C.row, padding: '4px 6px', border: '1px solid rgba(128,128,128,.3)', borderRadius: '6px', background: 'rgba(128,128,128,.05)' } },
|
|
2016
|
+
h('span', null, '已选 ' + sel.length + ' 条'),
|
|
2017
|
+
h('button', { style: C.btn, onClick: function () { setSel(list.map(function (b) { return b.bookKey })) } }, '全选当前筛选(' + list.length + ')'),
|
|
2018
|
+
h('button', { style: C.btn, disabled: !sel.length, onClick: function () { setSel([]) } }, '取消选择'),
|
|
2019
|
+
h('button', { style: C.btn, disabled: !sel.length, onClick: function () { setScope('selected'); setExportOpen(true) } }, '导出已选'),
|
|
2020
|
+
h('button', { style: C.btn, onClick: function () { setSelectMode(false); setSel([]) } }, '退出批量选择')) : null,
|
|
2021
|
+
exportOpen ? h('div', { style: { ...C.card, marginTop: '4px' } },
|
|
2022
|
+
h('div', { style: { fontWeight: 600 } }, '导出书签'),
|
|
2023
|
+
h('div', { style: C.row },
|
|
2024
|
+
[['selected', '已选 ' + sel.length + ' 条'], ['filtered', '当前筛选 ' + list.length + ' 条'], ['all', '全部 ' + (store.total || list.length) + ' 条']].map(function (o) {
|
|
2025
|
+
return h('label', { key: o[0], style: C.row },
|
|
2026
|
+
h('input', { type: 'radio', name: 'rs-export-scope', checked: scope === o[0], onChange: function () { setScope(o[0]) } }),
|
|
2027
|
+
h('span', null, o[1]))
|
|
2028
|
+
})),
|
|
2029
|
+
h('div', { style: C.row },
|
|
2030
|
+
h('select', { style: C.input, value: fmt, onChange: function (e) { setFmt(e.target.value) } },
|
|
2031
|
+
h('option', { value: 'csv' }, 'CSV'), h('option', { value: 'json' }, 'JSON'), h('option', { value: 'md' }, 'Markdown')),
|
|
2032
|
+
h('input', { style: { ...C.input, flex: 1, minWidth: '150px' }, placeholder: '导出目录(留空 = 默认目录)', value: dest, onChange: function (e) { setDest(e.target.value) } }),
|
|
2033
|
+
h('button', { style: C.btnOn, disabled: exporting || scopeCount() === 0, title: scopeCount() === 0 ? '这个范围没有条目' : '', onClick: doExport }, exporting ? '导出中…' : '导出 ' + scopeCount() + ' 条'),
|
|
2034
|
+
h('button', { style: C.btn, onClick: function () { jpost('/bookmark/open-folder', { path: String(dest || '').trim() || undefined }).then(function (r) { setExMsg('已打开 ' + ((r && r.opened) || '')) }).catch(function (e) { setExMsg('打不开:' + e) }) } }, '打开文件夹'),
|
|
2035
|
+
h('button', { style: C.btn, onClick: function () { setExportOpen(false) } }, '收起')),
|
|
2036
|
+
exMsg ? h('div', { style: C.muted }, String(exMsg).slice(0, 140)) : null) : null,
|
|
2037
|
+
list.length === 0 ? h('div', { style: C.muted }, store.list === null ? '' : (f.q || f.site || f.folder || f.tag ? '没有符合筛选条件的书签' : '还没有书签:在「榜单」里点书名旁的 ☆ 就能加')) : null,
|
|
1193
2038
|
list.map(function (b) {
|
|
1194
|
-
const
|
|
1195
|
-
|
|
2039
|
+
const lab = b.collectLabel || (b.site === 'fanqie' ? '在读' : '收藏')
|
|
2040
|
+
const editing = editKey === b.bookKey
|
|
2041
|
+
const noteText = String(b.note || '').replace(/\s+/g, ' ').trim()
|
|
2042
|
+
const metricText = metricChipText(b.metric, b.collect, lab)
|
|
2043
|
+
const oldMetric = b.metric && b.metric.value != null && b.metric.name === lab && b.metric.value !== b.collect ? b.metric.value : null
|
|
2044
|
+
return h('div', { key: b.bookKey, style: { ...C.card, padding: '6px 8px' } },
|
|
1196
2045
|
h('div', { style: C.row },
|
|
1197
|
-
h('input', { type: 'checkbox', style: { margin: '0 2px', flex: '0 0 auto' }, checked: sel.indexOf(b.bookKey) >= 0, onChange: function () { toggleSel(b.bookKey) } }),
|
|
2046
|
+
selectMode ? h('input', { type: 'checkbox', style: { margin: '0 2px', flex: '0 0 auto' }, checked: sel.indexOf(b.bookKey) >= 0, onChange: function () { toggleSel(b.bookKey) } }) : null,
|
|
1198
2047
|
h('span', { style: C.cardTitle }, b.label),
|
|
1199
2048
|
b.author ? h('span', { style: C.muted }, b.author) : null,
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
2049
|
+
h('span', { style: C.chip }, siteLabel(b.site)),
|
|
2050
|
+
b.collect == null
|
|
2051
|
+
? h('span', { style: { ...C.chip, opacity: 0.55 }, title: collectTitle(b, lab) }, lab + ' —')
|
|
2052
|
+
: h('span', { style: C.chip, title: collectTitle(b, lab) }, lab + ' ' + fmtRead(b.collect)),
|
|
2053
|
+
oldMetric != null ? h('span', { style: { ...C.chip, opacity: 0.8 }, title: '书签记录:最近一次自动更新时该榜的' + lab + '(与上面的实时值不是同一时点)' }, '书签记录 ' + fmtRead(oldMetric)) : null,
|
|
2054
|
+
metricText ? h('span', { style: C.chip }, metricText) : null,
|
|
2055
|
+
b.capturedAt ? h('span', { style: C.muted, title: '这张卡的数据截止到这一天' }, '截止 ' + mdOf(b.capturedAt) + (b.ageDays != null ? '(' + b.ageDays + ' 天前)' : '')) : null,
|
|
2056
|
+
b.ageDays != null && b.ageDays >= 7 ? h('span', { style: { ...C.chip, color: '#d9a441' }, title: '超过 7 天没有变新:点「更新本书数据」试试;仍不变则这个来源可能取不到数了' }, '数据已 ' + b.ageDays + ' 天未更新') : null,
|
|
1204
2057
|
b.valueFrom === 'manual' ? h('span', { style: C.chip }, '待补') : null),
|
|
1205
2058
|
h('div', { style: C.row },
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
2059
|
+
h('button', {
|
|
2060
|
+
style: { ...C.btn, border: '1px dashed rgba(128,128,128,.35)', textAlign: 'left', maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
2061
|
+
title: noteText ? '编辑备注' : '加备注',
|
|
2062
|
+
onClick: function () { startEdit(b) },
|
|
2063
|
+
}, noteText ? noteText.slice(0, 60) : '+ 备注'),
|
|
2064
|
+
(b.tags || []).map(function (t) { return h('span', { key: 't' + t, style: C.chip }, '#' + t) }),
|
|
2065
|
+
(b.folders || []).map(function (x) { return h('span', { key: 'f' + x, style: C.chip }, '夹 ' + x) })),
|
|
2066
|
+
editing ? h('div', { style: { ...C.detail, marginTop: '4px' } },
|
|
2067
|
+
h('div', { style: C.row },
|
|
2068
|
+
h('span', { style: C.muted }, '备注'),
|
|
2069
|
+
h('textarea', {
|
|
2070
|
+
rows: 2, value: draft.note, placeholder: '可用 #标签',
|
|
2071
|
+
onChange: function (e) { setDraft({ ...draft, note: e.target.value }) },
|
|
2072
|
+
style: { ...C.input, flex: 1, minWidth: '160px', resize: 'vertical', fontFamily: 'inherit' },
|
|
2073
|
+
})),
|
|
2074
|
+
h('div', { style: C.row },
|
|
2075
|
+
h('span', { style: C.muted }, '书签夹'),
|
|
2076
|
+
h('input', {
|
|
2077
|
+
style: { ...C.input, flex: 1, minWidth: '120px' }, value: draft.folders, placeholder: '空格分隔,可属于多个夹',
|
|
2078
|
+
onChange: function (e) { setDraft({ ...draft, folders: e.target.value }) },
|
|
2079
|
+
})),
|
|
2080
|
+
h('div', { style: C.row },
|
|
2081
|
+
h('button', { style: C.btnOn, disabled: editBusy, onClick: function () { saveEdit(b) } }, editBusy ? '保存中…' : '保存'),
|
|
2082
|
+
h('button', { style: C.btn, disabled: editBusy, onClick: function () { cancelEdit(b) } }, '取消'),
|
|
2083
|
+
discardAsk
|
|
2084
|
+
? h('span', { style: { ...C.row, color: '#d9a441' } },
|
|
2085
|
+
h('span', null, '放弃这些改动?'),
|
|
2086
|
+
h('button', { style: C.btn, onClick: function () { closeEdit() } }, '放弃'),
|
|
2087
|
+
h('button', { style: C.btn, onClick: function () { setDiscardAsk(false) } }, '继续编辑'))
|
|
2088
|
+
: null,
|
|
2089
|
+
editErr ? h('span', { style: { color: '#d9534f' } }, editErr) : null)) : null,
|
|
1237
2090
|
h('div', { style: C.row },
|
|
1238
|
-
h('button', { style: C.btn, onClick: function () { doRefresh([b.bookKey]) } }, '刷新'),
|
|
1239
|
-
// ★ 2026-10-16 使用方:书签卡「打开」与榜单页「书名」走同一条路 —— 首选 DSH 侧栏浏览器,服务不可见才退回新标签
|
|
1240
2091
|
h('a', { href: b.url || '#', style: { color: 'inherit', padding: '3px 8px' }, title: '在 DSH 侧栏浏览器打开', onClick: function (e) { e.preventDefault(); (props.openLink || function (u) { window.open(u, '_blank', 'noopener,noreferrer') })(b.url) } }, '打开'),
|
|
1241
|
-
h(
|
|
2092
|
+
h(PopMenu, { label: '更多', width: 190, items: [
|
|
2093
|
+
{ label: '编辑备注/夹', onClick: function () { startEdit(b) } },
|
|
2094
|
+
{ label: '更新本书数据(联网)', onClick: function () { doRefresh([b.bookKey]) }, title: '按书页取一次最新读数' },
|
|
2095
|
+
{ label: detailKey === b.bookKey ? '收起详情' : '查看详情', onClick: function () { setDetailKey(detailKey === b.bookKey ? null : b.bookKey) } },
|
|
2096
|
+
{ sep: true },
|
|
2097
|
+
{ label: '删除', onClick: function () { doRemove(b) } },
|
|
2098
|
+
] })),
|
|
2099
|
+
detailKey === b.bookKey ? h('div', { style: { ...C.detail, marginTop: '4px' } },
|
|
2100
|
+
b.firstSeen
|
|
2101
|
+
? h('div', { style: C.muted }, '首次发现:' + boardLabel(b.firstSeen.boardId) + ' 第 ' + (b.firstSeen.rank == null ? '—' : b.firstSeen.rank) + ' 名(' + b.firstSeen.dataDate + ')')
|
|
2102
|
+
: h('div', { style: C.muted }, '手动添加 · 无榜单来源'),
|
|
2103
|
+
b.source === 'manual' ? h('div', { style: C.muted }, '不在任何榜里 ⇒ 不会自动更新;点「更新本书数据」按书页取一次') : null,
|
|
2104
|
+
(b.seenBoards || []).length > 1
|
|
2105
|
+
? h('div', { style: C.muted }, '也上过:' + (b.seenBoards || []).map(function (s) { return boardLabel(s.boardId) }).join('、'))
|
|
2106
|
+
: null,
|
|
2107
|
+
h('div', { style: C.muted }, '备注与夹只由你改:任何自动更新都不会覆盖。')) : null)
|
|
1242
2108
|
}),
|
|
1243
2109
|
undo ? h('div', { style: { ...C.row, padding: '5px 7px', border: '1px solid rgba(217,164,65,.5)', borderRadius: '6px', background: 'rgba(217,164,65,.10)' } },
|
|
1244
2110
|
h('span', null, '已删除「' + undo.label + '」'),
|
|
1245
2111
|
h('button', { style: C.btnOn, onClick: doUndo }, '撤销'),
|
|
1246
2112
|
h('span', { style: C.muted }, '(8 秒内;之后可在回收站找回)')) : null,
|
|
1247
|
-
h('div', { style: {
|
|
1248
|
-
h('
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
h('
|
|
1259
|
-
h('
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
h('div', { style: { ...C.row, marginTop: '10px', flexWrap: 'wrap' } },
|
|
1269
|
-
h('span', { style: C.muted }, '导出'),
|
|
1270
|
-
h('span', { style: C.muted }, sel.length ? '已选 ' + sel.length + ' 条' : '未选(= 全部 ' + list.length + ' 条)'),
|
|
1271
|
-
h('button', { style: C.btn, onClick: function () { setSel(list.map(function (b) { return b.bookKey })) } }, '全选当前列表'),
|
|
1272
|
-
h('button', { style: C.btn, disabled: !sel.length, onClick: function () { setSel([]) } }, '清空选择'),
|
|
1273
|
-
h('button', {
|
|
1274
|
-
style: C.btn,
|
|
1275
|
-
title: '只勾选当前「站」筛选下的作品',
|
|
1276
|
-
onClick: function () { setSel(list.filter(function (b) { return !f.site || b.site === f.site }).map(function (b) { return b.bookKey })) },
|
|
1277
|
-
}, '按站全选'),
|
|
1278
|
-
h('button', {
|
|
1279
|
-
style: C.btn,
|
|
1280
|
-
title: '只勾选当前「夹」筛选下的作品',
|
|
1281
|
-
onClick: function () { setSel(list.filter(function (b) { return !f.folder || (b.folders || []).indexOf(f.folder) >= 0 }).map(function (b) { return b.bookKey })) },
|
|
1282
|
-
}, '按夹全选'),
|
|
1283
|
-
h('select', { style: C.input, value: fmt, onChange: function (e) { setFmt(e.target.value) } },
|
|
1284
|
-
h('option', { value: 'csv' }, 'CSV'), h('option', { value: 'json' }, 'JSON'), h('option', { value: 'md' }, 'Markdown')),
|
|
1285
|
-
h('input', { style: { ...C.input, flex: 1, minWidth: '180px' }, placeholder: '导出目录(默认 我的文档\\rank-scan-export)', value: dest, onChange: function (e) { setDest(e.target.value) } }),
|
|
1286
|
-
h('button', {
|
|
1287
|
-
style: C.btnOn,
|
|
1288
|
-
onClick: function () {
|
|
1289
|
-
setExMsg('导出中…')
|
|
1290
|
-
jpost('/bookmark/export-file', { format: fmt, bookKeys: sel, dest: dest.trim() || undefined })
|
|
1291
|
-
.then(function (r) { setExMsg((r && r.note) || '已导出'); return store.refreshList() })
|
|
1292
|
-
.then(function () { bump() })
|
|
1293
|
-
.catch(function (e) { setExMsg('导出失败:' + e); bump() })
|
|
1294
|
-
},
|
|
1295
|
-
}, '导出到目录'),
|
|
1296
|
-
h('button', {
|
|
1297
|
-
style: C.btn,
|
|
1298
|
-
title: '在资源管理器 / Finder 里打开导出目录',
|
|
1299
|
-
onClick: function () {
|
|
1300
|
-
jpost('/bookmark/open-folder', { path: dest.trim() || undefined })
|
|
1301
|
-
.then(function (r) { setExMsg('已打开 ' + ((r && r.opened) || '')) })
|
|
1302
|
-
.catch(function (e) { setExMsg('打不开:' + e) })
|
|
1303
|
-
},
|
|
1304
|
-
}, '打开文件夹'),
|
|
1305
|
-
exMsg ? h('span', { style: C.muted, flexBasis: '100%' }, String(exMsg).slice(0, 120)) : null,
|
|
1306
|
-
store.msg ? h('span', { style: C.muted }, store.msg) : null),
|
|
1307
|
-
h('div', { style: C.muted, marginTop: '6px' }, '书签是你的数据:独立于快照与保留策略;备注与夹不会被自动更新覆盖。'))
|
|
2113
|
+
showTrash ? h('div', { style: { marginTop: '8px', padding: '6px 8px', border: '1px solid rgba(128,128,128,.3)', borderRadius: '8px' } },
|
|
2114
|
+
h('div', { style: C.row },
|
|
2115
|
+
h('span', { style: { fontWeight: 600 } }, '回收站(' + trash.length + ')'),
|
|
2116
|
+
trash.length
|
|
2117
|
+
? (confirmPurge
|
|
2118
|
+
? h('span', { style: C.row },
|
|
2119
|
+
h('span', { style: { color: '#d9534f' } }, '清空后不可恢复,确定?'),
|
|
2120
|
+
h('button', { style: { ...C.btn, color: '#d9534f' }, onClick: function () { jpost('/bookmark', { action: 'purge', bookKeys: trash.map(function (b) { return b.bookKey }) }).then(function () { setConfirmPurge(false); load() }) } }, '确认清空'),
|
|
2121
|
+
h('button', { style: C.btn, onClick: function () { setConfirmPurge(false) } }, '取消'))
|
|
2122
|
+
: h('button', { style: C.btn, onClick: function () { setConfirmPurge(true) } }, '清空回收站'))
|
|
2123
|
+
: null),
|
|
2124
|
+
trash.length === 0 ? h('div', { style: C.muted }, '回收站是空的') : trash.map(function (b) {
|
|
2125
|
+
return h('div', { key: 'tr' + b.bookKey, style: { ...C.card, opacity: 0.8 } },
|
|
2126
|
+
h('div', { style: C.row },
|
|
2127
|
+
h('span', { style: C.cardTitle }, b.label),
|
|
2128
|
+
h('span', { style: C.muted }, '删除于 ' + String(b.deletedAt).slice(0, 10) + ' 还可找回 ' + b.daysLeft + ' 天'),
|
|
2129
|
+
h('button', { style: C.btn, onClick: function () { store.act({ action: 'restore', bookKey: b.bookKey }).then(function () { load() }).catch(function () {}) } }, '恢复')))
|
|
2130
|
+
})) : null,
|
|
2131
|
+
exMsg && !exportOpen ? h('div', { style: C.muted }, String(exMsg).slice(0, 140)) : null,
|
|
2132
|
+
store.msg ? h('div', { style: C.muted }, store.msg) : null,
|
|
2133
|
+
h('div', { style: { ...C.muted, marginTop: '6px' } }, '书签是你的数据:独立于快照与保留策略;备注与夹不会被自动更新覆盖。'))
|
|
1308
2134
|
}
|
|
2135
|
+
/**
|
|
2136
|
+
* 榜单:首屏先给作品 —— 工具栏只留 站/榜/日期/排序 + 「更多」。
|
|
2137
|
+
* · 抓取条数、扫描本榜、补全、历史直查 都收进「更多」(低频、会联网)
|
|
2138
|
+
* · 历史直查**按榜的能力**出现:只有能核对内容日期的榜才有入口
|
|
2139
|
+
* · 状态带一行写清:数据日期 · 源数据日期 · 对比基准(隔几天)· 跨期不可比
|
|
2140
|
+
* ★ 2026-10-22(B):同一天重扫会静默重读,且不重置站/榜/日期/排序/详情。
|
|
2141
|
+
*/
|
|
1309
2142
|
function BoardTab(props) {
|
|
1310
2143
|
const ov = props.ov
|
|
2144
|
+
/**
|
|
2145
|
+
* ★ 2026-10-23:可用宽度(面板宽减去正文左右 padding 与纵向滚动条)决定两件事 ——
|
|
2146
|
+
* ① 表格装几列(fitColumns,按宽装、超了从最不重要的列丢);
|
|
2147
|
+
* ② 太窄(<560)就整体换成卡片行,别硬留两列把右半屏空着。
|
|
2148
|
+
*/
|
|
2149
|
+
const avail = Math.max(320, Number(props.width) || (props.narrow ? 520 : 960))
|
|
2150
|
+
const cards = avail < 560
|
|
1311
2151
|
const sites = (ov && ov.sites) || []
|
|
1312
|
-
// 收起面板会卸载 BoardTab ⇒
|
|
2152
|
+
// 收起面板会卸载 BoardTab ⇒ 站/榜选择要持久化;日期/排序按榜各记各的
|
|
1313
2153
|
const [stSite, setStSite] = React.useState(function () { return sel.get().site })
|
|
1314
2154
|
const [bt, setBt] = React.useState(function () { return sel.get().board })
|
|
1315
|
-
const [sd, setSd] = React.useState('')
|
|
1316
|
-
const [ss, setSs] = React.useState('')
|
|
2155
|
+
const [sd, setSd] = React.useState(function () { return sel.pref(sel.get().board, 'date') })
|
|
2156
|
+
const [ss, setSs] = React.useState(function () { return sel.pref(sel.get().board, 'sort') })
|
|
1317
2157
|
const [data, setData] = React.useState(null)
|
|
2158
|
+
const [err, setErr] = React.useState(null)
|
|
1318
2159
|
const [pick, setPick] = React.useState(null)
|
|
1319
2160
|
const [depth, setDepth] = React.useState('')
|
|
1320
2161
|
const [info, setInfo] = React.useState({ max: 100, can: true, hint: '' })
|
|
1321
|
-
const [
|
|
1322
|
-
const [
|
|
2162
|
+
const [busy, setBusy] = React.useState(false)
|
|
2163
|
+
const [note, setNote] = React.useState(null)
|
|
1323
2164
|
const [qDate, setQDate] = React.useState('')
|
|
2165
|
+
/**
|
|
2166
|
+
* ★ Spec A/B(2026-10-24 审查):
|
|
2167
|
+
* · loadNonce —— 即使 sd/ss 本来就是空的,「回到最新」也必须真的重发一次 GET;
|
|
2168
|
+
* · directQ —— 直查视图是**站点历史**,不是本地快照:它有自己的元数据,
|
|
2169
|
+
* 也不能被本地快照的修订号静默替换掉。
|
|
2170
|
+
*/
|
|
2171
|
+
const [loadNonce, setLoadNonce] = React.useState(0)
|
|
2172
|
+
const [directQ, setDirectQ] = React.useState(null)
|
|
2173
|
+
const skipAutoKey = React.useRef('')
|
|
2174
|
+
// 读取序号:只有最后一次发起的请求允许写界面(防旧响应覆盖)
|
|
2175
|
+
const loadSeqRef = React.useRef(0)
|
|
2176
|
+
const catSeqRef = React.useRef(0)
|
|
1324
2177
|
const curSite = stSite || (sites[0] && sites[0].site)
|
|
1325
2178
|
const curBoards = ((sites.filter(function (s) { return s.site === curSite })[0] || {}).boards) || []
|
|
1326
2179
|
const curBoard = bt || (curBoards[0] && curBoards[0].boardId)
|
|
1327
|
-
// 派生榜(本地按区间算):没有快照日期 ⇒ 隐藏「日期」下拉;总是显示最新一期
|
|
1328
2180
|
const isDerived = String(curBoard || '').indexOf('fanqie.derived.') === 0
|
|
1329
|
-
const curMeta = curBoards.filter(function (b) { return b.boardId === curBoard })[0] || {}
|
|
1330
|
-
const mainLabel = curMeta.mainLabel || '名次'
|
|
1331
|
-
// 排序项由宿主按「这个榜真有什么」给出;再按当前列集合过滤一次(没有的列不给排)
|
|
1332
2181
|
const colKeys = ((data && data.columns) || []).map(function (c) { return c.key })
|
|
1333
2182
|
const sortOpts = ((data && data.sortOptions) || [{ value: '', label: '默认' }, { value: 'rank', label: '名次' }])
|
|
1334
2183
|
.filter(function (o) { return !o.value || o.value === 'rank' || colKeys.indexOf(o.value) >= 0 })
|
|
1335
|
-
//
|
|
1336
|
-
// 之前用全局 ov.dates ⇒ 给某个榜点一次历史查询,那个日期就出现在所有站点的下拉里(使用方 2026-10-15 反馈)。
|
|
2184
|
+
// 日期下拉只用**这个榜自己**有快照的日期(/board 回的 data.dates)
|
|
1337
2185
|
const allDates = (data && data.dates && data.dates.length ? data.dates : [])
|
|
1338
2186
|
const dateOpts = [{ value: '', label: '最新' }].concat(allDates.slice().reverse().map(function (d) { return { value: d, label: d } }))
|
|
1339
2187
|
React.useEffect(function () {
|
|
2188
|
+
const my = ++catSeqRef.current
|
|
1340
2189
|
jget('/catalog').then(function (c) {
|
|
2190
|
+
if (my !== catSeqRef.current) return // 已经换榜了:这份回答作废
|
|
1341
2191
|
const v = (c.depths || {})[curBoard]
|
|
1342
2192
|
const b = (c.boards || []).filter(function (x) { return x.boardId === curBoard })[0] || {}
|
|
1343
|
-
// 没配过就显示该站默认(番茄/刺猬猫 30),而不是空着
|
|
1344
2193
|
setDepth(v != null ? String(v) : (b.depth != null ? String(b.depth) : ''))
|
|
1345
2194
|
setInfo({ depth: v != null ? v : null, max: b.maxDepth || 100, can: b.canDepth !== false, hint: b.depthHint || '' })
|
|
1346
2195
|
}).catch(function () {})
|
|
1347
2196
|
}, [curBoard])
|
|
1348
|
-
|
|
2197
|
+
/**
|
|
2198
|
+
* silent=true:同日重扫后的静默重读(保留详情卡与选择)。
|
|
2199
|
+
* ★ 2026-10-22(并发):每次读都领一个序号,回来时序号已经不是最新的就**丢掉** ——
|
|
2200
|
+
* 否则快切榜/快改日期时,先发的旧请求后到,会把新榜的数据覆盖掉。
|
|
2201
|
+
*/
|
|
2202
|
+
const reloadBoard = React.useCallback(function (silent) {
|
|
1349
2203
|
if (!curBoard) return
|
|
2204
|
+
const my = ++loadSeqRef.current
|
|
1350
2205
|
const q = '/board?boardId=' + encodeURIComponent(curBoard) + (sd ? '&date=' + sd : '') + (ss ? '&sort=' + ss : '')
|
|
1351
|
-
jget(q).then(function (d) {
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
2206
|
+
jget(q).then(function (d) {
|
|
2207
|
+
if (my !== loadSeqRef.current) return
|
|
2208
|
+
setData(d); setDirectQ(null); setErr(null); if (!silent) setPick(null)
|
|
2209
|
+
})
|
|
2210
|
+
// 读失败**保留现有列表**,只在上方报错(不能清空界面伪装成「没有条目」)
|
|
2211
|
+
.catch(function (e) { if (my !== loadSeqRef.current) return; setErr(String(e)) })
|
|
2212
|
+
}, [curBoard, sd, ss, loadNonce])
|
|
2213
|
+
React.useEffect(function () {
|
|
2214
|
+
const key = [curBoard, sd, ss].join('|')
|
|
2215
|
+
const skip = skipAutoKey.current === key
|
|
2216
|
+
skipAutoKey.current = ''
|
|
2217
|
+
if (!skip) reloadBoard(false)
|
|
2218
|
+
}, [reloadBoard])
|
|
2219
|
+
// 同日重扫:修订号变了就静默重读一次(不动站/榜/日期/排序/详情)
|
|
2220
|
+
const revRef = React.useRef(null)
|
|
2221
|
+
React.useEffect(function () {
|
|
2222
|
+
const rev = props.rev || ''
|
|
2223
|
+
if (revRef.current === null) { revRef.current = rev; return }
|
|
2224
|
+
if (rev !== revRef.current) {
|
|
2225
|
+
revRef.current = rev
|
|
2226
|
+
// 正在看站点历史时,本地快照变了不能把它悄悄换成「最新」(否则横幅没了、行也换了)
|
|
2227
|
+
if (!directQ) reloadBoard(true)
|
|
2228
|
+
}
|
|
2229
|
+
}, [props.rev, reloadBoard, directQ])
|
|
1355
2230
|
const selXS = function (label, value, options, onChange) {
|
|
1356
2231
|
return h('label', { style: C.row }, h('span', { style: C.muted }, label),
|
|
1357
2232
|
h('select', { value: value, onChange: function (e) { onChange(e.target.value) }, style: C.btn },
|
|
1358
2233
|
options.map(function (o) { return h('option', { key: o.value, value: o.value }, o.label) })))
|
|
1359
2234
|
}
|
|
1360
|
-
|
|
1361
|
-
const
|
|
2235
|
+
const pickBoard = function (v) { sel.set({ board: v }); setBt(v); setSd(sel.pref(v, 'date')); setSs(sel.pref(v, 'sort')); setPick(null) }
|
|
2236
|
+
const pickSite = function (v) { sel.set({ site: v, board: null }); setStSite(v); setBt(null); setSd(''); setSs(''); setPick(null) }
|
|
2237
|
+
const pickDate = function (v) { setSd(v); sel.setPref(curBoard, 'date', v) }
|
|
2238
|
+
const pickSort = function (v) { setSs(v); sel.setPref(curBoard, 'sort', v) }
|
|
2239
|
+
/** 只保存条数(**不采集**);另有一个明确的「保存并扫描本榜」 */
|
|
2240
|
+
const saveDepth = function (alsoScan) {
|
|
1362
2241
|
const n = Math.max(1, Math.min(info.max || 100, Number(depth) || 10))
|
|
1363
|
-
|
|
1364
|
-
|
|
2242
|
+
setBusy(true)
|
|
2243
|
+
setNote('正在保存每榜取数 ' + n + ' 条…')
|
|
1365
2244
|
jpost('/depth', { boardId: curBoard, depth: n })
|
|
1366
|
-
.then(function () {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
2245
|
+
.then(function (r) {
|
|
2246
|
+
setNote((r && r.note) || ('已保存:每榜取 ' + n + ' 条'))
|
|
2247
|
+
if (!alsoScan) return null
|
|
2248
|
+
setNote('已保存 ' + n + ' 条,正在扫描本榜…')
|
|
2249
|
+
return jpost('/scan', { boards: curBoard }).then(function (rr) {
|
|
2250
|
+
const got = ((rr && rr.boards) || []).map(function (x) { return x.boardId + ' ' + x.rows + ' 条' }).join('')
|
|
2251
|
+
setNote('已保存并扫描:' + (got || '完成'))
|
|
2252
|
+
return reloadBoard(true)
|
|
2253
|
+
}).catch(function (e2) {
|
|
2254
|
+
// ★ 保存成功、采集失败要**分开说**,否则用户会以为设置没存住、反复点
|
|
2255
|
+
setNote('条数已保存,但扫描失败:' + e2 + '(可稍后重试扫描)')
|
|
2256
|
+
})
|
|
2257
|
+
})
|
|
2258
|
+
.catch(function (e) { setNote('保存失败:' + e) })
|
|
2259
|
+
.then(function () { setBusy(false) })
|
|
2260
|
+
}
|
|
2261
|
+
const scanBoard = function () {
|
|
2262
|
+
setBusy(true)
|
|
2263
|
+
setNote('正在扫描本榜…')
|
|
2264
|
+
jpost('/scan', { boards: curBoard })
|
|
2265
|
+
.then(function (rr) {
|
|
2266
|
+
const b0 = ((rr && rr.boards) || [])[0]
|
|
2267
|
+
setNote(b0 ? '已扫描:' + b0.boardId + ' ' + b0.rows + ' 条' : '已扫描')
|
|
2268
|
+
return reloadBoard(true)
|
|
2269
|
+
})
|
|
2270
|
+
.catch(function (e) { setNote('扫描失败:' + e) })
|
|
2271
|
+
.then(function () { setBusy(false) })
|
|
1370
2272
|
}
|
|
1371
2273
|
const doEnrich = function () {
|
|
1372
|
-
|
|
1373
|
-
|
|
2274
|
+
setBusy(true)
|
|
2275
|
+
setNote('补全中(逐本请求 + ' + fmtIntervalText() + ',可能要几十秒)…')
|
|
1374
2276
|
jpost('/enrich?boardId=' + encodeURIComponent(curBoard)).then(function (r) {
|
|
1375
|
-
|
|
1376
|
-
return reloadBoard()
|
|
1377
|
-
}).catch(function (e) {
|
|
2277
|
+
setNote(r && r.note ? r.note : '补全完成')
|
|
2278
|
+
return reloadBoard(true)
|
|
2279
|
+
}).catch(function (e) { setNote('补全失败:' + e) }).then(function () { setBusy(false) })
|
|
1378
2280
|
}
|
|
1379
|
-
/**
|
|
2281
|
+
/**
|
|
2282
|
+
* 按日期回看:只在**支持核对的榜**出现(能力驱动)。
|
|
2283
|
+
* 首订榜的站点口径是 n-1(上架 24 小时后才结算),所以「上架日」与「数据日期」不是一回事,
|
|
2284
|
+
* 这里把两者分开写,不让用户以为选的是同一个日子。
|
|
2285
|
+
*/
|
|
1380
2286
|
const queryDay = function (save) {
|
|
1381
|
-
if (!qDate) {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
2287
|
+
if (!qDate) { setNote('先选上架日'); return }
|
|
2288
|
+
// ★ 上架日 X ⇒ 数据日期 X+1(首订按 n-1 锚;适配器 contentDateFor(数据日) = 数据日-1)
|
|
2289
|
+
const dDate = addDaysStr(qDate, 1)
|
|
2290
|
+
if (!dDate) { setNote('日期格式不对:应为 YYYY-MM-DD'); return }
|
|
2291
|
+
const my = ++loadSeqRef.current
|
|
2292
|
+
setBusy(true)
|
|
2293
|
+
setNote((save ? '抓取' : '查看') + '上架日 ' + qDate + '(数据日期 ' + dDate + ')…')
|
|
2294
|
+
jpost('/day', { boardId: curBoard, date: dDate, save: !!save }).then(function (r) {
|
|
2295
|
+
if (my !== loadSeqRef.current) return null
|
|
2296
|
+
if (r && (r.ok === false || r.code)) {
|
|
2297
|
+
setNote('已拒绝:' + (r.error || '站点给不出这一天可核对的数据'))
|
|
1391
2298
|
return null
|
|
1392
2299
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
2300
|
+
const shown = (r && r.date) || dDate
|
|
2301
|
+
setNote(r && r.note ? r.note : (save ? '已抓取:上架日 ' + qDate + ' 存为数据日期 ' + dDate + ' 的快照' : '已查看(未落盘)'))
|
|
2302
|
+
if (save) { setDirectQ(null); setSd(shown); sel.setPref(curBoard, 'date', shown); setLoadNonce(function (n) { return n + 1 }); return null }
|
|
2303
|
+
/**
|
|
2304
|
+
* ★ Spec B(2026-10-24):直查视图是一份**独立**数据。
|
|
2305
|
+
* 旧实现用 { ...prev } 合并 ⇒ 沿用上一视图的 baselineDate / counts / enrich / fallbackFrom,
|
|
2306
|
+
* 于是出现「数据日期 10-19 · 对比 10-21」(基准晚于数据日)却变化列全「—」。
|
|
2307
|
+
* 现在显式给全自己的元数据,没基准就明说「无可比基准」。
|
|
2308
|
+
*/
|
|
2309
|
+
const prev = data || {}
|
|
2310
|
+
const ds = (prev.dates || []).slice()
|
|
2311
|
+
if (ds.indexOf(shown) < 0) ds.push(shown)
|
|
2312
|
+
ds.sort()
|
|
2313
|
+
// Skip only the local read caused by clearing this query's sort.
|
|
2314
|
+
if (ss) skipAutoKey.current = [curBoard, sd, ''].join('|')
|
|
1397
2315
|
setSs('')
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
/** 番茄全部已抓分类:逐榜补,**显示进度**(每本 1 请求 + 当前请求间隔,榜多就慢) */
|
|
1417
|
-
const doEnrichFanqie = function () {
|
|
1418
|
-
setEnrichBusy(true)
|
|
1419
|
-
jget('/catalog').then(function (cat) {
|
|
1420
|
-
const ids = (cat.captures || []).filter(function (x) { return x.indexOf('fanqie.m.') === 0 })
|
|
1421
|
-
if (!ids.length) { setEnrichNote('抓取集里没有番茄分类榜'); setEnrichBusy(false); return null }
|
|
1422
|
-
let done = 0
|
|
1423
|
-
let filled = 0
|
|
1424
|
-
let seq = Promise.resolve()
|
|
1425
|
-
ids.forEach(function (id) {
|
|
1426
|
-
seq = seq.then(function () {
|
|
1427
|
-
setEnrichNote('番茄补全中 ' + done + '/' + ids.length + ' 个榜(' + id + ')…')
|
|
1428
|
-
return jpost('/enrich?boardId=' + encodeURIComponent(id)).then(function (r) {
|
|
1429
|
-
done += 1
|
|
1430
|
-
filled += (r && r.filled) || 0
|
|
1431
|
-
if (r && r.learned) setEnrichNote('番茄 ' + done + '/' + ids.length + ':字体映射已学到 ' + r.learned + ' 字')
|
|
1432
|
-
}).catch(function () { done += 1 })
|
|
1433
|
-
})
|
|
2316
|
+
setPick(null)
|
|
2317
|
+
setData({
|
|
2318
|
+
boardId: curBoard,
|
|
2319
|
+
columns: prev.columns || [],
|
|
2320
|
+
sortOptions: prev.sortOptions || [],
|
|
2321
|
+
rows: (r.rowsAll || []).map(function (x) { return { ...x, delta: null, days: null } }),
|
|
2322
|
+
dates: ds,
|
|
2323
|
+
dataDate: shown,
|
|
2324
|
+
baselineDate: null,
|
|
2325
|
+
counts: null,
|
|
2326
|
+
crossPeriod: false,
|
|
2327
|
+
enrich: null,
|
|
2328
|
+
fallbackFrom: null,
|
|
2329
|
+
requestedDate: null,
|
|
2330
|
+
source: '站点直查(未落盘)',
|
|
2331
|
+
note: '直查站点 ' + shown + (r.contentDate && r.contentDate !== shown ? '(站点内容日期 ' + r.contentDate + ')' : ''),
|
|
2332
|
+
_queryDate: shown,
|
|
2333
|
+
_contentDate: (r && r.contentDate) || null,
|
|
1434
2334
|
})
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
2335
|
+
setDirectQ({ date: shown })
|
|
2336
|
+
}).catch(function (e) { setNote('直查失败:' + e) }).then(function () { setBusy(false) })
|
|
2337
|
+
}
|
|
2338
|
+
// Esc:先关详情卡(面板本身由 Panel 那层关)
|
|
2339
|
+
useEscLayer(pick ? function () { setPick(null); return true } : null)
|
|
2340
|
+
/** 状态带:一行说清「你在看哪份数据、跟哪天比」 */
|
|
2341
|
+
const band = (function () {
|
|
2342
|
+
if (!data) return null
|
|
2343
|
+
const bits = []
|
|
2344
|
+
const src = data._contentDate || (data.rows && data.rows[0] && data.rows[0].extra && data.rows[0].extra.showDate) || null
|
|
2345
|
+
bits.push('数据日期 ' + (data.dataDate || '—'))
|
|
2346
|
+
// 首订是 n-1 口径:直查时「内容日期(上架日)」与「数据日期」必须分开写清楚
|
|
2347
|
+
if (src && src !== data.dataDate) bits.push((data._queryDate ? '内容日期 ' : '源数据 ') + src)
|
|
2348
|
+
/** Spec S7:首订榜整批换的是「本期上架作品」,不标清会被读成榜单竞争意义的新入榜 */
|
|
2349
|
+
if (String(curBoard || '').indexOf('qidiantu.shouding') === 0) {
|
|
2350
|
+
bits.push('本期上架作品' + (src ? '(上架日 ' + src + ')' : '') + ' · 首订 = 上架后首订')
|
|
2351
|
+
}
|
|
2352
|
+
if (data.baselineDate) {
|
|
2353
|
+
const g = data.dataDate ? dayGap(data.baselineDate, data.dataDate) : null
|
|
2354
|
+
bits.push('对比 ' + data.baselineDate + (g && g > 1 ? '(隔 ' + g + ' 天,变化是累计值)' : ''))
|
|
2355
|
+
} else bits.push('无可比基准(不报 0)')
|
|
2356
|
+
const crossed = !!(data.rows && data.rows[0] && data.rows[0].extra && data.rows[0].extra.periodChanged)
|
|
2357
|
+
if (crossed) bits.push('新期:变化不可比')
|
|
2358
|
+
return bits.join(' · ')
|
|
2359
|
+
})()
|
|
2360
|
+
const enrichMissing = data && data.enrich && data.enrich.missing > 0 ? data.enrich.missing : 0
|
|
2361
|
+
// 减掉正文左右 padding(20)、纵向滚动条与一点余量 ⇒ 表格不会溢出成横向滚动
|
|
2362
|
+
const cols = fitColumns(data && data.columns, avail - 48)
|
|
2363
|
+
const viewDate = (data && (data._queryDate || sd)) || ''
|
|
2364
|
+
const menuItems = [
|
|
2365
|
+
{ label: '扫描本榜(联网)', disabled: busy, onClick: scanBoard, title: '只抓当前这一榜,不动其它榜' },
|
|
2366
|
+
{ sep: true },
|
|
2367
|
+
{
|
|
2368
|
+
rows: h('div', null,
|
|
2369
|
+
h('div', { style: { ...C.muted, marginBottom: '3px' } }, '每榜取多少条'),
|
|
2370
|
+
h('div', { style: C.row },
|
|
2371
|
+
h('input', {
|
|
2372
|
+
type: 'number', min: 1, max: info.max, value: depth, placeholder: String(info.max), disabled: !info.can,
|
|
2373
|
+
title: info.hint, onChange: function (e) { setDepth(e.target.value) },
|
|
2374
|
+
style: { width: '58px', fontSize: '12px', padding: '2px 4px' },
|
|
2375
|
+
}),
|
|
2376
|
+
h('span', { style: C.muted }, info.can ? '条(上限 ' + info.max + ')' : '条 · ' + info.hint),
|
|
2377
|
+
h('button', { style: C.btn, disabled: !info.can || busy, onClick: function () { saveDepth(false) }, title: '只保存,下次扫描生效' }, '保存'),
|
|
2378
|
+
h('button', { style: C.btn, disabled: !info.can || busy, onClick: function () { saveDepth(true) }, title: '保存后立刻抓一次这一榜(会联网)' }, '保存并扫描本榜'))),
|
|
2379
|
+
},
|
|
2380
|
+
{ sep: true },
|
|
2381
|
+
{
|
|
2382
|
+
label: enrichMissing ? '补全缺失字段(' + enrichMissing + ' 条)' : '补全缺失字段(当前没有待补)',
|
|
2383
|
+
disabled: busy || !enrichMissing,
|
|
2384
|
+
onClick: doEnrich,
|
|
2385
|
+
title: '只补当前这一榜还没取到的字段(收藏/字数等),可能走书页缓存',
|
|
2386
|
+
},
|
|
2387
|
+
// 补全没跑完必须可见(别让「有行但字段空」静默)
|
|
2388
|
+
enrichMissing ? { rows: h('div', { style: C.muted }, '补全未完成:还缺 ' + enrichMissing + ' 条(补全没跑完或被中断;点上面重试,或等定时续跑)') } : null,
|
|
2389
|
+
]
|
|
2390
|
+
if (canDayQuery(curBoard)) {
|
|
2391
|
+
menuItems.push({ sep: true })
|
|
2392
|
+
menuItems.push({
|
|
2393
|
+
rows: h('div', null,
|
|
2394
|
+
h('div', { style: { ...C.muted, marginBottom: '3px' } }, '按上架日回看(仅本榜支持核对)'),
|
|
2395
|
+
h('div', { style: C.row },
|
|
2396
|
+
h('input', { type: 'date', value: qDate, onChange: function (e) { setQDate(e.target.value) }, style: { fontSize: '12px', padding: '2px 4px' } }),
|
|
2397
|
+
h('button', { style: C.btn, disabled: busy || !qDate, onClick: function () { queryDay(false) } }, '查看'),
|
|
2398
|
+
h('button', { style: C.btn, disabled: busy || !qDate, onClick: function () { queryDay(true) }, title: '抓取该上架日并存为本地快照(已有快照不覆盖)' }, '存入本地')),
|
|
2399
|
+
h('div', { style: { ...C.muted, marginTop: '2px' } }, '首订按 n-1 锚:选上架日 X ⇒ 请求数据日期 X+1(页面内容日期就是 X);保存后快照记在 X+1 名下。站点给的日期对不上会被拒绝,不写任何文件。')),
|
|
2400
|
+
})
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* ★ 2026-10-23(窄面板「作品只显示书名前面的信息,后面一大片空白」):
|
|
2404
|
+
* 以前窄的时候是把次级列**整列删掉**、再让表格 width:100% 铺满 ⇒ 每行只剩名次 + 书名,
|
|
2405
|
+
* 右半张桌子全空,被删掉的指标也没有别处可看。窄的时候改成**卡片行**:
|
|
2406
|
+
* 第一行 名次 · 书名 · 作者 · 星标;第二行把这一榜要看的指标做成 chip(放不下自动换行)。
|
|
2407
|
+
*/
|
|
2408
|
+
const CHIP_SKIP = { title: 1, rank: 1, author: 1, cat: 1, subCat: 1, updated: 1, days: 1 }
|
|
2409
|
+
const chipCols = ((data && data.columns) || []).filter(function (c) { return !CHIP_SKIP[c.key] }).slice(0, 6)
|
|
2410
|
+
/** 该行是否正展开详情 */
|
|
2411
|
+
/**
|
|
2412
|
+
* ★ Spec C(2026-10-24 审查):窄窗/装列时被收起的列必须**显式可展开**。
|
|
2413
|
+
* 旧实现把列从表格里丢掉就没有任何入口(起点的分类/子分类、在榜天数、三江第 7 列起的逐日
|
|
2414
|
+
* 增量只能靠拉宽面板看)。这里算出「当前视图没显示的列」,在行详情里用**同一套 cell 渲染器**
|
|
2415
|
+
* 补全 —— 不截断真实字段,也不改现有列宽/收起策略。
|
|
2416
|
+
*/
|
|
2417
|
+
const SUMMARY_COLS = { title: 1, rank: 1, author: 1, words: 1, updated: 1 }
|
|
2418
|
+
const shownColKeys = (function () {
|
|
2419
|
+
const m = {}
|
|
2420
|
+
if (cards) {
|
|
2421
|
+
m.title = 1; m.rank = 1; m.author = 1
|
|
2422
|
+
chipCols.forEach(function (c) { m[c.key] = 1 })
|
|
2423
|
+
} else {
|
|
2424
|
+
cols.forEach(function (c) { m[c.key] = 1 })
|
|
2425
|
+
}
|
|
2426
|
+
return m
|
|
2427
|
+
})()
|
|
2428
|
+
const detailCols = ((data && data.columns) || []).filter(function (c) {
|
|
2429
|
+
return !shownColKeys[c.key] && !SUMMARY_COLS[c.key]
|
|
2430
|
+
})
|
|
2431
|
+
const isOpen = function (r) { return !!(pick && pick.key === r.key) }
|
|
2432
|
+
/**
|
|
2433
|
+
* ★ 2026-10-23(点了没反应):详情卡原来挂在**整张列表之后** ⇒ 列表一长就在视口外
|
|
2434
|
+
* (实测 820×640 面板:详情卡 top=738、可视区底 731,根本没进画面)。
|
|
2435
|
+
* 现在改成「点哪一行,详情就展开在哪一行下面」。
|
|
2436
|
+
*/
|
|
2437
|
+
const detailCard = function (r) {
|
|
2438
|
+
const ex = r.extra || {}
|
|
2439
|
+
return h('div', { style: { ...C.detail, marginTop: '4px' } },
|
|
2440
|
+
h('div', { style: { fontWeight: 600 } }, dash(r.title)),
|
|
2441
|
+
h('div', { style: C.muted }, '作者 ' + dash(r.author) + ' · 名次 ' + dash(r.rank) + ' · 字数 ' + fmtWords(ex.wordsText || ex.wordsCnt || ex.wordNumber || ex.words)),
|
|
2442
|
+
h('div', { style: C.muted }, '更新 ' + fmtTime(ex.lastChapterUpdateTime)),
|
|
2443
|
+
// 被当前宽度收起的列:在这里逐条列出(label + 与表格完全相同的渲染)
|
|
2444
|
+
detailCols.length ? h('div', { style: { marginTop: '3px' } }, detailCols.map(function (c) {
|
|
2445
|
+
return h('div', { key: 'dx-' + c.key, style: C.muted }, c.label + ':', cell(rowCellProps(r, c), r))
|
|
2446
|
+
})) : null,
|
|
2447
|
+
h('div', { style: C.row },
|
|
2448
|
+
h(BookmarkStar, { bookKey: bookKeyOf(curBoard, r.key), row: r, boardId: curBoard, dataDate: data && data.dataDate }),
|
|
2449
|
+
h(DetailBookmarkEditor, { bookKey: bookKeyOf(curBoard, r.key) }),
|
|
2450
|
+
h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); if (props.openLink) props.openLink(r.url); else window.open(r.url, '_blank', 'noopener,noreferrer') } }, '在 DSH 侧栏浏览器打开'),
|
|
2451
|
+
h('a', { href: r.url || '#', target: '_blank', rel: 'noreferrer', style: { color: 'inherit', padding: '3px 8px' }, onClick: function (e) { e.stopPropagation() } }, '新标签打开'),
|
|
2452
|
+
h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); try { navigator.clipboard.writeText(r.url || '') } catch (err) {} } }, '复制链接'),
|
|
2453
|
+
h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); setPick(null) } }, '关闭')),
|
|
2454
|
+
ex.qidiantuUrl || ex.sourceUrl
|
|
2455
|
+
? h('div', { style: C.row },
|
|
2456
|
+
(ex.qidiantuUrl ? h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); (props.openLink || window.open)(ex.qidiantuUrl) } }, '看起点图原始页') : null),
|
|
2457
|
+
(ex.sourceUrl ? h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); (props.openLink || window.open)(ex.sourceUrl) } }, '看原数据来源页') : null),
|
|
2458
|
+
h('span', { style: C.muted }, '(数据口径以来源页为准)'))
|
|
2459
|
+
: null)
|
|
2460
|
+
}
|
|
2461
|
+
const rowCellProps = function (r, c) {
|
|
2462
|
+
return { ...c, _openLink: props.openLink, _boardId: data.boardId, _dataDate: data.dataDate, _bmKey: bookKeyOf(data.boardId, r.key) }
|
|
2463
|
+
}
|
|
2464
|
+
const narrowRow = function (r, i) {
|
|
2465
|
+
const open = !!(pick && pick.key === r.key)
|
|
2466
|
+
const ex = r.extra || {}
|
|
2467
|
+
const titleText = (r.title || '') + (ex.titleSuspect || ex.titleTruncated ? ' ⚠' : '')
|
|
2468
|
+
const chips = chipCols.map(function (c) {
|
|
2469
|
+
const v = cell(rowCellProps(r, c), r)
|
|
2470
|
+
if (v === '—' || v === null || v === undefined || v === '') return null
|
|
2471
|
+
return h('span', { key: 'c' + c.key, style: C.chip, title: c.note || c.label },
|
|
2472
|
+
h('span', { style: { opacity: 0.62 } }, c.label), ' ', v)
|
|
2473
|
+
}).filter(Boolean)
|
|
2474
|
+
return h('div', {
|
|
2475
|
+
key: r.key || ('row' + i),
|
|
2476
|
+
tabIndex: 0,
|
|
2477
|
+
style: { ...C.card, padding: '5px 8px', margin: '5px 0', cursor: 'pointer',
|
|
2478
|
+
borderColor: open ? 'rgba(128,128,128,.62)' : undefined,
|
|
2479
|
+
background: open ? 'rgba(128,128,128,.10)' : undefined },
|
|
2480
|
+
onClick: function () { setPick(open ? null : r) },
|
|
2481
|
+
onKeyDown: function (e) { if (e && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); setPick(open ? null : r) } },
|
|
2482
|
+
},
|
|
2483
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '5px', minWidth: 0 } },
|
|
2484
|
+
h('span', { style: { ...C.num, ...C.muted, flex: '0 0 auto', minWidth: '16px', textAlign: 'right' } }, dash(r.rank)),
|
|
2485
|
+
h('a', {
|
|
2486
|
+
href: r.url || '#', title: '在 DSH 侧栏浏览器打开',
|
|
2487
|
+
style: { color: 'inherit', fontWeight: 600, flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
2488
|
+
onClick: function (e) { e.preventDefault(); e.stopPropagation(); (props.openLink || function (u) { window.open(u, '_blank', 'noopener,noreferrer') })(r.url) },
|
|
2489
|
+
}, titleText),
|
|
2490
|
+
r.author ? h('span', { style: { ...C.muted, flex: '0 0 auto', maxWidth: '92px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: r.author }, r.author) : null,
|
|
2491
|
+
h(BookmarkStar, { bookKey: bookKeyOf(data.boardId, r.key), row: r, boardId: data.boardId, dataDate: data.dataDate })),
|
|
2492
|
+
chips.length ? h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '4px', marginTop: '3px' } }, chips) : null)
|
|
1440
2493
|
}
|
|
1441
2494
|
return h('div', null,
|
|
1442
2495
|
h('div', { style: C.row },
|
|
1443
|
-
selXS('站', curSite || '', sites.map(function (s) { return { value: s.site, label: s.siteName } }),
|
|
1444
|
-
selXS('榜', curBoard || '', curBoards.map(function (b) { return { value: b.boardId, label: b.name } }),
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
h('div', { style: C.
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
h('span', { style:
|
|
1452
|
-
h('button', { style: C.btn, disabled:
|
|
1453
|
-
h('
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
: null,
|
|
2496
|
+
selXS('站', curSite || '', sites.map(function (s) { return { value: s.site, label: s.siteName } }), pickSite),
|
|
2497
|
+
selXS('榜', curBoard || '', curBoards.map(function (b) { return { value: b.boardId, label: b.name } }), pickBoard),
|
|
2498
|
+
isDerived ? null : selXS('日期', sd, dateOpts, pickDate),
|
|
2499
|
+
selXS('排序', ss, sortOpts, pickSort),
|
|
2500
|
+
h(PopMenu, { label: '更多', items: menuItems, width: 260, title: '采集与详情(低频操作)' })),
|
|
2501
|
+
band ? h('div', { style: { ...C.muted, marginTop: '2px' } }, band) : null,
|
|
2502
|
+
/* Spec 4.2:补全缺多少条要**就近可见**,别只藏在「更多」菜单里 */
|
|
2503
|
+
enrichMissing ? h('div', { style: { ...C.row, marginTop: '2px' } },
|
|
2504
|
+
h('span', { style: { color: '#d9a441' } }, '补全未完成:还缺 ' + enrichMissing + ' 条字段'),
|
|
2505
|
+
h('button', { style: C.btn, disabled: busy, onClick: doEnrich }, '补全'),
|
|
2506
|
+
h('span', { style: C.muted }, '(榜页没给收藏/字数,要进书页取;1 秒/本)')) : null,
|
|
2507
|
+
viewDate ? h('div', { style: { ...C.row, alignItems: 'center', gap: '6px', padding: '4px 6px', marginTop: '2px', background: 'rgba(255,193,7,0.12)', border: '1px solid rgba(255,193,7,0.45)', borderRadius: '4px' } },
|
|
2508
|
+
h('span', { style: { fontWeight: 600 } }, '正在查看历史:' + viewDate),
|
|
2509
|
+
h('span', { style: C.muted }, data && data._queryDate ? '(直查站点,未落盘)' : '(本地快照)'),
|
|
1458
2510
|
/**
|
|
1459
|
-
* ★ 2026-10-
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
2511
|
+
* ★ Spec A(2026-10-24):旧实现只清 sd/ss 并 setData(null)。
|
|
2512
|
+
* sd/ss 本来就是空的时候依赖没变化 ⇒ 一次 GET 都不发,列表永久停在「加载中…」。
|
|
2513
|
+
* 现在显式清直查视图 + 清本地日期偏好 + 递增 nonce ⇒ **一定**重发一次无 date 的 GET。
|
|
1462
2514
|
*/
|
|
1463
|
-
(
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
})(),
|
|
1475
|
-
data && data.note && String(data.boardId).indexOf('qidian.') !== 0 ? h('span', { style: C.muted }, dash(data.note)) : null),
|
|
1476
|
-
curSite === 'qidiantu'
|
|
1477
|
-
? h('div', { style: C.row },
|
|
1478
|
-
h('span', { style: C.muted }, '查历史日期(站点可直查)'),
|
|
1479
|
-
h('input', { type: 'date', value: qDate, onChange: function (e) { setQDate(e.target.value) }, style: { fontSize: '12px', padding: '2px 4px' } }),
|
|
1480
|
-
h('button', { style: C.btn, disabled: enrichBusy || !qDate, onClick: function () { queryDay(false) } }, '直接查看'),
|
|
1481
|
-
h('button', { style: C.btn, disabled: enrichBusy || !qDate, onClick: function () { queryDay(true) }, title: '抓取该日期并存为本地快照(当天已有的快照不会被覆盖)' }, '抓取并存入本地'))
|
|
1482
|
-
: null,
|
|
1483
|
-
// ★ 直查视图的日期横幅(使用方 2026-10-15):直接查看历史日期时,这里明确写出「你在看哪天」
|
|
1484
|
-
data && data._queryDate
|
|
1485
|
-
? h('div', { style: { ...C.row, alignItems: 'center', gap: '8px', padding: '4px 6px', background: 'rgba(255,193,7,0.12)', border: '1px solid rgba(255,193,7,0.45)', borderRadius: '4px' } },
|
|
1486
|
-
h('span', { style: { fontWeight: 600 } }, '📅 正在查看直查日期 ' + data._queryDate),
|
|
1487
|
-
h('span', { style: C.muted }, '(未落盘;按日期直查站点,所以没有名次变化/在榜天数)'),
|
|
1488
|
-
h('button', { style: C.btn, onClick: function () { setSs(''); setData(null); reloadBoard() } }, '回到最新'))
|
|
1489
|
-
: null,
|
|
1490
|
-
enrichNote ? h('div', { style: C.muted }, enrichNote) : null,
|
|
2515
|
+
h('button', {
|
|
2516
|
+
style: C.btn,
|
|
2517
|
+
onClick: function () {
|
|
2518
|
+
setSs('')
|
|
2519
|
+
setSd('')
|
|
2520
|
+
sel.setPref(curBoard, 'date', '')
|
|
2521
|
+
setDirectQ(null)
|
|
2522
|
+
setPick(null)
|
|
2523
|
+
setLoadNonce(function (n) { return n + 1 })
|
|
2524
|
+
},
|
|
2525
|
+
}, '回到最新')) : null,
|
|
1491
2526
|
data && data.fallbackFrom ? h('div', { style: C.muted }, '当天(' + data.requestedDate + ')没有快照 ⇒ 回落到 ' + data.fallbackFrom) : null,
|
|
1492
|
-
data && data.baselineDate ? h('div', { style: C.muted }, '基期 ' + data.baselineDate + ' · 数据日期 ' + dash(data.dataDate)) : null,
|
|
1493
|
-
/**
|
|
1494
|
-
* ★ 2026-10-16(起点图首订锚 n-1):行的 showDate 与快照数据日期不一致时,明确标出源数据日期。
|
|
1495
|
-
* 站点口径:上架 24 小时后才结算首订 ⇒ 抓到的榜永远是 n-1 那天的页面。
|
|
1496
|
-
*/
|
|
1497
|
-
data && data.rows && (function () {
|
|
1498
|
-
const src = (data.rows[0] && data.rows[0].extra && data.rows[0].extra.showDate) || null
|
|
1499
|
-
if (!src || src === data.dataDate) return null
|
|
1500
|
-
return h('div', { style: { ...C.row, alignItems: 'center', gap: '6px', padding: '4px 6px', background: 'rgba(33,150,243,0.10)', border: '1px solid rgba(33,150,243,0.40)', borderRadius: '4px' } },
|
|
1501
|
-
h('span', { style: { fontWeight: 600 } }, '源数据 ' + src),
|
|
1502
|
-
h('span', { style: C.muted }, '(首订榜按 n-1 锚点抓取:上架 24 小时后才结算首订;快照数据日期 ' + dash(data.dataDate) + ')'))
|
|
1503
|
-
})(),
|
|
1504
|
-
|
|
1505
2527
|
data && data.source ? h('div', { style: C.muted }, '来源:' + data.source) : null,
|
|
2528
|
+
err ? h('div', { style: { ...C.row, color: '#d9534f' } },
|
|
2529
|
+
h('span', null, '⚠ 读取失败:' + String(err).slice(0, 120)),
|
|
2530
|
+
h('button', { style: C.btn, onClick: function () { reloadBoard(false) } }, '重试')) : null,
|
|
2531
|
+
note ? h('div', { style: C.muted }, note) : null,
|
|
1506
2532
|
data && data.rows && data.rows.length
|
|
1507
|
-
?
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
2533
|
+
? (cards
|
|
2534
|
+
? h('div', null, data.rows.map(function (r, i) {
|
|
2535
|
+
// 卡片行 + 展开时紧跟其后的详情卡(详情别再挂到列表末尾)
|
|
2536
|
+
return h('div', { key: 'w' + (r.key || i) }, narrowRow(r, i), isOpen(r) ? detailCard(r) : null)
|
|
2537
|
+
}))
|
|
2538
|
+
: h('table', { style: C.table },
|
|
2539
|
+
h('thead', null, h('tr', null, cols.map(function (c) { return h('th', { key: c.key, style: C.th, title: c.note || '' }, c.label) }))),
|
|
2540
|
+
h('tbody', null, data.rows.flatMap(function (r, i) {
|
|
2541
|
+
const tr = h('tr', {
|
|
2542
|
+
key: r.key || i,
|
|
2543
|
+
tabIndex: 0,
|
|
2544
|
+
style: { cursor: 'pointer' },
|
|
2545
|
+
onClick: function () { setPick(isOpen(r) ? null : r) },
|
|
2546
|
+
onKeyDown: function (e) { if (e && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); setPick(isOpen(r) ? null : r) } },
|
|
2547
|
+
}, cols.map(function (c) {
|
|
2548
|
+
return h('td', { key: c.key, style: isNumCol(c.key) ? { ...C.td, ...C.num } : C.td }, cell(rowCellProps(r, c), r))
|
|
2549
|
+
}))
|
|
2550
|
+
// 详情卡作为紧跟那一行的一行(colSpan 占满),点哪一行就在哪一行下面展开
|
|
2551
|
+
return isOpen(r)
|
|
2552
|
+
? [tr, h('tr', { key: 'd' + (r.key || i) }, h('td', { colSpan: Math.max(1, cols.length), style: { padding: '0 0 4px' } }, detailCard(r)))]
|
|
2553
|
+
: [tr]
|
|
2554
|
+
}))))
|
|
1513
2555
|
: h('div', { style: C.muted }, data ? dash(data.note || '没有条目') : '加载中…'),
|
|
1514
|
-
|
|
1515
|
-
h('div', { style: { fontWeight: 600 } }, dash(pick.title)),
|
|
1516
|
-
h('div', { style: C.muted }, '作者 ' + dash(pick.author) + ' · 名次 ' + dash(pick.rank) + ' · 字数 ' + fmtWords((pick.extra || {}).wordsText || (pick.extra || {}).wordsCnt || (pick.extra || {}).wordNumber || (pick.extra || {}).words)),
|
|
1517
|
-
h('div', { style: C.muted }, '更新 ' + fmtTime((pick.extra || {}).lastChapterUpdateTime)),
|
|
1518
|
-
h('div', { style: C.row },
|
|
1519
|
-
h(BookmarkStar, { bookKey: bookKeyOf(curBoard, pick.key), row: pick, boardId: curBoard, dataDate: data && data.dataDate }),
|
|
1520
|
-
h(DetailBookmarkEditor, { bookKey: bookKeyOf(curBoard, pick.key) }),
|
|
1521
|
-
h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); if (props.openLink) props.openLink(pick.url); else window.open(pick.url, '_blank', 'noopener,noreferrer') } }, '在 DSH 侧栏浏览器打开'),
|
|
1522
|
-
h('a', { href: pick.url || '#', target: '_blank', rel: 'noreferrer', style: { color: 'inherit', padding: '3px 8px' }, onClick: function (e) { e.stopPropagation() } }, '新标签打开'),
|
|
1523
|
-
h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); try { navigator.clipboard.writeText(pick.url || '') } catch (err) {} } }, '复制链接'),
|
|
1524
|
-
h('button', { style: C.btn, onClick: function () { setPick(null) } }, '关闭')),
|
|
1525
|
-
// 原始数据来源页跳转(起点图首订 → 起点图 /info;刺猬猫首订(约)→ 第三方源)
|
|
1526
|
-
(pick.extra || {}).qidiantuUrl || (pick.extra || {}).sourceUrl
|
|
1527
|
-
? h('div', { style: C.row },
|
|
1528
|
-
((pick.extra || {}).qidiantuUrl
|
|
1529
|
-
? h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); (props.openLink || window.open)(pick.extra.qidiantuUrl) } }, '看起点图原始页')
|
|
1530
|
-
: null),
|
|
1531
|
-
((pick.extra || {}).sourceUrl
|
|
1532
|
-
? h('button', { style: C.btn, onClick: function (e) { e.stopPropagation(); (props.openLink || window.open)(pick.extra.sourceUrl) } }, '看原数据来源页')
|
|
1533
|
-
: null),
|
|
1534
|
-
h('span', { style: C.muted }, '(数据口径以来源页为准)'))
|
|
1535
|
-
: null) : null,
|
|
1536
|
-
h('div', { style: C.muted, marginTop: '6px' }, '列随榜变化:该站没有的字段整列不出现;有字段但这条没抓到显示「—」。'))
|
|
2556
|
+
h('div', { style: { ...C.muted, marginTop: '6px' } }, '列随榜变化:该站没有的字段整列不出现;有字段但这条没抓到显示「—」。面板变窄时列会按宽度自动收起(先收作者/分类/字数这类次级列,名次/变化/书名与该榜主指标一直在),再窄就换成卡片行;点行看详情。'))
|
|
1537
2557
|
}
|
|
1538
2558
|
|
|
1539
2559
|
/**
|
|
@@ -1630,52 +2650,160 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1630
2650
|
const [open, setOpen] = panelOpen.use()
|
|
1631
2651
|
// 收起面板会卸载 Panel ⇒ 用持久化的 tab(否则每次打开都跳回「概览」)
|
|
1632
2652
|
const [tab, setTab] = React.useState(function () { return sel.get().tab || 'ov' })
|
|
1633
|
-
const
|
|
2653
|
+
const LEAVE_LABEL = { bm: '书签备注', settings: '设置草稿' }
|
|
2654
|
+
const switchTab = function (t) {
|
|
2655
|
+
if (t === tab) return
|
|
2656
|
+
// 有没保存的东西:先拦一下(草稿不会丢,回来还在)
|
|
2657
|
+
if (dirtyGuard.any()) { setLeaveAsk({ tab: t, keys: dirtyGuard.list() }); return }
|
|
2658
|
+
sel.set({ tab: t }); setTab(t)
|
|
2659
|
+
}
|
|
2660
|
+
const doLeave = function () {
|
|
2661
|
+
const ask = leaveAsk
|
|
2662
|
+
setLeaveAsk(null)
|
|
2663
|
+
if (!ask) return
|
|
2664
|
+
if (ask.tab) { sel.set({ tab: ask.tab }); setTab(ask.tab) } else setOpen(false)
|
|
2665
|
+
}
|
|
1634
2666
|
const [ov, setOv] = React.useState(null)
|
|
1635
2667
|
const [busy, setBusy] = React.useState(false)
|
|
2668
|
+
/**
|
|
2669
|
+
* ★ Spec E:扫描类操作(扫描 / 重试 / 停止)自己的忙态。
|
|
2670
|
+
* 不能只靠 busy:POST /scan 还在路上时 overview 里仍是**上一轮的 completed**,
|
|
2671
|
+
* 面板若只看 ov.scan 就会退回 20s 慢轮询,用户点完扫描要等很久才看到 0/N。
|
|
2672
|
+
* 这个标记让「刚点完扫描」也立刻走 2s 快轮询,并在取消期间保持按钮禁用,
|
|
2673
|
+
* 直到 overview 真的不再显示在跑为止。
|
|
2674
|
+
*/
|
|
2675
|
+
const [scanActBusy, setScanActBusy] = React.useState(false)
|
|
2676
|
+
const postInFlightRef = React.useRef(0)
|
|
1636
2677
|
const [msg, setMsg] = React.useState(null)
|
|
1637
2678
|
const [rect, setRect] = useRect()
|
|
1638
|
-
|
|
2679
|
+
|
|
2680
|
+
/** 有未保存草稿时切页/收起先问一句(草稿留在 DRAFTS,回来还在) */
|
|
2681
|
+
const [leaveAsk, setLeaveAsk] = React.useState(null)
|
|
2682
|
+
const [, bumpDirty] = React.useState(0)
|
|
2683
|
+
React.useEffect(function () {
|
|
2684
|
+
if (typeof window === 'undefined' || !window.addEventListener) return undefined
|
|
2685
|
+
const onDirty = function () { bumpDirty(function (x) { return x + 1 }) }
|
|
2686
|
+
window.addEventListener('rank-scan:dirty', onDirty)
|
|
2687
|
+
return function () { window.removeEventListener('rank-scan:dirty', onDirty) }
|
|
2688
|
+
}, [])
|
|
2689
|
+
/** 轮询防重入:运行中每 2s 一次,慢请求不能叠成一堆(旧实现没有这道闸) */
|
|
2690
|
+
const reloadBusyRef = React.useRef(false)
|
|
2691
|
+
const reload = React.useCallback(function () {
|
|
2692
|
+
if (reloadBusyRef.current) return Promise.resolve()
|
|
2693
|
+
reloadBusyRef.current = true
|
|
2694
|
+
return readOverview()
|
|
2695
|
+
.then(setOv)
|
|
2696
|
+
.catch(function (e) { setMsg(String(e)) })
|
|
2697
|
+
.then(function () { reloadBusyRef.current = false })
|
|
2698
|
+
}, [])
|
|
1639
2699
|
React.useEffect(function () { reload() }, [reload])
|
|
1640
2700
|
// 轻量轮询:每 20s 静默刷新(不改变面板尺寸/位置,避免闪烁)
|
|
1641
2701
|
// ★ 2026-10-16(票 27):收起后必须彻底停 —— 旧写法把 `if (!open) return null` 放在 hooks 之后,
|
|
1642
2702
|
// 面板收起时这个 interval 仍在跑(每 20s 打一次 /overview)。现在:收起即清,重新展开立即拉一次;
|
|
1643
2703
|
// 页面隐藏(切到别的标签页)时跳过,恢复可见时补一次。
|
|
1644
2704
|
const polledOnce = React.useRef(false)
|
|
2705
|
+
/**
|
|
2706
|
+
* ★ Spec E(2026-10-24):轮询节奏跟着**真实扫描状态**走。
|
|
2707
|
+
* ① running(含定时扫描,inFlight=true)⇒ 2s,面板上 0/N → N/N 才动得起来;
|
|
2708
|
+
* ② 空闲 ⇒ 20s,维持原来「静默刷新」的成本;
|
|
2709
|
+
* ③ 收起面板 / 页面隐藏 ⇒ 彻底停(展开或回到可见时补一次);
|
|
2710
|
+
* ④ 不再拿 busy 当闸门:busy 只表示「本面板有个请求在路上」,
|
|
2711
|
+
* 定时扫描期间恒为 false,旧写法整轮都刷不到进度。
|
|
2712
|
+
*/
|
|
2713
|
+
const scanLive = !!(ov && ov.scan && ov.scan.outcome === 'running' && ov.scan.inFlight !== false)
|
|
2714
|
+
/** act 的 then 里要读「此刻是否还在跑」,用 ref 拿最新值(闭包里的 scanLive 是旧渲染的) */
|
|
2715
|
+
const scanLiveRef = React.useRef(false)
|
|
2716
|
+
scanLiveRef.current = scanLive
|
|
1645
2717
|
React.useEffect(function () {
|
|
1646
2718
|
if (!open) return undefined
|
|
1647
2719
|
if (polledOnce.current) reload()
|
|
1648
2720
|
else polledOnce.current = true
|
|
2721
|
+
// 刚点完扫描(POST 还没回)也要快轮询:那时 overview 仍是上一轮的 completed
|
|
2722
|
+
const every = pollDelay(scanLive, scanActBusy)
|
|
1649
2723
|
const t = setInterval(function () {
|
|
1650
|
-
if (
|
|
1651
|
-
},
|
|
2724
|
+
if (document.visibilityState !== 'hidden') reload()
|
|
2725
|
+
}, every)
|
|
1652
2726
|
const onVis = function () { if (document.visibilityState === 'visible') reload() }
|
|
1653
2727
|
document.addEventListener('visibilitychange', onVis)
|
|
1654
2728
|
return function () { clearInterval(t); document.removeEventListener('visibilitychange', onVis) }
|
|
1655
|
-
}, [reload,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
2729
|
+
}, [reload, open, scanLive, scanActBusy])
|
|
2730
|
+
/**
|
|
2731
|
+
* 跳到某个榜(概览的「查看本榜」与变化行都走这里):写进 sel 再切页,
|
|
2732
|
+
* BoardTab 挂载时按 sel 初始化 ⇒ 站/榜/日期/排序/详情都保留(Spec S6「保上下文」)。
|
|
2733
|
+
*/
|
|
2734
|
+
const openBoard = function (boardId) {
|
|
2735
|
+
const id = String(boardId || '')
|
|
2736
|
+
if (!id) return
|
|
2737
|
+
sel.set({ site: id.split('.')[0], board: id })
|
|
2738
|
+
switchTab('board')
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* path + 可选 JSON body(概览「重扫本榜」要传 {boards},以前 act 吞掉了 body)。
|
|
2742
|
+
* ★ Spec E:扫描/重试/停止走 scanActBusy —— 响应回来时如果 overview 还在 running,
|
|
2743
|
+
* 保持禁用(否则「停止本次」刚返回就能再点一次扫描,等于并发两轮);
|
|
2744
|
+
* 真正解锁交给下面的 scanLive 变化,避免抢先 setBusy(false)。
|
|
2745
|
+
*/
|
|
2746
|
+
const isScanAct = function (path) { return path === '/scan' || path === '/retry' || path === '/cancel' }
|
|
2747
|
+
const act = function (path, body) {
|
|
2748
|
+
const scanAct = isScanAct(path)
|
|
2749
|
+
if (scanAct) setScanActBusy(true)
|
|
2750
|
+
else setBusy(true)
|
|
2751
|
+
postInFlightRef.current += 1
|
|
2752
|
+
jpost(path, body).then(function (r) { setMsg(r && r.note ? r.note : '完成:' + (r.outcome || 'ok')); return reload() })
|
|
1659
2753
|
.catch(function (e) { setMsg(String(e)) })
|
|
1660
|
-
.then(function () {
|
|
2754
|
+
.then(function () {
|
|
2755
|
+
postInFlightRef.current -= 1
|
|
2756
|
+
if (!scanAct) return setBusy(false)
|
|
2757
|
+
if (!scanLiveRef.current && postInFlightRef.current === 0) setScanActBusy(false)
|
|
2758
|
+
})
|
|
1661
2759
|
}
|
|
2760
|
+
// 扫描真的停了(overview 不再 running)且没有扫描类请求在路上 ⇒ 解锁
|
|
2761
|
+
React.useEffect(function () {
|
|
2762
|
+
if (!scanLive && postInFlightRef.current === 0) setScanActBusy(false)
|
|
2763
|
+
}, [scanLive])
|
|
2764
|
+
// Esc:没有菜单/详情打开时收起面板;编辑中不收起(全局处理器已挡)
|
|
2765
|
+
// Esc 的最后一层:没有菜单/详情打开时收起面板(编辑中由全局处理器挡住)
|
|
2766
|
+
const closePanelLayer = React.useCallback(function () {
|
|
2767
|
+
if (dirtyGuard.any()) { setLeaveAsk({ tab: null, keys: dirtyGuard.list() }); return true }
|
|
2768
|
+
setOpen(false)
|
|
2769
|
+
return true
|
|
2770
|
+
}, [setOpen])
|
|
2771
|
+
useEscLayer(open ? closePanelLayer : null)
|
|
1662
2772
|
// 收起后:按钮同样可拖动、同样记住位置(用同一份 rect,不再回右上角)
|
|
1663
2773
|
if (!open) return null
|
|
1664
|
-
|
|
1665
|
-
|
|
2774
|
+
const narrow = rect.w < 720
|
|
2775
|
+
const rev = revOf(ov)
|
|
2776
|
+
return h('div', { 'data-rank-scan-win': '1', style: { ...C.win, left: rect.x + 'px', top: rect.y + 'px', width: rect.w + 'px', height: rect.h + 'px', fontSize: '13px' } },
|
|
2777
|
+
h(DragBar, {
|
|
2778
|
+
rect: rect, setRect: setRect,
|
|
2779
|
+
onCollapse: function () {
|
|
2780
|
+
if (dirtyGuard.any()) { setLeaveAsk({ tab: null, keys: dirtyGuard.list() }); return }
|
|
2781
|
+
setOpen(false)
|
|
2782
|
+
},
|
|
2783
|
+
}),
|
|
1666
2784
|
h('div', { style: C.body },
|
|
1667
2785
|
h('div', { style: C.tabs },
|
|
1668
2786
|
h('button', { style: C.tab(tab === 'ov'), onClick: function () { switchTab('ov') } }, '概览'),
|
|
1669
|
-
h('button', { style: C.tab(tab === 'board'), onClick: function () { switchTab('board') } }, '
|
|
1670
|
-
|
|
1671
|
-
h('button', { style: C.tab(tab === '
|
|
1672
|
-
h('button', { style: C.tab(tab === 'pick'), onClick: function () { switchTab('pick') } }, '抓什么')),
|
|
2787
|
+
h('button', { style: C.tab(tab === 'board'), onClick: function () { switchTab('board') } }, '榜单'),
|
|
2788
|
+
h('button', { style: C.tab(tab === 'bm'), onClick: function () { switchTab('bm') } }, '书签'),
|
|
2789
|
+
h('button', { style: C.tab(tab === 'pick'), onClick: function () { switchTab('pick') } }, '设置')),
|
|
1673
2790
|
msg ? h('div', { style: C.muted }, msg) : null,
|
|
2791
|
+
leaveAsk ? h('div', { style: { ...C.row, margin: '4px 0', padding: '5px 7px', borderRadius: '6px', border: '1px solid rgba(217,164,65,.55)', background: 'rgba(217,164,65,.12)' } },
|
|
2792
|
+
h('span', null, '有未保存的改动(' + (leaveAsk.keys || []).map(function (k) { return LEAVE_LABEL[k] || k }).join('、') + ')'),
|
|
2793
|
+
h('span', { style: C.muted }, '草稿会保留,下次进来还在'),
|
|
2794
|
+
h('button', { style: C.btnOn, onClick: doLeave }, '仍然离开'),
|
|
2795
|
+
h('button', { style: C.btn, onClick: function () { setLeaveAsk(null) } }, '继续编辑')) : null,
|
|
1674
2796
|
h(TabBoundary, { name: tab },
|
|
1675
|
-
tab === 'ov' ? h(Overview, {
|
|
1676
|
-
:
|
|
2797
|
+
tab === 'ov' ? h(Overview, {
|
|
2798
|
+
ov: ov, busy: busy || scanActBusy, act: act, reload: reload, narrow: narrow, width: rect.w, rev: rev,
|
|
2799
|
+
/** 刚点完扫描、overview 还没反映 running 时,按钮也要说「扫描中…」而不是「处理中…」 */
|
|
2800
|
+
scanStarting: scanActBusy && !scanLive,
|
|
2801
|
+
onOpenBoard: openBoard,
|
|
2802
|
+
onRescanBoard: function (boardId) { act('/scan', { boards: String(boardId) }) },
|
|
2803
|
+
})
|
|
2804
|
+
: tab === 'board' ? h(BoardTab, { ov: ov, openLink: props.openLink, narrow: narrow, width: rect.w, rev: rev })
|
|
1677
2805
|
: tab === 'bm' ? h(BookmarksTab, { openLink: props.openLink })
|
|
1678
|
-
: h(
|
|
2806
|
+
: h(SettingsTab, { ov: ov, onSaved: reload }))),
|
|
1679
2807
|
h(ResizeHandle, { rect: rect, setRect: setRect }))
|
|
1680
2808
|
}
|
|
1681
2809
|
|
|
@@ -1778,12 +2906,22 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1778
2906
|
* 以前会画成「名次 —」这种只有标签没有内容的空 chip;
|
|
1779
2907
|
* ② 与 collect chip 同源同值时不重复渲染 —— 番茄的 metric 与 collect 都是 row.value(在读)。
|
|
1780
2908
|
*/
|
|
1781
|
-
function metricChipText(metric, collect) {
|
|
2909
|
+
function metricChipText(metric, collect, collectLabel) {
|
|
1782
2910
|
if (!metric || metric.value == null) return null
|
|
1783
2911
|
if (collect != null && metric.value === collect) return null
|
|
2912
|
+
/**
|
|
2913
|
+
* ★ 2026-10-17:同口径(例如番茄的 metric 与 collect 都是「在读」)不再另画一个同名 chip ——
|
|
2914
|
+
* 上层会把它渲染成「书签记录 X」并说明不是同一时点;否则就是两个「在读」并排,看着像 bug。
|
|
2915
|
+
*/
|
|
2916
|
+
if (collectLabel && metric.name === collectLabel) return null
|
|
1784
2917
|
return metric.name + ' ' + metric.value
|
|
1785
2918
|
}
|
|
1786
2919
|
// 测试缝:宿主只消费 name/inject/apply,多挂一个纯展示函数对运行无影响
|
|
1787
|
-
|
|
2920
|
+
// 测试缝:宿主只消费 name/inject/apply;多挂纯函数与组件给离线测试用(对运行无影响)
|
|
2921
|
+
return { name: 'dsh-rank-scan', inject: inject, apply: apply, __test: {
|
|
2922
|
+
metricChipText: metricChipText,
|
|
2923
|
+
helpers: { revOf: revOf, statusText: statusText, scanLabel: scanLabel, pollDelay: pollDelay, canDayQuery: canDayQuery, fitColumns: fitColumns, colPrio: colPrio, mdOf: mdOf, boardLabel: boardLabel, rememberBoardNames: rememberBoardNames },
|
|
2924
|
+
components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel },
|
|
2925
|
+
} }
|
|
1788
2926
|
},
|
|
1789
2927
|
})
|