Skip to content

Commit c3ad1ec

Browse files
authored
Merge pull request #139 from minivv/master
【Simple设计器】流程模型->基本信息->谁可以发起,支持指定多个部门
2 parents 80ac4b0 + 1b3cbfc commit c3ad1ec

File tree

8 files changed

+279
-22
lines changed

8 files changed

+279
-22
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<template>
2+
<Dialog v-model="dialogVisible" title="部门选择" width="600">
3+
<el-row v-loading="formLoading">
4+
<el-col :span="24">
5+
<ContentWrap class="h-1/1">
6+
<el-tree
7+
ref="treeRef"
8+
:data="deptTree"
9+
:props="defaultProps"
10+
show-checkbox
11+
:check-strictly="checkStrictly"
12+
check-on-click-node
13+
default-expand-all
14+
highlight-current
15+
node-key="id"
16+
@check="handleCheck"
17+
/>
18+
</ContentWrap>
19+
</el-col>
20+
</el-row>
21+
<template #footer>
22+
<el-button
23+
:disabled="formLoading || !selectedDeptIds?.length"
24+
type="primary"
25+
@click="submitForm"
26+
>
27+
确 定
28+
</el-button>
29+
<el-button @click="dialogVisible = false">取 消</el-button>
30+
</template>
31+
</Dialog>
32+
</template>
33+
34+
<script lang="ts" setup>
35+
import { defaultProps, handleTree } from '@/utils/tree'
36+
import * as DeptApi from '@/api/system/dept'
37+
38+
defineOptions({ name: 'DeptSelectForm' })
39+
40+
const emit = defineEmits<{
41+
confirm: [deptList: any[]]
42+
}>()
43+
44+
const { t } = useI18n() // 国际化
45+
const message = useMessage() // 消息弹窗
46+
47+
const props = defineProps({
48+
// 是否严格的遵循父子不互相关联
49+
checkStrictly: {
50+
type: Boolean,
51+
default: false
52+
},
53+
// 是否支持多选
54+
multiple: {
55+
type: Boolean,
56+
default: true
57+
}
58+
})
59+
60+
const treeRef = ref()
61+
const deptTree = ref<Tree[]>([]) // 部门树形结构
62+
const selectedDeptIds = ref<number[]>([]) // 选中的部门ID列表
63+
const dialogVisible = ref(false) // 弹窗的是否展示
64+
const formLoading = ref(false) // 表单的加载中
65+
66+
/** 打开弹窗 */
67+
const open = async (selectedList?: DeptApi.DeptVO[]) => {
68+
resetForm()
69+
formLoading.value = true
70+
try {
71+
// 加载部门列表
72+
const deptData = await DeptApi.getSimpleDeptList()
73+
deptTree.value = handleTree(deptData)
74+
} finally {
75+
formLoading.value = false
76+
}
77+
dialogVisible.value = true
78+
// 设置已选择的部门
79+
if (selectedList?.length) {
80+
await nextTick()
81+
const selectedIds = selectedList.map(dept => dept.id).filter((id): id is number => id !== undefined)
82+
selectedDeptIds.value = selectedIds
83+
treeRef.value?.setCheckedKeys(selectedIds)
84+
}
85+
}
86+
87+
/** 处理选中状态变化 */
88+
const handleCheck = (data: any, checked: any) => {
89+
selectedDeptIds.value = treeRef.value.getCheckedKeys()
90+
if (!props.multiple && selectedDeptIds.value.length > 1) {
91+
// 单选模式下,只保留最后选择的节点
92+
const lastSelectedId = selectedDeptIds.value[selectedDeptIds.value.length - 1]
93+
selectedDeptIds.value = [lastSelectedId]
94+
treeRef.value.setCheckedKeys([lastSelectedId])
95+
}
96+
}
97+
98+
/** 提交选择 */
99+
const submitForm = async () => {
100+
try {
101+
// 获取选中的完整部门数据
102+
const checkedNodes = treeRef.value.getCheckedNodes()
103+
message.success(t('common.updateSuccess'))
104+
dialogVisible.value = false
105+
emit('confirm', checkedNodes)
106+
} finally {
107+
}
108+
}
109+
110+
/** 重置表单 */
111+
const resetForm = () => {
112+
deptTree.value = []
113+
selectedDeptIds.value = []
114+
if (treeRef.value) {
115+
treeRef.value.setCheckedKeys([])
116+
}
117+
}
118+
119+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
120+
</script>

src/components/SimpleProcessDesignerV2/src/SimpleProcessDesigner.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const props = defineProps({
5959
startUserIds: {
6060
type: Array,
6161
required: false
62+
},
63+
// 可发起流程的部门编号
64+
startDeptIds: {
65+
type: Array,
66+
required: false
6267
}
6368
})
6469
@@ -82,6 +87,7 @@ provide('deptList', deptOptions)
8287
provide('userGroupList', userGroupOptions)
8388
provide('deptTree', deptTreeOptions)
8489
provide('startUserIds', props.startUserIds)
90+
provide('startDeptIds', props.startDeptIds)
8591
provide('tasks', [])
8692
provide('processInstance', {})
8793
const message = useMessage() // 国际化

