From e965c012e69414583a207469ea5396f48c8c06eb Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Fri, 22 May 2026 15:33:35 +0800 Subject: [PATCH] feat(security-center): add reset container operation alongside update - system.ts: extract streamOperation helper; add streamSystemReset export - SecurityCenterView: replace single update button with update/reset descriptions table; shared dialog driven by operationType ref Co-Authored-By: Claude Sonnet 4.6 --- tenant-platform/src/api/system.ts | 13 ++++- .../src/views/security/SecurityCenterView.vue | 54 ++++++++++++------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/tenant-platform/src/api/system.ts b/tenant-platform/src/api/system.ts index 011b13f..c795b50 100644 --- a/tenant-platform/src/api/system.ts +++ b/tenant-platform/src/api/system.ts @@ -12,12 +12,13 @@ export async function getDeploymentStatus(): Promise { return json.data as DeploymentStatus } -export async function streamSystemUpdate( +async function streamOperation( + path: string, onLine: (line: string) => void, signal?: AbortSignal, ): Promise { const token = localStorage.getItem('token') ?? '' - const res = await fetch(`${BASE}/system/update`, { + const res = await fetch(`${BASE}${path}`, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, signal, @@ -41,3 +42,11 @@ export async function streamSystemUpdate( } if (buf) onLine(buf) } + +export function streamSystemUpdate(onLine: (line: string) => void, signal?: AbortSignal) { + return streamOperation('/system/update', onLine, signal) +} + +export function streamSystemReset(onLine: (line: string) => void, signal?: AbortSignal) { + return streamOperation('/system/reset', onLine, signal) +} diff --git a/tenant-platform/src/views/security/SecurityCenterView.vue b/tenant-platform/src/views/security/SecurityCenterView.vue index ef7a354..bac8004 100644 --- a/tenant-platform/src/views/security/SecurityCenterView.vue +++ b/tenant-platform/src/views/security/SecurityCenterView.vue @@ -47,18 +47,24 @@ 生成迁移密钥 - + -

- 拉取最新镜像并逐一重启各服务容器,全程无需手动操作。tenant-service 重启时页面连接会短暂中断,更新后自动恢复。 -

- 立即更新 + + + 拉取最新镜像并重建所有容器,用于升级到新版本。 + 立即更新 + + + 用当前本地镜像重建所有容器,无需下载新镜像,适合修复异常服务。 + 重置容器 + +
@@ -158,20 +164,21 @@ - +
-

将拉取最新镜像并重启所有运行中的服务容器。

+

将拉取最新镜像并重建所有运行中的服务容器,用于升级到新版本。

+

将用当前本地镜像重建所有运行中的服务容器,无需下载新镜像,适合修复异常服务。

- +
@@ -185,7 +192,7 @@
- +
@@ -197,10 +204,10 @@ - 开始更新 + {{ operationType === 'update' ? '开始更新' : '开始重置' }} @@ -214,7 +221,7 @@ import { Loading } from '@element-plus/icons-vue' import { accountApi } from '@/api/account' import { appApi, type App } from '@/api/app' import { migrateApi } from '@/api/migrate' -import { getDeploymentStatus, streamSystemUpdate } from '@/api/system' +import { getDeploymentStatus, streamSystemUpdate, streamSystemReset } from '@/api/system' import { useAuthStore } from '@/stores/auth' import { formatTime } from '@/utils/date' @@ -349,6 +356,7 @@ async function copyMigrateKey() { // ── System Update ────────────────────────────────────────────────────────── const showUpdateDialog = ref(false) +const operationType = ref<'update' | 'reset'>('update') const updating = ref(false) const updateDone = ref(false) const updateError = ref('') @@ -356,6 +364,11 @@ const selfRestarting = ref(false) const updateLog = ref([]) const logEl = ref(null) +function openOperationDialog(type: 'update' | 'reset') { + operationType.value = type + showUpdateDialog.value = true +} + function resetUpdateDialog() { if (updating.value) return updateLog.value = [] @@ -364,15 +377,18 @@ function resetUpdateDialog() { selfRestarting.value = false } -async function startUpdate() { +async function startOperation() { updating.value = true updateLog.value = [] updateDone.value = false updateError.value = '' selfRestarting.value = false + const streamFn = operationType.value === 'update' ? streamSystemUpdate : streamSystemReset + const failMsg = operationType.value === 'update' ? '更新失败' : '重置失败' + try { - await streamSystemUpdate((line) => { + await streamFn((line) => { if (line === 'RESTART_SELF') { selfRestarting.value = true updating.value = false @@ -391,7 +407,7 @@ async function startUpdate() { } catch (e: any) { if (!selfRestarting.value) { updating.value = false - updateError.value = e?.message ?? '更新失败' + updateError.value = e?.message ?? failMsg } } } @@ -404,7 +420,7 @@ async function pollForRecovery() { await getDeploymentStatus() selfRestarting.value = false updateDone.value = true - updateLog.value.push('>>> tenant-service 已重启,更新完成 ✓') + updateLog.value.push(operationType.value === 'update' ? '>>> tenant-service 已重启,更新完成 ✓' : '>>> tenant-service 已重启,重置完成 ✓') return } catch { // still restarting