|
@ -70,7 +70,7 @@ |
|
|
import { http } from '/nerv-lib/util'; |
|
|
import { http } from '/nerv-lib/util'; |
|
|
|
|
|
|
|
|
//搜索存储 拼凑树的搜索类型 |
|
|
//搜索存储 拼凑树的搜索类型 |
|
|
const dataList: TreeProps['treeData'] = []; |
|
|
let dataList: TreeProps['treeData'] = []; |
|
|
const generateList = (data: TreeProps['treeData']) => { |
|
|
const generateList = (data: TreeProps['treeData']) => { |
|
|
for (let i = 0; i < data.length; i++) { |
|
|
for (let i = 0; i < data.length; i++) { |
|
|
const node = data[i]; |
|
|
const node = data[i]; |
|
@ -80,23 +80,28 @@ |
|
|
generateList(node.children); |
|
|
generateList(node.children); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
console.log(dataList, '数据'); |
|
|
}; |
|
|
}; |
|
|
const getParentKey = ( |
|
|
const getParentKey = ( |
|
|
key: string | number, |
|
|
key: string | number, |
|
|
tree: TreeProps['treeData'], |
|
|
tree: TreeProps['treeData'], |
|
|
): string | number | undefined => { |
|
|
parents: (string | number)[] = [], |
|
|
let parentKey; |
|
|
): (string | number)[] | undefined => { |
|
|
for (let i = 0; i < tree.length; i++) { |
|
|
for (const node of tree) { |
|
|
const node = tree[i]; |
|
|
|
|
|
if (node.children) { |
|
|
if (node.children) { |
|
|
if (node.children.some((item) => item.key === key)) { |
|
|
if (node.children.some((item) => item.key === key)) { |
|
|
parentKey = node.key; |
|
|
// 找到目标节点的直接父节点 |
|
|
} else if (getParentKey(key, node.children)) { |
|
|
return [...parents, node.key]; |
|
|
parentKey = getParentKey(key, node.children); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 递归检查子节点的子节点 |
|
|
|
|
|
const result = getParentKey(key, node.children, [...parents, node.key]); |
|
|
|
|
|
if (result) { |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return parentKey; |
|
|
} |
|
|
|
|
|
return undefined; |
|
|
}; |
|
|
}; |
|
|
export default defineComponent({ |
|
|
export default defineComponent({ |
|
|
setup(props, { emit }) { |
|
|
setup(props, { emit }) { |
|
@ -172,6 +177,7 @@ |
|
|
getDepartList({ orgId: orgId.value }).then((res) => { |
|
|
getDepartList({ orgId: orgId.value }).then((res) => { |
|
|
deptTreeData.value = res; |
|
|
deptTreeData.value = res; |
|
|
selectedKeys.value = [orgId.value]; |
|
|
selectedKeys.value = [orgId.value]; |
|
|
|
|
|
dataList = []; |
|
|
generateList(deptTreeData.value); |
|
|
generateList(deptTreeData.value); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
@ -304,7 +310,12 @@ |
|
|
return null; |
|
|
return null; |
|
|
}) |
|
|
}) |
|
|
.filter((item, i, self) => item && self.indexOf(item) === i); |
|
|
.filter((item, i, self) => item && self.indexOf(item) === i); |
|
|
expandedKeys.value = expanded; |
|
|
console.log(expanded, '数据1111'); |
|
|
|
|
|
let selctky = []; |
|
|
|
|
|
expanded.forEach((item) => { |
|
|
|
|
|
selctky.push(...item); |
|
|
|
|
|
}); |
|
|
|
|
|
expandedKeys.value = selctky; |
|
|
searchValue.value = value; |
|
|
searchValue.value = value; |
|
|
autoExpandParent.value = true; |
|
|
autoExpandParent.value = true; |
|
|
}); |
|
|
}); |
|
|