refactor: 流程定义 useBeforeCloseDiff
This commit is contained in:
parent
ad7c33a7d6
commit
ebb4738be7
@ -12,6 +12,7 @@ import {
|
|||||||
workflowDefinitionInfo,
|
workflowDefinitionInfo,
|
||||||
workflowDefinitionUpdate,
|
workflowDefinitionUpdate,
|
||||||
} from '#/api/workflow/definition';
|
} from '#/api/workflow/definition';
|
||||||
|
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||||
|
|
||||||
import { modalSchema } from './data';
|
import { modalSchema } from './data';
|
||||||
|
|
||||||
@ -65,8 +66,16 @@ async function setupCategorySelect() {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||||
|
{
|
||||||
|
initializedGetter: defaultFormValueGetter(formApi),
|
||||||
|
currentGetter: defaultFormValueGetter(formApi),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const [BasicDrawer, modalApi] = useVbenModal({
|
const [BasicDrawer, modalApi] = useVbenModal({
|
||||||
onCancel: handleCancel,
|
onBeforeClose,
|
||||||
|
onCancel: handleClosed,
|
||||||
onConfirm: handleConfirm,
|
onConfirm: handleConfirm,
|
||||||
async onOpenChange(isOpen) {
|
async onOpenChange(isOpen) {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
@ -83,6 +92,7 @@ const [BasicDrawer, modalApi] = useVbenModal({
|
|||||||
const record = await workflowDefinitionInfo(id);
|
const record = await workflowDefinitionInfo(id);
|
||||||
await formApi.setValues(record);
|
await formApi.setValues(record);
|
||||||
}
|
}
|
||||||
|
await markInitialized();
|
||||||
|
|
||||||
modalApi.modalLoading(false);
|
modalApi.modalLoading(false);
|
||||||
},
|
},
|
||||||
@ -90,7 +100,7 @@ const [BasicDrawer, modalApi] = useVbenModal({
|
|||||||
|
|
||||||
async function handleConfirm() {
|
async function handleConfirm() {
|
||||||
try {
|
try {
|
||||||
modalApi.modalLoading(true);
|
modalApi.lock(true);
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
@ -103,17 +113,18 @@ async function handleConfirm() {
|
|||||||
await workflowDefinitionAdd(data);
|
await workflowDefinitionAdd(data);
|
||||||
emit('reload', 'add');
|
emit('reload', 'add');
|
||||||
}
|
}
|
||||||
await handleCancel();
|
resetInitialized();
|
||||||
|
modalApi.close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.modalLoading(false);
|
modalApi.lock(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCancel() {
|
async function handleClosed() {
|
||||||
modalApi.close();
|
|
||||||
await formApi.resetForm();
|
await formApi.resetForm();
|
||||||
|
resetInitialized();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user