feat: 8 条功能 + 身份口径改为号码布为准(含批量退赛/移出、基础数据导入导出、登录有效期)

用户给出的 8 条功能 + 一条口径变更,全部带真机/真浏览器验证:

① 录入页姓名后直接显示号码布(原「号码」列保留)
② 录入页批次进度条:`第 2 批 已录 5/8 · 3 条有错`,录完变绿;已录判据复用
   entryGuards.judgeEntryRow(与发布防呆同源,不会出现"进度条说录完、发布说缺 8 条")
⑦ 小项列表双击 → 跳到该小项的组别(编辑/删除按钮不误触)
③ 赛事开关 `standings.live_on_publish`(默认开=保持原行为):关闭后分批发布只上屏成绩,
   名次/流水/榜单一起等该组录完再结算 —— 代理实读代码后纠正了我的前提:
   奖牌榜读的是 results.rank(buildRanked)而非流水汇总,只延迟流水会出现
   「有金牌但 0 分」。另提供 POST /api/results/settle 人工兜底 + GET /api/results/settlement 未结算清单
④ 组别「就地更新」PUT /api/events/{id}/categories/{categoryId}:有报名数据时也能改名/改年龄/
   改性别/改权重(旧路径是整表替换,一改就被 409 拦下);改名不动报名/成绩/流水(真机逐字节比对);
   权重真的变了才触发该组重算(容差 1e-9)
④辅 运动员列表多选+全选,POST /api/athletes/batch 一次请求完成整批停用/彻底删除(逐条回报,
   dryRun 预览走同一段 SQL 但不提交、不写审计)——这才是绕开限流的正解
新增 报名项批量:POST /api/entries/batch(scratch/restore/remove)。退赛只动 registered、
   跳过 dq/dns 并说明原因;移出是物理删除,必须显式清 score_ledger(该表 entry_id 是
   ON DELETE SET NULL,不显式删会留下"人没了分还在"的孤儿流水,验证基线 orphan=0);
   退赛同时清 results.rank(否则出现"0 分还挂着金牌")
⑤ GET /api/export/entries.xlsx 报名名单导出(13 列含批次,状态中文与录入页逐字一致)
⑥ 基础数据包:GET /api/export/basedata.xlsx + POST /api/export/basedata/import
   (四张表、表头只有一份定义、表头行自动定位、列缺席≠写空、按编码 upsert、绝不删除、
   行级中文错误带真实 Excel 行号、枚举走既有校验、新增单位一定是启用)
⑧ 登录有效期面板可配:系统设置新页签,1–720 小时,默认 12h → 24h;滑动续期 +
   Cookie 同步刷新(只服务端续期是假的,浏览器侧的 Max-Age 到点仍会丢 Cookie)
身份口径:号码布为唯一标识、证件号退出匹配(号码布不同=同名的两个人,新建并单独报告);
   同一份表重复证件号不再报错;两个不同的人共用证件号仍报行级错误(唯一索引保留)

其它对齐:分项成绩表草稿行不再消失(成绩列「分数未录入」、名次/积分 `—`,没成绩的行同占位);
大屏实时赛况单栏铺满(留白 370→78px)、字号上限 56→96px、≥7 行自动拆左右两块;
删除报名项/退赛/权重等改动都会重算并推榜单。

测试:服务端 13 包(连跑两遍)、前端 335 例、vue-tsc + build、Console 18 文件 —— 全绿。
文档:README、docs/ 四份(含 debug/使用说明 副本)、devdocs 05/08/04/13。
版本号 dev_0.1.5 → dev_0.1.6。
This commit is contained in:
AskaEth committed 2026-09-11 17:14:02 +08:00
1 parent 8dd599bd97
commit 631c8dd8e1
80 files changed
+12468 -519

No files matched your search

