From f28363d03c3539b0219c5b58ea8b7db37d50be6f Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期二, 23 四月 2024 22:34:17 +0800
Subject: [PATCH] 编辑时间轴组件

---
 src/views/mdc/MYTree.vue |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/views/mdc/MYTree.vue b/src/views/mdc/MYTree.vue
index c54ec8f..9192086 100644
--- a/src/views/mdc/MYTree.vue
+++ b/src/views/mdc/MYTree.vue
@@ -1,16 +1,17 @@
 <!--
  * @Date: 2024-04-18 19:53:35
  * @LastEditors: Sneed
- * @LastEditTime: 2024-04-18 20:56:37
+ * @LastEditTime: 2024-04-21 10:37:48
  * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/MYTree.vue
 -->
 <template>
     <el-tree ref="treeRef" v-bind="$attrs" :show-checkbox="showCheckbox" :current-node-key="currentNodeKey"
         node-key="id" :props="defalutProps" :data="data" @check-change="checkChange" @node-click="handleNodeClick"
-        highlight-current default-expand-all></el-tree>
+        highlight-current default-expand-all :expand-on-click-node="false" :render-content="renderContent"></el-tree>
 </template>
 
 <script>
+import pmsPng from '@/assets/pms.png'
 export default {
     props: {
         showCheckbox: {
@@ -20,14 +21,19 @@
     },
     data() {
         return {
+            pmsPng,
             firstWorkKey: '',
-            currentNodeKey: '',
+            currentNodeKey: [],
             defalutProps: {
                 label: 'title',
-                children: 'children'
+                children: 'children',
+                disabled: 'disabled',
+                class: (data, node) => {
+                    return this.value.includes(data.id) ? 'active' : ''
+                }
             },
             data: [],
-            value: []
+            value: [],
         }
     },
     watch: {
@@ -42,8 +48,21 @@
     },
     created() {
         this.getList()
+        this.customNodeClass = (data, node) => {
+            return this.currentNodeKey == node.id || this.value.includes(node.id) ? 'active' : ''
+        }
     },
     methods: {
+        renderContent(h, { data }) {
+            let img = data.groupTag == 'fms_beltline'
+            return h('a', {
+                disabled: data.disabled
+            },
+                img ? h('img', {
+                    src: pmsPng
+                }, '') : '',
+                data.title)
+        },
         getList() {
             this.$HTTP.post('/api/blade-cps/group/groupWorkstation/type', {
                 groupCategory: 1,
@@ -53,6 +72,7 @@
                     this.data = this.formatData(data)
                     this.$nextTick(() => {
                         this.currentNodeKey = this.firstWorkKey
+                        this.$emit('loaded', this.firstWorkKey)
                     })
                 }
             })
@@ -67,6 +87,7 @@
             let newData = []
             if (!current) {
                 newData = data.filter(item => item.parentId == 0).map(v => {
+                    if (!v.isWorkstation) v.disabled = true
                     v.children = this.formatData(data, v).sort((a, b) => {
                         return b.sort - a.sort
                     })
@@ -76,6 +97,7 @@
             } else {
                 let res = data.filter(v => v.parentId == current.id)
                 res = res.map(item => {
+                    if (!item.isWorkstation) item.disabled = true
                     item.children = this.formatData(data, item).sort((a, b) => {
                         return b.sort - a.sort
                     })
@@ -87,7 +109,6 @@
             return newData
         },
         handleNodeClick(node) {
-            console.log(node)
             this.$nextTick(() => {
                 if (node.isWorkstation) {
                     this.currentNodeKey = node.id
@@ -102,4 +123,8 @@
 }
 </script>
 
-<style lang="scss" scoped></style>
\ No newline at end of file
+<style lang="scss">
+.active .el-tree-node__content {
+    background: var(--el-color-primary) !important;
+}
+</style>
\ No newline at end of file

--
Gitblit v1.9.3