Opt: instance status code

This commit is contained in:
Lazy 2024-03-02 22:21:13 +08:00
parent e3ad658089
commit f6f17cc57e
4 changed files with 24 additions and 18 deletions

View File

@ -2,7 +2,7 @@ import type { InstanceDetail, MapData } from "@/types";
import { t } from "@/lang/i18n";
import { computed, onMounted, onUnmounted, ref, type Ref } from "vue";
import { getInstanceInfo } from "@/services/apis/instance";
import { INSTANCE_STATUS } from "@/types/const";
import { INSTANCE_STATUS, INSTANCE_STATUS_CODE } from "@/types/const";
export const TYPE_UNIVERSAL = "universal";
export const TYPE_WEB_SHELL = "universal/web_shell";
@ -84,15 +84,19 @@ export function useInstanceInfo(params: Params) {
let finalState = state;
if (instanceInfo) finalState = instanceInfo;
const isRunning = computed(() => finalState?.value?.status === 3);
const isStopped = computed(() => finalState?.value?.status === 0);
const isUnknown = computed(() => finalState?.value?.status === INSTANCE_STATUS_CODE.UNKNOWN);
const isStopped = computed(() => finalState?.value?.status === INSTANCE_STATUS_CODE.STOPPED);
const isStopping = computed(() => finalState?.value?.status === INSTANCE_STATUS_CODE.STOPPING);
const isStarting = computed(() => finalState?.value?.status === INSTANCE_STATUS_CODE.STARTING);
const isRunning = computed(() => finalState?.value?.status === INSTANCE_STATUS_CODE.RUNNING);
const instanceTypeText = computed(() => {
return (
INSTANCE_TYPE_TRANSLATION[String(finalState?.value?.config.type)] || t("TXT_CODE_da7a0328")
);
});
const statusText = computed(
() => String(INSTANCE_STATUS[String(finalState?.value?.status)]) || t("TXT_CODE_c8333afa")
() => String(INSTANCE_STATUS[finalState.value?.status ?? -1]) || t("TXT_CODE_c8333afa")
);
onMounted(async () => {
@ -128,8 +132,11 @@ export function useInstanceInfo(params: Params) {
instanceInfo: state,
execute,
statusText,
isRunning,
isUnknown,
isStopped,
isStopping,
isStarting,
isRunning,
instanceTypeText
};
}

View File

@ -216,10 +216,8 @@ export function useTerminal() {
socket?.removeAllListeners();
});
const isStopped = computed(() =>
[INSTANCE_STATUS_CODE.STOPPED, INSTANCE_STATUS_CODE.UNKNOWN].includes(state?.value?.status ?? 0)
);
const isRunning = computed(() => !isStopped.value);
const isStopped = computed(() => state?.value?.status === INSTANCE_STATUS_CODE.STOPPED);
const isRunning = computed(() => state?.value?.status === INSTANCE_STATUS_CODE.RUNNING);
return {
events,

View File

@ -14,14 +14,6 @@ export const TERMINAL_CODE = [
"UTF-16"
];
export const INSTANCE_STATUS: Record<string, string> = {
"-1": t("TXT_CODE_342a04a9"),
"0": t("TXT_CODE_4ef6b040"),
"1": t("TXT_CODE_a409b8a9"),
"2": t("TXT_CODE_175b570d"),
"3": t("TXT_CODE_bdb620b9")
};
export enum INSTANCE_STATUS_CODE {
UNKNOWN = -1,
STOPPED = 0,
@ -30,6 +22,14 @@ export enum INSTANCE_STATUS_CODE {
RUNNING = 3
}
export const INSTANCE_STATUS: Record<INSTANCE_STATUS_CODE, string> = {
[INSTANCE_STATUS_CODE.UNKNOWN]: t("TXT_CODE_342a04a9"),
[INSTANCE_STATUS_CODE.STOPPED]: t("TXT_CODE_4ef6b040"),
[INSTANCE_STATUS_CODE.STOPPING]: t("TXT_CODE_a409b8a9"),
[INSTANCE_STATUS_CODE.STARTING]: t("TXT_CODE_175b570d"),
[INSTANCE_STATUS_CODE.RUNNING]: t("TXT_CODE_bdb620b9")
};
export const defaultDockerFile = `FROM ubuntu:latest\nRUN mkdir -p /workspace\nWORKDIR /workspace\n`;
export const openjdk8 = `FROM openjdk:8-jre

View File

@ -7,6 +7,7 @@ import type {
IMapData,
IGlobalInstanceDockerConfig
} from "../../../common/global";
import type { INSTANCE_STATUS_CODE } from "./const";
export type JsonData = IJsonData;
export type MapData<T> = IMapData<T>;
@ -29,7 +30,7 @@ export enum NEW_CARD_TYPE {
export interface InstanceDetail {
instanceUuid: string;
started: number;
status: number;
status: INSTANCE_STATUS_CODE;
info: {
currentPlayers: number;
fileLock: number;