Files
admin-govern/src/components/tree/index.vue

71 lines
1.9 KiB
Vue
Raw Normal View History

2024-01-09 13:49:21 +08:00
<template>
<div class="cn-tree">
<el-input v-model="filterText" placeholder="请输入内容" clearable style="margin-bottom: 10px">
<template #prefix>
<Icon name="el-icon-Search" style="font-size: 16px" />
</template>
</el-input>
<el-tree
2024-01-11 08:54:09 +08:00
style="flex: 1;overflow: auto;"
2024-01-09 13:49:21 +08:00
ref="treeRef"
:props="defaultProps"
v-bind="$attrs"
highlight-current
default-expand-all
:filter-node-method="filterNode"
2024-01-11 08:54:09 +08:00
node-key="id"
2024-01-09 13:49:21 +08:00
>
<template #default="{ node, data }">
<span class="custom-tree-node">
<Icon :name="data.icon" style="font-size: 16px" :style="{ color: data.color }" v-if="data.icon" />
<span style="margin-left: 4px">{{ node.label }}</span>
</span>
</template>
</el-tree>
</div>
</template>
<script lang="ts" setup>
2024-01-19 14:08:07 +08:00
import { ElTree } from 'element-plus';
2024-01-09 13:49:21 +08:00
import { ref, watch } from 'vue'
defineOptions({
name: 'govern/tree'
})
const filterText = ref('')
const defaultProps = {
label: 'name',
value: 'id'
}
watch(filterText, val => {
treeRef.value!.filter(val)
})
const filterNode = (value: string, data: any) => {
if (!value) return true
return data.name.includes(value)
}
2024-01-19 14:08:07 +08:00
const treeRef = ref<InstanceType<typeof ElTree>>()
2024-01-11 08:54:09 +08:00
defineExpose({ treeRef })
2024-01-09 13:49:21 +08:00
</script>
<style lang="scss" scoped>
.cn-tree {
flex-shrink: 0;
display: flex;
flex-direction: column;
box-sizing: border-box;
padding: 10px;
height: 100%;
width: 280px;
:deep(.el-tree) {
background: #efeff0;
}
:deep(.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content) {
background-color: var(--el-color-primary-light-7);
}
}
.custom-tree-node {
display: flex;
align-items: center;
}
</style>