浏览代码

feat: 处理音乐专辑添加多个列表数据,原来的数据不存在的问题

Damon 8 月之前
父节点
当前提交
5bc48859ff
共有 3 个文件被更改,包括 235 次插入21 次删除
  1. 60 1
      src/views/music/album/detail.vue
  2. 89 19
      src/views/music/blog/detail.vue
  3. 86 1
      src/views/music/menu/detail.vue

+ 60 - 1
src/views/music/album/detail.vue

@@ -398,7 +398,65 @@ export default {
 
 
     handleSelectionChange(val) {
     handleSelectionChange(val) {
       if (this.isLoad) {
       if (this.isLoad) {
-        this.form.programList = JSON.parse(JSON.stringify(val));
+        if (this.form.programList.length == 0) {
+          this.form.programList = JSON.parse(JSON.stringify(val));
+        } else {
+          ///查找dialogTableData里面有的
+          var tempDialogHas = [];
+          for (var i = 0; i < this.tableData.length; i++) {
+            for (var j = 0; j < val.length; j++) {
+              if (this.tableData[i].id === val[j].id) {
+                tempDialogHas.push(this.tableData[i]);
+                break;
+              }
+            }
+          }
+
+          ///查找dialogTableData里面没有的
+          var tempDialogNot = [];
+          if (tempDialogHas.length == 0) {
+            tempDialogNot = JSON.parse(JSON.stringify(this.tableData));
+          } else {
+            for (var i = 0; i < this.tableData.length; i++) {
+              var has = false;
+              for (var j = 0; j < tempDialogHas.length; j++) {
+                if (this.tableData[i].id === tempDialogHas[j].id) {
+                  has = true;
+                  break;
+                }
+              }
+              if (!has) {
+                tempDialogNot.push(this.tableData[i]);
+              }
+            }
+          }
+
+          ///减少val没有的
+          if (tempDialogNot.length > 0) {
+            for (var i = 0; i < tempDialogNot.length; i++) {
+              for (var j = 0; j < this.form.programList.length; j++) {
+                if (tempDialogNot[i].id === this.form.programList[j].id) {
+                  this.form.programList.splice(j, 1);
+                  break;
+                }
+              }
+            }
+          }
+
+          ///添加adminPodCastProgramDetailResp没有的
+          for (var i = 0; i < val.length; i++) {
+            var isHas = false;
+            for (var j = 0; j < this.form.programList.length; j++) {
+              if (val[i].id === this.form.programList[j].id) {
+                isHas = true;
+                break;
+              }
+            }
+            if (!isHas) {
+              this.form.programList.push(val[i]);
+            }
+          }
+        }
         this.form.programList = this.form.programList.filter((i) => i);
         this.form.programList = this.form.programList.filter((i) => i);
         this.$message.success("操作成功!");
         this.$message.success("操作成功!");
       }
       }
@@ -462,6 +520,7 @@ export default {
           this.loading = false;
           this.loading = false;
 
 
           this.isLoad = false;
           this.isLoad = false;
+          this.$refs.multipleTable.clearSelection();
           if (this.form.programList.length > 0) {
           if (this.form.programList.length > 0) {
             var temp = [];
             var temp = [];
             for (var i = 0; i < this.tableData.length; i++) {
             for (var i = 0; i < this.tableData.length; i++) {

+ 89 - 19
src/views/music/blog/detail.vue

@@ -116,12 +116,13 @@
           >解除关联</el-button
           >解除关联</el-button
         >
         >
       </el-form-item>
       </el-form-item>
+
       <el-form-item style="width: 100%">
       <el-form-item style="width: 100%">
         <el-table
         <el-table
           :data="form.adminPodCastProgramDetailResp"
           :data="form.adminPodCastProgramDetailResp"
           @selection-change="handleSelect"
           @selection-change="handleSelect"
         >
         >
-          <!-- <el-table-column type="selection" align="center" /> -->
+          <el-table-column type="selection" align="center" />
           <el-table-column
           <el-table-column
             label="ID"
             label="ID"
             prop="id"
             prop="id"
@@ -150,15 +151,6 @@
 
 
           <el-table-column label="操作" align="center">
           <el-table-column label="操作" align="center">
             <template slot-scope="scope">
             <template slot-scope="scope">
-              <Audio :src="scope.row.progaramUrl" />
-
-              <el-button
-                type="delete"
-                :disabled="disabled"
-                @click="getDeletePlus(scope.$index)"
-                >删除</el-button
-              >
-
               <!-- 向上移动 -->
               <!-- 向上移动 -->
               <el-button
               <el-button
                 type="text"
                 type="text"
@@ -489,9 +481,78 @@ export default {
 
 
     handleSelectionChange(val) {
     handleSelectionChange(val) {
       if (this.isLoad) {
       if (this.isLoad) {
-        this.form.adminPodCastProgramDetailResp = JSON.parse(
-          JSON.stringify(val)
-        );
+        if (this.form.adminPodCastProgramDetailResp.length == 0) {
+          this.form.adminPodCastProgramDetailResp = JSON.parse(
+            JSON.stringify(val)
+          );
+        } else {
+          ///查找dialogTableData里面有的
+          var tempDialogHas = [];
+          for (var i = 0; i < this.dialogTableData.length; i++) {
+            for (var j = 0; j < val.length; j++) {
+              if (this.dialogTableData[i].id === val[j].id) {
+                tempDialogHas.push(this.dialogTableData[i]);
+                break;
+              }
+            }
+          }
+
+          ///查找dialogTableData里面没有的
+          var tempDialogNot = [];
+          if (tempDialogHas.length == 0) {
+            tempDialogNot = JSON.parse(JSON.stringify(this.dialogTableData));
+          } else {
+            for (var i = 0; i < this.dialogTableData.length; i++) {
+              var has = false;
+              for (var j = 0; j < tempDialogHas.length; j++) {
+                if (this.dialogTableData[i].id === tempDialogHas[j].id) {
+                  has = true;
+                  break;
+                }
+              }
+              if (!has) {
+                tempDialogNot.push(this.dialogTableData[i]);
+              }
+            }
+          }
+
+          ///减少val没有的
+          if (tempDialogNot.length > 0) {
+            for (var i = 0; i < tempDialogNot.length; i++) {
+              for (
+                var j = 0;
+                j < this.form.adminPodCastProgramDetailResp.length;
+                j++
+              ) {
+                if (
+                  tempDialogNot[i].id ===
+                  this.form.adminPodCastProgramDetailResp[j].id
+                ) {
+                  this.form.adminPodCastProgramDetailResp.splice(j, 1);
+                  break;
+                }
+              }
+            }
+          }
+
+          ///添加adminPodCastProgramDetailResp没有的
+          for (var i = 0; i < val.length; i++) {
+            var isHas = false;
+            for (
+              var j = 0;
+              j < this.form.adminPodCastProgramDetailResp.length;
+              j++
+            ) {
+              if (val[i].id === this.form.adminPodCastProgramDetailResp[j].id) {
+                isHas = true;
+                break;
+              }
+            }
+            if (!isHas) {
+              this.form.adminPodCastProgramDetailResp.push(val[i]);
+            }
+          }
+        }
         this.form.adminPodCastProgramDetailResp =
         this.form.adminPodCastProgramDetailResp =
           this.form.adminPodCastProgramDetailResp.filter((i) => i);
           this.form.adminPodCastProgramDetailResp.filter((i) => i);
         this.$message.success("操作成功!");
         this.$message.success("操作成功!");
@@ -558,6 +619,7 @@ export default {
           this.loading = false;
           this.loading = false;
 
 
           this.isLoad = false;
           this.isLoad = false;
+          this.$refs.multipleTable.clearSelection();
           if (this.form.adminPodCastProgramDetailResp.length > 0) {
           if (this.form.adminPodCastProgramDetailResp.length > 0) {
             var temp = [];
             var temp = [];
             for (var i = 0; i < this.dialogTableData.length; i++) {
             for (var i = 0; i < this.dialogTableData.length; i++) {
@@ -643,6 +705,14 @@ export default {
           this.form.adminPodCastProgramDetailResp.map((i) => {
           this.form.adminPodCastProgramDetailResp.map((i) => {
             this.form.podcastProgramIds.push(i.id);
             this.form.podcastProgramIds.push(i.id);
           });
           });
+
+          console.log(
+            "gasdfasdfqerqewrqerqrqr==000=" +
+              this.form.adminPodCastProgramDetailResp.length
+          );
+          console.log(
+            "gasdfasdfqerqewrqerqrqr==111=" + this.form.podcastProgramIds.length
+          );
           submit(this.form).then((res) => {
           submit(this.form).then((res) => {
             // if (res.code === 0) {
             // if (res.code === 0) {
             if (res.code === 0) {
             if (res.code === 0) {
@@ -665,12 +735,12 @@ export default {
     },
     },
 
 
     // 多选
     // 多选
-    // handleSelect(e) {
-    //   this.ids = [];
-    //   e.map((i) => {
-    //     this.ids.push(i.id);
-    //   });
-    // },
+    handleSelect(e) {
+      this.ids = [];
+      e.map((i) => {
+        this.ids.push(i.id);
+      });
+    },
 
 
     // 取消
     // 取消
     cancel() {
     cancel() {

+ 86 - 1
src/views/music/menu/detail.vue

@@ -416,8 +416,72 @@ export default {
     },
     },
 
 
     handleSelectionChange(val) {
     handleSelectionChange(val) {
+      // if (this.isLoad) {
+      //   this.form.programList = JSON.parse(JSON.stringify(val));
+      //   this.form.programList = this.form.programList.filter((i) => i);
+      //   this.$message.success("操作成功!");
+      // }
+
       if (this.isLoad) {
       if (this.isLoad) {
-        this.form.programList = JSON.parse(JSON.stringify(val));
+        if (this.form.programList.length == 0) {
+          this.form.programList = JSON.parse(JSON.stringify(val));
+        } else {
+          ///查找dialogTableData里面有的
+          var tempDialogHas = [];
+          for (var i = 0; i < this.tableData.length; i++) {
+            for (var j = 0; j < val.length; j++) {
+              if (this.tableData[i].id === val[j].id) {
+                tempDialogHas.push(this.tableData[i]);
+                break;
+              }
+            }
+          }
+
+          ///查找dialogTableData里面没有的
+          var tempDialogNot = [];
+          if (tempDialogHas.length == 0) {
+            tempDialogNot = JSON.parse(JSON.stringify(this.tableData));
+          } else {
+            for (var i = 0; i < this.tableData.length; i++) {
+              var has = false;
+              for (var j = 0; j < tempDialogHas.length; j++) {
+                if (this.tableData[i].id === tempDialogHas[j].id) {
+                  has = true;
+                  break;
+                }
+              }
+              if (!has) {
+                tempDialogNot.push(this.tableData[i]);
+              }
+            }
+          }
+
+          ///减少val没有的
+          if (tempDialogNot.length > 0) {
+            for (var i = 0; i < tempDialogNot.length; i++) {
+              for (var j = 0; j < this.form.programList.length; j++) {
+                if (tempDialogNot[i].id === this.form.programList[j].id) {
+                  this.form.programList.splice(j, 1);
+                  break;
+                }
+              }
+            }
+          }
+
+          ///添加adminPodCastProgramDetailResp没有的
+          for (var i = 0; i < val.length; i++) {
+            var isHas = false;
+            for (var j = 0; j < this.form.programList.length; j++) {
+              if (val[i].id === this.form.programList[j].id) {
+                isHas = true;
+                break;
+              }
+            }
+            if (!isHas) {
+              this.form.programList.push(val[i]);
+            }
+          }
+        }
         this.form.programList = this.form.programList.filter((i) => i);
         this.form.programList = this.form.programList.filter((i) => i);
         this.$message.success("操作成功!");
         this.$message.success("操作成功!");
       }
       }
@@ -456,7 +520,28 @@ export default {
           this.total = res.data.total;
           this.total = res.data.total;
           this.loading = false;
           this.loading = false;
 
 
+          // this.isLoad = false;
+          // if (this.form.programList.length > 0) {
+          //   var temp = [];
+          //   for (var i = 0; i < this.tableData.length; i++) {
+          //     for (var j = 0; j < this.form.programList.length; j++) {
+          //       if (this.form.programList[j].id === this.tableData[i].id) {
+          //         temp.push(this.tableData[i]);
+          //         break;
+          //       }
+          //     }
+          //   }
+
+          //   if (temp.length > 0) {
+          //     temp.forEach((item) => {
+          //       this.$refs.multipleTable.toggleRowSelection(item, true);
+          //     });
+          //   }
+          // }
+          // this.isLoad = true;
+
           this.isLoad = false;
           this.isLoad = false;
+          this.$refs.multipleTable.clearSelection();
           if (this.form.programList.length > 0) {
           if (this.form.programList.length > 0) {
             var temp = [];
             var temp = [];
             for (var i = 0; i < this.tableData.length; i++) {
             for (var i = 0; i < this.tableData.length; i++) {