2025-04-22 10:22:33 +08:00

67 lines
2.2 KiB
TypeScript

import {get, post} from "@/utils/request";
import {hideLoading, showLoading, showToast} from "@/utils/uniapp";
import {isFunction} from "lodash";
export function useProcess() {
const models = ref<any>({})
async function queryActModelApi(param: { key: string }) {
const {result} = await get('/activiti/models/queryActModel', param)
models.value = result[0]
}
async function startDevInstanceApi(param: any) {
return await get('/activiti/instance/startDevInstance', param)
}
async function getMyAllTaskListApi(param: any) {
return await get('/activiti/task/getMyAllTaskList', param)
}
async function completeTaskApi(param: any) {
return await post('/activiti/task/completeTask', param)
}
async function pushProcess(vres: any, param: { comment: string, flag: 1 | 0 }, callback?: Function) {
showLoading({title: '加载中...'})
if (models.value.model_id) {
let procInstId = vres.procInstId
if (!procInstId) {
const res: any = await startDevInstanceApi({modelId: models.value.model_id, formDataId: vres.id})
procInstId = res['result']
}
const gres = await getMyAllTaskListApi({
processInstanceId: procInstId,
pageNo: 1,
pageSize: 1
})
let result = gres.rows;
if (result && result.length > 0) {
let taskData = result[0];
await completeTaskApi(Object.assign({
taskId: taskData.id,
procInstId: taskData.processInstanceId,
formDataId: taskData.formDataId,
}, param))
if (callback && isFunction(callback)) {
hideLoading()
callback()
}
} else {
hideLoading()
showToast({title: '接口异常,请联系开发人员', icon: 'none'})
}
} else {
hideLoading()
showToast({title: 'model_id没有获取到,请联系开发人员,或者重启程序再试', icon: 'none'})
}
}
return {queryActModelApi, pushProcess}
}