login-sheet.vue 13 KB

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