dsh-rank-scan 0.4.2 → 0.5.1

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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/lib/client.js +251 -55
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@ DeepSeek Harness 扫榜插件:定时 + 按需采集多站小说榜单,算变
18
18
 
19
19
  ```sh
20
20
  dsh plugin --profile desktop add github:kilo-s/dsh-rank-scan
21
- # 钉版本:github:kilo-s/dsh-rank-scan#v0.4.2
21
+ # 钉版本:github:kilo-s/dsh-rank-scan#v0.5.1
22
22
  ```
23
23
 
24
24
  仓库不含编译产物,这条命令会在安装时现场构建 `lib/`。首次可能被 pnpm 拦下构建脚本(它会打印要放行的键,加进 `allowBuilds` 后重跑即可),细节见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
@@ -37,14 +37,14 @@ dsh plugin --profile desktop add "<tgz 的完整路径>"
37
37
 
38
38
  ```sh
39
39
  dsh plugin --profile desktop add dsh-rank-scan
40
- # 钉版本:dsh-rank-scan@0.4.2
40
+ # 钉版本:dsh-rank-scan@0.5.1
41
41
  ```
42
42
 
43
43
  npm 上那份是 CI 从源码构建的(包内自带 `lib/`,发布带 `--provenance` 签名)——装的时候不用再编译,也不会被 pnpm 的 `allowBuilds` 拦下。面板的「检查更新」读的就是 npm 上的版本号。
44
44
 
45
45
  **验证**:重开 DSH 后左侧栏会话列表下方应出现「扫榜」入口;或访问 `http://127.0.0.1:19387/api/rank-scan/health`,返回 `{ok:true,...}` 即通。
46
46
 
