计算审批流

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

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>
+22 -9
View File
@@ -133,7 +133,7 @@
item-text="text"
item-value="priority"
class="jh-v-input"
label="审批人类型"
label="优先级"
v-model="node.priority"
></v-select>
</v-col>
@@ -141,6 +141,7 @@
<span class="jh-input-label">条件组</span>
<v-dialog
v-model="isConditionGroupShown"
persistent="true"
width="900"
>
<template v-slot:activator="{ on, attrs }">
@@ -174,13 +175,17 @@
@change="changeConditionId($event, item)"></v-select>
</template>
<template v-slot:item.express="{ item }">
<v-select :items="constantObj.operators[item.type]" dense filled single-line class="jh-v-input" v-model="item.express"></v-select>
<v-select :items="constantObj.operators[item.type]" dense filled single-line class="jh-v-input" v-model="item.express"
@change="changeExpress($event, item)"></v-select>
</template>
<template v-slot:item.option-list="{ item }">
<div v-if="item.type == 'number'" class="d-flex align-center">
<div v-if="item.type == 'number'">
<div v-if="item.express == 'between'" class="d-flex align-center">
<v-text-field class="jh-v-input" dense filled v-model="item.option.begin"></v-text-field>
<span> 至 </span>
<v-text-field class="jh-v-input" dense filled v-model="item.option.end"></v-text-field>
</div>
<v-text-field v-else class="jh-v-input" dense filled v-model="item.option"></v-text-field>
</div>
<v-select v-else :items="getOptionList(item)" item-text="text" item-value="value" dense filled class="jh-v-input" v-model="item.option" multiple></v-select>
</template>
@@ -315,8 +320,8 @@
operators: {
'single': [{ text: '包含', value: 'include' }],
'multiple': [{ text: '完全包含', value: 'fullInclude' }, { text: '其一包含', value: 'oneInclude'}],
'number': [{ text: '小于', value: 'less' }, { text: '小于等于', value: 'lessEqual'}, { text: '等于', value: 'equal'},
{ text: '大于等于', value: 'moreEqual'}, { text: '大于', value: 'more'}, { text: '介于(a≤x≤b)', value: 'between'},]
'number': [{ text: '小于', value: '<', value1: 'less' }, { text: '小于等于', value: '<=', value1: 'lessEqual'}, { text: '等于', value: '==', value1: 'equal'},
{ text: '大于等于', value: '>=', value1: 'moreEqual'}, { text: '大于', value: '>', value1: 'more'}, { text: '介于(a≤x≤b)', value: 'between'},]
}
},
@@ -430,14 +435,22 @@
var conditionItem = this.conditions.find(c => c.id == id)
item.type = conditionItem.type || null
item.express = null
item.option = item.type == 'number'? { begin: null, end: null} : null
// item.option = item.type == 'number'? { begin: null, end: null} : null
item.option = null
},
changeExpress(express, item){
if(item.type == 'number' && express == 'between'){
this.$set(item, 'option', { begin: null, end: null})
}else{
this.$set(item, 'option', null)
}
this.$forceUpdate()
console.log('changeExpress', item, express);
},
closeConditionGroupDialog(){
this.$forceUpdate()
this.$emit('reflesh-workflow')
this.isConditionGroupShown = false
},
getOptionList(item){
if(!item.id) return []
@@ -445,7 +458,7 @@
return this.user.map(u => {
return {
text: u.username,
value: u.id
value: u.userId
}
})
}else{
@@ -0,0 +1,119 @@
<template id="form-component-list">
<v-list-item>
<!-- 单选 -->
<v-list-item-content v-if="formItem.type === 'single'">
<template v-if="formItem.optionList.length > 0">
<v-radio-group :disabled='disabled' v-model="formItem.answer" @change="calcWorkflow">
<v-radio hide-details v-for="(option, optionIndex) in formItem.optionList"
:key="optionIndex" :label="option" :value="option"></v-radio>
</v-radio-group>
</template>
<div v-else class="text-caption">请添加选项~</div>
</v-list-item-content>
<!-- 多选 -->
<v-list-item-content v-if="formItem.type === 'multiple'">
<template v-if="formItem.optionList.length > 0">
<div v-for="(option, optionIndex) in formItem.optionList" :key="optionIndex">
<v-checkbox class="mt-0" :disabled='disabled' :label="option" :value="option" hide-details v-model="formItem.answer" @click="calcWorkflow"></v-checkbox>
</div>
</template>
<div v-else class="text-caption">请添加选项~</div>
</v-list-item-content>
<!-- 多行文本 -->
<v-list-item-content v-if="formItem.type === 'textarea'">
<v-textarea class="jh-v-input" dense outlined hide-details :disabled='disabled' :rows="4" placeholder='请输入' v-model="formItem.answer" />
</v-list-item-content>
<!-- 单行文本 -->
<v-list-item-content v-if="formItem.type === 'input'">
<v-text-field class="jh-v-input" dense outlined :disabled='disabled' placeholder='请输入' v-model="formItem.answer"></v-text-field>
</v-list-item-content>
<!-- 文件 -->
<v-list-item-content v-if="formItem.type === 'file'">
<v-file-input chips multiple :disabled='disabled' ></v-file-input>
</v-list-item-content>
<!-- 数字 -->
<v-list-item-content v-if="formItem.type === 'number'">
<v-text-field class="jh-v-input" type="number" dense outlined :disabled='disabled' placeholder='请输入' v-model="formItem.answer" @input="calcWorkflow"></v-text-field>
</v-list-item-content>
<!-- 日期选择器 -->
<v-list-item-content v-if="formItem.type === 'date'">
<v-menu
:close-on-content-click="false"
:nudge-right="40"
transition="scale-transition"
offset-y
min-width="auto"
:disabled='disabled'
>
<template v-slot:activator="{ on, attrs }">
<v-text-field
class="jh-v-input"
dense
single-line
filled
v-bind="attrs"
v-on="on"
placeholder='请选择'
v-model="formItem.answer"
></v-text-field>
</template>
<v-date-picker no-title scrollable></v-date-picker>
</v-menu>
</v-list-item-content>
<!-- 日期时间选择器 -->
<v-list-item-content v-if="formItem.type === 'time'">
<date-time-picker :disabled='disabled' @save-date-time="setDateTime" v-model="formItem.answer"></date-time-picker>
</v-list-item-content>
</v-list-item>
</template>
{% include 'component/common/dateTimePicker.html' %}
<script type="module">
Vue.component("form-component-list", {
template: '#form-component-list',
vuetify: new Vuetify(),
props: {
formItem: {
type: Object,
default: () => {
return {};
},
},
disabled: {
type: Boolean,
default: true,
},
},
data() {
return {
datetime:"2023-12-24 22:23",
}
},
computed: {
},
async created() {
},
methods: {
setDateTime(data){
this.datetime = data
},
async calcWorkflow(){
await this.$emit('calc-workflow')
}
}
})
</script>
<style scoped>
</style>
@@ -69,79 +69,7 @@
</span>
</template>
</div>
<v-list-item>
<!-- 单选 -->
<v-list-item-content v-if="formItem.type === 'single'">
<template v-if="formItem.optionList.length > 0">
<v-radio-group disabled>
<v-radio hide-details v-for="(option, optionIndex) in formItem.optionList"
:key="optionIndex" :label="option" :value="option"></v-radio>
</v-radio-group>
</template>
<div v-else class="text-caption">请添加选项~</div>
</v-list-item-content>
<!-- 多选 -->
<v-list-item-content v-if="formItem.type === 'multiple'">
<template v-if="formItem.optionList.length > 0">
<div v-for="(option, optionIndex) in formItem.optionList" :key="optionIndex">
<v-checkbox hide-details class="mt-0" disabled :label="option" hide-details ></v-checkbox>
</div>
</template>
<div v-else class="text-caption">请添加选项~</div>
</v-list-item-content>
<!-- 多行文本 -->
<v-list-item-content v-if="formItem.type === 'textarea'">
<v-textarea class="jh-v-input" dense outlined hide-details disabled :rows="4" placeholder='请输入' />
</v-list-item-content>
<!-- 单行文本 -->
<v-list-item-content v-if="formItem.type === 'input'">
<v-text-field class="jh-v-input" dense outlined disabled placeholder='请输入'></v-text-field>
</v-list-item-content>
<!-- 文件 -->
<v-list-item-content v-if="formItem.type === 'file'">
<v-file-input chips multiple disabled></v-file-input>
</v-list-item-content>
<!-- 数字 -->
<v-list-item-content v-if="formItem.type === 'number'">
<v-text-field class="jh-v-input" type="number" dense outlined disabled placeholder='请输入'></v-text-field>
</v-list-item-content>
<!-- 日期选择器 -->
<v-list-item-content v-if="formItem.type === 'date'">
<v-menu
:close-on-content-click="false"
:nudge-right="40"
transition="scale-transition"
offset-y
min-width="auto"
disabled
>
<template v-slot:activator="{ on, attrs }">
<v-text-field
class="jh-v-input"
dense
single-line
filled
v-bind="attrs"
v-on="on"
placeholder='请选择'
></v-text-field>
</template>
<v-date-picker no-title scrollable></v-date-picker>
</v-menu>
</v-list-item-content>
<!-- 日期时间选择器 -->
<v-list-item-content v-if="formItem.type === 'time'">
<date-time-picker :disabled='true' @save-date-time="setDateTime"></date-time-picker>
</v-list-item-content>
</v-list-item>
<form-component-list :form-item="formItem" disabled="true"></form-component-list>
</v-card>
</v-hover>
</draggable>
@@ -223,6 +151,8 @@
<script src="//cdn.jsdelivr.net/npm/sortablejs@1.8.4/Sortable.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js"></script>
{% include 'component/tpl/formComponentList.html' %}
<script>
// 1. v-main 滚动条
// 2. v-navigation-drawer 小屏幕 不要关闭
@@ -250,7 +180,7 @@ Vue.component("form-item-list-generator", {
],
tempComponent: null,
selectedFormItemId: null,
datetime:"2023-12-24 22:23"
}),
computed: {
selectCanvaIndex() {
@@ -329,9 +259,7 @@ Vue.component("form-item-list-generator", {
getFormItemList() {
return this.formItemList;
},
setDateTime(data){
this.datetime = data
}
},
})
</script>
+1 -3
View File
@@ -95,12 +95,10 @@
{% include 'component/tpl/tplFormDesign.html' %}
{% include 'component/tpl/formItemListGenerator.html' %}
{% include 'component/tpl/formItemListReview.html' %}
{% include 'component/flow/processFlow.html' %}
{% include 'component/flow/editLine.html' %}
{% include 'component/flow/editNode.html' %}
{% include 'component/workflowBasicInfo.html' %}
{% include 'component/common/dateTimePicker.html' %}
<script type="module">
Vue.component("workflow-editor-drawer", {
template: '#workflow-editor-drawer',
@@ -222,7 +220,7 @@ Vue.component("workflow-editor-drawer", {
}
})).data.appData.resultData;
this.constantObj.userList = rows.map(e => {
return {username: e.username, userId: e.userId, userId: e.userId}
return {username: e.username, userId: e.userId}
})
},
+10 -17
View File
@@ -53,7 +53,7 @@
<template>
<!-- pc端 -->
<template v-if="!isMobile">
<span role="button" class="success--text font-weight-medium font-size-2 mr-2 ml-2" @click="doUiAction('startCreateWorkflow', item)">
<span role="button" class="success--text font-weight-medium font-size-2 mr-2 ml-2" @click="doUiAction('startCreateTask', item)">
<v-icon size="16" class="success--text">mdi-note-edit-outline</v-icon>申请
</span>
<span role="button" class="success--text font-weight-medium font-size-2" @click="doUiAction('openWorkflowEditorDrawer', item)">
@@ -69,7 +69,7 @@
</span>
</template>
<v-list dense>
<v-list-item @click="doUiAction('startCreateWorkflow', item)">
<v-list-item @click="doUiAction('startCreateTask', item)">
<v-list-item-title>申请</v-list-item-title>
</v-list-item>
<v-list-item @click="doUiAction('openWorkflowEditorDrawer', item)">
@@ -99,6 +99,7 @@
<!-- <<<<<<<<<<<<< 页面内容 -->
</div>
<!-- <<<<<<<<<<<<< 创建审批抽屉 -->
<create-task-drawer ref="createTaskDrawer"></create-task-drawer>
<v-navigation-drawer v-model="isCreateDrawerShown" v-click-outside="drawerClickOutside" fixed temporary right width="80%" class="elevation-24">
<v-form v-if="isCreateDrawerShown" ref="createForm" lazy-validation>
<!-- 抽屉标题 -->
@@ -138,7 +139,7 @@
</v-row>
<!--抽屉操作按钮-->
<v-row class="justify-end mx-0 my-8 px-4">
<v-btn color="success" @click="doUiAction('createWorkflow')" small>保存</v-btn>
<v-btn color="success" @click="doUiAction('createTask')" small>保存</v-btn>
<v-btn class="ml-2" @click="isCreateDrawerShown = false" small>取消</v-btn>
</v-row>
</v-form>
@@ -182,6 +183,7 @@
<!-- 加载页面组件 >>>>>>>>>>>>> -->
{% include 'component/formItem.html' %}
{% include 'component/createTaskDrawer.html' %}
{% include 'component/workflowEditorDrawer.html' %}
{% include 'common/jianghuJs/fixedTableHeightV4.html' %}
<!-- <<<<<<<<<<<<< 加载页面组件 -->
@@ -229,11 +231,10 @@
await this.getTableData();
await this.parseTableData();
break;
case 'startCreateWorkflow':
await this.prepareCreateFormData(uiActionData);
await this.openCreateDrawer();
case 'startCreateTask':
await this.openCreateTaskDrawer(uiActionData);
break;
case 'createWorkflow':
case 'createTask':
await this.prepareDoCreateWork();
await this.prepareCreateValidate();
await this.confirmCreateWorkDialog();
@@ -302,16 +303,8 @@
},
// ---------- <<<<<<<<<< 申请项目审核 --------
async prepareCreateFormData(funObj) {
console.log('prepareCreateFormData', funObj);
const { workflowForm, workflowPersonList, workflowId } = funObj;
this.currentWorkflowForm = workflowForm;
this.currentWorkflowPersonList = workflowPersonList;
this.currentWorkflowId = workflowId;
},
async openCreateDrawer() {
this.isCreateDrawerShown = true;
async openCreateTaskDrawer(workflow) {
this.$refs.createTaskDrawer.doUiAction('open', workflow);
},
async prepareDoCreateWork() {
this.currentWorkflowPersonList.forEach(workflowPersonItem => {