FlowBL/src/views/system/user/DeptTree.vue

57 lines
1.4 KiB
Vue
Raw Normal View History

2023-03-29 22:07:53 +08:00
<template>
<div class="head-container">
2023-03-31 07:54:33 +08:00
<el-input v-model="deptName" placeholder="请输入部门名称" clearable class="mb-20px">
2023-03-29 22:07:53 +08:00
<template #prefix>
<Icon icon="ep:search" />
</template>
</el-input>
</div>
<div class="head-container">
<el-tree
2023-03-31 07:54:33 +08:00
:data="deptList"
2023-03-29 22:07:53 +08:00
:props="defaultProps"
2023-03-31 07:54:33 +08:00
node-key="id"
2023-03-29 22:07:53 +08:00
:expand-on-click-node="false"
:filter-node-method="filterNode"
ref="treeRef"
default-expand-all
highlight-current
2023-03-31 07:54:33 +08:00
@node-click="handleNodeClick"
2023-03-29 22:07:53 +08:00
/>
</div>
</template>
<script setup lang="ts" name="UserDeptTree">
import { ElTree } from 'element-plus'
import * as DeptApi from '@/api/system/dept'
import { defaultProps, handleTree } from '@/utils/tree'
const deptName = ref('')
2023-03-31 07:54:33 +08:00
const deptList = ref<Tree[]>([]) // 树形结构
2023-03-29 22:07:53 +08:00
const treeRef = ref<InstanceType<typeof ElTree>>()
2023-03-31 07:54:33 +08:00
/** 获得部门树 */
2023-03-29 22:07:53 +08:00
const getTree = async () => {
const res = await DeptApi.getSimpleDeptList()
2023-03-31 07:54:33 +08:00
deptList.value = []
deptList.value.push(...handleTree(res))
2023-03-29 22:07:53 +08:00
}
2023-03-31 07:54:33 +08:00
/** 基于名字过滤 */
const filterNode = (name: string, data: Tree) => {
if (!name) return true
return data.name.includes(name)
2023-03-29 22:07:53 +08:00
}
2023-03-31 07:54:33 +08:00
/** 处理部门被点击 */
const handleNodeClick = async (row: { [key: string]: any }) => {
2023-03-29 22:07:53 +08:00
emits('node-click', row)
}
2023-03-31 07:54:33 +08:00
const emits = defineEmits(['node-click'])
2023-03-29 22:07:53 +08:00
2023-03-31 07:54:33 +08:00
/** 初始化 */
2023-03-29 22:07:53 +08:00
onMounted(async () => {
await getTree()
})
</script>