Showing
1 changed file
with
12 additions
and
3 deletions
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | search | 7 | search |
| 8 | :clickRowToExpand="false" | 8 | :clickRowToExpand="false" |
| 9 | :treeData="treeData" | 9 | :treeData="treeData" |
| 10 | + :expandedKeys="treeExpandData" | ||
| 10 | :replaceFields="{ key: 'id', title: 'name' }" | 11 | :replaceFields="{ key: 'id', title: 'name' }" |
| 11 | :selectedKeys="selectedKeys" | 12 | :selectedKeys="selectedKeys" |
| 12 | @select="handleSelect" | 13 | @select="handleSelect" |
| @@ -20,17 +21,25 @@ | @@ -20,17 +21,25 @@ | ||
| 20 | const emit = defineEmits(['select']); | 21 | const emit = defineEmits(['select']); |
| 21 | const treeData = ref<TreeItem[]>([]); | 22 | const treeData = ref<TreeItem[]>([]); |
| 22 | const selectedKeys = ref<string[]>(); | 23 | const selectedKeys = ref<string[]>(); |
| 23 | - | 24 | + const treeExpandData = ref([]); |
| 25 | + //获取所有父级id | ||
| 26 | + function findForAllId(data = [], arr = []) { | ||
| 27 | + for (const item of data) { | ||
| 28 | + arr.push(item.id); | ||
| 29 | + } | ||
| 30 | + return arr; | ||
| 31 | + } | ||
| 24 | function handleSelect(keys) { | 32 | function handleSelect(keys) { |
| 25 | emit('select', keys[0]); | 33 | emit('select', keys[0]); |
| 26 | } | 34 | } |
| 27 | - | ||
| 28 | function resetOrganization() { | 35 | function resetOrganization() { |
| 29 | selectedKeys.value = []; | 36 | selectedKeys.value = []; |
| 30 | } | 37 | } |
| 31 | - | ||
| 32 | onMounted(async () => { | 38 | onMounted(async () => { |
| 33 | treeData.value = (await getOrganizationList()) as unknown as TreeItem[]; | 39 | treeData.value = (await getOrganizationList()) as unknown as TreeItem[]; |
| 40 | + const getAllIds = findForAllId(treeData.value as any, []); | ||
| 41 | + //设置要展开的id | ||
| 42 | + treeExpandData.value = getAllIds; | ||
| 34 | }); | 43 | }); |
| 35 | defineExpose({ | 44 | defineExpose({ |
| 36 | resetOrganization, | 45 | resetOrganization, |