From 51ad1f2614bc1f976aad98254649bb3c207332ee Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期三, 11 九月 2024 16:50:35 +0800
Subject: [PATCH] 转换树结构方法优化

---
 packageBookService/pages/bookServices/detail/index.js |   88 ++++++++++++++++++++++++++++++-------------
 1 files changed, 61 insertions(+), 27 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 99d3595..7dc1abf 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -169,6 +169,37 @@
       description: '',
       agree: false
     },
+    resourceVisible: false,
+    resourceValue: [],
+    fileTypeList: [{
+        label: '闊抽',
+        value: '闊抽'
+      },
+      {
+        label: '瑙嗛',
+        value: '瑙嗛'
+      },
+      {
+        label: '鍥剧墖',
+        value: '鍥剧墖'
+      },
+      {
+        label: 'PDF',
+        value: 'PDF'
+      },
+      {
+        label: '璧勬簮鍖�',
+        value: '璧勬簮鍖�'
+      },
+      {
+        label: '鏂囨。',
+        value: '鏂囨。'
+      },
+      {
+        label: '鍏朵粬',
+        value: '鍏朵粬'
+      }
+    ],
     fileList: [],
     isShowUp: true,
     protocolShow: false,
@@ -842,10 +873,9 @@
   },
 
   // 鎵佸钩鍖栨暟鎹浆鎹ree
-  getTreeList(rootList, pathLength, newArr, path) {
+  getTreeList(rootList, newArr, path) {
     for (const item of rootList) {
-      // 姝ゅ鍘熸湰 item.productLinkPath.length == pathLength 浣� productLinkPath 闀垮害涓埆涔﹀瓨鍦�4銆�5浣嶄氦閿�
-      if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) {
+      if (path == item.productLinkPath.replace('\\' + item.id, '')) {
         if (item.sysType == 'CmsItem') {
           if (item.selectType == 'webpage') {
             item.disabled = true
@@ -866,11 +896,9 @@
       }
     }
     //缁欐暟缁勯噷闈㈠啀娣诲姞涓�涓猚hildren鐨勭┖鏁扮粍
-    // let addnum1 = pathLength - path.length == 6 ? 6 : 7
     for (const i of newArr) {
       i.children = []
-      let addnum1 = i.productLinkPath.length - path.length == 6 ? 6 : 7
-      this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath)
+      this.getTreeList(rootList, i.children, i.productLinkPath)
       if (i.children.length == 0) {
         delete i.children
       }
@@ -897,26 +925,19 @@
   // 鎺掑簭鏁扮粍 鎸夌収productLinkPath
   insertAndSortObjectsByProductLinkPath(array, newObj) {
     // 鏌ユ壘鏂板璞″簲璇ユ彃鍏ョ殑浣嶇疆  
-    let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.lastIndexOf('\\') + 1, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.lastIndexOf('\\') + 1, obj.productLinkPath.length)));
+    let insertIndex = array.findIndex(obj => newObj.id < obj.id);
     // 濡傛灉娌℃湁鎵惧埌鍚堥�傜殑浣嶇疆锛屽垯鏀惧湪鏁扮粍鏈熬  
     if (insertIndex === -1) {
       insertIndex = array.length;
     }
     // 鎻掑叆鏂板璞″埌鏁扮粍  
     array.splice(insertIndex, 0, newObj);
-    // 娴嬭瘯6 姝e紡5
     // 瀵规暟缁勮繘琛屾帓搴�  
     array.sort((a, b) => {
-      if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) {
-        return -1;
-      }
-      if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) {
-        return 1;
-      }
-      // a must be equal to b  
+      if (a.id < b.id) return -1;
+      if (a.id > b.id) return 1;
       return 0;
     });
-
     // 杩斿洖鏇存柊鍚庣殑鏁扮粍  
     return array;
   },
@@ -1008,9 +1029,7 @@
             })
           }
         }
-        const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6
-        const num = query.cmsPath.length + addNum
-        this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\')
+        this.getTreeList(res.datas.cmsDatas[0].datas, list, query.cmsPath)
         list = this.ensureTreeConsistency(list)
         list = this.changeResourceChildren(list)
         let result = [];
@@ -1120,11 +1139,7 @@
             }
             if (data.length > 0) {
               let list = []
-              // 娴嬭瘯 6浣�// 姝e紡 5浣�//  娴嬭瘯璋冪敤浼�20锛屽唴閮�7  姝e紡璋冪敤浼�17 鍐呴儴浼�6
-
-              const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6
-              const num = query.cmsPath.length + addNum
-              that.getTreeList(data, num, list, '\\')
+              that.getTreeList(data, list, query.cmsPath)
               list = that.ensureTreeConsistency(list)
               that.findChildIds(list[0].children, result);
               that.setData({
@@ -2647,9 +2662,24 @@
       'resourceInfo.resourceName': e.detail.value,
     });
   },
-  onFileTypeInput(e) {
+  onResourcePicker(e) {
     this.setData({
-      'resourceInfo.fileType': e.detail.value,
+      resourceVisible: true,
+    });
+  },
+  onPickerChange(e) {
+    const {
+      value
+    } = e.detail;
+    this.setData({
+      resourceVisible: false,
+      resourceValue: value,
+      'resourceInfo.fileType': value.join(' '),
+    });
+  },
+  onPickerCancel(e) {
+    this.setData({
+      resourceVisible: false,
     });
   },
   textareaChange(e) {
@@ -2690,6 +2720,7 @@
         const pdfData = ['pdf']
         const Compression = ['rar', 'zip']
         const pictureData = ['jpg', 'png']
+        const documentData = ['doc', 'docx', 'xls', 'xlsx', "ppt", "pptx"]
         if (audioData.indexOf(Extension) > -1) {
           medioType = '闊抽'
         } else if (videoData.indexOf(Extension) > -1) {
@@ -2700,6 +2731,8 @@
           medioType = '璧勬簮鍖�'
         } else if (pictureData.indexOf(Extension) > -1) {
           medioType = '鍥剧墖'
+        } else if (documentData.indexOf(Extension) > -1) {
+          medioType = '鏂囨。'
         } else {
           medioType = '鍏朵粬'
         }
@@ -2743,6 +2776,7 @@
                     that.setData({
                       "resourceInfo.resourceName": FileName,
                       "resourceInfo.fileType": medioType,
+
                       fileList: file,
                       isShowUp: false
                     })
@@ -2772,7 +2806,7 @@
     if (this.data.resourceInfo.fileType == '') {
       return wx.showToast({
         icon: "error",
-        title: "璇峰~鍐欒祫婧愮被鍨�",
+        title: "璇烽�夋嫨璧勬簮绫诲瀷",
       });
     }
 

--
Gitblit v1.9.1