From e2fdfe540eaf160dc7d063c60667041edcc64e86 Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期二, 05 十一月 2024 22:55:14 +0800
Subject: [PATCH] 处理显示名称

---
 src/views/mdc/MYTree.vue |   40 +++++++++++-----------------------------
 1 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/src/views/mdc/MYTree.vue b/src/views/mdc/MYTree.vue
index 06363fd..f9b59f0 100644
--- a/src/views/mdc/MYTree.vue
+++ b/src/views/mdc/MYTree.vue
@@ -1,11 +1,11 @@
 <!--
  * @Date: 2024-04-18 19:53:35
  * @LastEditors: gaoshp
- * @LastEditTime: 2024-11-04 19:55:07
+ * @LastEditTime: 2024-11-04 20:05:01
  * @FilePath: /cps-web/src/views/mdc/MYTree.vue
 -->
 <template>
-    <el-input v-model="word" style="max-width: 600px" @change="search" placeholder="" class="input-with-select">
+    <el-input v-model="word" style="max-width: 600px" placeholder="" @change="search" class="input-with-select">
         <template #append>
             <el-button :icon="ElementPlusIconsVue.Search" />
         </template>
@@ -84,7 +84,6 @@
     },
     methods: {
         search() {
-            console.log('Search')
             this.getList()
         },
         switchFn(val) {
@@ -117,54 +116,37 @@
             }).then(({ code, data }) => {
                 if (code === 200) {
                     this.tableData = data.filter(v => v.isWorkstation && v.title.indexOf(this.word) > -1)
-                    this.data = this.formatData(data)
+                    this.data = this.formatData(data.filter(v => !v.isWorkstation || (v.isWorkstation && v.title.indexOf(this.word) > -1)))
                     this.$nextTick(() => {
-                        this.currentNodeKey = this.firstWorkKey
-                        this.$emit('loaded', this.firstWorkKey)
+                        this.setCurrentKey(data)
+                        this.$emit('loaded', this.currentNodeKey)
                         this.$emit('request', data)
                     })
                 }
             })
         },
-        setCurrentKey(v) {
-            if (this.firstWorkKey) return
-            if (v.isWorkstation) {
-                this.firstWorkKey = v.id
-            }
+        setCurrentKey(data) {
+            this.currentNodeKey = data.find(v => v.isWorkstation && v.title.indexOf(this.word) > -1).id
         },
         formatData(data, current) {
             let newData = []
             if (!current) {
                 newData = data.filter(item => item.parentId == 0).map(v => {
                     if (!v.isWorkstation) v.disabled = true
-                    let children = this.formatData(data, v).sort((a, b) => {
+                    v.children = this.formatData(data, v).sort((a, b) => {
                         return b.sort - a.sort
                     })
-                    v.children = children.filter(v => {
-                        if (v.isWorkstation) {
-                            return v.title.indexOf(this.word) > -1
-                        } else {
-                            return true
-                        }
-                    })
-                    this.setCurrentKey(v)
+                    // this.setCurrentKey(v)
                     return v
                 })
             } else {
                 let res = data.filter(v => v.parentId == current.id)
                 res = res.map(item => {
                     if (!item.isWorkstation) item.disabled = true
-                    let children = this.formatData(data, item).sort((a, b) => {
+                    item.children = this.formatData(data, item).sort((a, b) => {
                         return b.sort - a.sort
                     })
-                    item.children = children.filter(v => {
-                        if (v.isWorkstation) {
-                            return v.title.indexOf(this.word) > -1
-                        } else {
-                            return true
-                        }
-                    })
-                    this.setCurrentKey(item)
+                    // this.setCurrentKey(item)
                     return item
                 })
                 return res

--
Gitblit v1.9.3