<template>
|
<div class="tree-menu">
|
<div class="topMenu">
|
<span class="topMenu-title">模型库</span>
|
<div class="btnGroup">
|
<el-icon class="icon1"><FolderAdd /></el-icon>
|
<el-icon class="icon2"><Edit /></el-icon>
|
<el-icon class="icon3"><Delete /></el-icon>
|
</div>
|
</div>
|
<el-tree
|
ref="treeRef"
|
:data="filteredData"
|
:props="defaultProps"
|
:filter-node-method="filterNode"
|
default-expand-all
|
@node-click="handleNodeClick"
|
>
|
<template #default="{ node, data }">
|
<span class="custom-tree-node">
|
<el-icon v-if="data.icon"><component :is="data.icon" /></el-icon>
|
<span>{{ node.label }}</span>
|
</span>
|
</template>
|
</el-tree>
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { ref, watch, defineProps } from "vue";
|
import { useRouter } from "vue-router";
|
import { Document, FolderOpened } from "@element-plus/icons-vue";
|
|
const router = useRouter();
|
const treeRef = ref();
|
const props = defineProps<{
|
menuItem: string;
|
}>();
|
|
interface TreeNode {
|
label: string;
|
path?: string;
|
icon?: string;
|
children?: TreeNode[];
|
}
|
|
const modelTreeData = ref<TreeNode[]>([
|
{
|
label: "型号",
|
icon: "FolderOpened",
|
children: [
|
{
|
label: "型号1",
|
path: "/model/childrenModel01",
|
},
|
{
|
label: "型号2",
|
},
|
],
|
},
|
]);
|
|
const defaultProps = {
|
children: "children",
|
label: "label",
|
};
|
|
const filteredData = ref(modelTreeData.value);
|
|
const filterNode = (value: string, data: TreeNode) => {
|
if (!value) return true;
|
return data.label.toLowerCase().includes(value.toLowerCase());
|
};
|
|
const handleNodeClick = (data: TreeNode) => {
|
if (data.path) {
|
router.push(data.path);
|
}
|
};
|
|
watch(
|
() => props.menuItem,
|
(value) => {
|
if (value == "/" || value == "/model") {
|
filteredData.value = modelTreeData.value;
|
} else {
|
filteredData.value = []
|
}
|
}
|
);
|
</script>
|
|
<style lang="less" scoped>
|
.tree-menu {
|
height: 100%;
|
background-color: #fff;
|
|
:deep(.el-tree) {
|
padding: 10px;
|
}
|
|
.custom-tree-node {
|
display: flex;
|
align-items: center;
|
gap: 8px;
|
}
|
|
.topMenu {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 10px;
|
border-bottom: 1px solid #ebeef5;
|
.topMenu-title {
|
font-size: 16px;
|
font-weight: bold;
|
}
|
.btnGroup {
|
display: flex;
|
gap: 12px;
|
cursor: pointer;
|
|
.icon1,
|
.icon2,
|
.icon3 {
|
font-size: 18px;
|
color: #606266;
|
&:hover {
|
color: #409eff;
|
}
|
}
|
}
|
}
|
}
|
</style>
|