collection.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="contentBody">
  3. <van-nav-bar title="收藏" left-arrow @click-left="onClickLeft" />
  4. <van-list
  5. v-model="loading"
  6. :finished="finished"
  7. finished-text="没有更多了"
  8. @load="onLoad"
  9. >
  10. <van-cell
  11. v-for="(item, index) in favoritesList"
  12. :key="index"
  13. @click="toMaterialDetail(item)"
  14. >
  15. <div slot="default" class="contentItemDiv">
  16. <div>
  17. <div class="contentItemTitle">
  18. {{ item.materialTitle || "学习文章标题" }}
  19. </div>
  20. <div class="contentItemDescription">
  21. 收藏时间:
  22. <span>{{
  23. formateDatesFun(item.addedTime)
  24. }}</span>
  25. </div>
  26. </div>
  27. </div>
  28. </van-cell>
  29. </van-list>
  30. </div>
  31. </template>
  32. <script>
  33. import { mapState } from "vuex";
  34. export default {
  35. name: "collection",
  36. components: {},
  37. data() {
  38. return {
  39. favoritesList: [],
  40. loading: false,
  41. finished: false
  42. };
  43. },
  44. created() {
  45. this.getFavorites();
  46. this.setLanXinNavigator();
  47. },
  48. activated() {
  49. this.setLanXinNavigator();
  50. },
  51. computed: {
  52. ...mapState({
  53. user: state => state.user
  54. })
  55. },
  56. methods: {
  57. // 设置蓝信navigator
  58. setLanXinNavigator() {
  59. lx.ui.setNavigationBarTitle({
  60. title: "收藏"
  61. });
  62. },
  63. // 查询:收藏的文字ID列表
  64. getFavorites() {
  65. this.$store.commit("toggleLoading", true);
  66. let path = {
  67. userName: this.user.userInfo.userName
  68. };
  69. this.$_http
  70. .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
  71. .then(res => {
  72. if (res.data) {
  73. this.favoritesList = res.data;
  74. console.log("--index--" + JSON.stringify(this.favoritesList));
  75. this.finished = true;
  76. } else {
  77. this.$store.commit("toggleLoading", false);
  78. }
  79. this.loading = false;
  80. })
  81. .catch(() => {
  82. this.$store.commit("toggleLoading", false);
  83. });
  84. },
  85. onLoad() {},
  86. // 操作:返回
  87. onClickLeft() {
  88. this.$router.back();
  89. },
  90. toMaterialDetail(item) {
  91. this.$router.push({
  92. name: "learn-content",
  93. params: { materialId: item.id }
  94. });
  95. }
  96. }
  97. };
  98. </script>
  99. <style lang="scss" scoped>
  100. .contentBody {
  101. background-color: #fff;
  102. .contentItemDiv {
  103. .contentItemTitle {
  104. font-size: 0.65rem;
  105. font-weight: bold;
  106. }
  107. .contentItemDescription {
  108. margin-top: 0.5rem;
  109. color: #696969;
  110. span {
  111. margin-left: 0.5rem;
  112. }
  113. }
  114. }
  115. }
  116. </style>