login-sheet.vue 13 KB

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