瀏覽代碼

修改收藏展示

aaa 4 年之前
父節點
當前提交
e2cd3a7bf2

+ 8 - 3
src/store/modules/favorite.js

@@ -1,7 +1,6 @@
 const favorite = {
 const favorite = {
   state: {
   state: {
-    materials: [], // id列表
-    titles: [] // 标题列表
+    materials: [] // id列表
   },
   },
   mutations: {
   mutations: {
     updateFavoriteItemStore(state, { field, value }) {
     updateFavoriteItemStore(state, { field, value }) {
@@ -12,7 +11,13 @@ const favorite = {
     },
     },
     deleteFavoriteItemStore(state, { field, value }) {
     deleteFavoriteItemStore(state, { field, value }) {
       if (state[field].length > 0) {
       if (state[field].length > 0) {
-        let index = state[field].indexOf(value);
+        let index = "";
+        for (let i = 0; i < state[field].length; i++) {
+          if (state[field][i].id === value.id) {
+            index = i;
+            break;
+          }
+        }
         state[field].splice(index, 1);
         state[field].splice(index, 1);
       }
       }
     }
     }

+ 2 - 6
src/views/home/index.vue

@@ -145,14 +145,10 @@ export default {
       this.$_http
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
         .then(res => {
         .then(res => {
-          if (res.data.materials) {
+          if (res.data) {
             this.$store.commit("updateFavoriteItemStore", {
             this.$store.commit("updateFavoriteItemStore", {
               field: "materials",
               field: "materials",
-              value: res.data.materials
-            });
-            this.$store.commit("updateFavoriteItemStore", {
-              field: "titles",
-              value: res.data.titles
+              value: res.data
             });
             });
           } else {
           } else {
             this.$store.commit("toggleLoading", false);
             this.$store.commit("toggleLoading", false);

+ 4 - 4
src/views/home/learn/page-learn-content.vue

@@ -263,7 +263,7 @@ export default {
           //   新增收藏缓存
           //   新增收藏缓存
           this.$store.commit("addFavoriteItemStore", {
           this.$store.commit("addFavoriteItemStore", {
             field: "materials",
             field: "materials",
-            value: this.materialId
+            value: { materialId: this.materialId }
           });
           });
         })
         })
         .catch(() => {
         .catch(() => {
@@ -293,7 +293,7 @@ export default {
           //   删除收藏缓存
           //   删除收藏缓存
           this.$store.commit("deleteFavoriteItemStore", {
           this.$store.commit("deleteFavoriteItemStore", {
             field: "materials",
             field: "materials",
-            value: this.materialId
+            value: { materialId: this.materialId }
           });
           });
         })
         })
         .catch(() => {
         .catch(() => {
@@ -375,8 +375,8 @@ export default {
       if (this.favorite.materials && this.favorite.materials.length > 0) {
       if (this.favorite.materials && this.favorite.materials.length > 0) {
         console.log(this.favorite.materials);
         console.log(this.favorite.materials);
         console.log(this.materialId);
         console.log(this.materialId);
-        const item = this.favorite.materials.find(it => it === this.materialId);
-        if (item && item === this.materialId) {
+        const item = this.favorite.materials.find(it => it.materialId === this.materialId);
+        if (item && item.materialId === this.materialId) {
           this.isCollected = true;
           this.isCollected = true;
         }
         }
       }
       }

+ 5 - 26
src/views/home/person/collection.vue

@@ -15,12 +15,12 @@
         <div slot="default" class="contentItemDiv">
         <div slot="default" class="contentItemDiv">
           <div>
           <div>
             <div class="contentItemTitle">
             <div class="contentItemTitle">
-              {{ item.name || "学习文章标题" }}
+              {{ item.materialTitle || "学习文章标题" }}
             </div>
             </div>
             <div class="contentItemDescription">
             <div class="contentItemDescription">
               收藏时间:
               收藏时间:
               <span>{{
               <span>{{
-                formateDatesFun(item.createdTime) || item.createdTime
+                formateDatesFun(item.addedTime)
               }}</span>
               }}</span>
             </div>
             </div>
           </div>
           </div>
@@ -70,13 +70,9 @@ export default {
       this.$_http
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
         .then(res => {
         .then(res => {
-          if (res.data.materials) {
-            res.data.materials.forEach((item, index) => {
-              this.getFavoritesDetailFun(
-                item,
-                index + 1 === res.data.materials.length
-              );
-            });
+          if (res.data) {
+            this.favoritesList = res.data;
+            console.log("--index--" + JSON.stringify(this.favoritesList));
             this.finished = true;
             this.finished = true;
           } else {
           } else {
             this.$store.commit("toggleLoading", false);
             this.$store.commit("toggleLoading", false);
@@ -87,23 +83,6 @@ export default {
           this.$store.commit("toggleLoading", false);
           this.$store.commit("toggleLoading", false);
         });
         });
     },
     },
-    // 查询:单个文章的详情
-    getFavoritesDetailFun(item, isLast) {
-      let path = {
-        materialId: item
-      };
-      this.$_http
-        .get(this.$pathParams(this.$_API.JTXT_GET_MATERIAL_MATERIALID, path))
-        .then(res => {
-          this.favoritesList.push(res.data);
-          if (isLast) {
-            this.$store.commit("toggleLoading", false);
-          }
-        })
-        .catch(() => {
-          this.$store.commit("toggleLoading", false);
-        });
-    },
     onLoad() {},
     onLoad() {},
     // 操作:返回
     // 操作:返回
     onClickLeft() {
     onClickLeft() {