人员与报名:
- 人员唯一标识改为「证件号 或 号码布」二选一(0013/0014 迁移 + 导入匹配/回填/冲突)
- 人员新增「年龄」(0015 迁移):表单/列表/导入模板表头 11 列;冲突比较只在两边
都有值且不同时才算差异,旧数据不误报
- 冲突决策键改为「证件号优先 → 号码布」(前端原先只用 idCard,号码布行会互相覆盖)
- 报名选择器支持无证件号但有号码布的运动员
大屏与 Console:
- 大屏控制新增「显示器」菜单:可给指定显示器重建全屏窗口;单屏/主显示器强制窗口化,
限制在 Console 侧判定,不信任页面传参
- Console 服务管理窗口改左右两栏,运行日志独占右栏满高;窗口默认尺寸 1280×860
- 大屏右上角时钟精确到秒(同时把刷新间隔 15s 改为 1s)
图片与配置:
- 新增图片上传 POST /api/uploads(recorder+,png/jpg/webp/gif,≤5MiB)与匿名静态
访问 GET /uploads/{name}(防目录穿越);文件落赛事项目目录 uploads/,随赛事包
一起导出/导入
- 「赛事信息」新增赛事会标 / 大屏会标 / 大屏背景图三个上传项
- 参赛单位 logo 输入框右侧加上传按钮
关于页与构建:
- 构建时间打通:version.BuildTime + /api/system/about 返回 + build.bat 注入
(用 PowerShell 取时间戳,避免本地化 %DATE% 的非 ASCII 星期)
安装包:
- 主程序改名 Scoreboard_Console.exe(win.executableName;productName/显示名不变)
- 记住上次安装目录:自定义 NSIS 宏优先沿用自存路径(卸载不清除),并在 customInit
里补写回 electron-builder 的键,避免安装模式页把 $INSTDIR 打回默认
自检:服务端 12 包全绿;前端 vue-tsc + build 通过、node --test 58/58;console 12 文件通过。
119 lines
4.1 KiB
JavaScript
119 lines
4.1 KiB
JavaScript
'use strict'
|
||
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
// 默认值写死在代码里:config.json 只覆盖要改的项。
|
||
// 这样升级新增字段时老配置依然能用,现场也不容易配出半成品。
|
||
const DEFAULTS = {
|
||
server: {
|
||
exe: 'scoreboard.exe',
|
||
args: ['-config', 'config.yaml'],
|
||
host: '127.0.0.1',
|
||
port: 19540,
|
||
autoStart: true,
|
||
healthIntervalMs: 5000,
|
||
restartDelayMs: 3000,
|
||
// 0 表示无限重启;服务端是现场唯一进程,崩了必须拉起来
|
||
maxRestarts: 0,
|
||
// 优雅关闭握手:服务端需实现该回环接口并校验 X-Shutdown-Token,
|
||
// 未实现(404/连接失败)时回退到进程信号
|
||
shutdownPath: '/api/shutdown',
|
||
// 服务端受理关闭请求后等待其自行退出的上限,超过则强杀
|
||
shutdownTimeoutMs: 5000,
|
||
// 连续健康这么久后清零崩溃计数,避免历史崩溃耗尽 maxRestarts
|
||
healthyResetMs: 60000
|
||
},
|
||
display: {
|
||
// all-secondary | all | specified
|
||
selection: 'all-secondary',
|
||
displays: [],
|
||
// 只能写大屏实际支持的页名(见 web/src/display/types.ts 的 PAGE_ALIASES)
|
||
pages: ['standings', 'medals', 'individual', 'results'],
|
||
pageParam: 'page',
|
||
kiosk: true,
|
||
ignoreMouse: true,
|
||
reloadEveryHours: 24,
|
||
// 服务端迟迟没就绪时的兜底:超时后也把大屏开出来,避免现场一片黑
|
||
waitForServerMs: 20000,
|
||
backgroundColor: '#0b0f1a'
|
||
},
|
||
startup: {
|
||
// 默认注册登录项但不启用(任务管理器「启动」里可见);服务管理窗口的开关控制是否真的随系统启动
|
||
openAtLogin: false
|
||
},
|
||
admin: {
|
||
width: 1280,
|
||
height: 860
|
||
},
|
||
log: {
|
||
maxLines: 2000,
|
||
file: 'logs/console.log',
|
||
maxFileBytes: 4 * 1024 * 1024
|
||
}
|
||
}
|
||
|
||
function isPlainObject(value) {
|
||
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
||
}
|
||
|
||
function merge(base, override) {
|
||
const out = isPlainObject(base) ? { ...base } : {}
|
||
if (!isPlainObject(override)) return out
|
||
for (const [key, value] of Object.entries(override)) {
|
||
if (value === undefined) continue
|
||
out[key] = isPlainObject(value) && isPlainObject(base[key]) ? merge(base[key], value) : value
|
||
}
|
||
return out
|
||
}
|
||
|
||
function readJson(file) {
|
||
try {
|
||
const raw = fs.readFileSync(file, 'utf8')
|
||
return { values: JSON.parse(raw), warning: null }
|
||
} catch (err) {
|
||
if (err.code === 'ENOENT') return { values: {}, warning: `配置文件不存在,使用内置默认值:${file}` }
|
||
return { values: {}, warning: `配置文件无法解析,使用内置默认值:${file}(${err.message})` }
|
||
}
|
||
}
|
||
|
||
function loadConfig(configPath) {
|
||
const { values, warning } = readJson(configPath)
|
||
return {
|
||
path: configPath,
|
||
values: merge(DEFAULTS, values),
|
||
warning
|
||
}
|
||
}
|
||
|
||
// 就地改配置并写回文件:只动 raw 里已有的键,不把 DEFAULTS 全量落盘,
|
||
// 否则升级新增的默认值会被老文件冻结成显式值。
|
||
function updateConfig(configPath, mutate) {
|
||
const { values } = readJson(configPath)
|
||
const raw = isPlainObject(values) ? values : {}
|
||
mutate(raw)
|
||
fs.mkdirSync(path.dirname(configPath), { recursive: true })
|
||
fs.writeFileSync(configPath, JSON.stringify(raw, null, 2) + '\n', 'utf8')
|
||
return raw
|
||
}
|
||
|
||
// 相对路径的 exe 需要按「部署包根目录」理解,而部署包根目录在不同形态下不同:
|
||
// 开发时是 console/ 的上级,打包后是 exe 所在目录。逐个候选位置探测,避免写死。
|
||
function resolveExecutable(exe, configPath) {
|
||
if (!exe) return { path: null, candidates: [] }
|
||
if (path.isAbsolute(exe)) return { path: exe, candidates: [exe] }
|
||
|
||
const configDir = path.dirname(configPath)
|
||
const candidates = [
|
||
configDir,
|
||
process.cwd(),
|
||
path.resolve(configDir, '..'),
|
||
path.resolve(configDir, '..', 'dist')
|
||
].map((dir) => path.resolve(dir, exe))
|
||
|
||
const found = candidates.find((candidate) => fs.existsSync(candidate))
|
||
return { path: found || candidates[0], candidates: [...new Set(candidates)] }
|
||
}
|
||
|
||
module.exports = { loadConfig, updateConfig, resolveExecutable }
|