计算审批流

This commit is contained in:
ChenXinXin committed 2024-04-24 11:46:38 +08:00
1 parent f6460544f1
commit d418e9b853
6 files changed
+458 -109

No files matched your search

+298
View File
@@ -0,0 +1,298 @@
<template id="create-task-drawer">
<v-card class="pa-4">
<v-navigation-drawer v-model="isDrawerShown" v-if="isDrawerShown" :permanent="isDrawerShown" fixed temporary right width="90%" class="elevation-24">
<!-- 抽屉标题 -->
<v-row no-gutters>
<span class="text-h7 font-weight-bold pa-4">创建审批</span>
</v-row>
<!-- {{taskData.workflowForm}} -->
<!-- 表单 -->
<v-row class="px-4 mt-2">
<v-col cols="12" v-for="(formItem, index) in taskData.workflowForm" :key="index" class="pa-2 ma-0">
<span class="jh-input-label">{{ index + 1 }}. {{ formItem.statement }}<span v-show="formItem.isRequire" class="red--text ml-1">*</span></span>
<form-component-list :form-item="formItem" :disabled='false' @calc-workflow="getWorkflow"></form-component-list>
</v-col>
</v-row>
<v-divider class="jh-divider"></v-divider>
<!-- 审批流 -->
<v-row class="px-4 mt-2">
{{taskData.workflowConfig}}
</v-row>
<v-row class="justify-end mx-0 my-8 px-4">
<!-- 抽屉操作按钮 -->
<div class="d-flex justify-end pr-4">
<v-btn color="success" @click="doUiAction()" small>保存</v-btn>
<v-btn class="elevation-0 ml-2" @click="isDrawerShown = false" small>取消</v-btn>
</div>
</v-row>
<!-- 抽屉关闭按钮 -->
<v-btn elevation="0" color="success" fab absolute top left small tile class="drawer-close-float-btn" @click="isDrawerShown = false">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-navigation-drawer>
</v-card>
</template>
<script type="module">
Vue.component("create-task-drawer", {
template: '#create-task-drawer',
vuetify: new Vuetify(),
data() {
return {
isDrawerShown: false,
// 表格相关数据
isFormValid: true,
validationRules: {
requireRules: [
v => !!v || '必填',
],
},
constantObj: {
userList: [],
groupList: [],
labelList: []
},
isHelpPageDrawerShown: false,
defaultWorkflow: {},
taskData: {}
}
},
computed: {
isMobile() {
return window.innerWidth < 600;
},
},
watch: {
},
async created() {
this.doUiAction('getConstantData');
},
async mounted() {
},
methods: {
async doUiAction(uiActionId, uiActionData) {
switch (uiActionId) {
case 'open':
await this.prepareTaskData(uiActionData);
await this.getWorkflow();
await this.openDrawer();
break;
case 'close':
await this.closeDrawer();
break;
case 'getConstantData':
await this.getUserList();
await this.getGroupList();
await this.getLabelList();
break;
default:
console.error("[doUiAction] uiActionId not find", {uiActionId});
break;
}
},
async prepareTaskData(item) {
if(item) {
let formObj = _.cloneDeep(item);
formObj.workflowInfo = {
workflowName: item.workflowName,
...JSON.parse(item.workflowInfo),
}
formObj.workflowConfig = formObj.workflowConfig ? JSON.parse(formObj.workflowConfig) : null;
formObj.workflowForm = formObj.workflowForm ? (typeof formObj.workflowForm == 'string'? JSON.parse(formObj.workflowForm): formObj.workflowForm) : [];
formObj.workflowForm.forEach(f => f.answer = []) // 兼容多选
this.defaultWorkflow = _.cloneDeep(formObj.workflowConfig);
this.taskData = _.cloneDeep(formObj);
} else {
window.vtoast.fail('[createTaskDrawer] 出错,请联系管理员!');
throw new Error('[createTaskDrawer] 出错,请联系管理员!')
}
},
async openDrawer() {
this.isDrawerShown = true;
},
async closeDrawer() {
this.defaultWorkflow = null;
this.taskData = null;
this.isDrawerShown = false;
},
// -- 获取数据 >>>>>>>>>>> ---------------
/**
* 获取user数据
*/
async getUserList() {
const {rows} = (await window.jianghuAxios({
data: {
appData: {
pageId: 'workflowManagement',
actionId: 'selectUserList',
actionData: {},
where: {},
}
}
})).data.appData.resultData;
this.constantObj.userList = rows.map(e => {
return { username: e.username, userId: e.userId, userId: e.userId }
})
},
/**
* 获取group数据
*/
async getGroupList() {
const {rows} = (await window.jianghuAxios({
data: {
appData: {
pageId: 'workflowManagement',
actionId: 'selectGroupList',
actionData: {},
where: {},
}
}
})).data.appData.resultData;
this.constantObj.groupList = rows.map(e => {
return {groupName: e.groupName, groupId: e.groupId}
});
},
/**
* 获取label数据
*/
async getLabelList() {
const {rows} = (await window.jianghuAxios({
data: {
appData: {
pageId: 'allPage',
actionId: 'selectLabelList',
actionData: {},
where: {},
}
}
})).data.appData.resultData;
this.constantObj.labelList = rows;
},
// -- <<<<<<<<<<<<< 获取数据 --------------------
async getWorkflow(){
this.taskData.workflowConfig = await this.calcWorkflow(this.defaultWorkflow)
},
// 计算审批流
calcWorkflow(workflow = {}){
var newWorkflow = {
nodeList: [],
lineList: []
}
// 先找到开始节点
var beginNode = workflow.nodeList?.find(n => n.properties.type == 'start')
if(!beginNode){
window.vtoast.fail('[calcWorkflow] 审批流不存在开始节点,请联系管理员!')
throw new Error('[calcWorkflow] 审批流不存在开始节点,请联系管理员!')
}
// 再找开始节点的下一个节点
var nextNode = beginNode
newWorkflow.nodeList.push(beginNode)
do{
const { node, prevline } = this.calcNode(workflow, nextNode)
newWorkflow.nodeList.push(node)
newWorkflow.lineList.push(prevline)
nextNode = node
}while(nextNode.properties.type != 'end')
return newWorkflow
},
// 查找传入节点的下一个节点,直到找到结束节点
calcNode(workflow, node){
var lineList = workflow.lineList
var nodeList = workflow.nodeList
var nextNode = null
var prevLine = null
var nextNodeList = []
nextNodeList = _.intersectionWith(nodeList, lineList.filter(line => line.sourceNodeId == node.id),
(node, line) => line.targetNodeId == node.id);
if(nextNodeList.length == 1){
nextNode = nextNodeList[0]
}else if(nextNodeList.length > 1){
if(_.every(nextNodeList, (n) => n.properties.type == 'conditionTask')){
// 条件节点按优先级升序排序,默认条件节点放最后
var nextNodeListbySort = _.sortBy(nextNodeList, (obj) => obj.properties.priority == -1 ? Infinity : obj.properties.priority)
// 判断是否符合条件节点
for(let i = 0; i < nextNodeListbySort.length; i++){
if(nextNodeListbySort[i].properties.priority == -1){
nextNode = nextNode || nextNodeListbySort[i]
}
if(nextNodeListbySort[i].properties.conditionList?.length > 0 && _.every(this.isMatchCondition(nextNodeListbySort[i].properties.conditionList))){
nextNode = nextNode || nextNodeListbySort[i]
}
}
}
}
prevLine = lineList.filter(line => line.sourceNodeId == node.id && line.targetNodeId == nextNode.id)
return {
node: nextNode,
prevline: prevLine[0]
}
},
// 判断是否命中条件节点
isMatchCondition(conditionList){
var isMatch = new Array(conditionList.length)
conditionList.forEach((condition, index) => {
// 申请人
if(condition.id == 'single-applyPerson'){
if(condition.option.includes(`<$ ctx.userInfo.userId $>`)){
isMatch[index] = true
}
}else{
var answer = this.taskData.workflowForm.find(w => w.id == condition.id)?.answer
if(answer.length > 0){
switch (condition.type) {
case 'single':
isMatch[index] = condition.option.includes(answer)
break;
case 'multiple':
if(condition.express == 'fullInclude'){
isMatch[index] = answer.length > 0 && _.intersection(condition.option, answer).length == condition.option.length
}else if(condition.express == 'oneInclude'){
isMatch[index] = answer.length > 0 && _.intersection(answer, condition.option).length > 0
}
break;
case 'number':
if(condition.express != 'between'){
isMatch[index] = eval(answer + condition.express + condition.option)
}else{
if(condition.option.begin <= answer && answer <= condition.option.end){
isMatch[index] = true
}
}
break;
default :
isMatch[index] = false
break;
}
}
}
})
return isMatch
}
}
})
</script>
<style scoped>
</style>