From 7b1980f7b775a2483db4def48edde24407b7f9b0 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Thu, 27 Feb 2025 15:40:10 +0800 Subject: [PATCH] feat: Standardize runtime environment status handling (#8026) --- frontend/src/api/modules/files.ts | 2 +- frontend/src/utils/runtime.ts | 24 +++++++++++++++++++ .../views/website/runtime/dotnet/index.vue | 9 +++---- .../src/views/website/runtime/go/index.vue | 9 +++---- .../src/views/website/runtime/java/index.vue | 9 +++---- .../src/views/website/runtime/node/index.vue | 11 +++++---- .../src/views/website/runtime/php/index.vue | 23 +++++++----------- .../views/website/runtime/python/index.vue | 9 +++---- .../views/website/website/create/index.vue | 2 +- 9 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 frontend/src/utils/runtime.ts diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index 7f16a2ebc..4e5ef181b 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -86,7 +86,7 @@ export const computeDirSize = (params: File.DirSizeReq) => { }; export const fileWgetKeys = () => { - return http.get('files//wget/process/keys'); + return http.get('files/wget/process/keys'); }; export const getRecycleList = (params: ReqPage) => { diff --git a/frontend/src/utils/runtime.ts b/frontend/src/utils/runtime.ts new file mode 100644 index 000000000..33041557c --- /dev/null +++ b/frontend/src/utils/runtime.ts @@ -0,0 +1,24 @@ +import { Runtime } from '@/api/interface/runtime'; + +export function disabledButton(row: Runtime.Runtime, type: string): boolean { + switch (type) { + case 'stop': + return row.status === 'Recreating' || row.status === 'Stopped' || row.status === 'Building'; + case 'start': + return ( + row.status === 'Starting' || + row.status === 'Recreating' || + row.status === 'Running' || + row.status === 'Building' + ); + case 'restart': + return row.status === 'Recreating' || row.status === 'Building'; + case 'edit': + return row.status === 'Recreating' || row.status === 'Building'; + case 'extension': + case 'config': + return row.status != 'Running'; + default: + return false; + } +} diff --git a/frontend/src/views/website/runtime/dotnet/index.vue b/frontend/src/views/website/runtime/dotnet/index.vue index 256b35d17..35dc5deb1 100644 --- a/frontend/src/views/website/runtime/dotnet/index.vue +++ b/frontend/src/views/website/runtime/dotnet/index.vue @@ -108,6 +108,7 @@ import AppResources from '@/views/website/runtime/php/check/index.vue'; import { ElMessageBox } from 'element-plus'; import { GlobalStore } from '@/store'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; +import { disabledButton } from '@/utils/runtime'; let timer: NodeJS.Timer | null = null; const loading = ref(false); @@ -142,7 +143,7 @@ const buttons = [ operateRuntime('down', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped'; + return disabledButton(row, 'stop'); }, }, { @@ -151,7 +152,7 @@ const buttons = [ operateRuntime('up', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'starting' || row.status === 'recreating' || row.status === 'running'; + return disabledButton(row, 'start'); }, }, { @@ -160,7 +161,7 @@ const buttons = [ operateRuntime('restart', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'restart'); }, }, { @@ -169,7 +170,7 @@ const buttons = [ openDetail(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'edit'); }, }, { diff --git a/frontend/src/views/website/runtime/go/index.vue b/frontend/src/views/website/runtime/go/index.vue index e8f4cba97..3fdf41ed0 100644 --- a/frontend/src/views/website/runtime/go/index.vue +++ b/frontend/src/views/website/runtime/go/index.vue @@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue'; import { ElMessageBox } from 'element-plus'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; +import { disabledButton } from '@/utils/runtime'; let timer: NodeJS.Timer | null = null; const loading = ref(false); @@ -136,7 +137,7 @@ const buttons = [ operateRuntime('down', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped'; + return disabledButton(row, 'stop'); }, }, { @@ -145,7 +146,7 @@ const buttons = [ operateRuntime('up', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'starting' || row.status === 'recreating' || row.status === 'running'; + return disabledButton(row, 'start'); }, }, { @@ -154,7 +155,7 @@ const buttons = [ operateRuntime('restart', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'restart'); }, }, { @@ -163,7 +164,7 @@ const buttons = [ openDetail(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'edit'); }, }, { diff --git a/frontend/src/views/website/runtime/java/index.vue b/frontend/src/views/website/runtime/java/index.vue index eecc043c9..02695f362 100644 --- a/frontend/src/views/website/runtime/java/index.vue +++ b/frontend/src/views/website/runtime/java/index.vue @@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue'; import { ElMessageBox } from 'element-plus'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; +import { disabledButton } from '@/utils/runtime'; let timer: NodeJS.Timer | null = null; const loading = ref(false); @@ -136,7 +137,7 @@ const buttons = [ operateRuntime('down', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped'; + return disabledButton(row, 'stop'); }, }, { @@ -145,7 +146,7 @@ const buttons = [ operateRuntime('up', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'starting' || row.status === 'recreating' || row.status === 'running'; + return disabledButton(row, 'start'); }, }, { @@ -154,7 +155,7 @@ const buttons = [ operateRuntime('restart', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'restart'); }, }, { @@ -163,7 +164,7 @@ const buttons = [ openDetail(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'edit'); }, }, { diff --git a/frontend/src/views/website/runtime/node/index.vue b/frontend/src/views/website/runtime/node/index.vue index 992b35606..a5fac4a7f 100644 --- a/frontend/src/views/website/runtime/node/index.vue +++ b/frontend/src/views/website/runtime/node/index.vue @@ -109,6 +109,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue'; import { ElMessageBox } from 'element-plus'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; +import { disabledButton } from '@/utils/runtime'; let timer: NodeJS.Timer | null = null; const loading = ref(false); @@ -139,7 +140,7 @@ const buttons = [ openModules(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped'; + return disabledButton(row, 'stop'); }, }, { @@ -148,7 +149,7 @@ const buttons = [ operateRuntime('down', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped'; + return disabledButton(row, 'stop'); }, }, { @@ -157,7 +158,7 @@ const buttons = [ operateRuntime('up', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'starting' || row.status === 'recreating' || row.status === 'running'; + return disabledButton(row, 'start'); }, }, { @@ -166,7 +167,7 @@ const buttons = [ operateRuntime('restart', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'restart'); }, }, { @@ -175,7 +176,7 @@ const buttons = [ openDetail(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'edit'); }, }, { diff --git a/frontend/src/views/website/runtime/php/index.vue b/frontend/src/views/website/runtime/php/index.vue index e1d0250b0..1f71bc5b6 100644 --- a/frontend/src/views/website/runtime/php/index.vue +++ b/frontend/src/views/website/runtime/php/index.vue @@ -127,6 +127,7 @@ import ComposeLogs from '@/components/compose-log/index.vue'; import Config from '@/views/website/runtime/php/config/index.vue'; import Supervisor from '@/views/website/runtime/php/supervisor/index.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; +import { disabledButton } from '@/utils/runtime'; const paginationConfig = reactive({ cacheSizeKey: 'runtime-page-size', @@ -160,7 +161,7 @@ const buttons = [ openExtensionsManagement(row); }, disabled: function (row: Runtime.Runtime) { - return row.status != 'running'; + return disabledButton(row, 'extension'); }, }, { @@ -169,7 +170,7 @@ const buttons = [ operateRuntime('down', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped' || row.status === 'building'; + return disabledButton(row, 'stop'); }, }, { @@ -178,12 +179,7 @@ const buttons = [ operateRuntime('up', row.id); }, disabled: function (row: Runtime.Runtime) { - return ( - row.status === 'starting' || - row.status === 'recreating' || - row.status === 'running' || - row.status === 'building' - ); + return disabledButton(row, 'start'); }, }, { @@ -192,7 +188,7 @@ const buttons = [ operateRuntime('restart', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'building'; + return disabledButton(row, 'restart'); }, }, { @@ -201,7 +197,7 @@ const buttons = [ openDetail(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'building'; + return disabledButton(row, 'edit'); }, }, { @@ -210,7 +206,7 @@ const buttons = [ openConfig(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'building'; + return disabledButton(row, 'config'); }, }, { @@ -219,14 +215,11 @@ const buttons = [ openSupervisor(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'building'; + return disabledButton(row, 'config'); }, }, { label: i18n.global.t('commons.button.delete'), - disabled: function (row: Runtime.Runtime) { - return row.status === 'building'; - }, click: function (row: Runtime.Runtime) { openDelete(row); }, diff --git a/frontend/src/views/website/runtime/python/index.vue b/frontend/src/views/website/runtime/python/index.vue index fbd7920f6..4050a1b33 100644 --- a/frontend/src/views/website/runtime/python/index.vue +++ b/frontend/src/views/website/runtime/python/index.vue @@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue'; import { ElMessageBox } from 'element-plus'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; +import { disabledButton } from '@/utils/runtime'; let timer: NodeJS.Timer | null = null; const loading = ref(false); @@ -136,7 +137,7 @@ const buttons = [ operateRuntime('down', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating' || row.status === 'stopped'; + return disabledButton(row, 'stop'); }, }, { @@ -145,7 +146,7 @@ const buttons = [ operateRuntime('up', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'starting' || row.status === 'recreating' || row.status === 'running'; + return disabledButton(row, 'start'); }, }, { @@ -154,7 +155,7 @@ const buttons = [ operateRuntime('restart', row.id); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'restart'); }, }, { @@ -163,7 +164,7 @@ const buttons = [ openDetail(row); }, disabled: function (row: Runtime.Runtime) { - return row.status === 'recreating'; + return disabledButton(row, 'edit'); }, }, { diff --git a/frontend/src/views/website/website/create/index.vue b/frontend/src/views/website/website/create/index.vue index a50d5c778..f9800fd57 100644 --- a/frontend/src/views/website/website/create/index.vue +++ b/frontend/src/views/website/website/create/index.vue @@ -661,7 +661,7 @@ const runtimeResource = ref('appstore'); const initRuntimeReq = () => ({ page: 1, pageSize: 100, - status: 'running', + status: 'Running', type: 'php', }); const runtimeReq = ref(initRuntimeReq());