dsh-rank-scan 0.4.2 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/lib/client.js +191 -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.0
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.0
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.0**);面板「设置」页底部会读 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
@@ -17,7 +17,10 @@ window.__ModuleLoader__.load({
17
17
  const readResponse = async (response) => {
18
18
  const data = await response.json()
19
19
  if (response.ok === false || (data && (data.ok === false || data.error))) {
20
- throw new Error((data && (data.error || data.note)) || ('请求失败:' + response.status))
20
+ const err = new Error((data && (data.error || data.note)) || ('请求失败:' + response.status))
21
+ err.status = response.status
22
+ if (data && data.code) err.code = data.code
23
+ throw err
21
24
  }
22
25
  return data
23
26
  }
@@ -208,6 +211,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
208
211
  '.rs-banner.is-error{border-color:' + T.bad + ';background:' + wash(T.bad, 8) + '}',
209
212
  '.rs-banner .rs-banner-body{flex:1 1 100%;min-width:0}',
210
213
  '.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}',
214
+ '.rs-statcard:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
211
215
  '.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
216
  '.rs-toast.is-info{border-color:' + T.accent + ';background-image:linear-gradient(' + wash(T.accent, 10) + ',' + wash(T.accent, 10) + ')}',
213
217
  '.rs-toast.is-warn{border-color:' + T.warn + ';background-image:linear-gradient(' + wash(T.warn, 12) + ',' + wash(T.warn, 12) + ')}',
@@ -1037,6 +1041,74 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1037
1041
  * ③ 全部榜单(可折叠;逐榜状态 + 涨/新/退;同站抓取时刻一致时只写一次)
1038
1042
  * ★ 2026-10-22(简明性 B):存储/保留/诊断移到「设置」页 —— 采集管理不再占首屏。
1039
1043
  */
1044
+ /**
1045
+ * 概览数字卡(0.5.0):值大、标签小;tone 只影响左色条与数字颜色,文字本身必须能读懂状态。
1046
+ * 有 onClick 时渲染成 button(Tab 可聚焦,focus-visible 蓝框),没有时是 div。
1047
+ */
1048
+ function StatCard(props) {
1049
+ const tone = props.tone || 'muted'
1050
+ const color = tone === 'ok' ? T.ok : tone === 'warn' ? T.warn : tone === 'bad' ? T.bad : T.muted
1051
+ const body = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0, textAlign: 'left' } },
1052
+ h('div', { style: { ...C.muted, fontSize: T.fs.s, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, props.label),
1053
+ h('div', { style: { fontSize: T.fs.l, fontWeight: 700, fontVariantNumeric: 'tabular-nums', color, lineHeight: 1.2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, props.value),
1054
+ props.sub ? h('div', { style: { ...C.muted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }, title: String(props.sub) }, props.sub) : null)
1055
+ const style = {
1056
+ display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0, boxSizing: 'border-box', textAlign: 'left',
1057
+ padding: '8px 10px', paddingLeft: '12px', border: '1px solid ' + T.border, borderLeft: '3px solid ' + color,
1058
+ borderRadius: T.r.s, background: T.surface, color: T.fg, font: 'inherit',
1059
+ cursor: props.onClick ? 'pointer' : 'default',
1060
+ }
1061
+ if (props.onClick) {
1062
+ return h('button', { type: 'button', className: 'rs-statcard', style: Object.assign({ appearance: 'none' }, style), onClick: props.onClick, title: props.title || props.label },
1063
+ body)
1064
+ }
1065
+ return h('div', { className: 'rs-statcard', style: style, title: props.title || '' }, body)
1066
+ }
1067
+ /** 概览区块小标题:标题 + 右侧计数 + 可选操作;innerRef 供数字卡 scrollIntoView 用 */
1068
+ function SectionHeader(props) {
1069
+ return h('div', { ref: props.innerRef, style: { display: 'flex', alignItems: 'baseline', gap: '8px', minWidth: 0, margin: props.first ? '8px 0 4px' : '12px 0 6px' } },
1070
+ h('div', { style: { fontWeight: 600, fontSize: T.fs.m, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, props.title),
1071
+ h('div', { style: { marginLeft: 'auto', display: 'flex', alignItems: 'baseline', gap: '6px', flex: '0 0 auto' } },
1072
+ props.count != null && props.count !== '' ? h('span', { style: C.muted }, '(' + props.count + ')') : null,
1073
+ props.action || null))
1074
+ }
1075
+
1076
+ const SITE_LABELS = { qidian: '起点', qidiantu: '起点图', ciweimao: '刺猬猫', sfacg: '菠萝包', fanqie: '番茄' }
1077
+ const siteLabelOf = function (ov, s) {
1078
+ const hit = ((ov && ov.sites) || []).filter(function (x) { return x.site === s })[0]
1079
+ return hit ? hit.siteName : (SITE_LABELS[s] || String(s))
1080
+ }
1081
+ /**
1082
+ * 下次计划(0.5.0 验收修正):
1083
+ * · waiting 里最近站点的时刻 → 中性色;
1084
+ * · 今天全跑完(无 waiting/fallback)→ 取已启用站 siteTimes 的最早时刻,写「明天 HH:mm」;
1085
+ * · siteTimes 也为空 → label 改成「上次扫描」,避免把过去的时刻说成将来的计划;
1086
+ * · 定时关闭/只剩兜底 → warn。
1087
+ */
1088
+ function nextPlanOf(plan, ov, scan, total) {
1089
+ if (!plan) return { label: '下次计划', value: '—', sub: '计划读取中', tone: 'muted' }
1090
+ if (plan.enabled === false) return { label: '下次计划', value: '已关闭', sub: '定时扫描', tone: 'warn' }
1091
+ if (typeof total === 'number' && total === 0) return { label: '下次计划', value: '—', sub: '还没有勾选要扫的榜', tone: 'muted' }
1092
+ const times = plan.siteTimes || {}
1093
+ const waiting = (plan.waiting || []).filter(function (s) { return times[s] })
1094
+ if (waiting.length) {
1095
+ const order = waiting.slice().sort(function (a, b) { return String(times[a]).localeCompare(String(times[b])) })
1096
+ return { label: '下次计划', value: times[order[0]], sub: siteLabelOf(ov, order[0]), tone: 'muted' }
1097
+ }
1098
+ if ((plan.fallback || []).length) {
1099
+ return { label: '下次计划', value: plan.fallbackTime || '22:30', sub: siteLabelOf(ov, plan.fallback[0]), tone: 'warn' }
1100
+ }
1101
+ const enabled = ((ov && ov.sites) || []).map(function (s) { return s.site }).filter(function (s) { return times[s] })
1102
+ const nextTimes = enabled.slice().sort(function (a, b) { return String(times[a]).localeCompare(String(times[b])) })
1103
+ if (nextTimes.length) {
1104
+ const s = nextTimes[0]
1105
+ return { label: '下次计划', value: '明天 ' + times[s], sub: siteLabelOf(ov, s), tone: 'muted' }
1106
+ }
1107
+ const last = scan && (scan.startedAt || scan.at)
1108
+ if (last) return { label: '上次扫描', value: fmtLocalHM(last), sub: '最近一次', tone: 'muted' }
1109
+ return { label: '下次计划', value: '—', sub: '暂时算不出下次', tone: 'muted' }
1110
+ }
1111
+
1040
1112
  function Overview(props) {
1041
1113
  const ov = props.ov
1042
1114
  /**
@@ -1060,6 +1132,9 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1060
1132
  const allS = React.useState(true)
1061
1133
  const showAll = allS[0]
1062
1134
  const setShowAll = allS[1]
1135
+ const allRef = React.useRef(null)
1136
+ const issuesRef = React.useRef(null)
1137
+ const changesRef = React.useRef(null)
1063
1138
  const rev = props.rev || revOf(ov)
1064
1139
  /**
1065
1140
  * ★ 2026-10-22(同日刷新):依赖**修订号**而不是 dataDate。
@@ -1094,15 +1169,15 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1094
1169
  id = setInterval(tick, 5000)
1095
1170
  return function () { alive = false; if (id) clearInterval(id) }
1096
1171
  }, [])
1097
- if (!ov) return h('div', { style: C.muted }, '加载中…')
1098
- const c = ov.counts || {}
1172
+ // 0.5.0:/overview 未到时不再整页「加载中…」——四张卡先占位「—」,版面不跳
1173
+ const c = (ov && ov.counts) || {}
1099
1174
  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 } }) })
1175
+ const rows = ((ov && ov.sites) || []).flatMap(function (s) { return (s.boards || []).map(function (b) { return { ...b, siteName: s.siteName } }) })
1101
1176
 
1102
- const scan = ov.scan || null
1103
- const plan = (ov.services && ov.services.schedule) || null
1177
+ const scan = (ov && ov.scan) || null
1178
+ const plan = (ov && ov.services && ov.services.schedule) || null
1104
1179
  const staleIds = plan && plan.staleFlag
1105
- ? Object.keys(plan.staleFlag).filter(function (k) { return plan.staleFlag[k] && plan.staleFlag[k].date === ov.dataDate })
1180
+ ? Object.keys(plan.staleFlag).filter(function (k) { return plan.staleFlag[k] && plan.staleFlag[k].date === (ov && ov.dataDate) })
1106
1181
  : []
1107
1182
  /**
1108
1183
  * ★ Spec S3(2026-10-22):「未到计划」和「待补跑」不是失败。
@@ -1124,7 +1199,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1124
1199
  }
1125
1200
  const plannedTimeOf = function (b) {
1126
1201
  if (b.plannedTime) return String(b.plannedTime)
1127
- const times = (plan && plan.siteTimes) || (ov.defaults && ov.defaults.siteTimes) || {}
1202
+ const times = (plan && plan.siteTimes) || (ov && ov.defaults && ov.defaults.siteTimes) || {}
1128
1203
  return times[siteOfBoardId(b.boardId)] || ''
1129
1204
  }
1130
1205
  const waitingRows = rows.filter(function (b) { return scheduleStateOf(b) === 'waiting' })
@@ -1216,23 +1291,62 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1216
1291
  if (last && last.site === e.site) last.items.push(e)
1217
1292
  else shownBySite.push({ site: e.site, siteName: e.siteName, items: [e] })
1218
1293
  })
1294
+ const collectSub = [
1295
+ waitingRows.length ? '未到计划 ' + waitingRows.length : '',
1296
+ dueRows.length ? '待补跑 ' + dueRows.length : '',
1297
+ ].filter(Boolean).join(' · ')
1298
+ const collectSubText = collectSub || (badRows.length ? '有榜没抓到' : (ov && total > 0 && (c.ok || 0) === total ? '全部采集完成' : ''))
1299
+ const collectTone = badRows.length ? 'bad' : dueRows.length ? 'warn' : (ov && total > 0 && (c.ok || 0) === total ? 'ok' : 'muted')
1300
+ const issuesTone = !issues.length ? 'ok' : (issues.some(function (it) { return it.status !== 'stale' && it.status !== 'enrich' }) ? 'bad' : 'warn')
1301
+ const changesSub = Object.keys(chgTotals).slice(0, 2).map(function (g) { return g + ' ' + chgTotals[g] }).join(' · ')
1302
+ const nextPlan = nextPlanOf(plan, ov, scan, total)
1303
+ const noData = !!(ov && (c.ok || 0) === 0 && chgRealTotal === 0)
1304
+ const noChanges = !!(ov && (c.ok || 0) > 0 && chg && chgRealTotal === 0)
1305
+ const jump = function (ref) {
1306
+ const el = ref && ref.current
1307
+ if (el && typeof el.scrollIntoView === 'function') { try { el.scrollIntoView({ block: 'nearest' }) } catch (e) {} }
1308
+ }
1309
+ const goAll = function () {
1310
+ setShowAll(true)
1311
+ setTimeout(function () { jump(allRef) }, 0)
1312
+ }
1219
1313
  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 },
1314
+ /* ① 数据日期小字 */
1315
+ h('div', { style: { ...C.muted, display: 'flex', gap: '6px', flexWrap: 'wrap', marginBottom: '6px' } },
1316
+ h('span', { title: '扫描开始时刻的本地自然日' }, '数据日期 ' + dash(ov && ov.dataDate)),
1317
+ ov && ov.hiddenCount ? h('span', null, '· 未显示 ' + ov.hiddenCount + ' 个榜') : null),
1318
+ /* ② 四张数字卡:先回答「今天怎么样」 */
1319
+ // 480px 面板内宽约 455px:140px 会挤成 3 列,180px 才能落到验收要求的 2×2
1320
+ h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: '8px' } },
1321
+ h(StatCard, {
1322
+ label: '已采集', value: ov ? (c.ok || 0) + '/' + total : '—',
1323
+ sub: ov ? (collectSubText || (total ? '—' : '还没有采集')) : '读取中', tone: collectTone,
1324
+ onClick: goAll, title: '展开全部榜单并滚到那里',
1325
+ }),
1326
+ h(StatCard, {
1327
+ label: '待处理', value: !ov ? '—' : (issues.length ? String(issues.length) : '无'),
1328
+ sub: !ov ? '读取中' : (issues.length ? '需要你动手' : '没有要处理的'), tone: !ov ? 'muted' : issuesTone,
1329
+ onClick: issues.length ? function () { jump(issuesRef) } : undefined,
1330
+ title: issues.length ? '滚到「需要处理」' : '当前没有问题',
1331
+ }),
1332
+ h(StatCard, {
1333
+ label: '今日变化', value: chg ? String(chgRealTotal) : '—',
1334
+ sub: !chg ? '读取中' : (changesSub || (chgRealTotal ? '' : '今天没有变化')),
1335
+ tone: chgRealTotal ? 'ok' : 'muted',
1336
+ onClick: chg ? function () { jump(changesRef) } : undefined,
1337
+ title: '滚到「今天的变化」',
1338
+ }),
1339
+ h(StatCard, {
1340
+ label: nextPlan.label, value: nextPlan.value, sub: nextPlan.sub, tone: nextPlan.tone,
1341
+ onClick: plan && plan.enabled === false && props.onOpenSettings ? props.onOpenSettings : undefined,
1342
+ title: plan && plan.enabled === false ? '定时已关闭,点这里去设置' : '下一次站点计划',
1343
+ })),
1344
+ /* ③ 主动作:扫描(联网)与重新载入(只读本地)分开写清 */
1345
+ h('div', { style: { ...C.row, marginTop: '8px' } },
1232
1346
  h('button', {
1233
1347
  className: 'rs-btn is-primary',
1234
- disabled: scanBusy,
1235
- title: '按「设置 → 抓取范围」里勾选的榜逐个扫描(联网)',
1348
+ disabled: scanBusy || !ov || total === 0,
1349
+ title: total === 0 ? '还没有勾选要扫的榜,先去「设置 → 抓取范围」勾选' : '按「设置 → 抓取范围」里勾选的榜逐个扫描(联网)',
1236
1350
  onClick: function () { props.act('/scan') },
1237
1351
  }, scanBtnText),
1238
1352
  scanBusy ? h('button', { className: 'rs-btn is-danger', onClick: function () { props.act('/cancel') } }, '停止本次(保留已完成)') : null,
@@ -1240,14 +1354,26 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1240
1354
  h('button', { className: 'rs-btn is-ghost', onClick: props.reload, title: '只重新读取本地数据:不联网、不采集' }, '重新载入'),
1241
1355
  // 运行中不显示「上次 …」:那一轮还没结束,进度只放在主按钮一处(否则会同时出现两条「扫描中」)
1242
1356
  scanRunning ? null : h('span', { style: C.muted }, '上次 ' + scanLabel(scan))),
1243
- /* 补全进度:面板顶部只有这一条(三态:跑着 / 还能续跑 / 当日已试满) */
1357
+ /* ④ 需要处理:要用户动手的排后台补全前面 */
1358
+ issues.length ? h('div', { ref: issuesRef },
1359
+ h(Banner, { tone: issues.some(function (it) { return it.status !== 'stale' && it.status !== 'enrich' }) ? 'error' : 'warn', title: '需要处理' },
1360
+ h('div', { className: 'rs-banner-body', style: { display: 'flex', flexDirection: 'column', gap: '2px' } }, issues.map(function (it) {
1361
+ return h('div', { key: it.key, style: { ...C.row, alignItems: 'baseline' } },
1362
+ h('span', { style: C.dot(it.status === 'stale' || it.status === 'enrich' ? 'warn' : 'bad') }),
1363
+ h('span', { style: { fontWeight: 600 } }, it.name),
1364
+ it.at ? h('span', { style: C.muted }, fmtLocalHM(it.at)) : null,
1365
+ h('span', null, it.why),
1366
+ it.detail ? h('span', { style: C.muted }, '(' + String(it.detail).slice(0, 80) + ')') : null,
1367
+ it.boardId ? h('button', { className: 'rs-btn', disabled: props.busy, onClick: function () { props.onOpenBoard && props.onOpenBoard(it.boardId) }, title: '在「榜单」页打开这一榜(保上下文)' }, '查看本榜') : null,
1368
+ it.boardId ? h('button', { className: 'rs-btn', disabled: props.busy, onClick: function () { props.onRescanBoard && props.onRescanBoard(it.boardId) }, title: '只重扫这一榜(联网)' }, '重扫本榜') : null)
1369
+ })))) : null,
1370
+ /* ⑤ 补全进度:面板顶部只有这一条(三态:跑着 / 还能续跑 / 当日已试满) */
1244
1371
  (function () {
1245
1372
  if (!enrichStatus) return null
1246
1373
  const run = enrichStatus.enrichRun
1247
1374
  const active = !!(run && run.active === true)
1248
1375
  const left = typeof enrichStatus.pending === 'number' ? enrichStatus.pending : 0
1249
1376
  if (!active && !left) return null
1250
- // 「还能不能续跑」用宿主的 retryable 判(0 = 当日已试满),前端不自己猜
1251
1377
  const retryable = typeof enrichStatus.retryable === 'number' ? enrichStatus.retryable : null
1252
1378
  const label = active
1253
1379
  ? '补全中 ' + ((run && run.done) || 0) + '/' + ((run && run.total) || 0) + ' 个榜(可以先浏览,不用等)'
@@ -1256,27 +1382,16 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1256
1382
  : '补全未完成:还缺 ' + left + ' 个榜(后台会继续补,也可进榜点「补全缺失字段」)'
1257
1383
  return h(Banner, { tone: active ? 'info' : 'warn', live: false }, label)
1258
1384
  })(),
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
1385
  /* ④ 今天的变化 */
1276
- h('div', { style: C.siteBar }, '今天的变化' + (chgRealTotal ? '(' + chgRealTotal + ' 条)' : '')),
1386
+ h(SectionHeader, { innerRef: changesRef, title: '今天的变化', count: chgRealTotal ? chgRealTotal + ' 条' : '' }),
1277
1387
  chg && chg.note ? h('div', { style: C.muted }, chg.note) : null,
1278
1388
  previewLimited ? h('div', { style: C.muted }, '下表每榜每类最多列 20 条(本次 ' + chgEntries.length + ' 条,共 ' + chgRealTotal + ' 条);点行到榜页看全部。') : null,
1279
- chg && chg.count === 0 ? h('div', { style: C.muted }, '没有变化条目(或还没有可比基准)') : null,
1389
+ total === 0 ? h('div', { style: { ...C.row, alignItems: 'center' } },
1390
+ h('span', { style: C.muted }, '还没有勾选要扫的榜'),
1391
+ props.onOpenSettings ? h('button', { className: 'rs-btn is-ghost', onClick: props.onOpenSettings }, '去设置勾选') : null) : null,
1392
+ total === 0 ? null : noData ? h('div', { style: C.muted }, '今天还没有采集结果,到计划时刻会自动跑,也可以点「扫描已选榜」') : null,
1393
+ noChanges ? h('div', { style: C.muted }, '今天没有榜单变化') : null,
1394
+ ov && !chg && !noData ? h('div', { style: C.muted }, '正在读取今天的变化…') : null,
1280
1395
  chgEntries.length ? h('div', { style: C.row },
1281
1396
  [{ label: '全部', value: '' }].concat(groupNames.map(function (g) { return { label: g, value: g } })).map(function (o) {
1282
1397
  return h('button', {
@@ -1335,15 +1450,17 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1335
1450
  return [head].concat(body)
1336
1451
  })))) : null,
1337
1452
  /* ⑤ 全部榜单(可折叠) */
1338
- h('div', { style: { ...C.row, marginTop: '8px' } },
1339
- h('button', {
1453
+ h(SectionHeader, {
1454
+ innerRef: allRef, title: '全部榜单', count: total,
1455
+ action: h('button', {
1340
1456
  className: 'rs-btn is-ghost',
1341
1457
  'aria-expanded': showAll ? 'true' : 'false',
1342
1458
  onClick: function () { setShowAll(!showAll) },
1343
- }, (showAll ? '▾ ' : '▸ ') + '全部榜单(' + total + ')')),
1344
- showAll ? h('table', { style: C.table },
1459
+ }, showAll ? '收起' : '展开'),
1460
+ }),
1461
+ showAll && total > 0 ? h('table', { style: C.table },
1345
1462
  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) {
1463
+ h('tbody', null, ((ov && ov.sites) || []).flatMap(function (s) {
1347
1464
  const okN = s.boards.filter(function (b) { return b.status === 'ok' }).length
1348
1465
  const times = s.boards.map(function (b) { return b.lastCapture ? fmtLocalHM(b.lastCapture) : '' })
1349
1466
  const sameTime = times.length > 0 && times.every(function (t) { return t === times[0] })
@@ -2615,6 +2732,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2615
2732
  toast('success', (r && r.note) || ('已保存:每榜取 ' + n + ' 条'))
2616
2733
  if (!alsoScan) return null
2617
2734
  setScanning(true)
2735
+ if (props.onScanStart) props.onScanStart()
2618
2736
  setNote('已保存 ' + n + ' 条,正在扫描本榜…')
2619
2737
  return jpost('/scan', { boards: curBoard }).then(function (rr) {
2620
2738
  const got = ((rr && rr.boards) || []).map(function (x) { return x.boardId + ' ' + x.rows + ' 条' }).join('')
@@ -2625,14 +2743,25 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2625
2743
  }).catch(function (e2) {
2626
2744
  // ★ 保存成功、采集失败要**分开说**,否则用户会以为设置没存住、反复点
2627
2745
  setNote(null)
2628
- toast('error', '条数已保存,但扫描失败:' + e2 + '(可稍后重试扫描)')
2629
- })
2746
+ if (isScanBusyError(e2)) toast('warn', '已有扫描在进行,请等它跑完')
2747
+ else toast('error', '条数已保存,但扫描失败:' + e2 + '(可稍后重试扫描)')
2748
+ }).then(function () { if (props.onScanEnd) props.onScanEnd() })
2630
2749
  })
2631
2750
  .catch(function (e) { setNote(null); toast('error', '保存失败:' + e) })
2632
2751
  .then(function () { setScanning(false); setBusy(false) })
2633
2752
  }
2753
+ /** 409 = 已有扫描(host 互斥):不是错误,用 warn 提醒等一下 */
2754
+ const isScanBusyError = function (e) {
2755
+ return !!(e && (e.status === 409 || e.code === 'scan_in_flight' || /409|已有扫描/.test(String(e))))
2756
+ }
2757
+ const toastScanError = function (e) {
2758
+ setNote(null)
2759
+ if (isScanBusyError(e)) { toast('warn', '已有扫描在进行,请等它跑完'); return }
2760
+ toast('error', '扫描失败:' + e)
2761
+ }
2634
2762
  const scanBoard = function () {
2635
2763
  if (props.scanBusy || busy) return
2764
+ if (props.onScanStart) props.onScanStart()
2636
2765
  setBusy(true)
2637
2766
  setScanning(true)
2638
2767
  setNote('正在扫描本榜…')
@@ -2644,8 +2773,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2644
2773
  reloadBoard(true)
2645
2774
  if (props.onScanned) props.onScanned()
2646
2775
  })
2647
- .catch(function (e) { setNote(null); toast('error', '扫描失败:' + e) })
2648
- .then(function () { setScanning(false); setBusy(false) })
2776
+ .catch(function (e) { toastScanError(e) })
2777
+ .then(function () { if (props.onScanEnd) props.onScanEnd(); setScanning(false); setBusy(false) })
2649
2778
  }
2650
2779
  const doEnrich = function () {
2651
2780
  setBusy(true)
@@ -2857,7 +2986,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2857
2986
  selXS('排序', ss, sortOpts, pickSort)),
2858
2987
  dayOpen && canDay ? h('div', { style: { ...C.row, marginTop: '2px', flexWrap: 'wrap' } },
2859
2988
  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' } }),
2989
+ h('input', { type: 'date', value: qDate, onChange: function (e) { setQDate(e.target.value) }, style: { ...C.input, width: 'auto' } }),
2861
2990
  h('button', { className: 'rs-btn', disabled: busy || !qDate, onClick: function () { queryDay(false) }, title: '直查站点这一上架日的数据(联网,不落盘)' }, '查看'),
2862
2991
  h('button', { className: 'rs-btn', disabled: busy || !qDate, onClick: function () { queryDay(true) }, title: '抓取该上架日并存为本地快照(联网)' }, '存入本地'),
2863
2992
  h('button', { className: 'rs-btn is-ghost', onClick: function () { setDayOpen(false) } }, '收起'),
@@ -2880,7 +3009,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2880
3009
  h('input', {
2881
3010
  type: 'number', min: 1, max: info.max, value: depth, placeholder: String(info.max), disabled: !info.can || busy,
2882
3011
  title: info.hint, onChange: function (e) { setDepth(e.target.value) },
2883
- style: { width: '58px', fontSize: '12px', padding: '2px 4px' },
3012
+ style: { ...C.input, width: '58px' },
2884
3013
  }),
2885
3014
  h('span', { style: C.muted }, info.can ? '条(上限 ' + info.max + ')' : '条 · ' + info.hint),
2886
3015
  h('button', { className: 'rs-btn', disabled: !info.can || busy, onClick: function () { saveDepth(false) }, title: '只保存,下次扫描生效' }, '保存'),
@@ -3203,8 +3332,14 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3203
3332
  scanStarting: scanActBusy && !scanLive,
3204
3333
  onOpenBoard: openBoard,
3205
3334
  onRescanBoard: function (boardId) { act('/scan', { boards: String(boardId) }) },
3335
+ onOpenSettings: function () { switchTab('pick') },
3206
3336
  })
