gtsoft-snail-job-admin/src/views/home/modules/card-data.vue

210 lines
5.4 KiB
Vue
Raw Normal View History

2024-03-08 17:59:45 +08:00
<script setup lang="ts">
import { computed } from 'vue';
import { createReusableTemplate } from '@vueuse/core';
import { $t } from '@/locales';
defineOptions({
name: 'CardData'
});
2024-03-22 11:22:07 +08:00
interface Props {
modelValue: Api.Dashboard.CardCount;
}
const props = defineProps<Props>();
2024-03-08 17:59:45 +08:00
interface CardData {
key: string;
title: string;
2024-03-22 11:22:07 +08:00
tip: string;
2024-03-08 17:59:45 +08:00
value: number;
color: {
start: string;
end: string;
};
icon: string;
2024-03-22 11:22:07 +08:00
bottom: { label: string; value: number }[];
2024-03-08 17:59:45 +08:00
}
2024-03-22 11:22:07 +08:00
console.log(props.modelValue);
2024-03-08 17:59:45 +08:00
const cardData = computed<CardData[]>(() => [
{
2024-03-22 11:22:07 +08:00
key: 'retryTask',
title: $t('page.home.retryTask'),
tip: $t('page.home.retryTaskTip'),
value: props.modelValue?.retryTask.totalNum ?? 0,
2024-03-08 17:59:45 +08:00
unit: '',
color: {
2024-03-22 11:22:07 +08:00
start: '#40e9c5',
end: '#BEE3DB'
2024-03-08 17:59:45 +08:00
},
2024-03-22 11:22:07 +08:00
icon: 'ant-design:schedule-outlined',
bottom: [
{
label: $t('common.success'),
value: props.modelValue?.retryTask.finishNum ?? 0
},
{
label: $t('common.running'),
value: props.modelValue?.retryTask.runningNum ?? 0
},
{
label: $t('page.manage.retryTask.status.maxRetryTimes'),
value: props.modelValue?.retryTask.maxCountNum ?? 0
},
{
label: $t('page.manage.retryTask.status.pauseRetry'),
value: props.modelValue?.retryTask.suspendNum ?? 0
}
]
2024-03-08 17:59:45 +08:00
},
{
2024-03-22 11:22:07 +08:00
key: 'jobTask',
title: $t('page.home.jobTask'),
tip: $t('page.home.jobTaskTip'),
value: props.modelValue?.jobTask.totalNum ?? 0,
2024-03-08 17:59:45 +08:00
color: {
2024-03-22 11:22:07 +08:00
start: '#f5b386',
end: '#FFD6BA'
2024-03-08 17:59:45 +08:00
},
2024-03-22 11:22:07 +08:00
icon: 'ant-design:profile-outlined',
bottom: [
{
label: $t('common.success'),
value: props.modelValue?.jobTask.successNum ?? 0
},
{
label: $t('common.fail'),
value: props.modelValue?.jobTask.failNum ?? 0
},
{
label: $t('common.stop'),
value: props.modelValue?.jobTask.stopNum ?? 0
},
{
label: $t('common.cancel'),
value: props.modelValue?.jobTask.cancelNum ?? 0
}
]
2024-03-08 17:59:45 +08:00
},
{
2024-03-22 11:22:07 +08:00
key: 'onlineServiceCount',
title: $t('page.home.onlineServiceCount'),
tip: $t('page.home.onlineServiceTip'),
value: props.modelValue?.onLineService.total ?? 0,
2024-03-08 17:59:45 +08:00
unit: '',
color: {
2024-03-22 11:22:07 +08:00
start: '#b686d4',
end: '#c5a5d8'
2024-03-08 17:59:45 +08:00
},
2024-03-22 11:22:07 +08:00
icon: 'ant-design:database-outlined',
bottom: [
{
label: $t('page.manage.machine.type.client'),
value: props.modelValue?.onLineService.clientTotal ?? 0
},
{
label: $t('page.manage.machine.type.server'),
value: props.modelValue?.onLineService.serverTotal ?? 0
}
]
2024-03-08 17:59:45 +08:00
},
{
2024-03-22 11:22:07 +08:00
key: 'workflow',
title: $t('page.home.workflow'),
tip: $t('page.home.workflowTip'),
value: 7,
2024-03-08 17:59:45 +08:00
unit: '',
color: {
2024-03-22 11:22:07 +08:00
start: '#ec6f6f',
end: '#f99797'
2024-03-08 17:59:45 +08:00
},
2024-03-22 11:22:07 +08:00
icon: 'ant-design:database-outlined',
bottom: [
{
label: $t('common.success'),
value: 185
},
{
label: $t('common.fail'),
value: 37
},
{
label: $t('common.stop'),
value: 5
},
{
label: $t('common.cancel'),
value: 13
}
]
2024-03-08 17:59:45 +08:00
}
]);
interface GradientBgProps {
gradientColor: string;
}
const [DefineGradientBg, GradientBg] = createReusableTemplate<GradientBgProps>();
function getGradientColor(color: CardData['color']) {
return `linear-gradient(to bottom right, ${color.start}, ${color.end})`;
}
</script>
<template>
2024-03-21 10:57:53 +08:00
<NCard :bordered="false" size="small" class="card-wrapper">
2024-03-08 17:59:45 +08:00
<!-- define component start: GradientBg -->
<DefineGradientBg v-slot="{ $slots, gradientColor }">
2024-03-21 10:57:53 +08:00
<div class="rd-8px px-16px pb-4px pt-8px text-white" :style="{ backgroundImage: gradientColor }">
2024-03-08 17:59:45 +08:00
<component :is="$slots.default" />
</div>
</DefineGradientBg>
<!-- define component end: GradientBg -->
2024-03-21 10:57:53 +08:00
<NGrid cols="s:1 m:2 l:4" responsive="screen" :x-gap="16" :y-gap="16">
<NGi v-for="item in cardData" :key="item.key">
2024-03-22 11:22:07 +08:00
<NSpin :show="false">
<GradientBg :gradient-color="getGradientColor(item.color)" class="h-165px flex-1">
<div class="flex justify-between">
<div class="align-center flex">
<SvgIcon :icon="item.icon" class="text-26px" />
<h3 class="ml-2 text-18px">{{ item.title }}</h3>
</div>
<NPopover trigger="hover">
<template #trigger>
<NButton text>
<SvgIcon icon="ant-design:info-circle-outlined" class="text-20px color-white" />
</NButton>
</template>
{{ item.tip }}
</NPopover>
</div>
<div class="flex pt-12px">
<CountTo :start-value="0" :end-value="item.value" class="text-30px text-white" />
</div>
<NProgress type="line" color="#728bf9" rail-color="#ebebeb" :percentage="30" indicator-text-color="#fff" />
<NDivider />
<template v-for="(bottomItem, bottomIndex) in item.bottom" :key="bottomIndex">
<NDivider v-if="bottomIndex !== 0" vertical />
{{ bottomItem.label }}
<CountTo :start-value="0" :end-value="bottomItem.value" class="text-white" />
</template>
</GradientBg>
</NSpin>
2024-03-21 10:57:53 +08:00
</NGi>
</NGrid>
</NCard>
2024-03-08 17:59:45 +08:00
</template>
2024-03-22 11:22:07 +08:00
<style scoped>
.n-divider {
margin: 16px 0 6px;
}
.n-divider--vertical {
margin: 0 1px 0 5px;
}
</style>