<template>
|
<BasicDrawer
|
v-bind="$attrs"
|
@register="registerDrawer"
|
showFooter
|
:title="getTitle"
|
width="600px"
|
@ok="handleSubmit"
|
>
|
<BasicForm @register="registerForm" />
|
</BasicDrawer>
|
</template>
|
<script lang="ts" setup>
|
import { ref, computed, unref } from 'vue';
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
import { formSchema } from './job.data';
|
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
import { useI18n } from '/@/hooks/web/useI18n';
|
import { useMessage } from '/@/hooks/web/useMessage';
|
//api
|
import { SaveTskJob } from '/@/api/tigerapi/tsk/tsk_job';
|
import { TskParameter } from '/@/api/tigerapi/model/tskModel';
|
import { dateUtil } from '/@/utils/dateUtil';
|
import { isNullOrUnDef } from '/@/utils/is';
|
|
const { t } = useI18n();
|
const { notification, createErrorModal } = useMessage();
|
const emit = defineEmits(['success']);
|
const isUpdate = ref(true);
|
|
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
|
labelWidth: 120,
|
schemas: formSchema,
|
showActionButtonGroup: false,
|
});
|
|
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
resetFields();
|
setDrawerProps({ confirmLoading: false });
|
isUpdate.value = !!data?.isUpdate;
|
|
if (unref(isUpdate)) {
|
let tskParam = {} as unknown as TskParameter;
|
const args = JSON.parse(data.record.Triggers[0].Args);
|
tskParam.JobName = data.record.JobName;
|
tskParam.JobType = data.record.JobType;
|
tskParam.AssemblyName = data.record.AssemblyName;
|
tskParam.Remark = data.record.Remark;
|
tskParam.Days = args.Days;
|
tskParam.Hours = args.Hours;
|
tskParam.Minutes = args.Minutes;
|
tskParam.NonReentrant = args.NonReentrant;
|
tskParam.NowAddMinutes = args.NowAddMinutes;
|
tskParam.ToRunEvery = args.ToRunEvery;
|
tskParam.ToRunOnceAtDt = dateUtil(args.ToRunOnceAtDt);
|
tskParam.LastRunTime = dateUtil(data.record.Triggers[0].LastRunTime);
|
tskParam.ToRunOnceIn = args.ToRunOnceIn;
|
tskParam.runType = args.runType;
|
tskParam.Interval = args.Interval;
|
tskParam.ByInterval = isNullOrUnDef(args.ByInterval)?'N':args.ByInterval;
|
tskParam.type = args.Type;
|
|
setFieldsValue({
|
...tskParam,
|
});
|
}
|
});
|
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增任务' : '编辑任务'));
|
|
/**
|
* 提交
|
*/
|
async function handleSubmit() {
|
try {
|
const values = await validate();
|
setDrawerProps({ confirmLoading: true });
|
// TODO custom api
|
//保存任务
|
const apiAction = await SaveTskJob(values);
|
if (apiAction.IsSuccessed) {
|
closeDrawer();
|
emit('success');
|
} else {
|
createErrorModal({
|
title: t('sys.api.errorTip'),
|
content: apiAction.Message,
|
getContainer: () => document.body,
|
});
|
}
|
} finally {
|
setDrawerProps({ confirmLoading: false });
|
}
|
}
|
</script>
|