Showing
1 changed file
with
18 additions
and
38 deletions
| ... | ... | @@ -8,51 +8,31 @@ |
| 8 | 8 | :clickRowToExpand="false" |
| 9 | 9 | :treeData="treeData" |
| 10 | 10 | :replaceFields="{ key: 'id', title: 'name' }" |
| 11 | - v-model:expandedKeys="expandedKeys" | |
| 12 | - v-model:selectedKeys="selectedKeys" | |
| 11 | + :selectedKeys="selectedKeys" | |
| 13 | 12 | @select="handleSelect" |
| 14 | - :defaultExpandAll="true" | |
| 15 | 13 | /> |
| 16 | 14 | </div> |
| 17 | 15 | </template> |
| 18 | -<script lang="ts"> | |
| 19 | - import { defineComponent, onMounted, ref } from 'vue'; | |
| 20 | - | |
| 16 | +<script lang="ts" setup name="OrganizationIdTree"> | |
| 17 | + import { onMounted, ref } from 'vue'; | |
| 21 | 18 | import { BasicTree, TreeItem } from '/@/components/Tree'; |
| 22 | 19 | import { getOrganizationList } from '/@/api/system/system'; |
| 20 | + const emit = defineEmits(['select']); | |
| 21 | + const treeData = ref<TreeItem[]>([]); | |
| 22 | + const selectedKeys = ref<string[]>(); | |
| 23 | + | |
| 24 | + function handleSelect(keys) { | |
| 25 | + emit('select', keys[0]); | |
| 26 | + } | |
| 23 | 27 | |
| 24 | - export default defineComponent({ | |
| 25 | - name: 'OrganizationIdTree', | |
| 26 | - components: { BasicTree }, | |
| 27 | - | |
| 28 | - emits: ['select'], | |
| 29 | - setup(_, { emit }) { | |
| 30 | - const getTreeRef: any = ref(null); | |
| 31 | - const treeData = ref<TreeItem[]>([]); | |
| 32 | - const selectedKeys = ref<string[]>(); | |
| 33 | - const expandedKeys = ref<string[]>(); | |
| 34 | - async function fetch() { | |
| 35 | - treeData.value = (await getOrganizationList()) as unknown as TreeItem[]; | |
| 36 | - } | |
| 28 | + function resetOrganization() { | |
| 29 | + selectedKeys.value = []; | |
| 30 | + } | |
| 37 | 31 | |
| 38 | - function handleSelect(keys) { | |
| 39 | - emit('select', keys[0]); | |
| 40 | - } | |
| 41 | - function resetOrganization() { | |
| 42 | - selectedKeys.value = []; | |
| 43 | - } | |
| 44 | - | |
| 45 | - onMounted(() => { | |
| 46 | - fetch(); | |
| 47 | - }); | |
| 48 | - return { | |
| 49 | - treeData, | |
| 50 | - handleSelect, | |
| 51 | - resetOrganization, | |
| 52 | - selectedKeys, | |
| 53 | - expandedKeys, | |
| 54 | - getTreeRef, | |
| 55 | - }; | |
| 56 | - }, | |
| 32 | + onMounted(async () => { | |
| 33 | + treeData.value = (await getOrganizationList()) as unknown as TreeItem[]; | |
| 34 | + }); | |
| 35 | + defineExpose({ | |
| 36 | + resetOrganization, | |
| 57 | 37 | }); |
| 58 | 38 | </script> | ... | ... |