提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<div class="head-container"> |
|
3 |
<el-input v-model="deptName" class="mb-20px" clearable placeholder="请输入部门名称"> |
|
4 |
<template #prefix> |
|
5 |
<Icon icon="ep:search" /> |
|
6 |
</template> |
|
7 |
</el-input> |
|
8 |
</div> |
|
9 |
<div class="head-container"> |
|
10 |
<el-tree |
|
11 |
ref="treeRef" |
|
12 |
:data="deptList" |
|
13 |
:expand-on-click-node="false" |
|
14 |
:filter-node-method="filterNode" |
|
15 |
:props="defaultProps" |
|
16 |
default-expand-all |
|
17 |
highlight-current |
|
18 |
node-key="id" |
|
19 |
@node-click="handleNodeClick" |
|
20 |
/> |
|
21 |
</div> |
|
22 |
</template> |
|
23 |
|
|
24 |
<script lang="ts" setup> |
|
25 |
import { ElTree } from 'element-plus' |
|
26 |
import * as DeptApi from '@/api/system/dept' |
|
27 |
import { defaultProps, handleTree } from '@/utils/tree' |
|
28 |
|
|
29 |
defineOptions({ name: 'SystemUserDeptTree' }) |
|
30 |
|
|
31 |
const deptName = ref('') |
|
32 |
const deptList = ref<Tree[]>([]) // 树形结构 |
|
33 |
const treeRef = ref<InstanceType<typeof ElTree>>() |
|
34 |
|
|
35 |
/** 获得部门树 */ |
|
36 |
const getTree = async () => { |
|
37 |
const res = await DeptApi.getSimpleDeptList() |
|
38 |
deptList.value = [] |
|
39 |
deptList.value.push(...handleTree(res)) |
|
40 |
} |
|
41 |
|
|
42 |
/** 基于名字过滤 */ |
|
43 |
const filterNode = (name: string, data: Tree) => { |
|
44 |
if (!name) return true |
|
45 |
return data.name.includes(name) |
|
46 |
} |
|
47 |
|
|
48 |
/** 处理部门被点击 */ |
|
49 |
const handleNodeClick = async (row: { [key: string]: any }) => { |
|
50 |
emits('node-click', row) |
|
51 |
} |
|
52 |
const emits = defineEmits(['node-click']) |
|
53 |
|
|
54 |
/** 监听deptName */ |
|
55 |
watch(deptName, (val) => { |
|
56 |
treeRef.value!.filter(val) |
|
57 |
}) |
|
58 |
|
|
59 |
/** 初始化 */ |
|
60 |
onMounted(async () => { |
|
61 |
await getTree() |
|
62 |
}) |
|
63 |
</script> |