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

【我的作品】【我的素材】删除一个元素后填补一个元素以确保无限滚动请求新数据时不会请求到已有的数据。

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

+ 33 - 8
src/views/material/audio/index.vue

@@ -221,14 +221,39 @@ export default {
         ok: () => {
           delMaterial(item.id, () => {
             this.$msg.success("删除成功");
-            const index = this.list.findIndex((eachItem) => {
-              return eachItem.id === item.id
-            })
-            if (index >= 0) {
-              this.list.splice(index, 1)
-            } else {
-              console.error('在素材列表里没找到要删除的那一项!');
-            }
+            this.isRequestingMoreData = true
+            getMaterialList(
+              {
+                pageNum: this.list.length + 1,
+                pageSize: 1,
+                searchKey: this.searchKey,
+                type: TYPE,
+              },
+              (data) => {
+                const index = this.list.findIndex((eachItem) => {
+                  return eachItem.id === item.id
+                })
+                if (index >= 0) {
+                  this.list.splice(index, 1)
+                } else {
+                  console.error('在素材列表里没找到要删除的那一项!');
+                }
+
+                const newData = data.data.list.map((i) => {
+                  i.fileSize = changeByteUnit(Number(i.fileSize));
+                  return i;
+                });
+                this.list = this.list.concat(newData)
+                if (this.list.length === data.data.total) {
+                  this.hasMoreData = false
+                }
+
+                this.isRequestingMoreData = false
+              },
+              () => {
+                this.isRequestingMoreData = false
+              }
+            )
           });
         },
       });

+ 33 - 8
src/views/material/image/index.vue

@@ -222,14 +222,39 @@ export default {
         ok: () => {
           delMaterial(item.id, () => {
             this.$msg.success("删除成功");
-            const index = this.list.findIndex((eachItem) => {
-              return eachItem.id === item.id
-            })
-            if (index >= 0) {
-              this.list.splice(index, 1)
-            } else {
-              console.error('在素材列表里没找到要删除的那一项!');
-            }
+            this.isRequestingMoreData = true
+            getMaterialList(
+              {
+                pageNum: this.list.length + 1,
+                pageSize: 1,
+                searchKey: this.searchKey,
+                type: TYPE,
+              },
+              (data) => {
+                const index = this.list.findIndex((eachItem) => {
+                  return eachItem.id === item.id
+                })
+                if (index >= 0) {
+                  this.list.splice(index, 1)
+                } else {
+                  console.error('在素材列表里没找到要删除的那一项!');
+                }
+
+                const newData = data.data.list.map((i) => {
+                  i.fileSize = changeByteUnit(Number(i.fileSize));
+                  return i;
+                });
+                this.list = this.list.concat(newData)
+                if (this.list.length === data.data.total) {
+                  this.hasMoreData = false
+                }
+
+                this.isRequestingMoreData = false
+              },
+              () => {
+                this.isRequestingMoreData = false
+              }
+            )
           });
         },
       });

+ 33 - 8
src/views/material/pano/index.vue

@@ -355,14 +355,39 @@ export default {
         ok: () => {
           delMaterial(item.id, () => {
             this.$msg.success("删除成功");
-            const index = this.list.findIndex((eachItem) => {
-              return eachItem.id === item.id
-            })
-            if (index >= 0) {
-              this.list.splice(index, 1)
-            } else {
-              console.error('在素材列表里没找到要删除的那一项!');
-            }
+            this.isRequestingMoreData = true
+            getMaterialList(
+              {
+                pageNum: this.list.length + 1,
+                pageSize: 1,
+                searchKey: this.searchKey,
+                type: TYPE,
+              },
+              (data) => {
+                const index = this.list.findIndex((eachItem) => {
+                  return eachItem.id === item.id
+                })
+                if (index >= 0) {
+                  this.list.splice(index, 1)
+                } else {
+                  console.error('在素材列表里没找到要删除的那一项!');
+                }
+
+                const newData = data.data.list.map((i) => {
+                  i.fileSize = changeByteUnit(Number(i.fileSize));
+                  return i;
+                });
+                this.list = this.list.concat(newData)
+                if (this.list.length === data.data.total) {
+                  this.hasMoreData = false
+                }
+
+                this.isRequestingMoreData = false
+              },
+              () => {
+                this.isRequestingMoreData = false
+              }
+            )
           });
         },
       });

+ 33 - 8
src/views/material/video/index.vue

@@ -217,14 +217,39 @@ export default {
         ok: () => {
           delMaterial(item.id, () => {
             this.$msg.success("删除成功");
-            const index = this.list.findIndex((eachItem) => {
-              return eachItem.id === item.id
-            })
-            if (index >= 0) {
-              this.list.splice(index, 1)
-            } else {
-              console.error('在素材列表里没找到要删除的那一项!');
-            }
+            this.isRequestingMoreData = true
+            getMaterialList(
+              {
+                pageNum: this.list.length + 1,
+                pageSize: 1,
+                searchKey: this.searchKey,
+                type: TYPE,
+              },
+              (data) => {
+                const index = this.list.findIndex((eachItem) => {
+                  return eachItem.id === item.id
+                })
+                if (index >= 0) {
+                  this.list.splice(index, 1)
+                } else {
+                  console.error('在素材列表里没找到要删除的那一项!');
+                }
+
+                const newData = data.data.list.map((i) => {
+                  i.fileSize = changeByteUnit(Number(i.fileSize));
+                  return i;
+                });
+                this.list = this.list.concat(newData)
+                if (this.list.length === data.data.total) {
+                  this.hasMoreData = false
+                }
+
+                this.isRequestingMoreData = false
+              },
+              () => {
+                this.isRequestingMoreData = false
+              }
+            )
           });
         },
       });

+ 23 - 6
src/views/material/works/index.vue

@@ -147,18 +147,35 @@ export default {
         window.open(`./edit.html?id=${item.id}`)
     },
     del(item, index){
-      //  this.$msg({
-      //   message: `格式错误,请上传2:1、120MB以内、jpg格式的全景图片`,
-      //   type: 'error',
-      //   duration: 0
-      // });
       this.$confirm({
           title:'删除作品',
           content: "确定要删除作品吗?",
           ok: () => {
               delWorks(item.id,()=>{
                 this.$msg.success("删除成功");
-                this.list.splice(index, 1)
+                this.isRequestingMoreData = true
+                getWorksList(
+                  {
+                    pageNum: this.list.length + 1,
+                    pageSize: 1,
+                    searchKey: this.searchKey
+                  },
+                  (data) => {
+                    this.list.splice(index, 1)
+                    this.list = this.list.concat(data.data.list)
+                    if (this.list.length === data.data.total) {
+                      this.hasMoreData = false
+                    }
+                    this.isRequestingMoreData = false
+                    // TODO: 这是干啥呢?
+                    this.$nextTick(()=>{
+                      this.$bus.emit('refreshTips')
+                    })
+                  },
+                  () => {
+                    this.isRequestingMoreData = false
+                  }
+                )
               });
           },
       });