Skip to content

Commit e08dcc9

Browse files
author
puhui999
committed
update: 重构用户管理部门回显方法
1 parent 7c6e263 commit e08dcc9

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/views/system/user/index.vue

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -332,26 +332,24 @@ const getPostOptions = async () => {
332332
const res = await getSimplePostList()
333333
postOptions.value.push(...res)
334334
}
335-
const dataFormater = (val) => {
336-
return deptFormater(deptOptions.value, val)
337-
}
335+
const dataFormater = computed(() => (deptId: number) => deptFormater(deptOptions.value, deptId))
336+
338337
//部门回显
339-
const deptFormater = (ary, val: any) => {
340-
var o = ''
341-
if (ary && val) {
342-
for (const v of ary) {
343-
if (v.id == val) {
344-
o = v.name
345-
if (o) return o
346-
} else if (v.children?.length) {
347-
o = deptFormater(v.children, val)
348-
if (o) return o
338+
const deptFormater = (arr: Tree[], deptId: number) => {
339+
let deptName = ''
340+
if (arr && deptId) {
341+
for (const item of arr) {
342+
if (item.id === deptId) {
343+
deptName = item.name
344+
break
345+
}
346+
if (item.children) {
347+
deptName = deptFormater(item.children, deptId) ?? ''
348+
break
349349
}
350350
}
351-
return o
352-
} else {
353-
return val
354351
}
352+
return deptName
355353
}
356354
357355
// 设置标题

0 commit comments

Comments
 (0)