47
- **更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.4.2**);面板「设置」页底部会读 npm 上的版本号提示有没有新版,装了 [dsh-market](https://github.com/dsh-market/dsh-market) 的话还能就地更新。
47
+ **更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.5.1**);面板「设置」页底部会读 npm 上的版本号提示有没有新版,装了 [dsh-market](https://github.com/dsh-market/dsh-market) 的话还能就地更新。
48
48
 
49
49
  **卸载**:`dsh plugin --profile desktop remove dsh-rank-scan`。数据目录 `~/.dsh/data/rank-scan` 会保留,要彻底清理自行删除;脚本化卸载与 patch 安全口径见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
50
50
 
package/lib/client.js CHANGED
@@ -1,3 +1,8 @@
1
+ /* ---- parts/00-head.js ---- */
2
+ /**
3
+ * 00-head.js:文件头、__ModuleLoader__.load 入口、React/h/API 常量与 jget/jpost/readResponse 请求层。依赖:无。不要放组件或页面逻辑。
4
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
5
+ */
1
6
  /**
2
7
  * dsh-rank-scan — 面板(手写 bundle,零依赖;只用平台提供的 react)。
3
8
  * 2026-10-14 重写:可拖动/可缩放浮窗(位置尺寸本地记忆);概览单行汇总;异常榜折叠;行内详情卡。
@@ -17,7 +22,10 @@ window.__ModuleLoader__.load({
17
22
  const readResponse = async (response) => {
18
23
  const data = await response.json()
19
24
  if (response.ok === false || (data && (data.ok === false || data.error))) {
20
- throw new Error((data && (data.error || data.note)) || ('请求失败:' + response.status))
25
+ const err = new Error((data && (data.error || data.note)) || ('请求失败:' + response.status))
26
+ err.status = response.status
27
+ if (data && data.code) err.code = data.code
28
+ throw err
21
29
  }
22
30
  return data
23
31
  }
@@ -150,6 +158,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
150
158
  * 颜色优先读 DSH 宿主的 --dsw-alias-*(亮/暗主题各自解析),再退到旧版 --dsh-* 与静态兜底;
151
159
  * 兜底只为了在宿主变量缺失时不至于透明或白底白字,不是第二套主题。
152
160
  */
161
+ /* ---- parts/10-tokens.js ---- */
162
+ /**
163
+ * 10-tokens.js:设计令牌 T/C、主题变量、wash 与 ensureStyle 样式注入。依赖 00。不要放业务组件。
164
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
165
+ */
153
166
  const T = {
154
167
  surface: 'var(--dsw-alias-bg-layer-1, var(--dsh-surface, #fff))',
155
168
  surface2: 'var(--dsw-alias-bg-layer-2, var(--dsh-fill, rgba(128,128,128,.06)))',
@@ -208,6 +221,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
208
221
  '.rs-banner.is-error{border-color:' + T.bad + ';background:' + wash(T.bad, 8) + '}',
209
222
  '.rs-banner .rs-banner-body{flex:1 1 100%;min-width:0}',
210
223
  '.rs-toasts{position:absolute;right:12px;top:64px;bottom:auto;z-index:95;display:flex;flex-direction:column;gap:6px;max-width:min(380px,calc(100% - 24px));max-height:calc(100% - 80px);overflow:auto;pointer-events:none}',
224
+ '.rs-statcard:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
211
225
  '.rs-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:8px;padding:7px 9px;border-radius:' + T.r.s + ';border:1px solid;border-left-width:3px;background:' + T.surface + ';color:' + T.fg + ';box-shadow:' + T.shadowMenu + ';font-size:' + T.fs.s + ';line-height:1.45}',
212
226
  '.rs-toast.is-info{border-color:' + T.accent + ';background-image:linear-gradient(' + wash(T.accent, 10) + ',' + wash(T.accent, 10) + ')}',
213
227
  '.rs-toast.is-warn{border-color:' + T.warn + ';background-image:linear-gradient(' + wash(T.warn, 12) + ',' + wash(T.warn, 12) + ')}',
@@ -264,6 +278,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
264
278
  input: { padding: '3px 6px', fontSize: T.fs.s, borderRadius: T.r.s, border: '1px solid ' + T.border, background: 'transparent', color: 'inherit' },
265
279
  }
266
280
  /** 统一提示条:三种语气只差颜色,形状一致;错误用 role=alert 让读屏器打断 */
281
+ /* ---- parts/20-ui-kit.js ---- */
282
+ /**
283
+ * 20-ui-kit.js:通用 UI:Banner、Toast、PopMenu、Section、格式化/状态/列宽工具、useRect。依赖 10。不要放整页页签。
284
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
285
+ */
267
286
  function Banner(props) {
268
287
  const role = props.live === false ? null : (props.tone === 'error' ? 'alert' : 'status')
269
288
  return h('div', { className: 'rs-banner is-' + (props.tone || 'info'), role: role },
@@ -774,6 +793,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
774
793
  * 旧对象没有 filters,BookmarksTab 里一行 f.q 就把整个页签打成错误边界。
775
794
  * 所以每次取用都先 healStore() 按对象补,不管它由哪一代定义创建。
776
795
  */
796
+ /* ---- parts/25-bookmark-star.js ---- */
797
+ /**
798
+ * 25-bookmark-star.js:书签本地 store 的 healStore 与 BookmarkStar 小部件。依赖 10/20。不要放书签页签。
799
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
800
+ */
777
801
  const healStore = function (s) {
778
802
  if (!s || typeof s !== 'object') return s
779
803
  if (!s.filters || typeof s.filters !== 'object') s.filters = { q: '', site: '', folder: '', tag: '' }
@@ -941,6 +965,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
941
965
  * ③ 组件卸载(收起浮窗 / 热重载)。
942
966
  * 旧写法只处理 ①:②③ 之后每次鼠标移动都还在改一个已经卸载的浮窗的 rect。
943
967
  */
968
+ /* ---- parts/30-window.js ---- */
969
+ /**
970
+ * 30-window.js:浮窗拖拽/缩放:useWindowDrag、DragBar、ResizeHandle。依赖 10/20。不要放数据逻辑。
971
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
972
+ */
944
973
  function useWindowDrag() {
945
974
  const active = React.useRef(null)
946
975
  const stop = React.useCallback(function () {
@@ -1021,6 +1050,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1021
1050
  }
1022
1051
 
1023
1052
  /** 字节 → 人话(数据目录占用用;保留 1 位小数,够看趋势就行) */
1053
+ /* ---- parts/40-overview.js ---- */
1054
+ /**
1055
+ * 40-overview.js:概览页:fmtBytes、StatCard、SectionHeader、nextPlanOf、Overview。依赖 20。不要放设置/榜单页。
1056
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
1057
+ */
1024
1058
  const fmtBytes = (n) => {
1025
1059
  if (n == null || !isFinite(n)) return '—'
1026
1060
  const u = ['B', 'KB', 'MB', 'GB']
@@ -1037,6 +1071,74 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1037
1071
  * ③ 全部榜单(可折叠;逐榜状态 + 涨/新/退;同站抓取时刻一致时只写一次)
1038
1072
  * ★ 2026-10-22(简明性 B):存储/保留/诊断移到「设置」页 —— 采集管理不再占首屏。
1039
1073
  */
1074
+ /**
1075
+ * 概览数字卡(0.5.0):值大、标签小;tone 只影响左色条与数字颜色,文字本身必须能读懂状态。
1076
+ * 有 onClick 时渲染成 button(Tab 可聚焦,focus-visible 蓝框),没有时是 div。
1077
+ */
1078
+ function StatCard(props) {
1079
+ const tone = props.tone || 'muted'
1080
+ const color = tone === 'ok' ? T.ok : tone === 'warn' ? T.warn : tone === 'bad' ? T.bad : T.muted
1081
+ const body = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0, textAlign: 'left' } },
1082
+ h('div', { style: { ...C.muted, fontSize: T.fs.s, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, props.label),
1083
+ h('div', { style: { fontSize: T.fs.l, fontWeight: 700, fontVariantNumeric: 'tabular-nums', color, lineHeight: 1.2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, props.value),
1084
+ props.sub ? h('div', { style: { ...C.muted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }, title: String(props.sub) }, props.sub) : null)
1085
+ const style = {
1086
+ display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0, boxSizing: 'border-box', textAlign: 'left',
1087
+ padding: '8px 10px', paddingLeft: '12px', border: '1px solid ' + T.border, borderLeft: '3px solid ' + color,
1088
+ borderRadius: T.r.s, background: T.surface, color: T.fg, font: 'inherit',
1089
+ cursor: props.onClick ? 'pointer' : 'default',
1090
+ }
1091
+ if (props.onClick) {
1092
+ return h('button', { type: 'button', className: 'rs-statcard', style: Object.assign({ appearance: 'none' }, style), onClick: props.onClick, title: props.title || props.label },
1093
+ body)
1094
+ }
1095
+ return h('div', { className: 'rs-statcard', style: style, title: props.title || '' }, body)
1096
+ }
1097
+ /** 概览区块小标题:标题 + 右侧计数 + 可选操作;innerRef 供数字卡 scrollIntoView 用 */
1098
+ function SectionHeader(props) {
1099
+ return h('div', { ref: props.innerRef, style: { display: 'flex', alignItems: 'baseline', gap: '8px', minWidth: 0, margin: props.first ? '8px 0 4px' : '12px 0 6px' } },
1100
+ h('div', { style: { fontWeight: 600, fontSize: T.fs.m, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, props.title),
1101
+ h('div', { style: { marginLeft: 'auto', display: 'flex', alignItems: 'baseline', gap: '6px', flex: '0 0 auto' } },
1102
+ props.count != null && props.count !== '' ? h('span', { style: C.muted }, '(' + props.count + ')') : null,
1103
+ props.action || null))
1104
+ }
1105
+
1106
+ const SITE_LABELS = { qidian: '起点', qidiantu: '起点图', ciweimao: '刺猬猫', sfacg: '菠萝包', fanqie: '番茄' }
1107
+ const siteLabelOf = function (ov, s) {
1108
+ const hit = ((ov && ov.sites) || []).filter(function (x) { return x.site === s })[0]
1109
+ return hit ? hit.siteName : (SITE_LABELS[s] || String(s))
1110
+ }
1111
+ /**
1112
+ * 下次计划(0.5.0 验收修正):
1113
+ * · waiting 里最近站点的时刻 → 中性色;
1114
+ * · 今天全跑完(无 waiting/fallback)→ 取已启用站 siteTimes 的最早时刻,写「明天 HH:mm」;
1115
+ * · siteTimes 也为空 → label 改成「上次扫描」,避免把过去的时刻说成将来的计划;
1116
+ * · 定时关闭/只剩兜底 → warn。
1117
+ */
1118
+ function nextPlanOf(plan, ov, scan, total) {
1119
+ if (!plan) return { label: '下次计划', value: '—', sub: '计划读取中', tone: 'muted' }
1120
+ if (plan.enabled === false) return { label: '下次计划', value: '已关闭', sub: '定时扫描', tone: 'warn' }
1121
+ if (typeof total === 'number' && total === 0) return { label: '下次计划', value: '—', sub: '还没有勾选要扫的榜', tone: 'muted' }
1122
+ const times = plan.siteTimes || {}
1123
+ const waiting = (plan.waiting || []).filter(function (s) { return times[s] })
1124
+ if (waiting.length) {
1125
+ const order = waiting.slice().sort(function (a, b) { return String(times[a]).localeCompare(String(times[b])) })
1126
+ return { label: '下次计划', value: times[order[0]], sub: siteLabelOf(ov, order[0]), tone: 'muted' }
1127
+ }
1128
+ if ((plan.fallback || []).length) {
1129
+ return { label: '下次计划', value: plan.fallbackTime || '22:30', sub: siteLabelOf(ov, plan.fallback[0]), tone: 'warn' }
1130
+ }
1131
+ const enabled = ((ov && ov.sites) || []).map(function (s) { return s.site }).filter(function (s) { return times[s] })
1132
+ const nextTimes = enabled.slice().sort(function (a, b) { return String(times[a]).localeCompare(String(times[b])) })
1133
+ if (nextTimes.length) {
1134
+ const s = nextTimes[0]
1135
+ return { label: '下次计划', value: '明天 ' + times[s], sub: siteLabelOf(ov, s), tone: 'muted' }
1136
+ }
1137
+ const last = scan && (scan.startedAt || scan.at)
1138
+ if (last) return { label: '上次扫描', value: fmtLocalHM(last), sub: '最近一次', tone: 'muted' }
1139
+ return { label: '下次计划', value: '—', sub: '暂时算不出下次', tone: 'muted' }
1140
+ }
1141
+
1040
1142
  function Overview(props) {
1041
1143
  const ov = props.ov
1042
1144
  /**
@@ -1060,6 +1162,9 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1060
1162
  const allS = React.useState(true)
1061
1163
  const showAll = allS[0]
1062
1164
  const setShowAll = allS[1]
1165
+ const allRef = React.useRef(null)
1166
+ const issuesRef = React.useRef(null)
1167
+ const changesRef = React.useRef(null)
1063
1168
  const rev = props.rev || revOf(ov)
1064
1169
  /**
1065
1170
  * ★ 2026-10-22(同日刷新):依赖**修订号**而不是 dataDate。
@@ -1094,15 +1199,15 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1094
1199
  id = setInterval(tick, 5000)
1095
1200
  return function () { alive = false; if (id) clearInterval(id) }
1096
1201
  }, [])
1097
- if (!ov) return h('div', { style: C.muted }, '加载中…')
1098
- const c = ov.counts || {}
1202
+ // 0.5.0:/overview 未到时不再整页「加载中…」——四张卡先占位「—」,版面不跳
1203
+ const c = (ov && ov.counts) || {}
1099
1204
  const total = (c.ok || 0) + (c.missing || 0) + (c.stale || 0) + (c.login_required || 0) + (c.truncated || 0)
1100
- const rows = (ov.sites || []).flatMap(function (s) { return (s.boards || []).map(function (b) { return { ...b, siteName: s.siteName } }) })
1205
+ const rows = ((ov && ov.sites) || []).flatMap(function (s) { return (s.boards || []).map(function (b) { return { ...b, siteName: s.siteName } }) })
1101
1206
 
1102
- const scan = ov.scan || null
1103
- const plan = (ov.services && ov.services.schedule) || null
1207
+ const scan = (ov && ov.scan) || null
1208
+ const plan = (ov && ov.services && ov.services.schedule) || null
1104
1209
  const staleIds = plan && plan.staleFlag
1105
- ? Object.keys(plan.staleFlag).filter(function (k) { return plan.staleFlag[k] && plan.staleFlag[k].date === ov.dataDate })
1210
+ ? Object.keys(plan.staleFlag).filter(function (k) { return plan.staleFlag[k] && plan.staleFlag[k].date === (ov && ov.dataDate) })
1106
1211
  : []
1107
1212
  /**
1108
1213
  * ★ Spec S3(2026-10-22):「未到计划」和「待补跑」不是失败。
@@ -1124,7 +1229,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1124
1229
  }
1125
1230
  const plannedTimeOf = function (b) {
1126
1231
  if (b.plannedTime) return String(b.plannedTime)
1127
- const times = (plan && plan.siteTimes) || (ov.defaults && ov.defaults.siteTimes) || {}
1232
+ const times = (plan && plan.siteTimes) || (ov && ov.defaults && ov.defaults.siteTimes) || {}
1128
1233
  return times[siteOfBoardId(b.boardId)] || ''
1129
1234
  }
1130
1235
  const waitingRows = rows.filter(function (b) { return scheduleStateOf(b) === 'waiting' })
@@ -1216,23 +1321,62 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1216
1321
  if (last && last.site === e.site) last.items.push(e)
1217
1322
  else shownBySite.push({ site: e.site, siteName: e.siteName, items: [e] })
1218
1323
  })
1324
+ const collectSub = [
1325
+ waitingRows.length ? '未到计划 ' + waitingRows.length : '',
1326
+ dueRows.length ? '待补跑 ' + dueRows.length : '',
1327
+ ].filter(Boolean).join(' · ')
1328
+ const collectSubText = collectSub || (badRows.length ? '有榜没抓到' : (ov && total > 0 && (c.ok || 0) === total ? '全部采集完成' : ''))
1329
+ const collectTone = badRows.length ? 'bad' : dueRows.length ? 'warn' : (ov && total > 0 && (c.ok || 0) === total ? 'ok' : 'muted')
1330
+ const issuesTone = !issues.length ? 'ok' : (issues.some(function (it) { return it.status !== 'stale' && it.status !== 'enrich' }) ? 'bad' : 'warn')
1331
+ const changesSub = Object.keys(chgTotals).slice(0, 2).map(function (g) { return g + ' ' + chgTotals[g] }).join(' · ')
1332
+ const nextPlan = nextPlanOf(plan, ov, scan, total)
1333
+ const noData = !!(ov && (c.ok || 0) === 0 && chgRealTotal === 0)
1334
+ const noChanges = !!(ov && (c.ok || 0) > 0 && chg && chgRealTotal === 0)
1335
+ const jump = function (ref) {
1336
+ const el = ref && ref.current
1337
+ if (el && typeof el.scrollIntoView === 'function') { try { el.scrollIntoView({ block: 'nearest' }) } catch (e) {} }
1338
+ }
1339
+ const goAll = function () {
1340
+ setShowAll(true)
1341
+ setTimeout(function () { jump(allRef) }, 0)
1342
+ }
1219
1343
  return h('div', null,
1220
- /* ① 摘要带:日期 + 采集/待处理(文字,不靠颜色) */
1221
- h('div', { style: C.row },
1222
- h('span', { title: '扫描开始时刻的本地自然日', style: { fontWeight: 600 } }, '数据日期 ' + dash(ov.dataDate)),
1223
- h('span', { style: C.muted }, '·'),
1224
- h('span', null, '已采集 ' + (c.ok || 0) + '/' + total),
1225
- waitingRows.length ? h('span', { style: C.muted, title: '这些站今天还没到自己的抓取时刻:不是失败' }, '· 未到计划 ' + waitingRows.length) : null,
1226
- dueRows.length ? h('span', { style: { color: T.warn }, title: '已过计划时刻但还没抓到:等兜底,或点「扫描已选榜」马上跑' }, '· 待补跑 ' + dueRows.length) : null,
1227
- h('span', { style: issues.length ? { color: T.warn, fontWeight: 600 } : { color: T.ok } },
1228
- issues.length ? '待处理 ' + issues.length + ' 项' : '无待处理'),
1229
- ov.hiddenCount ? h('span', { style: C.muted }, '· 未显示 ' + ov.hiddenCount + ' 个榜') : null),
1230
- /* ② 主动作:扫描(联网)与重新载入(只读本地)分开写清 */
1231
- h('div', { style: C.row },
1344
+ /* ① 数据日期小字 */
1345
+ h('div', { style: { ...C.muted, display: 'flex', gap: '6px', flexWrap: 'wrap', marginBottom: '6px' } },
1346
+ h('span', { title: '扫描开始时刻的本地自然日' }, '数据日期 ' + dash(ov && ov.dataDate)),
1347
+ ov && ov.hiddenCount ? h('span', null, '· 未显示 ' + ov.hiddenCount + ' 个榜') : null),
1348
+ /* ② 四张数字卡:先回答「今天怎么样」 */
1349
+ // 480px 面板内宽约 455px:140px 会挤成 3 列,180px 才能落到验收要求的 2×2
1350
+ h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: '8px' } },
1351
+ h(StatCard, {
1352
+ label: '已采集', value: ov ? (c.ok || 0) + '/' + total : '—',
1353
+ sub: ov ? (collectSubText || (total ? '—' : '还没有采集')) : '读取中', tone: collectTone,
1354
+ onClick: goAll, title: '展开全部榜单并滚到那里',
1355
+ }),
1356
+ h(StatCard, {
1357
+ label: '待处理', value: !ov ? '—' : (issues.length ? String(issues.length) : '无'),
1358
+ sub: !ov ? '读取中' : (issues.length ? '需要你动手' : '没有要处理的'), tone: !ov ? 'muted' : issuesTone,
1359
+ onClick: issues.length ? function () { jump(issuesRef) } : undefined,
1360
+ title: issues.length ? '滚到「需要处理」' : '当前没有问题',
1361
+ }),
1362
+ h(StatCard, {
1363
+ label: '今日变化', value: chg ? String(chgRealTotal) : '—',
1364
+ sub: !chg ? '读取中' : (changesSub || (chgRealTotal ? '' : '今天没有变化')),
1365
+ tone: chgRealTotal ? 'ok' : 'muted',
1366
+ onClick: chg ? function () { jump(changesRef) } : undefined,
1367
+ title: '滚到「今天的变化」',
1368
+ }),
1369
+ h(StatCard, {
1370
+ label: nextPlan.label, value: nextPlan.value, sub: nextPlan.sub, tone: nextPlan.tone,
1371
+ onClick: plan && plan.enabled === false && props.onOpenSettings ? props.onOpenSettings : undefined,
1372
+ title: plan && plan.enabled === false ? '定时已关闭,点这里去设置' : '下一次站点计划',
1373
+ })),
1374
+ /* ③ 主动作:扫描(联网)与重新载入(只读本地)分开写清 */
1375
+ h('div', { style: { ...C.row, marginTop: '8px' } },
1232
1376
  h('button', {
1233
1377
  className: 'rs-btn is-primary',
1234
- disabled: scanBusy,
1235
- title: '按「设置 → 抓取范围」里勾选的榜逐个扫描(联网)',
1378
+ disabled: scanBusy || !ov || total === 0,
1379
+ title: total === 0 ? '还没有勾选要扫的榜,先去「设置 → 抓取范围」勾选' : '按「设置 → 抓取范围」里勾选的榜逐个扫描(联网)',
1236
1380
  onClick: function () { props.act('/scan') },
1237
1381
  }, scanBtnText),
1238
1382
  scanBusy ? h('button', { className: 'rs-btn is-danger', onClick: function () { props.act('/cancel') } }, '停止本次(保留已完成)') : null,
@@ -1240,14 +1384,26 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1240
1384
  h('button', { className: 'rs-btn is-ghost', onClick: props.reload, title: '只重新读取本地数据:不联网、不采集' }, '重新载入'),
1241
1385
  // 运行中不显示「上次 …」:那一轮还没结束,进度只放在主按钮一处(否则会同时出现两条「扫描中」)
1242
1386
  scanRunning ? null : h('span', { style: C.muted }, '上次 ' + scanLabel(scan))),
1243
- /* 补全进度:面板顶部只有这一条(三态:跑着 / 还能续跑 / 当日已试满) */
1387
+ /* ④ 需要处理:要用户动手的排后台补全前面 */
1388
+ issues.length ? h('div', { ref: issuesRef },
1389
+ h(Banner, { tone: issues.some(function (it) { return it.status !== 'stale' && it.status !== 'enrich' }) ? 'error' : 'warn', title: '需要处理' },
1390
+ h('div', { className: 'rs-banner-body', style: { display: 'flex', flexDirection: 'column', gap: '2px' } }, issues.map(function (it) {
1391
+ return h('div', { key: it.key, style: { ...C.row, alignItems: 'baseline' } },
1392
+ h('span', { style: C.dot(it.status === 'stale' || it.status === 'enrich' ? 'warn' : 'bad') }),
1393
+ h('span', { style: { fontWeight: 600 } }, it.name),
1394
+ it.at ? h('span', { style: C.muted }, fmtLocalHM(it.at)) : null,
1395
+ h('span', null, it.why),
1396
+ it.detail ? h('span', { style: C.muted }, '(' + String(it.detail).slice(0, 80) + ')') : null,
1397
+ it.boardId ? h('button', { className: 'rs-btn', disabled: props.busy, onClick: function () { props.onOpenBoard && props.onOpenBoard(it.boardId) }, title: '在「榜单」页打开这一榜(保上下文)' }, '查看本榜') : null,
1398
+ it.boardId ? h('button', { className: 'rs-btn', disabled: props.busy, onClick: function () { props.onRescanBoard && props.onRescanBoard(it.boardId) }, title: '只重扫这一榜(联网)' }, '重扫本榜') : null)
1399
+ })))) : null,
1400
+ /* ⑤ 补全进度:面板顶部只有这一条(三态:跑着 / 还能续跑 / 当日已试满) */
1244
1401
  (function () {
1245
1402
  if (!enrichStatus) return null
1246
1403
  const run = enrichStatus.enrichRun
1247
1404
  const active = !!(run && run.active === true)
1248
1405
  const left = typeof enrichStatus.pending === 'number' ? enrichStatus.pending : 0
1249
1406
  if (!active && !left) return null
1250
- // 「还能不能续跑」用宿主的 retryable 判(0 = 当日已试满),前端不自己猜
1251
1407
  const retryable = typeof enrichStatus.retryable === 'number' ? enrichStatus.retryable : null
1252
1408
  const label = active
1253
1409
  ? '补全中 ' + ((run && run.done) || 0) + '/' + ((run && run.total) || 0) + ' 个榜(可以先浏览,不用等)'
@@ -1256,27 +1412,16 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1256
1412
  : '补全未完成:还缺 ' + left + ' 个榜(后台会继续补,也可进榜点「补全缺失字段」)'
1257
1413
  return h(Banner, { tone: active ? 'info' : 'warn', live: false }, label)
1258
1414
  })(),
1259
- /* ③ 需要处理:仅有问题时出现 */
1260
- issues.length ? h(Banner, { tone: issues.some(function (it) { return it.status !== 'stale' && it.status !== 'enrich' }) ? 'error' : 'warn', title: '需要处理' },
1261
- h('div', { className: 'rs-banner-body', style: { display: 'flex', flexDirection: 'column', gap: '2px' } }, issues.map(function (it) {
1262
- /**
1263
- * Spec S5:一条问题要给「榜名 + 发生时间 + 影响 + 可执行动作」。
1264
- * 以前只有一个泛化「重试失败 N 个榜」,看不出是哪次尝试、也没法直接进榜看。
1265
- */
1266
- return h('div', { key: it.key, style: { ...C.row, alignItems: 'baseline' } },
1267
- h('span', { style: C.dot(it.status === 'stale' || it.status === 'enrich' ? 'warn' : 'bad') }),
1268
- h('span', { style: { fontWeight: 600 } }, it.name),
1269
- it.at ? h('span', { style: C.muted }, fmtLocalHM(it.at)) : null,
1270
- h('span', null, it.why),
1271
- it.detail ? h('span', { style: C.muted }, '(' + String(it.detail).slice(0, 80) + ')') : null,
1272
- it.boardId ? h('button', { className: 'rs-btn', disabled: props.busy, onClick: function () { props.onOpenBoard && props.onOpenBoard(it.boardId) }, title: '在「榜单」页打开这一榜(保上下文)' }, '查看本榜') : null,
1273
- it.boardId ? h('button', { className: 'rs-btn', disabled: props.busy, onClick: function () { props.onRescanBoard && props.onRescanBoard(it.boardId) }, title: '只重扫这一榜(联网)' }, '重扫本榜') : null)
1274
- }))) : null,
1275
1415
  /* ④ 今天的变化 */
1276
- h('div', { style: C.siteBar }, '今天的变化' + (chgRealTotal ? '(' + chgRealTotal + ' 条)' : '')),
1416
+ h(SectionHeader, { innerRef: changesRef, title: '今天的变化', count: chgRealTotal ? chgRealTotal + ' 条' : '' }),
1277
1417
  chg && chg.note ? h('div', { style: C.muted }, chg.note) : null,
1278
1418
  previewLimited ? h('div', { style: C.muted }, '下表每榜每类最多列 20 条(本次 ' + chgEntries.length + ' 条,共 ' + chgRealTotal + ' 条);点行到榜页看全部。') : null,
1279
- chg && chg.count === 0 ? h('div', { style: C.muted }, '没有变化条目(或还没有可比基准)') : null,
1419
+ total === 0 ? h('div', { style: { ...C.row, alignItems: 'center' } },
1420
+ h('span', { style: C.muted }, '还没有勾选要扫的榜'),
1421
+ props.onOpenSettings ? h('button', { className: 'rs-btn is-ghost', onClick: props.onOpenSettings }, '去设置勾选') : null) : null,
1422
+ total === 0 ? null : noData ? h('div', { style: C.muted }, '今天还没有采集结果,到计划时刻会自动跑,也可以点「扫描已选榜」') : null,
1423
+ noChanges ? h('div', { style: C.muted }, '今天没有榜单变化') : null,
1424
+ ov && !chg && !noData ? h('div', { style: C.muted }, '正在读取今天的变化…') : null,
1280
1425
  chgEntries.length ? h('div', { style: C.row },
1281
1426
  [{ label: '全部', value: '' }].concat(groupNames.map(function (g) { return { label: g, value: g } })).map(function (o) {
1282
1427
  return h('button', {
@@ -1335,15 +1480,17 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1335
1480
  return [head].concat(body)
1336
1481
  })))) : null,
1337
1482
  /* ⑤ 全部榜单(可折叠) */
1338
- h('div', { style: { ...C.row, marginTop: '8px' } },
1339
- h('button', {
1483
+ h(SectionHeader, {
1484
+ innerRef: allRef, title: '全部榜单', count: total,
1485
+ action: h('button', {
1340
1486
  className: 'rs-btn is-ghost',
1341
1487
  'aria-expanded': showAll ? 'true' : 'false',
1342
1488
  onClick: function () { setShowAll(!showAll) },
1343
- }, (showAll ? '▾ ' : '▸ ') + '全部榜单(' + total + ')')),
1344
- showAll ? h('table', { style: C.table },
1489
+ }, showAll ? '收起' : '展开'),
1490
+ }),
1491
+ showAll && total > 0 ? h('table', { style: C.table },
1345
1492
  h('thead', null, h('tr', null, ['榜(按站)', '涨 / 新 / 退', '状态'].concat(hasNoteCol && !chgNarrow ? ['备注'] : []).map(function (t) { return h('th', { key: t, style: C.th }, t) }))),
1346
- h('tbody', null, (ov.sites || []).flatMap(function (s) {
1493
+ h('tbody', null, ((ov && ov.sites) || []).flatMap(function (s) {
1347
1494
  const okN = s.boards.filter(function (b) { return b.status === 'ok' }).length
1348
1495
  const times = s.boards.map(function (b) { return b.lastCapture ? fmtLocalHM(b.lastCapture) : '' })
1349
1496
  const sameTime = times.length > 0 && times.every(function (t) { return t === times[0] })
@@ -1392,6 +1539,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1392
1539
  * 设置草稿 vs 已保存快照的差异(纯函数)。
1393
1540
  * captures 按集合比较(顺序不算变化);siteTimes 按字段比较。返回人类可读的分组名;空数组 = 干净。
1394
1541
  */
1542
+ /* ---- parts/50-settings.js ---- */
1543
+ /**
1544
+ * 50-settings.js:设置页:settingsDiff/retention/settingsSavedFrom、SettingsTab、VersionRow。依赖 10/20。不要放榜单页。
1545
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
1546
+ */
1395
1547
  const settingsDiff = function (saved, draft) {
1396
1548
  const out = []
1397
1549
  if (!saved || !draft) return out
@@ -1989,6 +2141,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1989
2141
  h('button', { className: 'rs-btn', disabled: busy !== '', onClick: function () { refresh() } }, '重新检查')))
1990
2142
  }
1991
2143
 
2144
+ /* ---- parts/55-board-cell.js ---- */
2145
+ /**
2146
+ * 55-board-cell.js:榜单表格单元格 cell、榜名记忆与 boardLabel。依赖 10/20。不要放 BoardTab 本体。
2147
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
2148
+ */
1992
2149
  function cell(c, r) {
1993
2150
  const k = c.key
1994
2151
  const ex = r.extra || {}
@@ -2087,6 +2244,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2087
2244
  return BOARD_NAMES[id] || (id || '—')
2088
2245
  }
2089
2246
 
2247
+ /* ---- parts/60-bookmarks.js ---- */
2248
+ /**
2249
+ * 60-bookmarks.js:书签页:bookKeyOf、DetailBookmarkEditor、BookmarksTab。依赖 20/25。不要放榜单页。
2250
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
2251
+ */
2090
2252
  function bookKeyOf(boardId, key) {
2091
2253
  const id = String(key == null ? '' : key).trim()
2092
2254
  if (!id) return ''
@@ -2487,6 +2649,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2487
2649
  * · 状态带一行写清:数据日期 · 源数据日期 · 对比基准(隔几天)· 跨期不可比
2488
2650
  * ★ 2026-10-22(B):同一天重扫会静默重读,且不重置站/榜/日期/排序/详情。
2489
2651
  */
2652
+ /* ---- parts/70-board.js ---- */
2653
+ /**
2654
+ * 70-board.js:榜单页:BoardTab(选择器、详情、操作条、本榜设置、日期回看)。依赖 20/55。不要放 Panel。
2655
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
2656
+ */
2490
2657
  function BoardTab(props) {
2491
2658
  const ov = props.ov
2492
2659
  /**
@@ -2615,6 +2782,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2615
2782
  toast('success', (r && r.note) || ('已保存:每榜取 ' + n + ' 条'))
2616
2783
  if (!alsoScan) return null
2617
2784
  setScanning(true)
2785
+ if (props.onScanStart) props.onScanStart()
2618
2786
  setNote('已保存 ' + n + ' 条,正在扫描本榜…')
2619
2787
  return jpost('/scan', { boards: curBoard }).then(function (rr) {
2620
2788
  const got = ((rr && rr.boards) || []).map(function (x) { return x.boardId + ' ' + x.rows + ' 条' }).join('')
@@ -2625,14 +2793,25 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2625
2793
  }).catch(function (e2) {
2626
2794
  // ★ 保存成功、采集失败要**分开说**,否则用户会以为设置没存住、反复点
2627
2795
  setNote(null)
2628
- toast('error', '条数已保存,但扫描失败:' + e2 + '(可稍后重试扫描)')
2629
- })
2796
+ if (isScanBusyError(e2)) toast('warn', '已有扫描在进行,请等它跑完')
2797
+ else toast('error', '条数已保存,但扫描失败:' + e2 + '(可稍后重试扫描)')
2798
+ }).then(function () { if (props.onScanEnd) props.onScanEnd() })
2630
2799
  })
2631
2800
  .catch(function (e) { setNote(null); toast('error', '保存失败:' + e) })
2632
2801
  .then(function () { setScanning(false); setBusy(false) })
2633
2802
  }
2803
+ /** 409 = 已有扫描(host 互斥):不是错误,用 warn 提醒等一下 */
2804
+ const isScanBusyError = function (e) {
2805
+ return !!(e && (e.status === 409 || e.code === 'scan_in_flight' || /409|已有扫描/.test(String(e))))
2806
+ }
2807
+ const toastScanError = function (e) {
2808
+ setNote(null)
2809
+ if (isScanBusyError(e)) { toast('warn', '已有扫描在进行,请等它跑完'); return }
2810
+ toast('error', '扫描失败:' + e)
2811
+ }
2634
2812
  const scanBoard = function () {
2635
2813
  if (props.scanBusy || busy) return
2814
+ if (props.onScanStart) props.onScanStart()
2636
2815
  setBusy(true)
2637
2816
  setScanning(true)
2638
2817
  setNote('正在扫描本榜…')
@@ -2644,8 +2823,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2644
2823
  reloadBoard(true)
2645
2824
  if (props.onScanned) props.onScanned()
2646
2825
  })
2647
- .catch(function (e) { setNote(null); toast('error', '扫描失败:' + e) })
2648
- .then(function () { setScanning(false); setBusy(false) })
2826
+ .catch(function (e) { toastScanError(e) })
2827
+ .then(function () { if (props.onScanEnd) props.onScanEnd(); setScanning(false); setBusy(false) })
2649
2828
  }
2650
2829
  const doEnrich = function () {
2651
2830
  setBusy(true)
@@ -2857,7 +3036,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2857
3036
  selXS('排序', ss, sortOpts, pickSort)),
2858
3037
  dayOpen && canDay ? h('div', { style: { ...C.row, marginTop: '2px', flexWrap: 'wrap' } },
2859
3038
  h('span', { style: C.muted }, '上架日'),
2860
- h('input', { type: 'date', value: qDate, onChange: function (e) { setQDate(e.target.value) }, style: { fontSize: '12px', padding: '2px 4px' } }),
3039
+ h('input', { type: 'date', value: qDate, onChange: function (e) { setQDate(e.target.value) }, style: { ...C.input, width: 'auto' } }),
2861
3040
  h('button', { className: 'rs-btn', disabled: busy || !qDate, onClick: function () { queryDay(false) }, title: '直查站点这一上架日的数据(联网,不落盘)' }, '查看'),
2862
3041
  h('button', { className: 'rs-btn', disabled: busy || !qDate, onClick: function () { queryDay(true) }, title: '抓取该上架日并存为本地快照(联网)' }, '存入本地'),
2863
3042
  h('button', { className: 'rs-btn is-ghost', onClick: function () { setDayOpen(false) } }, '收起'),
@@ -2880,7 +3059,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2880
3059
  h('input', {
2881
3060
  type: 'number', min: 1, max: info.max, value: depth, placeholder: String(info.max), disabled: !info.can || busy,
2882
3061
  title: info.hint, onChange: function (e) { setDepth(e.target.value) },
2883
- style: { width: '58px', fontSize: '12px', padding: '2px 4px' },
3062
+ style: { ...C.input, width: '58px' },
2884
3063
  }),
2885
3064
  h('span', { style: C.muted }, info.can ? '条(上限 ' + info.max + ')' : '条 · ' + info.hint),
2886
3065
  h('button', { className: 'rs-btn', disabled: !info.can || busy, onClick: function () { saveDepth(false) }, title: '只保存,下次扫描生效' }, '保存'),
@@ -2974,6 +3153,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2974
3153
  * · 无障碍名由注册项的 label 提供(宿主做 aria-label + tooltip),不是内部 id。
2975
3154
  * 开关浮窗的入口在下方的「薄 main 面板」里(Q29)。
2976
3155
  */
3156
+ /* ---- parts/80-panel.js ---- */
3157
+ /**
3158
+ * 80-panel.js:侧栏入口图标与 Panel 外壳(页签、轮询、尺寸、Toast 挂载)。依赖前面全部页签。不要放 apply。
3159
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
3160
+ */
2977
3161
  function SidebarEntryIcon(props) {
2978
3162
  const size = Number(props && props.size) || 16
2979
3163
  const active = !!(props && props.active)
@@ -3203,8 +3387,14 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3203
3387
  scanStarting: scanActBusy && !scanLive,
3204
3388
  onOpenBoard: openBoard,
3205
3389
  onRescanBoard: function (boardId) { act('/scan', { boards: String(boardId) }) },
3390
+ onOpenSettings: function () { switchTab('pick') },
3206
3391
  })
3207
- : tab === 'board' ? h(BoardTab, { ov: ov, openLink: props.openLink, narrow: narrow, width: rect.w, rev: rev, scanBusy: scanBusy, onScanned: reload })
3392
+ : tab === 'board' ? h(BoardTab, {
3393
+ ov: ov, openLink: props.openLink, narrow: narrow, width: rect.w, rev: rev, scanBusy: scanBusy,
3394
+ onScanned: reload,
3395
+ onScanStart: function () { postInFlightRef.current += 1; setScanActBusy(true) },
3396
+ onScanEnd: function () { postInFlightRef.current = Math.max(0, postInFlightRef.current - 1); if (!scanLiveRef.current && postInFlightRef.current === 0) setScanActBusy(false) },
3397
+ })
3208
3398
  : tab === 'bm' ? h(BookmarksTab, { openLink: props.openLink })
3209
3399
  : h(SettingsTab, { ov: ov, onSaved: reload }))),
3210
3400
  h(ToastHost, null),
@@ -3223,6 +3413,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3223
3413
  * 之前只认 ①,行内/详情卡传进来的是 (url) ⇒ url 形参恒 undefined ⇒ **静默 return,什么也不发生**,
3224
3414
  * 于是「看起点图原始页」点了没反应(使用方 2026-10-15 反馈的就是这个)。
3225
3415
  */
3416
+ /* ---- parts/90-tail.js ---- */
3417
+ /**
3418
+ * 90-tail.js:openLink/diagLink、inject、apply 与 factory 返回值/闭合括号。依赖全部。不要放组件。
3419
+ * 这个文件是同一闭包里的连续片段;顶层执行顺序由文件名排序保证。
3420
+ */
3226
3421
  function openLink(ctx, url) {
3227
3422
  if (typeof ctx === 'string' && url === undefined) { url = ctx; ctx = null }
3228
3423
  if (!url) return
@@ -3327,7 +3522,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3327
3522
  return { name: 'dsh-rank-scan', inject: inject, apply: apply, __test: {
3328
3523
  metricChipText: metricChipText,
3329
3524
  helpers: { revOf: revOf, statusText: statusText, scanLabel: scanLabel, pollDelay: pollDelay, canDayQuery: canDayQuery, fitColumns: fitColumns, colPrio: colPrio, mdOf: mdOf, boardLabel: boardLabel, rememberBoardNames: rememberBoardNames },
3330
- components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel, ToastHost: ToastHost },
3525
+ components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel, ToastHost: ToastHost, StatCard: StatCard, SectionHeader: SectionHeader },
3526
+ nextPlanOf: nextPlanOf,
3331
3527
  toast: toast, toastStore: toastStore, lastNote: lastNote, settingsDiff: settingsDiff,
3332
3528
  } }
3333
3529
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-rank-scan",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "description": "DSH 扫榜插件:多站小说榜单采集 + 本地变化分析 + 面板;零运行时依赖",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",