|
|
@@ -84,26 +84,26 @@ const findFirstNodeByDeptType = (nodes, targetType) => {
|
|
84
|
84
|
return null
|
|
85
|
85
|
}
|
|
86
|
86
|
|
|
87
|
|
-const buildPathForNode = (nodes, targetId, path = []) => {
|
|
88
|
|
- if (!nodes) return path
|
|
|
87
|
+const buildPathForNode = (nodes, targetId) => {
|
|
|
88
|
+ if (!nodes) return null
|
|
89
|
89
|
for (const node of nodes) {
|
|
90
|
90
|
if (node.id === targetId || node.deptId === targetId) {
|
|
91
|
91
|
// 如果是用户节点,不把用户名字加入 path
|
|
92
|
92
|
if (node.deptType === 'user' || node.nodeType === 'user') {
|
|
93
|
|
- return path
|
|
|
93
|
+ return []
|
|
94
|
94
|
}
|
|
95
|
95
|
const name = node.nickName || node.deptName || node.name || node.label
|
|
96
|
|
- return [...path, name]
|
|
|
96
|
+ return [name]
|
|
97
|
97
|
}
|
|
98
|
|
-
|
|
99
|
|
- const name = node.deptName || node.name || node.label
|
|
100
|
|
- const found = buildPathForNode(node.children, targetId, [...path, name])
|
|
101
|
|
- if (found.length > path.length) {
|
|
102
|
|
- return found
|
|
|
98
|
+ if (node.children && node.children.length > 0) {
|
|
|
99
|
+ const childPath = buildPathForNode(node.children, targetId)
|
|
|
100
|
+ if (childPath !== null) {
|
|
|
101
|
+ const name = node.deptName || node.name || node.label
|
|
|
102
|
+ return [name, ...childPath]
|
|
103
|
103
|
}
|
|
104
|
|
-
|
|
|
104
|
+ }
|
|
105
|
105
|
}
|
|
106
|
|
- return path
|
|
|
106
|
+ return null
|
|
107
|
107
|
}
|
|
108
|
108
|
|
|
109
|
109
|
const queryUsers = async (query, cb) => {
|
|
|
@@ -113,7 +113,7 @@ const queryUsers = async (query, cb) => {
|
|
113
|
113
|
const mapped = (res.data || []).map(u => {
|
|
114
|
114
|
let path = []
|
|
115
|
115
|
if (u.deptId) {
|
|
116
|
|
- path = buildPathForNode(departments.value, u.deptId)
|
|
|
116
|
+ path = buildPathForNode(departments.value, u.deptId) || []
|
|
117
|
117
|
}
|
|
118
|
118
|
return { ...u, value: u.nickName, path }
|
|
119
|
119
|
})
|
|
|
@@ -128,7 +128,7 @@ const queryDept = async (query, cb) => {
|
|
128
|
128
|
const mapped = (res.data || []).map(d => {
|
|
129
|
129
|
let path = []
|
|
130
|
130
|
if (d.id || d.deptId) {
|
|
131
|
|
- path = buildPathForNode(departments.value, d.deptId || d.id)
|
|
|
131
|
+ path = buildPathForNode(departments.value, d.deptId || d.id) || []
|
|
132
|
132
|
}
|
|
133
|
133
|
return { ...d, value: d.deptName, path }
|
|
134
|
134
|
})
|
|
|
@@ -139,14 +139,14 @@ const queryDept = async (query, cb) => {
|
|
139
|
139
|
const handleSelect = (item) => {
|
|
140
|
140
|
|
|
141
|
141
|
if (props.deptType === 'user') {
|
|
142
|
|
- const path = item.path && item.path.length > 0 ? item.path : (item.deptId ? buildPathForNode(departments.value, item.deptId) : [])
|
|
|
142
|
+ const path = item.path && item.path.length > 0 ? item.path : (item.deptId ? buildPathForNode(departments.value, item.deptId) || [] : [])
|
|
143
|
143
|
const name = item.nickName
|
|
144
|
144
|
|
|
145
|
145
|
personName.value = path.length > 0 ? `${path.join(' / ')} / ${name}` : name
|
|
146
|
146
|
curQuery.value = { personName: item.nickName,id:item.id }
|
|
147
|
147
|
searchHandler(curQuery.value)
|
|
148
|
148
|
} else {
|
|
149
|
|
- const path = item.path && item.path.length > 0 ? item.path : ((item.id || item.deptId) ? buildPathForNode(departments.value, item.deptId || item.id) : [])
|
|
|
149
|
+ const path = item.path && item.path.length > 0 ? item.path : ((item.id || item.deptId) ? buildPathForNode(departments.value, item.deptId || item.id) || [] : [])
|
|
150
|
150
|
const name = item.deptName || item.name || item.label
|
|
151
|
151
|
personName.value = path.length > 0 ? path.join(' / ') : name
|
|
152
|
152
|
if (props.deptType === 'BRIGADE' || props.deptType === 'STATION') {
|
|
|
@@ -229,7 +229,7 @@ const handleNodeClick = (node) => {
|
|
229
|
229
|
if (props.deptType === 'user') {
|
|
230
|
230
|
if (node.nodeType === 'user') {
|
|
231
|
231
|
|
|
232
|
|
- const path = buildPathForNode(departments.value, node.deptId || node.id)
|
|
|
232
|
+ const path = buildPathForNode(departments.value, node.deptId || node.id) || []
|
|
233
|
233
|
const name = node.label
|
|
234
|
234
|
|
|
235
|
235
|
personName.value = path.length > 0 ? `${path.join(' / ')} / ${name}` : name
|
|
|
@@ -238,7 +238,7 @@ const handleNodeClick = (node) => {
|
|
238
|
238
|
}
|
|
239
|
239
|
} else {
|
|
240
|
240
|
if (node.deptType === props.deptType) {
|
|
241
|
|
- const path = buildPathForNode(departments.value, node.deptId || node.id)
|
|
|
241
|
+ const path = buildPathForNode(departments.value, node.deptId || node.id) || []
|
|
242
|
242
|
const name = node.deptName || node.name || node.label;
|
|
243
|
243
|
personName.value = path.length > 0 ? path.join(' / ') : name
|
|
244
|
244
|
if (props.deptType === 'BRIGADE' || props.deptType === 'STATION') {
|
|
|
@@ -270,13 +270,13 @@ onMounted(async () => {
|
|
270
|
270
|
const nodeId = defaultNode.deptId || defaultNode.id
|
|
271
|
271
|
currentKey.value = nodeId
|
|
272
|
272
|
if (props.deptType === 'user') {
|
|
273
|
|
- const path = buildPathForNode(departments.value, nodeId)
|
|
|
273
|
+ const path = buildPathForNode(departments.value, nodeId) || []
|
|
274
|
274
|
const name = defaultNode.label
|
|
275
|
275
|
personName.value = path.length > 0 ? `${path.join(' / ')} / ${name}` : name
|
|
276
|
276
|
curQuery.value = { personName: defaultNode.label, id: defaultNode.id }
|
|
277
|
277
|
searchHandler(curQuery.value)
|
|
278
|
278
|
} else {
|
|
279
|
|
- const path = buildPathForNode(departments.value, nodeId)
|
|
|
279
|
+ const path = buildPathForNode(departments.value, nodeId) || []
|
|
280
|
280
|
const name = defaultNode.deptName || defaultNode.name || defaultNode.label
|
|
281
|
281
|
personName.value = path.length > 0 ? path.join(' / ') : name
|
|
282
|
282
|
if (props.deptType === 'BRIGADE' || props.deptType === 'STATION') {
|