Przeglądaj źródła

更新收藏接口

reghao 2 lat temu
rodzic
commit
33a18d1859
2 zmienionych plików z 29 dodań i 31 usunięć
  1. 13 1
      src/api/collect.js
  2. 16 30
      src/views/user/Collection.vue

+ 13 - 1
src/api/collect.js

@@ -1,7 +1,9 @@
-import { get, post } from '@/utils/request'
+import { get, post, delete0 } from '@/utils/request'
 
 const collectApi = {
   collectVideoApi: '/api/content/collect/video',
+  deleteCollectApi: '/api/content/collect/video/delete',
+  eraseCollectApi: '/api/content/collect/video/erase',
   userCollectionApi: '/api/content/collect/video',
 }
 
@@ -10,6 +12,16 @@ export function collectVideo(data) {
   return post(collectApi.collectVideoApi, data)
 }
 
+// 删除收藏
+export function deleteVideoCollection(videoId) {
+  return delete0(collectApi.deleteCollectApi + '/' + videoId)
+}
+
+// 清空收藏夹
+export function eraseVideoCollection() {
+  return delete0(collectApi.eraseCollectApi)
+}
+
 // 获取用户收藏
 export function getUserCollection(pageNumber) {
   return get(collectApi.userCollectionApi + '?pageNumber=' + pageNumber)

+ 16 - 30
src/views/user/Collection.vue

@@ -56,7 +56,7 @@
 
 <script>
 import VideoCard from '@/components/card/VideoCard'
-import { getUserCollection } from "@/api/collect";
+import { getUserCollection, deleteVideoCollection, eraseVideoCollection } from "@/api/collect";
 
 export default {
   name: 'Collection',
@@ -99,21 +99,14 @@ export default {
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        console.log('从收藏夹中删除 ' + videoId)
-        // 确认
-        /* removeCollection(this.uid, video.vid).then(res => {
-          // console.log(res);
-          // 将要删除的当前video对象移除数组
-          // 获取下标
-          const index = this.dataList.indexOf(video)
-          if (index > -1) {
-            this.dataList.splice(index, 1)
+        deleteVideoCollection(videoId).then(res => {
+          if (res.code === 0) {
+            this.$message({
+              type: 'success',
+              message: '移除成功!'
+            })
+            this.$router.go(0)
           }
-        })*/
-
-        this.$message({
-          type: 'success',
-          message: '移除成功!'
         })
       }).catch(() => {
         this.$message({
@@ -129,22 +122,15 @@ export default {
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        console.log('清空收藏夹')
-
-        const arr = []
-        for (const i of this.dataList) {
-          arr.push(i.vid)
-        }
-        // const vidStr = arr.join(',')
-        // console.log(vidStr);
-        // 确认
-        /* removeCollection(this.uid, vidStr).then(res => {
-          this.dataList = []
-        })*/
+        eraseVideoCollection().then(res => {
+          if (res.code === 0) {
+            this.$message({
+              type: 'success',
+              message: '收藏夹已清空!'
+            })
 
-        this.$message({
-          type: 'success',
-          message: '移除成功!'
+            this.$router.go(0)
+          }
         })
       }).catch(() => {
         this.$message({