1) 大屏背景图不生效:App.vue 里 .bg 与 .bg-fallback 都是 absolute inset:0, 而兜底渐变是不透明的且在图片之后绘制 → 配了背景图也只看得到渐变。 改成 v-if/v-else 互斥(用无头 Chromium 真渲染对照验证:修复后取到图片像素, 回退版本只剩渐变)。新增 background-layer.test.ts 锁住层次关系。 2) 规则/config 仍在安装目录,覆盖安装/卸载会连配置一起删:现在三样都落在 %LOCALAPPDATA%\ScoreboardConsole\(与数据目录同一基座): - console\config.json(Console 读写都用这份) - config.yaml(Console 用绝对路径 -config 传给服务端与 passwd) - rules\(首次从安装目录复制过去,之后只认用户目录那份) 首次运行复制迁移、已存在不覆盖、不可写则回落安装目录并记日志(不影响启动); 开发态行为不变。备份脚本与文档同步。 注意 resolveExecutable 必须显式传部署包根目录,否则会去用户目录找 scoreboard.exe。 自检:服务端 11 包全绿;console 语法 16 文件 + node:test 20/20; 前端 vue-tsc + build、node --test 69/69。
94 lines
3.5 KiB
JavaScript
94 lines
3.5 KiB
JavaScript
'use strict'
|
|
|
|
const path = require('path')
|
|
const { spawn } = require('child_process')
|
|
|
|
// 用户名 / 密码长度上限:passwd 自己也会限制,这里只是把明显不合法的挡在 UI 侧
|
|
const FIELD_MAX = 64
|
|
|
|
// 返回错误文案,null 表示通过。required 为 false 时允许空串(= 不改 / 随机生成)
|
|
function validateAccountField(value, label, required) {
|
|
if (typeof value !== 'string') return `${label}必须是文本`
|
|
if (value === '') return required ? `${label}不能为空` : null
|
|
// spawn 用参数数组、不经 shell,不存在命令注入;但空格会把参数拆成两段、
|
|
// 换行会截断输出,所以在入口直接拒掉,别让 passwd 报看不懂的错。
|
|
if (/\s/.test(value)) return `${label}不能包含空格、制表符或换行`
|
|
if (value.length > FIELD_MAX) return `${label}最多 ${FIELD_MAX} 个字符`
|
|
return null
|
|
}
|
|
|
|
// 空的新用户名 / 空密码直接传空串:passwd 的语义就是「留空则不改 / 随机生成」
|
|
// dataDir 非空时带上 -data,否则 passwd 会用 config.yaml 的默认目录、
|
|
// 改到另一个库里的账号上
|
|
function buildPasswdArgs({ configArg, dataDir, currentUsername, newUsername, password }) {
|
|
const args = ['passwd', '-config', configArg]
|
|
if (typeof dataDir === 'string' && dataDir !== '') args.push('-data', dataDir)
|
|
args.push('-user', currentUsername, '-new-username', newUsername, '-password', password)
|
|
return args
|
|
}
|
|
|
|
// passwd 正常是秒级完成;卡住(等待输入等)时必须自己收尾,否则 UI 重置按钮永久禁用
|
|
const DEFAULT_TIMEOUT_MS = 30000
|
|
|
|
// 跑一次 passwd,实时把 stdout/stderr 交给 onOutput,结束时返回完整输出与退出码
|
|
function runPasswd({ exePath, args, onOutput, timeoutMs = DEFAULT_TIMEOUT_MS }) {
|
|
return new Promise((resolve) => {
|
|
let child
|
|
try {
|
|
// cwd 取 exe 所在目录(部署包根目录);config.yaml 与数据目录都由参数给绝对路径,
|
|
// 不依赖 cwd
|
|
child = spawn(exePath, args, {
|
|
cwd: path.dirname(exePath),
|
|
windowsHide: true,
|
|
stdio: ['ignore', 'pipe', 'pipe']
|
|
})
|
|
} catch (err) {
|
|
resolve({ ok: false, error: `启动 passwd 失败:${err.message}`, output: '' })
|
|
return
|
|
}
|
|
|
|
let output = ''
|
|
let settled = false
|
|
let timer = null
|
|
const finish = (result) => {
|
|
if (settled) return
|
|
settled = true
|
|
if (timer) clearTimeout(timer)
|
|
resolve(result)
|
|
}
|
|
const onChunk = (chunk) => {
|
|
const text = String(chunk)
|
|
output += text
|
|
if (typeof onOutput === 'function') onOutput(text)
|
|
}
|
|
|
|
if (child.stdout) {
|
|
child.stdout.setEncoding('utf8')
|
|
child.stdout.on('data', onChunk)
|
|
}
|
|
if (child.stderr) {
|
|
child.stderr.setEncoding('utf8')
|
|
child.stderr.on('data', onChunk)
|
|
}
|
|
|
|
if (timeoutMs > 0) {
|
|
timer = setTimeout(() => {
|
|
try {
|
|
child.kill('SIGKILL')
|
|
} catch {
|
|
// 进程可能已经没了
|
|
}
|
|
finish({ ok: false, error: `passwd 执行超过 ${Math.ceil(timeoutMs / 1000)} 秒,已终止`, output })
|
|
}, timeoutMs)
|
|
}
|
|
|
|
child.on('error', (err) => finish({ ok: false, error: err.message, output }))
|
|
// 用 close 而不是 exit:等两个 stdio 都排空,输出才是完整的
|
|
child.on('close', (code, signal) => {
|
|
finish({ ok: code === 0, exitCode: code, signal: signal || null, output })
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports = { validateAccountField, buildPasswdArgs, runPasswd }
|