网关判断

This commit is contained in:
xiangheng
2023-12-26 18:56:51 +08:00
parent cd1649e010
commit 26e56f29b8
9 changed files with 285 additions and 214 deletions

View File

@@ -219,6 +219,7 @@ export default {
label: node?.text?.value,
type: node.type,
fieldAuth: node?.properties?.fieldAuth,
gateway: node?.properties?.gateway,
userType: node?.properties?.userType || 0,
userId: node?.properties?.userId || 0,

View File

@@ -29,10 +29,10 @@
<div
class="image-node"
@mousedown.stop.prevent="dragInNode('bpmn:exclusiveGateway', '网关')"
@mousedown.stop.prevent="dragInNode('bpmn:exclusiveGateway', '条件')"
>
<div class="pattern-condition"></div>
<div>网关</div>
<div>条件</div>
</div>
<div class="image-node" @mousedown.stop.prevent="dragInNode('bpmn:endEvent', '结束')">
<div class="pattern-end"></div>

View File

@@ -29,43 +29,7 @@
<div>数据入库</div>
</div>
<div v-if="node.type == 'bpmn:exclusiveGateway'">
<el-alert title="同一父级的网关只能有一个通过" type="warning" />
<!-- 设置优先级 -->
<div style="padding: 40px 0 20px">
<el-select v-model="selectGateway" placeholder="请选择">
<el-option
v-for="item in fieldList"
:key="item.id"
:label="item.label"
:value="item.id"
/>
</el-select>
<el-button type="primary" style="margin-left: 10px" @click="addCondition"
>添加条件</el-button
>
</div>
<el-table fit size="small" :data="GatewayList" style="width: 100%">
<el-table-column prop="label" label="表单"></el-table-column>
<el-table-column label="权限">
<template #default="{ row }">
<el-select v-model="row.condition" placeholder="请选择审批人">
<el-option
v-for="item in conditionList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="值">
<template #default="{ row }">
<el-input v-model="row.conditionValue" placeholder="请输入"></el-input>
</template>
</el-table-column>
</el-table>
<Gateway :node="node" :properties="properties" :fieldList="fieldList"></Gateway>
</div>
<div v-if="node.type == 'bpmn:endEvent'">结束</div>
@@ -75,12 +39,15 @@
<script>
import UserTask from './PropertyPanel/UserTask.vue'
import FieldAuth from './PropertyPanel/FieldAuth.vue'
import Gateway from './PropertyPanel/Gateway.vue'
export default {
name: 'PropertyPanel',
props: {},
components: {
UserTask,
FieldAuth
FieldAuth,
Gateway
},
data() {
return {
@@ -93,7 +60,8 @@ export default {
deptId: '', //审批部门id
postId: '', //岗位id
fieldAuth: {} // 字段权限
fieldAuth: {}, // 字段权限
gateway: [] //网关条件列表
},
/**
* 表单列表
@@ -103,29 +71,7 @@ export default {
* auth: 1,
* }]
*/
fieldList: [],
// 网关条件列表
GatewayList: [],
selectGateway: '',
conditionList: [
{
value: '=',
label: '等于'
},
{
value: '>=',
label: '大于等于'
},
{
value: '<=',
label: '小于等于'
},
{
value: 'include',
label: '包含'
}
]
fieldList: []
}
},
@@ -138,6 +84,8 @@ export default {
this.properties.deptId = node?.properties?.deptId || ''
this.properties.postId = node?.properties?.postId || ''
this.properties.gateway = node?.properties?.gateway || []
this.properties.fieldAuth = node?.properties?.fieldAuth
? { ...node?.properties?.fieldAuth }
: {}
@@ -161,69 +109,22 @@ export default {
this.fieldList.forEach((item) => {
fieldAuth[item.id] = item.auth
})
this.$emit('setProperties', this.node, { ...this.properties })
this.setProperties('fieldAuth', {
...fieldAuth
})
this.setProperties('userType', this.properties.userType)
this.setProperties('userId', this.properties.userId)
this.setProperties('deptId', this.properties.deptId)
this.setProperties('postId', this.properties.postId)
// this.setProperties('fieldAuth', {
// ...fieldAuth
// })
// this.setProperties('userType', this.properties.userType)
// this.setProperties('userId', this.properties.userId)
// this.setProperties('deptId', this.properties.deptId)
// this.setProperties('postId', this.properties.postId)
// this.setProperties('gateway', this.properties.gateway)
},
// getAdminList() {
// adminLists().then((res) => {
// console.log('res', res)
// this.adminUserList = res.lists.map((item) => {
// return {
// value: item.id,
// label: item.nickname
// }
// })
// })
// },
// getDeptList() {
// deptLists().then((res) => {
// console.log('res', res)
// this.deptList = res.map((item) => {
// return {
// value: item.id,
// label: item.name
// }
// })
// })
// },
// getPostList() {
// postAll().then((res) => {
// console.log('res', res)
// this.postList = res.map((item) => {
// return {
// value: item.id,
// label: item.name
// }
// })
// })
// },
setProperties(key, val) {
this.$emit('setProperties', this.node, {
[key]: val
})
},
addCondition() {
// this.selectGateway
this.fieldList.find((item) => {
if (item.id === this.selectGateway) {
// item.condition = this.GatewayList[this.GatewayList.length - 1].condition
// item.value = this.GatewayList[this.GatewayList.length - 1].value
this.GatewayList.push({
id: item.id,
label: item.label,
value: '',
condition: ''
})
}
})
}
}
}

View File

@@ -0,0 +1,119 @@
<template>
<div style="padding-bottom: 10px">
<el-card header="条件编辑">
<el-alert title="同一父级的网关只能有一个通过" type="warning" />
<!-- 设置优先级 -->
<div style="padding: 40px 0 20px">
<el-select v-model="selectGateway" placeholder="请选择">
<el-option
v-for="item in fieldList"
:key="item.id"
:label="item.label"
:value="item.id"
/>
</el-select>
<el-button type="primary" style="margin-left: 10px" @click="addCondition"
>添加条件</el-button
>
</div>
<el-table fit size="small" :data="props.properties.gateway" style="width: 100%">
<el-table-column prop="label" label="表单项">
<template #default="{ row }">
{{ getLabel(row.id) }}
</template>
</el-table-column>
<el-table-column label="权限">
<template #default="{ row }">
<el-select v-model="row.condition" placeholder="请选择判断符">
<el-option
v-for="item in conditionList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="值">
<template #default="{ row }">
<el-input v-model="row.value" placeholder="请输入"></el-input>
</template>
</el-table-column>
<el-table-column width="50px">
<template #default="{ row, $index }">
<el-button :icon="Close" circle @click="removeCondition(row, $index)" />
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</template>
<script setup>
import { defineProps, ref } from 'vue'
import { Close } from '@element-plus/icons-vue'
const props = defineProps({
node: {
type: Object,
default: () => ({})
},
fieldList: {
type: Array,
default: () => []
},
properties: {
type: Object,
default: () => ({})
}
})
const conditionList = [
{
value: '==',
label: '等于'
},
{
value: '!=',
label: '不等于'
},
{
value: '>=',
label: '大于等于'
},
{
value: '<=',
label: '小于等于'
},
{
value: 'include',
label: '包含'
}
]
const selectGateway = ref('')
function getLabel(id) {
return props.fieldList.find((item) => {
if (item.id === id) {
return item.label
}
})?.label
}
function addCondition() {
// this.selectGateway
props.fieldList.find((item) => {
if (item.id === selectGateway.value) {
props.properties.gateway.push({
id: item.id,
value: '',
condition: ''
})
}
})
}
function removeCondition(row, $index) {
props.properties.gateway.splice($index, 1)
}
</script>
<style lang="scss" scoped></style>

View File

@@ -1,10 +1,10 @@
// 基础图形
import CircleNode from "./basic/CircleNode";
import RectNode from "./basic/RectNode";
import RectRadiusNode from "./basic/RectRadiusNode";
import EllipseNode from "./basic/EllipseNode";
import TextNode from "./basic/TextNode";
import DiamondNode from "./basic/DiamondNode";
// import CircleNode from './basic/CircleNode'
// import RectNode from './basic/RectNode'
// import RectRadiusNode from './basic/RectRadiusNode'
// import EllipseNode from './basic/EllipseNode'
// import TextNode from './basic/TextNode'
// import DiamondNode from './basic/DiamondNode'
// // path绘制的个性化图形
// import CylindeNode from './path/CylindeNode'
// import TriangleNode from './path/TriangleNode'
@@ -31,17 +31,17 @@ import DiamondNode from "./basic/DiamondNode";
// image绘制左上角icon节点
// import IconMessage from './icon/Message'
// 注册边
import Ployline from "./edge/Polyline";
import Line from "./edge/Line";
import Bezier from "./edge/Bezier";
import Ployline from './edge/Polyline'
import Line from './edge/Line'
import Bezier from './edge/Bezier'
export const List = [
// office_network,
// firewall,
// router,
// coreSwitch,
];
console.log(List);
]
console.log(List)
export const registerCustomElement = (lf) => {
// 注册基础图形
// lf.register(CircleNode);
@@ -51,16 +51,15 @@ export const registerCustomElement = (lf) => {
// lf.register(DiamondNode);
// lf.register(TextNode);
// lf.register(status_error);
List.forEach((item) => {
lf.register({
type: item.type,
view: item.view,
model: item.model,
});
});
model: item.model
})
})
// // 注册path绘制的个性化图形
// lf.register(CylindeNode)
@@ -97,7 +96,7 @@ export const registerCustomElement = (lf) => {
// // 注册image绘制左上角icon节点
// lf.register(IconMessage)
// // 注册边
lf.register(Ployline);
lf.register(Line);
lf.register(Bezier);
};
lf.register(Ployline)
lf.register(Line)
lf.register(Bezier)
}

