@@ -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 = "11 0" >
< el-table-column label = "状态" width = "10 0" >
< 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 = "12 0" >
< template # default = "{ row }" > { { ( row as DigitalHumanVersion ) . minClientVersion || '—' } } < / template >
< el-table-column label = "文件大小 " width = "10 0" >
< 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 = "20 0" fixed = "right" >
< el-table-column label = "操作" width = "21 0" 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 : 10 px ; }
. dim { color : var ( -- el - text - color - secondary ) ; font - size : 12 px ; }
. star { color : # e6a23c ; font - weight : 700 ; }
< / style >