fix: 修掉十路审查发现的 9 个 P0 与一批 P1(数据正确性 / 越权 / 现场可用性)
P0(9 条全修): - 多通道项目奖牌重复计数:domain 层按 (EventID,CategoryID,EntryID/Subject) 去重, 通道优先级 athlete→team→id - 「只排名不计分」项目(scored:false)不再进奖牌榜,REST/WS/导出口径统一 - aggregate 流水 entry_id 恒 NULL 导致重算后分数翻倍:作废范围改按 event+category 定位 - 已发布成绩仍可被「存草稿」覆盖并清空 rank:服务端 409 STATE_INVALID + 前端禁编辑 - voidResult / 规则导入重算后名次不回写:接住 Ranked 调 applyComputedRanks - 赛事包覆盖导入可能「旧项目已删、新项目没成」:先改名成功再清理,失败回滚 - 导入赛事包可覆盖正在运行的赛事目录:name==当前项目直接 400 - Console spawn 失败后守护器永久卡死:清 child/pid + 调度重启 + stop 超时兜底 - /ws 快照向非 admin 下发 admin-only 配置:按角色裁剪 settings P1(计分口径 / 契约 / 现场): - standings.tieBreak 三处接线;profiles[].recordBonusMode 生效;破纪录校验 RecordEligible 与 entry 归属;破纪录登记校验已发布成绩 - export.loadRanked 与主路径对齐;ListBackups reason 解析;CLI backup 前缀修正 (原来只增不减会撑爆磁盘);单位积分明细/导出统一权重折算;停用单位展示 - 规则导入原子化(重算并入同一事务)+ 返回 compatible/affectedEventCount/ recalculatedLedgerRows;登录审计 user_id 修正 - WS 策略性断开用 Close(code,reason);HelloMessage 补 page/instanceId; 实例注册表清理;settings/单位/项目写操作补 change_log 触发大屏刷新 - 大屏:全量快照不再被版本守卫丢弃;个人积分榜刷新;公告返回页/轮播;行数截断; REST 竞态;1008 停止重连;握手超时;时区补 Z;401 仅 AUTH_REQUIRED 才登出 - 管理端:published 行禁编辑;saveDraft 补 unit(1:06.33 显示);前端预览改用服务端 points;空成绩行不再恒「已修改」;修订详情按 id 拉取;切项目请求序号与 dirty 保护; 发布后刷新项目状态;NAV/路由按角色过滤;recorder 不再打 admin-only 接口 - Console:大屏窗口销毁后重建;大屏 URL 复用 host 归一化;backup.bat 改纯 ASCII (已在 Meowhome 实跑验证) 自检:服务端 gofmt/build/vet 通过、12 包测试全绿;前端 vue-tsc + build 通过、 node --test 24/24;console check-syntax 12 文件通过。
This commit is contained in:
1 parent
96cf181ae3
commit
13f1f03cd0
124 files changed
+5658
-1820
No files matched your search
@@ -8,8 +8,9 @@ const data = useEventStore()
|
||||
|
||||
const SYSTEM_NAME = '运动会积分榜系统'
|
||||
const SYSTEM_EN = 'Scoreboard'
|
||||
// /api/health 只回 version,没有构建时间字段;构建期常量要改 vite.config,本页按约定显示 dev
|
||||
const BUILD_TIME = 'dev'
|
||||
// /api/health 只回 version,/api/system/about 也不带构建时间;前端构建期未注入该常量,
|
||||
// 因此这里如实显示「未注入」,不再用假的 'dev' 冒充构建时间。
|
||||
const BUILD_TIME = '未注入'
|
||||
|
||||
const version = ref<string | null>(null)
|
||||
const versionChecked = ref(false)
|
||||
|
||||
@@ -56,6 +56,7 @@ const localItems = ref<PointAdjustment[]>([])
|
||||
let nextLocalId = -1
|
||||
|
||||
const canWrite = computed(() => !auth.readOnly && data.canWrite)
|
||||
const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
/**
|
||||
* 人工调整开关:true / false / null(未知)。
|
||||
*
|
||||
@@ -77,12 +78,15 @@ const filteredItems = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
// 分页只作用于服务端记录;本地降级条目固定显示在当前页,不能混进 total 的页码计算。
|
||||
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / size)))
|
||||
const rangeText = computed(() => {
|
||||
if (total.value === 0) return '共 0 条'
|
||||
const local = localItems.value.length
|
||||
const suffix = local > 0 ? `,另有 ${local} 条本地示例记录` : ''
|
||||
if (total.value === 0) return local > 0 ? `共 ${local} 条本地示例记录` : '共 0 条'
|
||||
const from = (page.value - 1) * size + 1
|
||||
const to = Math.min(page.value * size, total.value)
|
||||
return `第 ${from}–${to} 条,共 ${total.value} 条`
|
||||
return `第 ${from}–${to} 条,共 ${total.value} 条${suffix}`
|
||||
})
|
||||
|
||||
function teamLabel(teamId: number): string {
|
||||
@@ -109,20 +113,33 @@ function isLocal(item: PointAdjustment): boolean {
|
||||
return item.id < 0
|
||||
}
|
||||
|
||||
/** 只有真的连不上服务端才做本地降级;业务 404 / 解析失败必须原样呈现。 */
|
||||
function isFallback(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof ApiError &&
|
||||
(['NETWORK', 'TIMEOUT', 'PARSE_FAILED'].includes(error.code) || error.status === 404)
|
||||
)
|
||||
return error instanceof ApiError && ['NETWORK', 'TIMEOUT'].includes(error.code)
|
||||
}
|
||||
|
||||
function isForbidden(error: unknown): boolean {
|
||||
return error instanceof ApiError && (error.status === 403 || error.code === 'FORBIDDEN')
|
||||
}
|
||||
|
||||
async function loadRules(): Promise<void> {
|
||||
try {
|
||||
rulePack.value = await adminApi.client.rules.get()
|
||||
ruleError.value = null
|
||||
// /api/rules/export 是 admin-only:录入员跳过它,改用下面的只读开关端点,
|
||||
// 否则页面会常驻一条红色「读取规则包失败:无权访问该资源」。
|
||||
if (isAdmin.value) {
|
||||
rulePack.value = await adminApi.client.rules.get()
|
||||
ruleError.value = null
|
||||
} else {
|
||||
rulePack.value = null
|
||||
ruleError.value = null
|
||||
}
|
||||
} catch (caught) {
|
||||
rulePack.value = null
|
||||
ruleError.value = caught instanceof Error ? caught.message : '无法读取规则包'
|
||||
ruleError.value = isForbidden(caught)
|
||||
? null
|
||||
: caught instanceof Error
|
||||
? caught.message
|
||||
: '无法读取规则包'
|
||||
}
|
||||
// 规则包只有 admin 能读;录入员改用只读开关端点,避免把已启用功能误报成关闭。
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import {
|
||||
formatPoints,
|
||||
@@ -25,6 +25,7 @@ interface EditableRow {
|
||||
categoryId: number
|
||||
bib: string | null
|
||||
teamId: number
|
||||
athleteId: number | null
|
||||
teamName: string
|
||||
teamShort: string
|
||||
athleteName: string
|
||||
@@ -78,6 +79,8 @@ const unpublishDialog = ref(false)
|
||||
const focusedEntryId = ref<number | null>(null)
|
||||
const tableRef = ref<HTMLElement | null>(null)
|
||||
const recordForEvent = ref<{ resultText: string; resultValue: number } | null>(null)
|
||||
/** 项目切换的请求序号:只有最新一次请求的响应才允许写入页面状态。 */
|
||||
let requestSeq = 0
|
||||
|
||||
const canWrite = computed(() => !auth.readOnly && data.canWrite)
|
||||
|
||||
@@ -93,7 +96,6 @@ const selectedEvent = computed(() => detail.value ?? (selectedEventId.value ===
|
||||
const categories = computed(() => detail.value?.categories ?? [])
|
||||
const channels = computed(() => detail.value?.channels ?? [])
|
||||
const weight = computed(() => data.settings?.standings.individualToTeamWeight ?? 1)
|
||||
const isIndividual = computed(() => selectedEvent.value?.eventType === 'individual')
|
||||
const manualRank = computed(() => selectedEvent.value?.resultMode === 'manual' || selectedEvent.value?.compare === 'none')
|
||||
|
||||
function unitOf(type: Event['resultType']): string {
|
||||
@@ -114,6 +116,7 @@ const scorable = computed<ScorableRow[]>(() =>
|
||||
visibleRows.value.map((row) => ({
|
||||
entryId: row.entryId,
|
||||
teamId: row.teamId,
|
||||
athleteId: row.athleteId,
|
||||
resultValue: parseResultValue(row.resultText, unit.value),
|
||||
rank: row.rank,
|
||||
status: row.status,
|
||||
@@ -136,16 +139,15 @@ const score = computed(() => {
|
||||
/**
|
||||
* 已发布行产生的分已经计入当前总分,预览时必须先扣掉,差值才是「本次发布」的影响。
|
||||
*
|
||||
* 不能用 result.points:服务端从不返回该字段(恒为 0),否则已发布分会被重复计算。
|
||||
* 这里改用与预览同一套算法算出的 rowPoints,口径与服务端计分一致。
|
||||
* 用 rowTeamPoints(各通道原始分,个人通道已按权重折算)而不是服务端 result.points:
|
||||
* 后者只覆盖已发布行,且编辑中的行服务端还没算分,两边口径无法混用。
|
||||
*/
|
||||
const publishedContribution = computed(() => {
|
||||
const map = new Map<number, number>()
|
||||
const rowPoints = score.value?.rowPoints
|
||||
const rowTeamPoints = score.value?.rowTeamPoints
|
||||
for (const row of visibleRows.value) {
|
||||
if (row.resultState !== 'published') continue
|
||||
const points = rowPoints?.get(row.entryId) ?? 0
|
||||
map.set(row.teamId, (map.get(row.teamId) ?? 0) + (isIndividual.value ? points * weight.value : points))
|
||||
map.set(row.teamId, (map.get(row.teamId) ?? 0) + (rowTeamPoints?.get(row.entryId) ?? 0))
|
||||
}
|
||||
return map
|
||||
})
|
||||
@@ -165,7 +167,13 @@ const preview = computed<PreviewRow[]>(() => {
|
||||
const maxDelta = computed(() => preview.value.reduce((max, row) => Math.max(max, Math.abs(row.delta)), 0))
|
||||
const affectedTeams = computed(() => preview.value.filter((row) => row.delta !== 0).length)
|
||||
const isPublished = computed(() => visibleRows.value.some((row) => row.resultState === 'published'))
|
||||
const dirty = computed(() => visibleRows.value.some((row) => rowDirty(row)))
|
||||
/** dirty 必须扫描全部组别,否则切到另一组别后「有未保存修改」徽标会凭空消失。 */
|
||||
const dirty = computed(() => allRows.value.some((row) => rowDirty(row)))
|
||||
|
||||
/** 已发布的行由服务端锁定:只能先撤销发布,不能就地改草稿。 */
|
||||
function rowLocked(row: EditableRow): boolean {
|
||||
return row.resultState === 'published'
|
||||
}
|
||||
|
||||
const issues = computed<Issue[]>(() => {
|
||||
const list: Issue[] = []
|
||||
@@ -233,9 +241,10 @@ function round(value: number): number {
|
||||
return Number(value.toFixed(2))
|
||||
}
|
||||
|
||||
/** 空缺成绩的快照必须与 rowDirty 拼出的默认行一致,否则一进页面就亮「已修改」。 */
|
||||
function snapshotOf(entry: EntryWithResult): string {
|
||||
const result = entry.result
|
||||
if (result === null) return '||||'
|
||||
if (result === null) return ['', '', 'ok', '0', ''].join('|')
|
||||
return [result.resultText, result.rank ?? '', result.status, result.isTie ? '1' : '0', result.note ?? ''].join('|')
|
||||
}
|
||||
|
||||
@@ -246,6 +255,7 @@ function toRow(entry: EntryWithResult): EditableRow {
|
||||
categoryId: entry.categoryId,
|
||||
bib: entry.bib,
|
||||
teamId: entry.teamId,
|
||||
athleteId: entry.athleteId,
|
||||
teamName: entry.teamName ?? data.teamById(entry.teamId)?.name ?? '未知单位',
|
||||
teamShort: entry.shortName ?? data.teamById(entry.teamId)?.shortName ?? '',
|
||||
athleteName: entry.athleteName ?? '',
|
||||
@@ -266,6 +276,14 @@ function rowDirty(row: EditableRow): boolean {
|
||||
return row.original !== [row.resultText, row.rank ?? '', row.status, row.isTie ? '1' : '0', row.note].join('|')
|
||||
}
|
||||
|
||||
/** 名次输入框清空时 v-model.number 会给出空串,必须在入口就归一为 null。 */
|
||||
function rankInputValue(event: InputEvent): number | null {
|
||||
const raw = (event.target as HTMLInputElement).value.trim()
|
||||
if (raw === '') return null
|
||||
const value = Number(raw)
|
||||
return Number.isFinite(value) ? Math.trunc(value) : null
|
||||
}
|
||||
|
||||
function rankOf(row: EditableRow): number | null {
|
||||
if (manualRank.value) return row.rank
|
||||
return score.value?.ranks.get(row.entryId) ?? null
|
||||
@@ -279,9 +297,17 @@ function issueFor(entryId: number): Issue | undefined {
|
||||
return issues.value.find((issue) => issue.entryId === entryId)
|
||||
}
|
||||
|
||||
/** 切换项目会丢弃当前编辑,先让操作员确认。 */
|
||||
function confirmDiscard(): boolean {
|
||||
if (!dirty.value) return true
|
||||
return window.confirm('当前有未保存的成绩修改,切换项目会丢弃这些修改。确定继续吗?')
|
||||
}
|
||||
|
||||
async function selectEvent(id: number): Promise<void> {
|
||||
if (selectedEventId.value === id && detail.value !== null) return
|
||||
if (!confirmDiscard()) return
|
||||
selectedEventId.value = id
|
||||
const seq = (requestSeq += 1)
|
||||
loading.value = true
|
||||
try {
|
||||
const [event, entries, records] = await Promise.all([
|
||||
@@ -289,28 +315,35 @@ async function selectEvent(id: number): Promise<void> {
|
||||
adminApi.entries(id),
|
||||
adminApi.records(),
|
||||
])
|
||||
// 切换过快时旧响应可能后到,只有最新一次请求的结果才允许覆盖页面。
|
||||
if (seq !== requestSeq) return
|
||||
detail.value = event
|
||||
selectedCategoryId.value = event.categories?.[0]?.id ?? null
|
||||
allRows.value = entries.map(toRow)
|
||||
const record = records.find((item) => item.eventId === id && item.isCurrent) ?? null
|
||||
recordForEvent.value = record === null ? null : { resultText: record.resultText, resultValue: record.resultValue }
|
||||
} catch (caught) {
|
||||
if (seq !== requestSeq) return
|
||||
toast.error(caught instanceof Error ? caught.message : '加载项目失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (seq === requestSeq) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function reload(): Promise<void> {
|
||||
if (selectedEventId.value === null) return
|
||||
const id = selectedEventId.value
|
||||
const seq = requestSeq
|
||||
loading.value = true
|
||||
try {
|
||||
allRows.value = (await adminApi.entries(id)).map(toRow)
|
||||
const entries = await adminApi.entries(id)
|
||||
if (seq !== requestSeq) return
|
||||
allRows.value = entries.map(toRow)
|
||||
} catch (caught) {
|
||||
if (seq !== requestSeq) return
|
||||
toast.error(caught instanceof Error ? caught.message : '重新加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (seq === requestSeq) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,6 +353,8 @@ function buildDraftPayload(): DraftResultInput[] {
|
||||
rank: manualRank.value ? row.rank : null,
|
||||
resultText: row.resultText.trim(),
|
||||
resultValue: parseResultValue(row.resultText, unit.value),
|
||||
// 不传 unit 时服务端会把已有单位覆盖成 NULL,大屏 100 米就会显示成 66.33。
|
||||
unit: unit.value,
|
||||
status: row.status,
|
||||
isTie: row.isTie,
|
||||
note: row.note.trim() === '' ? null : row.note.trim(),
|
||||
@@ -328,6 +363,12 @@ function buildDraftPayload(): DraftResultInput[] {
|
||||
|
||||
async function saveDraft(silent = false): Promise<boolean> {
|
||||
if (selectedEventId.value === null) return false
|
||||
if (saving.value) return false
|
||||
if (isPublished.value) {
|
||||
// 已发布行由服务端锁定:就地存草稿会清掉名次却不重算积分,必须先撤销发布。
|
||||
toast.error('该组已发布', '修改前请先撤销发布')
|
||||
return false
|
||||
}
|
||||
if (!canWrite.value) {
|
||||
toast.error('当前不可写入', auth.readOnly ? '请先登录' : '服务端未连接')
|
||||
return false
|
||||
@@ -361,6 +402,10 @@ function requestPublish(): void {
|
||||
toast.error('当前不可发布', auth.readOnly ? '请先登录' : '服务端未连接')
|
||||
return
|
||||
}
|
||||
if (isPublished.value) {
|
||||
toast.error('该组已发布', '如需修改请先撤销发布')
|
||||
return
|
||||
}
|
||||
if (errors.value.length > 0) {
|
||||
toast.error(`有 ${errors.value.length} 处校验未通过`, errors.value[0]?.message ?? null)
|
||||
return
|
||||
@@ -384,7 +429,7 @@ async function confirmPublish(): Promise<void> {
|
||||
})
|
||||
publishDialog.value = false
|
||||
await reload()
|
||||
await data.refreshStandings()
|
||||
await Promise.all([data.refreshStandings(), data.refreshEvents()])
|
||||
toast.success('发布成功,积分榜已更新')
|
||||
} catch (caught) {
|
||||
toast.error('发布失败', caught instanceof Error ? caught.message : null)
|
||||
@@ -403,7 +448,7 @@ async function confirmUnpublish(): Promise<void> {
|
||||
})
|
||||
unpublishDialog.value = false
|
||||
await reload()
|
||||
await data.refreshStandings()
|
||||
await Promise.all([data.refreshStandings(), data.refreshEvents()])
|
||||
toast.warning('已撤销发布,大屏将回退该组成绩')
|
||||
} catch (caught) {
|
||||
toast.error('撤销发布失败', caught instanceof Error ? caught.message : null)
|
||||
@@ -442,10 +487,18 @@ function onPageKeydown(event: KeyboardEvent): void {
|
||||
if (!event.ctrlKey && !event.altKey) return
|
||||
if (event.key !== 'Enter') return
|
||||
event.preventDefault()
|
||||
if (saving.value || publishing.value || unpublishing.value) return
|
||||
if (event.altKey) requestPublish()
|
||||
else void saveDraft()
|
||||
}
|
||||
|
||||
/** 关闭/刷新页面前拦住未保存的编辑,避免一整组成绩静默丢失。 */
|
||||
function onBeforeUnload(event: BeforeUnloadEvent): void {
|
||||
if (!dirty.value) return
|
||||
event.preventDefault()
|
||||
event.returnValue = ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel 粘贴:两列及以上时,第一列按单位名匹配行,最后一列作为成绩;
|
||||
* 单列时从当前行往下顺序填充(07 第 2 节第 4 条)。
|
||||
@@ -502,9 +555,14 @@ async function pickInitialEvent(): Promise<void> {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('beforeunload', onBeforeUnload)
|
||||
void pickInitialEvent()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('beforeunload', onBeforeUnload)
|
||||
})
|
||||
|
||||
// 项目列表由布局层异步加载,加载完成后补一次默认选中。
|
||||
watch(
|
||||
() => data.loaded,
|
||||
@@ -519,13 +577,19 @@ watch(
|
||||
<PageHeader title="成绩录入" :subtitle="selectedEvent?.name ?? '选择左侧项目开始录入'">
|
||||
<template #actions>
|
||||
<span v-if="dirty" class="mx-badge mx-badge-warning">有未保存修改</span>
|
||||
<button class="mx-btn mx-btn-secondary" type="button" :disabled="!canWrite || saving" @click="saveDraft()">
|
||||
<button
|
||||
class="mx-btn mx-btn-secondary"
|
||||
type="button"
|
||||
:disabled="!canWrite || saving || isPublished"
|
||||
:title="isPublished ? '该组已发布,请先撤销发布' : ''"
|
||||
@click="saveDraft()"
|
||||
>
|
||||
<MxIcon name="check" :size="15" /> 存草稿
|
||||
</button>
|
||||
<button
|
||||
class="mx-btn mx-btn-primary"
|
||||
type="button"
|
||||
:disabled="!canWrite || publishing || data.isMock"
|
||||
:disabled="!canWrite || publishing || data.isMock || isPublished"
|
||||
@click="requestPublish"
|
||||
>
|
||||
<MxIcon name="push" :size="15" /> 发布
|
||||
@@ -612,7 +676,7 @@ watch(
|
||||
|
||||
<div v-if="isPublished" class="published-note">
|
||||
<MxIcon name="lock" :size="15" />
|
||||
该组已发布,修改前需先「撤销发布」;草稿态不会上屏。
|
||||
该组已发布,成绩与名次已锁定上屏:如需修改,请先「撤销发布」。草稿态不会上屏。
|
||||
</div>
|
||||
|
||||
<div class="entry-body">
|
||||
@@ -648,7 +712,8 @@ watch(
|
||||
data-cell
|
||||
class="mx-cell-input mono"
|
||||
:class="{ 'is-invalid': issueFor(row.entryId)?.level === 'error' }"
|
||||
:disabled="!canWrite"
|
||||
:disabled="!canWrite || rowLocked(row)"
|
||||
:title="rowLocked(row) ? '已发布,请先撤销发布' : ''"
|
||||
:placeholder="unit === 's' ? '1:06.33' : unit"
|
||||
@focus="focusedEntryId = row.entryId"
|
||||
@blur="focusedEntryId = null"
|
||||
@@ -659,12 +724,14 @@ watch(
|
||||
<td class="center">
|
||||
<input
|
||||
v-if="manualRank"
|
||||
v-model.number="row.rank"
|
||||
:value="row.rank ?? ''"
|
||||
data-cell
|
||||
type="number"
|
||||
min="1"
|
||||
class="mx-cell-input rank-input"
|
||||
:disabled="!canWrite"
|
||||
:disabled="!canWrite || rowLocked(row)"
|
||||
:title="rowLocked(row) ? '已发布,请先撤销发布' : ''"
|
||||
@input="row.rank = rankInputValue($event)"
|
||||
@focus="focusedEntryId = row.entryId"
|
||||
@blur="focusedEntryId = null"
|
||||
@keydown="onCellKeydown($event, $event.currentTarget as HTMLElement)"
|
||||
@@ -676,7 +743,8 @@ watch(
|
||||
v-model="row.status"
|
||||
data-cell
|
||||
class="mx-cell-input status-select"
|
||||
:disabled="!canWrite"
|
||||
:disabled="!canWrite || rowLocked(row)"
|
||||
:title="rowLocked(row) ? '已发布,请先撤销发布' : ''"
|
||||
@focus="focusedEntryId = row.entryId"
|
||||
@blur="focusedEntryId = null"
|
||||
@keydown="onCellKeydown($event, $event.currentTarget as HTMLElement)"
|
||||
@@ -696,7 +764,8 @@ watch(
|
||||
v-model="row.note"
|
||||
data-cell
|
||||
class="mx-cell-input"
|
||||
:disabled="!canWrite"
|
||||
:disabled="!canWrite || rowLocked(row)"
|
||||
:title="rowLocked(row) ? '已发布,请先撤销发布' : ''"
|
||||
placeholder="—"
|
||||
@focus="focusedEntryId = row.entryId"
|
||||
@blur="focusedEntryId = null"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import {
|
||||
ApiError,
|
||||
formatDateTime,
|
||||
type EntryWithResult,
|
||||
type Event,
|
||||
@@ -13,7 +14,7 @@ import PageHeader from '../components/PageHeader.vue'
|
||||
import RevisionGraph from '../components/history/RevisionGraph.vue'
|
||||
import RevisionDetail from '../components/history/RevisionDetail.vue'
|
||||
import { buildGraph, describeRow, diffSnapshots, laneColor } from '../components/history/graph'
|
||||
import { fetchRevisions } from '../components/history/revisionsSource'
|
||||
import { fetchRevisionDetail, fetchRevisions } from '../components/history/revisionsSource'
|
||||
import { createMockRevisions } from '../components/history/mockRevisions'
|
||||
import { ACTION_LABELS, type Revision, type RevisionDiffRow, type TeamImpact } from '../components/history/types'
|
||||
import { adminApi } from '../api/client'
|
||||
@@ -36,16 +37,21 @@ const revisions = ref<Revision[]>([])
|
||||
const loading = ref(false)
|
||||
const usingMock = ref(false)
|
||||
const mockReason = ref<string | null>(null)
|
||||
const loadError = ref<string | null>(null)
|
||||
const eventFilter = ref<number | 'all'>('all')
|
||||
const timeFilter = ref<TimeFilter>('all')
|
||||
const selectedId = ref<number | null>(null)
|
||||
const contexts = ref<Record<number, EventContext>>({})
|
||||
/** 已成功拉到快照的修订 id,避免 watch 反复请求。 */
|
||||
const detailLoadedIds = ref<number[]>([])
|
||||
const detailLoading = ref(false)
|
||||
const detailError = ref<string | null>(null)
|
||||
|
||||
const weight = computed(() => data.settings?.standings.individualToTeamWeight ?? 1)
|
||||
|
||||
const visibleRevisions = computed(() => {
|
||||
const threshold = timeThreshold(timeFilter.value)
|
||||
const list = threshold === null ? revisions.value : revisions.value.filter((item) => item.createdAt >= threshold)
|
||||
const list = threshold === null ? revisions.value : revisions.value.filter((item) => toTime(item.createdAt) >= threshold)
|
||||
return [...list].sort((a, b) => (a.createdAt === b.createdAt ? b.id - a.id : a.createdAt < b.createdAt ? 1 : -1))
|
||||
})
|
||||
|
||||
@@ -129,10 +135,21 @@ function round(value: number): number {
|
||||
return Number(value.toFixed(2))
|
||||
}
|
||||
|
||||
function timeThreshold(filter: TimeFilter): string | null {
|
||||
function timeThreshold(filter: TimeFilter): number | null {
|
||||
if (filter === 'all') return null
|
||||
const hours = filter === '24h' ? 24 : 24 * 7
|
||||
return new Date(Date.now() - hours * 3_600_000).toISOString()
|
||||
return Date.now() - hours * 3_600_000
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端存的是 SQLite `datetime('now')`,即无时区后缀的 UTC 串。
|
||||
* 直接做字符串比较会因空格(0x20)小于 'T'(0x54)而整体误判,必须先转时间戳。
|
||||
*/
|
||||
function toTime(value: string): number {
|
||||
if (value === '') return 0
|
||||
const normalized = /[zZ]|[+-]\d{2}:?\d{2}$/.test(value) ? value : `${value.replace(' ', 'T')}Z`
|
||||
const parsed = Date.parse(normalized)
|
||||
return Number.isNaN(parsed) ? 0 : parsed
|
||||
}
|
||||
|
||||
function teamLabel(teamId: number): string {
|
||||
@@ -171,6 +188,7 @@ function teamTotals(revision: Revision, context: EventContext | null): Map<numbe
|
||||
scorable.push({
|
||||
entryId: row.entryId,
|
||||
teamId,
|
||||
athleteId: context.entryById.get(row.entryId)?.athleteId ?? null,
|
||||
resultValue: row.resultValue,
|
||||
rank: row.rank,
|
||||
status: normalizeStatus(row.status),
|
||||
@@ -205,14 +223,48 @@ async function ensureContext(eventId: number): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表接口不含成绩快照,只有详情接口才带;选中节点后补拉一次,
|
||||
* 否则真机上 diff 恒 0、影响单位恒空、积分流水恒 0。
|
||||
*/
|
||||
async function loadDetail(id: number): Promise<void> {
|
||||
if (usingMock.value || detailLoadedIds.value.includes(id)) return
|
||||
detailLoading.value = true
|
||||
detailError.value = null
|
||||
try {
|
||||
const detail = await fetchRevisionDetail(id)
|
||||
if (detail === null) return
|
||||
revisions.value = revisions.value.map((item) => (item.id === id ? { ...item, ...detail } : item))
|
||||
detailLoadedIds.value = [...detailLoadedIds.value, id]
|
||||
} catch (caught) {
|
||||
detailError.value = caught instanceof Error ? caught.message : '加载变更详情失败'
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 只有网络不可达才降级示例数据;403 / 404 / 500 必须原样呈现。 */
|
||||
function isUnavailable(error: unknown): boolean {
|
||||
return error instanceof ApiError && ['NETWORK', 'TIMEOUT'].includes(error.code)
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
const eventId = eventFilter.value === 'all' ? undefined : eventFilter.value
|
||||
detailLoadedIds.value = []
|
||||
detailError.value = null
|
||||
loadError.value = null
|
||||
try {
|
||||
revisions.value = await fetchRevisions(eventId === undefined ? {} : { eventId })
|
||||
usingMock.value = false
|
||||
mockReason.value = null
|
||||
} catch (caught) {
|
||||
if (!isUnavailable(caught)) {
|
||||
revisions.value = []
|
||||
usingMock.value = false
|
||||
loadError.value = caught instanceof Error ? caught.message : '变更历史接口不可用'
|
||||
return
|
||||
}
|
||||
const all = createMockRevisions()
|
||||
revisions.value = eventId === undefined ? all : all.filter((item) => item.eventId === eventId)
|
||||
usingMock.value = true
|
||||
@@ -245,7 +297,9 @@ watch(
|
||||
watch(
|
||||
selectedRevision,
|
||||
(revision) => {
|
||||
if (revision !== null) void ensureContext(revision.eventId)
|
||||
if (revision === null) return
|
||||
void ensureContext(revision.eventId)
|
||||
if (revision.snapshot.length === 0) void loadDetail(revision.id)
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
@@ -268,6 +322,12 @@ watch(
|
||||
<span class="mock-hint">接口就绪后自动切换为真实数据</span>
|
||||
</div>
|
||||
|
||||
<div v-if="loadError !== null" class="error-banner">
|
||||
<MxIcon name="warning" :size="15" />
|
||||
<span>{{ loadError }}</span>
|
||||
<button class="mx-btn mx-btn-secondary mx-btn-sm" type="button" @click="load">重试</button>
|
||||
</div>
|
||||
|
||||
<div class="filter-bar">
|
||||
<label class="filter">
|
||||
<span>小项</span>
|
||||
@@ -341,6 +401,8 @@ watch(
|
||||
<span v-if="selectedRevision" class="mx-badge mx-badge-neutral mono">#{{ selectedRevision.id }}</span>
|
||||
</div>
|
||||
<div class="mx-card-body">
|
||||
<p v-if="detailLoading" class="detail-hint">正在加载节点详情…</p>
|
||||
<p v-else-if="detailError !== null" class="detail-hint error">加载节点详情失败:{{ detailError }}</p>
|
||||
<RevisionDetail
|
||||
v-if="selectedRevision"
|
||||
:revision="selectedRevision"
|
||||
@@ -381,6 +443,20 @@ watch(
|
||||
color: var(--mx-t3);
|
||||
font-size: 12px;
|
||||
}
|
||||
.error-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 14px;
|
||||
margin-top: 14px;
|
||||
border-radius: var(--mx-r-sm);
|
||||
background: rgba(248, 113, 113, 0.08);
|
||||
color: var(--mx-red);
|
||||
font-size: 13px;
|
||||
}
|
||||
.error-banner .mx-btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -464,6 +540,14 @@ watch(
|
||||
background: rgba(251, 191, 36, 0.12);
|
||||
color: var(--mx-amber);
|
||||
}
|
||||
.detail-hint {
|
||||
font-size: 12px;
|
||||
color: var(--mx-t3);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.detail-hint.error {
|
||||
color: var(--mx-error);
|
||||
}
|
||||
.foot-hint {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -6,7 +6,7 @@ import PageHeader from '../components/PageHeader.vue'
|
||||
import MockBadge from '../components/system/MockBadge.vue'
|
||||
import JsonDiff from '../components/system/JsonDiff.vue'
|
||||
import { describeError } from '../components/system/systemApi'
|
||||
import { adminApi, mockMode } from '../api/client'
|
||||
import { adminApi } from '../api/client'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
@@ -81,14 +81,18 @@ function onFilterChange(): void {
|
||||
page.value = 1
|
||||
}
|
||||
|
||||
const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
|
||||
async function load(): Promise<void> {
|
||||
// /api/audit-logs 是 admin-only;非 admin 直接不请求,避免常驻 403 报错。
|
||||
if (!isAdmin.value) return
|
||||
loading.value = true
|
||||
loadError.value = null
|
||||
try {
|
||||
const result = await adminApi.auditLogs({ page: 1, size: WINDOW_SIZE })
|
||||
rows.value = result.items
|
||||
// adminApi 内部静默降级,只能从全局标记反推这批数据是不是示例。
|
||||
usingMock.value = mockMode.value
|
||||
// 用局部 mock 标记判断本批数据是不是示例,不读会被并发请求清掉的全局状态。
|
||||
const result = await adminApi.auditLogsWithMock({ page: 1, size: WINDOW_SIZE })
|
||||
rows.value = result.data.items
|
||||
usingMock.value = result.mock
|
||||
if (page.value > pageCount.value) page.value = 1
|
||||
} catch (caught) {
|
||||
loadError.value = describeError(caught)
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import MxIcon from '../components/MxIcon.vue'
|
||||
import PageHeader from '../components/PageHeader.vue'
|
||||
import type { IconName } from '../components/icons'
|
||||
|
||||
/**
|
||||
* 未实现页面的统一骨架。
|
||||
* M4 只要求占位路由,这里把「这页将来做什么」写清楚,避免点进来是一片空白。
|
||||
*/
|
||||
const route = useRoute()
|
||||
|
||||
const TITLE_ICONS: Record<string, IconName> = {
|
||||
review: 'review',
|
||||
records: 'record',
|
||||
adjustments: 'adjust',
|
||||
'base-data': 'database',
|
||||
export: 'export',
|
||||
history: 'history',
|
||||
logs: 'logs',
|
||||
system: 'system',
|
||||
}
|
||||
|
||||
const title = computed(() => (typeof route.meta.title === 'string' ? route.meta.title : '页面'))
|
||||
const note = computed(() => (typeof route.meta.note === 'string' ? route.meta.note : ''))
|
||||
const icon = computed<IconName>(() => TITLE_ICONS[String(route.name)] ?? 'system')
|
||||
|
||||
const PLANNED: Record<string, string[]> = {
|
||||
review: ['草稿列表(按项目 / 时间筛选)', '并排对比历史版本', '批量发布 / 退回,留审计'],
|
||||
records: ['疑似破纪录自动提示', '裁判长确认后生成加分流水', '本期破纪录加分关闭,功能保留'],
|
||||
adjustments: ['人工加减分(分值可正可负)', '类别:处罚 / 补分 / 更正', '理由必填、可作废、全程审计'],
|
||||
'base-data': ['单位 / 大项 / 小项 / 组别', '积分模板与计分通道', '运动员与报名表 xlsx 导入'],
|
||||
export: ['总表 / 分项成绩表 / 单位明细', '按小项、组别单独导出', '赛事项目包 zip 导入导出'],
|
||||
history: ['仿 Git Graph 的时间轴 + 分支线', '节点详情:操作人 / 动作 / 分数增减', '只读,不做一键回滚'],
|
||||
logs: ['审计日志:谁在什么时候改了什么', '按实体类型 / 用户 / 时间筛选', '可关联 requestId 追查重试'],
|
||||
system: ['用户与角色管理', '备份与恢复', '赛事信息与项目切换'],
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader :title="title" :subtitle="note">
|
||||
<template #actions>
|
||||
<span class="mx-badge mx-badge-neutral">规划中</span>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div class="mx-card">
|
||||
<div class="mx-card-body">
|
||||
<div class="skeleton-head">
|
||||
<span class="skeleton-icon"><MxIcon :name="icon" :size="22" /></span>
|
||||
<div>
|
||||
<h2>{{ title }}页面将在后续里程碑实现</h2>
|
||||
<p>M4 只交付占位路由与骨架,核心链路(成绩录入 → 积分榜 → 大屏)已可用。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="planned">
|
||||
<div class="planned-title">计划能力</div>
|
||||
<ul>
|
||||
<li v-for="item in PLANNED[String(route.name)] ?? []" :key="item">
|
||||
<MxIcon name="check" :size="14" />
|
||||
<span>{{ item }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="mx-stat-grid skeleton-grid">
|
||||
<div v-for="index in 3" :key="index" class="mx-stat skeleton-stat">
|
||||
<div class="mx-skeleton line short"></div>
|
||||
<div class="mx-skeleton line tall"></div>
|
||||
<div class="mx-skeleton line"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.skeleton-head {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.skeleton-icon {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: var(--mx-r-sm);
|
||||
background: var(--mx-primary-glow);
|
||||
color: var(--mx-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.skeleton-head h2 {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.skeleton-head p {
|
||||
font-size: 13px;
|
||||
color: var(--mx-t3);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.planned {
|
||||
padding: 14px 16px;
|
||||
border-radius: var(--mx-r-sm);
|
||||
background: var(--mx-s3);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.planned-title {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--mx-t3);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.planned ul {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.planned li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--mx-t2);
|
||||
}
|
||||
.planned li svg {
|
||||
color: var(--mx-green);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.skeleton-grid {
|
||||
opacity: 0.6;
|
||||
}
|
||||
.skeleton-stat {
|
||||
cursor: default;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
.line {
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.line.short {
|
||||
width: 40%;
|
||||
}
|
||||
.line.tall {
|
||||
height: 24px;
|
||||
width: 60%;
|
||||
}
|
||||
</style>
|
||||
@@ -78,6 +78,7 @@ const rejectedKeys = ref<string[]>([])
|
||||
const approvedKeys = ref<string[]>([])
|
||||
|
||||
const canWrite = computed(() => !auth.readOnly && data.canWrite)
|
||||
const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
/**
|
||||
* 破纪录加分开关:true / false / null(未知)。
|
||||
*
|
||||
@@ -139,11 +140,13 @@ function levelRank(level: RecordLevel): number {
|
||||
return index < 0 ? 0 : index
|
||||
}
|
||||
|
||||
/** 只有真的连不上服务端才做本地降级;业务 404 / 解析失败必须原样呈现。 */
|
||||
function isFallback(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof ApiError &&
|
||||
(['NETWORK', 'TIMEOUT', 'PARSE_FAILED'].includes(error.code) || error.status === 404)
|
||||
)
|
||||
return error instanceof ApiError && ['NETWORK', 'TIMEOUT'].includes(error.code)
|
||||
}
|
||||
|
||||
function isForbidden(error: unknown): boolean {
|
||||
return error instanceof ApiError && (error.status === 403 || error.code === 'FORBIDDEN')
|
||||
}
|
||||
|
||||
function teamLabel(teamId: number): string {
|
||||
@@ -161,11 +164,22 @@ function beats(compare: Event['compare'], value: number, recordValue: number): b
|
||||
async function loadRules(): Promise<void> {
|
||||
rulesLoading.value = true
|
||||
try {
|
||||
rulePack.value = await adminApi.client.rules.get()
|
||||
ruleError.value = null
|
||||
// /api/rules/export 是 admin-only:录入员跳过它,改用下面的只读开关端点,
|
||||
// 否则页面会常驻一条红色「读取规则包失败:无权访问该资源」。
|
||||
if (isAdmin.value) {
|
||||
rulePack.value = await adminApi.client.rules.get()
|
||||
ruleError.value = null
|
||||
} else {
|
||||
rulePack.value = null
|
||||
ruleError.value = null
|
||||
}
|
||||
} catch (caught) {
|
||||
rulePack.value = null
|
||||
ruleError.value = caught instanceof Error ? caught.message : '无法读取规则包'
|
||||
ruleError.value = isForbidden(caught)
|
||||
? null
|
||||
: caught instanceof Error
|
||||
? caught.message
|
||||
: '无法读取规则包'
|
||||
} finally {
|
||||
rulesLoading.value = false
|
||||
}
|
||||
@@ -459,7 +473,14 @@ watch(
|
||||
>
|
||||
确认加分
|
||||
</button>
|
||||
<button class="mx-btn mx-btn-ghost mx-btn-sm" type="button" @click="rejectTarget = item">拒绝</button>
|
||||
<button
|
||||
class="mx-btn mx-btn-ghost mx-btn-sm"
|
||||
type="button"
|
||||
:disabled="!canWrite"
|
||||
@click="rejectTarget = item"
|
||||
>
|
||||
拒绝
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { computed, onMounted, ref, watch } from 'vue'
|
||||
import {
|
||||
ApiError,
|
||||
formatPoints,
|
||||
parseResultValue,
|
||||
type EntryWithResult,
|
||||
type Event,
|
||||
type EventCategory,
|
||||
@@ -128,11 +129,35 @@ function teamLabel(teamId: number, fallback: string): string {
|
||||
return team?.shortName ?? team?.name ?? fallback
|
||||
}
|
||||
|
||||
/** 只有真的连不上服务端才做本地降级;业务 404 / 解析失败必须原样呈现。 */
|
||||
function isFallback(error: unknown): boolean {
|
||||
return (
|
||||
error instanceof ApiError &&
|
||||
(['NETWORK', 'TIMEOUT', 'PARSE_FAILED'].includes(error.code) || error.status === 404)
|
||||
)
|
||||
return error instanceof ApiError && ['NETWORK', 'TIMEOUT'].includes(error.code)
|
||||
}
|
||||
|
||||
function unitOf(type: Event['resultType']): string {
|
||||
if (type === 'time') return 's'
|
||||
if (type === 'distance') return 'm'
|
||||
if (type === 'count') return '次'
|
||||
if (type === 'score') return 'pts'
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 发布前防呆:与录入页同一套校验,避免整组发布缺成绩 / 无法解析的行。 */
|
||||
function publishBlockers(group: DraftGroup): string[] {
|
||||
const unit = unitOf(group.event.resultType)
|
||||
const manual = group.event.resultMode === 'manual' || group.event.compare === 'none'
|
||||
const blockers: string[] = []
|
||||
for (const row of group.rows) {
|
||||
if (row.status !== 'ok') continue
|
||||
const label = row.athleteName || row.memberNames?.join('、') || row.teamShort || `#${row.entryId}`
|
||||
if (row.resultText.trim() === '') {
|
||||
if (!(manual && row.rank !== null)) blockers.push(`${label}:缺少成绩`)
|
||||
} else if (parseResultValue(row.resultText, unit) === null) {
|
||||
blockers.push(`${label}:成绩格式无法解析`)
|
||||
}
|
||||
if (manual && row.rank === null) blockers.push(`${label}:缺少名次`)
|
||||
}
|
||||
return blockers
|
||||
}
|
||||
|
||||
function sportNameOf(event: Event): string {
|
||||
@@ -147,6 +172,7 @@ function buildGroup(event: Event, category: EventCategory | null, entries: Entry
|
||||
const scorable: ScorableRow[] = scoped.map((entry) => ({
|
||||
entryId: entry.id,
|
||||
teamId: entry.teamId,
|
||||
athleteId: entry.athleteId,
|
||||
resultValue: entry.result?.resultValue ?? null,
|
||||
rank: entry.result?.rank ?? null,
|
||||
status: entry.result?.status ?? 'ok',
|
||||
@@ -160,15 +186,16 @@ function buildGroup(event: Event, category: EventCategory | null, entries: Entry
|
||||
weight: weight.value,
|
||||
}
|
||||
const score = computeEventScore(scorable, context)
|
||||
const individual = event.eventType === 'individual'
|
||||
|
||||
// 已发布行的分已经计入当前总分,对比时必须先扣掉,差值才是「本次发布」的影响。
|
||||
// result.points 服务端从不返回(恒为 0),改用与预览同一套算法算出的 rowPoints。
|
||||
// rowTeamPoints 已按通道 scope 折算好个人→单位系数,与服务端流水口径一致。
|
||||
const published = new Map<number, number>()
|
||||
for (const entry of scoped) {
|
||||
if (entry.result?.state !== 'published') continue
|
||||
const points = round(score.rowPoints.get(entry.id) ?? 0) * (individual ? weight.value : 1)
|
||||
published.set(entry.teamId, (published.get(entry.teamId) ?? 0) + points)
|
||||
published.set(
|
||||
entry.teamId,
|
||||
(published.get(entry.teamId) ?? 0) + round(score.rowTeamPoints.get(entry.id) ?? 0),
|
||||
)
|
||||
}
|
||||
|
||||
const teamIds = new Set<number>([...score.teamPoints.keys(), ...published.keys()])
|
||||
@@ -277,6 +304,11 @@ function requestPublish(group: DraftGroup): void {
|
||||
toast.error('当前不可发布', auth.readOnly ? '请先登录' : '服务端未连接')
|
||||
return
|
||||
}
|
||||
const blockers = publishBlockers(group)
|
||||
if (blockers.length > 0) {
|
||||
toast.error(`有 ${blockers.length} 处校验未通过`, blockers[0] ?? null)
|
||||
return
|
||||
}
|
||||
publishTarget.value = group
|
||||
}
|
||||
|
||||
@@ -288,7 +320,7 @@ async function confirmPublish(): Promise<void> {
|
||||
await adminApi.publish({ eventId: group.event.id, categoryId: group.category?.id })
|
||||
publishTarget.value = null
|
||||
await load()
|
||||
await data.refreshStandings()
|
||||
await Promise.all([data.refreshStandings(), data.refreshEvents()])
|
||||
toast.success('发布成功,积分榜已更新', `${group.eventName} · ${group.categoryName}`)
|
||||
} catch (caught) {
|
||||
toast.error('发布失败', caught instanceof Error ? caught.message : null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import PageHeader from '../components/PageHeader.vue'
|
||||
import UsersPanel from '../components/system/UsersPanel.vue'
|
||||
import BackupPanel from '../components/system/BackupPanel.vue'
|
||||
@@ -28,6 +28,16 @@ const data = useEventStore()
|
||||
const activeTab = ref<TabKey>('users')
|
||||
|
||||
const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
/** 用户管理 / 备份的后端接口是 admin-only,非 admin 不挂载这两个面板。 */
|
||||
const visibleTabs = computed(() => (isAdmin.value ? TABS : TABS.filter((tab) => tab.key === 'event')))
|
||||
|
||||
watch(
|
||||
isAdmin,
|
||||
(admin) => {
|
||||
if (!admin && activeTab.value !== 'event') activeTab.value = 'event'
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -37,7 +47,7 @@ const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
<div class="system-toolbar">
|
||||
<div class="mx-tabs">
|
||||
<button
|
||||
v-for="tab in TABS"
|
||||
v-for="tab in visibleTabs"
|
||||
:key="tab.key"
|
||||
class="mx-tab"
|
||||
:class="{ active: activeTab === tab.key }"
|
||||
@@ -48,7 +58,7 @@ const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
</button>
|
||||
</div>
|
||||
<span class="mx-badge" :class="isAdmin ? 'mx-badge-success' : 'mx-badge-neutral'">
|
||||
{{ isAdmin ? `当前身份:${auth.displayName}` : `只读访客 · ${auth.displayName}` }}
|
||||
{{ isAdmin ? `当前身份:${auth.displayName}` : `${auth.roleLabel} · ${auth.displayName}` }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -59,8 +69,8 @@ const isAdmin = computed(() => auth.user?.role === 'admin')
|
||||
|
||||
<p v-if="data.error !== null" class="role-note error">数据加载失败:{{ data.error }}</p>
|
||||
|
||||
<UsersPanel v-if="activeTab === 'users'" />
|
||||
<BackupPanel v-else-if="activeTab === 'backup'" />
|
||||
<UsersPanel v-if="isAdmin && activeTab === 'users'" />
|
||||
<BackupPanel v-else-if="isAdmin && activeTab === 'backup'" />
|
||||
<EventInfoPanel v-else />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user