1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-01 03:24:14 +08:00

feat: Standardize runtime environment status handling (#8026)

This commit is contained in:
zhengkunwang 2025-02-27 15:40:10 +08:00 committed by GitHub
parent aae839f921
commit 7b1980f7b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 60 additions and 38 deletions

View File

@ -86,7 +86,7 @@ export const computeDirSize = (params: File.DirSizeReq) => {
}; };
export const fileWgetKeys = () => { export const fileWgetKeys = () => {
return http.get<File.FileKeys>('files//wget/process/keys'); return http.get<File.FileKeys>('files/wget/process/keys');
}; };
export const getRecycleList = (params: ReqPage) => { export const getRecycleList = (params: ReqPage) => {

View File

@ -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;
}
}

View File

@ -108,6 +108,7 @@ import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import { GlobalStore } from '@/store'; import { GlobalStore } from '@/store';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';
let timer: NodeJS.Timer | null = null; let timer: NodeJS.Timer | null = null;
const loading = ref(false); const loading = ref(false);
@ -142,7 +143,7 @@ const buttons = [
operateRuntime('down', row.id); operateRuntime('down', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('up', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('restart', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'restart');
}, },
}, },
{ {
@ -169,7 +170,7 @@ const buttons = [
openDetail(row); openDetail(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'edit');
}, },
}, },
{ {

View File

@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';
let timer: NodeJS.Timer | null = null; let timer: NodeJS.Timer | null = null;
const loading = ref(false); const loading = ref(false);
@ -136,7 +137,7 @@ const buttons = [
operateRuntime('down', row.id); operateRuntime('down', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('up', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('restart', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'restart');
}, },
}, },
{ {
@ -163,7 +164,7 @@ const buttons = [
openDetail(row); openDetail(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'edit');
}, },
}, },
{ {

View File

@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';
let timer: NodeJS.Timer | null = null; let timer: NodeJS.Timer | null = null;
const loading = ref(false); const loading = ref(false);
@ -136,7 +137,7 @@ const buttons = [
operateRuntime('down', row.id); operateRuntime('down', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('up', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('restart', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'restart');
}, },
}, },
{ {
@ -163,7 +164,7 @@ const buttons = [
openDetail(row); openDetail(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'edit');
}, },
}, },
{ {

View File

@ -109,6 +109,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';
let timer: NodeJS.Timer | null = null; let timer: NodeJS.Timer | null = null;
const loading = ref(false); const loading = ref(false);
@ -139,7 +140,7 @@ const buttons = [
openModules(row); openModules(row);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('down', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('up', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('restart', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'restart');
}, },
}, },
{ {
@ -175,7 +176,7 @@ const buttons = [
openDetail(row); openDetail(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'edit');
}, },
}, },
{ {

View File

@ -127,6 +127,7 @@ import ComposeLogs from '@/components/compose-log/index.vue';
import Config from '@/views/website/runtime/php/config/index.vue'; import Config from '@/views/website/runtime/php/config/index.vue';
import Supervisor from '@/views/website/runtime/php/supervisor/index.vue'; import Supervisor from '@/views/website/runtime/php/supervisor/index.vue';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';
const paginationConfig = reactive({ const paginationConfig = reactive({
cacheSizeKey: 'runtime-page-size', cacheSizeKey: 'runtime-page-size',
@ -160,7 +161,7 @@ const buttons = [
openExtensionsManagement(row); openExtensionsManagement(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status != 'running'; return disabledButton(row, 'extension');
}, },
}, },
{ {
@ -169,7 +170,7 @@ const buttons = [
operateRuntime('down', row.id); operateRuntime('down', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('up', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return ( return disabledButton(row, 'start');
row.status === 'starting' ||
row.status === 'recreating' ||
row.status === 'running' ||
row.status === 'building'
);
}, },
}, },
{ {
@ -192,7 +188,7 @@ const buttons = [
operateRuntime('restart', row.id); operateRuntime('restart', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'building'; return disabledButton(row, 'restart');
}, },
}, },
{ {
@ -201,7 +197,7 @@ const buttons = [
openDetail(row); openDetail(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'building'; return disabledButton(row, 'edit');
}, },
}, },
{ {
@ -210,7 +206,7 @@ const buttons = [
openConfig(row); openConfig(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'building'; return disabledButton(row, 'config');
}, },
}, },
{ {
@ -219,14 +215,11 @@ const buttons = [
openSupervisor(row); openSupervisor(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'building'; return disabledButton(row, 'config');
}, },
}, },
{ {
label: i18n.global.t('commons.button.delete'), label: i18n.global.t('commons.button.delete'),
disabled: function (row: Runtime.Runtime) {
return row.status === 'building';
},
click: function (row: Runtime.Runtime) { click: function (row: Runtime.Runtime) {
openDelete(row); openDelete(row);
}, },

View File

@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue'; import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus'; import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue'; import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';
let timer: NodeJS.Timer | null = null; let timer: NodeJS.Timer | null = null;
const loading = ref(false); const loading = ref(false);
@ -136,7 +137,7 @@ const buttons = [
operateRuntime('down', row.id); operateRuntime('down', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('up', row.id);
}, },
disabled: function (row: Runtime.Runtime) { 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); operateRuntime('restart', row.id);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'restart');
}, },
}, },
{ {
@ -163,7 +164,7 @@ const buttons = [
openDetail(row); openDetail(row);
}, },
disabled: function (row: Runtime.Runtime) { disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating'; return disabledButton(row, 'edit');
}, },
}, },
{ {

View File

@ -661,7 +661,7 @@ const runtimeResource = ref('appstore');
const initRuntimeReq = () => ({ const initRuntimeReq = () => ({
page: 1, page: 1,
pageSize: 100, pageSize: 100,
status: 'running', status: 'Running',
type: 'php', type: 'php',
}); });
const runtimeReq = ref<Runtime.RuntimeReq>(initRuntimeReq()); const runtimeReq = ref<Runtime.RuntimeReq>(initRuntimeReq());