rkljw 2 dni temu
rodzic
commit
46a5211a2b
1 zmienionych plików z 38 dodań i 32 usunięć
  1. 38 32
      src/views/website/categoryList.vue

+ 38 - 32
src/views/website/categoryList.vue

@@ -389,19 +389,14 @@ export default {
       parentData: {
         checkStrictly: true,
         lazy: true,
-        // Use an arrow function to maintain the correct `this` context
         lazyLoad: async (node, resolve) => {
+          const { level, data } = node;
+          if (data && data.children && data.children.length !== 0) {
+            return resolve(node);
+          }
+          const parentId = level === 0 ? 0 : data.value;
           try {
-            const { level, data } = node;
-            if (data && data.children && data.children.length !== 0) {
-              return resolve(node);
-            }
-            const parentId = level === 0 ? 0 : data.value;
-            const parames = {
-              pid: parentId
-            };
-            // Now `this` refers to the Vue instance
-            const res = await this.$store.dispatch('pool/categoryList', parames);
+            const res = await this.$store.dispatch('pool/categoryList', { pid: parentId });
             if (res.data) {
               const nodes = res.data.map(item => ({
                 value: item.id,
@@ -450,7 +445,7 @@ export default {
   
       this.$store.dispatch('pool/getCategoryList', this.getApiData).then(res => {
         // console.log("=============:",res.data)
-        this.tableData = res.data.rows; //��与内容
+        this.tableData = res.data.rows; //与内容
         this.allCount = res.data.total
       }).catch(() => {
         this.$message({
@@ -530,30 +525,41 @@ export default {
       this.windowStatus = true;
     },
     //2.1.1 添加栏目池
-    addCategoryList(row) {
-      this.form.pid_arr =[];
+    async addCategoryList(row) {
+      this.form.pid_arr = [];
       this.show_url = false;
-      // this.form.is_url = 0;
       this.editId = 0;
       this.editBtn = false;
-      this.tags = []
-      if(row){
-        if(row.pid==0){
-          console.log("ceshi:::",row.id)
-          this.form.pid_arr.push(row.id)
-        }else{
-          let pidArr = [];
-          // console.log("fuck:",row.pid_arr);
-          pidArr =  JSON.parse(row.pid_arr)
-          console.log("ceshi:::###",pidArr,row.id)
-          pidArr.push(row.id)
-          this.form.pid_arr = pidArr
-          // console.log('追加id:',this.form.pid_arr)
+      this.tags = [];
+      
+      if(row) {
+        let pidArr = [];
+        if(row.pid == 0) {
+          pidArr = [row.id];
+        } else {
+          try {
+            pidArr = JSON.parse(row.pid_arr);
+            pidArr.push(row.id);
+          } catch(e) {
+            pidArr = [];
+          }
+        }
+        
+        // 先打开窗口
+        this.openWindow();
+        
+        // 预加载数据
+        for(let i = 0; i < pidArr.length; i++) {
+          const parentId = i === 0 ? 0 : pidArr[i - 1];
+          await this.$store.dispatch('pool/categoryList', { pid: parentId });
         }
+        
+        // 设置值并更新 key
+        this.form.pid_arr = pidArr;
+        this.parentKey += 1;
+      } else {
+        this.openWindow();
       }
-      // console.log(this.form.pid_arr)
-      console.log("=========:", this.form.pid_arr)
-      this.openWindow();
     },
     //2.2 关闭弹出框
     closeWindow() {
@@ -774,7 +780,7 @@ export default {
 
 ::v-deep .custom-textarea .el-textarea__inner {
   resize: none;
-  /* 禁止用���拖拽调整大小 */
+  /* 禁止用拖拽调整大小 */
 }
 
 ::v-deep .custom-align-right .el-form-item__label {