You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
993 B

<script lang="ts" setup>
2 years ago
import { onMounted, ref } from 'vue'
import type { TreeItem } from '@/components/Tree'
import { BasicTree } from '@/components/Tree'
import { listSimpleDept } from '@/api/system/dept'
2 years ago
import { handleTree } from '@/utils/tree'
defineOptions({ name: 'SystemDeptTree' })
2 years ago
const emit = defineEmits(['select'])
2 years ago
const treeRef = ref()
2 years ago
const treeData = ref<TreeItem[]>([])
async function fetch() {
const res = await listSimpleDept()
2 years ago
treeData.value = handleTree(res, 'id')
}
function handleSelect(keys) {
emit('select', keys[0])
}
onMounted(() => {
fetch()
})
</script>
<template>
2 years ago
<div class="m-4 mr-0 overflow-hidden" v-bind="$attrs">
<BasicTree
2 years ago
ref="treeRef"
title="部门列表"
toolbar
search
tree-wrapper-class-name="h-[calc(100%-35px)] overflow-auto"
:click-row-to-expand="false"
:tree-data="treeData"
:field-names="{ key: 'id', title: 'name' }"
@select="handleSelect"
/>
</div>
</template>