feat: 后端发起流程
This commit is contained in:
parent
daf61f7409
commit
3525571fab
@ -63,9 +63,9 @@ export interface StartWorkFlowReqData {
|
||||
*/
|
||||
variables: Record<string, any>;
|
||||
/**
|
||||
* 流程实例业务扩展业务对象
|
||||
* 流程实例业务扩展业务对象 必须要有不能为null 可以为空对象
|
||||
*/
|
||||
flowInstanceBizExtBo?: Record<string, any>;
|
||||
flowInstanceBizExtBo: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface TaskOperationData {
|
||||
|
||||
@ -35,6 +35,7 @@ export interface LeaveVO {
|
||||
*
|
||||
*/
|
||||
status: string;
|
||||
applyCode?: string;
|
||||
}
|
||||
|
||||
export interface LeaveForm extends BaseEntity {
|
||||
|
||||
@ -136,6 +136,14 @@ export const modalSchema: () => VbenFormSchema[] = () => [
|
||||
],
|
||||
},
|
||||
defaultValue: 'frontend',
|
||||
dependencies: {
|
||||
componentProps: (model) => {
|
||||
return {
|
||||
disabled: model.id,
|
||||
};
|
||||
},
|
||||
triggerFields: ['id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '请假类型',
|
||||
|
||||
@ -60,14 +60,22 @@ onMounted(async () => {
|
||||
const router = useRouter();
|
||||
|
||||
/**
|
||||
* 提取通用逻辑
|
||||
* 获取已经处理好的表单参数
|
||||
*/
|
||||
async function handleSaveOrUpdate() {
|
||||
async function getFormData() {
|
||||
let data = cloneDeep(await formApi.getValues()) as any;
|
||||
data = omit(data, 'flowType');
|
||||
data = omit(data, 'flowType', 'type');
|
||||
// 处理日期
|
||||
data.startDate = dayjs(data.dateRange[0]).format('YYYY-MM-DD HH:mm:ss');
|
||||
data.endDate = dayjs(data.dateRange[1]).format('YYYY-MM-DD HH:mm:ss');
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂存/提交 提取通用逻辑
|
||||
*/
|
||||
async function handleSaveOrUpdate() {
|
||||
const data = await getFormData();
|
||||
if (id) {
|
||||
data.id = id;
|
||||
return await leaveUpdate(data);
|
||||
@ -103,37 +111,47 @@ async function handleStartWorkFlow() {
|
||||
}
|
||||
// 获取发起类型
|
||||
const { type } = await formApi.getValues();
|
||||
if (type === 'backend') {
|
||||
let data = cloneDeep(await formApi.getValues()) as any;
|
||||
data = omit(data, 'flowType', 'type');
|
||||
// 处理日期
|
||||
data.startDate = dayjs(data.dateRange[0]).format('YYYY-MM-DD HH:mm:ss');
|
||||
data.endDate = dayjs(data.dateRange[1]).format('YYYY-MM-DD HH:mm:ss');
|
||||
await submitAndStartWorkflow(data);
|
||||
await handleCompleteOrCancel();
|
||||
} else {
|
||||
// 保存业务
|
||||
const leaveResp = await handleSaveOrUpdate();
|
||||
// 启动流程
|
||||
const taskVariables = {
|
||||
leaveDays: leaveResp!.leaveDays,
|
||||
userList: ['1', '3', '4'],
|
||||
};
|
||||
const formValues = await formApi.getValues();
|
||||
const flowCode = formValues?.flowType ?? 'leave1';
|
||||
const startWorkFlowData: StartWorkFlowReqData = {
|
||||
businessId: leaveResp!.id,
|
||||
flowCode,
|
||||
variables: taskVariables,
|
||||
};
|
||||
const { taskId } = await startWorkFlow(startWorkFlowData);
|
||||
// 打开窗口
|
||||
applyModalApi.setData({
|
||||
taskId,
|
||||
taskVariables,
|
||||
variables: {},
|
||||
});
|
||||
applyModalApi.open();
|
||||
/**
|
||||
* 这里只是demo 实际只会用到一种
|
||||
*/
|
||||
switch (type) {
|
||||
// 后端发起流程
|
||||
case 'backend': {
|
||||
const data = await getFormData();
|
||||
await submitAndStartWorkflow(data);
|
||||
await handleCompleteOrCancel();
|
||||
break;
|
||||
}
|
||||
// 前端发起流程
|
||||
case 'frontend': {
|
||||
// 保存业务
|
||||
const leaveResp = await handleSaveOrUpdate();
|
||||
// 启动流程
|
||||
const taskVariables = {
|
||||
leaveDays: leaveResp!.leaveDays,
|
||||
userList: ['1', '3', '4'],
|
||||
};
|
||||
const formValues = await formApi.getValues();
|
||||
const flowCode = formValues?.flowType ?? 'leave1';
|
||||
const startWorkFlowData: StartWorkFlowReqData = {
|
||||
businessId: leaveResp!.id,
|
||||
flowCode,
|
||||
variables: taskVariables,
|
||||
flowInstanceBizExtBo: {
|
||||
businessTitle: '请假申请 - 自定义业务标题',
|
||||
businessCode: leaveResp!.applyCode,
|
||||
},
|
||||
};
|
||||
const { taskId } = await startWorkFlow(startWorkFlowData);
|
||||
// 打开窗口
|
||||
applyModalApi.setData({
|
||||
taskId,
|
||||
taskVariables,
|
||||
variables: {},
|
||||
});
|
||||
applyModalApi.open();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user