fix(admin): 后台时间统一展示为 YYYY-MM-DD HH:mm:ss(formatDateTime 全页接入)
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 数字人版本管理页:列表 + 上传 + 发布 + 设最新 + 下载。 */
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { fetchDigitalHumanVersions, uploadDigitalHumanVersion, releaseDigitalHumanVersion, setLatestDigitalHumanVersion } from './digitalhuman-api.ts'
|
||||
import type { DigitalHumanVersion } from './digitalhuman-dto.ts'
|
||||
import { validateDigitalHumanUpload } from './digitalhuman-upload-model.ts'
|
||||
|
||||
const loading = ref(false)
|
||||
const items = ref<DigitalHumanVersion[]>([])
|
||||
|
||||
const uploadVisible = ref(false)
|
||||
const uploading = ref(false)
|
||||
const form = ref({ version: '', file: null as { name?: string; size?: number } | null, changelog: '', minClientVersion: '' })
|
||||
|
||||
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 {
|
||||
items.value = (await fetchDigitalHumanVersions()).items
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '版本列表加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onFileChange(file: File) {
|
||||
form.value.file = file
|
||||
}
|
||||
|
||||
async function submitUpload() {
|
||||
const { valid, errors } = validateDigitalHumanUpload({ ...form.value, file: form.value.file })
|
||||
if (!valid) {
|
||||
ElMessage.warning(errors.version || errors.file || '请完善上传信息')
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
try {
|
||||
await uploadDigitalHumanVersion(
|
||||
{ version: form.value.version, file: form.value.file, changelog: form.value.changelog, minClientVersion: form.value.minClientVersion },
|
||||
form.value.file?.name,
|
||||
)
|
||||
ElMessage.success('上传成功')
|
||||
uploadVisible.value = false
|
||||
form.value = { version: '', file: null, changelog: '', minClientVersion: '' }
|
||||
load()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '上传失败')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function release(row: DigitalHumanVersion) {
|
||||
confirming.value = row.version
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认发布版本 ${row.version}?`, '发布版本', { type: 'warning' })
|
||||
await releaseDigitalHumanVersion(row.version)
|
||||
ElMessage.success('已发布')
|
||||
load()
|
||||
} catch (error) {
|
||||
if (error === 'cancel' || error === 'close') return
|
||||
ElMessage.error(error instanceof Error ? error.message : '发布失败')
|
||||
} finally {
|
||||
confirming.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function setLatest(row: DigitalHumanVersion) {
|
||||
confirming.value = row.version
|
||||
try {
|
||||
await ElMessageBox.confirm(`将 ${row.version} 设为最新版本?`, '设为最新', { type: 'warning' })
|
||||
await setLatestDigitalHumanVersion(row.version)
|
||||
ElMessage.success('已设为最新')
|
||||
load()
|
||||
} catch (error) {
|
||||
if (error === 'cancel' || error === 'close') return
|
||||
ElMessage.error(error instanceof Error ? error.message : '操作失败')
|
||||
} finally {
|
||||
confirming.value = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-stack">
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<h2>数字人版本管理</h2>
|
||||
<p>管理数字人客户端的草稿/已发布版本。</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<el-button type="primary" @click="uploadVisible = true">上传数字人版本</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never">
|
||||
<el-table v-loading="loading" :data="items" stripe border>
|
||||
<el-table-column prop="version" label="版本号" min-width="150" />
|
||||
<el-table-column label="状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="(row as DigitalHumanVersion).status === 'RELEASED' ? 'success' : 'info'" size="small">
|
||||
{{ (row as DigitalHumanVersion).status === 'RELEASED' ? '已发布' : '草稿' }}
|
||||
</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>
|
||||
<el-table-column prop="minClientVersion" label="最低客户端" width="120">
|
||||
<template #default="{ row }">{{ (row as DigitalHumanVersion).minClientVersion || '—' }}</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">
|
||||
<template #default="{ row }">{{ formatDateTime((row as DigitalHumanVersion).releasedAt) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" 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="(row as DigitalHumanVersion).downloadUrl" text type="success" size="small">
|
||||
<el-link type="success" :href="(row as DigitalHumanVersion).downloadUrl" target="_blank">下载</el-link>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="uploadVisible" title="上传数字人版本" width="560px">
|
||||
<el-form label-width="110px">
|
||||
<el-form-item label="版本号" required>
|
||||
<el-input v-model="form.version" placeholder="如 1.0.2" />
|
||||
</el-form-item>
|
||||
<el-form-item label="压缩包" required>
|
||||
<el-upload :auto-upload="false" :limit="1" accept=".zip,.rar,.7z" :on-change="(file: any) => onFileChange(file.raw)" :on-remove="() => (form.file = null)">
|
||||
<el-button>选择文件</el-button>
|
||||
</el-upload>
|
||||
<div v-if="form.file" class="dim">{{ form.file.name }}</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="最低客户端">
|
||||
<el-input v-model="form.minClientVersion" placeholder="可选,客户端最低版本要求" />
|
||||
</el-form-item>
|
||||
<el-form-item label="更新说明">
|
||||
<el-input v-model="form.changelog" type="textarea" :rows="3" placeholder="可选" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="uploadVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="uploading" @click="submitUpload">上传</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.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; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user