collection.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 favorites"
  12. :key="index"
  13. @click="toMaterialDetail(item)"
  14. >
  15. <div slot="default" class="contentItemDiv">
  16. <div>
  17. <div class="contentItemTitle">{{ item.name || "学习文章" }}</div>
  18. <div class="contentItemDescription">
  19. <div>
  20. 收藏时间:
  21. {{ "2021-01-01" || formateDateTimeFun(item.startTime) }}
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </van-cell>
  27. </van-list>
  28. </div>
  29. </template>
  30. <script>
  31. import { mapState } from "vuex";
  32. export default {
  33. name: "collection",
  34. components: {},
  35. data() {
  36. return {
  37. favorites: [],
  38. loading: false,
  39. finished: false
  40. };
  41. },
  42. mounted() {
  43. console.log("--收藏--");
  44. this.getFavorites();
  45. },
  46. computed: {
  47. ...mapState({
  48. user: state => state.user
  49. })
  50. },
  51. methods: {
  52. getFavorites() {
  53. let path = {
  54. userName: this.user.userName
  55. };
  56. this.$_http
  57. .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
  58. .then(res => {
  59. this.favorites = res.data.materials;
  60. console.log("--collection--" + JSON.stringify(this.favorites));
  61. this.finished = true;
  62. })
  63. .catch(() => {
  64. this.$store.commit("toggleLoading", false);
  65. });
  66. },
  67. onClickLeft() {
  68. this.$router.back();
  69. },
  70. onLoad() {},
  71. toMaterialDetail(item) {
  72. this.$router.push({
  73. name: "learn-content",
  74. params: { materialId: item }
  75. });
  76. },
  77. formateDateTimeFun(time) {
  78. // 获取当前日期
  79. let date = new Date(time);
  80. // 获取当前月份
  81. let nowMonth = date.getMonth() + 1;
  82. // 获取当前是几号
  83. let strDate = date.getDate();
  84. // 添加分隔符“-”
  85. let seperator = "-";
  86. // 对月份进行处理,1-9月在前面添加一个“0”
  87. if (nowMonth >= 1 && nowMonth <= 9) {
  88. nowMonth = "0" + nowMonth;
  89. }
  90. // 对月份进行处理,1-9号在前面添加一个“0”
  91. if (strDate >= 0 && strDate <= 9) {
  92. strDate = "0" + strDate;
  93. }
  94. // 最后拼接字符串,得到一个格式为(yyyy-MM-dd)的日期
  95. return date.getFullYear() + seperator + nowMonth + seperator + strDate;
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .contentBody {
  102. background-color: #fff;
  103. .contentItemDiv {
  104. .contentItemTitle {
  105. font-size: 0.65rem;
  106. font-weight: bold;
  107. }
  108. .contentItemDescription {
  109. display: flex;
  110. justify-content: space-between;
  111. align-items: center;
  112. }
  113. }
  114. }
  115. </style>