index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view>
  3. <view class="comment" v-for="(res, index) in commentList" :key="res.id">
  4. <view class="left"><image :src="res.url" mode="aspectFill"></image></view>
  5. <view class="right">
  6. <view class="top">
  7. <view class="name">{{ res.name }}</view>
  8. <view class="like" :class="{ highlight: res.isLike }">
  9. <view class="num">{{ res.likeNum }}</view>
  10. <u-icon v-if="!res.isLike" name="thumb-up" :size="30" color="#9a9a9a" @click="getLike(index)"></u-icon>
  11. <u-icon v-if="res.isLike" name="thumb-up-fill" :size="30" @click="getLike(index)"></u-icon>
  12. </view>
  13. </view>
  14. <view class="content">{{ res.contentText }}</view>
  15. <view class="reply-box">
  16. <view class="item" v-for="(item, index) in res.replyList" :key="item.index">
  17. <view class="username">{{ item.name }}</view>
  18. <view class="text">{{ item.contentStr }}</view>
  19. </view>
  20. <view class="all-reply" @tap="toAllReply" v-if="res.replyList != undefined">
  21. 共{{ res.allReply }}条回复
  22. <u-icon class="more" name="arrow-right" :size="26"></u-icon>
  23. </view>
  24. </view>
  25. <view class="bottom">
  26. {{ res.date }}
  27. <view class="reply">回复</view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. commentList: []
  38. };
  39. },
  40. onLoad() {
  41. this.getComment();
  42. },
  43. methods: {
  44. // 跳转到全部回复
  45. toAllReply() {
  46. uni.navigateTo({
  47. url: '/pages_template/pages/comment/reply'
  48. });
  49. },
  50. // 点赞
  51. getLike(index) {
  52. this.commentList[index].isLike = !this.commentList[index].isLike;
  53. if (this.commentList[index].isLike == true) {
  54. this.commentList[index].likeNum++;
  55. } else {
  56. this.commentList[index].likeNum--;
  57. }
  58. },
  59. // 评论列表
  60. getComment() {
  61. this.commentList = [
  62. {
  63. id: 1,
  64. name: '叶轻眉',
  65. date: '12-25 18:58',
  66. contentText: '我不信伊朗会没有后续反应,美国肯定会为今天的事情付出代价的',
  67. url: 'https://cdn.uviewui.com/uview/template/SmilingDog.jpg',
  68. allReply: 12,
  69. likeNum: 33,
  70. isLike: false,
  71. replyList: [
  72. {
  73. name: 'uview',
  74. contentStr: 'uview是基于uniapp的一个UI框架,代码优美简洁,宇宙超级无敌彩虹旋转好用,用它!'
  75. },
  76. {
  77. name: '粘粘',
  78. contentStr: '今天吃什么,明天吃什么,晚上吃什么,我只是一只小猫咪为什么要烦恼这么多'
  79. }
  80. ]
  81. },
  82. {
  83. id: 2,
  84. name: '叶轻眉1',
  85. date: '01-25 13:58',
  86. contentText: '我不信伊朗会没有后续反应,美国肯定会为今天的事情付出代价的',
  87. allReply: 0,
  88. likeNum: 11,
  89. isLike: false,
  90. url: 'https://cdn.uviewui.com/uview/template/niannian.jpg',
  91. },
  92. {
  93. id: 3,
  94. name: '叶轻眉2',
  95. date: '03-25 13:58',
  96. contentText: '我不信伊朗会没有后续反应,美国肯定会为今天的事情付出代价的',
  97. allReply: 0,
  98. likeNum: 21,
  99. isLike: false,
  100. allReply: 2,
  101. url: '../../../static/logo.png',
  102. replyList: [
  103. {
  104. name: 'uview',
  105. contentStr: 'uview是基于uniapp的一个UI框架,代码优美简洁,宇宙超级无敌彩虹旋转好用,用它!'
  106. },
  107. {
  108. name: '豆包',
  109. contentStr: '想吃冰糖葫芦粘豆包,但没钱5555.........'
  110. }
  111. ]
  112. },
  113. {
  114. id: 4,
  115. name: '叶轻眉3',
  116. date: '06-20 13:58',
  117. contentText: '我不信伊朗会没有后续反应,美国肯定会为今天的事情付出代价的',
  118. url: 'https://cdn.uviewui.com/uview/template/SmilingDog.jpg',
  119. allReply: 0,
  120. likeNum: 150,
  121. isLike: false
  122. }
  123. ];
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. .comment {
  130. display: flex;
  131. padding: 30rpx;
  132. .left {
  133. image {
  134. width: 64rpx;
  135. height: 64rpx;
  136. border-radius: 50%;
  137. background-color: #f2f2f2;
  138. }
  139. }
  140. .right {
  141. flex: 1;
  142. padding-left: 20rpx;
  143. font-size: 30rpx;
  144. .top {
  145. display: flex;
  146. justify-content: space-between;
  147. align-items: center;
  148. margin-bottom: 10rpx;
  149. .name {
  150. color: #5677fc;
  151. }
  152. .like {
  153. display: flex;
  154. align-items: center;
  155. color: #9a9a9a;
  156. font-size: 26rpx;
  157. .num {
  158. margin-right: 4rpx;
  159. color: #9a9a9a;
  160. }
  161. }
  162. .highlight {
  163. color: #5677fc;
  164. .num {
  165. color: #5677fc;
  166. }
  167. }
  168. }
  169. .content {
  170. margin-bottom: 10rpx;
  171. }
  172. .reply-box {
  173. background-color: rgb(242, 242, 242);
  174. border-radius: 12rpx;
  175. .item {
  176. padding: 20rpx;
  177. border-bottom: solid 2rpx $u-border-color;
  178. .username {
  179. font-size: 24rpx;
  180. color: #999999;
  181. }
  182. }
  183. .all-reply {
  184. padding: 20rpx;
  185. display: flex;
  186. color: #5677fc;
  187. align-items: center;
  188. .more {
  189. margin-left: 6rpx;
  190. }
  191. }
  192. }
  193. .bottom {
  194. margin-top: 20rpx;
  195. display: flex;
  196. font-size: 24rpx;
  197. color: #9a9a9a;
  198. .reply {
  199. color: #5677fc;
  200. margin-left: 10rpx;
  201. }
  202. }
  203. }
  204. }
  205. </style>