login-sheet.vue 16 KB

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