Files
geg-gas-web/src/views/code/demo/components/DeptTree.vue

36 lines
1.1 KiB
Vue
Raw Normal View History

<template>
2025-10-21 18:04:02 +08:00
<div class="m-4 mr-0 overflow-hidden bg-white">
<BasicTree title="机构列表" toolbar search :clickRowToExpand="true" :treeData="treeData" :fieldNames="{ key: 'id', title: 'name' }" @select="handleSelect" />
</div>
</template>
<script lang="ts">
2025-10-21 18:04:02 +08:00
import { defineComponent, onMounted, ref } from 'vue';
import { getDepartmentTree } from '/@/api/system/department';
2025-10-21 18:04:02 +08:00
import { BasicTree, TreeItem } from '/@/components/Tree';
2025-10-21 18:04:02 +08:00
export default defineComponent({
name: 'DeptTree',
components: { BasicTree },
2025-10-21 18:04:02 +08:00
emits: ['select'],
setup(_, { emit }) {
const treeData = ref<TreeItem[]>([]);
2025-10-21 18:04:02 +08:00
async function fetch() {
treeData.value = (await getDepartmentTree()) as unknown as TreeItem[];
}
2025-10-21 18:04:02 +08:00
function handleSelect(keys: string, e) {
emit('select', keys[0]);
console.log(keys, e);
}
2025-10-21 18:04:02 +08:00
onMounted(() => {
fetch();
});
return { treeData, handleSelect };
}
});
</script>