569 lines
17 KiB
Vue
569 lines
17 KiB
Vue
<script setup lang="ts">
|
||
/** 数字人版本管理页 · 像素复刻旧版 admin.html panel-digital-human-version(自绘:面板头+上传、三态状态色、最新★、操作矩阵、数字页码分页)。
|
||
* script 逻辑沿用现有 Vue 实现(确认文案/上传进度/下载取链接);确认走原生 confirm 对齐旧版。 */
|
||
import { formatDateTime } from '@/utils/datetime'
|
||
import { computed, onMounted, ref, watch } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import {
|
||
deleteDigitalHumanVersion,
|
||
fetchDigitalHumanDownloadUrl,
|
||
fetchDigitalHumanVersions,
|
||
releaseDigitalHumanVersion,
|
||
setLatestDigitalHumanVersion,
|
||
uploadDigitalHumanVersion,
|
||
} from './digitalhuman-api.ts'
|
||
import type { DigitalHumanVersion } from './digitalhuman-dto.ts'
|
||
import {
|
||
digitalHumanChangelogShort,
|
||
digitalHumanDeleteConfirmText,
|
||
digitalHumanVersionFileSizeText,
|
||
} 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 OldPagination from '@/components/OldPagination.vue'
|
||
import { digitalHumanStatusDisplay } from './digitalhuman-status-display.ts'
|
||
|
||
const loading = ref(false)
|
||
const items = ref<DigitalHumanVersion[]>([])
|
||
|
||
/** 分页(对齐 admin.js:6311 pageSize=20 + 数字页码 + 跳转;Java 列表接口不分页,前端分页呈现)。 */
|
||
const pageSize = ref(10)
|
||
const page = ref(1)
|
||
/** 版本号搜索(客户端过滤)。 */
|
||
const versionKeyword = ref('')
|
||
const filteredItems = computed(() => {
|
||
const kw = (versionKeyword.value || '').trim().toLowerCase()
|
||
if (!kw) return items.value
|
||
return items.value.filter((item) => `${item.version}`.toLowerCase().includes(kw))
|
||
})
|
||
const pagedItems = computed(() => {
|
||
const start = (page.value - 1) * pageSize.value
|
||
return filteredItems.value.slice(start, start + pageSize.value)
|
||
})
|
||
const totalPages = computed(() => Math.max(1, Math.ceil(filteredItems.value.length / pageSize.value)))
|
||
const jumpPage = ref('')
|
||
|
||
const uploadVisible = ref(false)
|
||
const uploading = ref(false)
|
||
const uploadProgress = ref<number | null>(null)
|
||
const form = ref({ version: '', file: null as { name?: string; size?: number } | null, changelog: '', minClientVersion: '' })
|
||
|
||
const confirming = ref<string | null>(null)
|
||
const downloadingVersion = ref<string | null>(null)
|
||
|
||
async function load() {
|
||
loading.value = true
|
||
try {
|
||
items.value = (await fetchDigitalHumanVersions()).items
|
||
// 页码越界回钳见下方 watch(items)。
|
||
} catch (error) {
|
||
ElMessage.error(error instanceof Error ? error.message : '版本列表加载失败')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function changePage(next: number): void {
|
||
if (next < 1 || next > totalPages.value) return
|
||
page.value = next
|
||
}
|
||
|
||
function changeSize(size: number) {
|
||
pageSize.value = size
|
||
page.value = 1
|
||
}
|
||
|
||
// 版本号搜索导致数据收缩时回钳页码,避免停在空页。
|
||
watch(items, () => {
|
||
const last = Math.max(Math.ceil(filteredItems.value.length / pageSize.value), 1)
|
||
if (page.value > last) page.value = last
|
||
})
|
||
|
||
function goJump(): void {
|
||
const n = Number.parseInt(jumpPage.value, 10)
|
||
if (Number.isNaN(n)) {
|
||
ElMessage.warning('请输入页码')
|
||
return
|
||
}
|
||
changePage(Math.min(Math.max(n, 1), totalPages.value))
|
||
}
|
||
|
||
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
|
||
uploadProgress.value = 0
|
||
const version = (form.value.version || '').trim()
|
||
try {
|
||
await uploadDigitalHumanVersion(
|
||
{ version, file: form.value.file, changelog: form.value.changelog, minClientVersion: form.value.minClientVersion },
|
||
form.value.file?.name,
|
||
(percent) => {
|
||
uploadProgress.value = percent
|
||
},
|
||
)
|
||
ElMessage.success(`上传成功!版本:${version}(状态:草稿,请在列表中点击“发布”按钮)`)
|
||
uploadVisible.value = false
|
||
uploadProgress.value = null
|
||
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) {
|
||
const text = releaseDigitalHumanConfirmText(row.version)
|
||
if (!text) return
|
||
// 对齐旧版:原生 confirm。
|
||
if (!window.confirm(text)) return
|
||
confirming.value = row.version
|
||
try {
|
||
await releaseDigitalHumanVersion(row.version)
|
||
ElMessage.success('已发布')
|
||
load()
|
||
} catch (error) {
|
||
ElMessage.error(error instanceof Error ? error.message : '发布失败')
|
||
} finally {
|
||
confirming.value = null
|
||
}
|
||
}
|
||
|
||
async function setLatest(row: DigitalHumanVersion) {
|
||
const text = setLatestDigitalHumanConfirmText(row.version)
|
||
if (!text) return
|
||
if (!window.confirm(text)) return
|
||
confirming.value = row.version
|
||
try {
|
||
await setLatestDigitalHumanVersion(row.version)
|
||
ElMessage.success('已设为最新')
|
||
load()
|
||
} catch (error) {
|
||
ElMessage.error(error instanceof Error ? error.message : '操作失败')
|
||
} finally {
|
||
confirming.value = null
|
||
}
|
||
}
|
||
|
||
/** 下载(对齐 admin.js downloadDigitalHumanVersion:RELEASED 恒显示,点击取链接并触发下载)。 */
|
||
async function download(row: DigitalHumanVersion) {
|
||
if (!row.version) return
|
||
downloadingVersion.value = row.version
|
||
try {
|
||
const url = await fetchDigitalHumanDownloadUrl(row.version)
|
||
const anchor = document.createElement('a')
|
||
anchor.href = url
|
||
anchor.download = `ShuFuDigitalHuman-${row.version}.zip`
|
||
anchor.target = '_blank'
|
||
anchor.rel = 'noopener'
|
||
document.body.appendChild(anchor)
|
||
anchor.click()
|
||
document.body.removeChild(anchor)
|
||
} catch (error) {
|
||
ElMessage.error(error instanceof Error ? error.message : '下载失败')
|
||
} finally {
|
||
downloadingVersion.value = null
|
||
}
|
||
}
|
||
|
||
async function remove(row: DigitalHumanVersion) {
|
||
const text = digitalHumanDeleteConfirmText(row.version)
|
||
if (!text) return
|
||
if (!window.confirm(text)) return
|
||
confirming.value = row.version
|
||
try {
|
||
await deleteDigitalHumanVersion(row.version)
|
||
ElMessage.success('删除成功')
|
||
load()
|
||
} catch (error) {
|
||
ElMessage.error(error instanceof Error ? error.message : '删除失败')
|
||
} finally {
|
||
confirming.value = null
|
||
}
|
||
}
|
||
|
||
function canDelete(row: DigitalHumanVersion): boolean {
|
||
return row.isLatest !== true
|
||
}
|
||
|
||
function statusOf(row: DigitalHumanVersion): { text: string; tag: 'info' | 'success' | 'danger' } {
|
||
return digitalHumanStatusDisplay(row.status)
|
||
}
|
||
|
||
onMounted(load)
|
||
</script>
|
||
|
||
<template>
|
||
<div class="dh-view">
|
||
<section class="panel-box">
|
||
<div class="dh-head">
|
||
<h3>版本列表</h3>
|
||
<div class="dh-head-tools">
|
||
<input v-model="versionKeyword" type="text" placeholder="搜索版本号" class="dh-keyword" />
|
||
<button class="btn" type="button" @click="uploadVisible = true">上传新版本</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="table-scroll digital-human-version-table-scroll">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th style="width: 80px">版本号</th>
|
||
<th style="width: 60px">状态</th>
|
||
<th style="width: 60px">最新</th>
|
||
<th style="width: 80px">文件大小</th>
|
||
<th style="width: 120px">MD5</th>
|
||
<th>更新日志</th>
|
||
<th style="width: 140px">发布时间</th>
|
||
<th style="width: 240px">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<template v-if="pagedItems.length">
|
||
<tr v-for="row in pagedItems" :key="row.version + row.id">
|
||
<td><span class="mono-cell">{{ row.version }}</span></td>
|
||
<td>
|
||
<span class="st-pill" :class="`is-${statusOf(row).tag}`">{{ statusOf(row).text }}</span>
|
||
</td>
|
||
<td><span v-if="row.isLatest" class="star" title="最新版本">★</span><span v-else class="dim">—</span></td>
|
||
<td>{{ digitalHumanVersionFileSizeText(row.fileSize) }}</td>
|
||
<td><span :title="row.md5 || ''" class="mono-cell">{{ row.md5 ? `${row.md5.substring(0, 12)}...` : '—' }}</span></td>
|
||
<td>
|
||
<span :title="row.changelog || ''" class="changelog-cell">{{ digitalHumanChangelogShort(row.changelog) }}</span>
|
||
</td>
|
||
<td>{{ formatDateTime(row.releasedAt) }}</td>
|
||
<td class="ops-cell">
|
||
<button v-if="canReleaseDigitalHumanVersion(row.status)" class="btn btn-sm" type="button" :disabled="confirming === row.version" @click="release(row)">发布</button>
|
||
<button
|
||
v-if="!canReleaseDigitalHumanVersion(row.status) && canSetLatestDigitalHumanVersion(row.status) && !row.isLatest"
|
||
class="btn btn-sm"
|
||
type="button"
|
||
:disabled="confirming === row.version"
|
||
@click="setLatest(row)"
|
||
>
|
||
设为最新
|
||
</button>
|
||
<button v-if="canSetLatestDigitalHumanVersion(row.status)" class="btn btn-sm btn-secondary" type="button" :disabled="downloadingVersion === row.version" @click="download(row)">下载</button>
|
||
<button v-if="canDelete(row)" class="btn btn-sm btn-danger" type="button" :disabled="confirming === row.version" @click="remove(row)">删除</button>
|
||
</td>
|
||
</tr>
|
||
</template>
|
||
<tr v-else-if="loading">
|
||
<td colspan="8" class="empty-tip">加载中...</td>
|
||
</tr>
|
||
<tr v-else>
|
||
<td colspan="8" class="empty-tip">{{ versionKeyword ? '暂无匹配版本' : '暂无版本记录' }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<div v-if="filteredItems.length > pageSize" class="pagination">
|
||
<OldPagination :total="filteredItems.length" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||
</div>
|
||
</section>
|
||
|
||
<el-dialog v-model="uploadVisible" title="上传数字人版本" width="560px">
|
||
<p class="upload-desc">上传数字人程序 ZIP 包,系统会自动计算 MD5 并存储到 OSS。上传后状态为草稿,需要手动发布。</p>
|
||
<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" :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-alert v-if="uploading && uploadProgress != null" :title="`正在上传:${uploadProgress}%`" type="info" :closable="false" show-icon />
|
||
</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>
|
||
/* 像素复刻旧版 admin.html panel-digital-human-version(蓝白末层)。 */
|
||
.dh-view {
|
||
font-family: inherit;
|
||
color: #24384d;
|
||
}
|
||
.panel-box {
|
||
width: 100%;
|
||
min-width: 0;
|
||
padding: 20px 22px 24px;
|
||
border: 1px solid #d8e3ee;
|
||
border-radius: 14px;
|
||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||
}
|
||
h3 {
|
||
margin: 0;
|
||
font-size: 15px;
|
||
font-weight: 650;
|
||
color: #24384d;
|
||
letter-spacing: 0.2px;
|
||
}
|
||
.dh-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
margin-bottom: 16px;
|
||
}
|
||
.dh-head-tools {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
.dh-keyword {
|
||
width: 200px;
|
||
min-height: 42px;
|
||
padding: 6px 12px;
|
||
border: 1px solid #cbd9e6;
|
||
border-radius: 9px;
|
||
background: #f8fbfd;
|
||
color: #24384d;
|
||
font-size: 13.5px;
|
||
font-family: inherit;
|
||
color-scheme: light;
|
||
outline: none;
|
||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||
}
|
||
.dh-keyword:hover {
|
||
border-color: #9fb7cd;
|
||
}
|
||
.dh-keyword:focus {
|
||
background: #ffffff;
|
||
border-color: #5f85ad;
|
||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||
}
|
||
.btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 8px;
|
||
min-height: 42px;
|
||
padding: 9px 18px;
|
||
border: 1px solid #4f78a5;
|
||
border-radius: 9px;
|
||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||
color: #ffffff;
|
||
font-family: inherit;
|
||
font-size: 13.5px;
|
||
cursor: pointer;
|
||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||
}
|
||
.btn:hover:not(:disabled) {
|
||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||
}
|
||
.btn:disabled {
|
||
cursor: not-allowed;
|
||
opacity: 0.55;
|
||
}
|
||
.btn-secondary {
|
||
background: #ffffff;
|
||
color: #5b6f83;
|
||
border-color: #c7d7e5;
|
||
}
|
||
.btn-secondary:hover:not(:disabled) {
|
||
color: #2f5d8b;
|
||
border-color: #95b1cb;
|
||
background: #edf5fb;
|
||
}
|
||
.btn-danger {
|
||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||
border-color: #b35f6a;
|
||
}
|
||
.btn-danger:hover:not(:disabled) {
|
||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||
}
|
||
.btn-sm {
|
||
min-height: 36px;
|
||
padding: 7px 12px;
|
||
}
|
||
.table-scroll {
|
||
width: 100%;
|
||
min-width: 0;
|
||
overflow-x: auto;
|
||
border: 1px solid #dbe5ee;
|
||
border-radius: 10px;
|
||
background: #ffffff;
|
||
}
|
||
.table-scroll table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
table-layout: fixed;
|
||
}
|
||
.digital-human-version-table-scroll > table {
|
||
min-width: 1120px;
|
||
}
|
||
.table-scroll th,
|
||
.table-scroll td {
|
||
padding: 10px 12px;
|
||
text-align: left;
|
||
font-size: 13.5px;
|
||
line-height: 1.5;
|
||
border-bottom: 1px solid #e0e8ef;
|
||
vertical-align: middle;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.table-scroll th {
|
||
background: #edf4fa;
|
||
color: #4e6479;
|
||
border-bottom-color: #d5e1eb;
|
||
font-size: 12.5px;
|
||
font-weight: 600;
|
||
letter-spacing: 0.4px;
|
||
}
|
||
.table-scroll tbody tr:hover td {
|
||
background: #f1f7fb;
|
||
}
|
||
.table-scroll tbody tr:last-child td {
|
||
border-bottom: 0;
|
||
}
|
||
.mono-cell {
|
||
font-family: "Cascadia Mono", Consolas, monospace;
|
||
font-size: 12.5px;
|
||
}
|
||
.st-pill {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
padding: 2px 10px;
|
||
border-radius: 999px;
|
||
font-size: 12px;
|
||
line-height: 1.7;
|
||
border: 1px solid transparent;
|
||
}
|
||
.st-pill.is-info {
|
||
color: #6b7280;
|
||
background: #f1f3f5;
|
||
border-color: #dfe3e8;
|
||
}
|
||
.st-pill.is-success {
|
||
color: #398a3f;
|
||
background: #eaf7ec;
|
||
border-color: #bfe3c5;
|
||
}
|
||
.st-pill.is-danger {
|
||
color: #b8454d;
|
||
background: #fbedee;
|
||
border-color: #ecc9cc;
|
||
}
|
||
.star {
|
||
color: #d64545;
|
||
font-weight: 700;
|
||
}
|
||
.changelog-cell {
|
||
display: block;
|
||
color: #5b6f83;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
.ops-cell {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.empty-tip {
|
||
padding: 44px 24px;
|
||
text-align: center;
|
||
color: #8293a5;
|
||
font-size: 13.5px;
|
||
}
|
||
.pagination {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: 8px;
|
||
margin-top: 18px;
|
||
color: #5b6f83;
|
||
font-size: 13px;
|
||
}
|
||
.pagination button {
|
||
min-height: 30px;
|
||
padding: 4px 12px;
|
||
border: 1px solid #c7d7e5;
|
||
border-radius: 8px;
|
||
background: #ffffff;
|
||
color: #5b6f83;
|
||
font-family: inherit;
|
||
font-size: 13px;
|
||
cursor: pointer;
|
||
}
|
||
.pagination button:hover:not(:disabled) {
|
||
background: #edf5fb;
|
||
border-color: #95b1cb;
|
||
color: #2f5d8b;
|
||
}
|
||
.pagination button:disabled {
|
||
background: #eef3f7;
|
||
color: #9baaba;
|
||
cursor: not-allowed;
|
||
}
|
||
.page-nums {
|
||
display: inline-flex;
|
||
gap: 6px;
|
||
}
|
||
.num-page {
|
||
min-width: 30px;
|
||
padding: 4px 8px;
|
||
}
|
||
.num-page.is-active {
|
||
background: #2f5d8b;
|
||
border-color: #2f5d8b;
|
||
color: #ffffff;
|
||
}
|
||
.page-jump {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
.page-jump input {
|
||
width: 56px;
|
||
min-height: 30px;
|
||
padding: 4px 8px;
|
||
border: 1px solid #cbd9e6;
|
||
border-radius: 8px;
|
||
background: #f8fbfd;
|
||
color: #24384d;
|
||
font-size: 13px;
|
||
font-family: inherit;
|
||
}
|
||
.dim {
|
||
color: #8293a5;
|
||
font-size: 12px;
|
||
}
|
||
.upload-desc {
|
||
margin: 0 0 12px;
|
||
color: #5b6f83;
|
||
font-size: 12.5px;
|
||
line-height: 1.6;
|
||
}
|
||
</style>
|