feat(workbench-client): 新增数富AI工作台客户端包管理独立更新渠道

后台上传安装包,confirm 阶段由服务端从 MinIO 实物流式复算 sha256 后落库,
客户端经 /api/workbench-client/version/latest 自动检查更新;与 ShuFuAI 桌面端
的 nanri-image/versions/ 渠道隔离,包体落 client 桶 workbench-client/versions/。
This commit is contained in:
2026-10-24 12:49:51 +08:00
parent b94555f411
commit ba20f5ed42
22 changed files with 1789 additions and 53 deletions
@@ -89,6 +89,10 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
text: '上传新的教程压缩包后即刻生效:工具台首页「立即下载教程」以下载最新上传的包为准。确认旧包不再需要后再删除。',
steps: ['上传教程压缩包', '到工具台核对下载', '清理历史包'],
},
admin_workbench_client_package: {
text: '上传新的工作台客户端 ZIP 包后即刻生效:客户端从 /api/workbench-client/version/latest 自动检测版本并升级;服务端会复算 sha256 供客户端校验。确认旧包不再需要后再删除。',
steps: ['填写版本号并上传 ZIP', '核对版本与 sha256', '清理历史包'],
},
digital_human_version: {
text: '数字人版本需先上传草稿,再发布并标记最新版本。',
steps: ['上传草稿', '确认更新日志', '发布或设为最新'],
@@ -0,0 +1,503 @@
<script setup lang="ts">
import { formatDateTime } from '@/utils/datetime'
/** 数富AI工作台客户端包管理页:上传 ZIP → 直传 MinIO → 服务端复算 sha256 落库;
* 客户端从 /api/workbench-client/version/latest 自动检测并按最新上传升级。
* 列表默认按上传时间倒序,第一条即当前生效版本;删除最新包后自动回落到上一版。 */
import { computed, onMounted, ref, watch } from 'vue'
import OldPagination from '@/components/OldPagination.vue'
import { ElMessage } from 'element-plus'
import {
deleteWorkbenchClientPackages,
fetchWorkbenchClientPackages,
uploadWorkbenchClientPackage,
} from './workbench-client-api.ts'
import { formatFileSize, isValidWorkbenchClientVersion, WORKBENCH_CLIENT_VERSION_MAX_LENGTH } from './workbench-client-model.ts'
import type { WorkbenchClientPackageItem } from './workbench-client-dto.ts'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { openAdminConfirm } from '@/components/admin-confirm'
import LoadFailureBar from '@/components/LoadFailureBar.vue'
const loading = ref(false)
const loadFailure = ref('')
const items = ref<WorkbenchClientPackageItem[]>([])
/** 版本号/文件名搜索(客户端过滤)。 */
const keyword = ref('')
const filteredItems = computed(() => {
const kw = (keyword.value || '').trim().toLowerCase()
if (!kw) return items.value
return items.value.filter((item) =>
`${item.version}`.toLowerCase().includes(kw) || item.fileName.toLowerCase().includes(kw),
)
})
/** 全站分页统一:客户端分页(10/20/50/100)。 */
const page = ref(1)
const pageSize = ref(10)
const pagedItems = computed(() => filteredItems.value.slice((page.value - 1) * pageSize.value, page.value * pageSize.value))
function changePage(p: number) { page.value = p }
function changeSize(size: number) { pageSize.value = size; page.value = 1 }
// 搜索导致数据收缩时回钳页码,避免停在空页。
watch(filteredItems, () => {
page.value = Math.min(page.value, Math.max(1, Math.ceil(filteredItems.value.length / pageSize.value)))
})
/** 当前生效版本 = 列表第一条(客户端更新接口下发的就是它)。 */
const activeId = computed(() => items.value[0]?.id ?? null)
// 勾选删除:选中跨页累计;表头复选只作用于当前页,避免误选整表。
const selectedIds = ref<Set<number>>(new Set())
const selectedCount = computed(() => selectedIds.value.size)
function toggleSelect(id: number) {
const next = new Set(selectedIds.value)
if (next.has(id)) next.delete(id)
else next.add(id)
selectedIds.value = next
}
function toggleSelectAllPage() {
const pageRows = pagedItems.value
const allOn = pageRows.length > 0 && pageRows.every((row) => selectedIds.value.has(row.id))
const next = new Set(selectedIds.value)
if (allOn) pageRows.forEach((row) => next.delete(row.id))
else pageRows.forEach((row) => next.add(row.id))
selectedIds.value = next
}
async function removeSelected() {
if (!selectedCount.value) return
const rows = items.value.filter((row) => selectedIds.value.has(row.id))
const sample = rows.slice(0, 3).map((row) => row.version).join('、')
const summary = rows.length > 3 ? `${sample} 等 ${rows.length} 个` : sample
if (!(await openAdminConfirm({ message: `确认删除选中的 ${rows.length} 个客户端包(${summary})?此操作不可恢复。`, danger: true }))) return
try {
await deleteWorkbenchClientPackages(Array.from(selectedIds.value))
ElMessage.success(`已删除 ${rows.length} 个客户端包`)
selectedIds.value = new Set()
await load()
} catch (error) {
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
}
}
async function removeOne(row: WorkbenchClientPackageItem) {
if (!(await openAdminConfirm({ message: `确认删除客户端包 ${row.version}(${row.fileName})?此操作不可恢复。`, danger: true }))) return
try {
await deleteWorkbenchClientPackages([row.id])
ElMessage.success('删除成功')
selectedIds.value = new Set([...selectedIds.value].filter((id) => id !== row.id))
await load()
} catch (error) {
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
}
}
const uploadVisible = ref(false)
const uploading = ref(false)
const uploadPercent = ref(0)
const newVersion = ref('')
const pickedFile = ref<File | null>(null)
const uploadMsg = ref('')
const uploadMsgOk = ref(false)
async function load() {
loading.value = true
loadFailure.value = ''
try {
items.value = (await fetchWorkbenchClientPackages()).items
} catch (error) {
loadFailure.value = error instanceof Error ? error.message : '客户端包列表加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
}
}
function onFileChange(file: File) {
pickedFile.value = file
}
function openUpload() {
uploadMsg.value = ''
uploadMsgOk.value = false
newVersion.value = ''
pickedFile.value = null
uploadVisible.value = true
}
async function submitUpload() {
uploadMsg.value = ''
uploadMsgOk.value = false
uploadPercent.value = 0
if (!newVersion.value.trim()) {
uploadMsg.value = '请填写版本号'
return
}
if (!isValidWorkbenchClientVersion(newVersion.value)) {
uploadMsg.value = `版本号不能超过 ${WORKBENCH_CLIENT_VERSION_MAX_LENGTH} 个字符`
return
}
if (!pickedFile.value) {
uploadMsg.value = '请选择 zip 压缩包'
return
}
if (!/\.zip$/i.test(pickedFile.value.name)) {
uploadMsg.value = '仅支持 .zip 格式'
return
}
if (pickedFile.value.size > 512 * 1024 * 1024) {
uploadMsg.value = '文件超过允许的大小限制'
return
}
uploading.value = true
try {
await uploadWorkbenchClientPackage(pickedFile.value, pickedFile.value.name, newVersion.value.trim(), (p) => {
uploadPercent.value = p
uploadMsg.value = p >= 100 ? '上传完成,正在复算 sha256 并登记...' : `正在上传:${p}%`
})
uploadMsg.value = '上传成功,客户端已可检测到新版本'
uploadMsgOk.value = true
newVersion.value = ''
pickedFile.value = null
uploadPercent.value = 0
load()
} catch (error) {
uploadMsg.value = error instanceof Error ? error.message : '上传失败'
} finally {
uploading.value = false
}
}
onMounted(load)
</script>
<template>
<div class="workbench-view">
<section class="panel-box">
<div class="workbench-head">
<h3>客户端包列表</h3>
<div class="workbench-head-tools">
<input v-model="keyword" type="text" placeholder="搜索版本号或文件名" class="workbench-keyword" />
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
<button class="btn" type="button" @click="openUpload">上传客户端包</button>
</div>
</div>
<p class="page-hint">客户端更新检查接口:<code>/api/workbench-client/version/latest</code>;最新上传的一条即当前生效版本。</p>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<div class="table-scroll workbench-table-scroll">
<table>
<thead>
<tr>
<th style="width: 40px" class="th-select">
<input type="checkbox" :checked="pagedItems.length > 0 && pagedItems.every((r) => selectedIds.has(r.id))" @change="toggleSelectAllPage" :disabled="!pagedItems.length" />
</th>
<th style="width: 120px">版本号</th>
<th style="width: 220px">文件名</th>
<th style="width: 100px">大小</th>
<th style="width: 220px">SHA-256</th>
<th style="width: 150px">上传时间</th>
<th>下载链接</th>
<th style="width: 170px">操作</th>
</tr>
</thead>
<tbody>
<template v-if="filteredItems.length">
<tr v-for="row in pagedItems" :key="row.id" :class="{ 'row-selected': selectedIds.has(row.id) }">
<td class="td-select">
<input type="checkbox" :checked="selectedIds.has(row.id)" @change="toggleSelect(row.id)" />
</td>
<td>
<span class="version-cell" :title="row.version">{{ row.version }}</span>
<span v-if="row.id === activeId" class="tag-active">当前生效</span>
</td>
<td>
<span class="file-name" :title="row.fileName">{{ row.fileName }}</span>
</td>
<td>{{ formatFileSize(row.fileSize) }}</td>
<td>
<span v-if="row.sha256" class="sha-cell" :title="row.sha256">{{ row.sha256 }}</span>
<span v-else class="dim">—</span>
</td>
<td>{{ formatDateTime(row.createdAt) }}</td>
<td>
<a v-if="row.fileUrl" class="link-cell" :href="row.fileUrl" target="_blank" rel="noopener" :title="row.fileUrl">{{ row.fileUrl }}</a>
<span v-else class="dim">—</span>
</td>
<td class="ops-cell">
<a v-if="row.fileUrl" class="btn btn-sm dl-btn" :href="row.fileUrl" download>下载</a>
<span v-else class="dim">—</span>
<button class="btn btn-sm btn-danger" type="button" @click="removeOne(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">{{ keyword ? '暂无匹配客户端包' : '暂无客户端包记录' }}</td>
</tr>
</tbody>
</table>
</div>
<OldPagination v-if="filteredItems.length > 0" :total="filteredItems.length" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
</section>
<el-dialog v-model="uploadVisible" title="上传客户端包" width="540px">
<p class="upload-desc">上传数富AI工作台客户端 ZIP 包后,客户端会从公开版本接口自动检测到新版本并升级;服务端会复算 sha256 供客户端校验。</p>
<el-form label-width="110px">
<el-form-item label="版本号" required>
<el-input v-model="newVersion" :placeholder="`例如:1.0.0(最长 ${WORKBENCH_CLIENT_VERSION_MAX_LENGTH} 字符)`" :maxlength="WORKBENCH_CLIENT_VERSION_MAX_LENGTH" />
<p class="zip-hint">客户端按版本号判断是否需要升级,必填</p>
</el-form-item>
<el-form-item label="ZIP 压缩包" required>
<el-upload :auto-upload="false" :limit="1" accept=".zip" :on-change="(file: any) => onFileChange(file.raw)" :on-remove="() => (pickedFile = null)">
<el-button>选择文件</el-button>
</el-upload>
<p class="zip-hint">仅支持 .zip 格式,最大 512MB</p>
<div v-if="pickedFile" class="dim">{{ pickedFile.name }}({{ formatFileSize(pickedFile.size) }})</div>
</el-form-item>
<el-progress v-if="uploading && uploadPercent > 0" :percentage="uploadPercent" :stroke-width="10" :status="uploadPercent >= 100 ? 'success' : undefined" class="upload-progress" />
<el-alert v-if="uploadMsg" :title="uploadMsg" :type="uploadMsgOk ? 'success' : 'error'" :closable="false" show-icon class="upload-msg" />
</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-version)的样式语言。 */
.workbench-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;
}
.workbench-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.workbench-head-tools {
display: flex;
align-items: center;
gap: 10px;
}
.workbench-keyword {
width: 220px;
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;
}
.workbench-keyword:hover {
border-color: #9fb7cd;
}
.workbench-keyword:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.page-hint {
margin: -6px 0 14px;
color: #5b6f83;
font-size: 12.5px;
}
.page-hint code {
padding: 1px 6px;
border-radius: 5px;
background: #edf4fa;
color: #2f5d8b;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.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-sm {
min-height: 36px;
padding: 7px 12px;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.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;
}
.workbench-table-scroll > table {
min-width: 1200px;
}
.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;
}
.file-name,
.version-cell {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
}
.tag-active {
display: inline-block;
margin-left: 6px;
padding: 1px 7px;
border: 1px solid #4f9a72;
border-radius: 999px;
background: #eaf6ef;
color: #2f7a55;
font-size: 11.5px;
vertical-align: middle;
}
.sha-cell {
display: block;
overflow: hidden;
color: #5b6f83;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
text-overflow: ellipsis;
}
.link-cell {
display: block;
color: #2f5d8b;
text-decoration: none;
overflow: hidden;
text-overflow: ellipsis;
}
.link-cell:hover {
text-decoration: underline;
}
.dl-btn {
text-decoration: none;
}
.dim {
color: #8293a5;
font-size: 12px;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.upload-desc {
margin: 0 0 12px;
color: #5b6f83;
font-size: 12.5px;
line-height: 1.6;
}
.zip-hint {
margin: 4px 0 0;
color: #5b6f83;
font-size: 12px;
}
.ops-cell {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
.row-selected td {
background: #fdf0ee;
}
.th-select,
.td-select {
text-align: center;
padding-left: 4px !important;
padding-right: 4px !important;
}
.th-select input,
.td-select input {
cursor: pointer;
accent-color: #b33a2e;
}
.upload-progress {
margin: 2px 0 10px;
}
.upload-msg {
margin-bottom: 8px;
}
.upload-msg :deep(.el-alert__title) {
word-break: break-all;
}
</style>
@@ -0,0 +1,98 @@
/** 工作台客户端包接口适配:列表 / 直传预签名 / 确认 / 删除。 */
import axios from 'axios'
import { http, unwrap } from '@/api/http'
import {
parseWorkbenchClientPackageList,
parseWorkbenchClientPackageUpload,
} from './workbench-client-model.ts'
import type { WorkbenchClientPackageItem, WorkbenchClientPackageList } from './workbench-client-dto.ts'
export const WORKBENCH_CLIENT_PACKAGES_ENDPOINT = '/api/admin/workbench-client/packages'
export const WORKBENCH_CLIENT_PACKAGE_ENDPOINT = '/api/admin/workbench-client/package'
export const WORKBENCH_CLIENT_PRESIGN_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/presign`
export const WORKBENCH_CLIENT_CONFIRM_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/confirm`
export const WORKBENCH_CLIENT_DELETE_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/delete`
/** 客户端自动更新契约(后管页面不直接调用):GET 返回 {version,file_url,sha256,...}。 */
export const WORKBENCH_CLIENT_PUBLIC_LATEST_ENDPOINT = '/api/workbench-client/version/latest'
/** MinIO 直传专用实例:不带 cookie、不挂 401 跳登录拦截器;大 zip 给足超时。 */
const directPut = axios.create({ timeout: 600_000, withCredentials: false })
export async function fetchWorkbenchClientPackages(): Promise<WorkbenchClientPackageList> {
const { data } = await http.get<unknown>(WORKBENCH_CLIENT_PACKAGES_ENDPOINT)
return parseWorkbenchClientPackageList(data)
}
export interface WorkbenchClientUploadTarget {
objectKey: string
uploadUrl: string
fileUrl: string
version: string
fileName: string
}
/** 第一步:向后端申请直传 PUT 预签名地址(登录会话签发,3 分钟有效)。 */
export async function requestWorkbenchClientPresign(
fileName: string,
version: string,
): Promise<WorkbenchClientUploadTarget> {
const { data } = await http.post<unknown>(WORKBENCH_CLIENT_PRESIGN_ENDPOINT, null, {
params: { file_name: fileName, version },
})
const core = (unwrap(data) ?? {}) as Record<string, unknown>
const uploadUrl = typeof core.upload_url === 'string' ? core.upload_url : ''
const objectKey = typeof core.object_key === 'string' ? core.object_key : ''
if (!uploadUrl || !objectKey) {
throw new Error('后端未返回直传地址,请重试')
}
return {
objectKey,
uploadUrl,
fileUrl: typeof core.file_url === 'string' ? core.file_url : '',
version: typeof core.version === 'string' ? core.version : version.trim(),
fileName: typeof core.file_name === 'string' ? core.file_name : fileName,
}
}
/** 第三步:直传完成后通知后端核对对象、复算 sha256 并落库(data.item 为新记录行)。 */
export async function confirmWorkbenchClientPackage(
objectKey: string,
fileName: string,
version: string,
): Promise<WorkbenchClientPackageItem | null> {
const { data } = await http.post<unknown>(WORKBENCH_CLIENT_CONFIRM_ENDPOINT, null, {
params: { object_key: objectKey, file_name: fileName, version },
})
return parseWorkbenchClientPackageUpload(data)
}
/** 按 id 批量删除客户端包(后端会顺带清理无引用对象的 MinIO 包体);返回实际删除行数。 */
export async function deleteWorkbenchClientPackages(ids: number[]): Promise<number> {
if (!ids.length) return 0
const { data } = await http.post<unknown>(WORKBENCH_CLIENT_DELETE_ENDPOINT, ids)
const core = (unwrap(data) ?? {}) as Record<string, unknown>
return typeof core.deleted === 'number' ? core.deleted : ids.length
}
/**
* 上传客户端包(浏览器直传):presign 申请 → 直接 PUT 到 MinIO client 桶(不走 Java 中转)
* → confirm 由服务端复算 sha256 落库。onProgress 回传 0-100 上传进度。
*/
export async function uploadWorkbenchClientPackage(
file: Blob,
fileName: string,
version: string,
onProgress?: (percent: number) => void,
): Promise<WorkbenchClientPackageItem | null> {
const target = await requestWorkbenchClientPresign(fileName, version)
await directPut.put(target.uploadUrl, file, {
headers: { 'Content-Type': 'application/octet-stream' },
onUploadProgress: (event) => {
if (!onProgress) return
const total = event.total || 0
onProgress(total > 0 ? Math.min(Math.round((event.loaded / total) * 100), 100) : 0)
},
})
return confirmWorkbenchClientPackage(target.objectKey, target.fileName, target.version)
}
@@ -0,0 +1,22 @@
/** 工作台客户端包 DTO(后管「数富AI工作台客户端包管理」页)。纯类型。 */
/** 客户端包行(GET /api/admin/workbench-client/packages data.items,Java snake)。 */
export interface WorkbenchClientPackageItem {
id: number
version: string
fileName: string
objectKey: string
fileSize: number
/** 更新包 sha256(hex 小写),客户端下载后的完整性锚点 */
sha256: string
fileUrl: string
createdAt: string
}
export interface WorkbenchClientPackageList {
items: WorkbenchClientPackageItem[]
}
export function emptyWorkbenchClientPackageList(): WorkbenchClientPackageList {
return { items: [] }
}
@@ -0,0 +1,72 @@
/** 工作台客户端包列表加载模型:解析 snake/camel、格式化大小与版本号校验;纯逻辑。 */
import { unwrap } from '../../api/envelope.ts'
import { type WorkbenchClientPackageItem, type WorkbenchClientPackageList } from './workbench-client-dto.ts'
/** 与后端 biz_workbench_client_package.version VARCHAR(64) 对齐。 */
export const WORKBENCH_CLIENT_VERSION_MAX_LENGTH = 64
function text(value: unknown): string {
return typeof value === 'string' ? value.trim() : ''
}
function numberOrNull(value: unknown): number | null {
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
}
/** 解析单条客户端包行;缺 id 视为无效。 */
export function toWorkbenchClientPackageItem(raw: unknown): WorkbenchClientPackageItem | null {
if (!raw || typeof raw !== 'object') return null
const r = raw as Record<string, unknown>
const id = numberOrNull(r.id)
if (id === null) return null
return {
id,
version: text(r.version),
fileName: text(r.file_name ?? r.fileName),
objectKey: text(r.object_key ?? r.objectKey),
fileSize: numberOrNull(r.file_size ?? r.fileSize) ?? 0,
sha256: text(r.sha256),
fileUrl: text(r.file_url ?? r.fileUrl),
createdAt: text(r.created_at ?? r.createdAt),
}
}
/** 归一化客户端包列表负载为前端结果;缺省回空列表。 */
export function parseWorkbenchClientPackageList(payload: unknown): WorkbenchClientPackageList {
const data = unwrap<unknown>(payload)
const record = data && typeof data === 'object' ? (data as Record<string, unknown>) : {}
const items = Array.isArray(record.items)
? record.items
.map((raw) => toWorkbenchClientPackageItem(raw))
.filter((item): item is WorkbenchClientPackageItem => item !== null)
: []
return { items }
}
/** 上传成功后返回的新记录行(data.item);无 item 回 null。 */
export function parseWorkbenchClientPackageUpload(payload: unknown): WorkbenchClientPackageItem | null {
const data = unwrap<unknown>(payload)
if (!data || typeof data !== 'object') return null
const item = (data as Record<string, unknown>).item
return item ? toWorkbenchClientPackageItem(item) : null
}
/** 版本号必填且不超过后端列宽;客户端要靠它比较是否需要升级。 */
export function isValidWorkbenchClientVersion(value: string): boolean {
const normalized = typeof value === 'string' ? value.trim() : ''
return normalized.length > 0 && normalized.length <= WORKBENCH_CLIENT_VERSION_MAX_LENGTH
}
/** 字节数展示:0=未知展示为 -,其余按 KB/MB/GB 人性化。 */
export function formatFileSize(bytes: number): string {
if (!Number.isFinite(bytes) || bytes <= 0) return '—'
if (bytes < 1024) return `${bytes} B`
const units = ['KB', 'MB', 'GB']
let value = bytes / 1024
let unitIndex = 0
while (value >= 1024 && unitIndex < units.length - 1) {
value /= 1024
unitIndex += 1
}
return `${value >= 100 ? value.toFixed(0) : value.toFixed(1)} ${units[unitIndex]}`
}
+1
View File
@@ -30,6 +30,7 @@ export const adminPages: AdminPageDef[] = [
{ path: 'records/history', menuKey: 'admin_history', title: '生成记录', companyScoped: true, load: () => import('@/pages/records/RecordsHistoryPage.vue') },
{ path: 'records/software-version', menuKey: 'admin_version', title: '软件版本管理', companyScoped: false, load: () => import('@/pages/records/RecordsSoftwareVersionPage.vue') },
{ path: 'records/tutorial', menuKey: 'admin_tutorial', title: '教程管理', companyScoped: false, load: () => import('@/pages/records/RecordsTutorialPage.vue') },
{ path: 'records/workbench-client-package', menuKey: 'admin_workbench_client_package', title: '数富AI工作台客户端包管理', companyScoped: false, load: () => import('@/pages/records/WorkbenchClientPackagePage.vue') },
{ path: 'records/device-logs', menuKey: 'admin_device_logs', title: '日志管理', companyScoped: true, load: () => import('@/pages/records/DeviceLogsPage.vue') },
{ path: 'task-center/board', menuKey: 'admin_task_center', title: '客户端任务管理', companyScoped: true, load: () => import('@/pages/task-center/TaskCenterBoardPage.vue') },
{ path: 'records/digital-human-version', menuKey: 'digital_human_version', title: '数字人版本管理', load: () => import('@/pages/records/RecordsDigitalHumanVersionPage.vue') },