moment-item.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <script lang="ts" setup>
  2. import Card from '@/components/card.vue'
  3. import dayjs from 'dayjs'
  4. import { beforeNow } from '../utils/date-util'
  5. import Tag from './tag.vue'
  6. import { stringify } from 'qs'
  7. import { isImageOrVideo } from '../core/utils/common'
  8. import { useRouter } from '../core/utils/router'
  9. import { likeActived, likeBlack } from '@designer-hub/assets/src/icons'
  10. import { NetImages } from '../core/libs/net-images'
  11. import { currRoute } from '../utils'
  12. import { usePermissions } from '../composables/permissions'
  13. import { levelsByLevel } from '@/core/libs/levels'
  14. const props = withDefaults(
  15. defineProps<{
  16. options: {
  17. id: number
  18. headUrl?: string
  19. stylistId?: number
  20. stylistName?: string
  21. marketing?: string
  22. circleDesc?: string
  23. tagName?: string
  24. detailsType?: string
  25. detailsUrl?: string
  26. detailsDesc?: string
  27. circleType?: string
  28. spaceType?: string
  29. designStyle?: string
  30. spaceAddr?: string
  31. customerDemand?: string
  32. createTime: number
  33. bannerUrls: string[]
  34. shareCount?: number
  35. upvoteCount?: number
  36. ownUpvote: boolean
  37. reviewCount: number
  38. }
  39. isOwn?: boolean
  40. }>(),
  41. {},
  42. )
  43. const emits = defineEmits<{ delete: [id: number]; like: [options: any] }>()
  44. const router = useRouter()
  45. const { features } = usePermissions()
  46. const imgClass = ref('')
  47. const isVideo = ref(false)
  48. const toDetail = () => {
  49. uni.navigateTo({
  50. url: `/pages/home/moment/index?${stringify({ id: props.options.id })}`,
  51. })
  52. }
  53. const handleDelete = async () => {
  54. emits('delete', props.options.id)
  55. }
  56. onMounted(async () => {
  57. if (
  58. props.options.bannerUrls?.length === 1 &&
  59. isImageOrVideo(props.options.bannerUrls[0]) === 'image'
  60. ) {
  61. const { width, height } = await uni.getImageInfo({
  62. src: props.options.bannerUrls[0],
  63. })
  64. if (Number(width / height) > 1) {
  65. imgClass.value = 'w-[60vw]'
  66. } else {
  67. imgClass.value = 'w-[44vw]'
  68. }
  69. }
  70. if (
  71. props.options.bannerUrls?.length === 1 &&
  72. isImageOrVideo(props.options.bannerUrls[0]) === 'video'
  73. ) {
  74. isVideo.value = true
  75. }
  76. })
  77. </script>
  78. <template>
  79. <div @click="toDetail">
  80. <Card>
  81. <view class="flex items-center">
  82. <view
  83. class="overflow-hidden rounded-full mr-2"
  84. @click.stop="
  85. features.toDesignerHomePage &&
  86. currRoute().path !== '/pages/mine/homepage/index' &&
  87. router.push(`/pages/mine/homepage/index?id=${options.stylistId}`)
  88. "
  89. >
  90. <wd-img
  91. custom-class="vertical-bottom"
  92. :width="35"
  93. :height="35"
  94. :src="props.options.headUrl || NetImages.DefaultAvatar"
  95. mode="scaleToFill"
  96. />
  97. </view>
  98. <view class="">{{ props.options.stylistName }}</view>
  99. <div v-if="levelsByLevel[options?.member?.level]?.badge">
  100. <wd-img
  101. width="63"
  102. height="18.6"
  103. :src="levelsByLevel[options?.member?.level]?.badge"
  104. ></wd-img>
  105. </div>
  106. <view class="flex-1"></view>
  107. <view>{{ beforeNow(dayjs(props.options.createTime).toDate()) }}</view>
  108. </view>
  109. <div v-if="isVideo" class="aspect-[1.64/1] rounded-lg overflow-hidden my-6" @click.stop>
  110. <video class="w-full h-full" :src="options.bannerUrls[0]"></video>
  111. </div>
  112. <view
  113. v-if="!isVideo"
  114. :class="[
  115. props.options.bannerUrls?.length > 1 ? 'grid grid-cols-3 grid-gap-1' : 'w-full',
  116. 'my-6',
  117. ]"
  118. >
  119. <template v-for="it of props.options.bannerUrls" :key="it">
  120. <view
  121. :class="[
  122. props.options.bannerUrls?.length > 1 ? 'aspect-square' : '',
  123. 'rounded-lg overflow-hidden',
  124. imgClass,
  125. ]"
  126. >
  127. <wd-img
  128. custom-class="vertical-bottom"
  129. :width="'100%'"
  130. :src="it"
  131. :height="props.options.bannerUrls?.length > 1 ? '100%' : 'auto'"
  132. :mode="props.options.bannerUrls?.length > 1 ? 'aspectFill' : 'widthFix'"
  133. ></wd-img>
  134. </view>
  135. </template>
  136. </view>
  137. <view class="text-[rgba(0,0,0,0.85)] text-4 font-400 my-1">
  138. {{ props.options.circleDesc }}
  139. </view>
  140. <view class="my-5.5 flex flex-wrap gap-3.5">
  141. <template v-if="props.options.tagName !== ''">
  142. <template v-for="it of props.options.tagName?.split(',')" :key="it">
  143. <Tag>{{ it }}</Tag>
  144. </template>
  145. </template>
  146. </view>
  147. <view class="flex justify-between">
  148. <div>
  149. <button
  150. open-type="share"
  151. class="bg-transparent! p-0!"
  152. :data-options="options"
  153. @click.stop
  154. >
  155. <view
  156. class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  157. >
  158. <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>
  159. <view class="ml-1">{{ props.options.shareCount }}</view>
  160. </view>
  161. </button>
  162. </div>
  163. <view class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5">
  164. <wd-img width="15" height="15" src="/static/svgs/comment.svg"></wd-img>
  165. <view class="ml-1">{{ props.options.reviewCount }}</view>
  166. </view>
  167. <view
  168. class="flex items-center text-3.5 font-400 line-height-5.5"
  169. :class="[options.ownUpvote ? 'text-[#ca5141]' : 'text-[rgba(0,0,0,0.85)]']"
  170. @click.stop="emits('like', { upvote: options.ownUpvote, circleId: options.id })"
  171. >
  172. <template v-if="options.ownUpvote">
  173. <wd-img width="18" height="18" :src="likeActived"></wd-img>
  174. </template>
  175. <template v-else>
  176. <wd-img width="18" height="18" :src="likeBlack"></wd-img>
  177. </template>
  178. <view class="ml-1">{{ props.options.upvoteCount }}</view>
  179. </view>
  180. <div v-if="isOwn" @click.stop="handleDelete()">
  181. <wd-button type="text" size="small">
  182. <span class="text-black/30 text-xs font-normal font-['PingFang_SC']">
  183. 删除
  184. <wd-icon name="close" size="12"></wd-icon>
  185. </span>
  186. </wd-button>
  187. </div>
  188. </view>
  189. </Card>
  190. </div>
  191. </template>