@@ -0,0 +1,202 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { ApiError } from '@/shared'
import {
downloadBaseDataXLSX,
downloadEntriesXLSX,
entriesExportPath,
importBaseDataXLSX,
} from '@/shared/basedata'
/**
* 报名名单导出与基础数据包导入的前端契约:路径、筛选参数、dryRun 标志、解析出的差异。
*
* 路径或参数写错时现场拿到的是 404 或「筛了却导出全量」;dryRun 标志丢了则会
* 让「预览差异」直接写库。这里用 stub fetch 钉住真正发出去的请求。
*/
interface Captured {
url?: string
method?: string
body?: unknown
}
function jsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: { 'Content-Type': 'application/json' },
})
}
function xlsxResponse(): Response {
return new Response(new Blob([new Uint8Array([0x50, 0x4b, 0x03, 0x04])]), {
status: 200,
headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' },
})
}
let reply: () => Response = () => xlsxResponse()
let lastRequest: Captured = {}
globalThis.fetch = (async (input: unknown, init?: RequestInit) => {
lastRequest = { url: String(input), method: init?.method ?? 'GET', body: init?.body }
return reply()
}) as typeof fetch
function respondWith(next: () => Response): void {
lastRequest = {}
reply = next
}
function formValue(body: unknown, key: string): FormDataEntryValue | null {
assert.ok(body instanceof FormData, '上传必须是 multipart FormData')
return body.get(key)
}
test('报名名单导出路径按筛选条件拼 query,留空的维度不出现', () => {
assert.equal(entriesExportPath(), '/export/entries.xlsx')
assert.equal(entriesExportPath({ eventId: 3 }), '/export/entries.xlsx?eventId=3')
assert.equal(
entriesExportPath({ eventId: 3, categoryId: 9, teamId: 1, heat: 2 }),
'/export/entries.xlsx?eventId=3&categoryId=9&teamId=1&heat=2',
)
})
test('导出报名名单走 GET /api/export/entries.xlsx,文件名是「报名名单.xlsx」', async () => {
respondWith(() => xlsxResponse())
const result = await downloadEntriesXLSX({ eventId: 3, heat: 2 })
assert.equal(lastRequest.url, '/api/export/entries.xlsx?eventId=3&heat=2')
assert.equal(lastRequest.method, 'GET')
assert.equal(result.filename, '报名名单.xlsx')
assert.equal(result.blob.size, 4)
})
test('导出基础数据包走 GET /api/export/basedata.xlsx,文件名是「基础数据包.xlsx」', async () => {
respondWith(() => xlsxResponse())
const result = await downloadBaseDataXLSX()
assert.equal(lastRequest.url, '/api/export/basedata.xlsx')
assert.equal(result.filename, '基础数据包.xlsx')
})
test('预览差异带 dryRun=1,结果里的三类计数与逐行差异都解析出来', async () => {
respondWith(() => jsonResponse({
ok: true,
data: {
dryRun: true,
added: 1,
updated: 2,
unchanged: 5,
errorCount: 1,
errors: ['单位 第 3 行:单位编码必填'],
changes: [
{
sheet: '单位',
line: 2,
action: 'updated',
key: 'T1',
fields: [{ field: '单位名称', from: '第一分公司', to: '第一分公司(改)' }],
},
],
},
}))
const file = new File(['x'], 'basedata.xlsx')
const result = await importBaseDataXLSX(file, { dryRun: true })
assert.equal(lastRequest.url, '/api/export/basedata/import')
assert.equal(lastRequest.method, 'POST')
assert.equal(formValue(lastRequest.body, 'dryRun'), '1')
assert.equal(formValue(lastRequest.body, 'file'), file)
assert.equal(result.dryRun, true)
assert.equal(result.added, 1)
assert.equal(result.updated, 2)
assert.equal(result.unchanged, 5)
assert.equal(result.errorCount, 1)
assert.deepEqual(result.errors, ['单位 第 3 行:单位编码必填'])
assert.equal(result.changes.length, 1)
assert.equal(result.changes[0].sheet, '单位')
assert.equal(result.changes[0].line, 2)
assert.equal(result.changes[0].fields[0].field, '单位名称')
assert.equal(result.changes[0].fields[0].from, '第一分公司')
assert.equal(result.changes[0].fields[0].to, '第一分公司(改)')
})
test('确认写入不带 dryRun,避免预览之后又走一次只读分支', async () => {
respondWith(() => jsonResponse({
ok: true,
data: { dryRun: false, added: 3, updated: 0, unchanged: 0, errorCount: 0, errors: [], changes: [] },
}))
const result = await importBaseDataXLSX(new File(['x'], 'basedata.xlsx'), { dryRun: false })
assert.equal(formValue(lastRequest.body, 'dryRun'), null)
assert.equal(result.dryRun, false)
assert.equal(result.added, 3)
})
test('服务端 400 的行级错误原样抛出,页面能拿到那句中文', async () => {
respondWith(() => jsonResponse({
ok: false,
error: { code: 'VALIDATION_FAILED', message: '导出链接参数不对' },
}, 400))
await assert.rejects(
() => downloadEntriesXLSX({ heat: 0 }),
(error: unknown) => {
assert.ok(error instanceof ApiError)
assert.equal(error.status, 400)
assert.equal(error.code, 'VALIDATION_FAILED')
assert.equal(error.message, '导出链接参数不对')
return true
},
)
})
test('导入 403 / 500 原样抛出,不降级成示例数据', async () => {
respondWith(() => jsonResponse({
ok: false,
error: { code: 'FORBIDDEN', message: '只有管理员可以导入基础数据' },
}, 403))
await assert.rejects(
() => importBaseDataXLSX(new File(['x'], 'basedata.xlsx')),
(error: unknown) => {
assert.ok(error instanceof ApiError)
assert.equal(error.code, 'FORBIDDEN')
assert.equal(error.message, '只有管理员可以导入基础数据')
return true
},
)
})
test('响应不是 {ok,data} 结构时报解析错误,而不是假装导入成功', async () => {
respondWith(() => jsonResponse({ hello: 'world' }))
await assert.rejects(
() => importBaseDataXLSX(new File(['x'], 'basedata.xlsx')),
(error: unknown) => {
assert.ok(error instanceof ApiError)
assert.equal(error.code, 'INTERNAL')
return true
},
)
})
test('连不上服务端时报 NETWORK,页面据此区分「后端未就绪」', async () => {
respondWith(() => {
throw new TypeError('fetch failed')
})
await assert.rejects(
() => downloadEntriesXLSX(),
(error: unknown) => {
assert.ok(error instanceof ApiError)
assert.equal(error.code, 'NETWORK')
return true
},
)
})