src/components/SimpleProcessDesignerV2/src/nodes-config/StartUserNodeConfig.vue

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,38 @@
2525
</template>
2626
<el-tabs type="border-card" v-model="activeTabName">
2727
<el-tab-pane label="权限" name="user">
28-
<el-text v-if="!startUserIds || startUserIds.length === 0"> 全部成员可以发起流程 </el-text>
29-
<el-text v-else-if="startUserIds.length == 1">
30-
{{ getUserNicknames(startUserIds) }} 可发起流程
31-
</el-text>
32-
<el-text v-else>
33-
<el-tooltip
34-
class="box-item"
35-
effect="dark"
36-
placement="top"
37-
:content="getUserNicknames(startUserIds)"
38-
>
39-
{{ getUserNicknames(startUserIds.slice(0, 2)) }} 等
40-
{{ startUserIds.length }} 人可发起流程
41-
</el-tooltip>
42-
</el-text>
28+
<el-text v-if="(!startUserIds || startUserIds.length === 0) && (!startDeptIds || startDeptIds.length === 0)"> 全部成员可以发起流程 </el-text>
29+
<div v-else-if="startUserIds && startUserIds.length > 0">
30+
<el-text v-if="startUserIds.length == 1">
31+
{{ getUserNicknames(startUserIds) }} 可发起流程
32+
</el-text>
33+
<el-text v-else>
34+
<el-tooltip
35+
class="box-item"
36+
effect="dark"
37+
placement="top"
38+
:content="getUserNicknames(startUserIds)"
39+
>
40+
{{ getUserNicknames(startUserIds.slice(0,2)) }} 等 {{ startUserIds.length }} 人可发起流程
41+
</el-tooltip>
42+
</el-text>
43+
</div>
44+
<div v-else-if="startDeptIds && startDeptIds.length > 0">
45+
<el-text v-if="startDeptIds.length == 1">
46+
{{ getDeptNames(startDeptIds) }} 可发起流程
47+
</el-text>
48+
<el-text v-else>
49+
<el-tooltip
50+
class="box-item"
51+
effect="dark"
52+
placement="top"
53+
:content="getDeptNames(startDeptIds)"
54+
>
55+
{{ getDeptNames(startDeptIds.slice(0,2)) }} 等 {{ startDeptIds.length }} 个部门的人可发起流程
56+
</el-tooltip>
57+
</el-text>
58+
</div>
59+
4360
</el-tab-pane>
4461
<el-tab-pane label="表单字段权限" name="fields" v-if="formType === 10">
4562
<div class="field-setting-pane">
@@ -107,6 +124,7 @@
107124
import { SimpleFlowNode, NodeType, FieldPermissionType, START_USER_BUTTON_SETTING } from '../consts'
108125
import { useWatchNode, useDrawer, useNodeName, useFormFieldsPermission } from '../node'
109126
import * as UserApi from '@/api/system/user'
127+
import * as DeptApi from '@/api/system/dept'
110128
defineOptions({
111129
name: 'StartUserNodeConfig'
112130
})
@@ -118,8 +136,12 @@ const props = defineProps({
118136
})
119137
// 可发起流程的用户编号
120138
const startUserIds = inject<Ref<any[]>>('startUserIds')
139+
// 可发起流程的部门编号
140+
const startDeptIds = inject<Ref<any[]>>('startDeptIds')
121141
// 用户列表
122142
const userOptions = inject<Ref<UserApi.UserVO[]>>('userList')
143+
// 部门列表
144+
const deptOptions = inject<Ref<DeptApi.DeptVO[]>>('deptList')
123145
// 抽屉配置
124146
const { settingVisible, closeDrawer, openDrawer } = useDrawer()
125147
// 当前节点
@@ -145,6 +167,19 @@ const getUserNicknames = (userIds: number[]): string => {
145167
})
146168
return nicknames.join(',')
147169
}
170+
const getDeptNames = (deptIds: number[]): string => {
171+
if (!deptIds || deptIds.length === 0) {
172+
return ''
173+
}
174+
const deptNames: string[] = []
175+
deptIds.forEach((deptId) => {
176+
const found = deptOptions?.value.find((item) => item.id === deptId)
177+
if (found && found.name) {
178+
deptNames.push(found.name)
179+
}
180+
})
181+
return deptNames.join(',')
182+
}
148183
// 保存配置
149184
const saveConfig = async () => {
150185
activeTabName.value = 'user'

src/views/bpm/model/CategoryDraggableModel.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,23 @@
9797
</el-table-column>
9898
<el-table-column label="可见范围" prop="startUserIds" min-width="150">
9999
<template #default="{ row }">
100-
<el-text v-if="!row.startUsers?.length"> 全部可见 </el-text>
100+
<el-text v-if="!row.startUsers?.length && !row.startDepts?.length"> 全部可见 </el-text>
101101
<el-text v-else-if="row.startUsers.length === 1">
102102
{{ row.startUsers[0].nickname }}
103103
</el-text>
104+
<el-text v-else-if="row.startDepts?.length === 1">
105+
{{ row.startDepts[0].name }}
106+
</el-text>
107+
<el-text v-else-if="row.startDepts?.length > 1">
108+
<el-tooltip
109+
class="box-item"
110+
effect="dark"
111+
placement="top"
112+
:content="row.startDepts.map((dept: any) => dept.name).join('、')"
113+
>
114+
{{ row.startDepts[0].name }}等 {{ row.startDepts.length }} 个部门可见
115+
</el-tooltip>
116+
</el-text>
104117
<el-text v-else>
105118
<el-tooltip
106119
class="box-item"

0 commit comments

Comments
 (0)