index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <scroll-view class="card-container" scroll-y @scroll="onScroll" :scroll-top="0">
  3. <!-- 顶部背景 -->
  4. <image class="top-bg" src="/static/image/home/top-bg.png" />
  5. <NavBar :title="'首页'" :show_back="false" :color="'#fff'" :fixed="true" :bgImg="'/static/image/home/top-bg.png'" :bg="'transparent'">
  6. <template #left>
  7. <!-- <view class="left-title">{{appName}}</view> -->
  8. </template>
  9. </NavBar>
  10. <!-- 名片卡片 -->
  11. <view class="page-top">
  12. <view class="user-card" id="user-card">
  13. <!-- 背景图 -->
  14. <image class="user-card-bg" src="/static/image/home/usecard-bg.png" />
  15. <!-- 左上:姓名 + 职位 -->
  16. <view class="user-header">
  17. <view class="name-row">
  18. <text class="user-name">{{ cardInfo.nickName || '用户' }}</text>
  19. <text class="user-role">{{ cardInfo.postName || '职位' }}</text>
  20. </view>
  21. <text class="company-name">{{ cardInfo.companyName || '公司名称' }}</text>
  22. </view>
  23. <!-- 右上:头像 -->
  24. <view class="avatar-wrapper">
  25. <UserAvatar :src="cardInfo.avatar" :name="cardInfo.nickName" :size="142"
  26. :badge-src="'/static/image/public/badge-icon.png'" :badge-size="56" />
  27. </view>
  28. <!-- 左下:联系方式 -->
  29. <view class="user-contact">
  30. <view class="contact-row" @click="makeCall">
  31. <uni-icons type="phone" :size="18" color="#666666"></uni-icons>
  32. <text class="contact-text">{{ cardInfo.phonenumber || '暂无电话' }}</text>
  33. </view>
  34. <view class="contact-row">
  35. <uni-icons type="email" :size="18" color="#666666"></uni-icons>
  36. <text class="contact-text">{{ cardInfo.email || '暂无邮箱' }}</text>
  37. </view>
  38. <view class="contact-row">
  39. <uni-icons type="location" :size="18" color="#666666"></uni-icons>
  40. <text class="contact-text">{{ cardInfo.companyAddress || '暂无地址' }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <ShareButton />
  45. </view>
  46. <view class="card-content">
  47. <!-- 企业简介 -->
  48. <CompanyIntroduce></CompanyIntroduce>
  49. </view>
  50. <!-- 隐藏的 Canvas 用于生成名片快照 -->
  51. <canvas id="posterCanvas" type="2d"
  52. style="position: fixed; left: -9999px; top: -9999px; width: 750px; height: 780px;"></canvas>
  53. <!-- 隐藏的 Canvas 用于生成二维码海报 -->
  54. <view class="hidden-canvas-box">
  55. <canvas id="qrPosterCanvas" type="2d" style="width: 600px; height: 700px;"></canvas>
  56. </view>
  57. </scroll-view>
  58. </template>
  59. <script setup>
  60. import {
  61. ref,
  62. onMounted
  63. } from 'vue'
  64. import {
  65. onShareAppMessage
  66. } from '@dcloudio/uni-app';
  67. import NavBar from '@/components/nav-bar/index.vue'
  68. import UserAvatar from '@/components/user-avatar/index.vue'
  69. import EmptyState from '@/components/empty-state/index.vue'
  70. import ShareButton from '@/components/shareButton/index.vue'
  71. import CompanyIntroduce from '@/components/companyIntroduce/index.vue'
  72. import {
  73. useUserStore
  74. } from '@/store/modules/user.js'
  75. import {
  76. storeToRefs
  77. } from 'pinia'
  78. // 使用 Pinia 管理用户状态
  79. const userStore = useUserStore()
  80. const {
  81. cardInfo,
  82. companyInfo,
  83. cardImage
  84. } = storeToRefs(userStore)
  85. let appName = ref('')
  86. onShareAppMessage(() => {
  87. return {
  88. path: 'pages/splash/splash?userId=' + cardInfo.value.userId,
  89. imageUrl: cardImage.value,
  90. title: `${cardInfo.value.nickName} 向你分享了名片`
  91. };
  92. });
  93. // 导航栏滚动渐变
  94. const navBg = ref('transparent')
  95. const navColor = ref('#ffffff')
  96. const onScroll = (e) => {
  97. const scrollTop = e.detail.scrollTop
  98. if (scrollTop > 30) {
  99. navBg.value = '#ffffff'
  100. navColor.value = '#333333'
  101. } else {
  102. navBg.value = 'transparent'
  103. navColor.value = '#ffffff'
  104. }
  105. }
  106. const makeCall = () => {
  107. if (cardInfo.value.phonenumber) {
  108. uni.makePhoneCall({
  109. phoneNumber: cardInfo.value.phonenumber
  110. })
  111. } else {
  112. uni.showToast({
  113. title: '暂无电话号码',
  114. icon: 'none'
  115. })
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .card-container {
  121. background: #f5f6f8;
  122. height: 100vh;
  123. }
  124. .left-title {
  125. font-size: 44rpx;
  126. font-weight: bold;
  127. color: #ffffff;
  128. text-shadow: 2px 2px 0 black;
  129. }
  130. .top-bg {
  131. width: 100%;
  132. position: fixed;
  133. top: 0;
  134. left: 0;
  135. z-index: 1;
  136. }
  137. // 顶部背景区域
  138. .header-bg {
  139. background: linear-gradient(135deg, #4A90E2 0%, #6FB3F2 50%, #87CEEB 100%);
  140. padding: 0 40rpx;
  141. padding-top: calc(var(--status-bar-height) + 20rpx);
  142. padding-bottom: 60rpx;
  143. position: relative;
  144. overflow: hidden;
  145. // 背景光效
  146. &::before {
  147. content: '';
  148. position: absolute;
  149. top: -100rpx;
  150. right: -100rpx;
  151. width: 500rpx;
  152. height: 500rpx;
  153. background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
  154. border-radius: 50%;
  155. }
  156. // 导航栏
  157. .nav-bar {
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-between;
  161. height: 88rpx;
  162. position: relative;
  163. z-index: 10;
  164. .nav-back {
  165. width: 60rpx;
  166. height: 60rpx;
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. }
  171. .nav-title {
  172. font-size: 32rpx;
  173. font-weight: 600;
  174. color: #ffffff;
  175. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  176. }
  177. .nav-right {
  178. display: flex;
  179. align-items: center;
  180. .more-btn,
  181. .refresh-btn {
  182. width: 64rpx;
  183. height: 64rpx;
  184. border-radius: 50%;
  185. background: rgba(255, 255, 255, 0.15);
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. margin-left: 16rpx;
  190. }
  191. }
  192. }
  193. }
  194. .page-top {
  195. margin: 0 24rpx 24rpx;
  196. .user-card {
  197. position: relative;
  198. z-index: 2;
  199. width: 100%;
  200. height: 400rpx;
  201. box-sizing: border-box;
  202. padding: 80rpx 40rpx 32rpx;
  203. position: relative;
  204. .user-card-bg {
  205. position: absolute;
  206. top: 0;
  207. left: 0;
  208. width: 100%;
  209. height: 100%;
  210. z-index: 0;
  211. }
  212. view,
  213. text {
  214. position: relative;
  215. z-index: 1;
  216. }
  217. .user-header {
  218. .name-row {
  219. display: flex;
  220. align-items: center;
  221. margin-bottom: 16rpx;
  222. .user-name {
  223. font-size: 44rpx;
  224. font-weight: 700;
  225. color: #202020;
  226. line-height: 1.2;
  227. }
  228. .user-role {
  229. margin-left: 16rpx;
  230. padding: 6rpx 16rpx;
  231. background: rgba(68, 110, 255, 0.10);
  232. border-radius: 8rpx;
  233. font-size: 24rpx;
  234. font-weight: 500;
  235. color: #446eff;
  236. }
  237. }
  238. .company-name {
  239. font-size: 28rpx;
  240. font-weight: 500;
  241. color: #666666;
  242. line-height: 1.4;
  243. }
  244. }
  245. .avatar-wrapper {
  246. position: absolute;
  247. top: 74rpx;
  248. right: 36rpx;
  249. z-index: 2;
  250. }
  251. .user-contact {
  252. margin-top: 32rpx;
  253. .contact-row {
  254. display: flex;
  255. align-items: center;
  256. margin-bottom: 16rpx;
  257. /* 溢出部分用省略号代替 */
  258. uni-icons {
  259. margin-right: 12rpx;
  260. flex-shrink: 0;
  261. }
  262. .contact-text {
  263. font-size: 26rpx;
  264. color: #666666;
  265. overflow: hidden;
  266. /* 隐藏溢出的内容 */
  267. white-space: nowrap;
  268. /* 强制文本在一行内显示 */
  269. text-overflow: ellipsis;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. // 名片内容区域
  276. .card-content {
  277. margin: 0 24rpx;
  278. padding: 20rpx 40rpx;
  279. border-radius: 24rpx;
  280. background: #ffffff;
  281. box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.04);
  282. position: relative;
  283. bottom: 24rpx;
  284. z-index: 2;
  285. }
  286. // 隐藏的 canvas 容器
  287. .hidden-canvas-box {
  288. position: fixed;
  289. left: -9999px;
  290. top: -9999px;
  291. width: 1px;
  292. height: 1px;
  293. overflow: hidden;
  294. }
  295. </style>