1
1
<template >
2
2
<!-- 操作栏 -->
3
- <el-row justify =" end" >
4
- <el-button @click =" openForm" >
5
- <Icon class =" mr-5px" icon =" fluent:people-team-add-20-filled " />
6
- 添加团队成员
3
+ <el-row v-if = " showAction " justify =" end" >
4
+ <el-button v-if = " validateOwnerUser " type = " primary " @click =" openForm" >
5
+ <Icon class =" mr-5px" icon =" ep:plus " />
6
+ 新增
7
7
</el-button >
8
- <el-button @click =" handleUpdate" >
8
+ <el-button v-if = " validateOwnerUser " @click =" handleUpdate" >
9
9
<Icon class =" mr-5px" icon =" ep:edit" />
10
10
编辑
11
11
</el-button >
12
- <el-button @click =" handleDelete" >
12
+ <el-button v-if = " validateOwnerUser " @click =" handleDelete" >
13
13
<Icon class =" mr-5px" icon =" ep:delete" />
14
14
移除
15
15
</el-button >
16
- <el-button type =" danger" @click =" handleQuit" > 退出团队</el-button >
16
+ <el-button v-if =" !validateOwnerUser && list.length > 0" type =" danger" @click =" handleQuit" >
17
+ 退出团队
18
+ </el-button >
17
19
</el-row >
18
-
19
- <!-- 列表 -->
20
- <ContentWrap class =" mt-10px" >
21
- <el-table
22
- v-loading =" loading"
23
- :data =" list"
24
- :show-overflow-tooltip =" true"
25
- :stripe =" true"
26
- @selection-change =" handleSelectionChange"
27
- >
28
- <!-- TODO @puhui999:负责人不允许选中 -->
29
- <el-table-column type =" selection" width =" 55" />
30
- <el-table-column align =" center" label =" 姓名" prop =" nickname" />
31
- <el-table-column align =" center" label =" 部门" prop =" deptName" />
32
- <el-table-column align =" center" label =" 岗位" prop =" postNames" />
33
- <el-table-column align =" center" label =" 权限" prop =" level" >
34
- <template #default =" { row } " >
35
- <dict-tag :type =" DICT_TYPE.CRM_PERMISSION_LEVEL" :value =" row.level" />
36
- </template >
37
- </el-table-column >
38
- <el-table-column
39
- :formatter =" dateFormatter"
40
- align =" center"
41
- label =" 加入时间"
42
- prop =" createTime"
43
- />
44
- </el-table >
45
- </ContentWrap >
20
+ <!-- 团队成员展示 -->
21
+ <el-table
22
+ ref =" elTableRef"
23
+ v-loading =" loading"
24
+ :data =" list"
25
+ :show-overflow-tooltip =" true"
26
+ :stripe =" true"
27
+ class =" mt-20px"
28
+ @selection-change =" handleSelectionChange"
29
+ >
30
+ <el-table-column type =" selection" width =" 55" />
31
+ <el-table-column align =" center" label =" 姓名" prop =" nickname" />
32
+ <el-table-column align =" center" label =" 部门" prop =" deptName" />
33
+ <el-table-column align =" center" label =" 岗位" prop =" postNames" />
34
+ <el-table-column align =" center" label =" 权限级别" prop =" level" >
35
+ <template #default =" { row } " >
36
+ <dict-tag :type =" DICT_TYPE.CRM_PERMISSION_LEVEL" :value =" row.level" />
37
+ </template >
38
+ </el-table-column >
39
+ <el-table-column :formatter =" dateFormatter" align =" center" label =" 加入时间" prop =" createTime" />
40
+ </el-table >
46
41
47
42
<!-- 表单弹窗:添加/修改 -->
48
43
<CrmPermissionForm ref =" formRef" @success =" getList" />
49
44
</template >
50
45
<script lang="ts" setup>
51
46
import { dateFormatter } from ' @/utils/formatTime'
52
- import { DICT_TYPE } from ' @/utils/dict '
47
+ import { ElTable } from ' element-plus '
53
48
import * as PermissionApi from ' @/api/crm/permission'
54
- import { PermissionLevelEnum } from ' @/api/crm/permission'
55
49
import { useUserStoreWithOut } from ' @/store/modules/user'
56
50
import CrmPermissionForm from ' ./PermissionForm.vue'
51
+ import { DICT_TYPE } from ' @/utils/dict'
57
52
58
53
defineOptions ({ name: ' CrmPermissionList' })
59
- const props = defineProps <{
60
- bizType: number // 业务类型
61
- bizId: number // 业务编号
62
- }>()
63
54
64
55
const message = useMessage () // 消息
56
+
57
+ const props = defineProps <{
58
+ bizType: number // 模块类型
59
+ bizId: number | undefined // 模块数据编号
60
+ showAction: boolean // 是否展示操作按钮
61
+ }>()
65
62
const loading = ref (true ) // 列表的加载中
66
63
const list = ref <PermissionApi .PermissionVO []>([]) // 列表的数据
64
+ const formData = ref ({
65
+ ownerUserId: 0
66
+ })
67
+ const userStore = useUserStoreWithOut () // 用户信息缓存
67
68
68
69
/** 查询列表 */
69
70
const getList = async () => {
70
71
loading .value = true
71
72
try {
72
- list . value = await PermissionApi .getPermissionList ({
73
+ const data = await PermissionApi .getPermissionList ({
73
74
bizType: props .bizType ,
74
75
bizId: props .bizId
75
76
})
77
+ list .value = data
78
+ const permission = list .value .find (
79
+ (item ) =>
80
+ item .userId === userStore .getUser .id &&
81
+ item .level === PermissionApi .PermissionLevelEnum .OWNER
82
+ )
83
+ if (permission ) {
84
+ formData .value .ownerUserId = userStore .getUser .id
85
+ }
76
86
} finally {
77
87
loading .value = false
78
88
}
79
89
}
80
-
81
- /** 选中团队成员 */
82
90
const multipleSelection = ref <PermissionApi .PermissionVO []>([]) // 选择的团队成员
91
+ const elTableRef = ref <InstanceType <typeof ElTable >>()
83
92
const handleSelectionChange = (val : PermissionApi .PermissionVO []) => {
93
+ if (val .findIndex ((item ) => item .level === PermissionApi .PermissionLevelEnum .OWNER ) !== - 1 ) {
94
+ message .warning (' 不能选择负责人!' )
95
+ elTableRef .value ?.clearSelection ()
96
+ return
97
+ }
84
98
multipleSelection .value = val
85
99
}
86
100
87
- /** 添加团队成员 */
88
- const formRef = ref <InstanceType <typeof CrmPermissionForm >>() // 权限表单 Ref
89
- const openForm = () => {
90
- formRef .value ?.open (' create' , props .bizType , props .bizId )
91
- }
92
-
93
101
/** 编辑团队成员 */
102
+ const formRef = ref <InstanceType <typeof CrmPermissionForm >>() // 权限表单 Ref
94
103
const handleUpdate = () => {
95
104
if (multipleSelection .value ?.length === 0 ) {
96
105
message .warning (' 请先选择团队成员后操作!' )
97
106
return
98
107
}
99
- const ids = multipleSelection .value ?.map ((item ) => item .id ) as number []
100
- formRef .value ?.open (' update' , props .bizType , props .bizId , ids )
108
+ const ids = multipleSelection .value ?.map ((item ) => item .id ) as unknown as number []
109
+ formRef .value ?.open (' update' , props .bizType , props .bizId ! , ids )
101
110
}
102
111
103
112
/** 移除团队成员 */
@@ -106,36 +115,75 @@ const handleDelete = async () => {
106
115
message .warning (' 请先选择团队成员后操作!' )
107
116
return
108
117
}
109
- await message .delConfirm (' 是否删除选择的团队成员? ' )
118
+ await message .delConfirm ()
110
119
const ids = multipleSelection .value ?.map ((item ) => item .id )
111
120
await PermissionApi .deletePermissionBatch ({
112
121
bizType: props .bizType ,
113
122
bizId: props .bizId ,
114
123
ids
115
124
})
116
- message .success (' 删除成功' )
117
125
}
118
126
127
+ /** 添加团队成员 */
128
+ const openForm = () => {
129
+ formRef .value ?.open (' create' , props .bizType , props .bizId ! )
130
+ }
131
+
132
+ // 校验负责人权限和编辑权限
133
+ const validateOwnerUser = ref (false )
134
+ const validateWrite = ref (false )
135
+ const isPool = ref (false )
136
+ watch (
137
+ list ,
138
+ (newArr ) => {
139
+ isPool .value = false
140
+ if (newArr ?.length > 0 ) {
141
+ isPool .value = ! list .value .some (
142
+ (item ) => item .level === PermissionApi .PermissionLevelEnum .OWNER
143
+ )
144
+ validateOwnerUser .value = false
145
+ validateWrite .value = false
146
+ const userId = userStore .getUser ?.id
147
+ list .value
148
+ .filter ((item ) => item .userId === userId )
149
+ .forEach ((item ) => {
150
+ if (item .level === PermissionApi .PermissionLevelEnum .OWNER ) {
151
+ validateOwnerUser .value = true
152
+ validateWrite .value = true
153
+ } else if (item .level === PermissionApi .PermissionLevelEnum .WRITE ) {
154
+ validateWrite .value = true
155
+ }
156
+ })
157
+ } else {
158
+ isPool .value = true
159
+ }
160
+ },
161
+ {
162
+ immediate: true
163
+ }
164
+ )
165
+
166
+ defineExpose ({ openForm , validateOwnerUser , validateWrite , isPool })
119
167
/** 退出团队 */
120
- const userStore = useUserStoreWithOut () // 用户信息缓存
121
168
const handleQuit = async () => {
122
169
const permission = list .value .find (
123
- (item ) => item .userId === userStore .getUser .id && item .level === PermissionLevelEnum .OWNER
170
+ (item ) =>
171
+ item .userId === userStore .getUser .id && item .level === PermissionApi .PermissionLevelEnum .OWNER
124
172
)
125
173
if (permission ) {
126
174
message .warning (' 负责人不能退出团队!' )
127
175
return
128
176
}
129
- await message .confirm (' 确认退出团队吗?' )
130
177
const userPermission = list .value .find ((item ) => item .userId === userStore .getUser .id )
131
- await PermissionApi .deleteSelfPermission (userPermission ?.id )
178
+ if (userPermission ) {
179
+ await PermissionApi .deleteSelfPermission (userPermission .id ! )
180
+ }
132
181
}
133
182
134
- /** 监听打开的 bizId + bizType,从而加载最新的列表 */
135
183
watch (
136
- () => [ props .bizId , props . bizType ] ,
137
- (val ) => {
138
- if (! val [ 0 ] ) {
184
+ () => props .bizId ,
185
+ (bizId ) => {
186
+ if (! bizId ) {
139
187
return
140
188
}
141
189
getList ()
0 commit comments