Feat: optimized code

This commit is contained in:
alongw 2023-09-16 23:59:25 +08:00
parent 4a4f900717
commit 6d9885b459
2 changed files with 13 additions and 16 deletions

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { t } from "@/lang/i18n";
import { ref, onMounted } from "vue";
import { onMounted } from "vue";
import type { LayoutCard } from "@/types";
import { userInfoApi } from "@/services/apis/index";
import { useRouter } from "vue-router";
@ -11,7 +11,7 @@ defineProps<{
const router = useRouter();
const { execute } = userInfoApi();
const { execute, state } = userInfoApi();
const status = {
"-1": t("状态未知"),
@ -21,7 +21,6 @@ const status = {
"3": t("正在运行")
};
const state = ref();
const columns = [
{
title: t("实例名称"),
@ -63,12 +62,11 @@ const columns = [
];
const getInstanceList = async () => {
const res = await execute({
await execute({
params: {
advanced: true
}
});
state.value = res.value?.instances;
};
const operate = (e: any) => {
@ -91,7 +89,7 @@ onMounted(() => {
<template #title>{{ card.title }}</template>
<template #body>
<a-table
:data-source="state"
:data-source="state?.instances"
:columns="columns"
:pagination="false"
:scroll="{ x: 'max-content' }"

View File

@ -3,7 +3,7 @@ import { useLayoutCardTools } from "@/hooks/useCardTools";
import { t } from "@/lang/i18n";
import type { LayoutCard } from "@/types";
import { computed, onMounted, ref } from "vue";
import { computed, onMounted } from "vue";
import { userInfoApi } from "@/services/apis/index";
@ -11,17 +11,14 @@ const props = defineProps<{
card: LayoutCard;
}>();
const { execute } = userInfoApi();
const state = ref();
const { execute, state } = userInfoApi();
const getInstanceList = async () => {
const res = await execute({
await execute({
params: {
advanced: true
}
});
state.value = res.value?.instances;
};
const { getMetaValue } = useLayoutCardTools(props.card);
@ -35,22 +32,24 @@ const computedStatusList = computed(() => {
{
type: "instance_all",
title: t("管理员所分配给您的所有实例总数"),
value: state.value.length
value: state.value.instances.length
},
{
type: "instance_running",
title: t("实例正在运行中的数量"),
value: state.value.filter((e: any) => e.status == 3).length
value: state.value.instances.filter((e: any) => e.status == 3).length
},
{
type: "instance_stop",
title: t("实例未处于运行中的数量"),
value: state.value.filter((e: any) => e.status == 0).length
value: state.value.instances.filter((e: any) => e.status == 0).length
},
{
type: "instance_error",
title: t("暂时不可使用的实例数"),
value: state.value.filter((e: any) => e.status == -1 || e.status == 1 || e.status == 2).length
value: state.value.instances.filter(
(e: any) => e.status == -1 || e.status == 1 || e.status == 2
).length
}
];
});