| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- <template>
- <view class="login-container">
- <!-- 顶部品牌区 -->
- <view class="brand-section">
- <image class="logo" src="/static/logo.png" mode="aspectFit" @error="handleImageError"></image>
- <text class="app-name">浠艾福</text>
- <text class="slogan">给全家的一站式主动健康方案</text>
- </view>
- <!-- 主动健康理念 + 闭环 -->
- <view class="concept-card">
- <view class="concept-desc">
- 不等问题发生,先一步<text class="concept-highlight">识别风险 · 主动干预 · 持续评估</text>,把全家健康管理融入每一天。
- </view>
- <view class="loop-row">
- <view class="loop-pill loop-pill-indigo"><text>🔍</text><text class="loop-pill-text">提前识别</text></view>
- <text class="loop-arrow">→</text>
- <view class="loop-pill loop-pill-green"><text>🛡️</text><text class="loop-pill-text">风险管控</text></view>
- <text class="loop-arrow">→</text>
- <view class="loop-pill loop-pill-amber"><text>⚡</text><text class="loop-pill-text">主动干预</text></view>
- <text class="loop-arrow">→</text>
- <view class="loop-pill loop-pill-red"><text>📊</text><text class="loop-pill-text">效果评估</text></view>
- </view>
- </view>
- <!-- 五维标签 -->
- <view class="dims-row">
- <view class="dim-tag dim-tag-body"><text>🌏</text><text>身·健康</text></view>
- <view class="dim-tag dim-tag-wisdom"><text>⚡</text><text>智·赋能</text></view>
- <view class="dim-tag dim-tag-wealth"><text>💧</text><text>富·创富</text></view>
- <view class="dim-tag dim-tag-action"><text>🌿</text><text>行·和谐</text></view>
- <view class="dim-tag dim-tag-mind"><text>🔥</text><text>心·大爱</text></view>
- </view>
- <!-- 登录表单 -->
- <view class="login-form">
- <view class="phone-section">
- <button
- class="phone-btn"
- open-type="getPhoneNumber"
- @getphonenumber="getPhoneNumber"
- >
- <text class="phone-btn-icon">📱</text>
- <text>手机号快捷登录</text>
- </button>
- </view>
- <!-- 暂不登录 -->
- <view class="skip-section">
- <text class="skip-btn" @click="handleSkipLogin">暂不登录,先逛逛</text>
- </view>
- <view class="agreement">
- <checkbox-group @change="onAgreementChange">
- <label>
- <checkbox value="agree" :checked="agreed" />
- <text class="agreement-text">我已阅读并同意</text>
- </label>
- </checkbox-group>
- <text class="link" @click="showAgreement">《用户协议》</text>
- <text class="agreement-text">和</text>
- <text class="link" @click="showPrivacy">《隐私政策》</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { wechatPhoneLogin, checkTeamInviteStatus, joinTeamByInvite, bindReferralIfNotSelf } from '../../utils/api.js'
- export default {
- data() {
- return {
- loading: false,
- agreed: false,
- nickname: '',
- avatar: '',
- redirectUrl: ''
- }
- },
- onLoad(options) {
- // 处理邀请码
- if (options.inviteCode) {
- uni.setStorageSync('inviteCode', options.inviteCode)
- uni.setStorageSync('inviteType', options.inviteType || 'family')
- }
- // 处理推广码(refCode):来自 join.vue 的推广绑定流程
- if (options.refCode) {
- uni.setStorageSync('inviteCode', options.refCode)
- uni.setStorageSync('inviteType', '')
- }
- // 存储登录后跳转地址
- if (options.redirect) {
- this.redirectUrl = decodeURIComponent(options.redirect)
- }
- // 注意:不在 onLoad 预取 login code —— 微信 code 一次性有效(5分钟且用过即废),
- // 预取后如果用户隔几分钟再点击授权,code 已失效会报 invalid code (40029)。
- // 正确做法:getPhoneNumber 中用户点击授权时实时获取。
- },
- methods: {
- handleImageError(e) {
- console.log('Logo 加载失败,使用默认显示')
- },
- onAgreementChange(e) {
- this.agreed = e.detail.value.length > 0
- },
- showAgreement() {
- uni.navigateTo({
- url: '/pages/policy/agreement'
- })
- },
- showPrivacy() {
- uni.navigateTo({
- url: '/pages/policy/privacy'
- })
- },
- handleSkipLogin() {
- // 不登录直接进入首页
- uni.switchTab({ url: '/pages/index-home/index' })
- },
- getPhoneNumber: function(e) {
- if (!this.agreed) {
- uni.showToast({ title: '请先同意用户协议', icon: 'none' })
- return
- }
- if (!e.detail || !e.detail.code) {
- uni.showToast({ title: '授权失败,请重试', icon: 'none' })
- return
- }
- var self = this
- self.loading = true
- // 点击授权时实时获取 login code(微信 code 一次性有效,不能复用旧 code)
- uni.login({
- provider: 'weixin',
- success: function(loginRes) {
- if (!loginRes.code) {
- uni.showToast({ title: '网络异常,请重试', icon: 'none' })
- self.loading = false
- return
- }
- wechatPhoneLogin({ code: loginRes.code, phoneCode: e.detail.code }).then(function(res) {
- self.completeLogin(res.data)
- }).catch(function(err) {
- uni.showToast({ title: err.message || '登录失败', icon: 'none' })
- self.loading = false
- })
- },
- fail: function() {
- uni.showToast({ title: '网络异常,请重试', icon: 'none' })
- self.loading = false
- }
- })
- },
- completeLogin: function(data) {
- var self = this
- uni.setStorageSync('token', data.token)
- uni.setStorageSync('userId', data.userId)
- uni.setStorageSync('role', data.role)
- uni.setStorageSync('currentRole', data.role)
- uni.setStorageSync('isSwitchedChild', false)
- uni.setStorageSync('isSwitchedTeacher', false)
- if (data.openid) uni.setStorageSync('openid', data.openid)
- // familyId 必须持久化:家庭在注册时已由后端创建,缺失会导致页面误判无家庭而重复创建
- uni.setStorageSync('userInfo', { nickname: data.nickname, userId: data.userId, familyId: data.familyId })
- if (data.phone) uni.setStorageSync('phone', data.phone)
- if (data.teacherStatus) uni.setStorageSync('teacherStatus', data.teacherStatus)
- if (data.teacherRejectReason) uni.setStorageSync('teacherRejectReason', data.teacherRejectReason)
- self.$store.commit('setFamilyId', data.familyId)
- uni.showToast({ title: '登录成功', icon: 'success' })
- self.loading = false
- // 新用户,或存在待加入的家庭邀请(join.vue 已写入 pendingFamilyInviteCode):
- // 都进入个人信息完善页,填写家庭身份并提交加入申请
- var hasPendingFamilyInvite = !!uni.getStorageSync('pendingFamilyInviteCode')
- if (data.needsRoleSelect || hasPendingFamilyInvite) {
- uni.redirectTo({ url: '/pages/user-edit/user-edit?token=' + data.token + '&userId=' + data.userId + '&autoParent=true' })
- } else {
- self.handlePostLoginRouting()
- }
- },
- handlePostLoginRouting() {
- const inviteCode = uni.getStorageSync('inviteCode')
- const inviteType = uni.getStorageSync('inviteType')
- if (inviteCode && inviteType === 'team') {
- this.handleTeamInviteFlow(inviteCode)
- } else if (inviteCode) {
- // 非 team 邀请码(如分享文章/商品/活动的邀请码),绑定推荐关系
- this.handleReferralBind(inviteCode)
- } else {
- this.navigateToHome()
- }
- },
- async handleReferralBind(inviteCode) {
- try {
- var res = await bindReferralIfNotSelf(inviteCode)
- if (res && res.code === 200) {
- console.log('登录后绑定邀请码成功', inviteCode)
- }
- } catch (e) {
- // 后端 Result.error(code=500) → request() 已 toast「已绑定推荐人,不可修改」等业务消息
- if (e && e.code !== undefined && e.code !== 401) {
- console.log('登录后邀请码业务拒绝', inviteCode, e.message || '')
- } else {
- console.log('登录后邀请码绑定失败', e)
- }
- }
- uni.removeStorageSync('inviteCode')
- uni.removeStorageSync('inviteType')
- this.navigateToHome()
- },
- async handleTeamInviteFlow(inviteCode) {
- try {
- const res = await checkTeamInviteStatus(inviteCode)
- const status = res.data.status
- if (status === 'not_planner') {
- uni.redirectTo({ url: `/pages/guide/register/index?inviteCode=${inviteCode}` })
- } else if (status === 'not_in_team') {
- uni.showModal({
- title: '加入团队',
- content: '是否加入该规划师团队?',
- success: async (confirmRes) => {
- if (confirmRes.confirm) {
- try {
- await joinTeamByInvite(inviteCode)
- uni.showToast({ title: '加入成功', icon: 'success' })
- uni.removeStorageSync('inviteCode')
- uni.removeStorageSync('inviteType')
- this.navigateToHome()
- } catch (e) {
- uni.showToast({ title: e.message || '加入失败', icon: 'none' })
- }
- } else {
- this.navigateToHome()
- }
- }
- })
- } else if (status === 'already_in_team') {
- uni.showModal({
- title: '加入新团队',
- content: '您已在其他团队中,离开当前团队并加入新团队?',
- success: async (confirmRes) => {
- if (confirmRes.confirm) {
- try {
- await joinTeamByInvite(inviteCode)
- uni.showToast({ title: '加入成功', icon: 'success' })
- uni.removeStorageSync('inviteCode')
- uni.removeStorageSync('inviteType')
- this.navigateToHome()
- } catch (e) {
- uni.showToast({ title: e.message || '加入失败', icon: 'none' })
- }
- } else {
- this.navigateToHome()
- }
- }
- })
- } else {
- this.navigateToHome()
- }
- } catch (e) {
- uni.showToast({ title: e.message || '处理邀请失败', icon: 'none' })
- this.navigateToHome()
- }
- },
- navigateToHome() {
- if (this.redirectUrl) {
- const redirect = this.redirectUrl
- this.redirectUrl = ''
- // 注意: redirectTo 不支持跳转 tabBar 页面,必须用 switchTab
- // 只有 pages.json tabBar.list 注册的页面才能用 switchTab
- var tabBarPages = ['/pages/index-home/index', '/pages/mind/index', '/pages/body/index', '/pages/wisdom/index', '/pages/wealth/index']
- if (tabBarPages.indexOf(redirect) !== -1) {
- uni.switchTab({ url: redirect })
- } else {
- uni.redirectTo({ url: redirect })
- }
- } else {
- uni.switchTab({ url: '/pages/index-home/index' })
- }
- }
- }
- }
- </script>
- <style scoped>
- .login-container {
- min-height: 100vh;
- background: linear-gradient(180deg, #FFF9F0 0%, #FFEEDB 100%);
- padding: 40rpx 36rpx 32rpx;
- display: flex;
- flex-direction: column;
- }
- /* ===== 顶部品牌区 ===== */
- .brand-section {
- text-align: center;
- margin-bottom: 32rpx;
- }
- .logo {
- width: 104rpx;
- height: 104rpx;
- border-radius: 52rpx;
- background: #fff;
- box-shadow: 0 8rpx 24rpx rgba(249,115,22,0.2);
- }
- .app-name {
- display: block;
- font-size: 44rpx;
- font-weight: bold;
- color: #7C2D12;
- margin-top: 14rpx;
- letter-spacing: 6rpx;
- }
- .slogan {
- display: block;
- font-size: 24rpx;
- color: #9A3412;
- margin-top: 8rpx;
- }
- /* ===== 主动健康理念 + 闭环 ===== */
- .concept-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 26rpx 28rpx;
- margin-bottom: 24rpx;
- box-shadow: 0 4rpx 16rpx rgba(249,115,22,0.08);
- }
- .concept-desc {
- font-size: 24rpx;
- color: #4B5563;
- line-height: 1.6;
- margin-bottom: 20rpx;
- }
- .concept-highlight {
- color: #B45309;
- font-weight: 600;
- }
- .loop-row {
- display: flex;
- align-items: center;
- gap: 6rpx;
- }
- .loop-pill {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 4rpx;
- flex-direction: column;
- font-size: 20rpx;
- padding: 10rpx 4rpx;
- border-radius: 12rpx;
- line-height: 1.3;
- }
- .loop-pill-text {
- font-size: 20rpx;
- font-weight: 500;
- }
- .loop-pill-indigo { background: #EEF2FF; color: #4F46E5; }
- .loop-pill-green { background: #D1FAE5; color: #047857; }
- .loop-pill-amber { background: #FEF3C7; color: #B45309; }
- .loop-pill-red { background: #FEE2E2; color: #B91C1C; }
- .loop-arrow {
- font-size: 24rpx;
- color: #D1D5DB;
- flex-shrink: 0;
- }
- /* ===== 五维标签 ===== */
- .dims-row {
- display: flex;
- justify-content: center;
- gap: 8rpx;
- margin-bottom: 24rpx;
- flex-wrap: wrap;
- }
- .dim-tag {
- display: flex;
- align-items: center;
- gap: 4rpx;
- font-size: 20rpx;
- color: #fff;
- font-weight: 500;
- padding: 8rpx 14rpx;
- border-radius: 24rpx;
- white-space: nowrap;
- }
- .dim-tag-body { background: #F97316; }
- .dim-tag-wisdom { background: #6366F1; }
- .dim-tag-wealth { background: #D97706; }
- .dim-tag-action { background: #10B981; }
- .dim-tag-mind { background: #EC4899; }
- /* ===== 登录表单 ===== */
- .login-form {
- background: #fff;
- border-radius: 20rpx;
- padding: 36rpx 36rpx 28rpx;
- margin-top: 48rpx;
- box-shadow: 0 4rpx 24rpx rgba(0,0,0,0.06);
- }
- .phone-section {
- margin-bottom: 24rpx;
- }
- .phone-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 12rpx;
- width: 100%;
- height: 88rpx;
- background: #07c160;
- color: #fff;
- border-radius: 44rpx;
- font-size: 32rpx;
- font-weight: 500;
- border: none;
- }
- .phone-btn::after {
- border: none;
- }
- .phone-btn-icon {
- font-size: 36rpx;
- }
- /* ===== 跳过登录 ===== */
- .skip-section {
- text-align: center;
- margin-bottom: 20rpx;
- }
- .skip-btn {
- font-size: 26rpx;
- color: #F97316;
- font-weight: 500;
- padding: 10rpx 20rpx;
- background: rgba(249, 115, 22, 0.08);
- border-radius: 30rpx;
- }
- /* ===== 协议 ===== */
- .agreement {
- margin-top: 4rpx;
- text-align: center;
- font-size: 22rpx;
- line-height: 1.6;
- }
- .agreement checkbox {
- transform: scale(0.8);
- }
- .agreement-text {
- color: #9CA3AF;
- }
- .link {
- color: #5B9BD5;
- text-decoration: underline;
- }
- </style>
|