feat(sj_1.0.0_beta4): 首页任务Card添加点击动作

This commit is contained in:
xlsea 2024-06-03 10:43:45 +08:00
parent d45fb15e9f
commit 2e350c0ea8
4 changed files with 51 additions and 34 deletions

View File

@ -21,10 +21,11 @@ export function useRouterPush(inSetup = true) {
interface RouterPushOptions { interface RouterPushOptions {
query?: Record<string, string>; query?: Record<string, string>;
params?: Record<string, string>; params?: Record<string, string>;
state?: Record<string, string>;
} }
async function routerPushByKey(key: RouteKey, options?: RouterPushOptions) { async function routerPushByKey(key: RouteKey, options?: RouterPushOptions) {
const { query, params } = options || {}; const { query, params, state } = options || {};
const routeLocation: RouteLocationRaw = { const routeLocation: RouteLocationRaw = {
name: key name: key
@ -38,6 +39,10 @@ export function useRouterPush(inSetup = true) {
routeLocation.params = params; routeLocation.params = params;
} }
if (state) {
routeLocation.state = state;
}
return routerPush(routeLocation); return routerPush(routeLocation);
} }

View File

@ -77,20 +77,18 @@ const props = withDefaults(defineProps<Props>(), {
}) })
}); });
/** 卡片 key 类型, 与卡片的路由的 name 一致, 便于直接使用 routerPushByKey */
type KeyType = 'job_task' | 'retry_task' | 'workflow_task' | 'pods';
interface CardData { interface CardData {
key: KeyType; key: string;
title: string; title: string;
tip: string; tip: string;
value: number; value: number;
click?: () => void;
color: { color: {
start: string; start: string;
end: string; end: string;
}; };
icon: string; icon: string;
bottom: { label: string; value: number }[]; bottom: { label: string; value: number; click?: () => void }[];
} }
// eslint-disable-next-line complexity // eslint-disable-next-line complexity
@ -100,6 +98,7 @@ const cardData = computed<CardData[]>(() => [
title: $t('page.home.jobTask'), title: $t('page.home.jobTask'),
tip: $t('page.home.jobTaskTip'), tip: $t('page.home.jobTaskTip'),
value: props.modelValue?.jobTask.totalNum ?? 0, value: props.modelValue?.jobTask.totalNum ?? 0,
click: () => routerPushByKey('job_task'),
color: { color: {
start: '#f5b386', start: '#f5b386',
end: '#FFD6BA' end: '#FFD6BA'
@ -108,19 +107,23 @@ const cardData = computed<CardData[]>(() => [
bottom: [ bottom: [
{ {
label: $t('common.success'), label: $t('common.success'),
value: props.modelValue?.jobTask.successNum ?? 0 value: props.modelValue?.jobTask.successNum ?? 0,
click: () => routerPushByKey('job_batch', { state: { taskBatchStatus: '3' } })
}, },
{ {
label: $t('common.fail'), label: $t('common.fail'),
value: props.modelValue?.jobTask.failNum ?? 0 value: props.modelValue?.jobTask.failNum ?? 0,
click: () => routerPushByKey('job_batch', { state: { taskBatchStatus: '4' } })
}, },
{ {
label: $t('common.stop'), label: $t('common.stop'),
value: props.modelValue?.jobTask.stopNum ?? 0 value: props.modelValue?.jobTask.stopNum ?? 0,
click: () => routerPushByKey('job_batch', { state: { taskBatchStatus: '5' } })
}, },
{ {
label: $t('common.cancel'), label: $t('common.cancel'),
value: props.modelValue?.jobTask.cancelNum ?? 0 value: props.modelValue?.jobTask.cancelNum ?? 0,
click: () => routerPushByKey('job_batch', { state: { taskBatchStatus: '6' } })
} }
] ]
}, },
@ -129,6 +132,7 @@ const cardData = computed<CardData[]>(() => [
title: $t('page.home.retryTask'), title: $t('page.home.retryTask'),
tip: $t('page.home.retryTaskTip'), tip: $t('page.home.retryTaskTip'),
value: props.modelValue?.retryTask.totalNum ?? 0, value: props.modelValue?.retryTask.totalNum ?? 0,
click: () => routerPushByKey('retry_task'),
unit: '', unit: '',
color: { color: {
start: '#40e9c5', start: '#40e9c5',
@ -159,6 +163,7 @@ const cardData = computed<CardData[]>(() => [
title: $t('page.home.workflow'), title: $t('page.home.workflow'),
tip: $t('page.home.workflowTip'), tip: $t('page.home.workflowTip'),
value: props.modelValue?.workFlowTask.totalNum, value: props.modelValue?.workFlowTask.totalNum,
click: () => routerPushByKey('workflow_task'),
unit: '', unit: '',
color: { color: {
start: '#ec6f6f', start: '#ec6f6f',
@ -189,6 +194,7 @@ const cardData = computed<CardData[]>(() => [
title: $t('page.home.onlineServiceCount'), title: $t('page.home.onlineServiceCount'),
tip: $t('page.home.onlineServiceTip'), tip: $t('page.home.onlineServiceTip'),
value: props.modelValue?.onLineService.total ?? 0, value: props.modelValue?.onLineService.total ?? 0,
click: () => routerPushByKey('pods'),
unit: '', unit: '',
color: { color: {
start: '#b686d4', start: '#b686d4',
@ -234,11 +240,8 @@ function getGradientColor(color: CardData['color']) {
<NGrid :cols="gridCol" responsive="screen" :x-gap="16" :y-gap="16"> <NGrid :cols="gridCol" responsive="screen" :x-gap="16" :y-gap="16">
<NGi v-for="item in cardData" :key="item.key"> <NGi v-for="item in cardData" :key="item.key">
<NSpin :show="false"> <NSpin :show="false">
<GradientBg <GradientBg :gradient-color="getGradientColor(item.color)" class="h-165px flex-1">
:gradient-color="getGradientColor(item.color)" <div :class="item.click ? 'cursor-pointer' : null" @click="item.click">
class="h-165px flex-1 cursor-pointer"
@click="routerPushByKey(item.key)"
>
<div class="flex justify-between"> <div class="flex justify-between">
<div class="align-center flex"> <div class="align-center flex">
<SvgIcon :icon="item.icon" class="text-26px" /> <SvgIcon :icon="item.icon" class="text-26px" />
@ -256,6 +259,7 @@ function getGradientColor(color: CardData['color']) {
<div class="flex"> <div class="flex">
<CountTo :start-value="0" :end-value="item.value" class="text-30px text-white" /> <CountTo :start-value="0" :end-value="item.value" class="text-30px text-white" />
</div> </div>
</div>
<NProgress <NProgress
v-if="item.key === 'job_task'" v-if="item.key === 'job_task'"
class="mb-24px h-20px pt-18px" class="mb-24px h-20px pt-18px"
@ -279,8 +283,10 @@ function getGradientColor(color: CardData['color']) {
<NDivider /> <NDivider />
<template v-for="(bottomItem, bottomIndex) in item.bottom" :key="bottomIndex"> <template v-for="(bottomItem, bottomIndex) in item.bottom" :key="bottomIndex">
<NDivider v-if="bottomIndex !== 0" vertical /> <NDivider v-if="bottomIndex !== 0" vertical />
<span :class="bottomItem.click ? 'cursor-pointer' : null" @click="bottomItem.click">
{{ bottomItem.label }} {{ bottomItem.label }}
<CountTo :start-value="0" :end-value="bottomItem.value" class="text-white" /> <CountTo :start-value="0" :end-value="bottomItem.value" class="text-white" />
</span>
</template> </template>
</GradientBg> </GradientBg>
</NSpin> </NSpin>
@ -295,7 +301,7 @@ function getGradientColor(color: CardData['color']) {
} }
.n-divider--vertical { .n-divider--vertical {
margin: 0 1px 0 5px; margin: 0 5px 0 5px;
} }
:deep(.n-progress-icon--as-text) { :deep(.n-progress-icon--as-text) {

View File

@ -23,6 +23,12 @@ function reset() {
function search() { function search() {
emit('search'); emit('search');
} }
const taskBatchStatus = history.state.taskBatchStatus;
if (taskBatchStatus) {
model.value.taskBatchStatus = Number(taskBatchStatus) as Api.Common.TaskBatchStatus;
}
</script> </script>
<template> <template>

View File

@ -13,7 +13,7 @@ onMounted(() => {
}); });
const node = ref<Flow.NodeDataType>({ const node = ref<Flow.NodeDataType>({
workflowName: `Workflow ${new Date().getTime()}`, workflowName: `WF-${new Date().getTime()}`,
workflowStatus: 1, workflowStatus: 1,
blockStrategy: 1, blockStrategy: 1,
description: undefined, description: undefined,