feat: 人员年龄/号码布、图片上传、多显示器菜单、Console 两栏、exe 改名等一批改动

人员与报名:
- 人员唯一标识改为「证件号 或 号码布」二选一(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 文件通过。
This commit is contained in:
AskaEth committed 2026-09-10 09:05:06 +08:00
1 parent 24fff8dd08
commit 6483acf9ad
50 files changed
+2980 -395

No files matched your search

@@ -14,9 +14,12 @@ const toast = useToastStore()
interface AthleteForm {
name: string
gender: '' | Gender
// type="number" 的 v-model 会被 Vue 自动转成 number(空值仍是 ''),这里如实标注
age: string | number
teamId: string
employeeNo: string
idCard: string
bib: string
active: boolean
}
@@ -38,7 +41,21 @@ const confirmTarget = ref<Athlete | null>(null)
const confirmPending = ref(false)
function emptyForm(): AthleteForm {
return { name: '', gender: '', teamId: '', employeeNo: '', idCard: '', active: true }
return { name: '', gender: '', age: '', teamId: '', employeeNo: '', idCard: '', bib: '', active: true }
}
/**
* 年龄取值。
*
* `type="number"` 的 v-model 会被 Vue 自动转成 number(空值仍是 ''),所以不能直接 `.trim()`:
* 填了数字后字段是 number,`.trim()` 抛 TypeError,点击处理器中断,表现为「点了没反应」。
* 非法输入返回 NaN,交给 validate 标红。
*/
function toAge(value: string | number): number | null {
const text = String(value).trim()
if (text === '') return null
const parsed = Number(text)
return Number.isFinite(parsed) ? parsed : Number.NaN
}
const filtered = computed(() => {
@@ -53,6 +70,7 @@ const filtered = computed(() => {
athlete.name.toLowerCase().includes(keyword) ||
(athlete.employeeNo ?? '').toLowerCase().includes(keyword) ||
(athlete.idCard ?? '').toLowerCase().includes(keyword) ||
(athlete.bib ?? '').toLowerCase().includes(keyword) ||
(team?.name ?? '').toLowerCase().includes(keyword)
)
})
@@ -74,9 +92,11 @@ function openEdit(athlete: Athlete): void {
form.value = {
name: athlete.name,
gender: athlete.gender ?? '',
age: athlete.age === null ? '' : String(athlete.age),
teamId: String(athlete.teamId),
employeeNo: athlete.employeeNo ?? '',
idCard: athlete.idCard ?? '',
bib: athlete.bib ?? '',
active: athlete.active,
}
errors.value = {}
@@ -90,6 +110,8 @@ function validate(): boolean {
if (form.value.teamId === '' || data.teamById(Number(form.value.teamId)) === undefined) {
next.teamId = '必须选择一个参赛单位'
}
const age = toAge(form.value.age)
if (age !== null && (!Number.isInteger(age) || age < 0 || age > 120)) next.age = '年龄为 0–120 的整数'
errors.value = next
return Object.keys(next).length === 0
}
@@ -101,9 +123,11 @@ async function submit(): Promise<void> {
const input: AthleteInput = {
name: form.value.name.trim(),
gender: form.value.gender === '' ? null : form.value.gender,
age: toAge(form.value.age),
teamId: Number(form.value.teamId),
employeeNo: form.value.employeeNo.trim() === '' ? null : form.value.employeeNo.trim(),
idCard: form.value.idCard.trim() === '' ? null : form.value.idCard.trim(),
bib: form.value.bib.trim() === '' ? null : form.value.bib.trim(),
active: form.value.active,
}
try {
@@ -133,9 +157,11 @@ async function toggleActive(athlete: Athlete): Promise<void> {
{
name: athlete.name,
gender: athlete.gender,
age: athlete.age,
teamId: athlete.teamId,
employeeNo: athlete.employeeNo,
idCard: athlete.idCard,
bib: athlete.bib,
active: !athlete.active,
},
athlete.id,
@@ -162,7 +188,7 @@ async function toggleActive(athlete: Athlete): Promise<void> {
<div class="bd-toolbar-left">
<div class="mx-input-wrap bd-search">
<span class="mx-input-icon"><MxIcon name="search" :size="15" /></span>
<input v-model="search" class="mx-input" placeholder="搜索姓名 / 工号 / 证件号" />
<input v-model="search" class="mx-input" placeholder="搜索姓名 / 工号 / 证件号 / 号码布" />
</div>
<select v-model="teamFilter" class="mx-cell-input bd-select">
<option value="all">全部单位</option>
@@ -187,16 +213,18 @@ async function toggleActive(athlete: Athlete): Promise<void> {
<tr>
<th>姓名</th>
<th class="bd-cell-mini">性别</th>
<th class="bd-cell-mini">年龄</th>
<th>所属单位</th>
<th>工号 / 学号</th>
<th>证件号</th>
<th>号码布</th>
<th>状态</th>
<th class="right">操作</th>
</tr>
</thead>
<tbody>
<tr v-if="data.loading.value && data.athletes.value.length === 0">
<td colspan="7">
<td colspan="9">
<div class="mx-empty bd-empty">
<span class="mx-spinner" />
<div class="mx-empty-title">加载中…</div>
@@ -207,9 +235,11 @@ async function toggleActive(athlete: Athlete): Promise<void> {
<tr v-for="athlete in filtered" :key="athlete.id">
<td>{{ athlete.name }}</td>
<td>{{ athlete.gender ?? '—' }}</td>
<td>{{ athlete.age ?? '—' }}</td>
<td>{{ data.teamById(athlete.teamId)?.name ?? '未知单位' }}</td>
<td class="bd-mono">{{ athlete.employeeNo ?? '—' }}</td>
<td class="bd-mono">{{ athlete.idCard ?? '—' }}</td>
<td class="bd-mono">{{ athlete.bib ?? '—' }}</td>
<td>
<span class="mx-badge" :class="athlete.active ? 'mx-badge-success' : 'mx-badge-neutral'">
{{ athlete.active ? '启用' : '已停用' }}
@@ -233,7 +263,7 @@ async function toggleActive(athlete: Athlete): Promise<void> {
</td>
</tr>
<tr v-if="filtered.length === 0">
<td colspan="7">
<td colspan="9">
<div class="mx-empty bd-empty">
<div class="mx-empty-title">{{ data.athletes.value.length === 0 ? '还没有运动员' : '没有匹配的运动员' }}</div>
<div class="mx-empty-desc">也可以直接通过「报名导入」批量导入</div>
@@ -267,6 +297,9 @@ async function toggleActive(athlete: Athlete): Promise<void> {
<option value="女">女</option>
</select>
</FormField>
<FormField label="年龄" hint="可留空,填了必须是 0–120 的整数" :error="errors.age">
<input v-model="form.age" class="mx-cell-input" type="number" min="0" max="120" placeholder="例如 26" />
</FormField>
<FormField label="所属单位" required :error="errors.teamId">
<select v-model="form.teamId" class="mx-cell-input">
<option value="" disabled>请选择单位</option>
@@ -278,9 +311,12 @@ async function toggleActive(athlete: Athlete): Promise<void> {
<FormField label="工号 / 学号" hint="可留空,用于对账">
<input v-model="form.employeeNo" class="mx-cell-input" placeholder="例如 F1-001" />
</FormField>
<FormField label="证件号" hint="人员唯一标识,建议必填">
<FormField label="证件号" hint="证件号与号码布至少填一个,二者都是人员唯一标识">
<input v-model="form.idCard" class="mx-cell-input" placeholder="例如 110101199001011234" />
</FormField>
<FormField label="号码布" hint="没有身份证信息时可只填号码布">
<input v-model="form.bib" class="mx-cell-input" placeholder="例如 101" />
</FormField>
<FormField label="状态" wide>
<label class="bd-check"><input v-model="form.active" type="checkbox" /> 启用</label>
</FormField>
@@ -83,9 +83,11 @@ function isRegistered(athlete: Athlete): boolean {
return mode.value === 'individual' && registeredAthleteIds.value.has(athlete.id)
}
/** 个人项目的行必须带证件号;团体行运动员为空,不受影响。 */
function missingIdCard(athlete: Athlete): boolean {
return mode.value === 'individual' && (athlete.idCard === null || athlete.idCard === '')
/** 个人项目的行必须带证件号或号码布;团体行运动员为空,不受影响。 */
function missingIdentifier(athlete: Athlete): boolean {
const noIdCard = athlete.idCard === null || athlete.idCard === ''
const noBib = athlete.bib === null || athlete.bib === ''
return mode.value === 'individual' && noIdCard && noBib
}
async function loadEntries(id: number): Promise<void> {
@@ -138,7 +140,7 @@ async function submit(): Promise<void> {
categoryName: category.name,
teamCode: team.code,
mode: mode.value,
athletes: chosen.map((athlete) => ({ name: athlete.name, idCard: athlete.idCard })),
athletes: chosen.map((athlete) => ({ name: athlete.name, idCard: athlete.idCard, bib: athlete.bib })),
})
const file = new File([toCsv(rows)], 'selection.csv', { type: 'text/csv' })
const result = await data.importEntries(file)
@@ -227,12 +229,12 @@ async function submit(): Promise<void> {
v-model="checked"
type="checkbox"
:value="athlete.id"
:disabled="!data.canWrite.value || isRegistered(athlete) || missingIdCard(athlete)"
:disabled="!data.canWrite.value || isRegistered(athlete) || missingIdentifier(athlete)"
/>
<span class="picker-name">{{ athlete.name }}</span>
<span class="bd-note">{{ athlete.employeeNo ?? '—' }}</span>
<span class="bd-note">{{ athlete.employeeNo ?? '—' }}{{ athlete.bib ? ` · 号码布 ${athlete.bib}` : '' }}</span>
<span v-if="isRegistered(athlete)" class="mx-badge mx-badge-neutral">已报名</span>
<span v-else-if="missingIdCard(athlete)" class="mx-badge mx-badge-warning">缺证件号</span>
<span v-else-if="missingIdentifier(athlete)" class="mx-badge mx-badge-warning">缺证件号/号码布</span>
</label>
<div v-if="filteredAthletes.length === 0" class="bd-note picker-empty">
{{ teamAthletes.length === 0 ? '该单位没有启用中的运动员' : '没有匹配的运动员' }}
@@ -243,8 +245,8 @@ async function submit(): Promise<void> {
<template v-if="mode === 'individual'">个人项目:勾选的人各生成一条报名,已报名的运动员不可重复勾选。</template>
<template v-else>团体 / 对抗项目:勾选的人合成一条报名,队员名单按列表顺序写入;已报名时再次提交会更新队员名单。</template>
</p>
<p class="bd-note">号码布、种子等字段仍通过下方报名表导入填写。</p>
<p v-if="mode === 'individual'" class="bd-note">证件号缺失的运动员不能报名个人项目,请先在「运动员」分区补全证件号。</p>
<p class="bd-note">报名会自动带上该运动员的证件号(优先)或号码布;种子等字段仍通过下方报名表导入填写。</p>
<p v-if="mode === 'individual'" class="bd-note">证件号与号码布都没有的运动员不能报名个人项目,请先在「运动员」分区补齐其中一项。</p>
<div v-if="error !== null" class="mx-badge mx-badge-error picker-error">{{ error }}</div>
</template>
@@ -8,6 +8,8 @@ import { useToastStore } from '../../stores/toast'
import {
REQUIRED_COLUMNS,
conflictDiffs,
conflictLabel,
decisionKeyOf,
decisionsPayload,
pruneDecisions,
recordDecisions,
@@ -20,8 +22,9 @@ const toast = useToastStore()
const TEMPLATE_CSV = [
REQUIRED_COLUMNS.join(','),
'M100,男子组,F1,张伟,110101199001011234,男,101,,registered,',
'BB,混合组,F2,,,,,种子1,registered,第一分公司代表队',
'M100,男子组,F1,张伟,110101199001011234,男,26,101,,registered,',
'W100,女子组,F2,王芳,,女,,202,,registered,',
'BB,混合组,F2,,,,,,种子1,registered,第一分公司代表队',
].join('\n')
const MAX_SIZE = 16 * 1024 * 1024
@@ -33,7 +36,7 @@ const importing = ref(false)
const result = ref<EntryImportResult | null>(null)
const error = ref<string | null>(null)
/** 冲突决策面板的暂存状态:证件号 → 保留哪一侧,点「应用决策」才提交。 */
/** 冲突决策面板的暂存状态:决策键(证件号优先,否则号码布)→ 保留哪一侧,点「应用决策」才提交。 */
const decisions = ref<DecisionMap>({})
const selected = ref<string[]>([])
const resolving = ref(false)
@@ -88,7 +91,7 @@ function clearFile(): void {
}
function selectAll(): void {
selected.value = conflicts.value.map((conflict) => conflict.idCard)
selected.value = conflicts.value.map(decisionKeyOf)
}
function clearSelection(): void {
@@ -101,7 +104,7 @@ function decideSelected(action: ConflictAction): void {
}
function decideOne(conflict: ImportConflict, action: ConflictAction): void {
decisions.value = recordDecisions(decisions.value, conflicts.value, [conflict.idCard], action)
decisions.value = recordDecisions(decisions.value, conflicts.value, [decisionKeyOf(conflict)], action)
}
async function applyDecisions(): Promise<void> {
@@ -116,8 +119,8 @@ async function applyDecisions(): Promise<void> {
result.value = next
// 已决策的人不再出现在剩余冲突里,同步清掉暂存与勾选,避免串到下一轮。
decisions.value = pruneDecisions(decisions.value, next.conflicts)
const remaining = new Set(next.conflicts.map((conflict) => conflict.idCard))
selected.value = selected.value.filter((idCard) => remaining.has(idCard))
const remaining = new Set(next.conflicts.map(decisionKeyOf))
selected.value = selected.value.filter((key) => remaining.has(key))
toast.success('冲突决策已应用', `新增 ${next.created} · 更新 ${next.updated} · 跳过 ${next.skipped}`)
} catch (caught) {
resolveError.value = caught instanceof Error ? caught.message : '应用决策失败'
@@ -186,9 +189,10 @@ function downloadTemplate(): void {
<div class="bd-warn">
<MxIcon name="warning" :size="14" />
<span>
表头为:{{ REQUIRED_COLUMNS.join(' / ') }}(大小写不敏感)。id_card、gender 可缺省,
但有姓名的行必须填证件号,否则该行会报错并跳过。证件号是人员唯一标识:先按证件号匹配,
未命中再按「姓名 + 单位」匹配库里证件号为空的人并回填。
表头为:{{ REQUIRED_COLUMNS.join(' / ') }}(大小写不敏感)。id_card、gender、age 可缺省,
但有姓名的行必须填证件号或号码布之一,否则该行会报错并跳过。年龄可留空,填了必须是 0–120 的整数。
证件号与号码布都是人员唯一标识:
先按证件号匹配,未命中再按号码布匹配,仍未命中则按「姓名 + 单位」匹配库里证件号为空的人并回填。
</span>
</div>
@@ -258,7 +262,7 @@ function downloadTemplate(): void {
<div class="conflicts-head">
<span class="mx-badge mx-badge-warning">{{ conflicts.length }} 人信息冲突</span>
<span class="bd-note">
同一证件号在库里与报名表里的姓名 / 性别 / 单位不一致,本轮未落库,也不建报名。
同一证件号 / 号码布在库里与报名表里的姓名 / 性别 / 年龄 / 单位 / 号码布不一致,本轮未落库,也不建报名。
</span>
</div>
<p class="bd-note">逐条选择保留哪一侧;未决策的冲突会一直留在列表里,不会静默丢弃。</p>
@@ -294,23 +298,23 @@ function downloadTemplate(): void {
<div class="conflict-list">
<div
v-for="conflict in conflicts"
:key="conflict.idCard"
:key="decisionKeyOf(conflict)"
class="conflict-item"
:class="{ decided: decisions[conflict.idCard] !== undefined }"
:class="{ decided: decisions[decisionKeyOf(conflict)] !== undefined }"
>
<div class="conflict-head">
<label class="bd-check conflict-check">
<input v-model="selected" type="checkbox" :value="conflict.idCard" />
<span class="conflict-id bd-mono">{{ conflict.idCard }}</span>
<input v-model="selected" type="checkbox" :value="decisionKeyOf(conflict)" />
<span class="conflict-id bd-mono">{{ conflictLabel(conflict) }}</span>
<span class="conflict-name">{{ conflict.existing.name }}</span>
<span class="bd-note">第 {{ conflict.row }} 行</span>
</label>
<span
v-if="decisions[conflict.idCard] !== undefined"
v-if="decisions[decisionKeyOf(conflict)] !== undefined"
class="mx-badge"
:class="decisions[conflict.idCard] === 'keep-existing' ? 'mx-badge-neutral' : 'mx-badge-success'"
:class="decisions[decisionKeyOf(conflict)] === 'keep-existing' ? 'mx-badge-neutral' : 'mx-badge-success'"
>
{{ decisions[conflict.idCard] === 'keep-existing' ? '保留已有数据' : '使用新数据' }}
{{ decisions[decisionKeyOf(conflict)] === 'keep-existing' ? '保留已有数据' : '使用新数据' }}
</span>
<div class="bd-actions conflict-actions">
<button class="mx-btn mx-btn-ghost mx-btn-sm" type="button" @click="decideOne(conflict, 'keep-existing')">
@@ -3,6 +3,7 @@ import { computed, ref } from 'vue'
import type { Team, TeamInput } from '@/shared'
import MxIcon from '../MxIcon.vue'
import ConfirmDialog from '../ConfirmDialog.vue'
import ImageUploadField from '../system/ImageUploadField.vue'
import FormDialog from './FormDialog.vue'
import FormField from './FormField.vue'
import { useBaseData } from './useBaseData'
@@ -281,8 +282,8 @@ async function toggleActive(team: Team): Promise<void> {
<span v-if="form.color" class="bd-color" :style="{ background: form.color }" />
</div>
</FormField>
<FormField label="Logo 路径" hint="相对 uploads/,可留空">
<input v-model="form.logoPath" class="mx-cell-input" placeholder="logos/team1.png" />
<FormField label="Logo 路径" hint="留空则不显示单位图标;上传的图片随赛事包一起导出">
<ImageUploadField v-model="form.logoPath" :disabled="!data.canWrite.value" />
</FormField>
<FormField label="排序" :error="errors.sortOrder" hint="数字越小越靠前">
<input v-model="form.sortOrder" class="mx-cell-input" type="number" min="0" max="9999" />
@@ -21,14 +21,15 @@ export const REQUIRED_COLUMNS = [
'athlete_name',
'id_card',
'gender',
'age',
'bib',
'seed',
'status',
'member_names',
] as const
/** 可选列:表头缺失不报错,但 athlete_name 非空的行必须带 id_card。 */
export const OPTIONAL_COLUMNS = ['id_card', 'gender'] as const
/** 可选列:表头缺失不报错,但 athlete_name 非空的行必须带 id_card 或 bib 之一。 */
export const OPTIONAL_COLUMNS = ['id_card', 'gender', 'age'] as const
/** 必须存在的表头;服务端缺任一列会直接拒绝整份文件。 */
const OPTIONAL_SET: readonly string[] = OPTIONAL_COLUMNS
@@ -44,8 +45,8 @@ export interface SelectionInput {
teamCode: string
status?: string
mode: SelectionMode
/** 个人项目按 (姓名, 单位) 匹配已有运动员,带上证件号才能命中证件号优先的匹配规则。 */
athletes: { name: string; idCard?: string | null }[]
/** 个人项目按 (姓名, 单位) 匹配已有运动员,带上证件号 / 号码布才能命中对应匹配规则。 */
athletes: { name: string; idCard?: string | null; bib?: string | null }[]
/** 团体项目队员名单;缺省时按 athletes 的列表顺序取姓名。 */
memberNames?: string[]
}
@@ -69,6 +70,7 @@ export function buildSelectionRows(input: SelectionInput): string[][] {
athlete.idCard ?? '',
'',
'',
athlete.bib ?? '',
'',
status,
'',
@@ -77,7 +79,19 @@ export function buildSelectionRows(input: SelectionInput): string[][] {
return rows
}
const names = input.memberNames ?? input.athletes.map((athlete) => athlete.name)
rows.push([input.eventCode, input.categoryName, input.teamCode, '', '', '', '', '', status, names.join('/')])
rows.push([
input.eventCode,
input.categoryName,
input.teamCode,
'',
'',
'',
'',
'',
'',
status,
names.join('/'),
])
return rows
}
@@ -96,8 +110,10 @@ function escapeField(field: string): string {
const CONFLICT_FIELD_LABELS: Record<ImportConflictField, string> = {
name: '姓名',
gender: '性别',
age: '年龄',
teamCode: '单位',
employeeNo: '工号 / 学号',
bib: '号码布',
}
/** 一条冲突里某个字段的两侧取值,changed 为 true 时界面高亮。 */
@@ -120,32 +136,48 @@ export function conflictDiffs(conflict: ImportConflict): ConflictFieldDiff[] {
}))
}
function formatFieldValue(value: string | null): string {
return value === null || value === '' ? '—' : value
function formatFieldValue(value: string | number | null | undefined): string {
return value === null || value === undefined || value === '' ? '—' : String(value)
}
/** 证件号 → 决策,作为面板上的暂存状态,点「应用决策」时才提交。 */
/**
* 冲突的决策键:证件号优先,没有证件号时用号码布。
*
* 与服务端 repo_import.go 的 decisionKey() 是同一个约定,两边必须保持一致;
* 只有号码布的行证件号为空串,直接拿证件号当键会让多条冲突互相覆盖。
*/
export function decisionKeyOf(conflict: ImportConflict): string {
return conflict.idCard !== '' ? conflict.idCard : conflict.bib
}
/** 冲突行的标识:与决策键同源,键为空时给占位符,避免面板显示空白。 */
export function conflictLabel(conflict: ImportConflict): string {
const key = decisionKeyOf(conflict)
return key === '' ? '(无证件号 / 号码布)' : key
}
/** 决策键 → 决策,作为面板上的暂存状态,点「应用决策」时才提交。 */
export type DecisionMap = Record<string, ConflictAction>
/** 把选中人员批量记为某个决策;只接受仍存在的冲突,避免脏证件号混进载荷。 */
/** 把选中人员批量记为某个决策;只接受仍存在的冲突,避免脏键混进载荷。 */
export function recordDecisions(
current: DecisionMap,
conflicts: readonly ImportConflict[],
idCards: readonly string[],
keys: readonly string[],
action: ConflictAction,
): DecisionMap {
const known = new Set(conflicts.map((conflict) => conflict.idCard))
const known = new Set(conflicts.map(decisionKeyOf))
const next: DecisionMap = { ...current }
for (const idCard of idCards) {
if (known.has(idCard)) next[idCard] = action
for (const key of keys) {
if (known.has(key)) next[key] = action
}
return next
}
/** 丢弃已不存在的证件号,换文件或 resolve 之后调用。 */
/** 丢弃已不存在的决策键,换文件或 resolve 之后调用。 */
export function pruneDecisions(current: DecisionMap, conflicts: readonly ImportConflict[]): DecisionMap {
const known = new Set(conflicts.map((conflict) => conflict.idCard))
return Object.fromEntries(Object.entries(current).filter(([idCard]) => known.has(idCard)))
const known = new Set(conflicts.map(decisionKeyOf))
return Object.fromEntries(Object.entries(current).filter(([key]) => known.has(key)))
}
/** 按冲突在结果里的顺序生成 resolve 载荷,服务端回显顺序与界面一致。 */
@@ -154,8 +186,12 @@ export function decisionsPayload(
conflicts: readonly ImportConflict[],
): ImportConflictDecision[] {
return conflicts
.filter((conflict) => current[conflict.idCard] !== undefined)
.map((conflict) => ({ idCard: conflict.idCard, action: current[conflict.idCard] as ConflictAction }))
.filter((conflict) => current[decisionKeyOf(conflict)] !== undefined)
.map((conflict) => ({
idCard: conflict.idCard,
bib: conflict.bib,
action: current[decisionKeyOf(conflict)] as ConflictAction,
}))
}
export interface DecisionSummary {
@@ -171,7 +207,7 @@ export function summarizeDecisions(
): DecisionSummary {
const summary: DecisionSummary = { keepExisting: 0, keepNew: 0, undecided: 0 }
for (const conflict of conflicts) {
const action = current[conflict.idCard]
const action = current[decisionKeyOf(conflict)]
if (action === 'keep-existing') summary.keepExisting += 1
else if (action === 'keep-new') summary.keepNew += 1
else summary.undecided += 1
+101 -15
View File
@@ -237,6 +237,8 @@ export class MockBaseData {
teamId: team.id,
employeeNo: `${team.code}-${String(nameIndex + 1).padStart(3, '0')}`,
idCard: null,
bib: `${team.id}${String(nameIndex + 1).padStart(2, '0')}`,
age: 22 + nameIndex * 2,
active: true,
})
})
@@ -409,6 +411,8 @@ export class MockBaseData {
}
createAthlete(input: AthleteInput): Athlete {
this.assertAthleteIdentityFree(input, null)
this.assertAthleteAge(input)
const athlete: Athlete = { ...input, id: (this.nextAthleteId += 1) }
this.athletes = [...this.athletes, athlete]
return { ...athlete }
@@ -417,11 +421,32 @@ export class MockBaseData {
updateAthlete(id: number, input: AthleteInput): Athlete {
const index = this.athletes.findIndex((athlete) => athlete.id === id)
if (index < 0) throw new Error(`运动员 ${id} 不存在`)
this.assertAthleteIdentityFree(input, id)
this.assertAthleteAge(input)
const athlete: Athlete = { ...input, id }
this.athletes[index] = athlete
return { ...athlete }
}
/** 证件号 / 号码布都是人员唯一标识,重复时报出具体是哪个字段。 */
private assertAthleteIdentityFree(input: AthleteInput, selfId: number | null): void {
const idCard = input.idCard ?? ''
if (idCard !== '' && this.athletes.some((athlete) => athlete.id !== selfId && athlete.idCard === idCard)) {
throw new Error(`证件号 ${idCard} 已被其他人员使用`)
}
const bib = input.bib ?? ''
if (bib !== '' && this.athletes.some((athlete) => athlete.id !== selfId && athlete.bib === bib)) {
throw new Error(`号码布 ${bib} 已被其他人员使用`)
}
}
/** 年龄可空;填了就必须是 0–120 的整数,与服务端校验一致。 */
private assertAthleteAge(input: AthleteInput): void {
if (input.age !== null && (!Number.isInteger(input.age) || input.age < 0 || input.age > 120)) {
throw new Error('年龄必须是 0–120 的整数')
}
}
removeAthlete(id: number): void {
const index = this.athletes.findIndex((athlete) => athlete.id === id)
if (index < 0) throw new Error(`运动员 ${id} 不存在`)
@@ -434,9 +459,12 @@ export class MockBaseData {
return this.runImport(file, new Map())
}
/** 冲突决策重跑:decisions 为空的证件号仍视为未决策,继续留在返回的 conflicts 里。 */
/** 冲突决策重跑:没给决策的键仍视为未决策,继续留在返回的 conflicts 里。 */
async resolveImportConflicts(file: File, decisions: ImportConflictDecision[]): Promise<EntryImportResult> {
return this.runImport(file, new Map(decisions.map((decision) => [decision.idCard, decision.action])))
// 与服务端一致:证件号优先,没有证件号时用号码布当决策键。
const keyOf = (decision: ImportConflictDecision): string =>
decision.idCard !== '' ? decision.idCard : decision.bib
return this.runImport(file, new Map(decisions.map((decision) => [keyOf(decision), decision.action])))
}
private async runImport(file: File, decisions: Map<string, ConflictAction>): Promise<EntryImportResult> {
@@ -453,6 +481,7 @@ export class MockBaseData {
const result: EntryImportResult = { created: 0, updated: 0, skipped: 0, errors: [], conflicts: [] }
const seenIdCards = new Set<string>()
const seenBibs = new Set<string>()
rows.slice(1).forEach((row, offset) => {
const line = offset + 2
if (row.every((cell) => cell.trim() === '')) return
@@ -498,35 +527,58 @@ export class MockBaseData {
return
}
const idCard = cell('id_card')
if (idCard === '') {
const bib = cell('bib')
if (idCard === '' && bib === '') {
result.skipped += 1
result.errors.push(`第 ${line} 行:有姓名的行必须填证件号`)
result.errors.push(`第 ${line} 行:有姓名的行必须填证件号或号码布`)
return
}
if (seenIdCards.has(idCard)) {
// 年龄可空;填了就必须是 0–120 的整数,非法行直接跳过,不占证件号 / 号码布名额。
const age = parseAge(cell('age'))
if (age !== null && (!Number.isInteger(age) || age < 0 || age > 120)) {
result.skipped += 1
result.errors.push(`第 ${line} 行:年龄必须是 0–120 的整数`)
return
}
if (idCard !== '' && seenIdCards.has(idCard)) {
result.skipped += 1
result.errors.push(`第 ${line} 行:证件号 ${idCard} 在文件中重复出现`)
return
}
seenIdCards.add(idCard)
if (bib !== '' && seenBibs.has(bib)) {
result.skipped += 1
result.errors.push(`第 ${line} 行:号码布 ${bib} 在文件中重复出现`)
return
}
if (idCard !== '') seenIdCards.add(idCard)
if (bib !== '') seenBibs.add(bib)
const rawGender = cell('gender')
const gender = rawGender === '男' || rawGender === '女' ? rawGender : null
const matched = this.athletes.find((athlete) => athlete.idCard === idCard)
// 契约匹配顺序:证件号 → 号码布 → 姓名 + 单位(库里证件号为空)。
const matched =
(idCard === '' ? undefined : this.athletes.find((athlete) => athlete.idCard === idCard)) ??
(bib === '' ? undefined : this.athletes.find((athlete) => athlete.bib === bib))
if (matched !== undefined) {
const conflict = this.detectConflict(matched, line, idCard, athleteName, gender, team)
if (conflict !== null && decisions.get(idCard) === undefined) {
const conflict = this.detectConflict(matched, line, idCard, bib, athleteName, gender, age, team)
const key = idCard !== '' ? idCard : bib
if (conflict !== null && decisions.get(key) === undefined) {
result.conflicts.push(conflict)
return
}
if (conflict !== null && decisions.get(idCard) === 'keep-new') {
if (conflict !== null && decisions.get(key) === 'keep-new') {
matched.name = athleteName
if (gender !== null) matched.gender = gender
if (age !== null) matched.age = age
matched.teamId = team.id
if (idCard !== '') matched.idCard = idCard
if (bib !== '') matched.bib = bib
}
// 库里没有年龄时按表里的值回填,已有年龄一律不动。
if (age !== null && matched.age === null) matched.age = age
result.created += 1
return
}
// 证件号未命中,但 (姓名, 单位) 命中且库里证件号为空:视为同一人并回填。
// 证件号 / 号码布未命中,但 (姓名, 单位) 命中且库里证件号为空:视为同一人并回填。
const legacy = this.athletes.find(
(athlete) =>
athlete.name === athleteName &&
@@ -534,7 +586,18 @@ export class MockBaseData {
(athlete.idCard === null || athlete.idCard === ''),
)
if (legacy !== undefined) {
legacy.idCard = idCard
const conflict = this.detectConflict(legacy, line, idCard, bib, athleteName, gender, age, team)
const legacyKey = idCard !== '' ? idCard : bib
if (conflict !== null && decisions.get(legacyKey) === undefined) {
result.conflicts.push(conflict)
return
}
if (conflict !== null && decisions.get(legacyKey) === 'keep-new' && bib !== '') legacy.bib = bib
if (conflict !== null && decisions.get(legacyKey) === 'keep-new' && age !== null) legacy.age = age
if (idCard !== '') legacy.idCard = idCard
if (bib !== '' && (legacy.bib === null || legacy.bib === '')) legacy.bib = bib
// 其余情况只补库中为空的年龄,绝不用空值清掉已有值。
if (age !== null && legacy.age === null) legacy.age = age
result.created += 1
return
}
@@ -544,7 +607,9 @@ export class MockBaseData {
gender,
teamId: team.id,
employeeNo: null,
idCard,
idCard: idCard === '' ? null : idCard,
bib: bib === '' ? null : bib,
age,
active: true,
})
result.created += 1
@@ -552,36 +617,57 @@ export class MockBaseData {
return result
}
/** name / gender / teamCode 与库里不一致才算冲突;表里 gender 为空视为未指定。 */
/** name / gender / age / teamCode / bib 与库里不一致才算冲突;表里为空的字段视为未指定。 */
private detectConflict(
athlete: Athlete,
row: number,
idCard: string,
bib: string,
name: string,
gender: Athlete['gender'],
age: number | null,
team: Team,
): ImportConflict | null {
const changed: ImportConflictField[] = []
if (athlete.name !== name) changed.push('name')
if (gender !== null && athlete.gender !== gender) changed.push('gender')
// 年龄两侧都有值且不同才算差异;旧数据没有年龄时不能把所有人标成冲突。
if (age !== null && athlete.age !== null && athlete.age !== age) changed.push('age')
if (athlete.teamId !== team.id) changed.push('teamCode')
// 号码布两侧都给了且不一致才算差异;表里没给视为不修改。
if (bib !== '' && athlete.bib !== null && athlete.bib !== '' && athlete.bib !== bib) changed.push('bib')
if (changed.length === 0) return null
return {
row,
idCard,
bib,
athleteId: athlete.id,
existing: {
name: athlete.name,
gender: athlete.gender,
age: athlete.age,
teamCode: this.teams.find((item) => item.id === athlete.teamId)?.code ?? '',
employeeNo: athlete.employeeNo,
bib: athlete.bib,
},
incoming: { name, gender, teamCode: team.code, employeeNo: null },
incoming: { name, gender, age, teamCode: team.code, employeeNo: null, bib: bib === '' ? null : bib },
changedFields: changed,
}
}
}
/**
* 报名表里的年龄:空值返回 null(未指定),非数字返回 NaN 交给调用方报错。
*
* 与「组别」表的写法一致:不能对 number 直接 `.trim()`,先 `String()` 再解析。
*/
function parseAge(raw: string): number | null {
const text = String(raw).trim()
if (text === '') return null
const parsed = Number(text)
return Number.isFinite(parsed) ? parsed : Number.NaN
}
/** 够用的 CSV 解析:支持双引号包裹与 `""` 转义,报名表不会出现更复杂的结构。 */
function parseCsv(text: string): string[][] {
const rows: string[][] = []
@@ -2,6 +2,7 @@
import { computed, ref, watch } from 'vue'
import type { EventSettings } from '@/shared'
import MxIcon from '../MxIcon.vue'
import ImageUploadField from './ImageUploadField.vue'
import MockBadge from './MockBadge.vue'
import { describeError, settingsApi, type EventSettingsPatch } from './systemApi'
import { useAuthStore } from '../../stores/auth'
@@ -77,11 +78,15 @@ async function save(): Promise<void> {
name: next.event.name.trim(),
subtitle: optional(next.event.subtitle),
host: optional(next.event.host),
// 同理:会标清空必须传空串,传 null 服务端会当成「不改动」。
logoPath: optional(next.event.logoPath),
},
display: {
...next.display,
title: next.display.title.trim(),
subtitle: optional(next.display.subtitle),
logo: optional(next.display.logo),
background: optional(next.display.background),
rotateSeconds,
},
standings: { ...next.standings },
@@ -151,10 +156,34 @@ async function save(): Promise<void> {
<input id="event-host" v-model="form.event.host" class="mx-input" placeholder="可选" />
</div>
</div>
<div class="field wide">
<span class="mx-label">赛事会标</span>
<ImageUploadField
v-model="form.event.logoPath"
:disabled="!isAdmin"
hint="积分榜左上角的会标。上传的图片存放在服务端 uploads/ 下,会随赛事包一起导出。"
/>
</div>
</div>
<h3 class="group-title">大屏配置</h3>
<div class="form-grid">
<div class="field wide">
<span class="mx-label">大屏会标</span>
<ImageUploadField
v-model="form.display.logo"
:disabled="!isAdmin"
hint="大屏顶栏的会标;留空则回落到赛事会标。"
/>
</div>
<div class="field wide">
<span class="mx-label">大屏背景图</span>
<ImageUploadField
v-model="form.display.background"
:disabled="!isAdmin"
hint="大屏整屏背景图,建议 1920×1080;留空则不显示背景图。"
/>
</div>
<div class="field">
<label class="mx-label" for="display-title">大屏标题</label>
<div class="mx-input-wrap">
@@ -243,6 +272,10 @@ async function save(): Promise<void> {
display: flex;
flex-direction: column;
}
/* 图片字段要比纯文本框宽:缩略图与两个按钮并排。 */
.field.wide {
grid-column: 1 / -1;
}
.switch-field {
justify-content: flex-end;
}
@@ -0,0 +1,187 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import MxIcon from '../MxIcon.vue'
import { adminApi } from '../../api/client'
import { useToastStore } from '../../stores/toast'
import { describeError } from './systemApi'
import { resolveAssetUrl } from './imagePath'
/**
* 图片字段:文本框(可手填 / 粘贴路径)+ 上传按钮 + 缩略图预览。
*
* 上传走 POST /api/uploads,把服务端返回的 `/uploads/<随机名>` 写回 v-model;
* 服务端的 uploads 目录随赛事包一起导出,所以跨设备转移只需导出整包。
* 清空一律写空串而不是 null:服务端对 *string 的 nil 是「保持原值」,
* 传 null 会让旧图永远清不掉。
*/
const MAX_UPLOAD_BYTES = 5 * 1024 * 1024
const props = withDefaults(
defineProps<{
modelValue: string | null
hint?: string
disabled?: boolean
accept?: string
}>(),
{
hint: '',
disabled: false,
accept: 'image/png,image/jpeg,image/webp,image/gif',
},
)
const emit = defineEmits<{ 'update:modelValue': [value: string | null] }>()
const toast = useToastStore()
const fileInput = ref<HTMLInputElement | null>(null)
const uploading = ref(false)
const broken = ref(false)
/** 上传中的本地即时预览(Blob URL),上传成功后以服务端返回路径为准。 */
const localPreview = ref<string | null>(null)
const hasValue = computed(() => (props.modelValue ?? '').trim() !== '')
const previewUrl = computed(() => localPreview.value ?? resolveAssetUrl(props.modelValue))
watch(
() => props.modelValue,
() => {
broken.value = false
},
)
onBeforeUnmount(revokeLocalPreview)
function revokeLocalPreview(): void {
if (localPreview.value === null) return
URL.revokeObjectURL(localPreview.value)
localPreview.value = null
}
function choose(): void {
if (props.disabled || uploading.value) return
fileInput.value?.click()
}
function onInput(event: Event): void {
emit('update:modelValue', (event.target as HTMLInputElement).value)
}
function clear(): void {
revokeLocalPreview()
emit('update:modelValue', '')
}
async function onPick(event: Event): Promise<void> {
const input = event.target as HTMLInputElement
const file = input.files?.[0] ?? null
// 不清空 value 时连续选同一个文件不会再触发 change。
input.value = ''
if (file === null) return
if (file.size > MAX_UPLOAD_BYTES) {
toast.error('图片过大', `单张图片不能超过 ${MAX_UPLOAD_BYTES / 1024 / 1024} MB`)
return
}
revokeLocalPreview()
localPreview.value = URL.createObjectURL(file)
uploading.value = true
try {
const result = await adminApi.client.uploads.upload(file)
revokeLocalPreview()
emit('update:modelValue', result.path)
toast.success('图片已上传', result.path)
} catch (caught) {
revokeLocalPreview()
toast.error('图片上传失败', describeError(caught))
} finally {
uploading.value = false
}
}
</script>
<template>
<div class="img-field">
<div class="img-row">
<input
class="mx-cell-input"
type="text"
:value="modelValue ?? ''"
:disabled="disabled"
placeholder="可手填相对路径,如 uploads/logo.png"
@input="onInput"
/>
<button
class="mx-btn mx-btn-secondary"
type="button"
:disabled="disabled || uploading"
@click="choose"
>
<MxIcon name="push" :size="15" /> {{ uploading ? '上传中…' : '上传图片' }}
</button>
<button
v-if="hasValue"
class="mx-btn mx-btn-ghost"
type="button"
:disabled="disabled || uploading"
@click="clear"
>
清除
</button>
</div>
<input ref="fileInput" class="file-input" type="file" :accept="accept" @change="onPick" />
<div v-if="previewUrl !== ''" class="img-preview">
<img :src="previewUrl" alt="" @load="broken = false" @error="broken = true" />
<span v-if="broken" class="img-note error">图片无法加载,请检查路径</span>
<span v-else-if="localPreview !== null" class="img-note">上传中,预览为本地文件</span>
</div>
<span v-else class="img-note">未设置:留空则不显示</span>
<span v-if="hint !== ''" class="img-note">{{ hint }}</span>
</div>
</template>
<style scoped>
.img-field {
display: flex;
flex-direction: column;
gap: 6px;
min-width: 0;
}
.img-row {
display: flex;
align-items: center;
gap: 8px;
}
.img-row .mx-cell-input {
flex: 1;
min-width: 0;
}
.file-input {
display: none;
}
.img-preview {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
}
.img-preview img {
max-width: 180px;
max-height: 64px;
border-radius: var(--mx-r-xs);
border: 1px solid var(--mx-border);
background: var(--mx-s3);
}
.img-note {
display: block;
font-size: 12px;
color: var(--mx-t3);
line-height: 1.6;
word-break: break-all;
}
.img-note.error {
color: var(--mx-error);
}
</style>
@@ -0,0 +1,13 @@
/**
* 图片路径解析(供 <img src> 使用)。
*
* 上传接口返回的路径本就带 `/uploads/` 前缀,这里主要兼容手填的历史值:
* 绝对地址(http/https)、内联数据(data:)与已带前导斜杠的路径原样使用,
* 其余相对路径补一个 `/`,否则浏览器会相对当前路由解析(如 `/admin/logos/x.png`)。
*/
export function resolveAssetUrl(value: string | null | undefined): string {
const path = (value ?? '').trim()
if (path === '') return ''
if (path.startsWith('/') || path.startsWith('data:') || /^https?:\/\//i.test(path)) return path
return `/${path}`
}