View File

@@ -48,7 +48,7 @@
<template #footer>
<el-button @click="dialogVisible = false">关闭</el-button>
<el-button type="primary" @click="getData"> 通过 </el-button>
<el-button type="primary" @click="submit"> 通过 </el-button>
</template>
</el-dialog>
</template>
@@ -63,7 +63,6 @@ import {
} from '@/api/flow/flow_history'
const dialogVisible = ref(false)
// const props = defineProps({
// save: {
// type: Function,
@@ -102,11 +101,6 @@ function open(applyId) {
}).then((res) => {
console.log('res', res)
next_nodes.value = res
// res.map((item) => {
// if (item.type == 'bpmn:userTask') {
// }
// })
})
flow_history_get_approver({ applyId: applyId }).then((user) => {
console.log('user', user)
@@ -118,8 +112,8 @@ function BeforeClose() {
// formData = {}
}
function getData() {
console.log('getData', next_nodes)
function submit() {
console.log('submit', next_nodes)
if (userTask.value && !formData.applyUserId) {
feedback.msgWarning('请选择审批人')
@@ -132,18 +126,8 @@ function getData() {
}).then(() => {
BeforeClose()
})
// formRef.value.getFormData().then((formData) => {
// console.log('formData', formData)
// props
// .save(formData)
// .then(() => {
// BeforeClose()
// })
// .catch(() => {})
// })
}
defineExpose({
getData,
open
})
</script>

View File

@@ -3,8 +3,11 @@
"gocode",
"gonic",
"gorm",
"x_admin",
"Infof",
"jinzhu",
"mapstructure",
"rmvb"
"rmvb",
"Warnf",
"x_admin"
]
}

View File

@@ -72,6 +72,12 @@ type FlowHistoryResp struct {
CreateTime core.TsTime `json:"createTime" structs:"createTime"` // 创建时间
}
type gateway struct {
// 网关节点
Id string `json:"id"`
Condition string `json:"condition"`
Value string `json:"value"`
}
type FlowTree struct {
Id string `json:"id"`
Pid string `json:"pid"`
@@ -85,6 +91,8 @@ type FlowTree struct {
FieldAuth map[string]int `json:"fieldAuth"`
Gateway *[]gateway
Children *[]FlowTree `json:"children"`
}
type NextNodeReq struct {

View File

@@ -3,6 +3,8 @@ package flow_history
import (
"encoding/json"
"errors"
"fmt"
"strconv"
"x_admin/admin/flow/flow_apply"
"x_admin/admin/system/admin"
"x_admin/admin/system/dept"
@@ -390,12 +392,66 @@ func DeepNextNode(nextNodes []FlowTree, flowTree *[]FlowTree, formValue map[stri
break
} else if v.Type == "bpmn:exclusiveGateway" {
// 网关
// v.Gateway
var haveFalse = false
var gateway = *v.Gateway
for i := 0; i < len(gateway); i++ {
var id = gateway[i].Id
var value = gateway[i].Value
var condition = gateway[i].Condition
if condition == "==" {
if formValue[id].(string) == value { // 等与
} else {
haveFalse = true
}
} else if condition == "!=" {
if formValue[id].(string) != value { // 不等与
} else {
haveFalse = true
}
} else if condition == ">=" {
var val, err = strconv.Atoi(value)
if err != nil {
fmt.Println(err)
continue
}
var formVal = formValue[id].(int64)
if formVal >= int64(val) { // 大于等于
} else {
haveFalse = true
}
} else if condition == "<=" {
var val, err = strconv.Atoi(value)
if err != nil {
fmt.Println(err)
continue
}
var formVal = formValue[id].(int64)
if formVal <= int64(val) { // 小于等于
} else {
haveFalse = true
}
} else {
haveFalse = true
fmt.Println("未知的条件")
}
}
// 不满足条件,继续循环
if haveFalse {
continue
} else {
// 判断formValue值决定是不是递归这个网关
child := DeepNextNode(nextNodes, v.Children, formValue)
nextNodes = append(nextNodes, v)
nextNodes = append(nextNodes, child...)
break
}
} else if v.Type == "bpmn:serviceTask" {
// 系统服务
child := DeepNextNode(nextNodes, v.Children, formValue)