task-261(admin.html观感对齐): 数字人版本页对齐(状态/最新★/文件大小/MD5截断/操作矩阵/上传文案/删除)
This commit is contained in:
@@ -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)}…`
|
||||
}
|
||||
Reference in New Issue
Block a user