litian
2025-03-18 4a8d8a5f49321d9597251e7ba69bf39f78baa51b
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<template>
  <div class="tree-menu-box">
    <div class="flex">
      <div class="tree-menu">
        <div class="topMenu">
          <span class="topMenu-title">{{ menuName }}</span>
          <div class="btnGroup" v-if="props.menuItem == 'model'">
            <el-icon class="icon1" @click="addBtn"><FolderAdd /></el-icon>
            <el-icon class="icon2" @click="editBtn"><Edit /></el-icon>
            <el-icon class="icon3" @click="delBtn"><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>
      <div class="tree-menu" v-if="props.menuItem == 'systemManage'">
        <div class="topMenu">
          <span class="topMenu-title">{{ systemMenuName }}</span>
          <div class="btnGroup">
            <el-icon class="icon1" @click="addBtn"><FolderAdd /></el-icon>
            <el-icon class="icon2" @click="editBtn"><Edit /></el-icon>
            <el-icon class="icon3" @click="delBtn"><Delete /></el-icon>
          </div>
        </div>
        <el-tree
          ref="treeRef"
          :data="systemData"
          :props="defaultProps"
          :filter-node-method="filterNode1"
          default-expand-all
          @node-click="systemClick"
        >
          <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>
    </div>
  </div>
  <el-dialog
    v-model="dialogFormVisible"
    :title="dialogTitle"
    width="500"
    @close="closeDialog(formRef)"
  >
    <el-form :model="form" ref="formRef" :rules="formRules" label-width="140px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" autocomplete="off" placeholder="请输入" style="width: 240px"/>
      </el-form-item>
      <el-form-item label="描述">
        <el-input
          v-model="form.description"
          style="width: 240px"
          :rows="2"
          type="textarea"
          placeholder="请输入"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog(formRef)">取消</el-button>
        <el-button type="primary" @click="submitBtn(formRef)"> 确定 </el-button>
      </div>
    </template>
  </el-dialog>
</template>
 
<script setup lang="ts">
import { ref, reactive, defineProps, onMounted } from "vue";
import { useRouter } from "vue-router";
import type { FormInstance, FormRules} from "element-plus";
import { ElMessage, ElMessageBox } from 'element-plus'
import { Document, FolderOpened } from "@element-plus/icons-vue";
 
const router = useRouter();
const treeRef = ref();
const props = defineProps<{
  menuItem: string;
}>();
const menuName = ref("模型库");
const filteredData = ref();
const systemMenuName = ref("");
const systemData = ref();
const selectData = ref()
interface TreeNode {
  label: string;
  path?: string;
  icon?: string;
  children?: TreeNode[];
}
const defaultProps = {
  children: "children",
  label: "label",
};
 
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 visualSimulationTreeData = ref<TreeNode[]>([
  {
    label: "测试仿真",
    path: "/testSimulation",
    icon: "Document",
  },
  {
    label: "实时仿真",
    path: "realTimeSimulation",
    icon: "Document",
  },
  {
    label: "自主功能",
    path: "/autonomousFunction",
    icon: "Document",
  },
]);
 
const systemManageTreeData = ref<TreeNode[]>([
  {
    label: "机构用户",
    path: "/userManage",
    icon: "Document",
  },
  {
    label: "角色权限管理",
    path: "/roleManage",
    icon: "Document",
  },
]);
 
const systemTreeData = ref<TreeNode[]>([
  {
    label: "501",
    path: "",
    icon: "Document",
    children: [
      {
        label: "一室",
        path: "",
        icon: "",
      },
      {
        label: "二室",
        path: "",
        icon: "",
      },
      {
        label: "三室",
        path: "",
        icon: "",
      },
    ],
  },
]);
const systemTreeData1 = ref<TreeNode[]>([
  {
    label: "系统管理员",
    path: "",
    icon: "",
  },
  {
    label: "模型管理员",
    path: "",
    icon: "",
  },
  {
    label: "测试人员",
    path: "",
    icon: "",
  },
  {
    label: "报告查看人员",
    path: "",
    icon: "",
  },
]);
 
const dialogFormVisible = ref(false);
const dialogTitle = ref()
const formRef = ref<FormInstance>();
const form = reactive({
  name: "",
  description: "",
});
 
interface formInfo {
  name: string;
}
const formRules = reactive<FormRules<formInfo>>({
  name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
});
 
onMounted(() => {
  console.log(props.menuItem, "123");
  if (props.menuItem == "model") {
    filteredData.value = modelTreeData.value;
    menuName.value = "模型库";
  } else if (props.menuItem == "simulation") {
    menuName.value = "可视化仿真";
    filteredData.value = visualSimulationTreeData.value;
  } else if (props.menuItem == "systemManage") {
    menuName.value = "系统管理";
    filteredData.value = systemManageTreeData.value;
  } else {
    filteredData.value = [];
  }
  systemMenuName.value = systemManageTreeData.value[0].label;
});
 
const filterNode = (value: string, data: TreeNode) => {
  if (!value) return true;
  return data.label.toLowerCase().includes(value.toLowerCase());
};
 
const filterNode1 = (value: string, data: TreeNode) => {
  if (!value) return true;
  return data.label.toLowerCase().includes(value.toLowerCase());
};
 
const handleNodeClick = (data: TreeNode) => {
  console.log(data, 12);
  selectData.value = data
  if (data.path) {
    systemMenuName.value = data.label;
    if (data.path == "/userManage") {
      systemData.value = systemTreeData.value;
    } else if (data.path == "/roleManage") {
      systemData.value = systemTreeData1.value;
    }
    router.push(data.path);
  }
};
 
//添加目录
const addBtn = () => {
  dialogTitle.value = '添加'
  dialogFormVisible.value = true;
};
const submitBtn = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
    }
  });
};
const closeDialog = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
  dialogFormVisible.value = false;
};
 
const editBtn =() =>{
  dialogTitle.value = '编辑'
  form.name = selectData.value.label
  dialogFormVisible.value = true;
 
}
 
const delBtn =()=>{
  ElMessageBox.confirm(
    '确定要删除选中的数据?',
    'Warning',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      console.log()
     
    })
    .catch(() => {
      
    })
}
 
const systemClick = (data: TreeNode) => {};
</script>
 
<style lang="less" scoped>
.tree-menu-box {
  height: 100%;
  background-color: #fff;
  .flex {
    height: 100%;
  }
}
.tree-menu {
  width: 260px;
  height: 100%;
  border-right: 1px solid #e9eef3;
  :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>