Files
ss-crm-manage-web/src/views/Basic/User/DeptTree.vue

49 lines
1.1 KiB
Vue
Raw Normal View History

2024-04-28 16:20:45 +08:00
<template>
<div class="head-container">
<el-tree
ref="treeRef"
:data="deptList"
:expand-on-click-node="false"
:filter-node-method="filterNode"
:props="defaultProps"
default-expand-all
highlight-current
node-key="id"
@node-click="handleNodeClick"
/>
</div>
</template>
<script lang="ts" name="SystemUserDeptTree" setup>
import { ElTree } from 'element-plus'
2024-05-23 15:24:05 +08:00
import * as DeptApi from '@/api/system/dept'
2024-04-28 16:20:45 +08:00
import { defaultProps, handleTree } from '@/utils/tree'
const deptList = ref<Tree[]>([]) // 树形结构
const treeRef = ref<InstanceType<typeof ElTree>>()
/** 获得部门树 */
const getTree = async () => {
2024-05-23 15:24:05 +08:00
const res = await DeptApi.getSimpleDeptList()
2024-04-28 16:20:45 +08:00
deptList.value = []
deptList.value.push(...handleTree(res))
}
/** 基于名字过滤 */
const filterNode = (name: string, data: Tree) => {
if (!name) return true
return data.name.includes(name)
}
/** 处理部门被点击 */
const handleNodeClick = async (row: { [key: string]: any }) => {
emits('node-click', row)
}
const emits = defineEmits(['node-click'])
/** 初始化 */
onMounted(async () => {
await getTree()
})
</script>