index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!-- 使用 type="home" 属性设置首页,其他页面不需要设置,默认为page;推荐使用json5,更强大,且允许注释 -->
  2. <route lang="json5" type="home">
  3. {
  4. layout: 'tabbar',
  5. style: {
  6. navigationStyle: 'custom',
  7. navigationBarTitleText: '首页',
  8. },
  9. }
  10. </route>
  11. <script lang="ts" setup>
  12. import Card from '@/components/card.vue'
  13. import HotActivity from '@/components/hot-activity.vue'
  14. import MomentItem from '@/components/moment-item.vue'
  15. import HomeBanner from './components/home-banner.vue'
  16. import useRequest from '../../hooks/useRequest'
  17. import Menus from './components/menus.vue'
  18. import {
  19. getActivities,
  20. getCircles,
  21. getMyStudyTours,
  22. getSetIndexConfigs,
  23. getStudyTours,
  24. shareCircle,
  25. updateSetIndexConfig,
  26. } from '../../core/libs/requests'
  27. import { logo } from '../../core/libs/svgs'
  28. import PageHelper from '@/components/page-helper.vue'
  29. import { ComponentExposed } from 'vue-component-type-helpers'
  30. import { usePermissions } from '../../composables/permissions'
  31. import { storeToRefs } from 'pinia'
  32. import { messages } from '../../core/libs/messages'
  33. import { handleUpvoteClick, handleShareClick } from '../../core/libs/actions'
  34. import { useUserStore } from '../../store'
  35. import ScheduleCard from './components/schedule-card.vue'
  36. import TiltedButton from '@/components/tilted-button.vue'
  37. import ButtonEvo from '@/components/button-evo.vue'
  38. import ImgBtnEvo from '@/components/img-btn-evo.vue'
  39. import SectionHeading from '@/components/section-heading.vue'
  40. import dayjs from 'dayjs'
  41. import { pick, sort } from 'radash'
  42. import { Activity, StudyTour } from '../../core/libs/models'
  43. import PageHelperEvo from '@/components/page-helper-evo.vue'
  44. import { useMessage } from 'wot-design-uni'
  45. import { useHonorDialog } from '../../composables/honor-dialog'
  46. defineOptions({
  47. name: 'Home',
  48. })
  49. useMessage()
  50. const { show } = useHonorDialog()
  51. const userStore = useUserStore()
  52. const { userInfo } = storeToRefs(userStore)
  53. const { features } = usePermissions()
  54. const pageHelperRef = ref<ComponentExposed<typeof PageHelperEvo>>()
  55. const { data: indexConfigsData, run: setIndexConfigsData } = useRequest(
  56. () => getSetIndexConfigs(),
  57. { initialData: { list: [] } },
  58. )
  59. const { data: studyTours, run: setStudyTours } = useRequest(() => getMyStudyTours(), {
  60. initialData: [],
  61. })
  62. const swiperData = ref<{ data: any }[]>()
  63. const swiperCurrent = ref(0)
  64. const hotActivities =
  65. ref<{ type: 'studyTour' | 'activity'; data: StudyTour & Activity; startAt: string | number }[]>()
  66. const currentStudyTour = computed(() =>
  67. studyTours.value.find(
  68. (it) => dayjs(it.studyStartTime).isBefore(dayjs()) && dayjs(it.studyEndTime).isAfter(dayjs()),
  69. ),
  70. )
  71. const toAbout = () => {
  72. uni.navigateTo({ url: '/pages/home/about/index' })
  73. }
  74. const handleSwiperChange = ({ detail: { current } }) => {
  75. swiperCurrent.value = current
  76. }
  77. const handleLike = async (options) => {
  78. await handleUpvoteClick({
  79. ...options,
  80. userId: userInfo.value.userId,
  81. userName: userInfo.value.nickname,
  82. })
  83. pageHelperRef.value?.refresh()
  84. }
  85. const setHotActivities = async () => {
  86. const res = await Promise.all([
  87. getStudyTours({ headRecommend: 1 }).then((res) =>
  88. res.data.list.map((it) => ({ type: 'studyTour', data: it, startAt: it.applyStartTime })),
  89. ),
  90. getActivities({ headRecommend: 1 }).then((res) =>
  91. res.data.list.map((it) => ({ type: 'activity', data: it, startAt: it.applyStartTime })),
  92. ),
  93. ])
  94. console.log(sort(res.flat(), (it) => it.startAt))
  95. hotActivities.value = sort(res.flat(), (it) => it.startAt) as any
  96. }
  97. const handlePlay = async (id) => {
  98. const body = pick(swiperData.value?.find((it) => it.data.id === id).data, ['id', 'status'])
  99. await updateSetIndexConfig(body)
  100. }
  101. onShow(async () => {
  102. pageHelperRef.value?.reload()
  103. await Promise.all([setHotActivities(), setStudyTours()])
  104. })
  105. onLoad(async () => {
  106. await Promise.all([setIndexConfigsData()])
  107. swiperData.value = indexConfigsData.value.list.map((it) => ({
  108. data: it,
  109. }))
  110. show.value({ title: '看不见', content: '看不见', path: '', image: '' })
  111. })
  112. onShareAppMessage(async ({ from, target }) => {
  113. console.log('from', from)
  114. console.log('target', target)
  115. const res: Page.CustomShareContent = {}
  116. if (from === 'button') {
  117. await shareCircle(target.dataset.options.id)
  118. res.path = `/pages/home/moment/index?id=${target.dataset.options.id}&isShared=true`
  119. res.imageUrl = target.dataset.options.bannerUrls[0]
  120. res.title = `${target.dataset.options.stylistName}: ${target.dataset.options.circleDesc}`
  121. }
  122. if (from === 'menu') {
  123. res.title = messages.home.shareTitle
  124. }
  125. return res
  126. })
  127. </script>
  128. <template>
  129. <view class="">
  130. <view class="bg-black w-full relative aspect-[1.26/1]">
  131. <swiper autoplay @change="handleSwiperChange">
  132. <template
  133. v-for="{ data: { id, coverVideoImage, indexPromotionalVideoImage } } of swiperData"
  134. :key="id"
  135. >
  136. <swiper-item>
  137. <HomeBanner
  138. :id="id"
  139. :url="indexPromotionalVideoImage"
  140. :cover="coverVideoImage"
  141. @play="handlePlay"
  142. />
  143. </swiper-item>
  144. </template>
  145. </swiper>
  146. </view>
  147. <view class="bg-[#f6f6f6] relative bottom-4 rounded-t-2xl py-1">
  148. <template v-if="currentStudyTour">
  149. <ScheduleCard
  150. custom-class="my-6 mx-3.5"
  151. :items="currentStudyTour.studyTravelDOList"
  152. ></ScheduleCard>
  153. </template>
  154. <!-- <SectionHeading title="按钮调试"></SectionHeading> -->
  155. <!-- <div class="flex">
  156. <TiltedButton size="large" custom-class="w-30"></TiltedButton>
  157. <ButtonEvo>神奇按钮</ButtonEvo>
  158. <ImgBtnEvo></ImgBtnEvo>
  159. </div> -->
  160. <!-- <div class="flex flex-col gap-1">
  161. <button>咲</button>
  162. <ButtonEvo custom-class="w-auto!">咲</ButtonEvo>
  163. <ButtonEvo custom-class="">遥星</ButtonEvo>
  164. <ButtonEvo custom-class="">血不染</ButtonEvo>
  165. <ButtonEvo custom-class="">天地不容</ButtonEvo>
  166. <ButtonEvo custom-class="">飒沓如流星</ButtonEvo>
  167. <ButtonEvo custom-class="">君有才能纵捭阖</ButtonEvo>
  168. <div class="w-full">
  169. <ButtonEvo custom-class="" block>诗仙纵横,刀剑茫茫去不还</ButtonEvo>
  170. </div>
  171. <ButtonEvo color="red" size="lg">敌无命</ButtonEvo>
  172. </div> -->
  173. <menus></menus>
  174. <view v-if="hotActivities?.length" class="my-6 mx-3.5">
  175. <HotActivity :items="hotActivities"></HotActivity>
  176. </view>
  177. <view v-if="features.about" class="my-6 mx-3.5" @click="toAbout()">
  178. <Card>
  179. <div class="flex items-center gap-2">
  180. <wd-img width="28" height="28" :src="logo"></wd-img>
  181. <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-[10.18px]">
  182. 1分钟快速了解筑巢荟
  183. </div>
  184. <div class="flex-1"></div>
  185. <wd-icon name="help-circle" size="22px" custom-class="text-black/60"></wd-icon>
  186. </div>
  187. </Card>
  188. </view>
  189. <view class="mx-3.5 text-5 font-400">设计圈</view>
  190. <view class="mx-3.5">
  191. <PageHelperEvo ref="pageHelperRef" :request="getCircles" class="">
  192. <template #default="{ source }">
  193. <template v-for="it of source.list" :key="it.id">
  194. <view class="my-3">
  195. <MomentItem :options="it" @like="handleLike"></MomentItem>
  196. </view>
  197. </template>
  198. </template>
  199. </PageHelperEvo>
  200. </view>
  201. </view>
  202. </view>
  203. </template>
  204. <style></style>