feat: 定时任务批次支持参数传递

This commit is contained in:
dhb52 2024-05-07 00:33:27 +08:00
parent 34424ad9b2
commit 8b15a96ab4
5 changed files with 56 additions and 4 deletions

View File

@ -60,3 +60,12 @@ export function fetchTriggerJob(jobId: string) {
method: 'post'
});
}
/** job name list */
export function fetchGetJobNameList(params?: Api.Job.JobNameListSearchParams) {
return request<Api.Job.Job[]>({
url: '/job/job-name/list',
method: 'get',
params
});
}

View File

@ -980,6 +980,12 @@ declare namespace Api {
/** 2、固定时间 3、CRON表达式 99、工作流 */
type TriggerType = 2 | 3 | 99;
type JobNameListSearchParams = CommonType.RecordNullable<{
groupName?: string;
jobId?: number;
keywords?: string;
}>;
}
/**

View File

@ -1,8 +1,9 @@
<script setup lang="tsx">
import { NButton, NTag } from 'naive-ui';
import { useBoolean } from '@sa/hooks';
import { ref } from 'vue';
import { fetchGetJobBatchList } from '@/service/api';
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { fetchGetJobBatchList, fetchGetJobNameList } from '@/service/api';
import { $t } from '@/locales';
import { useAppStore } from '@/store/modules/app';
import { useTable } from '@/hooks/common/table';
@ -12,6 +13,7 @@ import JobBatchSearch from './modules/job-batch-search.vue';
import JobBatchDetailDrawer from './modules/job-batch-detail-drawer.vue';
const appStore = useAppStore();
const route = useRoute();
/** 详情页属性数据 */
const detailData = ref<Api.JobBatch.JobBatch | null>();
@ -97,6 +99,31 @@ const { columns, data, getData, loading, mobilePagination, searchParams, resetSe
function detail(id: string) {
console.log(id);
}
/** 处理路由 query 参数变化 */
async function handleQueryChanged(jobId: number) {
if (jobId === 0) {
searchParams.jobName = null;
} else {
const { data: jobList, error } = await fetchGetJobNameList({ jobId });
if (!error && jobList.length > 0) {
const jobName = jobList[0].jobName;
searchParams.jobName = jobName;
}
}
getData();
}
watch(
() => route.query,
() => {
if (route.name === 'job_batch' && route.query.jobId) {
const jobId = Number(route.query.jobId);
handleQueryChanged(jobId);
}
},
{ immediate: true }
);
</script>
<template>

View File

@ -1,4 +1,5 @@
<script setup lang="ts">
import SelectGroup from '@/components/common/select-group.vue';
import TaskBatchStatus from '@/components/common/task-batch-status.vue';
import { $t } from '@/locales';
@ -27,7 +28,7 @@ function search() {
<template>
<SearchForm :model="model" @search="search" @reset="reset">
<NFormItemGi span="24 s:12 m:6" :label="$t('page.jobBatch.groupName')" path="groupName" class="pr-24px">
<NInput v-model:value="model.groupName" :placeholder="$t('page.jobBatch.form.groupName')" />
<SelectGroup v-model:value="model.groupName" />
</NFormItemGi>
<NFormItemGi span="24 s:12 m:6" :label="$t('page.jobBatch.jobName')" path="jobName" class="pr-24px">
<NInput v-model:value="model.jobName" :placeholder="$t('page.jobBatch.form.jobName')" />

View File

@ -8,11 +8,13 @@ import { useAppStore } from '@/store/modules/app';
import { useTable, useTableOperate } from '@/hooks/common/table';
import { blockStrategyRecord, taskTypeRecord, triggerTypeRecord } from '@/constants/business';
import StatusSwitch from '@/components/common/status-switch.vue';
import { useRouterPush } from '@/hooks/common/router';
import JobTaskOperateDrawer from './modules/job-task-operate-drawer.vue';
import JobTaskSearch from './modules/job-task-search.vue';
import JobTaskDetailDrawer from './modules/job-task-detail-drawer.vue';
const appStore = useAppStore();
const { routerPushByKey } = useRouterPush();
/** 详情页属性数据 */
const detailData = ref<Api.Job.Job | null>();
@ -162,7 +164,7 @@ const { columns, data, getData, loading, mobilePagination, searchParams, resetSe
key: 'operate',
title: $t('common.operate'),
align: 'center',
width: 130,
width: 260,
render: row => (
<div class="flex-center gap-8px">
<NButton type="primary" ghost size="small" onClick={() => edit(row.id!)}>
@ -188,6 +190,9 @@ const { columns, data, getData, loading, mobilePagination, searchParams, resetSe
)
}}
</NPopconfirm>
<NButton type="primary" ghost size="small" onClick={() => goToBatch(row.id!)}>
{$t('common.batchList')}
</NButton>
</div>
)
}
@ -223,6 +228,10 @@ async function handleTriggerJob(id: string) {
window.$message?.error($t('common.executeFailed'));
}
}
function goToBatch(jobId: string) {
routerPushByKey('job_batch', { query: { jobId } });
}
</script>
<template>