index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <scroll-view class="card-container" scroll-y @scroll="onScroll" :scroll-top="0">
  3. <!-- 顶部背景 -->
  4. <NavBar :title="'首页'" :show_back="false" :color="'#fff'" :fixed="true" :bgImg="'/static/image/home/top-bg.png'"
  5. :bg="'transparent'">
  6. <template #left>
  7. <!-- <view class="left-title">{{appName}}</view> -->
  8. </template>
  9. </NavBar>
  10. <image class="top-bg" src="/static/image/home/top-bg.png" />
  11. <!-- 名片轮播 -->
  12. <view class="page-top" :class="{activeCard:pageIn}">
  13. <swiper class="card-swiper" :current="currentIndex" @change="onSwiperChange" circular
  14. :indicator-dots="false" :autoplay="false">
  15. <swiper-item v-for="(card, idx) in cardList" :key="card.userId || idx">
  16. <view class="swiper-item-wrapper">
  17. <UserCard :info="card" @call="makeCall" />
  18. </view>
  19. </swiper-item>
  20. </swiper>
  21. <ShareButton />
  22. </view>
  23. <view class="card-content" :class="{activeCard:pageIn}">
  24. <!-- 企业简介 -->
  25. <CompanyIntroduce></CompanyIntroduce>
  26. </view>
  27. <!-- 隐藏的 Canvas 用于生成名片快照 -->
  28. <canvas id="posterCanvas" type="2d"
  29. style="position: fixed; left: -9999px; top: -9999px; width: 750px; height: 780px;"></canvas>
  30. <!-- 隐藏的 Canvas 用于生成二维码海报 -->
  31. <view class="hidden-canvas-box">
  32. <canvas id="qrPosterCanvas" type="2d" style="width: 600px; height: 700px;"></canvas>
  33. </view>
  34. </scroll-view>
  35. </template>
  36. <script setup>
  37. import {
  38. ref,
  39. computed,
  40. onMounted
  41. } from 'vue'
  42. import {
  43. onShareAppMessage
  44. } from '@dcloudio/uni-app';
  45. import NavBar from '@/components/nav-bar/index.vue'
  46. import UserAvatar from '@/components/user-avatar/index.vue'
  47. import EmptyState from '@/components/empty-state/index.vue'
  48. import ShareButton from '@/components/shareButton/index.vue'
  49. import CompanyIntroduce from '@/components/companyIntroduce/index.vue'
  50. import UserCard from '@/components/user-card/index.vue'
  51. import {
  52. useUserStore
  53. } from '@/store/modules/user.js'
  54. import {
  55. storeToRefs
  56. } from 'pinia'
  57. // 使用 Pinia 管理用户状态
  58. const userStore = useUserStore()
  59. const {
  60. cardInfo,
  61. cardList,
  62. currentIndex,
  63. cardImage,
  64. queryCardPoster
  65. } = storeToRefs(userStore)
  66. let appName = ref('')
  67. // 入场动画状态
  68. const pageIn = ref(false)
  69. onMounted(() => {
  70. pageIn.value = true
  71. })
  72. const loading = ref(false)
  73. const onSwiperChange = (e) => {
  74. userStore.setCurrentIndex(e.detail.current)
  75. }
  76. onShareAppMessage(() => {
  77. return {
  78. path: `pages/splash/splash?userId=${cardInfo.value.userId}&currentIndex=${currentIndex.value}`,
  79. imageUrl: cardImage.value,
  80. title: `${cardInfo.value.nickName} 向你分享了名片`
  81. };
  82. });
  83. // 导航栏滚动渐变
  84. const navBg = ref('transparent')
  85. const navColor = ref('#ffffff')
  86. const onScroll = (e) => {
  87. const scrollTop = e.detail.scrollTop
  88. if (scrollTop > 30) {
  89. navBg.value = '#ffffff'
  90. navColor.value = '#333333'
  91. } else {
  92. navBg.value = 'transparent'
  93. navColor.value = '#ffffff'
  94. }
  95. }
  96. // 拨打电话交由 UserCard 组件内部处理,这里只是留空以备后续扩展
  97. const makeCall = () => {}
  98. </script>
  99. <style lang="scss" scoped>
  100. .card-container {
  101. background: #f5f6f8;
  102. height: 100vh;
  103. }
  104. .left-title {
  105. font-size: 44rpx;
  106. font-weight: bold;
  107. color: #ffffff;
  108. text-shadow: 2px 2px 0 black;
  109. }
  110. .top-bg {
  111. width: 100%;
  112. position: fixed;
  113. top: 0;
  114. left: 0;
  115. z-index: 1;
  116. }
  117. // 顶部背景区域
  118. .header-bg {
  119. background: linear-gradient(135deg, #4A90E2 0%, #6FB3F2 50%, #87CEEB 100%);
  120. padding: 0 40rpx;
  121. padding-top: calc(var(--status-bar-height) + 20rpx);
  122. padding-bottom: 60rpx;
  123. position: relative;
  124. overflow: hidden;
  125. // 背景光效
  126. &::before {
  127. content: '';
  128. position: absolute;
  129. top: -100rpx;
  130. right: -100rpx;
  131. width: 500rpx;
  132. height: 500rpx;
  133. background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
  134. border-radius: 50%;
  135. }
  136. // 导航栏
  137. .nav-bar {
  138. display: flex;
  139. align-items: center;
  140. justify-content: space-between;
  141. height: 88rpx;
  142. position: relative;
  143. z-index: 10;
  144. .nav-back {
  145. width: 60rpx;
  146. height: 60rpx;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. }
  151. .nav-title {
  152. font-size: 32rpx;
  153. font-weight: 600;
  154. color: #ffffff;
  155. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  156. }
  157. .nav-right {
  158. display: flex;
  159. align-items: center;
  160. .more-btn,
  161. .refresh-btn {
  162. width: 64rpx;
  163. height: 64rpx;
  164. border-radius: 50%;
  165. background: rgba(255, 255, 255, 0.15);
  166. display: flex;
  167. align-items: center;
  168. justify-content: center;
  169. margin-left: 16rpx;
  170. }
  171. }
  172. }
  173. }
  174. .page-top {
  175. margin: 0 24rpx 24rpx;
  176. position: relative;
  177. z-index: 2;
  178. transform: scale(0.85);
  179. }
  180. // 名片轮播
  181. .card-swiper {
  182. height: 392rpx;
  183. position: relative;
  184. z-index: 2;
  185. }
  186. // 轮播索引指示器
  187. .swiper-indicator {
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. gap: 12rpx;
  192. margin-top: 16rpx;
  193. padding-bottom: 8rpx;
  194. .indicator-dot {
  195. width: 14rpx;
  196. height: 14rpx;
  197. border-radius: 50%;
  198. background: rgba(0, 0, 0, 0.15);
  199. transition: all 0.3s ease;
  200. &.active {
  201. width: 32rpx;
  202. border-radius: 8rpx;
  203. background: rgba(64, 128, 255, 0.8);
  204. }
  205. }
  206. }
  207. // 名片内容区域
  208. .card-content {
  209. margin: 0 24rpx;
  210. padding: 20rpx 40rpx;
  211. border-radius: 24rpx;
  212. background: #ffffff;
  213. box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.04);
  214. position: relative;
  215. bottom: 24rpx;
  216. z-index: 2;
  217. transform: translateY(150rpx);
  218. }
  219. // 隐藏的 canvas 容器
  220. .hidden-canvas-box {
  221. position: fixed;
  222. left: -9999px;
  223. top: -9999px;
  224. width: 1px;
  225. height: 1px;
  226. overflow: hidden;
  227. }
  228. </style>