index.vue 5.3 KB

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