feat: localize app update management

This commit is contained in:
biss committed 2026-10-31 11:56:22 +08:00
1 parent 76c21b39b1
commit 5199dde008
3 files changed
+53 -65

No files matched your search

+51 -65
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import type { UploadFile, UploadFiles } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Refresh, UploadFilled } from '@element-plus/icons-vue'
@@ -34,6 +35,7 @@ interface PageResult<T> {
}
const loading = ref(false)
const { locale, t } = useI18n()
const uploadBusy = ref(false)
const rows = ref<AppUpdateRelease[]>([])
const cursors = ref<string[]>([])
@@ -58,7 +60,7 @@ const form = reactive({
function formatTime(value?: string) {
if (!value) return '—'
return new Date(value).toLocaleString('zh-CN', { hour12: false })
return new Date(value).toLocaleString(locale.value, { hour12: false })
}
function formatBytes(value: number) {
@@ -72,15 +74,11 @@ function platformLabel(value: UpdatePlatform) {
}
function channelLabel(value: UpdateChannel) {
return value === 'Production' ? '正式' : '测试'
return t(`appUpdates.channels.${value}`)
}
function statusLabel(value: UpdateStatus) {
return value === 'Published'
? '已发布'
: value === 'Archived'
? '已归档'
: '草稿'
return t(`appUpdates.statuses.${value}`)
}
function statusType(value: UpdateStatus) {
@@ -160,11 +158,11 @@ function handleBundleRemove() {
async function uploadRelease() {
if (!selectedBundle.value) {
ElMessage.warning('请选择更新 ZIP。')
ElMessage.warning(t('appUpdates.messages.selectZip'))
return
}
if (!form.version.trim() || !form.nativeVersion.trim()) {
ElMessage.warning('请填写热更新版本和兼容的原生版本。')
ElMessage.warning(t('appUpdates.messages.versionRequired'))
return
}
@@ -181,7 +179,7 @@ async function uploadRelease() {
await http.post('/app-updates/releases', body, {
timeout: 10 * 60 * 1000,
})
ElMessage.success('更新包已上传为草稿,确认无误后再发布。')
ElMessage.success(t('appUpdates.messages.uploaded'))
uploadVisible.value = false
await loadReleases()
} catch (error) {
@@ -197,17 +195,16 @@ async function publishRelease(tableRow: Record<string, unknown>) {
try {
await ElMessageBox.confirm(
isRollback
? `将把 ${platformLabel(row.platform)} ${row.nativeVersion} 的正式通道回滚到 ${row.version}。新启动的 App 将下载此版本。`
: `确认发布 ${row.version}?同平台、通道和原生版本下当前生效的更新将自动归档。`,
isRollback ? '确认版本回滚' : '确认发布更新',
? t('appUpdates.messages.rollbackConfirm', { platform: platformLabel(row.platform), native: row.nativeVersion, version: row.version })
: t('appUpdates.messages.publishConfirm', { version: row.version }),
t(isRollback ? 'appUpdates.messages.rollbackTitle' : 'appUpdates.messages.publishTitle'),
{
type: isRollback ? 'warning' : 'info',
confirmButtonText: isRollback ? '确认回滚' : '发布',
cancelButtonText: '取消',
confirmButtonText: t(isRollback ? 'appUpdates.confirmRollback' : 'appUpdates.publish'), cancelButtonText: t('appUpdates.cancel'),
},
)
await http.post(`/app-updates/releases/${row.id}/publish`)
ElMessage.success(isRollback ? '已回滚到指定版本。' : '更新已发布。')
ElMessage.success(t(isRollback ? 'appUpdates.messages.rolledBack' : 'appUpdates.messages.published'))
await loadReleases()
} catch (error) {
if (error === 'cancel' || error === 'close') return
@@ -219,16 +216,14 @@ async function deleteRelease(tableRow: Record<string, unknown>) {
const row = tableRow as unknown as AppUpdateRelease
try {
await ElMessageBox.confirm(
`将永久删除 ${row.version} 的发布历史和 ZIP 更新包(${row.fileName})。此操作不会影响已安装到设备的版本,且不可恢复。`,
'删除更新包',
t('appUpdates.messages.deleteConfirm', { version: row.version, file: row.fileName }), t('appUpdates.messages.deleteTitle'),
{
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
confirmButtonText: t('appUpdates.delete'), cancelButtonText: t('appUpdates.cancel'),
},
)
await http.delete(`/app-updates/releases/${row.id}`)
ElMessage.success('发布历史和更新包已删除。')
ElMessage.success(t('appUpdates.messages.deleted'))
await loadReleases()
} catch (error) {
if (error === 'cancel' || error === 'close') return
@@ -244,72 +239,67 @@ onMounted(loadReleases)
<header class="update-heading">
<div>
<span>SELF-HOSTED OTA</span>
<h3>App 前端热更新</h3>
<p>上传构建后的 ZIP,按原生版本和通道发布;保留历史包用于快速回滚。</p>
<h3>{{ t('appUpdates.title') }}</h3><p>{{ t('appUpdates.description') }}</p>
</div>
<div class="heading-actions">
<el-button :icon="Refresh" :loading="loading" @click="loadReleases">
刷新
{{ t('appUpdates.refresh') }}
</el-button>
<el-button type="primary" :icon="UploadFilled" @click="openUpload">
上传更新包
{{ t('appUpdates.upload') }}
</el-button>
</div>
</header>
<div class="update-rules">
<strong>发布边界</strong>
<span>仅限 HTML、JavaScript、CSS 和静态资源</span>
<span>新增原生插件、权限或 Android/iOS 代码必须重新发版</span>
<span>更新失败时 App 自动回退到上一个可用版本</span>
<strong>{{ t('appUpdates.boundary') }}</strong><span>{{ t('appUpdates.webOnly') }}</span><span>{{ t('appUpdates.nativeBoundary') }}</span><span>{{ t('appUpdates.autoRollback') }}</span>
</div>
<div class="update-filter">
<el-select v-model="filter.platform" clearable placeholder="全部平台">
<el-select v-model="filter.platform" clearable :placeholder="t('appUpdates.allPlatforms')">
<el-option label="Android" value="Android" />
<el-option label="iOS" value="Ios" />
</el-select>
<el-select v-model="filter.channel" clearable placeholder="全部通道">
<el-option label="正式通道" value="Production" />
<el-option label="测试通道" value="Staging" />
<el-select v-model="filter.channel" clearable :placeholder="t('appUpdates.allChannels')">
<el-option :label="t('appUpdates.production')" value="Production" /><el-option :label="t('appUpdates.staging')" value="Staging" />
</el-select>
<el-button type="primary" @click="search">查询</el-button>
<el-button type="primary" @click="search">{{ t('appUpdates.search') }}</el-button>
</div>
<el-table v-loading="loading" :data="rows" stripe>
<el-table-column label="版本" min-width="142">
<el-table-column :label="t('appUpdates.version')" min-width="142">
<template #default="{ row }">
<strong class="version">{{ row.version }}</strong>
<small>原生 {{ row.nativeVersion }}</small>
<small>{{ t('appUpdates.nativeVersionValue', { version: row.nativeVersion }) }}</small>
</template>
</el-table-column>
<el-table-column label="目标" width="132">
<el-table-column :label="t('appUpdates.target')" width="132">
<template #default="{ row }">
{{ platformLabel(row.platform) }} · {{ channelLabel(row.channel) }}
</template>
</el-table-column>
<el-table-column label="状态" width="94">
<el-table-column :label="t('appUpdates.status')" width="94">
<template #default="{ row }">
<el-tag :type="statusType(row.status)" effect="plain">
{{ statusLabel(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="更新说明" min-width="210" show-overflow-tooltip>
<el-table-column :label="t('appUpdates.releaseNotes')" min-width="210" show-overflow-tooltip>
<template #default="{ row }">{{ row.releaseNotes || '—' }}</template>
</el-table-column>
<el-table-column label="更新包" min-width="205" show-overflow-tooltip>
<el-table-column :label="t('appUpdates.bundle')" min-width="205" show-overflow-tooltip>
<template #default="{ row }">
<span class="file-name">{{ row.fileName }}</span>
<small>{{ formatBytes(row.fileSize) }} · {{ row.sha256.slice(0, 12) }}…</small>
</template>
</el-table-column>
<el-table-column label="时间" width="168">
<el-table-column :label="t('appUpdates.time')" width="168">
<template #default="{ row }">
{{ formatTime(row.publishedAt || row.createdAt) }}
</template>
</el-table-column>
<el-table-column label="操作" fixed="right" width="152">
<el-table-column :label="t('appUpdates.actions')" fixed="right" width="152">
<template #default="{ row }">
<el-button
v-if="row.status !== 'Published'"
@@ -317,7 +307,7 @@ onMounted(loadReleases)
type="primary"
@click="publishRelease(row)"
>
{{ row.status === 'Archived' ? '回滚至此版本' : '发布' }}
{{ t(row.status === 'Archived' ? 'appUpdates.rollback' : 'appUpdates.publish') }}
</el-button>
<el-button
v-if="row.status !== 'Published'"
@@ -325,60 +315,56 @@ onMounted(loadReleases)
type="danger"
@click="deleteRelease(row)"
>
删除
{{ t('appUpdates.delete') }}
</el-button>
<span v-else class="active-label">当前生效</span>
<span v-else class="active-label">{{ t('appUpdates.active') }}</span>
</template>
</el-table-column>
<template #empty>
<span>尚未上传 App 热更新包。</span>
<span>{{ t('appUpdates.empty') }}</span>
</template>
</el-table>
<div v-if="cursors.length || hasMore" class="cursor-pager">
<el-button :disabled="!cursors.length || loading" @click="previousPage">上一批</el-button>
<span>第 {{ filter.page }} 批</span>
<el-button type="primary" :disabled="!hasMore || loading" @click="nextPage">下一批</el-button>
<el-button :disabled="!cursors.length || loading" @click="previousPage">{{ t('appUpdates.previous') }}</el-button><span>{{ t('appUpdates.page', { page: filter.page }) }}</span><el-button type="primary" :disabled="!hasMore || loading" @click="nextPage">{{ t('appUpdates.next') }}</el-button>
</div>
<el-dialog
v-model="uploadVisible"
title="上传 App 热更新包"
:title="t('appUpdates.uploadTitle')"
width="min(620px, 92vw)"
destroy-on-close
>
<el-form label-position="top">
<div class="form-grid">
<el-form-item label="平台">
<el-form-item :label="t('appUpdates.platform')">
<el-select v-model="form.platform">
<el-option label="Android" value="Android" />
<el-option label="iOS" value="Ios" />
</el-select>
</el-form-item>
<el-form-item label="通道">
<el-form-item :label="t('appUpdates.channel')">
<el-select v-model="form.channel">
<el-option label="正式通道" value="Production" />
<el-option label="测试通道" value="Staging" />
<el-option :label="t('appUpdates.production')" value="Production" /><el-option :label="t('appUpdates.staging')" value="Staging" />
</el-select>
</el-form-item>
<el-form-item label="热更新版本">
<el-input v-model="form.version" placeholder="例如 1.0.1" />
<el-form-item :label="t('appUpdates.hotVersion')">
<el-input v-model="form.version" :placeholder="t('appUpdates.versionPlaceholder')" />
</el-form-item>
<el-form-item label="兼容的原生版本">
<el-input v-model="form.nativeVersion" placeholder="当前 Android 为 1.0" />
<el-form-item :label="t('appUpdates.compatibleNative')"><el-input v-model="form.nativeVersion" :placeholder="t('appUpdates.nativePlaceholder')" />
</el-form-item>
</div>
<el-form-item label="更新说明">
<el-form-item :label="t('appUpdates.releaseNotes')">
<el-input
v-model="form.releaseNotes"
type="textarea"
:rows="3"
maxlength="1000"
show-word-limit
placeholder="说明本次修复内容,不要包含敏感信息。"
:placeholder="t('appUpdates.notesPlaceholder')"
/>
</el-form-item>
<el-form-item label="更新 ZIP">
<el-form-item :label="t('appUpdates.updateZip')">
<el-upload
v-model:file-list="uploadFiles"
accept=".zip,application/zip"
@@ -387,19 +373,19 @@ onMounted(loadReleases)
:on-change="handleBundleChange"
:on-remove="handleBundleRemove"
>
<el-button :icon="UploadFilled">选择 ZIP</el-button>
<el-button :icon="UploadFilled">{{ t('appUpdates.selectZip') }}</el-button>
<template #tip>
<div class="el-upload__tip">
最大 30 MB,ZIP 根目录必须直接包含 index.html。
{{ t('appUpdates.zipHint') }}
</div>
</template>
</el-upload>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="uploadVisible = false">取消</el-button>
<el-button @click="uploadVisible = false">{{ t('appUpdates.cancel') }}</el-button>
<el-button type="primary" :loading="uploadBusy" @click="uploadRelease">
上传为草稿
{{ t('appUpdates.uploadDraft') }}
</el-button>
</template>
</el-dialog>
+1
View File
@@ -184,6 +184,7 @@ export default {
performance: {
title: 'System performance', description: 'Trace response-time costs from API endpoints into the database.', rangeAria: 'Performance report time range', refreshAria: 'Refresh performance report', notConfigured: 'Waiting for a performance data source', unavailable: 'Performance data is unavailable', fallbackNote: 'Business APIs continue operating normally. The report will not fall back to reading the academic business database.', openDashboard: 'Open monitoring platform', sampleConclusion: 'Sample conclusion', requestCount: 'Total requests', endpointP95: 'Endpoint P95', errorRate: '5xx rate', databaseP95: 'Database P95', slowQueries: 'Slow queries', queryFailures: 'Query failures', chartAria: 'Request rate and endpoint P95 trend', noSamples: 'The data source is connected, but no request metrics were received in this time range.', endpointRanking: 'Endpoint latency ranking', endpointMetrics: 'P95 / requests / 5xx', endpointCounts: '{count} requests · {errors} errors', noEndpoints: 'No endpoint metrics in this range.', databaseRanking: 'Database query ranking', databaseMetrics: 'P95 / calls / slow queries', databaseCounts: '{count} calls · {slow} slow', noDatabase: 'No database metrics in this range.', generatedAt: 'Generated {date} · Page data uses a short cache', viewTraces: 'View raw traces', requestsPerSecond: 'Requests / second', requestRate: 'Request rate', ranges: { '15m': '15 minutes', '1h': '1 hour', '24h': '24 hours', '7d': '7 days' }, notes: { waiting: 'Waiting for metric samples', failedDatabase: 'Database command failures detected', serverErrors: 'Server error rate needs attention', slowQueries: 'Queries exceeded the slow-query threshold', healthy: 'No significant anomalies in the current sample window' },
},
appUpdates: { title: 'App web hot updates', description: 'Upload a built ZIP and publish by native version and channel, retaining previous packages for fast rollback.', refresh: 'Refresh', upload: 'Upload update', boundary: 'Release boundary', webOnly: 'HTML, JavaScript, CSS, and static assets only', nativeBoundary: 'New native plugins, permissions, or Android/iOS code require a new native release', autoRollback: 'The app automatically returns to the last usable version if an update fails', allPlatforms: 'All platforms', allChannels: 'All channels', production: 'Production channel', staging: 'Staging channel', search: 'Search', version: 'Version', nativeVersionValue: 'Native {version}', target: 'Target', status: 'Status', releaseNotes: 'Release notes', bundle: 'Update bundle', time: 'Time', actions: 'Actions', rollback: 'Roll back to this version', publish: 'Publish', delete: 'Delete', active: 'Currently active', empty: 'No App hot-update packages uploaded.', previous: 'Previous batch', page: 'Batch {page}', next: 'Next batch', uploadTitle: 'Upload App hot update', platform: 'Platform', channel: 'Channel', hotVersion: 'Hot-update version', versionPlaceholder: 'For example 1.0.1', compatibleNative: 'Compatible native version', nativePlaceholder: 'Current Android version: 1.0', notesPlaceholder: 'Describe the fixes without including sensitive information.', updateZip: 'Update ZIP', selectZip: 'Select ZIP', zipHint: 'Maximum 30 MB. index.html must be directly in the ZIP root.', cancel: 'Cancel', uploadDraft: 'Upload as draft', confirmRollback: 'Confirm rollback', channels: { Production: 'Production', Staging: 'Staging' }, statuses: { Published: 'Published', Archived: 'Archived', Draft: 'Draft' }, messages: { selectZip: 'Select an update ZIP.', versionRequired: 'Enter the hot-update version and compatible native version.', uploaded: 'Update uploaded as a draft. Review it before publishing.', rollbackConfirm: 'Roll back the {platform} {native} production channel to {version}. Newly started apps will download this version.', publishConfirm: 'Publish {version}? The currently active update for the same platform, channel, and native version will be archived.', rollbackTitle: 'Confirm version rollback', publishTitle: 'Confirm update publication', rolledBack: 'Rolled back to the selected version.', published: 'Update published.', deleteConfirm: 'Permanently delete the {version} release history and ZIP package ({file})? Installed versions are unaffected, and this cannot be recovered.', deleteTitle: 'Delete update package', deleted: 'Release history and update package deleted.' } },
api: {
'data.constraint_conflict': 'A data constraint conflict occurred.',
'server.unhandled_error': 'The server encountered an error while processing the request.',
+1
View File
@@ -184,6 +184,7 @@ export default {
performance: {
title: '系统性能', description: '从接口进入数据库,定位响应时间消耗在哪里。', rangeAria: '性能报表时间范围', refreshAria: '刷新性能报表', notConfigured: '等待连接性能数据源', unavailable: '性能数据暂不可用', fallbackNote: '业务接口继续正常运行;报表不会回退读取教务业务数据库。', openDashboard: '打开监控平台', sampleConclusion: '采样结论', requestCount: '请求总量', endpointP95: '接口 P95', errorRate: '5xx 比例', databaseP95: '数据库 P95', slowQueries: '慢查询', queryFailures: '查询失败', chartAria: '请求速率与接口 P95 趋势图', noSamples: '数据源已连接,但该时间范围内尚未收到请求指标。', endpointRanking: '接口耗时排行', endpointMetrics: 'P95 / 请求量 / 5xx', endpointCounts: '{count} 次 · {errors} 错误', noEndpoints: '该范围内没有接口指标。', databaseRanking: '数据库查询排行', databaseMetrics: 'P95 / 调用量 / 慢查询', databaseCounts: '{count} 次 · {slow} 慢', noDatabase: '该范围内没有数据库指标。', generatedAt: '生成于 {date} · 页面数据采用短时缓存', viewTraces: '查看原始调用链', requestsPerSecond: '请求 / 秒', requestRate: '请求速率', ranges: { '15m': '15 分钟', '1h': '1 小时', '24h': '24 小时', '7d': '7 天' }, notes: { waiting: '等待指标样本', failedDatabase: '存在失败的数据库命令', serverErrors: '服务端错误率需要关注', slowQueries: '存在超过阈值的慢查询', healthy: '当前采样窗口内未见明显异常' },
},
appUpdates: { title: 'App 前端热更新', description: '上传构建后的 ZIP,按原生版本和通道发布;保留历史包用于快速回滚。', refresh: '刷新', upload: '上传更新包', boundary: '发布边界', webOnly: '仅限 HTML、JavaScript、CSS 和静态资源', nativeBoundary: '新增原生插件、权限或 Android/iOS 代码必须重新发版', autoRollback: '更新失败时 App 自动回退到上一个可用版本', allPlatforms: '全部平台', allChannels: '全部通道', production: '正式通道', staging: '测试通道', search: '查询', version: '版本', nativeVersionValue: '原生 {version}', target: '目标', status: '状态', releaseNotes: '更新说明', bundle: '更新包', time: '时间', actions: '操作', rollback: '回滚至此版本', publish: '发布', delete: '删除', active: '当前生效', empty: '尚未上传 App 热更新包。', previous: '上一批', page: '第 {page} 批', next: '下一批', uploadTitle: '上传 App 热更新包', platform: '平台', channel: '通道', hotVersion: '热更新版本', versionPlaceholder: '例如 1.0.1', compatibleNative: '兼容的原生版本', nativePlaceholder: '当前 Android 为 1.0', notesPlaceholder: '说明本次修复内容,不要包含敏感信息。', updateZip: '更新 ZIP', selectZip: '选择 ZIP', zipHint: '最大 30 MB,ZIP 根目录必须直接包含 index.html。', cancel: '取消', uploadDraft: '上传为草稿', confirmRollback: '确认回滚', channels: { Production: '正式', Staging: '测试' }, statuses: { Published: '已发布', Archived: '已归档', Draft: '草稿' }, messages: { selectZip: '请选择更新 ZIP。', versionRequired: '请填写热更新版本和兼容的原生版本。', uploaded: '更新包已上传为草稿,确认无误后再发布。', rollbackConfirm: '将把 {platform} {native} 的正式通道回滚到 {version}。新启动的 App 将下载此版本。', publishConfirm: '确认发布 {version}?同平台、通道和原生版本下当前生效的更新将自动归档。', rollbackTitle: '确认版本回滚', publishTitle: '确认发布更新', rolledBack: '已回滚到指定版本。', published: '更新已发布。', deleteConfirm: '将永久删除 {version} 的发布历史和 ZIP 更新包({file})。此操作不会影响已安装到设备的版本,且不可恢复。', deleteTitle: '删除更新包', deleted: '发布历史和更新包已删除。' } },
api: {
'data.constraint_conflict': '数据约束冲突。',
'server.unhandled_error': '服务器处理请求时发生错误。',