2024-04-22 23:58:22 +08:00
|
|
|
<script setup lang="tsx">
|
2024-04-25 16:35:10 +08:00
|
|
|
import { NButton, NPopconfirm, NTag } from 'naive-ui';
|
2024-05-05 10:54:12 +08:00
|
|
|
import { useBoolean } from '@sa/hooks';
|
|
|
|
import { ref } from 'vue';
|
2024-04-25 23:45:29 +08:00
|
|
|
import { fetchDeleteJob, fetchGetJobPage, fetchTriggerJob, fetchUpdateJobStatus } from '@/service/api';
|
2024-04-22 23:58:22 +08:00
|
|
|
import { $t } from '@/locales';
|
|
|
|
import { useAppStore } from '@/store/modules/app';
|
|
|
|
import { useTable, useTableOperate } from '@/hooks/common/table';
|
2024-04-25 02:01:38 +08:00
|
|
|
import { blockStrategyRecord, taskTypeRecord, triggerTypeRecord } from '@/constants/business';
|
2024-04-25 16:35:10 +08:00
|
|
|
import StatusSwitch from '@/components/common/status-switch.vue';
|
2024-05-07 00:33:27 +08:00
|
|
|
import { useRouterPush } from '@/hooks/common/router';
|
2024-05-11 16:18:29 +08:00
|
|
|
import { useAuth } from '@/hooks/business/auth';
|
2024-04-22 23:58:22 +08:00
|
|
|
import JobTaskOperateDrawer from './modules/job-task-operate-drawer.vue';
|
|
|
|
import JobTaskSearch from './modules/job-task-search.vue';
|
2024-05-05 10:54:12 +08:00
|
|
|
import JobTaskDetailDrawer from './modules/job-task-detail-drawer.vue';
|
2024-05-11 16:18:29 +08:00
|
|
|
const { hasAuth } = useAuth();
|
2024-04-22 23:58:22 +08:00
|
|
|
|
|
|
|
const appStore = useAppStore();
|
2024-05-07 00:33:27 +08:00
|
|
|
const { routerPushByKey } = useRouterPush();
|
2024-04-22 23:58:22 +08:00
|
|
|
|
2024-05-05 10:54:12 +08:00
|
|
|
/** 详情页属性数据 */
|
|
|
|
const detailData = ref<Api.Job.Job | null>();
|
|
|
|
/** 详情页可见状态 */
|
|
|
|
const { bool: detailVisible, setTrue: openDetail } = useBoolean(false);
|
|
|
|
|
2024-05-08 00:55:24 +08:00
|
|
|
const { columnChecks, columns, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
|
2024-04-25 02:01:38 +08:00
|
|
|
apiFn: fetchGetJobPage,
|
2024-04-22 23:58:22 +08:00
|
|
|
apiParams: {
|
|
|
|
page: 1,
|
|
|
|
size: 10,
|
|
|
|
groupName: null,
|
|
|
|
jobName: null,
|
|
|
|
jobStatus: null
|
|
|
|
},
|
|
|
|
columns: () => [
|
|
|
|
{
|
|
|
|
key: 'index',
|
|
|
|
title: $t('common.index'),
|
|
|
|
align: 'center',
|
2024-05-22 00:11:44 +08:00
|
|
|
width: 120
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'jobName',
|
|
|
|
title: $t('page.jobTask.jobName'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 140,
|
|
|
|
fixed: 'left',
|
2024-05-05 10:54:12 +08:00
|
|
|
render: row => {
|
|
|
|
async function showDetailDrawer() {
|
|
|
|
detailData.value = row;
|
|
|
|
openDetail();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<n-button text tag="a" type="primary" onClick={showDetailDrawer} class="ws-normal">
|
|
|
|
{row.jobName}
|
|
|
|
</n-button>
|
|
|
|
);
|
|
|
|
}
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'groupName',
|
|
|
|
title: $t('page.jobTask.groupName'),
|
|
|
|
align: 'left',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 180
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'nextTriggerAt',
|
|
|
|
title: $t('page.jobTask.nextTriggerAt'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 120
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'jobStatus',
|
|
|
|
title: $t('page.jobTask.jobStatus'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 60,
|
2024-04-25 02:01:38 +08:00
|
|
|
render: row => {
|
2024-04-25 22:14:58 +08:00
|
|
|
const fetchFn = async (jobStatus: Api.Common.EnableStatusNumber, callback: () => void) => {
|
2024-04-25 21:29:20 +08:00
|
|
|
const { error } = await fetchUpdateJobStatus({ id: row.id!, jobStatus });
|
|
|
|
if (!error) {
|
|
|
|
row.jobStatus = jobStatus;
|
2024-04-25 16:35:10 +08:00
|
|
|
window.$message?.success($t('common.updateSuccess'));
|
|
|
|
}
|
2024-04-25 22:14:58 +08:00
|
|
|
callback();
|
2024-04-25 16:35:10 +08:00
|
|
|
};
|
|
|
|
|
2024-05-05 09:23:45 +08:00
|
|
|
return <StatusSwitch v-model:value={row.jobStatus} onFetch={fetchFn} />;
|
2024-04-25 02:01:38 +08:00
|
|
|
}
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'taskType',
|
|
|
|
title: $t('page.jobTask.taskType'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 120,
|
2024-04-25 02:01:38 +08:00
|
|
|
render: row => {
|
|
|
|
if (row.taskType === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const tagMap: Record<Api.Common.TaskType, NaiveUI.ThemeColor> = {
|
|
|
|
1: 'info',
|
|
|
|
2: 'success',
|
|
|
|
3: 'error'
|
|
|
|
};
|
|
|
|
const label = $t(taskTypeRecord[row.taskType!]);
|
|
|
|
|
|
|
|
return <NTag type={tagMap[row.taskType!]}>{label}</NTag>;
|
|
|
|
}
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'triggerType',
|
|
|
|
title: $t('page.jobTask.triggerType'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 120,
|
2024-04-25 02:01:38 +08:00
|
|
|
render: row => {
|
|
|
|
if (row.triggerType === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const tagMap: Record<Api.Job.TriggerType, NaiveUI.ThemeColor> = {
|
|
|
|
2: 'info',
|
|
|
|
3: 'success',
|
|
|
|
99: 'error'
|
|
|
|
};
|
|
|
|
const label = $t(triggerTypeRecord[row.triggerType!]);
|
|
|
|
|
|
|
|
return <NTag type={tagMap[row.triggerType!]}>{label}</NTag>;
|
|
|
|
}
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'triggerInterval',
|
|
|
|
title: $t('page.jobTask.triggerInterval'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 80
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'blockStrategy',
|
|
|
|
title: $t('page.jobTask.blockStrategy'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 80,
|
2024-04-25 02:01:38 +08:00
|
|
|
render: row => {
|
|
|
|
if (row.blockStrategy === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const tagMap: Record<Api.Common.BlockStrategy, NaiveUI.ThemeColor> = {
|
|
|
|
1: 'info',
|
|
|
|
2: 'success',
|
|
|
|
3: 'error'
|
|
|
|
};
|
|
|
|
const label = $t(blockStrategyRecord[row.blockStrategy!]);
|
|
|
|
|
|
|
|
return <NTag type={tagMap[row.blockStrategy!]}>{label}</NTag>;
|
|
|
|
}
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'executorTimeout',
|
|
|
|
title: $t('page.jobTask.executorTimeout'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 80
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'updateDt',
|
2024-05-08 00:55:24 +08:00
|
|
|
title: $t('page.jobTask.updateDt'),
|
2024-04-22 23:58:22 +08:00
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 120
|
2024-04-22 23:58:22 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'operate',
|
|
|
|
title: $t('common.operate'),
|
|
|
|
align: 'center',
|
2024-05-08 00:55:24 +08:00
|
|
|
width: 180,
|
|
|
|
fixed: 'right',
|
2024-04-22 23:58:22 +08:00
|
|
|
render: row => (
|
|
|
|
<div class="flex-center gap-8px">
|
2024-05-11 21:26:21 +08:00
|
|
|
<NPopconfirm onPositiveClick={() => handleTriggerJob(row.id!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmExecute'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="error" ghost size="small">
|
|
|
|
{$t('common.execute')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
<NButton type="primary" ghost size="small" onClick={() => goToBatch(row.id!)}>
|
|
|
|
{$t('common.batchList')}
|
|
|
|
</NButton>
|
|
|
|
<NButton type="warning" ghost size="small" onClick={() => edit(row.id!)}>
|
2024-04-22 23:58:22 +08:00
|
|
|
{$t('common.edit')}
|
|
|
|
</NButton>
|
2024-05-11 16:18:29 +08:00
|
|
|
{hasAuth('R_ADMIN') ? (
|
|
|
|
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmDelete'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="error" ghost size="small">
|
|
|
|
{$t('common.delete')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
2024-04-22 23:58:22 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const {
|
|
|
|
drawerVisible,
|
|
|
|
operateType,
|
|
|
|
editingData,
|
|
|
|
handleAdd,
|
|
|
|
handleEdit,
|
|
|
|
checkedRowKeys,
|
|
|
|
onDeleted
|
|
|
|
// closeDrawer
|
|
|
|
} = useTableOperate(data, getData);
|
|
|
|
|
2024-04-25 23:45:29 +08:00
|
|
|
async function handleDelete(id: string) {
|
|
|
|
const { error } = await fetchDeleteJob(id);
|
|
|
|
if (error) return;
|
2024-04-22 23:58:22 +08:00
|
|
|
onDeleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
function edit(id: string) {
|
|
|
|
handleEdit(id);
|
|
|
|
}
|
2024-04-25 23:45:29 +08:00
|
|
|
|
|
|
|
async function handleTriggerJob(id: string) {
|
|
|
|
const { error } = await fetchTriggerJob(id);
|
|
|
|
if (error) {
|
|
|
|
window.$message?.error($t('common.executeFailed'));
|
2024-05-11 21:26:21 +08:00
|
|
|
} else {
|
|
|
|
window.$message?.success($t('common.executeSuccess'));
|
2024-04-25 23:45:29 +08:00
|
|
|
}
|
|
|
|
}
|
2024-05-07 00:33:27 +08:00
|
|
|
|
|
|
|
function goToBatch(jobId: string) {
|
|
|
|
routerPushByKey('job_batch', { query: { jobId } });
|
|
|
|
}
|
2024-04-22 23:58:22 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
|
|
|
<JobTaskSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
|
|
|
|
<NCard
|
|
|
|
:title="$t('page.jobTask.title')"
|
|
|
|
:bordered="false"
|
|
|
|
size="small"
|
|
|
|
class="sm:flex-1-hidden card-wrapper"
|
|
|
|
header-class="view-card-header"
|
|
|
|
>
|
|
|
|
<template #header-extra>
|
2024-05-08 00:55:24 +08:00
|
|
|
<TableHeaderOperation
|
|
|
|
v-model:columns="columnChecks"
|
|
|
|
:loading="loading"
|
|
|
|
:show-delete="false"
|
|
|
|
@add="handleAdd"
|
|
|
|
@refresh="getData"
|
|
|
|
/>
|
2024-04-22 23:58:22 +08:00
|
|
|
</template>
|
|
|
|
<NDataTable
|
|
|
|
v-model:checked-row-keys="checkedRowKeys"
|
|
|
|
:columns="columns"
|
|
|
|
:data="data"
|
|
|
|
:flex-height="!appStore.isMobile"
|
2024-05-08 00:55:24 +08:00
|
|
|
:scroll-x="2000"
|
2024-04-22 23:58:22 +08:00
|
|
|
:loading="loading"
|
|
|
|
remote
|
|
|
|
:row-key="row => row.id"
|
|
|
|
:pagination="mobilePagination"
|
|
|
|
class="sm:h-full"
|
|
|
|
/>
|
|
|
|
</NCard>
|
2024-05-08 00:55:24 +08:00
|
|
|
<JobTaskOperateDrawer
|
|
|
|
v-model:visible="drawerVisible"
|
|
|
|
:operate-type="operateType"
|
|
|
|
:row-data="editingData"
|
|
|
|
@submitted="getData"
|
|
|
|
/>
|
2024-05-05 10:54:12 +08:00
|
|
|
<JobTaskDetailDrawer v-model:visible="detailVisible" :row-data="detailData" />
|
2024-04-22 23:58:22 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|