QYF-GitLab1
2025-03-03 b3850046bfb2b8fd81c5b08dff7c9291e5d9bab4
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<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: "着陆器模型库",
        path: "/model/landerModel",
        icon: "Document",
      },
      {
        label: "巡视器模型库",
        path: "/model/roverModel",
        icon: "Document",
      },
      {
        label: "飞跃器模型库",
        path: "/model/leapMachineModel",
        icon: "Document",
      },
    ],
  },
]);
 
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>