index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <route lang="json">
  2. {
  3. "style": {
  4. "navigationBarTitleText": "详情",
  5. "navigationBarBackgroundColor": "#fff",
  6. "navigationStyle": "custom"
  7. }
  8. }
  9. </route>
  10. <script setup lang="ts">
  11. import Tag from '@/components/tag.vue'
  12. import {
  13. createCircleReview,
  14. getCircle,
  15. getCircleReviews,
  16. getCircleUpvotes,
  17. shareCircle,
  18. } from '../../../core/libs/requests'
  19. import { handleShareClick, handleUpvoteClick } from '../../../core/libs/actions'
  20. import CommentItem from '../components/comment-item.vue'
  21. import { useDictStore, useUserStore } from '../../../store'
  22. import { storeToRefs } from 'pinia'
  23. import { isImageOrVideo, requestToast } from '../../../core/utils/common'
  24. import dayjs from 'dayjs'
  25. import SectionHeading from '@/components/section-heading.vue'
  26. import BottomAppBar from '@/components/bottom-app-bar.vue'
  27. import { likeActived, likeBlack } from '@designer-hub/assets/src/icons'
  28. import NavBarEvo from '@/components/navbar-evo.vue'
  29. import { useRouter } from '../../../core/utils/router'
  30. import { usePermissions } from '../../../composables/permissions'
  31. import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html.vue'
  32. import WdInput from 'wot-design-uni/components/wd-input/wd-input.vue'
  33. import { getRect, addUnit } from 'wot-design-uni/components/common/util'
  34. import Card from '@/components/card.vue'
  35. import { get } from 'radash'
  36. import { DictType } from '../../../core/libs/models'
  37. import MomentVideo from '@/pages-sub/home/components/moment-video.vue'
  38. import { ComponentExposed } from 'vue-component-type-helpers'
  39. import { useShare } from '@/composables/share'
  40. const { features, clickByPermission } = usePermissions()
  41. const { shareAppMessage } = useShare()
  42. const userStore = useUserStore()
  43. const { userInfo } = storeToRefs(userStore)
  44. const router = useRouter()
  45. const dictStore = useDictStore()
  46. const { getOptionLabel } = dictStore
  47. const id = ref()
  48. const current = ref(0)
  49. const isShared = ref(false)
  50. const commentRef = ref<InstanceType<typeof WdInput>>()
  51. const commentItemRef = ref<InstanceType<typeof CommentItem>[]>()
  52. const instance = getCurrentInstance()
  53. const momentVideoRef = ref<ComponentExposed<typeof MomentVideo>[]>()
  54. const focus = ref(false)
  55. const hot = ref(true)
  56. const active = ref('hot');
  57. const { data, run } = useRequest(() => getCircle(id.value), { initialData: {} })
  58. const { data: reviews, run: runGetReviews } = useRequest(
  59. () => getCircleReviews({ circleId: id.value,hot:hot.value}),
  60. {
  61. initialData: {
  62. list: [],
  63. },
  64. },
  65. )
  66. const { data: circleUpvotes, run: setCircleUpvotes } = useRequest(
  67. () => getCircleUpvotes(id.value),
  68. { initialData: { list: [], total: 0 } },
  69. )
  70. const swiperStyle = ref()
  71. const reviewContent = ref('')
  72. const reviewId = ref()
  73. const refreshIndex = ref<number>()
  74. const isVideo = computed(
  75. () => data.value?.bannerUrls?.length && isImageOrVideo(data.value.bannerUrls.at(0)) === 'video',
  76. )
  77. const handleChange = ({ detail }) => {
  78. console.log('current', current.value, detail.current)
  79. console.log(momentVideoRef.value)
  80. if (isVideo.value) {
  81. momentVideoRef.value[current.value]?.videoContext.pause()
  82. }
  83. current.value = detail.current
  84. }
  85. const setSwiperStyle = async () => {
  86. if (!data.value.bannerUrls.length) return
  87. const { screenWidth } = await uni.getSystemInfo()
  88. if (isImageOrVideo(data.value.bannerUrls[0]) === 'video') {
  89. return
  90. }
  91. const { width, height } = await uni.getImageInfo({ src: data.value.bannerUrls.at(0) })
  92. console.log(screenWidth / width)
  93. swiperStyle.value = {
  94. height:
  95. height > width
  96. ? addUnit(500)
  97. : height === width
  98. ? addUnit(screenWidth)
  99. : addUnit(
  100. screenWidth / width > 1
  101. ? height / (screenWidth / width)
  102. : height * (screenWidth / width),
  103. ),
  104. }
  105. console.log('swiperStyle', swiperStyle.value)
  106. }
  107. const handleSend = async () => {
  108. if (!reviewContent.value) {
  109. await uni.showToast({ title: '请输入评论内容', icon: 'none' })
  110. return
  111. }
  112. const { code, msg } = await createCircleReview({
  113. circleId: id.value,
  114. userId: userInfo.value.userId,
  115. userName: userInfo.value.nickname,
  116. reviewContent: reviewContent.value,
  117. replayReviewId: reviewId.value,
  118. })
  119. if (code !== 0) {
  120. await uni.showToast({ title: msg, icon: 'none' })
  121. } else {
  122. reviewContent.value = ''
  123. console.log('refreshIndex', refreshIndex.value)
  124. await uni.showToast({ title: '评论成功', icon: 'none' })
  125. if (refreshIndex.value !== undefined) {
  126. console.log(instance.refs)
  127. await commentItemRef.value.at(refreshIndex.value).refresh()
  128. reviewId.value = undefined
  129. refreshIndex.value = undefined
  130. } else {
  131. await runGetReviews()
  132. }
  133. focus.value = false
  134. }
  135. }
  136. const handleReplay = async (options) => {
  137. reviewId.value = options.reviewId
  138. refreshIndex.value = options.index
  139. focus.value = true
  140. }
  141. const handleDelete = async (index?: number) => {
  142. if (index !== undefined) {
  143. await commentItemRef.value.at(index).refresh()
  144. } else {
  145. await runGetReviews()
  146. }
  147. }
  148. const handleUpvote = async (index?: number) => {
  149. if (index !== undefined) {
  150. await commentItemRef.value.at(index).refresh()
  151. }
  152. await runGetReviews()
  153. }
  154. const toDesignerHomepage = () => {
  155. if (['1', '2'].includes(String(data.value?.circleType))) {
  156. router.push(
  157. `/pages-sub/mine/homepage/index?id=${data.value?.stylistId}${isShared.value ? '&isShared=true' : ''}`,
  158. )
  159. }
  160. }
  161. onMounted(async () => {})
  162. onLoad(async (query?: { id: string; isShared?: boolean }) => {
  163. id.value = query?.id
  164. isShared.value = query?.isShared
  165. await run()
  166. await setSwiperStyle()
  167. await runGetReviews()
  168. await setCircleUpvotes()
  169. })
  170. // onShareAppMessage(async () => {
  171. // await shareCircle(id.value)
  172. // return { title: data.value?.circleDesc }
  173. // })
  174. onShareAppMessage(shareAppMessage)
  175. const handleClick = async (value:boolean) => {
  176. active.value = value ? 'hot' : 'time';
  177. hot.value = value
  178. await runGetReviews()
  179. };
  180. </script>
  181. <template>
  182. <view class="bg-white flex-grow">
  183. <NavBarEvo placeholder :isShowBack="!isShared">
  184. <template #prepend>
  185. <div class="flex items-center gap-2" @click="toDesignerHomepage">
  186. <wd-img width="24" height="24" round :src="data.headUrl"></wd-img>
  187. <div class="text-black/90 text-sm font-normal font-['PingFang_SC'] leading-[10.18px]">
  188. {{ data.stylistName || data.marketing }}
  189. </div>
  190. </div>
  191. </template>
  192. </NavBarEvo>
  193. <!-- <div class="my-4 text-black/90 text-lg font-normal font-['PingFang_SC'] leading-[10.18px]">
  194. {{ data?.detailsDesc }}
  195. </div> -->
  196. <template v-if="data.circleType === '1'">
  197. <template v-if="!isVideo">
  198. <div class="pos-relative">
  199. <div class="currentImg">{{ current + 1 }}/{{ data?.bannerUrls.length }}</div>
  200. <swiper
  201. :current="current"
  202. :style="swiperStyle"
  203. @change="handleChange"
  204. :indicator-dots="true"
  205. >
  206. <template v-for="it of data?.bannerUrls" :key="it">
  207. <swiper-item>
  208. <wd-img
  209. width="100%"
  210. height="100%"
  211. :src="it"
  212. mode="aspectFill"
  213. :enable-preview="true"
  214. ></wd-img>
  215. </swiper-item>
  216. </template>
  217. </swiper>
  218. </div>
  219. </template>
  220. <template v-if="isVideo">
  221. <div class="relative aspect-[1.64/1]">
  222. <div class="currentImg">{{ current + 1 }}/{{ data?.bannerUrls.length }}</div>
  223. <swiper @change="handleChange">
  224. <template v-for="it of data?.bannerUrls" :key="it">
  225. <swiper-item>
  226. <!-- <video-->
  227. <!-- ref="momentVideo"-->
  228. <!-- width="100%"-->
  229. <!-- class="w-full aspect-[1.64/1]"-->
  230. <!-- :controls="'contimg'"-->
  231. <!-- :loop="true"-->
  232. <!-- :enable-progress-gesture="false"-->
  233. <!-- :src="it"-->
  234. <!-- ></video>-->
  235. <MomentVideo
  236. ref="momentVideoRef"
  237. :src="it"
  238. :enable-progress-gesture="false"
  239. ></MomentVideo>
  240. </swiper-item>
  241. </template>
  242. </swiper>
  243. </div>
  244. </template>
  245. </template>
  246. <template v-if="data.circleType === '2'">
  247. <div>
  248. <div class="aspect-[1.02/1]">
  249. <wd-img width="100%" height="100%" mode="aspectFill" :src="data.bannerUrls[0]"></wd-img>
  250. </div>
  251. <div class="relative">
  252. <div
  253. class="absolute top-0 left-3.5 right-3.5 box-border h-full flex items-center justify-center"
  254. >
  255. <div class="w-full px-4 py-7 bg-white rounded-2xl shadow">
  256. <div class="text-black/90 text-xl font-normal font-['PingFang_SC']">
  257. 设计案例:{{ data?.caseName }}
  258. </div>
  259. <div class="mt-4 flex items-center justify-between text-black/40 text-sm">
  260. <div class="font-normal font-['PingFang_SC']">
  261. 类别:{{ getOptionLabel(DictType.circleSpaceType, data?.spaceType) }}
  262. </div>
  263. |
  264. <div class="text-black/40 text-sm font-normal font-['PingFang_SC']">
  265. 风格:{{ getOptionLabel(DictType.memberDesignStyle, data.designStyle) }}
  266. </div>
  267. |
  268. <div class="text-black/40 text-sm font-normal font-['PingFang_SC']">
  269. 面积:{{ data.spaceExtent }}
  270. </div>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. </template>
  277. <div v-if="data.circleType === '2'" class="mt-24 px-3.5">
  278. <SectionHeading custom-class="" title="案例描述"></SectionHeading>
  279. </div>
  280. <view v-if="data.circleType === '3'">
  281. <mpHtml :content="data.detailsDesc"></mpHtml>
  282. </view>
  283. <view class="m-3.5" :class="data.circleType === '2' ? 'mx-7' : ''">
  284. <div class="text-black/90 text-base font-normal font-['PingFang_SC']">
  285. {{ data?.circleDesc }}
  286. </div>
  287. <view class="my-5.5 flex gap-3.5 flex-wrap">
  288. <!-- <TiltedButton>按钮</TiltedButton> -->
  289. <template v-if="data?.tagName !== ''">
  290. <template v-for="it of data?.tagName?.split(',')" :key="it">
  291. <Tag>{{ it }}</Tag>
  292. </template>
  293. </template>
  294. </view>
  295. </view>
  296. <div v-if="data.circleType === '2'" class="mb-4">
  297. <SectionHeading custom-class="mx-3.5 my-7" title="效果图"></SectionHeading>
  298. <template v-for="(it, i) in data?.bannerUrls" :key="i">
  299. <wd-img width="100%" mode="widthFix" :src="it"></wd-img>
  300. </template>
  301. </div>
  302. <div class="mx-3.5">
  303. <div class="text-black/30 text-xs font-normal font-['PingFang_SC'] leading-[10.18px]">
  304. {{ dayjs(data.createTime).format('YYYY-MM-DD HH:mm') }}
  305. </div>
  306. <!-- <view class="flex items-center my-4">
  307. <view class="flex items-center">
  308. <avatar-group-casual
  309. :show-number="3"
  310. :urls="[
  311. 'https://via.placeholder.com/20x20',
  312. 'https://via.placeholder.com/20x20',
  313. 'https://via.placeholder.com/20x20',
  314. ]"
  315. ></avatar-group-casual>
  316. <div
  317. class="ml-1 text-black/60 text-sm font-normal font-['PingFang_SC'] leading-[10.18px]"
  318. >
  319. {{ circleUpvotes.total }}人赞过
  320. </div>
  321. </view>
  322. <view class="flex-1"></view>
  323. <view><wd-icon class="text-black/65" name="arrow-right" size="22px"></wd-icon></view>
  324. </view> -->
  325. <div v-if="!isShared" class="h-0.25 bg-[#dadada] my-7"></div>
  326. <SectionHeading v-if="!isShared" :title="`评论`" size="base">
  327. <template #append>
  328. <view v-if="reviews?.list" class="flex">
  329. <div @click="handleClick(true)" :class="{
  330. 'text-black/90': active === 'hot',
  331. 'text-black/40': active !== 'hot'
  332. }" class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-[10.18px]">
  333. 按热度
  334. </div>
  335. <div
  336. class="text-xs font-normal font-['PingFang_SC'] leading-[10.18px]"
  337. >
  338. |
  339. </div>
  340. <div @click="handleClick(false)" :class="{
  341. 'text-black/90': active === 'time',
  342. 'text-black/40': active !== 'time'
  343. }" class="text-xs font-normal font-['PingFang_SC'] leading-[10.18px]">
  344. 按时间
  345. </div>
  346. </view>
  347. </template>
  348. </SectionHeading>
  349. <view v-if="!isShared" clas="mt-8.25">
  350. <template v-if="reviews?.list.length">
  351. <template v-for="(it, i) in reviews?.list" :key="it.id">
  352. <CommentItem
  353. ref="commentItemRef"
  354. :options="it"
  355. :isChild="false"
  356. :index="i"
  357. @upvote="handleUpvote"
  358. @delete="handleDelete"
  359. @replay="handleReplay"
  360. ></CommentItem>
  361. <!-- <template v-for="child of it.childrens" :key="child.id">
  362. <CommentItem :options="child" :isChild="true"></CommentItem>
  363. </template> -->
  364. </template>
  365. </template>
  366. <template v-else>
  367. <view class="flex items-center justify-center mt-26 mb-36">
  368. <div class="text-black/40 text-xs font-normal font-['PingFang_SC'] leading-[10.18px]">
  369. 这里空空的
  370. </div>
  371. <div
  372. class="ml-1.5 text-[#2f4471]/90 text-xs font-normal font-['PingFang_SC'] leading-[10.18px]"
  373. @click="focus = true"
  374. >
  375. 点击评论~
  376. </div>
  377. </view>
  378. </template>
  379. </view>
  380. </div>
  381. <BottomAppBar v-if="!isShared" fixed placeholder border custom-class="">
  382. <div class="bg-white flex items-center">
  383. <div class="w-[168px] bg-[#f6f6f6] rounded-[60px] px-3.5 py-2 flex items-center">
  384. <wd-input
  385. ref="commentRef"
  386. custom-class="bg-transparent!"
  387. no-border
  388. confirm-type="send"
  389. v-model="reviewContent"
  390. placeholder="说点什么..."
  391. :focus="focus"
  392. :cursor-spacing="16"
  393. @blur="focus = false"
  394. @confirm="handleSend"
  395. ></wd-input>
  396. </div>
  397. <view class="flex justify-around flex-1">
  398. <div>
  399. <template v-if="features.shareMoment">
  400. <button
  401. open-type="share"
  402. class="bg-transparent! p-0!"
  403. :data-options="data"
  404. @click.stop
  405. >
  406. <view
  407. class="flex flex-col items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  408. >
  409. <div class="w-4.5 h-4.5 flex items-center justify-center">
  410. <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>
  411. </div>
  412. <view class="">{{ data?.shareCount || 0 }}</view>
  413. </view>
  414. </button>
  415. </template>
  416. <template v-else>
  417. <!-- <view-->
  418. <!-- @click.stop="clickByPermission('share', () => emits('share', options))"-->
  419. <!-- class="flex items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"-->
  420. <!-- >-->
  421. <!-- <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>-->
  422. <!-- <view class="ml-1">{{ props.options.shareCount }}</view>-->
  423. <!-- </view>-->
  424. <view
  425. class="flex flex-col items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  426. @click.stop="clickByPermission('share', () => run())"
  427. >
  428. <div class="w-4.5 h-4.5 flex items-center justify-center">
  429. <wd-img width="15" height="15" src="/static/svgs/share.svg"></wd-img>
  430. </div>
  431. <view class="">{{ data?.shareCount || 0 }}</view>
  432. </view>
  433. </template>
  434. <!-- <button open-type="share" class="bg-transparent! p-0!">-->
  435. <!-- </button>-->
  436. </div>
  437. <view
  438. class="flex flex-col items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  439. >
  440. <div class="w-4.5 h-4.5 flex items-center justify-center">
  441. <wd-img width="15" height="15" src="/static/svgs/comment.svg"></wd-img>
  442. </div>
  443. <view class="">{{ data?.reviewCount }}</view>
  444. </view>
  445. <view
  446. class="flex flex-col items-center text-[rgba(0,0,0,0.85)] text-3.5 font-400 line-height-5.5"
  447. @click="
  448. clickByPermission('thumbsUp', () =>
  449. handleUpvoteClick(
  450. {
  451. upvote: data.ownUpvote,
  452. circleId: data.id,
  453. userId: userInfo.userId,
  454. userName: userInfo.nickname,
  455. },
  456. () => run(),
  457. ),
  458. )
  459. "
  460. >
  461. <template v-if="data.ownUpvote">
  462. <wd-img width="18" height="18" :src="likeActived"></wd-img>
  463. </template>
  464. <template v-else>
  465. <wd-img width="18" height="18" :src="likeBlack"></wd-img>
  466. </template>
  467. <view>{{ data.upvoteCount }}</view>
  468. </view>
  469. </view>
  470. </div>
  471. </BottomAppBar>
  472. <BottomAppBar v-if="isShared" fixed placeholder>
  473. <div>
  474. <wd-button block :round="false" @click="toDesignerHomepage">查看设计师主页</wd-button>
  475. </div>
  476. </BottomAppBar>
  477. </view>
  478. </template>
  479. <style lang="scss" scope>
  480. .currentImg {
  481. position: absolute;
  482. z-index: 2;
  483. color: #fff;
  484. background-color: rgba(0, 0, 0, 0.5);
  485. top: 10rpx;
  486. right: 10rpx;
  487. padding: 4rpx 20rpx;
  488. font-size: 24rpx;
  489. border-radius: 8rpx;
  490. }
  491. </style>