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