login-sheet.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. this.$nextTick(() => {
  120. setTimeout(() => {
  121. this.panelShow = true
  122. }, 10)
  123. })
  124. },
  125. close() {
  126. this.panelShow = false
  127. setTimeout(() => {
  128. this.visible = false
  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: 9999;
  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: 85vh;
  250. max-height: 85vh;
  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-section {
  285. display: flex;
  286. flex-direction: column;
  287. align-items: center;
  288. padding: 24rpx 0 8rpx;
  289. }
  290. .logo {
  291. width: 128rpx;
  292. height: 128rpx;
  293. border-radius: 24rpx;
  294. }
  295. .app-name {
  296. font-size: calc(44rpx * var(--font-scale, 1));
  297. font-weight: bold;
  298. color: $facade-text-strong;
  299. margin-top: 16rpx;
  300. }
  301. .identity {
  302. font-size: calc(26rpx * var(--font-scale, 1));
  303. color: $brand-primary;
  304. margin-top: 8rpx;
  305. }
  306. .slogan {
  307. font-size: calc(24rpx * var(--font-scale, 1));
  308. color: $facade-text-muted;
  309. margin-top: 12rpx;
  310. text-align: center;
  311. }
  312. /* ===== 理念卡 ===== */
  313. .concept-card {
  314. background: rgba(249, 115, 22, 0.08);
  315. border-radius: 24rpx;
  316. padding: 24rpx;
  317. margin-top: 28rpx;
  318. }
  319. .concept-desc {
  320. font-size: calc(26rpx * var(--font-scale, 1));
  321. color: $facade-text-deep;
  322. line-height: 1.6;
  323. }
  324. .concept-highlight {
  325. color: $brand-primary;
  326. font-weight: 600;
  327. }
  328. .loop-row {
  329. display: flex;
  330. flex-direction: row;
  331. align-items: center;
  332. justify-content: space-between;
  333. margin-top: 16rpx;
  334. flex-wrap: nowrap; /* 禁止换行,确保四步/五维在一行 */
  335. margin-bottom: 16rpx;
  336. }
  337. .loop-pill {
  338. display: flex;
  339. flex-direction: row;
  340. align-items: center;
  341. border-radius: 999rpx;
  342. padding: 6rpx 12rpx;
  343. font-size: calc(22rpx * var(--font-scale, 1));
  344. flex-shrink: 0; /* 防止被压缩导致文本换行 */
  345. white-space: nowrap;
  346. }
  347. .loop-pill-indigo { background: rgba(99, 102, 241, 0.12); color: $dim-wisdom; }
  348. .loop-pill-green { background: rgba(16, 185, 129, 0.12); color: $status-success; }
  349. .loop-pill-amber { background: rgba(245, 158, 11, 0.12); color: $dim-wealth; }
  350. .loop-pill-red { background: rgba(239, 68, 68, 0.12); color: $status-danger; }
  351. .loop-pill-text {
  352. margin-left: 4rpx;
  353. white-space: nowrap; /* 禁止四字步骤文本换行 */
  354. }
  355. .loop-arrow {
  356. font-size: calc(24rpx * var(--font-scale, 1));
  357. color: $facade-text-ghost-light;
  358. padding: 0 2rpx;
  359. flex-shrink: 0; /* 箭头不被压缩 */
  360. }
  361. /* ===== 五维标签 ===== */
  362. .dims-row {
  363. display: flex;
  364. flex-direction: row;
  365. justify-content: center;
  366. align-items: center;
  367. flex-wrap: nowrap; /* 禁止换行,保持五维维度在一行 */
  368. margin-top: 24rpx;
  369. padding: 0 32rpx; /* 左右留白,避免贴边 */
  370. box-sizing: border-box;
  371. }
  372. .dim-tag {
  373. display: flex;
  374. flex-direction: row;
  375. align-items: center;
  376. border-radius: 999rpx;
  377. padding: 8rpx 14rpx;
  378. font-size: calc(22rpx * var(--font-scale, 1));
  379. color: $app-surface;
  380. margin: 0 8rpx; /* 使用 margin 替代 gap,微信小程序不支持 gap */
  381. white-space: nowrap;
  382. }
  383. .dim-tag-body { background: $status-success; }
  384. .dim-tag-wisdom { background: $dim-wisdom; }
  385. .dim-tag-wealth { background: $dim-wealth; }
  386. .dim-tag-action { background: #14b8a6; }
  387. .dim-tag-mind { background: $status-danger; }
  388. /* ===== 登录表单 ===== */
  389. .login-form {
  390. margin-top: 32rpx;
  391. }
  392. .phone-btn {
  393. width: 100%;
  394. height: 96rpx;
  395. border-radius: 24rpx;
  396. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  397. color: $app-surface;
  398. font-size: calc(32rpx * var(--font-scale, 1));
  399. font-weight: 600;
  400. display: flex;
  401. flex-direction: row;
  402. align-items: center;
  403. justify-content: center;
  404. border: none;
  405. }
  406. .phone-btn::after {
  407. border: none;
  408. }
  409. .phone-btn[disabled] {
  410. background: #e0d8cc !important;
  411. color: $text-ghost-soft !important;
  412. }
  413. .phone-btn-icon {
  414. margin-right: 8rpx;
  415. }
  416. /* ===== 暂不登录 ===== */
  417. .skip-section {
  418. display: flex;
  419. justify-content: center;
  420. margin-top: 24rpx;
  421. }
  422. .skip-btn {
  423. font-size: calc(26rpx * var(--font-scale, 1));
  424. color: $facade-text-muted;
  425. text-decoration: underline;
  426. }
  427. /* ===== 协议 ===== */
  428. .agreement {
  429. display: flex;
  430. flex-direction: row;
  431. align-items: center;
  432. justify-content: center;
  433. flex-wrap: wrap;
  434. margin-top: 24rpx;
  435. font-size: calc(24rpx * var(--font-scale, 1));
  436. color: $facade-text-muted;
  437. }
  438. .link {
  439. color: $brand-primary;
  440. }
  441. </style>