Просмотр исходного кода

【我的素材】调通重命名功能

任一存 4 лет назад
Родитель
Сommit
f8985b3fa2

+ 13 - 5
src/views/material/audio/index.vue

@@ -117,6 +117,7 @@
       </div>
     </div>
 
+    <!-- TODO: :show改用v-show以避免重命名完成后控制台报错 -->
     <rename
       :item="popupItem"
       :show="showRename"
@@ -161,7 +162,7 @@ export default {
       config,
       showRename: false,
       showList: false,
-      popupItem: "",
+      popupItem: null,
       tabHeader: data,
       selectedArr: [],
       searchKey: "",
@@ -190,17 +191,24 @@ export default {
         }
       });
     },
-    handleRename(data) {
+    handleRename(newName) {
       editMaterial(
         {
           id: this.popupItem.id,
-          name: data,
+          name: newName,
         },
         () => {
           this.$msg.success("修改成功");
+          const index = this.list.findIndex((eachItem) => {
+            return eachItem.id === this.popupItem.id
+          })
+          if (index >= 0) {
+            this.list[index].name = newName
+          } else {
+            console.error('在素材列表里没找到要重命名的那一项!');
+          }
           this.showRename = false;
-          this.popupItem = "";
-          this.getMaterialList();
+          this.popupItem = null;
         }
       );
     },

+ 12 - 6
src/views/material/image/index.vue

@@ -166,7 +166,7 @@ export default {
       showPreview: false,
       showRename: false,
       showList: false,
-      popupItem: "",
+      popupItem: null,
       tabHeader: data,
       selectedArr: [],
       searchKey: "",
@@ -192,21 +192,27 @@ export default {
       const viewer = this.$el.querySelector("#" + id).$viewer;
       viewer.show();
     },
-    handleRename(data) {
+    handleRename(newName) {
       editMaterial(
         {
           id: this.popupItem.id,
-          name: data,
+          name: newName,
         },
         () => {
           this.$msg.success("修改成功");
+          const index = this.list.findIndex((eachItem) => {
+            return eachItem.id === this.popupItem.id
+          })
+          if (index >= 0) {
+            this.list[index].name = newName
+          } else {
+            console.error('在素材列表里没找到要重命名的那一项!');
+          }
           this.showRename = false;
-          this.popupItem = "";
-          this.getMaterialList();
+          this.popupItem = null;
         }
       );
     },
-
     delUploadItem(index) {
       ~index && this.uploadList.splice(index, 1);
     },

+ 12 - 5
src/views/material/pano/index.vue

@@ -203,7 +203,7 @@ export default {
       showPreview: false,
       showCover: false,
       showList: false,
-      popupItem: "",
+      popupItem: null,
       tabHeader: data,
       selectedArr: [],
       searchKey: "",
@@ -245,17 +245,24 @@ export default {
         this._checkMStatus(true);
       }, LONGPOLLINGTIME * 1000);
     },
-    handleRename(data) {
+    handleRename(newName) {
       editMaterial(
         {
           id: this.popupItem.id,
-          name: data,
+          name: newName,
         },
         () => {
           this.$msg.success("修改成功");
+          const index = this.list.findIndex((eachItem) => {
+            return eachItem.id === this.popupItem.id
+          })
+          if (index >= 0) {
+            this.list[index].name = newName
+          } else {
+            console.error('在素材列表里没找到要重命名的那一项!');
+          }
           this.showRename = false;
-          this.popupItem = "";
-          this.getMaterialList();
+          this.popupItem = null;
         }
       );
     },

+ 12 - 5
src/views/material/video/index.vue

@@ -165,7 +165,7 @@ export default {
       showRename: false,
       showList: false,
       showPreview: false,
-      popupItem: "",
+      popupItem: null,
       tabHeader: data,
       selectedArr: [],
       searchKey: "",
@@ -187,17 +187,24 @@ export default {
   watch: {
   },
   methods: {
-    handleRename(data) {
+    handleRename(newName) {
       editMaterial(
         {
           id: this.popupItem.id,
-          name: data,
+          name: newName,
         },
         () => {
           this.$msg.success("修改成功");
+          const index = this.list.findIndex((eachItem) => {
+            return eachItem.id === this.popupItem.id
+          })
+          if (index >= 0) {
+            this.list[index].name = newName
+          } else {
+            console.error('在素材列表里没找到要重命名的那一项!');
+          }
           this.showRename = false;
-          this.popupItem = "";
-          this.getMaterialList();
+          this.popupItem = null;
         }
       );
     },