list-item.nvue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="list-item">
  3. <view class="header">
  4. <view class="header-left">
  5. <view class="header-img-wrapper">
  6. <image class="header-img" :src="item.avatar" mode="aspectFit"></image>
  7. </view>
  8. <view class="header-name-identity">
  9. <text class="header-name">{{ item.author }}</text>
  10. <text class="header-identity" v-if="item.off == 1">官方</text>
  11. </view>
  12. </view>
  13. <text class="header-right">{{ item.created_at | DistanceNow }}</text>
  14. </view>
  15. <view v-if="item.type == 0" class="item-body-article" @tap="toDetail">
  16. <text class="article-title">{{ item.title }}</text>
  17. <text class="article-des">{{ item.summary }}...</text>
  18. <view class="img-list">
  19. <view class="img-list-item" v-for="item in item.imgurl" :key="item">
  20. <image class="img-list-item-img" :src="item"></image>
  21. </view>
  22. </view>
  23. </view>
  24. <view v-else-if="item.type == 1" class="item-body-video" @tap="toDetail">
  25. <text class="article-title">{{ item.title }}</text>
  26. <text class="article-des">{{ item.summary }}...</text>
  27. <view class="video-poster">
  28. <image class="video-poster-img" :src="item.imgurl[0]" mode="center"></image>
  29. <image class="video-poster-play" src="../../../static/icon/Video.png"></image>
  30. </view>
  31. </view>
  32. <view class="footer">
  33. <view class="footer-item footer-left" @tap="like()">
  34. <image v-if="item.like" class="footer-item-img" src="../../../static/icon/like-fill.png"></image>
  35. <image v-else class="footer-item-img" src="../../../static/icon/like.png"></image>
  36. <text class="footer-item-text">点赞</text>
  37. </view>
  38. <view class="footer-item footer-center" @tap="collection()">
  39. <image v-if="item.collection" class="footer-item-img" src="../../../static/icon/heart-fill.png"></image>
  40. <image v-else class="footer-item-img" src="../../../static/icon/heart.png"></image>
  41. <text class="footer-item-text">收藏</text>
  42. </view>
  43. <view class="footer-item footer-right" @tap="share">
  44. <image class="footer-item-img" src="../../../static/icon/share.png"></image>
  45. <text class="footer-item-text">分享</text>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import _share from '@/common/util/share.js'
  52. import { ArticleURL } from '@/common/util/request.js'
  53. export default {
  54. props: {
  55. typeIndex: Number,
  56. listIndex: Number
  57. },
  58. filters: {
  59. DistanceNow(t) {
  60. const d = +new Date - Number(t)
  61. if (d >= 0 && d < 10800000) {
  62. return '刚刚发表'
  63. } else if (d >= 10800000 && d < 86400000) {
  64. return `${Math.floor(d / 3600000)}小时前`
  65. } else if (d >= 86400000) {
  66. return `${Math.floor(d / 86400000)}天前`
  67. }
  68. }
  69. },
  70. computed: {
  71. item() {
  72. return this.$store.state.article.lists[this.typeIndex][this.listIndex]
  73. }
  74. },
  75. methods: {
  76. toDetail() {
  77. uni.navigateTo({ url: '/pages/article-detail/article-detail?type=' + this.typeIndex + '&index=' + this.listIndex })
  78. },
  79. like() { // 点赞
  80. this.$store.commit('article/LIKE', { listsIndex: this.typeIndex, commuIndex: this.listIndex })
  81. },
  82. collection() { // 收藏
  83. this.$store.commit('article/COLLECTION', { listsIndex: this.typeIndex, commuIndex: this.listIndex })
  84. },
  85. share() { // 分享
  86. _share({
  87. type: 0,
  88. title: this.item.title,
  89. summary: this.item.summary,
  90. imageUrl: this.item.imgurl[0],
  91. href: ArticleURL + '?id=' + this.item.id
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. .list-item { }
  99. .header { height: 130rpx; flex-direction: row; justify-content: space-between; align-items: center; }
  100. .header-left { height: 80rpx; flex: 1; flex-direction: row; align-items: center; }
  101. .header-right { font-size: 24rpx; color: #999999; }
  102. .header-img-wrapper { width: 80rpx; height: 80rpx; border-radius: 80rpx; }
  103. .header-img { width: 80rpx; height: 80rpx; }
  104. .header-name-identity { margin-left: 18rpx; flex-direction: row; align-items: center; }
  105. .header-name { font-size: 28rpx; color: #505050; }
  106. .header-identity { width: 56rpx; height: 28rpx; background-color: #F76454; font-size: 20rpx; color: #FFFFFF; margin-left: 20rpx; text-align: center; line-height: 28rpx; border-radius: 4rpx; }
  107. .footer { height: 90rpx; flex-direction: row; align-items: center; border-top-color: #F2F2F2; border-top-width: 1px; margin-top: 20rpx; }
  108. .footer-item { height: 40rpx; flex: 1; flex-direction: row; align-items: center; justify-content: center; }
  109. .footer-item-img { width: 38rpx; height: 38rpx; }
  110. .footer-item-text { font-size: 24rpx; color: #666666; margin-left: 10rpx; }
  111. .footer-left { border-right-color: #F2F2F2; border-right-width: 1px; }
  112. .footer-right { border-left-color: #F2F2F2; border-left-width: 1px; }
  113. .video-poster { height: 280rpx; margin-top: 20rpx; border-radius: 20rpx; position: relative; }
  114. .video-poster-play { position: absolute; width: 68rpx; height: 68rpx; left: 311rpx; top: 106rpx; }
  115. .video-poster-img { width: 690rpx; height: 280rpx; }
  116. .article-title { font-size: 32rpx; }
  117. .article-des { font-size: 26rpx; color: #666666; margin-top: 10rpx; margin-bottom: 10rpx; }
  118. .img-list { flex-direction: row; height: 150rpx; justify-content: flex-start; }
  119. .img-list-item { height: 150rpx; width: 222rpx; border-radius: 10rpx; margin-right: 12rpx; }
  120. .img-list-item-img { height: 150rpx; width: 222rpx; }
  121. </style>