提交 | 用户 | 时间
|
3e359e
|
1 |
<template> |
H |
2 |
<div v-loading="loading" class="overflow-auto"> |
|
3 |
<SimpleProcessModel |
|
4 |
v-if="processNodeTree" |
|
5 |
:flow-node="processNodeTree" |
|
6 |
:readonly="false" |
|
7 |
@save="saveSimpleFlowModel" |
|
8 |
/> |
|
9 |
<Dialog v-model="errorDialogVisible" title="保存失败" width="400" :fullscreen="false"> |
|
10 |
<div class="mb-2">以下节点内容不完善,请修改后保存</div> |
|
11 |
<div |
|
12 |
class="mb-3 b-rounded-1 bg-gray-100 p-2 line-height-normal" |
|
13 |
v-for="(item, index) in errorNodes" |
|
14 |
:key="index" |
|
15 |
> |
|
16 |
{{ item.name }} : {{ NODE_DEFAULT_TEXT.get(item.type) }} |
|
17 |
</div> |
|
18 |
<template #footer> |
|
19 |
<el-button type="primary" @click="errorDialogVisible = false">知道了</el-button> |
|
20 |
</template> |
|
21 |
</Dialog> |
|
22 |
</div> |
|
23 |
</template> |
|
24 |
|
|
25 |
<script setup lang="ts"> |
|
26 |
import SimpleProcessModel from './SimpleProcessModel.vue' |
|
27 |
import { updateBpmSimpleModel, getBpmSimpleModel } from '@/api/bpm/simple' |
|
28 |
import { SimpleFlowNode, NodeType, NodeId, NODE_DEFAULT_TEXT } from './consts' |
|
29 |
import { getModel } from '@/api/bpm/model' |
|
30 |
import { getForm, FormVO } from '@/api/bpm/form' |
|
31 |
import { handleTree } from '@/utils/tree' |
|
32 |
import * as RoleApi from '@/api/system/role' |
|
33 |
import * as DeptApi from '@/api/system/dept' |
|
34 |
import * as PostApi from '@/api/system/post' |
|
35 |
import * as UserApi from '@/api/system/user' |
|
36 |
import * as UserGroupApi from '@/api/bpm/userGroup' |
|
37 |
|
|
38 |
defineOptions({ |
|
39 |
name: 'SimpleProcessDesigner' |
|
40 |
}) |
|
41 |
const emits = defineEmits(['success']) // 保存成功事件 |
|
42 |
|
|
43 |
const props = defineProps({ |
|
44 |
modelId: { |
|
45 |
type: String, |
|
46 |
required: true |
|
47 |
} |
|
48 |
}) |
|
49 |
|
|
50 |
const loading = ref(false) |
|
51 |
const formFields = ref<string[]>([]) |
|
52 |
const formType = ref(20) |
|
53 |
const roleOptions = ref<RoleApi.RoleVO[]>([]) // 角色列表 |
|
54 |
const postOptions = ref<PostApi.PostVO[]>([]) // 岗位列表 |
|
55 |
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表 |
|
56 |
const deptOptions = ref<DeptApi.DeptVO[]>([]) // 部门列表 |
|
57 |
const deptTreeOptions = ref() |
|
58 |
const userGroupOptions = ref<UserGroupApi.UserGroupVO[]>([]) // 用户组列表 |
|
59 |
provide('formFields', formFields) |
|
60 |
provide('formType', formType) |
|
61 |
provide('roleList', roleOptions) |
|
62 |
provide('postList', postOptions) |
|
63 |
provide('userList', userOptions) |
|
64 |
provide('deptList', deptOptions) |
|
65 |
provide('userGroupList', userGroupOptions) |
|
66 |
provide('deptTree', deptTreeOptions) |
|
67 |
|
|
68 |
const message = useMessage() // 国际化 |
|
69 |
const processNodeTree = ref<SimpleFlowNode | undefined>() |
|
70 |
const errorDialogVisible = ref(false) |
|
71 |
let errorNodes: SimpleFlowNode[] = [] |
|
72 |
const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => { |
|
73 |
if (!simpleModelNode) { |
|
74 |
message.error('模型数据为空') |
|
75 |
return |
|
76 |
} |
|
77 |
try { |
|
78 |
loading.value = true |
|
79 |
const data = { |
|
80 |
id: props.modelId, |
|
81 |
simpleModel: simpleModelNode |
|
82 |
} |
|
83 |
const result = await updateBpmSimpleModel(data) |
|
84 |
if (result) { |
|
85 |
message.success('修改成功') |
|
86 |
emits('success') |
|
87 |
} else { |
|
88 |
message.alert('修改失败') |
|
89 |
} |
|
90 |
} finally { |
|
91 |
loading.value = false |
|
92 |
} |
|
93 |
} |
|
94 |
// 校验节点设置。 暂时以 showText 为空 未节点错误配置 |
|
95 |
const validateNode = (node: SimpleFlowNode | undefined, errorNodes: SimpleFlowNode[]) => { |
|
96 |
if (node) { |
|
97 |
const { type, showText, conditionNodes } = node |
|
98 |
if (type == NodeType.END_EVENT_NODE) { |
|
99 |
return |
|
100 |
} |
|
101 |
if (type == NodeType.START_USER_NODE) { |
|
102 |
// 发起人节点暂时不用校验,直接校验孩子节点 |
|
103 |
validateNode(node.childNode, errorNodes) |
|
104 |
} |
|
105 |
|
|
106 |
if ( |
|
107 |
type === NodeType.USER_TASK_NODE || |
|
108 |
type === NodeType.COPY_TASK_NODE || |
|
109 |
type === NodeType.CONDITION_NODE |
|
110 |
) { |
|
111 |
if (!showText) { |
|
112 |
errorNodes.push(node) |
|
113 |
} |
|
114 |
validateNode(node.childNode, errorNodes) |
|
115 |
} |
|
116 |
|
|
117 |
if ( |
|
118 |
type == NodeType.CONDITION_BRANCH_NODE || |
|
119 |
type == NodeType.PARALLEL_BRANCH_NODE || |
|
120 |
type == NodeType.INCLUSIVE_BRANCH_NODE |
|
121 |
) { |
|
122 |
// 分支节点 |
|
123 |
// 1. 先校验各个分支 |
|
124 |
conditionNodes?.forEach((item) => { |
|
125 |
validateNode(item, errorNodes) |
|
126 |
}) |
|
127 |
// 2. 校验孩子节点 |
|
128 |
validateNode(node.childNode, errorNodes) |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
onMounted(async () => { |
|
134 |
try { |
|
135 |
loading.value = true |
|
136 |
// 获取表单字段 |
|
137 |
const bpmnModel = await getModel(props.modelId) |
|
138 |
if (bpmnModel) { |
|
139 |
formType.value = bpmnModel.formType |
|
140 |
if (formType.value === 10) { |
|
141 |
const bpmnForm = (await getForm(bpmnModel.formId)) as unknown as FormVO |
|
142 |
formFields.value = bpmnForm?.fields |
|
143 |
} |
|
144 |
} |
|
145 |
// 获得角色列表 |
|
146 |
roleOptions.value = await RoleApi.getSimpleRoleList() |
|
147 |
// 获得岗位列表 |
|
148 |
postOptions.value = await PostApi.getSimplePostList() |
|
149 |
// 获得用户列表 |
|
150 |
userOptions.value = await UserApi.getSimpleUserList() |
|
151 |
// 获得部门列表 |
|
152 |
deptOptions.value = await DeptApi.getSimpleDeptList() |
|
153 |
|
|
154 |
deptTreeOptions.value = handleTree(deptOptions.value as DeptApi.DeptVO[], 'id') |
|
155 |
// 获取用户组列表 |
|
156 |
userGroupOptions.value = await UserGroupApi.getUserGroupSimpleList() |
|
157 |
|
|
158 |
//获取 SIMPLE 设计器模型 |
|
159 |
const result = await getBpmSimpleModel(props.modelId) |
|
160 |
if (result) { |
|
161 |
processNodeTree.value = result |
|
162 |
} else { |
|
163 |
// 初始值 |
|
164 |
processNodeTree.value = { |
|
165 |
name: '发起人', |
|
166 |
type: NodeType.START_USER_NODE, |
|
167 |
id: NodeId.START_USER_NODE_ID, |
|
168 |
childNode: { |
|
169 |
id: NodeId.END_EVENT_NODE_ID, |
|
170 |
name: '结束', |
|
171 |
type: NodeType.END_EVENT_NODE |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
} finally { |
|
176 |
loading.value = false |
|
177 |
} |
|
178 |
}) |
|
179 |
</script> |