auth-web/src/views/monitor/schedulerExecuteLog/utils/hooks.ts

100 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-10-18 13:51:03 +08:00
import { addDialog } from '@/components/BaseDialog/index';
2024-10-18 23:09:48 +08:00
import QuartzExecuteLogDialog from '@/views/monitor/schedulerExecuteLog/quartz-execute-log-dialog.vue';
import { useQuartzExecuteLogStore } from '@/store/monitor/quartzExecuteLog';
2024-10-18 13:51:03 +08:00
import { h, ref } from 'vue';
import { messageBox } from '@/utils/message';
2024-10-18 23:09:48 +08:00
import type { FormItemProps } from '@/views/monitor/schedulerExecuteLog/utils/types';
2024-10-18 13:51:03 +08:00
import { $t } from '@/plugins/i18n';
export const formRef = ref();
// 删除ids
export const deleteIds = ref([]);
const quartzExecuteLogStore = useQuartzExecuteLogStore();
/**
* *
*/
export async function onSearch() {
quartzExecuteLogStore.loading = true;
await quartzExecuteLogStore.getQuartzExecuteLogList();
quartzExecuteLogStore.loading = false;
}
/**
* *
* @param row
*/
export function onUpdate(row: any) {
addDialog({
title: `${$t('modify')}${$t('quartzExecuteLog')}`,
width: '30%',
props: {
formInline: {
jobName: row.jobName,
jobGroup: row.jobGroup,
jobClassName: row.jobClassName,
cronExpression: row.cronExpression,
triggerName: row.triggerName,
executeResult: row.executeResult,
duration: row.duration,
endTime: row.endTime,
},
},
draggable: true,
fullscreenIcon: true,
closeOnClickModal: false,
contentRenderer: () => h(QuartzExecuteLogDialog, { ref: formRef }),
beforeSure: (done, { options }) => {
const form = options.props.formInline as FormItemProps;
formRef.value.formRef.validate(async (valid: any) => {
if (!valid) return;
const result = await quartzExecuteLogStore.updateQuartzExecuteLog({ ...form, id: row.id });
if (!result) return;
done();
await onSearch();
});
},
});
}
/**
* *
*/
export const onDelete = async (row: any) => {
const id = row.id;
// 是否确认删除
const result = await messageBox({
title: $t('confirm_delete'),
showMessage: false,
confirmMessage: undefined,
cancelMessage: $t('cancel_delete'),
});
if (!result) return;
// 删除数据
await quartzExecuteLogStore.deleteQuartzExecuteLog([id]);
await onSearch();
};
/**
*
*/
export const onDeleteBatch = async () => {
const ids = deleteIds.value;
// 是否确认删除
const result = await messageBox({
title: $t('confirm_delete'),
showMessage: false,
confirmMessage: undefined,
cancelMessage: $t('cancel_delete'),
});
if (!result) return;
// 删除数据
await quartzExecuteLogStore.deleteQuartzExecuteLog(ids);
await onSearch();
};