refactor(项目管理): 优化任务中心

This commit is contained in:
wxg0103 2024-03-30 17:52:56 +08:00 committed by Craftsman
parent 813c29a2d3
commit 781d5c5610
3 changed files with 63 additions and 5 deletions

View File

@ -29,6 +29,8 @@
</template> </template>
<template #operation="{ record }"> <template #operation="{ record }">
<a-switch v-model="record.enable" size="small" type="line" /> <a-switch v-model="record.enable" size="small" type="line" />
<a-divider direction="vertical" />
<MsButton class="!mr-0" @click="delSchedule(record)">{{ t('common.delete') }}</MsButton>
<!-- TODO这一版不上 --> <!-- TODO这一版不上 -->
<!-- <a-divider direction="vertical" /> <!-- <a-divider direction="vertical" />
<MsButton class="!mr-0" @click="edit(record)">{{ t('common.edit') }}</MsButton> <MsButton class="!mr-0" @click="edit(record)">{{ t('common.edit') }}</MsButton>
@ -41,27 +43,32 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { Message } from '@arco-design/web-vue';
import dayjs from 'dayjs';
import MsButton from '@/components/pure/ms-button/index.vue'; import MsButton from '@/components/pure/ms-button/index.vue';
import MsBaseTable from '@/components/pure/ms-table/base-table.vue'; import MsBaseTable from '@/components/pure/ms-table/base-table.vue';
import type { BatchActionParams, BatchActionQueryParams, MsTableColumn } from '@/components/pure/ms-table/type'; import type { BatchActionParams, BatchActionQueryParams, MsTableColumn } from '@/components/pure/ms-table/type';
import useTable from '@/components/pure/ms-table/useTable'; import useTable from '@/components/pure/ms-table/useTable';
import MsTableMoreAction from '@/components/pure/ms-table-more-action/index.vue';
import type { ActionsItem } from '@/components/pure/ms-table-more-action/types'; import type { ActionsItem } from '@/components/pure/ms-table-more-action/types';
import { switchDefinitionSchedule } from '@/api/modules/api-test/management';
import { import {
deleteScheduleSysTask,
getScheduleOrgApiCaseList, getScheduleOrgApiCaseList,
getScheduleProApiCaseList, getScheduleProApiCaseList,
getScheduleSysApiCaseList, getScheduleSysApiCaseList,
} from '@/api/modules/project-management/taskCenter'; } from '@/api/modules/project-management/taskCenter';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal';
import { useTableStore } from '@/store'; import { useTableStore } from '@/store';
import { TimingTaskCenterApiCaseItem } from '@/models/projectManagement/taskCenter';
import { TableKeyEnum } from '@/enums/tableEnum'; import { TableKeyEnum } from '@/enums/tableEnum';
import { TaskCenterEnum } from '@/enums/taskCenter'; import { TaskCenterEnum } from '@/enums/taskCenter';
const tableStore = useTableStore(); const tableStore = useTableStore();
const { openModal } = useModal();
const { t } = useI18n(); const { t } = useI18n();
const props = defineProps<{ const props = defineProps<{
@ -128,14 +135,14 @@
slotName: 'nextTime', slotName: 'nextTime',
dataIndex: 'nextTime', dataIndex: 'nextTime',
showInTable: true, showInTable: true,
width: 300, width: 200,
showDrag: true, showDrag: true,
}, },
{ {
title: 'common.operation', title: 'common.operation',
slotName: 'operation', slotName: 'operation',
dataIndex: 'operation', dataIndex: 'operation',
width: 120, width: 180,
fixed: 'right', fixed: 'right',
showDrag: false, showDrag: false,
}, },
@ -159,7 +166,12 @@
heightUsed: 300, heightUsed: 300,
enableDrag: false, enableDrag: false,
showSelectorAll: true, showSelectorAll: true,
} },
// eslint-disable-next-line no-return-assign
(item) => ({
...item,
nextTime: dayjs(item.nextTime).format('YYYY-MM-DD HH:mm:ss'),
})
); );
function initData() { function initData() {
@ -192,6 +204,45 @@
function edit(record: any) {} function edit(record: any) {}
function delSchedule(record: any) {
openModal({
type: 'error',
title: t('project.taskCenter.delSchedule'),
content: t('project.taskCenter.delSchedule.tip'),
okText: t('common.confirmDelete'),
cancelText: t('common.cancel'),
okButtonProps: {
status: 'danger',
},
maskClosable: false,
onBeforeOk: async () => {
try {
await deleteScheduleSysTask(record?.id as string);
Message.success(t('project.taskCenter.delScheduleSuccess'));
initData();
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
},
hideCancel: false,
});
}
async function handleBeforeEnableChange(record: TimingTaskCenterApiCaseItem) {
try {
await switchDefinitionSchedule(record.id);
Message.success(
t(record.enable ? 'apiTestManagement.disableTaskSuccess' : 'apiTestManagement.enableTaskSuccess')
);
return true;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
return false;
}
}
const moreActions: ActionsItem[] = [ const moreActions: ActionsItem[] = [
{ {
label: 'common.delete', label: 'common.delete',

View File

@ -41,4 +41,8 @@ export default {
'project.taskCenter.realTimeTask': 'Real Time Task', 'project.taskCenter.realTimeTask': 'Real Time Task',
'project.taskCenter.createTask': 'create', 'project.taskCenter.createTask': 'create',
'project.taskCenter.apiCaseList': '{type} list', 'project.taskCenter.apiCaseList': '{type} list',
'project.taskCenter.delSchedule': 'Are you sure to delete the scheduled task?',
'project.taskCenter.delScheduleSuccess': 'Delete scheduled task successfully',
'project.taskCenter.delSchedule.tip':
'Deleting the scheduled task will cause the task to stop. Do you want to continue?',
}; };

View File

@ -40,4 +40,7 @@ export default {
'project.taskCenter.realTimeTask': '实时任务', 'project.taskCenter.realTimeTask': '实时任务',
'project.taskCenter.createTask': '创建定时任务', 'project.taskCenter.createTask': '创建定时任务',
'project.taskCenter.apiCaseList': '{type}列表', 'project.taskCenter.apiCaseList': '{type}列表',
'project.taskCenter.delSchedule': '确定删除定时任务吗?',
'project.taskCenter.delScheduleSuccess': '删除定时任务成功',
'project.taskCenter.delSchedule.tip': '删除定时任务会导致任务停止,是否继续?',
}; };