feat(splash): 启动加载改成真实进度条(局域网资料目录也能看到进度)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m0s

用户把资料目录放在局域网/NAS 上,启动要逐个读 canvases/*.json,原来是无限跑马灯,
不知道在读什么、还要多久。

- src/runtime-boot-progress.js(新增):进度总线,按阶段分配权重
  prepare 0-6 / data 6-10 / canvases 10-70 / library 70-80 / finalize 80-96,完成收口 100;
  百分比单调不减,并发分支晚回来不会回退
- src/storage-file.js:loadInto 读 data.json / 逐个画布 / 资源库文件时按文件数上报
- src/runtime-boot-load.js:进入"恢复会话"阶段上报一次
- src/ui-splash.js(新增):启动屏搬到独立模块(app.js 由 8327 行降到 8322),
  细进度条 + 流光 + 阶段文字 + 右侧百分比 + aria progressbar
- style.css:进度条重做(圆角全用 token、渐变语义色、流光动画、减少动效时关闭动画)
- tests/boot-progress-test.js:16 项钉住换算规则(起点/中途/收口/单调/订阅)
This commit is contained in:
qiqi committed 2026-11-27 21:28:40 +08:00
1 parent 64b6652bb1
commit e3c7a3ff9b
14 files changed
+223 -18

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
/* boot-progress.js —— 启动加载进度总线(v3.26.109)
*
* 为什么要它:资料目录放在局域网/NAS 上时,读取是"每个文件一次网络往返",
* canvases/ 里有几十个文件就要等几十次。原来的启动屏只有一条不定长动画,
* 用户不知道在读什么、还要多久。
*
* 这里把"读到第几个文件"换算成真实百分比(按阶段分配权重),启动屏只负责渲染。
* 百分比单调不减:并发分支回来的慢结果不会让进度条倒退。
*/
;(function (global) {
'use strict'
const PHASES = {
prepare: { from: 0, to: 6, label: '准备资料目录' },
data: { from: 6, to: 10, label: '读取 data.json' },
canvases: { from: 10, to: 70, label: '读取画布' },
library: { from: 70, to: 80, label: '读取资源库' },
finalize: { from: 80, to: 96, label: '恢复会话' },
}
const state = { pct: 0, label: '正在启动…', detail: '', indeterminate: true, done: false }
const subs = new Set()
const snapshot = () => ({ pct: state.pct, label: state.label, detail: state.detail, indeterminate: state.indeterminate, done: state.done })
function emit () {
const s = snapshot()
subs.forEach((fn) => { try { fn(s) } catch (e) { /* 单个订阅者出错不影响其它 */ } })
}
// report(阶段, 已完成, 总数):total 缺省/0 时该阶段仍算"不定长"
function report (phase, done, total, detail) {
const p = PHASES[phase]
if (p) {
const d = Number(done) || 0
const t = Number(total) || 0
const k = t > 0 ? Math.max(0, Math.min(1, d / t)) : 0
const pct = Math.round(p.from + (p.to - p.from) * k)
if (pct > state.pct) state.pct = pct
state.indeterminate = !(t > 0)
state.label = p.label
state.detail = detail || (t > 0 ? d + ' / ' + t : '')
}
if (detail) state.detail = String(detail)
emit()
}
function note (text) {
if (text) state.detail = String(text)
emit()
}
function finish () {
if (state.done) return
state.pct = 100
state.indeterminate = false
state.done = true
state.label = '加载完成'
state.detail = ''
emit()
}
function subscribe (fn) {
if (typeof fn !== 'function') return function () {}
subs.add(fn)
try { fn(snapshot()) } catch (e) { /* ignore */ }
return function () { subs.delete(fn) }
}
global.IWBBootProgress = { report, note, finish, subscribe, snapshot, phases: PHASES }
})(typeof window !== 'undefined' ? window : globalThis)