2024-04-21 12:45:12 +08:00
|
|
|
<script setup lang="tsx">
|
|
|
|
import { NButton, NPopconfirm, NTag } from 'naive-ui';
|
2024-04-21 22:03:04 +08:00
|
|
|
import { useBoolean } from '@sa/hooks';
|
2024-06-04 22:56:38 +08:00
|
|
|
import { onMounted, ref } from 'vue';
|
2024-04-21 23:55:16 +08:00
|
|
|
import {
|
|
|
|
fetchBatchDeleteRetryTask,
|
|
|
|
fetchExecuteRetryTask,
|
2024-06-04 22:56:38 +08:00
|
|
|
fetchGetAllGroupNameList,
|
2024-04-29 23:12:14 +08:00
|
|
|
fetchGetRetryTaskById,
|
2024-04-21 23:55:16 +08:00
|
|
|
fetchGetRetryTaskList,
|
|
|
|
fetchUpdateRetryTaskStatus
|
|
|
|
} from '@/service/api';
|
2024-04-21 12:45:12 +08:00
|
|
|
import { $t } from '@/locales';
|
|
|
|
import { useAppStore } from '@/store/modules/app';
|
|
|
|
import { useTable, useTableOperate } from '@/hooks/common/table';
|
|
|
|
import { retryTaskStatusTypeRecord, retryTaskTypeRecord } from '@/constants/business';
|
2024-04-29 23:12:14 +08:00
|
|
|
import { tagColor } from '@/utils/common';
|
2024-04-21 12:45:12 +08:00
|
|
|
import RetryTaskOperateDrawer from './modules/retry-task-operate-drawer.vue';
|
2024-04-21 22:03:04 +08:00
|
|
|
import RetryTaskBatchAddDrawer from './modules/retry-task-batch-add-drawer.vue';
|
2024-04-21 12:45:12 +08:00
|
|
|
import RetryTaskSearch from './modules/retry-task-search.vue';
|
2024-04-29 23:12:14 +08:00
|
|
|
import RetryTaskDetailDrawerVue from './modules/retry-task-detail-drawer.vue';
|
2024-05-04 23:17:20 +08:00
|
|
|
|
|
|
|
/** 详情页属性数据 */
|
|
|
|
const detailData = ref<Api.RetryTask.RetryTask | null>();
|
|
|
|
/** 详情页可见状态 */
|
|
|
|
const { bool: detailVisible, setTrue: openDetail } = useBoolean(false);
|
2024-04-21 12:45:12 +08:00
|
|
|
|
|
|
|
const appStore = useAppStore();
|
|
|
|
|
|
|
|
const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
|
|
|
|
apiFn: fetchGetRetryTaskList,
|
|
|
|
apiParams: {
|
|
|
|
page: 1,
|
|
|
|
size: 10,
|
|
|
|
uniqueId: null,
|
|
|
|
groupName: null,
|
|
|
|
sceneName: null,
|
|
|
|
idempotentId: null,
|
|
|
|
bizNo: null,
|
|
|
|
retryStatus: null
|
|
|
|
},
|
|
|
|
columns: () => [
|
|
|
|
{
|
|
|
|
type: 'selection',
|
|
|
|
align: 'center',
|
|
|
|
width: 48
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'uniqueId',
|
|
|
|
title: $t('page.retryTask.uniqueId'),
|
|
|
|
align: 'left',
|
2024-05-12 10:46:55 +08:00
|
|
|
fixed: 'left',
|
2024-04-29 23:12:14 +08:00
|
|
|
minWidth: 120,
|
|
|
|
render: row => {
|
|
|
|
async function showDetailDrawer() {
|
|
|
|
await loadRetryInfo(row);
|
2024-05-04 23:17:20 +08:00
|
|
|
openDetail();
|
2024-04-29 23:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<n-button text tag="a" type="primary" onClick={showDetailDrawer} class="ws-normal">
|
|
|
|
{row.uniqueId}
|
|
|
|
</n-button>
|
|
|
|
);
|
|
|
|
}
|
2024-04-21 12:45:12 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'groupName',
|
|
|
|
title: $t('page.retryTask.groupName'),
|
2024-05-12 10:46:55 +08:00
|
|
|
align: 'left',
|
|
|
|
resizable: true,
|
|
|
|
minWidth: 120,
|
|
|
|
maxWidth: 250
|
2024-04-21 12:45:12 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'sceneName',
|
|
|
|
title: $t('page.retryTask.sceneName'),
|
2024-05-12 10:46:55 +08:00
|
|
|
align: 'left',
|
2024-04-21 12:45:12 +08:00
|
|
|
minWidth: 120
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'nextTriggerAt',
|
|
|
|
title: $t('page.retryTask.nextTriggerAt'),
|
2024-05-12 10:46:55 +08:00
|
|
|
align: 'left',
|
|
|
|
resizable: true,
|
|
|
|
minWidth: 120,
|
|
|
|
maxWidth: 150
|
2024-04-21 12:45:12 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'retryCount',
|
|
|
|
title: $t('page.retryTask.retryCount'),
|
|
|
|
align: 'center',
|
2024-05-12 10:46:55 +08:00
|
|
|
width: 80
|
2024-04-21 12:45:12 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'retryStatus',
|
|
|
|
title: $t('page.retryTask.retryStatus'),
|
2024-05-12 10:46:55 +08:00
|
|
|
align: 'left',
|
|
|
|
width: 120,
|
2024-04-21 12:45:12 +08:00
|
|
|
render: row => {
|
|
|
|
if (row.retryStatus === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const label = $t(retryTaskStatusTypeRecord[row.retryStatus!]);
|
|
|
|
|
2024-04-29 23:12:14 +08:00
|
|
|
return <NTag type={tagColor(row.retryStatus!)}>{label}</NTag>;
|
2024-04-21 12:45:12 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'taskType',
|
|
|
|
title: $t('page.retryTask.taskType'),
|
2024-05-12 10:46:55 +08:00
|
|
|
align: 'left',
|
|
|
|
width: 100,
|
2024-04-21 12:45:12 +08:00
|
|
|
render: row => {
|
|
|
|
if (row.taskType === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const tagMap: Record<Api.RetryTask.TaskType, NaiveUI.ThemeColor> = {
|
|
|
|
1: 'warning',
|
|
|
|
2: 'error'
|
|
|
|
};
|
|
|
|
const label = $t(retryTaskTypeRecord[row.taskType!]);
|
|
|
|
|
|
|
|
return <NTag type={tagMap[row.taskType!]}>{label}</NTag>;
|
|
|
|
}
|
|
|
|
},
|
2024-05-12 10:46:55 +08:00
|
|
|
{
|
|
|
|
key: 'idempotentId',
|
|
|
|
title: $t('page.retryTask.idempotentId'),
|
|
|
|
align: 'left',
|
|
|
|
resizable: true,
|
|
|
|
minWidth: 150,
|
|
|
|
maxWidth: 300
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'bizNo',
|
|
|
|
title: $t('page.retryTask.bizNo'),
|
|
|
|
align: 'left',
|
|
|
|
resizable: true,
|
|
|
|
minWidth: 150,
|
|
|
|
maxWidth: 300
|
|
|
|
},
|
2024-04-21 12:45:12 +08:00
|
|
|
{
|
|
|
|
key: 'operate',
|
|
|
|
title: $t('common.operate'),
|
2024-05-12 10:46:55 +08:00
|
|
|
align: 'left',
|
2024-04-21 23:55:16 +08:00
|
|
|
width: 260,
|
2024-05-12 10:46:55 +08:00
|
|
|
fixed: 'right',
|
2024-04-21 12:45:12 +08:00
|
|
|
render: row => (
|
|
|
|
<div class="flex-center gap-8px">
|
2024-04-21 23:55:16 +08:00
|
|
|
{/* 非[完成,最大次数], 显示[执行]按钮 */}
|
|
|
|
{row.retryStatus !== 1 && row.retryStatus !== 2 ? (
|
2024-05-26 18:34:05 +08:00
|
|
|
<>
|
|
|
|
<NPopconfirm onPositiveClick={() => handleExecute(row.groupName!, row.uniqueId!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmExecute'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="info" text ghost size="small">
|
|
|
|
{$t('common.execute')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
<n-divider vertical />
|
|
|
|
</>
|
2024-04-21 23:55:16 +08:00
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
|
|
|
{/* 非[完成,最大次数], 显示[完成]按钮 */}
|
|
|
|
{row.retryStatus !== 1 && row.retryStatus !== 2 ? (
|
2024-05-26 18:34:05 +08:00
|
|
|
<>
|
|
|
|
<NPopconfirm onPositiveClick={() => handleFinish(Number(row.id!), row.groupName!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmFinish'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="warning" text ghost size="small">
|
|
|
|
{$t('common.finish')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
<n-divider vertical />
|
|
|
|
</>
|
2024-04-21 23:55:16 +08:00
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
|
|
|
{/* 重试中, 显示[停止]按钮 */}
|
|
|
|
{row.retryStatus === 0 ? (
|
2024-05-26 18:34:05 +08:00
|
|
|
<>
|
|
|
|
<NPopconfirm onPositiveClick={() => handlePause(Number(row.id!), row.groupName!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmPause'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="success" text ghost size="small">
|
|
|
|
{$t('common.pause')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
<n-divider vertical />
|
|
|
|
</>
|
2024-04-21 23:55:16 +08:00
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
|
|
|
{/* 暂停, 显示[开始]按钮 */}
|
|
|
|
{row.retryStatus === 3 ? (
|
2024-05-26 18:34:05 +08:00
|
|
|
<>
|
|
|
|
<NPopconfirm onPositiveClick={() => handleResume(Number(row.id!), row.groupName!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmResume'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="info" text ghost size="small">
|
|
|
|
{$t('common.resume')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
<n-divider vertical />
|
|
|
|
</>
|
2024-04-21 23:55:16 +08:00
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
2024-04-29 23:12:14 +08:00
|
|
|
{
|
|
|
|
<NPopconfirm onPositiveClick={() => handleDelete(row.groupName!, row.id!)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmDelete'),
|
|
|
|
trigger: () => (
|
2024-05-26 18:34:05 +08:00
|
|
|
<NButton type="error" text ghost size="small">
|
2024-04-29 23:12:14 +08:00
|
|
|
{$t('common.delete')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
}
|
2024-04-21 12:45:12 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const {
|
|
|
|
drawerVisible,
|
|
|
|
operateType,
|
|
|
|
handleAdd,
|
|
|
|
checkedRowKeys,
|
2024-04-21 23:55:16 +08:00
|
|
|
onBatchDeleted,
|
2024-04-21 12:45:12 +08:00
|
|
|
onDeleted
|
|
|
|
// closeDrawer
|
|
|
|
} = useTableOperate(data, getData);
|
|
|
|
|
2024-04-21 22:03:04 +08:00
|
|
|
const { bool: batchAddDrawerVisible, setTrue: openBatchAddDrawer } = useBoolean();
|
|
|
|
|
2024-04-21 23:55:16 +08:00
|
|
|
async function handleDelete(groupName: string, id: string) {
|
|
|
|
const { error } = await fetchBatchDeleteRetryTask({ groupName, ids: [id] });
|
|
|
|
if (error) return;
|
2024-04-21 12:45:12 +08:00
|
|
|
|
|
|
|
onDeleted();
|
|
|
|
}
|
|
|
|
|
2024-04-29 23:12:14 +08:00
|
|
|
async function loadRetryInfo(row: Api.RetryTask.RetryTask) {
|
|
|
|
const res = await fetchGetRetryTaskById(row.id!, row.groupName!);
|
|
|
|
detailData.value = (res.data as Api.RetryLog.RetryLog) || null;
|
|
|
|
}
|
|
|
|
|
2024-04-21 23:55:16 +08:00
|
|
|
async function handleBatchDelete() {
|
|
|
|
const ids: string[] = checkedRowKeys.value as string[];
|
|
|
|
if (ids.length === 0) return;
|
|
|
|
const groupName = data.value[0].groupName;
|
|
|
|
const { error } = await fetchBatchDeleteRetryTask({ groupName, ids });
|
|
|
|
if (error) return;
|
|
|
|
|
|
|
|
onBatchDeleted();
|
|
|
|
}
|
|
|
|
|
2024-04-21 22:03:04 +08:00
|
|
|
function handleBatchAdd() {
|
|
|
|
openBatchAddDrawer();
|
|
|
|
}
|
|
|
|
|
2024-04-21 23:55:16 +08:00
|
|
|
function handleExecute(groupName: string, uniqueId: string) {
|
|
|
|
fetchExecuteRetryTask({ groupName, uniqueIds: [uniqueId] });
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleResume(id: number, groupName: string) {
|
|
|
|
updateRetryTaskStatus(id, groupName, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handlePause(id: number, groupName: string) {
|
|
|
|
updateRetryTaskStatus(id, groupName, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleFinish(id: number, groupName: string) {
|
|
|
|
updateRetryTaskStatus(id, groupName, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateRetryTaskStatus(id: number, groupName: string, retryStatus: Api.RetryTask.RetryStatusType) {
|
|
|
|
const { error } = await fetchUpdateRetryTaskStatus({ id, groupName, retryStatus });
|
|
|
|
if (error) return;
|
2024-04-21 22:03:04 +08:00
|
|
|
window.$message?.success($t('common.updateSuccess'));
|
2024-04-21 23:55:16 +08:00
|
|
|
getData();
|
2024-04-21 22:03:04 +08:00
|
|
|
}
|
2024-06-04 22:56:38 +08:00
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
const { error, data: groupList } = await fetchGetAllGroupNameList();
|
|
|
|
if (!error && groupList.length > 0) {
|
|
|
|
searchParams.groupName = groupList[0];
|
|
|
|
getData();
|
|
|
|
}
|
|
|
|
});
|
2024-04-21 12:45:12 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
|
|
|
<RetryTaskSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
|
|
|
|
<NCard
|
|
|
|
:title="$t('page.retryTask.title')"
|
|
|
|
:bordered="false"
|
|
|
|
size="small"
|
|
|
|
class="sm:flex-1-hidden card-wrapper"
|
|
|
|
header-class="view-card-header"
|
|
|
|
>
|
|
|
|
<template #header-extra>
|
2024-05-27 22:50:25 +08:00
|
|
|
<TableHeaderOperation
|
2024-04-21 12:45:12 +08:00
|
|
|
v-model:columns="columnChecks"
|
|
|
|
:disabled-delete="checkedRowKeys.length === 0"
|
|
|
|
:loading="loading"
|
|
|
|
@add="handleAdd"
|
2024-04-21 23:55:16 +08:00
|
|
|
@delete="handleBatchDelete"
|
2024-04-21 12:45:12 +08:00
|
|
|
@refresh="getData"
|
2024-05-27 22:50:25 +08:00
|
|
|
>
|
|
|
|
<template #addAfter>
|
|
|
|
<NButton size="small" ghost type="primary" @click="handleBatchAdd">
|
|
|
|
<template #icon>
|
|
|
|
<icon-ic-round-plus class="text-icon" />
|
|
|
|
</template>
|
|
|
|
{{ $t('common.batchAdd') }}
|
|
|
|
</NButton>
|
|
|
|
</template>
|
|
|
|
</TableHeaderOperation>
|
2024-04-21 12:45:12 +08:00
|
|
|
</template>
|
|
|
|
<NDataTable
|
|
|
|
v-model:checked-row-keys="checkedRowKeys"
|
|
|
|
:columns="columns"
|
|
|
|
:data="data"
|
|
|
|
:flex-height="!appStore.isMobile"
|
2024-05-12 10:46:55 +08:00
|
|
|
:scroll-x="2000"
|
2024-04-21 12:45:12 +08:00
|
|
|
:loading="loading"
|
|
|
|
remote
|
|
|
|
:row-key="row => row.id"
|
|
|
|
:pagination="mobilePagination"
|
|
|
|
class="sm:h-full"
|
|
|
|
/>
|
2024-04-22 22:21:49 +08:00
|
|
|
<RetryTaskOperateDrawer v-model:visible="drawerVisible" :operate-type="operateType" @submitted="getData" />
|
|
|
|
<RetryTaskBatchAddDrawer v-model:visible="batchAddDrawerVisible" @submitted="getData" />
|
2024-04-29 23:12:14 +08:00
|
|
|
<RetryTaskDetailDrawerVue v-model:visible="detailVisible" :row-data="detailData" />
|
2024-04-21 12:45:12 +08:00
|
|
|
</NCard>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|