moment-item.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 { useMemberLevelsStore } from '../store/member-levles'
  14. import { useDictStore } from '../store'
  15. import { DictType } from '../core/libs/models'
  16. import { CircleRes } from '../core/libs/requests'
  17. const props = withDefaults(
  18. defineProps<{
  19. options: CircleRes
  20. isOwn?: boolean
  21. isShared?: boolean
  22. dict?: Object
  23. }>(),
  24. {},
  25. )
  26. const emits = defineEmits<{
  27. delete: [id: number]
  28. like: [options: any]
  29. share: [options: CircleRes]
  30. }>()
  31. const router = useRouter()
  32. const { features, clickByPermission } = usePermissions()
  33. const memberLevelsStore = useMemberLevelsStore()
  34. const { getMemberLevelLogo, getMemberAvatarFrame } = memberLevelsStore
  35. // const dictStore = useDictStore()
  36. // const { getOptionLabel } = dictStore
  37. const imgClass = ref('')
  38. // const isVideo = ref(false)
  39. const isVideo = computed(
  40. () => props.options.bannerUrls?.length && isImageOrVideo(props.options.bannerUrls[0]) === 'video',
  41. )
  42. const toDetail = () => {
  43. uni.navigateTo({
  44. url: `/pages-sub/home/moment/index?${stringify({ id: props.options.id })}${props.isShared ? '&isShared=true' : ''}`,
  45. })
  46. }
  47. const handleDelete = async () => {
  48. emits('delete', props.options.id)
  49. }
  50. const dictLabelChange = (dictArr: any, value: any) => {
  51. for (let i in dictArr) {
  52. if (dictArr[i].value === value) {
  53. return dictArr[i].label
  54. }
  55. }
  56. }
  57. onMounted(async () => {
  58. if (
  59. props.options.circleType === '1' &&
  60. props.options.bannerUrls?.length === 1 &&
  61. isImageOrVideo(props.options.bannerUrls[0]) === 'image'
  62. ) {
  63. const { width, height } = await uni.getImageInfo({
  64. src: props.options.bannerUrls[0],
  65. })
  66. if (Number(width / height) > 1) {
  67. imgClass.value = 'w-[60vw]'
  68. } else {
  69. imgClass.value = 'w-[44vw]'
  70. }
  71. }
  72. // if (
  73. // props.options.bannerUrls?.length === 1 &&
  74. // isImageOrVideo(props.options.bannerUrls[0]) === 'video'
  75. // ) {
  76. // isVideo.value = true
  77. // }
  78. })
  79. </script>
  80. <template>
  81. <div @click="toDetail">
  82. <Card>
  83. <view class="flex items-center gap-2">
  84. <view
  85. class="relative"
  86. @click.stop="
  87. options?.levelId >= 2 &&
  88. ['1', '2'].includes(options?.circleType) &&
  89. currRoute().path !== '/pages-sub/mine/homepage/index' &&
  90. router.push(`/pages-sub/mine/homepage/index?id=${options.stylistId}`)
  91. "
  92. >
  93. <wd-img
  94. custom-class="vertical-bottom"
  95. :width="35"
  96. :height="35"
  97. round
  98. :src="props.options.headUrl || NetImages.DefaultAvatar"
  99. mode="scaleToFill"
  100. />
  101. <wd-img
  102. v-if="getMemberAvatarFrame(options?.levelId)"
  103. custom-class="absolute! level-circle"
  104. :width="37"
  105. :height="40"
  106. :src="getMemberAvatarFrame(options?.levelId) || ''"
  107. ></wd-img>
  108. </view>
  109. <view class="">{{ props.options.stylistName || props.options.marketing }}</view>
  110. <template v-if="getMemberLevelLogo(options?.levelId)">
  111. <wd-img
  112. width="63"
  113. height="18.6"
  114. :src="getMemberLevelLogo(options?.levelId) || ''"
  115. ></wd-img>
  116. </template>
  117. <view class="flex-1"></view>
  118. <div class="text-black/40 text-sm font-medium font-['PingFang_SC'] leading-[10.18px]">
  119. {{ beforeNow(dayjs(props.options.createTime).toDate()) }}
  120. </div>
  121. </view>
  122. <div v-if="isVideo" class="aspect-[1.64/1] rounded-lg overflow-hidden my-6" @click.stop>
  123. <video class="w-full h-full" :src="options.bannerUrls[0]"></video>
  124. </div>
  125. <view v-if="!isVideo" class="my-6">
  126. <template v-if="options.circleType === '1'">
  127. <div
  128. :class="[
  129. props.options.bannerUrls?.length > 1 ? 'grid grid-cols-3 grid-gap-1' : 'w-full',
  130. '',
  131. ]"
  132. >
  133. <template v-for="it of props.options.bannerUrls" :key="it">
  134. <view
  135. :class="[
  136. props.options.bannerUrls?.length > 1 ? 'aspect-square' : '',
  137. 'rounded-lg overflow-hidden',
  138. imgClass,
  139. ]"
  140. >
  141. <wd-img
  142. custom-class="vertical-bottom"
  143. :width="'100%'"
  144. :src="it"
  145. :height="props.options.bannerUrls?.length > 1 ? '100%' : 'auto'"
  146. :mode="props.options.bannerUrls?.length > 1 ? 'aspectFill' : 'widthFix'"
  147. ></wd-img>
  148. </view>
  149. </template>
  150. </div>
  151. </template>
  152. <view class="aspect-[1.64/1] rounded-lg overflow-hidden" v-else>
  153. <wd-img
  154. custom-class="vertical-bottom"
  155. width="100%"
  156. height="100%"
  157. :src="options.bannerUrls[0]"
  158. mode="aspectFill"
  159. ></wd-img>
  160. </view>
  161. </view>
  162. <div
  163. v-if="options.circleType === '2'"
  164. class="text-black/90 text-xl font-normal font-['PingFang_SC']"
  165. >
  166. 设计案例:{{ options?.caseName }}
  167. </div>
  168. <view class="text-[rgba(0,0,0,0.85)] text-4 font-400 my-1 flex items-center">
  169. <template v-if="options.circleType === '2'">
  170. <div class="w-full mt-4 flex items-center justify-between text-black/40 text-sm">
  171. <!-- <div class="font-normal font-['PingFang_SC']">
  172. 类别:{{ getOptionLabel(DictType.circleSpaceType, options?.spaceType) }}
  173. </div>
  174. |
  175. <div class="text-black/40 text-sm font-normal font-['PingFang_SC']">
  176. 风格:{{ getOptionLabel(DictType.memberDesignStyle, options.designStyle) }}
  177. </div> -->
  178. <div class="font-normal font-['PingFang_SC']">
  179. 类别:{{ dictLabelChange(dict?.spaceType, options?.spaceType) }}
  180. </div>
  181. |
  182. <div class="text-black/40 text-sm font-normal font-['PingFang_SC']">
  183. 风格:{{ dictLabelChange(dict?.designStyle, options.designStyle) }}
  184. </div>
  185. |
  186. <div class="text-black/40 text-sm font-normal font-['PingFang_SC']">
  187. 面积:{{ options.spaceExtent }}
  188. </div>
  189. </div>
  190. </template>
  191. <template v-else>{{ options.circleDesc }}</template>
  192. </view>
  193. <view v-if="props.options.tagName !== ''" class="my-5.5 flex flex-wrap gap-3.5">
  194. <template v-if="props.options.tagName !== ''">
  195. <template v-for="it of props.options.tagName?.split(',')" :key="it">
  196. <Tag>{{ it }}</Tag>
  197. </template>
  198. </template>
  199. </view>
  200. <view v-if="!isShared" class="flex justify-between">
  201. <div>
  202. <template v-if="features.shareMoment">
  203. <button
  204. open-type="share"
  205. class="bg-transparent! p-0!"
  206. :data-options="options"
  207. @click.stop
  208. >
  209. <view
  210. class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  211. >
  212. <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>
  213. <view class="ml-1">{{ props.options.shareCount }}</view>
  214. </view>
  215. </button>
  216. </template>
  217. <template v-else>
  218. <view
  219. @click.stop="clickByPermission('share', () => {})"
  220. class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  221. >
  222. <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>
  223. <view class="ml-1">{{ props.options.shareCount }}</view>
  224. </view>
  225. </template>
  226. </div>
  227. <view class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5">
  228. <wd-img width="15" height="15" src="/static/svgs/comment.svg"></wd-img>
  229. <view class="ml-1">{{ props.options.reviewCount }}</view>
  230. </view>
  231. <view
  232. class="flex items-center text-3.5 font-400 line-height-5.5"
  233. :class="[options.ownUpvote ? 'text-[#ca5141]' : 'text-[rgba(0,0,0,0.85)]']"
  234. @click.stop="
  235. clickByPermission('thumbsUp', () =>
  236. emits('like', { upvote: options.ownUpvote, circleId: options.id }),
  237. )
  238. "
  239. >
  240. <template v-if="options.ownUpvote">
  241. <wd-img width="18" height="18" :src="likeActived"></wd-img>
  242. </template>
  243. <template v-else>
  244. <wd-img width="18" height="18" :src="likeBlack"></wd-img>
  245. </template>
  246. <view class="ml-1">{{ props.options.upvoteCount }}</view>
  247. </view>
  248. <div v-if="isOwn" @click.stop="handleDelete()">
  249. <wd-button type="text" size="small">
  250. <span class="text-black/30 text-xs font-normal font-['PingFang_SC']">
  251. 删除
  252. <wd-icon name="close" size="12"></wd-icon>
  253. </span>
  254. </wd-button>
  255. </div>
  256. </view>
  257. </Card>
  258. </div>
  259. </template>