3207
- : tab === 'board' ? h(BoardTab, { ov: ov, openLink: props.openLink, narrow: narrow, width: rect.w, rev: rev, scanBusy: scanBusy, onScanned: reload })
3337
+ : tab === 'board' ? h(BoardTab, {
3338
+ ov: ov, openLink: props.openLink, narrow: narrow, width: rect.w, rev: rev, scanBusy: scanBusy,
3339
+ onScanned: reload,
3340
+ onScanStart: function () { postInFlightRef.current += 1; setScanActBusy(true) },
3341
+ onScanEnd: function () { postInFlightRef.current = Math.max(0, postInFlightRef.current - 1); if (!scanLiveRef.current && postInFlightRef.current === 0) setScanActBusy(false) },
3342
+ })
3208
3343
  : tab === 'bm' ? h(BookmarksTab, { openLink: props.openLink })
3209
3344
  : h(SettingsTab, { ov: ov, onSaved: reload }))),
3210
3345
  h(ToastHost, null),
@@ -3327,7 +3462,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3327
3462
  return { name: 'dsh-rank-scan', inject: inject, apply: apply, __test: {
3328
3463
  metricChipText: metricChipText,
3329
3464
  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 },
3465
+ components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel, ToastHost: ToastHost, StatCard: StatCard, SectionHeader: SectionHeader },
3466
+ nextPlanOf: nextPlanOf,
3331
3467
  toast: toast, toastStore: toastStore, lastNote: lastNote, settingsDiff: settingsDiff,
3332
3468
  } }
3333
3469
  },
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.0",
4
4
  "description": "DSH 扫榜插件:多站小说榜单采集 + 本地变化分析 + 面板;零运行时依赖",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",