login-sheet.vue 13 KB

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