task-261(admin.html观感对齐): 数字人版本页对齐(状态/最新★/文件大小/MD5截断/操作矩阵/上传文案/删除)

This commit is contained in:
2026-09-05 21:58:55 +08:00
parent 6bd44e6884
commit a6b18b78e6
4 changed files with 146 additions and 29 deletions
@@ -1,11 +1,22 @@
<script setup lang="ts">
/** 数字人版本管理页(module 13 task 261 对齐 admin panel-digital-human-version)。 */
import { formatDateTime } from '@/utils/datetime'
/** 数字人版本管理页:列表 + 上传 + 发布 + 设最新 + 下载。 */
import { formatFileSize } from './version-format.ts'
import { md5Short } from './digitalhuman-format.ts'
import { onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchDigitalHumanVersions, uploadDigitalHumanVersion, releaseDigitalHumanVersion, setLatestDigitalHumanVersion } from './digitalhuman-api.ts'
import {
deleteDigitalHumanVersion,
fetchDigitalHumanVersions,
releaseDigitalHumanVersion,
setLatestDigitalHumanVersion,
uploadDigitalHumanVersion,
} from './digitalhuman-api.ts'
import type { DigitalHumanVersion } from './digitalhuman-dto.ts'
import { validateDigitalHumanUpload } from './digitalhuman-upload-model.ts'
import { canReleaseDigitalHumanVersion, releaseDigitalHumanConfirmText } from './digitalhuman-release.ts'
import { canSetLatestDigitalHumanVersion, setLatestDigitalHumanConfirmText } from './digitalhuman-latest.ts'
import { digitalHumanStatusDisplay, latestBadgeText } from './digitalhuman-status-display.ts'
const loading = ref(false)
const items = ref<DigitalHumanVersion[]>([])
@@ -16,13 +27,6 @@ const form = ref({ version: '', file: null as { name?: string; size?: number } |
const confirming = ref<string | null>(null)
function formatSize(size?: number): string {
if (size === undefined || size === null) return ''
if (size < 1024) return `${size}B`
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)}KB`
return `${(size / 1024 / 1024).toFixed(1)}MB`
}
async function load() {
loading.value = true
try {
@@ -45,12 +49,13 @@ async function submitUpload() {
return
}
uploading.value = true
const version = (form.value.version || '').trim()
try {
await uploadDigitalHumanVersion(
{ version: form.value.version, file: form.value.file, changelog: form.value.changelog, minClientVersion: form.value.minClientVersion },
{ version, file: form.value.file, changelog: form.value.changelog, minClientVersion: form.value.minClientVersion },
form.value.file?.name,
)
ElMessage.success('上传成功')
ElMessage.success(`上传成功!版本:${version}(状态:草稿,请在列表中点击“发布”按钮)`)
uploadVisible.value = false
form.value = { version: '', file: null, changelog: '', minClientVersion: '' }
load()
@@ -62,9 +67,11 @@ async function submitUpload() {
}
async function release(row: DigitalHumanVersion) {
const text = releaseDigitalHumanConfirmText(row.version)
if (!text) return
confirming.value = row.version
try {
await ElMessageBox.confirm(`确认发布版本 ${row.version}`, '发布版本', { type: 'warning' })
await ElMessageBox.confirm(text, '发布版本', { type: 'warning', confirmButtonText: '发布', cancelButtonText: '取消' })
await releaseDigitalHumanVersion(row.version)
ElMessage.success('已发布')
load()
@@ -77,9 +84,11 @@ async function release(row: DigitalHumanVersion) {
}
async function setLatest(row: DigitalHumanVersion) {
const text = setLatestDigitalHumanConfirmText(row.version)
if (!text) return
confirming.value = row.version
try {
await ElMessageBox.confirm(`${row.version} 设为最新版本?`, '设为最新', { type: 'warning' })
await ElMessageBox.confirm(text, '设为最新', { type: 'warning', confirmButtonText: '设为最新', cancelButtonText: '取消' })
await setLatestDigitalHumanVersion(row.version)
ElMessage.success('已设为最新')
load()
@@ -91,6 +100,29 @@ async function setLatest(row: DigitalHumanVersion) {
}
}
async function remove(row: DigitalHumanVersion) {
confirming.value = row.version
try {
await ElMessageBox.confirm(`确定删除数字人版本 ${row.version} 吗?此操作不可恢复。`, '删除版本', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
})
await deleteDigitalHumanVersion(row.version)
ElMessage.success('删除成功')
load()
} catch (error) {
if (error === 'cancel' || error === 'close') return
ElMessage.error(error instanceof Error ? error.message : '删除失败')
} finally {
confirming.value = null
}
}
function canDelete(row: DigitalHumanVersion): boolean {
return row.isLatest !== true
}
onMounted(load)
</script>
@@ -107,36 +139,41 @@ onMounted(load)
</div>
<el-card shadow="never">
<el-table v-loading="loading" :data="items" stripe border>
<el-table v-loading="loading" :data="items" stripe border empty-text="暂无数字人版本">
<el-table-column prop="version" label="版本号" min-width="150" />
<el-table-column label="状态" width="110">
<el-table-column label="状态" width="100">
<template #default="{ row }">
<el-tag :type="(row as DigitalHumanVersion).status === 'RELEASED' ? 'success' : 'info'" size="small">
{{ (row as DigitalHumanVersion).status === 'RELEASED' ? '已发布' : '草稿' }}
<el-tag :type="(digitalHumanStatusDisplay((row as DigitalHumanVersion).status).tag as 'success' | 'info')" size="small">
{{ digitalHumanStatusDisplay((row as DigitalHumanVersion).status).text }}
</el-tag>
<el-tag v-if="(row as DigitalHumanVersion).isLatest" type="primary" size="small" effect="dark" style="margin-left: 4px">最新</el-tag>
</template>
</el-table-column>
<el-table-column label="大小" width="110">
<template #default="{ row }">{{ formatSize((row as DigitalHumanVersion).fileSize) || '—' }}</template>
<el-table-column label="最新" width="60" align="center">
<template #default="{ row }">
<span v-if="(row as DigitalHumanVersion).isLatest" class="star" title="最新版本"></span>
<span v-else></span>
</template>
</el-table-column>
<el-table-column prop="minClientVersion" label="最低客户端" width="120">
<template #default="{ row }">{{ (row as DigitalHumanVersion).minClientVersion || '—' }}</template>
<el-table-column label="文件大小" width="100">
<template #default="{ row }">{{ (row as DigitalHumanVersion).fileSize != null ? formatFileSize((row as DigitalHumanVersion).fileSize!) : '—' }}</template>
</el-table-column>
<el-table-column label="MD5" width="130">
<template #default="{ row }">
<span :title="(row as DigitalHumanVersion).md5 || ''">{{ md5Short((row as DigitalHumanVersion).md5) || '—' }}</span>
</template>
</el-table-column>
<el-table-column prop="changelog" label="更新说明" min-width="180" show-overflow-tooltip />
<el-table-column prop="createdAt" label="创建时间" min-width="170">
<template #default="{ row }">{{ formatDateTime(row.createdAt) }}</template>
</el-table-column>
<el-table-column prop="releasedAt" label="发布时间" min-width="170">
<el-table-column label="发布时间" min-width="170">
<template #default="{ row }">{{ formatDateTime((row as DigitalHumanVersion).releasedAt) }}</template>
</el-table-column>
<el-table-column label="操作" width="200" fixed="right">
<el-table-column label="操作" width="210" fixed="right">
<template #default="{ row }">
<el-button v-if="(row as DigitalHumanVersion).status === 'DRAFT'" text type="warning" size="small" :loading="confirming === (row as DigitalHumanVersion).version" @click="release(row as DigitalHumanVersion)">发布</el-button>
<el-button text type="primary" size="small" :loading="confirming === (row as DigitalHumanVersion).version" @click="setLatest(row as DigitalHumanVersion)">设最新</el-button>
<el-button v-if="canReleaseDigitalHumanVersion((row as DigitalHumanVersion).status)" text type="warning" size="small" :loading="confirming === (row as DigitalHumanVersion).version" @click="release(row as DigitalHumanVersion)">发布</el-button>
<el-button v-if="!canReleaseDigitalHumanVersion((row as DigitalHumanVersion).status) && canSetLatestDigitalHumanVersion((row as DigitalHumanVersion).status) && !(row as DigitalHumanVersion).isLatest" text type="primary" size="small" :loading="confirming === (row as DigitalHumanVersion).version" @click="setLatest(row as DigitalHumanVersion)">设最新</el-button>
<el-button v-if="(row as DigitalHumanVersion).downloadUrl" text type="success" size="small">
<el-link type="success" :href="(row as DigitalHumanVersion).downloadUrl" target="_blank">下载</el-link>
</el-button>
<el-button v-if="canDelete(row as DigitalHumanVersion)" text type="danger" size="small" :loading="confirming === (row as DigitalHumanVersion).version" @click="remove(row as DigitalHumanVersion)">删除</el-button>
</template>
</el-table-column>
</el-table>
@@ -172,4 +209,5 @@ onMounted(load)
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; }
.actions { display: flex; align-items: center; gap: 10px; }
.dim { color: var(--el-text-color-secondary); font-size: 12px; }
.star { color: #e6a23c; font-weight: 700; }
</style>
@@ -29,3 +29,8 @@ export async function releaseDigitalHumanVersion(version: string): Promise<void>
export async function setLatestDigitalHumanVersion(version: string): Promise<void> {
await http.post<unknown>(`${DIGITAL_HUMAN_VERSIONS_ENDPOINT}/${encodeURIComponent(version)}/set-latest`)
}
/** 删除数字人版本:DELETE /{version}。 */
export async function deleteDigitalHumanVersion(version: string): Promise<void> {
await http.delete<unknown>(`${DIGITAL_HUMAN_VERSIONS_ENDPOINT}/${encodeURIComponent(version)}`)
}
@@ -0,0 +1,9 @@
/** 数字人版本展示格式化(module 13 task 261):MD5 截断展示;纯逻辑。 */
/** MD5 前 len 位(默认 12,对齐 admin)展示;空值回空串。 */
export function md5Short(md5: string | null | undefined, len = 12): string {
const text = typeof md5 === 'string' ? md5.trim() : ''
if (!text) return ''
const max = typeof len === 'number' && Number.isFinite(len) && len >= 1 ? Math.floor(len) : 12
return text.length <= max ? text : `${text.slice(0, max)}`
}
+65
View File
@@ -0,0 +1,65 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { digitalHumanStatusDisplay, latestBadgeText } from '../src/pages/records/digitalhuman-status-display.ts'
import { canReleaseDigitalHumanVersion } from '../src/pages/records/digitalhuman-release.ts'
import { canSetLatestDigitalHumanVersion } from '../src/pages/records/digitalhuman-latest.ts'
import { md5Short } from '../src/pages/records/digitalhuman-format.ts'
// module 13 task 261:数字人版本页对齐 admin panel-digital-human-version(状态/最新★/大小/MD5截断/操作矩阵/上传文案)。
test('test_task_261_dh_normal_primary_path', () => {
// 正常主路径:状态映射与发布/设最新判定。
assert.deepEqual(digitalHumanStatusDisplay('DRAFT'), { text: '草稿', tag: 'info' })
assert.deepEqual(digitalHumanStatusDisplay('RELEASED'), { text: '已发布', tag: 'success' })
assert.equal(canReleaseDigitalHumanVersion('DRAFT'), true)
assert.equal(canSetLatestDigitalHumanVersion('RELEASED'), true)
assert.equal(canSetLatestDigitalHumanVersion('DRAFT'), false)
})
test('test_task_261_dh_normal_variant_input', () => {
assert.equal(md5Short('a'.repeat(12)), 'a'.repeat(12), '恰好 12 位原样')
assert.equal(md5Short('a'.repeat(20)), `${'a'.repeat(12)}`, '超长截 12 位并省略')
assert.equal(md5Short(''), '')
assert.equal(md5Short(null), '')
})
test('test_task_261_dh_normal_repeated_operation_is_idempotent', () => {
assert.equal(digitalHumanStatusDisplay('draft').text, '草稿')
assert.equal(digitalHumanStatusDisplay('draft').text, '草稿')
})
test('test_task_261_dh_boundary_empty_input', () => {
assert.equal(latestBadgeText(true), '最新')
assert.equal(latestBadgeText(false), '')
assert.equal(digitalHumanStatusDisplay('').text, '草稿', '未知状态归一草稿')
})
test('test_task_261_dh_boundary_single_item', () => {
const page = readSource('src/pages/records/RecordsDigitalHumanVersionPage.vue')
assert.match(page, /formatFileSize/, '文件大小走共享格式化')
assert.match(page, /md5Short/, 'MD5 截断展示')
assert.match(page, /canReleaseDigitalHumanVersion/, '发布按钮按状态显隐')
})
test('test_task_261_dh_boundary_limit_or_missing_field', () => {
// 边界上限:文件大小格式化(复用了版本页 formatFileSize)。
const fmt = readSource('src/pages/records/version-format.ts')
assert.match(fmt, /formatFileSize/)
})
test('test_task_261_dh_invalid_input_rejected', () => {
// 异常:删除需二次确认;删除走后端 DELETE;删除失败有兜底。
const page = readSource('src/pages/records/RecordsDigitalHumanVersionPage.vue')
assert.match(page, /此操作不可恢复/, '删除需危险二次确认')
assert.match(page, /删除失败/, '删除失败有兜底文案')
const api = readSource('src/pages/records/digitalhuman-api.ts')
assert.match(api, /http\.delete/, '删除调用 DELETE 适配')
})
test('test_task_261_dh_dependency_failure_returns_actionable_message', () => {
// 依赖失败:上传成功文案含“请在列表中点击发布”。
const page = readSource('src/pages/records/RecordsDigitalHumanVersionPage.vue')
assert.match(page, /上传成功!版本:/, '上传成功文案需含版本')
assert.match(page, /请在列表中点击“发布”按钮/, '上传成功引导发布')
})