Browse Source

添加收藏

aaa 4 years ago
parent
commit
b1d378a6ad
2 changed files with 45 additions and 2 deletions
  1. 3 1
      src/api/modules/user.js
  2. 42 1
      src/views/home/person/collection.vue

+ 3 - 1
src/api/modules/user.js

@@ -5,6 +5,8 @@ export default {
     // 查询根目录
     JTXT_GET_USER_DAIYL_POINTS: "user/{userName}/daily-points",
     //  查询考试历史
-    JTXT_GET_USER_EXAMS_HISTORY: "exams/history"
+    JTXT_GET_USER_EXAMS_HISTORY: "exams/history",
+    // 查询收藏
+    JTXT_GET_USER_FAVORITES: "/user/{userName}/favorites"
   }
 };

+ 42 - 1
src/views/home/person/collection.vue

@@ -1,6 +1,20 @@
 <template>
   <div>
     <van-nav-bar title="收藏" left-arrow @click-left="onClickLeft" />
+    <van-list
+      v-model="loading"
+      :finished="finished"
+      finished-text="没有更多了"
+      @load="onLoad"
+    >
+      <van-cell
+        v-for="(item, index) in favorites"
+        :key="index"
+        :title="item"
+        @click="toMaterialDetail(item)"
+      >
+      </van-cell>
+    </van-list>
   </div>
 </template>
 
@@ -9,14 +23,41 @@ export default {
   name: "collection",
   components: {},
   data() {
-    return {};
+    return {
+      favorites: [],
+      loading: false,
+      finished: false
+    };
   },
   mounted() {
     console.log("--收藏--");
+    this.getFavorites();
   },
   methods: {
+    getFavorites() {
+      let path = {
+        userName: "testuser-zirKBELIlg"
+      };
+      this.$_http
+        .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
+        .then(res => {
+          this.favorites = res.data.materials;
+          console.log("--collection--" + JSON.stringify(this.favorites));
+          this.finished = true;
+        })
+        .catch(() => {
+          this.$store.commit("toggleLoading", false);
+        });
+    },
     onClickLeft() {
       this.$router.back();
+    },
+    onLoad() {},
+    toMaterialDetail(item) {
+      this.$router.push({
+        name: "learn-content",
+        params: { materialId: item }
+      });
     }
   }
 };