QYF-GitLab1
2025-02-28 7a07041e87f5fea69ad4d83868f095c6b612e710
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<template>
  <div class="tree-menu">
    <SearchBar @search="handleSearch" />
    <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 } from 'vue'
import { useRouter } from 'vue-router'
import SearchBar from './SearchBar.vue'
import { Document, FolderOpened } from '@element-plus/icons-vue'
 
const router = useRouter()
const treeRef = ref()
 
interface TreeNode {
  label: string
  path?: string
  icon?: string
  children?: TreeNode[]
}
 
const treeData = ref<TreeNode[]>([
  {
    label: '模型管理',
    icon: 'FolderOpened',
    children: [
      {
        label: '机构模型',
        path: '/mechanism',
        icon: 'Document'
      },
      {
        label: '运动学模型',
        path: '/kinematic',
        icon: 'Document'
      }
    ]
  },
  {
    label: '可视化仿真',
    icon: 'FolderOpened',
    children: [
      {
        label: '仿真配置',
        path: '/simulation-config',
        icon: 'Document'
      },
      {
        label: '仿真结果',
        path: '/simulation-result',
        icon: 'Document'
      }
    ]
  },
  {
    label: '系统管理',
    icon: 'FolderOpened',
    children: [
      {
        label: '用户管理',
        path: '/system/user',
        icon: 'Document'
      },
      {
        label: '权限设置',
        path: '/system/permission',
        icon: 'Document'
      }
    ]
  }
])
 
const defaultProps = {
  children: 'children',
  label: 'label'
}
 
const filteredData = ref(treeData.value)
 
const filterNode = (value: string, data: TreeNode) => {
  if (!value) return true
  return data.label.toLowerCase().includes(value.toLowerCase())
}
 
const handleSearch = (searchText: string) => {
  treeRef.value?.filter(searchText)
}
 
const handleNodeClick = (data: TreeNode) => {
  if (data.path) {
    router.push(data.path)
  }
}
</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;
  }
}
</style>