collection.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="我的收藏"></fa-navbar>
  5. <u-swipe-action v-for="(res, index) in list" :show="res.show" :index="index" :key="res.id" @open="open" @click="click" :options="options">
  6. <view class="comment" @click="goDetail(res)">
  7. <view class="left"><image :src="res.image" mode="aspectFill"></image></view>
  8. <view class="right">
  9. <view class="content u-line-2">{{ res.title }}</view>
  10. <view class="reply-box">
  11. <view class="u-tips-color">收藏于:{{ res.create_date }}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </u-swipe-action>
  16. <!-- 回到顶部 -->
  17. <u-back-top :scroll-top="scrollTop" :icon-style="{ color: theme.bgColor }" :custom-style="{ backgroundColor: lightColor }"></u-back-top>
  18. <!-- 为空 -->
  19. <view class="u-m-t-60 u-p-t-60 u-p-b-60" v-if="is_empty"><u-empty text="您还没有收藏哦..." mode="list"></u-empty></view>
  20. <!-- 更多 -->
  21. <view class="u-p-t-30 u-p-b-30"><u-loadmore :status="has_more ? status : 'nomore'" /></view>
  22. <!-- 底部导航 -->
  23. <fa-tabbar></fa-tabbar>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. list: [],
  31. page: 1,
  32. has_more: false,
  33. status: 'loadmore',
  34. scrollTop: 0,
  35. show: false,
  36. is_empty: false,
  37. options: [
  38. {
  39. text: '删除',
  40. style: {
  41. backgroundColor: '#dd524d'
  42. }
  43. }
  44. ]
  45. };
  46. },
  47. onLoad() {
  48. this.getCollection();
  49. },
  50. methods: {
  51. //列表
  52. getCollection() {
  53. this.$api.getCollection({ page: this.page }).then(res => {
  54. this.status = 'loadmore';
  55. if (res.code == 1) {
  56. let {collectionList} = res.data;
  57. collectionList.data.map(item => {
  58. item.show = false;
  59. });
  60. this.list = [...this.list, ...collectionList.data];
  61. this.has_more = collectionList.last_page > collectionList.current_page;
  62. this.is_empty = !this.list.length;
  63. }
  64. });
  65. },
  66. goDetail(item) {
  67. let p = '';
  68. switch (item.type) {
  69. case 'page':
  70. break;
  71. case 'diyform':
  72. p = '/pages/diyform/detail'
  73. break;
  74. default:
  75. p = '/pages/article/detail';
  76. }
  77. this.$Router.push({
  78. path: p,
  79. query: { id: item.aid }
  80. });
  81. },
  82. click(index, index1) {
  83. this.$api
  84. .delCollection({
  85. id: this.list[index].id
  86. })
  87. .then(res => {
  88. this.$u.toast(res.msg);
  89. if (res.code == 1) {
  90. this.list.splice(index, 1);
  91. }
  92. });
  93. },
  94. open(index) {
  95. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  96. // 原本为'false',再次设置为'false'会无效
  97. this.list[index].show = true;
  98. this.list.map((val, idx) => {
  99. if (index != idx) this.list[idx].show = false;
  100. });
  101. }
  102. },
  103. onPageScroll(e) {
  104. this.scrollTop = e.scrollTop;
  105. },
  106. //底部加载更多
  107. onReachBottom() {
  108. if (this.has_more) {
  109. this.status = 'loading';
  110. this.page++;
  111. this.getCollection();
  112. }
  113. }
  114. };
  115. </script>
  116. <style>
  117. page {
  118. background-color: #ffffff;
  119. }
  120. </style>
  121. <style lang="scss" scoped>
  122. .comment {
  123. display: flex;
  124. padding: 30rpx;
  125. border-bottom: 1px solid #eee;
  126. width: 100vw;
  127. .left {
  128. image {
  129. width: 180rpx;
  130. height: 130rpx;
  131. background-color: #f2f2f2;
  132. border-radius: 10rpx;
  133. }
  134. }
  135. .right {
  136. flex: 1;
  137. padding-left: 20rpx;
  138. font-size: 28rpx;
  139. .content {
  140. margin-bottom: 10rpx;
  141. }
  142. .reply-box {
  143. word-break: break-word;
  144. }
  145. }
  146. }
  147. </style>