1
1
<template >
2
- <div v-loading = " loading " class =" overflow-auto" >
2
+ <div class =" overflow-auto" >
3
3
<SimpleProcessModel
4
4
ref =" simpleProcessModelRef"
5
5
v-if =" processNodeTree"
@@ -56,7 +56,7 @@ const props = defineProps({
56
56
required: false
57
57
},
58
58
// 可发起流程的人员编号
59
- startUserIds : {
59
+ startUserIds: {
60
60
type: Array ,
61
61
required: false
62
62
},
@@ -75,6 +75,7 @@ const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
75
75
const deptOptions = ref <DeptApi .DeptVO []>([]) // 部门列表
76
76
const deptTreeOptions = ref ()
77
77
const userGroupOptions = ref <UserGroupApi .UserGroupVO []>([]) // 用户组列表
78
+ const isDataInitialized = ref (false ) // 添加标记,用于判断数据是否已初始化
78
79
79
80
// 添加当前值的引用
80
81
const currentValue = ref <SimpleFlowNode | undefined >()
@@ -221,9 +222,32 @@ const validateNode = (node: SimpleFlowNode | undefined, errorNodes: SimpleFlowNo
221
222
}
222
223
}
223
224
224
- onMounted (async () => {
225
+ // 初始化数据的方法
226
+ const initializeData = async () => {
227
+ if (isDataInitialized .value ) {
228
+ return
229
+ }
230
+
225
231
try {
226
232
loading .value = true
233
+
234
+ // 并行加载所有数据
235
+ const [roleList, postList, userList, deptList, userGroupList] = await Promise .all ([
236
+ RoleApi .getSimpleRoleList (),
237
+ PostApi .getSimplePostList (),
238
+ UserApi .getSimpleUserList (),
239
+ DeptApi .getSimpleDeptList (),
240
+ UserGroupApi .getUserGroupSimpleList ()
241
+ ])
242
+
243
+ // 更新数据
244
+ roleOptions .value = roleList
245
+ postOptions .value = postList
246
+ userOptions .value = userList
247
+ deptOptions .value = deptList
248
+ deptTreeOptions .value = handleTree (deptList as DeptApi .DeptVO [], ' id' )
249
+ userGroupOptions .value = userGroupList
250
+
227
251
// 获取表单字段
228
252
if (props .modelId ) {
229
253
const bpmnModel = await getModel (props .modelId )
@@ -234,21 +258,7 @@ onMounted(async () => {
234
258
formFields .value = bpmnForm ?.fields
235
259
}
236
260
}
237
- }
238
- // 获得角色列表
239
- roleOptions .value = await RoleApi .getSimpleRoleList ()
240
- // 获得岗位列表
241
- postOptions .value = await PostApi .getSimplePostList ()
242
- // 获得用户列表
243
- userOptions .value = await UserApi .getSimpleUserList ()
244
- // 获得部门列表
245
- deptOptions .value = await DeptApi .getSimpleDeptList ()
246
- deptTreeOptions .value = handleTree (deptOptions .value as DeptApi .DeptVO [], ' id' )
247
- // 获取用户组列表
248
- userGroupOptions .value = await UserGroupApi .getUserGroupSimpleList ()
249
261
250
- // 加载流程数据
251
- if (props .modelId ) {
252
262
// 获取 SIMPLE 设计器模型
253
263
const result = await getBpmSimpleModel (props .modelId )
254
264
if (result ) {
@@ -261,9 +271,27 @@ onMounted(async () => {
261
271
} else {
262
272
updateModel ()
263
273
}
274
+
275
+ isDataInitialized .value = true
276
+ } catch (error ) {
277
+ console .error (' 初始化数据失败:' , error )
264
278
} finally {
265
279
loading .value = false
266
280
}
281
+ }
282
+
283
+ onMounted (async () => {
284
+ await initializeData ()
285
+ })
286
+
287
+ // 添加 activated 生命周期钩子
288
+ onActivated (() => {
289
+ // 组件被激活时,只需要刷新视图
290
+ if (isDataInitialized .value ) {
291
+ refresh ()
292
+ } else {
293
+ initializeData ()
294
+ }
267
295
})
268
296
269
297
const simpleProcessModelRef = ref ()
0 commit comments