Kaynağa Gözat

添加修改积分

aaa 4 yıl önce
ebeveyn
işleme
d841f74355

+ 14 - 14
src/store/modules/favorite.js

@@ -1,17 +1,17 @@
-const exam = {
-    state: {
-        materials: [], // id列表
-        titles: [] // 标题列表
+const favorite = {
+  state: {
+    materials: [], // id列表
+    titles: [] // 标题列表
+  },
+  mutations: {
+    updateFavoriteItemStore(state, { field, value }) {
+      state[field] = value;
     },
-    mutations: {
-        updateFavoriteItemStore(state, { field, value }) {
-            state[field] = value;
-        },
-        addFavoriteItemStore(state, { field, value }) {
-            state[field].push(value);
-        }
-    },
-    actions: {}
+    addFavoriteItemStore(state, { field, value }) {
+      state[field].push(value);
+    }
+  },
+  actions: {}
 };
 
-export default exam;
+export default favorite;

+ 34 - 0
src/views/home/index.vue

@@ -31,6 +31,7 @@ import PageLearn from "./learn/page-learn";
 import PageAnswer from "./answer/page-answer";
 import PageExam from "./exam/page-exam";
 import PagePerson from "./person/page-person";
+import { mapState } from "vuex";
 export default {
   name: "home",
   components: { PageLearn, PageAnswer, PageExam, PagePerson },
@@ -66,8 +67,14 @@ export default {
       ]
     };
   },
+  computed: {
+    ...mapState({
+      user: state => state.user
+    })
+  },
   created() {
     this.initFun();
+    this.getCollection();
   },
   methods: {
     initFun() {
@@ -92,6 +99,33 @@ export default {
     },
     onChange(index) {
       this.currentComponents = this.tabbars[this.activeTabName].pageName;
+    },
+    // 获取所有收藏
+    getCollection() {
+      let path = {
+        userName: this.user.userInfo.userName
+      };
+      this.$_http
+        .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
+        .then(res => {
+          if (res.data.materials) {
+            console.log(res.data.materials);
+            this.$store.commit("updateFavoriteItemStore", {
+              field: "materials",
+              value: res.data.materials.materials
+            });
+            this.$store.commit("updateFavoriteItemStore", {
+              field: "titles",
+              value: res.data.materials.titles
+            });
+          } else {
+            this.$store.commit("toggleLoading", false);
+          }
+          this.loading = false;
+        })
+        .catch(() => {
+          this.$store.commit("toggleLoading", false);
+        });
     }
   }
 };

+ 1 - 4
src/views/home/learn/page-learn-child.vue

@@ -96,9 +96,7 @@ export default {
     };
   },
   computed: {},
-  created() {
-    console.log("---");
-  },
+  created() {},
   mounted() {},
   watch: {
     //   第一次加载内容
@@ -134,7 +132,6 @@ export default {
           )
         )
         .then(res => {
-          console.log("--ContentList----ed-");
           this.contentList = res.data;
           this.finished = true;
         })

+ 49 - 2
src/views/home/learn/page-learn-content.vue

@@ -119,7 +119,8 @@ export default {
       isCollected: false, // 是否被收藏了
       commentList: [], // 评论列表内容
       commentValue: "", // 即将评论的内容
-      startStudyInterval: null
+      startStudyInterval: null,
+      isRead: false
     };
   },
   computed: {
@@ -130,6 +131,7 @@ export default {
   created() {},
   mounted() {
     this.getContent();
+    this.checkReadMaterial();
   },
   beforeDestroy() {
     clearInterval(this.startStudyInterval);
@@ -185,6 +187,9 @@ export default {
           this.seconds--;
         } else {
           Toast("学习完成");
+          if (this.isRead) {
+            this.ReadMaterial();
+          }
           clearInterval(this.startStudyInterval);
         }
       }, 1000);
@@ -246,7 +251,7 @@ export default {
         materialId: this.materialId
       };
       let params = {
-        userId: "testuser-ztdxxDGdNj",
+        userId: this.user.userInfo.userName,
         content: inputVal,
         materialId: this.materialId
       };
@@ -268,6 +273,48 @@ export default {
     // 操作:取消评论
     canclePostCommentFun() {
       this.commentValue = "";
+    },
+    // 检查是否可以阅读
+    checkReadMaterial() {
+      let path = {
+        materialId: this.materialId
+      };
+      let params = {
+        user: this.user.userInfo.userName
+      };
+      this.$_http
+        .get(this.$pathParams(this.$_API.JTXT_GET_MATERIALS_READ, path), {
+          params
+        })
+        .then(res => {
+          this.isRead = res;
+          console.log(this.isRead);
+          if (this.isRead) {
+            this.ReadMaterial();
+          }
+        })
+        .catch(() => {
+          this.$store.commit("toggleLoading", false);
+        });
+    },
+    ReadMaterial() {
+      let path = {
+        materialId: this.materialId
+      };
+      let params = {
+        user: this.user.userInfo
+      };
+      this.$_http
+        .post(
+          this.$pathParams(this.$_API.JTXT_POST_MATERIALS_READ, path),
+          params
+        )
+        .then(res => {
+          console.log(res);
+        })
+        .catch(() => {
+          this.$store.commit("toggleLoading", false);
+        });
     }
   }
 };