login-sheet.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <view class="login-sheet-overlay" :class="{ 'login-sheet-overlay--visible': visible }" @click="handleOverlayClick">
  3. <view class="login-sheet-panel" :class="{ 'login-sheet-panel--show': panelShow }" @click.stop>
  4. <view class="login-sheet-header">
  5. <view class="login-sheet-title">欢迎回来</view>
  6. </view>
  7. <scroll-view scroll-y class="login-sheet-scroll" :show-scrollbar="false">
  8. <view class="login-sheet-content">
  9. <!-- 品牌区(左上角锁定版式,与首页一致) -->
  10. <view class="brand-bar">
  11. <image class="brand-logo" src="/static/logo.png" mode="aspectFit" @error="handleImageError"></image>
  12. <view class="brand-texts">
  13. <text class="brand-name">浠艾福</text>
  14. <text class="brand-tagline">您的专属家庭主动健康陪跑</text>
  15. </view>
  16. </view>
  17. <!-- 理念卡 -->
  18. <view class="concept-card">
  19. <view class="loop-row">
  20. <view class="loop-pill loop-pill-indigo"><text>🔍</text><text class="loop-pill-text">提前识别</text></view>
  21. <text class="loop-arrow">→</text>
  22. <view class="loop-pill loop-pill-green"><text>🛡️</text><text class="loop-pill-text">风险管控</text></view>
  23. <text class="loop-arrow">→</text>
  24. <view class="loop-pill loop-pill-amber"><text>⚡</text><text class="loop-pill-text">主动干预</text></view>
  25. <text class="loop-arrow">→</text>
  26. <view class="loop-pill loop-pill-red"><text>📊</text><text class="loop-pill-text">效果评估</text></view>
  27. </view>
  28. </view>
  29. <!-- 登录表单 -->
  30. <view class="login-form">
  31. <view class="phone-section">
  32. <button
  33. class="phone-btn"
  34. open-type="getPhoneNumber"
  35. @getphonenumber="getPhoneNumber"
  36. @tap="onPhoneBtnTap"
  37. :loading="loading"
  38. :disabled="!agreed || loading || tapLock"
  39. >
  40. <text class="phone-btn-icon">📱</text>
  41. <text class="phone-btn-text">手机号快捷登录</text>
  42. <text class="phone-arrows">›››</text>
  43. </button>
  44. </view>
  45. <view class="agreement">
  46. <checkbox-group @change="onAgreementChange">
  47. <label>
  48. <checkbox value="agree" :checked="agreed" />
  49. <text class="agreement-text">我已阅读并同意</text>
  50. </label>
  51. </checkbox-group>
  52. <text class="link" @click="showAgreement">《用户协议》</text>
  53. <text class="agreement-text">和</text>
  54. <text class="link" @click="showPrivacy">《隐私政策》</text>
  55. </view>
  56. <view class="skip-section">
  57. <view class="skip-btn" @click="handleSkipLogin">暂不登录,先逛逛</view>
  58. </view>
  59. </view>
  60. </view>
  61. </scroll-view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { wechatPhoneLogin } from '../utils/api.js'
  67. export default {
  68. name: 'login-sheet',
  69. data() {
  70. return {
  71. visible: false,
  72. panelShow: false,
  73. loading: false,
  74. // tapLock:在「点击」瞬间上锁,用于关闭授权弹窗弹出前的连点窗口(见 onPhoneBtnTap)
  75. tapLock: false,
  76. agreed: false,
  77. nickname: '',
  78. avatar: '',
  79. redirectUrl: '',
  80. _tapLockTimer: null
  81. }
  82. },
  83. beforeDestroy() {
  84. this.clearTimers()
  85. },
  86. methods: {
  87. clearTimers() {
  88. if (this._tapLockTimer) {
  89. clearTimeout(this._tapLockTimer)
  90. this._tapLockTimer = null
  91. }
  92. },
  93. // 由宿主页面通过 mixin openLoginSheet() 调用,或 pages/login/login.vue 兜底壳调用
  94. open(options) {
  95. options = options || {}
  96. // 处理邀请码
  97. if (options.inviteCode) {
  98. uni.setStorageSync('inviteCode', options.inviteCode)
  99. uni.setStorageSync('inviteType', options.inviteType || 'family')
  100. }
  101. // 处理推荐码(refCode)
  102. if (options.refCode) {
  103. uni.setStorageSync('refCode', options.refCode)
  104. }
  105. // 存储登录后跳转地址
  106. if (options.redirect) {
  107. this.redirectUrl = decodeURIComponent(options.redirect)
  108. }
  109. this.visible = true
  110. // 通知宿主页面(页面可借此隐藏可能盖住浮层的原生 canvas 等)
  111. this.$emit('open')
  112. this.$nextTick(() => {
  113. setTimeout(() => {
  114. this.panelShow = true
  115. }, 10)
  116. })
  117. },
  118. close() {
  119. this.panelShow = false
  120. setTimeout(() => {
  121. this.visible = false
  122. // 浮层完全淡出后再通知,避免宿主提前恢复被隐藏的原生 canvas 造成闪烁
  123. this.$emit('close')
  124. }, 250)
  125. },
  126. handleOverlayClick() {
  127. this.close()
  128. },
  129. handleImageError() {
  130. console.log('Logo 加载失败,使用默认显示')
  131. },
  132. onAgreementChange(e) {
  133. this.agreed = e.detail.value.length > 0
  134. },
  135. showAgreement() {
  136. uni.navigateTo({
  137. url: '/pages/policy/agreement'
  138. })
  139. },
  140. showPrivacy() {
  141. uni.navigateTo({
  142. url: '/pages/policy/privacy'
  143. })
  144. },
  145. handleSkipLogin() {
  146. // 不登录直接关闭浮层,停留当前页
  147. this.close()
  148. },
  149. // 点击瞬间上锁,关闭「授权弹窗弹出前」的连点窗口
  150. onPhoneBtnTap() {
  151. if (this.loading || this.tapLock) return
  152. this.tapLock = true
  153. if (this._tapLockTimer) clearTimeout(this._tapLockTimer)
  154. this._tapLockTimer = setTimeout(() => {
  155. this.tapLock = false
  156. this._tapLockTimer = null
  157. }, 3000)
  158. },
  159. getPhoneNumber(e) {
  160. // 授权流程已结束,释放 tap 锁与兜底定时器,按钮恢复可点
  161. if (this._tapLockTimer) {
  162. clearTimeout(this._tapLockTimer)
  163. this._tapLockTimer = null
  164. }
  165. this.tapLock = false
  166. if (!this.agreed) {
  167. uni.showToast({ title: '请先同意用户协议', icon: 'none' })
  168. return
  169. }
  170. if (!e.detail || !e.detail.code) {
  171. uni.showToast({ title: '授权失败,请重试', icon: 'none' })
  172. return
  173. }
  174. var self = this
  175. self.loading = true
  176. // 点击授权时实时获取 login code(微信 code 一次性有效,不能复用旧 code)
  177. uni.login({
  178. provider: 'weixin',
  179. success: function(loginRes) {
  180. if (!loginRes.code) {
  181. uni.showToast({ title: '网络异常,请重试', icon: 'none' })
  182. self.loading = false
  183. return
  184. }
  185. wechatPhoneLogin({ code: loginRes.code, phoneCode: e.detail.code }).then(function(res) {
  186. self.completeLogin(res.data)
  187. }).catch(function(err) {
  188. uni.showToast({ title: err.message || '登录失败', icon: 'none' })
  189. self.loading = false
  190. })
  191. },
  192. fail: function() {
  193. uni.showToast({ title: '网络异常,请重试', icon: 'none' })
  194. self.loading = false
  195. }
  196. })
  197. },
  198. completeLogin(data) {
  199. if (!data) return
  200. // 写入登录态
  201. if (data.token) uni.setStorageSync('token', data.token)
  202. if (data.userId) uni.setStorageSync('userId', data.userId)
  203. if (data.openid) uni.setStorageSync('openid', data.openid)
  204. if (data.nickname) {
  205. this.nickname = data.nickname
  206. uni.setStorageSync('nickname', data.nickname)
  207. }
  208. if (data.avatar) {
  209. this.avatar = data.avatar
  210. uni.setStorageSync('avatar', data.avatar)
  211. }
  212. // 通知宿主页面(页面通过 @success="onSheetLoginSuccess" 刷新数据)
  213. this.$emit('success', data)
  214. // 关闭浮层,停留当前页
  215. this.close()
  216. }
  217. }
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. /* ===== 浮层遮罩 ===== */
  222. .login-sheet-overlay {
  223. position: fixed;
  224. top: 0;
  225. left: 0;
  226. right: 0;
  227. bottom: 0;
  228. background: rgba(0, 0, 0, 0.5);
  229. z-index: 99999;
  230. opacity: 0;
  231. visibility: hidden;
  232. transition: opacity 0.25s ease;
  233. }
  234. .login-sheet-overlay--visible {
  235. opacity: 1;
  236. visibility: visible;
  237. }
  238. /* ===== 底部面板 ===== */
  239. .login-sheet-panel {
  240. position: fixed;
  241. left: 0;
  242. right: 0;
  243. bottom: 0;
  244. height: 60vh;
  245. max-height: 65vh;
  246. background: linear-gradient(180deg, #fffaf3 0%, #fff3e4 100%);
  247. border-radius: 24rpx 24rpx 0 0;
  248. overflow: hidden;
  249. transform: translateY(100%);
  250. transition: transform 0.3s ease;
  251. display: flex;
  252. flex-direction: column;
  253. }
  254. .login-sheet-panel--show {
  255. transform: translateY(0);
  256. }
  257. .login-sheet-header {
  258. padding: 24rpx 32rpx 8rpx;
  259. display: flex;
  260. justify-content: center;
  261. }
  262. .login-sheet-title {
  263. font-size: calc(32rpx * var(--font-scale, 1));
  264. font-weight: bold;
  265. color: $facade-text-strong;
  266. }
  267. /* ===== 滚动区域 ===== */
  268. .login-sheet-scroll {
  269. flex: 1;
  270. min-height: 0;
  271. width: 100%;
  272. box-sizing: border-box;
  273. }
  274. .login-sheet-content {
  275. padding: 24rpx 48rpx 60rpx;
  276. box-sizing: border-box;
  277. }
  278. /* ===== 品牌区(左上角锁定版式,与首页一致) ===== */
  279. .brand-bar {
  280. display: flex;
  281. align-items: center;
  282. gap: 20rpx;
  283. padding: 4rpx 0;
  284. box-sizing: border-box;
  285. }
  286. .brand-logo {
  287. width: 80rpx;
  288. height: 80rpx;
  289. border-radius: 20rpx;
  290. background: $app-surface;
  291. box-shadow: 0 6rpx 16rpx rgba($brand-primary, 0.18);
  292. flex-shrink: 0;
  293. }
  294. .brand-texts {
  295. display: flex;
  296. flex-direction: column;
  297. justify-content: center;
  298. min-width: 0;
  299. padding-left: 20rpx;
  300. border-left: 2rpx solid rgba($brand-primary, 0.28);
  301. }
  302. .brand-name {
  303. font-size: calc(38rpx * var(--font-scale, 1));
  304. font-weight: bold;
  305. color: $facade-text-strong;
  306. letter-spacing: 3rpx;
  307. line-height: 1.2;
  308. }
  309. .brand-tagline {
  310. display: block;
  311. font-size: calc(22rpx * var(--font-scale, 1));
  312. font-weight: 500;
  313. color: $brand-primary-deep;
  314. margin-top: 6rpx;
  315. letter-spacing: 1rpx;
  316. line-height: 1.2;
  317. white-space: nowrap;
  318. }
  319. /* ===== 理念卡 ===== */
  320. .concept-card {
  321. background: rgba(249, 115, 22, 0.08);
  322. border-radius: 24rpx;
  323. padding: 24rpx;
  324. margin-top: 28rpx;
  325. }
  326. .loop-row {
  327. display: flex;
  328. flex-direction: row;
  329. align-items: center;
  330. justify-content: space-between;
  331. margin-top: 16rpx;
  332. flex-wrap: nowrap; /* 禁止换行,确保四步/五维在一行 */
  333. margin-bottom: 16rpx;
  334. }
  335. .loop-pill {
  336. display: flex;
  337. flex-direction: row;
  338. align-items: center;
  339. border-radius: 999rpx;
  340. padding: 6rpx 12rpx;
  341. font-size: calc(22rpx * var(--font-scale, 1));
  342. flex-shrink: 0; /* 防止被压缩导致文本换行 */
  343. white-space: nowrap;
  344. }
  345. .loop-pill-indigo { background: rgba(99, 102, 241, 0.12); color: $dim-wisdom; }
  346. .loop-pill-green { background: rgba(16, 185, 129, 0.12); color: $status-success; }
  347. .loop-pill-amber { background: rgba(245, 158, 11, 0.12); color: $dim-wealth; }
  348. .loop-pill-red { background: rgba(239, 68, 68, 0.12); color: $status-danger; }
  349. .loop-pill-text {
  350. margin-left: 4rpx;
  351. white-space: nowrap; /* 禁止四字步骤文本换行 */
  352. }
  353. .loop-arrow {
  354. font-size: calc(24rpx * var(--font-scale, 1));
  355. color: $facade-text-ghost-light;
  356. padding: 0 2rpx;
  357. flex-shrink: 0; /* 箭头不被压缩 */
  358. }
  359. /* 轨道环:缓慢旋转,呼应 Web 端虚线轨道 */
  360. .orbit-ring {
  361. position: absolute;
  362. left: 50%; top: 50%;
  363. width: 240rpx; height: 240rpx;
  364. margin-left: -120rpx; margin-top: -120rpx;
  365. border: 2rpx dashed rgba(194, 112, 61, 0.35);
  366. border-radius: 50%;
  367. box-sizing: border-box;
  368. animation: orbitRingSpin 24s linear infinite;
  369. }
  370. @keyframes orbitRingSpin {
  371. 0% { transform: rotate(0deg); }
  372. 100% { transform: rotate(360deg); }
  373. }
  374. /* 中心"家"徽章:金色脉冲,呼应 Web 端中心节点 */
  375. .orbit-center {
  376. position: absolute;
  377. left: 50%; top: 50%;
  378. width: 84rpx; height: 84rpx;
  379. margin-left: -42rpx; margin-top: -42rpx;
  380. border-radius: 50%;
  381. background: #F59E0B;
  382. display: flex; align-items: center; justify-content: center;
  383. color: #fff; font-size: calc(36rpx * var(--font-scale, 1)); font-weight: 700;
  384. box-shadow: 0 0 20rpx rgba(245, 158, 11, 0.4);
  385. animation: orbitCenterPulse 3s ease-in-out infinite;
  386. z-index: 3;
  387. }
  388. @keyframes orbitCenterPulse {
  389. 0%, 100% { box-shadow: 0 0 20rpx rgba(245, 158, 11, 0.4); transform: scale(1); }
  390. 50% { box-shadow: 0 0 36rpx rgba(245, 158, 11, 0.6); transform: scale(1.06); }
  391. }
  392. /* 五维公转节点:绕中心旋转,文字保持正立 */
  393. .orbit-node {
  394. position: absolute;
  395. left: 50%; top: 50%;
  396. width: 76rpx; height: 76rpx;
  397. margin-left: -38rpx; margin-top: -38rpx;
  398. border-radius: 50%;
  399. background: var(--node-color);
  400. display: flex; align-items: center; justify-content: center;
  401. color: #fff; font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 700;
  402. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
  403. z-index: 2;
  404. animation-duration: 15s;
  405. animation-timing-function: linear;
  406. animation-iteration-count: infinite;
  407. }
  408. .orbit-node-char { line-height: 1; }
  409. /* 五节点:颜色 + 起始角度 + 错峰延迟,与 Web 端一致 */
  410. .node-0 { --node-color: #FF8C42; animation-name: orbitNode0; animation-delay: 0s; } /* 身 */
  411. .node-1 { --node-color: #1677FF; animation-name: orbitNode1; animation-delay: -3s; } /* 智 */
  412. .node-2 { --node-color: #F59E0B; animation-name: orbitNode2; animation-delay: -6s; } /* 富 */
  413. .node-3 { --node-color: #10B981; animation-name: orbitNode3; animation-delay: -9s; } /* 行 */
  414. .node-4 { --node-color: #FF6B9D; animation-name: orbitNode4; animation-delay: -12s; } /* 心 */
  415. @keyframes orbitNode0 {
  416. 0% { transform: rotate(0deg) translateX(120rpx) rotate(0deg); }
  417. 100% { transform: rotate(360deg) translateX(120rpx) rotate(-360deg); }
  418. }
  419. @keyframes orbitNode1 {
  420. 0% { transform: rotate(72deg) translateX(120rpx) rotate(-72deg); }
  421. 100% { transform: rotate(432deg) translateX(120rpx) rotate(-432deg); }
  422. }
  423. @keyframes orbitNode2 {
  424. 0% { transform: rotate(144deg) translateX(120rpx) rotate(-144deg); }
  425. 100% { transform: rotate(504deg) translateX(120rpx) rotate(-504deg); }
  426. }
  427. @keyframes orbitNode3 {
  428. 0% { transform: rotate(216deg) translateX(120rpx) rotate(-216deg); }
  429. 100% { transform: rotate(576deg) translateX(120rpx) rotate(-576deg); }
  430. }
  431. @keyframes orbitNode4 {
  432. 0% { transform: rotate(288deg) translateX(120rpx) rotate(-288deg); }
  433. 100% { transform: rotate(648deg) translateX(120rpx) rotate(-648deg); }
  434. }
  435. /* ===== 登录表单 ===== */
  436. .login-form {
  437. margin-top: 32rpx;
  438. }
  439. .phone-btn {
  440. width: 100%;
  441. height: 82rpx;
  442. border-radius: 24rpx;
  443. background: linear-gradient(135deg, #FFC24A 0%, #FFA726 100%);
  444. color: #14458F;
  445. font-size: calc(32rpx * var(--font-scale, 1));
  446. font-weight: 600;
  447. display: flex;
  448. flex-direction: row;
  449. align-items: center;
  450. justify-content: center;
  451. border: none;
  452. box-shadow: 0 8rpx 20rpx rgba(255, 167, 38, 0.32);
  453. }
  454. .phone-btn::after {
  455. border: none;
  456. }
  457. .phone-btn[disabled] {
  458. background: #FFEFD0 !important;
  459. color: #B57E2A !important;
  460. }
  461. .phone-btn-icon {
  462. margin-right: 8rpx;
  463. }
  464. .phone-btn-text {
  465. color: #000000;
  466. }
  467. .phone-arrows {
  468. margin-left: 10rpx;
  469. font-weight: bold;
  470. letter-spacing: 2rpx;
  471. color: #000000;
  472. animation: arrowBlink 1s ease-in-out infinite;
  473. }
  474. @keyframes arrowBlink {
  475. 0%, 100% { opacity: 1; }
  476. 50% { opacity: 0.15; }
  477. }
  478. /* ===== 暂不登录 ===== */
  479. .skip-section {
  480. display: flex;
  481. justify-content: center;
  482. margin-top: 24rpx;
  483. }
  484. .skip-btn {
  485. font-size: calc(26rpx * var(--font-scale, 1));
  486. color: $facade-text-muted;
  487. text-decoration: underline;
  488. }
  489. /* ===== 协议 ===== */
  490. .agreement {
  491. display: flex;
  492. flex-direction: row;
  493. align-items: center;
  494. justify-content: center;
  495. flex-wrap: wrap;
  496. margin-top: 24rpx;
  497. font-size: calc(24rpx * var(--font-scale, 1));
  498. color: $facade-text-muted;
  499. }
  500. .link {
  501. color: $brand-primary;
  502. }
  503. </style>