save.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="main">
  3. <view class="container">
  4. <view class="prompt-message" style="text-align: center;margin: 20px 0;" v-if="collectList.length<=0">
  5. 没有更多数据了...
  6. </view>
  7. <uni-swipe-action v-else>
  8. <view class="list" :key="index" v-for="(item , index) in collectList" @click="articleDetails(item.id)">
  9. <uni-swipe-action-item :options="options" @click="uncollect(item.id)" class="list-item">
  10. <view class="infobox">
  11. <view class="left">
  12. <view class="infoname">{{item.title}}</view>
  13. <view class="infotxt">{{item.gist == null? '': item.gist}}</view>
  14. <view class="infolook">
  15. <image src="../../static/index/look.png"></image>
  16. <view>{{ item.virtual_view + item.view }}</view>
  17. </view>
  18. </view>
  19. <view class="right">
  20. <image :src="item.image"></image>
  21. </view>
  22. </view>
  23. </uni-swipe-action-item>
  24. </view>
  25. </uni-swipe-action>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. // 引入uniapp滑动组件
  31. import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
  32. import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue'
  33. export default {
  34. name: 'CollectList',
  35. components: {
  36. uniSwipeAction,
  37. uniSwipeActionItem
  38. },
  39. data() {
  40. return {
  41. options: [{
  42. text: '取消收藏',
  43. style: {
  44. backgroundColor: 'rgb(255,58,49)'
  45. }
  46. }, ],
  47. collectList: []
  48. }
  49. },
  50. onLoad() {
  51. },
  52. mounted() {
  53. this.CollectData()
  54. },
  55. methods: {
  56. // 下拉刷新数据
  57. onPullDownRefresh: function() {
  58. this.CollectData()
  59. setTimeout(function() {
  60. uni.stopPullDownRefresh();
  61. }, 1000);
  62. },
  63. async CollectData() {
  64. let res = await this.$request.post('/api/Article/favoriteList');
  65. console.log(res.data)
  66. if (res.code == 200) {
  67. this.collectList = res.data
  68. console.log(this.collectList)
  69. } else {
  70. uni.showToast({
  71. icon: 'none',
  72. title: res.message
  73. })
  74. }
  75. },
  76. // 删除函数
  77. async uncollect(id) {
  78. console.log(id)
  79. let url = '/api/article/deleteFavroite?id=' + id
  80. let res = await this.$request.post(url);
  81. if (res.code == 200) {
  82. uni.showToast({
  83. title: '取消成功'
  84. })
  85. this.CollectData()
  86. } else {
  87. uni.showToast({
  88. icon: 'none',
  89. title: res.message
  90. })
  91. }
  92. },
  93. // 跳转到文章详情
  94. articleDetails(id) {
  95. uni.navigateTo({
  96. url: '/pages/index/articleDetails?id=' + id
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style>
  103. page {
  104. background: #F5F5F5;
  105. }
  106. .main {
  107. width: 100vw;
  108. height: auto;
  109. margin-bottom: 20px;
  110. }
  111. .container {
  112. padding: 0 15px;
  113. }
  114. .list {
  115. width: 100%;
  116. height: auto;
  117. margin-top: 20px;
  118. }
  119. .list .infobox {
  120. width: 100%;
  121. /* height: 200rpx; */
  122. /* margin: 15px 0; */
  123. padding: 15rpx;
  124. display: flex;
  125. justify-content: space-between;
  126. background: #fff;
  127. border-radius: 5px;
  128. }
  129. .infobox .left {
  130. width: 54vw;
  131. }
  132. .infobox .right {
  133. width: 34vw;
  134. }
  135. .infobox .right .right-img-item {
  136. border-radius: 12rpx;
  137. }
  138. .right image {
  139. width: 100%;
  140. height: 100%;
  141. }
  142. .left .infoname {
  143. /* width: 100%; */
  144. /* height: 80rpx; */
  145. font-size: 32rpx;
  146. font-weight: 400;
  147. color: rgba(85, 88, 100, 1);
  148. font-family: PingFangSC-Regular, sans-serif;
  149. /* overflow: hidden; */
  150. }
  151. .left .infotxt {
  152. width: 100%;
  153. /* height: 92rpx; */
  154. display: flex;
  155. align-items: center;
  156. color: #999;
  157. font-size: 24rpx;
  158. font-family: PingFangSC-Regular, sans-serif;
  159. overflow: hidden;
  160. text-overflow: ellipsis;
  161. white-space: nowrap;
  162. }
  163. .left .infolook {
  164. width: 100%;
  165. height: 50rpx;
  166. display: flex;
  167. align-items: center;
  168. }
  169. .infolook image {
  170. width: 34rpx;
  171. height: 34rpx;
  172. margin: 2px;
  173. border-radius: 12rpx;
  174. }
  175. .infolook view {
  176. width: auto;
  177. height: 30px;
  178. line-height: 30px;
  179. padding: 0 5px;
  180. color: #999;
  181. }
  182. </style>