moment-item.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <script lang="ts" setup>
  2. import Card from '@/components/card.vue'
  3. import dayjs from 'dayjs'
  4. import TiltedButton from './tilted-button.vue'
  5. import { beforeNow } from '@/utils/date-util'
  6. import Tag from './tag.vue'
  7. const props = defineProps({
  8. options: {
  9. type: Object as PropType<{
  10. id: number
  11. headUrl?: string
  12. stylistId?: number
  13. stylistName?: string
  14. marketing?: string
  15. circleDesc?: string
  16. tagName?: string
  17. detailsType?: string
  18. detailsUrl?: string
  19. detailsDesc?: string
  20. circleType?: string
  21. spaceType?: string
  22. designStyle?: string
  23. spaceAddr?: string
  24. customerDemand?: string
  25. createTime: number
  26. bannerUrls: string[]
  27. shareCount?: number
  28. upvoteCount?: number
  29. ownUpvote: boolean
  30. reviewCount: number
  31. }>,
  32. default: () => ({
  33. author: {
  34. nickname: '张三',
  35. avatar: 'https://img.yzcdn.cn/vant/cat.jpeg',
  36. },
  37. createTime: new Date(),
  38. images: [
  39. 'https://via.placeholder.com/104x104',
  40. 'https://via.placeholder.com/104x104',
  41. 'https://via.placeholder.com/104x104',
  42. ],
  43. content: '',
  44. tags: [],
  45. shares: 0,
  46. comments: 0,
  47. likes: 0,
  48. }),
  49. },
  50. })
  51. const imgClass = ref('')
  52. const toDetail = () => {
  53. uni.navigateTo({
  54. url: '/pages/home/moment/index',
  55. })
  56. }
  57. onMounted(async () => {
  58. // console.log('加载')
  59. if (props.options.bannerUrls.length === 1) {
  60. const { width, height } = await uni.getImageInfo({
  61. src: props.options.bannerUrls[0],
  62. })
  63. if (Number(width / height) > 1) {
  64. imgClass.value = 'w-[60vw]'
  65. } else {
  66. imgClass.value = 'w-[44vw]'
  67. }
  68. }
  69. })
  70. </script>
  71. <template>
  72. <Card @click="toDetail" @tap="toDetail">
  73. <view class="flex items-center">
  74. <view class="overflow-hidden rounded-full mr-2">
  75. <wd-img
  76. custom-class="vertical-bottom"
  77. :width="35"
  78. :height="35"
  79. :src="props.options.headUrl"
  80. mode="scaleToFill"
  81. />
  82. </view>
  83. <view class="">{{ props.options.stylistName }}</view>
  84. <view class="flex-1"></view>
  85. <view>{{ beforeNow(dayjs(props.options.createTime).toDate()) }}</view>
  86. </view>
  87. <view
  88. :class="[
  89. props.options.bannerUrls.length > 1 ? 'grid grid-cols-3 grid-gap-1' : 'w-full',
  90. 'my-6',
  91. ]"
  92. >
  93. <template v-for="it of props.options.bannerUrls" :key="it">
  94. <view
  95. :class="[
  96. props.options.bannerUrls.length > 1 ? 'aspect-square' : '',
  97. 'rounded-lg overflow-hidden',
  98. imgClass,
  99. ]"
  100. >
  101. <wd-img
  102. custom-class="vertical-bottom"
  103. :width="'100%'"
  104. :src="it"
  105. :height="props.options.bannerUrls.length > 1 ? '100%' : 'auto'"
  106. :mode="props.options.bannerUrls.length > 1 ? 'aspectFill' : 'widthFix'"
  107. ></wd-img>
  108. </view>
  109. </template>
  110. </view>
  111. <view class="text-[rgba(0,0,0,0.85)] text-4 font-400 line-height-2.5 my-1">
  112. {{ props.options.circleDesc }}
  113. </view>
  114. <view class="my-5.5">
  115. <!-- <TiltedButton>按钮</TiltedButton> -->
  116. <template v-for="it of props.options.tagName?.split(',')" :key="it">
  117. <Tag>{{ it }}</Tag>
  118. </template>
  119. </view>
  120. <view class="flex justify-between">
  121. <view class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5">
  122. <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>
  123. <view class="ml-1">{{ props.options.shareCount }}</view>
  124. </view>
  125. <view class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5">
  126. <wd-img width="15" height="15" src="/static/svgs/comment.svg"></wd-img>
  127. <view class="ml-1">{{ props.options.shareCount }}</view>
  128. </view>
  129. <view class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5">
  130. <wd-img width="15" height="15" src="/static/svgs/like.svg"></wd-img>
  131. <view class="ml-1">{{ props.options.shareCount }}</view>
  132. </view>
  133. </view>
  134. </Card>
  135. </template>