feat(desktop): add client release updater
Desktop Client Build / Resolve Build Metadata (push) Successful in 19s
Frontend CI / Frontend (push) Successful in 3m20s
Backend CI / Backend (push) Successful in 16m48s
Desktop Client Build / Build Desktop Client (push) Successful in 24m46s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 37s
Desktop Client Build / Resolve Build Metadata (push) Successful in 19s
Frontend CI / Frontend (push) Successful in 3m20s
Backend CI / Backend (push) Successful in 16m48s
Desktop Client Build / Build Desktop Client (push) Successful in 24m46s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 37s
This commit is contained in:
@@ -50,12 +50,13 @@ import {
|
||||
AuditOutlined,
|
||||
BookOutlined,
|
||||
ClockCircleOutlined,
|
||||
CloudDownloadOutlined,
|
||||
ControlOutlined,
|
||||
CrownOutlined,
|
||||
FileSearchOutlined,
|
||||
GlobalOutlined,
|
||||
PartitionOutlined,
|
||||
LineChartOutlined,
|
||||
PartitionOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SettingOutlined,
|
||||
TeamOutlined,
|
||||
@@ -83,6 +84,7 @@ const menuLeaves: MenuLeaf[] = [
|
||||
{ key: '/admin-users', label: '用户管理', path: '/admin-users' },
|
||||
{ key: '/kol-subscriptions', label: '订阅包审批', path: '/kol-subscriptions' },
|
||||
{ key: '/site-domain-mappings', label: '站点映射', path: '/site-domain-mappings' },
|
||||
{ key: '/desktop-client/releases', label: '客户端版本', path: '/desktop-client/releases' },
|
||||
{ key: '/compliance/policy', label: '全局策略', path: '/compliance/policy' },
|
||||
{ key: '/compliance/dictionaries', label: '合规词库', path: '/compliance/dictionaries' },
|
||||
{ key: '/compliance/manual-reviews', label: '人工审阅', path: '/compliance/manual-reviews' },
|
||||
@@ -110,6 +112,11 @@ const menuItems = computed<ItemType[]>(() => [
|
||||
label: '站点映射',
|
||||
icon: () => h(GlobalOutlined),
|
||||
},
|
||||
{
|
||||
key: '/desktop-client/releases',
|
||||
label: '客户端版本',
|
||||
icon: () => h(CloudDownloadOutlined),
|
||||
},
|
||||
{
|
||||
key: 'compliance',
|
||||
label: '内容安全',
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { http } from '@/lib/http'
|
||||
|
||||
export type DesktopReleasePlatform = 'darwin' | 'win32' | 'linux'
|
||||
export type DesktopReleaseArch = 'universal' | 'x64' | 'arm64' | 'ia32'
|
||||
export type DesktopReleaseSource = 'oss' | 'custom'
|
||||
|
||||
export interface DesktopClientRelease {
|
||||
id: number
|
||||
platform: DesktopReleasePlatform
|
||||
arch: DesktopReleaseArch
|
||||
channel: string
|
||||
version: string
|
||||
min_supported_version?: string | null
|
||||
download_source: DesktopReleaseSource
|
||||
oss_object_key?: string | null
|
||||
custom_download_url?: string | null
|
||||
download_url?: string | null
|
||||
file_name?: string | null
|
||||
file_size_bytes?: number | null
|
||||
sha256?: string | null
|
||||
updater_download_source?: DesktopReleaseSource | null
|
||||
updater_oss_object_key?: string | null
|
||||
updater_custom_download_url?: string | null
|
||||
updater_download_url?: string | null
|
||||
updater_file_name?: string | null
|
||||
updater_file_size_bytes?: number | null
|
||||
updater_sha256?: string | null
|
||||
release_notes?: string | null
|
||||
force_update: boolean
|
||||
enabled: boolean
|
||||
published_at?: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface DesktopClientReleasePayload {
|
||||
platform: DesktopReleasePlatform
|
||||
arch: DesktopReleaseArch
|
||||
channel: string
|
||||
version: string
|
||||
min_supported_version?: string | null
|
||||
download_source: DesktopReleaseSource
|
||||
oss_object_key?: string | null
|
||||
custom_download_url?: string | null
|
||||
file_name?: string | null
|
||||
file_size_bytes?: number | null
|
||||
sha256?: string | null
|
||||
updater_download_source?: DesktopReleaseSource | null
|
||||
updater_oss_object_key?: string | null
|
||||
updater_custom_download_url?: string | null
|
||||
updater_file_name?: string | null
|
||||
updater_file_size_bytes?: number | null
|
||||
updater_sha256?: string | null
|
||||
release_notes?: string | null
|
||||
force_update: boolean
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export interface DesktopClientReleaseList {
|
||||
items: DesktopClientRelease[]
|
||||
total: number
|
||||
page: number
|
||||
size: number
|
||||
}
|
||||
|
||||
export interface DesktopClientReleaseUploadResult {
|
||||
oss_object_key: string
|
||||
file_name: string
|
||||
file_size_bytes: number
|
||||
sha256: string
|
||||
}
|
||||
|
||||
export interface DesktopClientReleaseDownloadURLResult {
|
||||
download_url: string
|
||||
expires_in?: number | null
|
||||
}
|
||||
|
||||
export const platformOptions = [
|
||||
{ label: 'macOS', value: 'darwin' },
|
||||
{ label: 'Windows', value: 'win32' },
|
||||
{ label: 'Linux', value: 'linux' },
|
||||
]
|
||||
|
||||
export const archOptions = [
|
||||
{ label: 'Universal', value: 'universal' },
|
||||
{ label: 'x64', value: 'x64' },
|
||||
{ label: 'arm64', value: 'arm64' },
|
||||
{ label: 'ia32', value: 'ia32' },
|
||||
]
|
||||
|
||||
export const desktopClientReleaseApi = {
|
||||
list(params: {
|
||||
keyword?: string
|
||||
platform?: string
|
||||
channel?: string
|
||||
enabled?: string
|
||||
page?: number
|
||||
size?: number
|
||||
}) {
|
||||
return http.get<DesktopClientReleaseList>('/desktop-client/releases', params)
|
||||
},
|
||||
create(payload: DesktopClientReleasePayload) {
|
||||
return http.post<DesktopClientRelease, DesktopClientReleasePayload>(
|
||||
'/desktop-client/releases',
|
||||
payload,
|
||||
)
|
||||
},
|
||||
update(id: number, payload: DesktopClientReleasePayload) {
|
||||
return http.patch<DesktopClientRelease, DesktopClientReleasePayload>(
|
||||
`/desktop-client/releases/${id}`,
|
||||
payload,
|
||||
)
|
||||
},
|
||||
setEnabled(id: number, enabled: boolean) {
|
||||
return http.post<DesktopClientRelease, { enabled: boolean }>(
|
||||
`/desktop-client/releases/${id}/enabled`,
|
||||
{ enabled },
|
||||
)
|
||||
},
|
||||
async uploadOSS(
|
||||
file: File,
|
||||
target: {
|
||||
platform: string
|
||||
arch: string
|
||||
channel: string
|
||||
version: string
|
||||
kind?: 'installer' | 'updater'
|
||||
},
|
||||
) {
|
||||
const form = new FormData()
|
||||
form.append('file', file, file.name)
|
||||
form.append('platform', target.platform)
|
||||
form.append('arch', target.arch)
|
||||
form.append('channel', target.channel)
|
||||
form.append('version', target.version)
|
||||
form.append('kind', target.kind ?? 'installer')
|
||||
const response = await http.raw.post<{
|
||||
code: number
|
||||
message: string
|
||||
data: DesktopClientReleaseUploadResult
|
||||
}>('/desktop-client/releases/upload', form)
|
||||
return response.data.data
|
||||
},
|
||||
resolveDownloadURL(id: number) {
|
||||
return http.get<DesktopClientReleaseDownloadURLResult>(
|
||||
`/desktop-client/releases/${id}/download-url`,
|
||||
)
|
||||
},
|
||||
delete(id: number) {
|
||||
return http.delete<{ id: number }>(`/desktop-client/releases/${id}`)
|
||||
},
|
||||
}
|
||||
|
||||
export function platformLabel(value: string): string {
|
||||
return platformOptions.find((item) => item.value === value)?.label ?? value
|
||||
}
|
||||
@@ -57,7 +57,8 @@ const client: AxiosInstance = axios.create({
|
||||
|
||||
function isLoginRequest(url: string | undefined, method: string | undefined): boolean {
|
||||
return (
|
||||
method?.toLowerCase() === 'post' && (url === '/auth/login' || Boolean(url?.endsWith('/auth/login')))
|
||||
method?.toLowerCase() === 'post' &&
|
||||
(url === '/auth/login' || Boolean(url?.endsWith('/auth/login')))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -117,4 +118,5 @@ export const http = {
|
||||
put: <T, B = unknown>(url: string, body?: B) => unwrap<T>(client.put(url, body)),
|
||||
patch: <T, B = unknown>(url: string, body?: B) => unwrap<T>(client.patch(url, body)),
|
||||
delete: <T>(url: string) => unwrap<T>(client.delete(url)),
|
||||
raw: client,
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
Popconfirm,
|
||||
Radio,
|
||||
Result,
|
||||
Segmented,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
@@ -32,6 +33,7 @@ import {
|
||||
Tabs,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Upload,
|
||||
message,
|
||||
} from 'ant-design-vue'
|
||||
import { createApp } from 'vue'
|
||||
@@ -95,6 +97,7 @@ bindUnauthorizedHandler(() => {
|
||||
Radio,
|
||||
Result,
|
||||
Select,
|
||||
Segmented,
|
||||
Space,
|
||||
Spin,
|
||||
Statistic,
|
||||
@@ -103,6 +106,7 @@ bindUnauthorizedHandler(() => {
|
||||
Tabs,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Upload,
|
||||
].forEach((component) => {
|
||||
app.use(component)
|
||||
})
|
||||
|
||||
@@ -61,6 +61,12 @@ export const router = createRouter({
|
||||
component: () => import('@/views/SiteDomainMappingsView.vue'),
|
||||
meta: { title: '站点映射' },
|
||||
},
|
||||
{
|
||||
path: 'desktop-client/releases',
|
||||
name: 'desktop-client-releases',
|
||||
component: () => import('@/views/DesktopClientReleasesView.vue'),
|
||||
meta: { title: '客户端版本' },
|
||||
},
|
||||
{
|
||||
path: 'compliance/policy',
|
||||
name: 'compliance-policy',
|
||||
|
||||
@@ -0,0 +1,986 @@
|
||||
<template>
|
||||
<div class="release-page">
|
||||
<div class="release-header">
|
||||
<div>
|
||||
<h2 class="ops-page-title release-title">客户端版本</h2>
|
||||
<div class="release-summary">
|
||||
<span>全部 {{ total }}</span>
|
||||
<span>本页启用 {{ enabledRows }}</span>
|
||||
<span>强制更新 {{ forceRows }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<a-button type="primary" @click="openCreate">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
新增版本
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<div class="ops-card release-card">
|
||||
<div class="ops-toolbar release-toolbar">
|
||||
<a-input
|
||||
v-model:value="filter.keyword"
|
||||
class="release-search"
|
||||
placeholder="搜索版本 / Object Key / 下载地址"
|
||||
allow-clear
|
||||
@press-enter="resetAndReload"
|
||||
@change="onKeywordChange"
|
||||
/>
|
||||
<a-select
|
||||
v-model:value="filter.platform"
|
||||
class="release-select"
|
||||
:options="platformOptions"
|
||||
placeholder="平台"
|
||||
allow-clear
|
||||
@change="resetAndReload"
|
||||
/>
|
||||
<a-input
|
||||
v-model:value="filter.channel"
|
||||
class="release-channel"
|
||||
placeholder="渠道 stable"
|
||||
allow-clear
|
||||
@press-enter="resetAndReload"
|
||||
/>
|
||||
<a-select
|
||||
v-model:value="filter.enabled"
|
||||
class="release-enabled"
|
||||
:options="enabledOptions"
|
||||
placeholder="状态"
|
||||
allow-clear
|
||||
@change="resetAndReload"
|
||||
/>
|
||||
<a-button @click="reload">
|
||||
<template #icon><ReloadOutlined /></template>
|
||||
刷新
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1280 }"
|
||||
@change="onTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'target'">
|
||||
<div class="target-cell">
|
||||
<strong>{{ platformLabel(record.platform) }}</strong>
|
||||
<span>{{ record.arch }} · {{ record.channel }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'version'">
|
||||
<div class="version-cell">
|
||||
<strong>{{ record.version }}</strong>
|
||||
<span v-if="record.min_supported_version">
|
||||
最低 {{ record.min_supported_version }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'source'">
|
||||
<div class="source-stack">
|
||||
<div class="source-asset">
|
||||
<a-tag :color="record.download_source === 'oss' ? 'blue' : 'gold'">
|
||||
官网 {{ record.download_source === 'oss' ? 'OSS' : '自定义' }}
|
||||
</a-tag>
|
||||
<span>{{ assetTargetText(record, 'installer') }}</span>
|
||||
</div>
|
||||
<div class="source-asset">
|
||||
<a-tag :color="updaterAssetConfigured(record) ? 'purple' : 'default'">
|
||||
更新 {{ updaterSourceText(record) }}
|
||||
</a-tag>
|
||||
<span>{{ assetTargetText(record, 'updater') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'policy'">
|
||||
<a-space size="small">
|
||||
<a-tag :color="record.enabled ? 'green' : 'default'">
|
||||
{{ record.enabled ? '启用' : '停用' }}
|
||||
</a-tag>
|
||||
<a-tag v-if="record.force_update" color="red">强更</a-tag>
|
||||
</a-space>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'updated_at'">
|
||||
{{ formatDate(record.updated_at) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<div class="table-actions-row" style="justify-content: flex-end">
|
||||
<a-tooltip title="复制最终下载地址">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn"
|
||||
@click="copyDownloadURL(record)"
|
||||
>
|
||||
<LinkOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip title="编辑">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click="openEdit(record)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip :title="record.enabled ? '停用' : '启用'">
|
||||
<a-switch
|
||||
size="small"
|
||||
:checked="record.enabled"
|
||||
:loading="statusLoadingId === record.id"
|
||||
@change="onEnabledSwitchChange(record, $event)"
|
||||
/>
|
||||
</a-tooltip>
|
||||
<a-tooltip title="删除">
|
||||
<a-popconfirm title="确认删除该客户端版本配置?" @confirm="deleteRelease(record)">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-tooltip>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
|
||||
<a-drawer
|
||||
v-model:open="drawerOpen"
|
||||
:title="editingRow ? '编辑客户端版本' : '新增客户端版本'"
|
||||
width="620"
|
||||
:destroy-on-close="true"
|
||||
@close="closeDrawer"
|
||||
>
|
||||
<a-form layout="vertical" :model="form">
|
||||
<div class="form-grid">
|
||||
<a-form-item label="平台" required>
|
||||
<a-select v-model:value="form.platform" :options="platformOptions" />
|
||||
</a-form-item>
|
||||
<a-form-item label="架构" required>
|
||||
<a-select v-model:value="form.arch" :options="archOptions" />
|
||||
</a-form-item>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<a-form-item label="渠道" required>
|
||||
<a-input v-model:value="form.channel" placeholder="stable" />
|
||||
</a-form-item>
|
||||
<a-form-item label="最新版本" required>
|
||||
<a-input v-model:value="form.version" placeholder="0.1.0" />
|
||||
</a-form-item>
|
||||
</div>
|
||||
<a-form-item label="最低支持版本">
|
||||
<a-input v-model:value="form.min_supported_version" placeholder="低于该版本将强制更新" />
|
||||
</a-form-item>
|
||||
|
||||
<section class="asset-section">
|
||||
<div class="asset-section-head">
|
||||
<div>
|
||||
<h3>官网安装包</h3>
|
||||
<p>installer</p>
|
||||
</div>
|
||||
</div>
|
||||
<a-form-item label="下载来源" required>
|
||||
<a-segmented v-model:value="form.download_source" :options="sourceOptions" />
|
||||
</a-form-item>
|
||||
<template v-if="form.download_source === 'oss'">
|
||||
<a-form-item label="上传安装包" required>
|
||||
<a-upload
|
||||
:before-upload="beforeUploadInstallerPackage"
|
||||
:show-upload-list="false"
|
||||
accept=".dmg,.pkg,.exe,.msi,.zip,.AppImage,.appimage,.deb,.rpm,.tar.gz,.tgz"
|
||||
>
|
||||
<a-button :loading="uploading">
|
||||
<template #icon><UploadOutlined /></template>
|
||||
{{ form.oss_object_key ? '重新上传' : '选择文件并上传' }}
|
||||
</a-button>
|
||||
</a-upload>
|
||||
<div v-if="form.file_name" class="upload-result">
|
||||
<strong>{{ form.file_name }}</strong>
|
||||
<span>{{ formatBytes(form.file_size_bytes) }}</span>
|
||||
<a v-if="canCopyFormDownloadURL" href="#" @click.prevent="copyFormDownloadURL">
|
||||
复制下载地址
|
||||
</a>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="OSS Object Key">
|
||||
<a-input
|
||||
v-model:value="form.oss_object_key"
|
||||
placeholder="上传后自动生成,可手动填已有对象作为兜底"
|
||||
/>
|
||||
</a-form-item>
|
||||
</template>
|
||||
<a-form-item v-else label="自定义下载地址" required>
|
||||
<a-input
|
||||
v-model:value="form.custom_download_url"
|
||||
placeholder="https://download.example.com/desktop/app.exe"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<div class="form-grid">
|
||||
<a-form-item label="文件名">
|
||||
<a-input v-model:value="form.file_name" placeholder="可选" />
|
||||
</a-form-item>
|
||||
<a-form-item label="文件大小 Bytes">
|
||||
<a-input-number
|
||||
v-model:value="form.file_size_bytes"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
placeholder="可选"
|
||||
/>
|
||||
</a-form-item>
|
||||
</div>
|
||||
<a-form-item label="SHA256">
|
||||
<a-input v-model:value="form.sha256" placeholder="64 位十六进制,可选" />
|
||||
</a-form-item>
|
||||
</section>
|
||||
|
||||
<section class="asset-section">
|
||||
<div class="asset-section-head">
|
||||
<div>
|
||||
<h3>自动更新包</h3>
|
||||
<p>updater</p>
|
||||
</div>
|
||||
<a-button size="small" @click="reuseInstallerForUpdater">复用官网包</a-button>
|
||||
</div>
|
||||
<a-form-item label="更新来源">
|
||||
<a-segmented
|
||||
v-model:value="form.updater_download_source"
|
||||
:options="updaterSourceOptions"
|
||||
/>
|
||||
</a-form-item>
|
||||
<template v-if="form.updater_download_source === 'oss'">
|
||||
<a-form-item label="上传更新包">
|
||||
<a-upload
|
||||
:before-upload="beforeUploadUpdaterPackage"
|
||||
:show-upload-list="false"
|
||||
accept=".zip,.exe,.AppImage,.appimage"
|
||||
>
|
||||
<a-button :loading="updaterUploading">
|
||||
<template #icon><UploadOutlined /></template>
|
||||
{{ form.updater_oss_object_key ? '重新上传' : '选择文件并上传' }}
|
||||
</a-button>
|
||||
</a-upload>
|
||||
<div v-if="form.updater_file_name" class="upload-result">
|
||||
<strong>{{ form.updater_file_name }}</strong>
|
||||
<span>{{ formatBytes(form.updater_file_size_bytes) }}</span>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="更新包 OSS Object Key">
|
||||
<a-input
|
||||
v-model:value="form.updater_oss_object_key"
|
||||
placeholder="可复用官网包 Object Key,也可上传后自动生成"
|
||||
/>
|
||||
</a-form-item>
|
||||
</template>
|
||||
<a-form-item v-else-if="form.updater_download_source === 'custom'" label="更新包自定义地址">
|
||||
<a-input
|
||||
v-model:value="form.updater_custom_download_url"
|
||||
placeholder="https://download.example.com/desktop/app.zip"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-alert
|
||||
v-else
|
||||
type="info"
|
||||
show-icon
|
||||
message="复用官网安装包"
|
||||
/>
|
||||
|
||||
<div v-if="form.updater_download_source !== ''" class="form-grid">
|
||||
<a-form-item label="更新包文件名">
|
||||
<a-input v-model:value="form.updater_file_name" placeholder="可选" />
|
||||
</a-form-item>
|
||||
<a-form-item label="更新包大小 Bytes">
|
||||
<a-input-number
|
||||
v-model:value="form.updater_file_size_bytes"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
placeholder="可选"
|
||||
/>
|
||||
</a-form-item>
|
||||
</div>
|
||||
<a-form-item v-if="form.updater_download_source !== ''" label="更新包 SHA256" required>
|
||||
<a-input v-model:value="form.updater_sha256" placeholder="64 位十六进制" />
|
||||
</a-form-item>
|
||||
</section>
|
||||
|
||||
<a-form-item label="发布说明">
|
||||
<a-textarea v-model:value="form.release_notes" :rows="4" placeholder="可选" />
|
||||
</a-form-item>
|
||||
<div class="switch-row">
|
||||
<a-checkbox v-model:checked="form.force_update">强制更新</a-checkbox>
|
||||
<a-checkbox v-model:checked="form.enabled">启用该版本</a-checkbox>
|
||||
</div>
|
||||
</a-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="drawer-footer">
|
||||
<a-button @click="closeDrawer">取消</a-button>
|
||||
<a-button type="primary" :loading="saving" @click="submitForm">保存</a-button>
|
||||
</div>
|
||||
</template>
|
||||
</a-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
LinkOutlined,
|
||||
PlusOutlined,
|
||||
ReloadOutlined,
|
||||
UploadOutlined,
|
||||
} from '@ant-design/icons-vue'
|
||||
import type { TablePaginationConfig } from 'ant-design-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
|
||||
import {
|
||||
archOptions,
|
||||
desktopClientReleaseApi,
|
||||
platformLabel,
|
||||
platformOptions,
|
||||
type DesktopClientRelease,
|
||||
type DesktopReleaseArch,
|
||||
type DesktopReleasePlatform,
|
||||
type DesktopReleaseSource,
|
||||
} from '@/lib/desktop-client-releases'
|
||||
import { showOpsError } from '@/lib/errors'
|
||||
|
||||
const enabledOptions = [
|
||||
{ label: '启用', value: 'true' },
|
||||
{ label: '停用', value: 'false' },
|
||||
]
|
||||
|
||||
const sourceOptions = [
|
||||
{ label: 'OSS 自动地址', value: 'oss' },
|
||||
{ label: '自定义地址', value: 'custom' },
|
||||
]
|
||||
|
||||
const updaterSourceOptions = [
|
||||
{ label: '复用/不单独配置', value: '' },
|
||||
{ label: 'OSS 自动地址', value: 'oss' },
|
||||
{ label: '自定义地址', value: 'custom' },
|
||||
]
|
||||
|
||||
const columns = [
|
||||
{ title: '目标', key: 'target', width: 190 },
|
||||
{ title: '版本', key: 'version', width: 170 },
|
||||
{ title: '下载来源', key: 'source', width: 420 },
|
||||
{ title: '策略', key: 'policy', width: 150 },
|
||||
{ title: '更新时间', key: 'updated_at', width: 180 },
|
||||
{ title: '操作', key: 'actions', width: 190, align: 'right' as const },
|
||||
]
|
||||
|
||||
const filter = reactive({
|
||||
keyword: '',
|
||||
platform: undefined as string | undefined,
|
||||
channel: '',
|
||||
enabled: undefined as string | undefined,
|
||||
})
|
||||
|
||||
const rows = ref<DesktopClientRelease[]>([])
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const size = ref(20)
|
||||
const total = ref(0)
|
||||
const statusLoadingId = ref<number | null>(null)
|
||||
const uploading = ref(false)
|
||||
const updaterUploading = ref(false)
|
||||
|
||||
const enabledRows = computed(() => rows.value.filter((row) => row.enabled).length)
|
||||
const forceRows = computed(() => rows.value.filter((row) => row.force_update).length)
|
||||
const pagination = computed<TablePaginationConfig>(() => ({
|
||||
current: page.value,
|
||||
pageSize: size.value,
|
||||
total: total.value,
|
||||
showSizeChanger: true,
|
||||
pageSizeOptions: ['10', '20', '50', '100'],
|
||||
}))
|
||||
|
||||
let keywordTimer: number | null = null
|
||||
|
||||
function onKeywordChange() {
|
||||
if (keywordTimer) window.clearTimeout(keywordTimer)
|
||||
keywordTimer = window.setTimeout(() => {
|
||||
resetAndReload()
|
||||
}, 300)
|
||||
}
|
||||
|
||||
function resetAndReload() {
|
||||
page.value = 1
|
||||
void reload()
|
||||
}
|
||||
|
||||
async function reload() {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await desktopClientReleaseApi.list({
|
||||
keyword: filter.keyword || undefined,
|
||||
platform: filter.platform || undefined,
|
||||
channel: filter.channel || undefined,
|
||||
enabled: filter.enabled || undefined,
|
||||
page: page.value,
|
||||
size: size.value,
|
||||
})
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
} catch (error) {
|
||||
showOpsError(error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onTableChange(pag: TablePaginationConfig) {
|
||||
page.value = pag.current ?? 1
|
||||
size.value = pag.pageSize ?? 20
|
||||
void reload()
|
||||
}
|
||||
|
||||
const drawerOpen = ref(false)
|
||||
const saving = ref(false)
|
||||
const editingRow = ref<DesktopClientRelease | null>(null)
|
||||
const form = reactive({
|
||||
platform: 'darwin' as DesktopReleasePlatform,
|
||||
arch: 'universal' as DesktopReleaseArch,
|
||||
channel: 'stable',
|
||||
version: '',
|
||||
min_supported_version: '',
|
||||
download_source: 'oss' as DesktopReleaseSource,
|
||||
oss_object_key: '',
|
||||
custom_download_url: '',
|
||||
download_url: '',
|
||||
file_name: '',
|
||||
file_size_bytes: undefined as number | undefined,
|
||||
sha256: '',
|
||||
updater_download_source: '' as '' | DesktopReleaseSource,
|
||||
updater_oss_object_key: '',
|
||||
updater_custom_download_url: '',
|
||||
updater_file_name: '',
|
||||
updater_file_size_bytes: undefined as number | undefined,
|
||||
updater_sha256: '',
|
||||
release_notes: '',
|
||||
force_update: false,
|
||||
enabled: true,
|
||||
})
|
||||
const canCopyFormDownloadURL = computed(
|
||||
() => Boolean(editingRow.value?.id) || Boolean(form.download_url.trim()),
|
||||
)
|
||||
|
||||
watch(
|
||||
() => form.download_source,
|
||||
(source) => {
|
||||
if (source === 'oss') {
|
||||
form.custom_download_url = ''
|
||||
} else {
|
||||
form.oss_object_key = ''
|
||||
form.download_url = ''
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => form.updater_download_source,
|
||||
(source) => {
|
||||
if (source === 'oss') {
|
||||
form.updater_custom_download_url = ''
|
||||
} else if (source === 'custom') {
|
||||
form.updater_oss_object_key = ''
|
||||
} else {
|
||||
clearUpdaterAsset()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
function resetForm() {
|
||||
form.platform = 'darwin'
|
||||
form.arch = 'universal'
|
||||
form.channel = 'stable'
|
||||
form.version = ''
|
||||
form.min_supported_version = ''
|
||||
form.download_source = 'oss'
|
||||
form.oss_object_key = ''
|
||||
form.custom_download_url = ''
|
||||
form.download_url = ''
|
||||
form.file_name = ''
|
||||
form.file_size_bytes = undefined
|
||||
form.sha256 = ''
|
||||
clearUpdaterAsset()
|
||||
form.release_notes = ''
|
||||
form.force_update = false
|
||||
form.enabled = true
|
||||
editingRow.value = null
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
resetForm()
|
||||
drawerOpen.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: DesktopClientRelease) {
|
||||
editingRow.value = row
|
||||
form.platform = row.platform
|
||||
form.arch = row.arch
|
||||
form.channel = row.channel
|
||||
form.version = row.version
|
||||
form.min_supported_version = row.min_supported_version ?? ''
|
||||
form.download_source = row.download_source
|
||||
form.oss_object_key = row.oss_object_key ?? ''
|
||||
form.custom_download_url = row.custom_download_url ?? ''
|
||||
form.download_url = row.download_url ?? ''
|
||||
form.file_name = row.file_name ?? ''
|
||||
form.file_size_bytes = row.file_size_bytes ?? undefined
|
||||
form.sha256 = row.sha256 ?? ''
|
||||
form.updater_download_source = row.updater_download_source ?? ''
|
||||
form.updater_oss_object_key = row.updater_oss_object_key ?? ''
|
||||
form.updater_custom_download_url = row.updater_custom_download_url ?? ''
|
||||
form.updater_file_name = row.updater_file_name ?? ''
|
||||
form.updater_file_size_bytes = row.updater_file_size_bytes ?? undefined
|
||||
form.updater_sha256 = row.updater_sha256 ?? ''
|
||||
form.release_notes = row.release_notes ?? ''
|
||||
form.force_update = row.force_update
|
||||
form.enabled = row.enabled
|
||||
drawerOpen.value = true
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
drawerOpen.value = false
|
||||
}
|
||||
|
||||
async function beforeUploadReleasePackage(file: File, kind: 'installer' | 'updater') {
|
||||
if (!form.version.trim()) {
|
||||
message.warning('请先填写最新版本')
|
||||
return false
|
||||
}
|
||||
if (kind === 'installer') {
|
||||
uploading.value = true
|
||||
} else {
|
||||
updaterUploading.value = true
|
||||
}
|
||||
try {
|
||||
const result = await desktopClientReleaseApi.uploadOSS(file, {
|
||||
platform: form.platform,
|
||||
arch: form.arch,
|
||||
channel: form.channel.trim() || 'stable',
|
||||
version: form.version.trim(),
|
||||
kind,
|
||||
})
|
||||
if (kind === 'installer') {
|
||||
form.oss_object_key = result.oss_object_key
|
||||
form.download_url = ''
|
||||
form.file_name = result.file_name
|
||||
form.file_size_bytes = result.file_size_bytes
|
||||
form.sha256 = result.sha256
|
||||
} else {
|
||||
form.updater_download_source = 'oss'
|
||||
form.updater_oss_object_key = result.oss_object_key
|
||||
form.updater_custom_download_url = ''
|
||||
form.updater_file_name = result.file_name
|
||||
form.updater_file_size_bytes = result.file_size_bytes
|
||||
form.updater_sha256 = result.sha256
|
||||
}
|
||||
message.success(kind === 'installer' ? '安装包已上传到 OSS' : '自动更新包已上传到 OSS')
|
||||
} catch (error) {
|
||||
showOpsError(error)
|
||||
} finally {
|
||||
uploading.value = false
|
||||
updaterUploading.value = false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function beforeUploadInstallerPackage(file: File) {
|
||||
return beforeUploadReleasePackage(file, 'installer')
|
||||
}
|
||||
|
||||
function beforeUploadUpdaterPackage(file: File) {
|
||||
return beforeUploadReleasePackage(file, 'updater')
|
||||
}
|
||||
|
||||
function clearUpdaterAsset() {
|
||||
form.updater_download_source = ''
|
||||
form.updater_oss_object_key = ''
|
||||
form.updater_custom_download_url = ''
|
||||
form.updater_file_name = ''
|
||||
form.updater_file_size_bytes = undefined
|
||||
form.updater_sha256 = ''
|
||||
}
|
||||
|
||||
function reuseInstallerForUpdater() {
|
||||
form.updater_download_source = form.download_source
|
||||
form.updater_oss_object_key = form.download_source === 'oss' ? form.oss_object_key : ''
|
||||
form.updater_custom_download_url =
|
||||
form.download_source === 'custom' ? form.custom_download_url : ''
|
||||
form.updater_file_name = form.file_name
|
||||
form.updater_file_size_bytes = form.file_size_bytes
|
||||
form.updater_sha256 = form.sha256
|
||||
message.success('已复用官网安装包配置')
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!form.version.trim()) {
|
||||
message.warning('请输入最新版本')
|
||||
return
|
||||
}
|
||||
if (form.download_source === 'oss' && !form.oss_object_key.trim()) {
|
||||
message.warning('请输入 OSS Object Key')
|
||||
return
|
||||
}
|
||||
if (form.download_source === 'custom' && !form.custom_download_url.trim()) {
|
||||
message.warning('请输入自定义下载地址')
|
||||
return
|
||||
}
|
||||
if (form.updater_download_source === 'oss' && !form.updater_oss_object_key.trim()) {
|
||||
message.warning('请输入更新包 OSS Object Key')
|
||||
return
|
||||
}
|
||||
if (form.updater_download_source === 'custom' && !form.updater_custom_download_url.trim()) {
|
||||
message.warning('请输入更新包自定义地址')
|
||||
return
|
||||
}
|
||||
if (form.updater_download_source !== '' && !form.updater_sha256.trim()) {
|
||||
message.warning('请输入更新包 SHA256')
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = {
|
||||
platform: form.platform,
|
||||
arch: form.arch,
|
||||
channel: form.channel.trim() || 'stable',
|
||||
version: form.version.trim(),
|
||||
min_supported_version: nullableText(form.min_supported_version),
|
||||
download_source: form.download_source,
|
||||
oss_object_key: form.download_source === 'oss' ? nullableText(form.oss_object_key) : null,
|
||||
custom_download_url:
|
||||
form.download_source === 'custom' ? nullableText(form.custom_download_url) : null,
|
||||
file_name: nullableText(form.file_name),
|
||||
file_size_bytes: form.file_size_bytes ?? null,
|
||||
sha256: nullableText(form.sha256),
|
||||
updater_download_source: form.updater_download_source || null,
|
||||
updater_oss_object_key:
|
||||
form.updater_download_source === 'oss' ? nullableText(form.updater_oss_object_key) : null,
|
||||
updater_custom_download_url:
|
||||
form.updater_download_source === 'custom'
|
||||
? nullableText(form.updater_custom_download_url)
|
||||
: null,
|
||||
updater_file_name:
|
||||
form.updater_download_source !== '' ? nullableText(form.updater_file_name) : null,
|
||||
updater_file_size_bytes:
|
||||
form.updater_download_source !== '' ? (form.updater_file_size_bytes ?? null) : null,
|
||||
updater_sha256:
|
||||
form.updater_download_source !== '' ? nullableText(form.updater_sha256) : null,
|
||||
release_notes: nullableText(form.release_notes),
|
||||
force_update: form.force_update,
|
||||
enabled: form.enabled,
|
||||
}
|
||||
if (editingRow.value) {
|
||||
await desktopClientReleaseApi.update(editingRow.value.id, payload)
|
||||
message.success('已保存客户端版本')
|
||||
} else {
|
||||
await desktopClientReleaseApi.create(payload)
|
||||
message.success('已新增客户端版本')
|
||||
}
|
||||
drawerOpen.value = false
|
||||
resetForm()
|
||||
void reload()
|
||||
} catch (error) {
|
||||
showOpsError(error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function nullableText(value: string): string | null {
|
||||
const trimmed = value.trim()
|
||||
return trimmed ? trimmed : null
|
||||
}
|
||||
|
||||
function updaterAssetConfigured(row: DesktopClientRelease): boolean {
|
||||
return Boolean(row.updater_download_source)
|
||||
}
|
||||
|
||||
function updaterSourceText(row: DesktopClientRelease): string {
|
||||
if (!row.updater_download_source) {
|
||||
return '复用官网'
|
||||
}
|
||||
return row.updater_download_source === 'oss' ? 'OSS' : '自定义'
|
||||
}
|
||||
|
||||
function assetTargetText(
|
||||
row: DesktopClientRelease,
|
||||
kind: 'installer' | 'updater',
|
||||
): string {
|
||||
if (kind === 'installer' || !row.updater_download_source) {
|
||||
return row.download_source === 'oss'
|
||||
? (row.oss_object_key ?? '未配置')
|
||||
: (row.custom_download_url ?? '未配置')
|
||||
}
|
||||
return row.updater_download_source === 'oss'
|
||||
? (row.updater_oss_object_key ?? '未配置')
|
||||
: (row.updater_custom_download_url ?? '未配置')
|
||||
}
|
||||
|
||||
async function setEnabled(row: DesktopClientRelease, enabled: boolean) {
|
||||
statusLoadingId.value = row.id
|
||||
try {
|
||||
const next = await desktopClientReleaseApi.setEnabled(row.id, enabled)
|
||||
Object.assign(row, next)
|
||||
message.success(enabled ? '已启用' : '已停用')
|
||||
} catch (error) {
|
||||
showOpsError(error)
|
||||
} finally {
|
||||
statusLoadingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function onEnabledSwitchChange(row: DesktopClientRelease, checked: unknown) {
|
||||
void setEnabled(row, Boolean(checked))
|
||||
}
|
||||
|
||||
async function deleteRelease(row: DesktopClientRelease) {
|
||||
try {
|
||||
await desktopClientReleaseApi.delete(row.id)
|
||||
message.success('已删除')
|
||||
void reload()
|
||||
} catch (error) {
|
||||
showOpsError(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function copyDownloadURL(row: DesktopClientRelease) {
|
||||
try {
|
||||
const result = await desktopClientReleaseApi.resolveDownloadURL(row.id)
|
||||
await navigator.clipboard.writeText(result.download_url)
|
||||
message.success('下载地址已复制')
|
||||
} catch (error) {
|
||||
showOpsError(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function copyFormDownloadURL() {
|
||||
if (form.download_url) {
|
||||
await navigator.clipboard.writeText(form.download_url)
|
||||
message.success('下载地址已复制')
|
||||
return
|
||||
}
|
||||
if (!editingRow.value?.id) return
|
||||
await copyDownloadURL(editingRow.value)
|
||||
}
|
||||
|
||||
function formatDate(value: string | null | undefined): string {
|
||||
return value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '—'
|
||||
}
|
||||
|
||||
function formatBytes(value: number | null | undefined): string {
|
||||
if (!value) return '0 B'
|
||||
if (value < 1024) return `${value} B`
|
||||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`
|
||||
if (value < 1024 * 1024 * 1024) return `${(value / 1024 / 1024).toFixed(1)} MB`
|
||||
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void reload()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.release-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.release-header {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.release-title {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.release-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
color: #64748b;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.release-summary span {
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.release-card {
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.release-toolbar {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.release-search {
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
.release-select,
|
||||
.release-enabled {
|
||||
width: 140px;
|
||||
}
|
||||
|
||||
.release-channel {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.target-cell,
|
||||
.version-cell {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.target-cell strong,
|
||||
.version-cell strong {
|
||||
color: #0f172a;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.target-cell span,
|
||||
.version-cell span {
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.source-stack {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.source-asset {
|
||||
display: grid;
|
||||
min-width: 0;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.source-asset span {
|
||||
overflow: hidden;
|
||||
max-width: 360px;
|
||||
color: #64748b;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.asset-section {
|
||||
margin: 16px 0;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
padding: 14px 14px 4px;
|
||||
}
|
||||
|
||||
.asset-section-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.asset-section-head h3 {
|
||||
margin: 0 0 4px;
|
||||
color: #0f172a;
|
||||
font-size: 15px;
|
||||
font-weight: 750;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.asset-section-head p {
|
||||
margin: 0;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.switch-row {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.upload-result {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.upload-result strong {
|
||||
color: #0f172a;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.upload-result a {
|
||||
color: #1677ff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.drawer-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.release-header {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.release-search,
|
||||
.release-select,
|
||||
.release-channel,
|
||||
.release-enabled {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user