|
@@ -126,13 +126,15 @@ export default {
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState({
|
|
|
- user: state => state.user
|
|
|
+ user: state => state.user,
|
|
|
+ favorite: state => state.favorite
|
|
|
})
|
|
|
},
|
|
|
created() {},
|
|
|
mounted() {
|
|
|
this.getContent();
|
|
|
this.checkReadMaterial();
|
|
|
+ this.checkCollection();
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
clearInterval(this.startStudyInterval);
|
|
@@ -211,6 +213,11 @@ export default {
|
|
|
)
|
|
|
.then(res => {
|
|
|
this.isCollected = true;
|
|
|
+ // 新增收藏缓存
|
|
|
+ this.$store.commit("addFavoriteItemStore", {
|
|
|
+ field: "materials",
|
|
|
+ value: this.materialId
|
|
|
+ });
|
|
|
})
|
|
|
.catch(() => {
|
|
|
this.$store.commit("toggleLoading", false);
|
|
@@ -236,6 +243,11 @@ export default {
|
|
|
)
|
|
|
.then(res => {
|
|
|
this.isCollected = false;
|
|
|
+ // 删除收藏缓存
|
|
|
+ this.$store.commit("deleteFavoriteItemStore", {
|
|
|
+ field: "materials",
|
|
|
+ value: this.materialId
|
|
|
+ });
|
|
|
})
|
|
|
.catch(() => {
|
|
|
this.$store.commit("toggleLoading", false);
|
|
@@ -314,6 +326,16 @@ export default {
|
|
|
.catch(() => {
|
|
|
this.$store.commit("toggleLoading", false);
|
|
|
});
|
|
|
+ },
|
|
|
+ checkCollection() {
|
|
|
+ if (this.favorite.materials && this.favorite.materials.length > 0) {
|
|
|
+ console.log(this.favorite.materials);
|
|
|
+ console.log(this.materialId);
|
|
|
+ const item = this.favorite.materials.find(it => it === this.materialId);
|
|
|
+ if (item && item === this.materialId) {
|
|
|
+ this.isCollected = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|