| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- <template>
- <view class="login-container">
- <!-- Logo 区 -->
- <view class="logo-section">
- <image class="logo" src="/static/logo.png" mode="aspectFit" @error="handleImageError"></image>
- <text class="app-name">浠艾福</text>
- <text class="slogan">给全家的一站式幸福提案</text>
- <text class="powered">亿图腾科技出品</text>
- </view>
- <!-- 角色价值说明 -->
- <view class="value-section">
- <view class="value-title">你能得到什么</view>
- <!-- 家长端 -->
- <view class="role-card role-parent">
- <view class="role-badge">
- <text class="role-badge-icon">👨👩👧</text>
- <text class="role-badge-text">家长</text>
- </view>
- <view class="role-items">
- <view class="role-item"><text class="role-item-icon">📋</text><text class="role-item-text">一键创建家庭成长计划</text></view>
- <view class="role-item"><text class="role-item-icon">📊</text><text class="role-item-text">跟踪孩子任务完成情况</text></view>
- <view class="role-item"><text class="role-item-icon">🧠</text><text class="role-item-text">预约专业心智测评</text></view>
- <view class="role-item"><text class="role-item-icon">🩺</text><text class="role-item-text">健康报告 AI 智能解析</text></view>
- </view>
- </view>
- <!-- 孩子端 -->
- <view class="role-card role-child">
- <view class="role-badge role-badge-child">
- <text class="role-badge-icon">👶</text>
- <text class="role-badge-text">孩子</text>
- </view>
- <view class="role-items">
- <view class="role-item"><text class="role-item-icon">🎯</text><text class="role-item-text">每日趣味任务挑战</text></view>
- <view class="role-item"><text class="role-item-icon">🏆</text><text class="role-item-text">积分兑换心愿奖励</text></view>
- <view class="role-item"><text class="role-item-icon">🧩</text><text class="role-item-text">专注力小游戏训练</text></view>
- </view>
- </view>
- </view>
- <!-- 五维能量 -->
- <view class="wuxing-section">
- <view class="wuxing-title">五维成长体系</view>
- <view class="wuxing-tags">
- <view class="wuxing-tag wuxing-body"><text class="wuxing-emoji">🌏</text>身·健康</view>
- <view class="wuxing-tag wuxing-mind"><text class="wuxing-emoji">🔥</text>心·情绪</view>
- <view class="wuxing-tag wuxing-wisdom"><text class="wuxing-emoji">⚡</text>智·赋能</view>
- <view class="wuxing-tag wuxing-action"><text class="wuxing-emoji">🌿</text>行·习惯</view>
- <view class="wuxing-tag wuxing-wealth"><text class="wuxing-emoji">💧</text>富·财商</view>
- </view>
- <text class="wuxing-desc">五行平衡 · 全面评估全家健康状态</text>
- </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, bindReferral, bindFamilyInviter } from '../../utils/api.js'
- export default {
- data() {
- return {
- loading: false,
- agreed: false,
- nickname: '',
- avatar: '',
- redirectUrl: ''
- }
- },
- onLoad(options) {
- options = options || {}
- // 处理家庭邀请码(新流程:仅首次注册时绑定邀请人)
- if (options.familyInviteCode) {
- uni.setStorageSync('pendingFamilyInviteCode', options.familyInviteCode)
- }
- // 兼容旧邀请码参数
- if (options.inviteCode) {
- uni.setStorageSync('inviteCode', options.inviteCode)
- uni.setStorageSync('inviteType', options.inviteType || 'family')
- }
- // 推广码
- if (options.refCode) {
- uni.setStorageSync('pendingRefCode', options.refCode)
- }
- // 存储登录后跳转地址
- 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
- // 判断是否首次注册(后端返回 needsRoleSelect 或无 familyId)
- var isNewUser = data.needsRoleSelect === true || !data.familyId
- // 处理家庭邀请码(仅首次注册时绑定邀请人)
- var familyInviteCode = uni.getStorageSync('pendingFamilyInviteCode')
- if (familyInviteCode && isNewUser) {
- // 新用户注册:绑定家庭邀请人
- self.bindFamilyInviter(familyInviteCode).then(function() {
- uni.removeStorageSync('pendingFamilyInviteCode')
- self.handlePostLoginRouting()
- }).catch(function() {
- uni.removeStorageSync('pendingFamilyInviteCode')
- self.handlePostLoginRouting()
- })
- return
- }
- // 非新用户或无家庭邀请码,清理存储并走原有流程
- if (familyInviteCode) {
- uni.removeStorageSync('pendingFamilyInviteCode')
- }
-
- if (data.needsRoleSelect) {
- uni.redirectTo({ url: '/pages/user-edit/user-edit?token=' + data.token + '&userId=' + data.userId + '&autoParent=true' })
- } else {
- self.handlePostLoginRouting()
- }
- },
- // 绑定家庭邀请人(首次注册调用)
- bindFamilyInviter: function(code) {
- var self = this
- return bindFamilyInviter(code).then(function(res) {
- if (res && res.code === 200) {
- console.log('首次注册绑定家庭邀请人成功', code)
- uni.showToast({ title: '已关联邀请家庭', icon: 'success' })
- } else if (res && res.code === 400) {
- console.log('已有邀请人,跳过绑定')
- }
- }).catch(function(e) {
- console.log('绑定家庭邀请人失败', e)
- })
- },
- 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 bindReferral(inviteCode)
- if (res && res.code === 200) {
- console.log('登录后绑定邀请码成功', inviteCode)
- } else if (res && res.code === 400) {
- console.log('用户已有邀请人,跳过绑定')
- }
- } catch (e) {
- 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(160deg, #FFF7ED 0%, #FED7AA 60%, #F97316 100%);
- padding: 48rpx 40rpx 40rpx;
- }
- /* ===== Logo 区 ===== */
- .logo-section {
- text-align: center;
- margin-bottom: 40rpx;
- }
- .logo {
- width: 120rpx;
- height: 120rpx;
- border-radius: 60rpx;
- background: #fff;
- box-shadow: 0 8rpx 32rpx rgba(249,115,22,0.2);
- }
- .app-name {
- display: block;
- font-size: 52rpx;
- font-weight: bold;
- color: #fff;
- margin-top: 16rpx;
- letter-spacing: 8rpx;
- }
- .slogan {
- display: block;
- font-size: 26rpx;
- color: rgba(255, 255, 255, 0.85);
- margin-top: 8rpx;
- }
- .powered {
- display: block;
- font-size: 20rpx;
- color: rgba(255, 255, 255, 0.55);
- margin-top: 12rpx;
- }
- /* ===== 角色价值说明 ===== */
- .value-section {
- margin-bottom: 32rpx;
- }
- .value-title {
- font-size: 28rpx;
- font-weight: 600;
- color: #fff;
- margin-bottom: 20rpx;
- padding-left: 4rpx;
- }
- .role-card {
- background: rgba(255, 255, 255, 0.92);
- border-radius: 20rpx;
- padding: 24rpx 28rpx;
- margin-bottom: 16rpx;
- box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.08);
- }
- .role-badge {
- display: inline-flex;
- align-items: center;
- gap: 8rpx;
- background: linear-gradient(135deg, #FF8C42, #FF6B2D);
- border-radius: 30rpx;
- padding: 8rpx 20rpx;
- margin-bottom: 20rpx;
- }
- .role-badge-child {
- background: linear-gradient(135deg, #FF6B9D, #FF3D7F);
- }
- .role-badge-icon {
- font-size: 28rpx;
- }
- .role-badge-text {
- font-size: 26rpx;
- font-weight: 600;
- color: #fff;
- }
- .role-items {
- display: flex;
- flex-direction: column;
- gap: 14rpx;
- }
- .role-item {
- display: flex;
- align-items: center;
- gap: 12rpx;
- }
- .role-item-icon {
- font-size: 28rpx;
- flex-shrink: 0;
- }
- .role-item-text {
- font-size: 26rpx;
- color: #374151;
- line-height: 1.5;
- }
- /* ===== 五维能量 ===== */
- .wuxing-section {
- background: rgba(255, 255, 255, 0.92);
- border-radius: 20rpx;
- padding: 28rpx;
- margin-bottom: 32rpx;
- text-align: center;
- box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.08);
- }
- .wuxing-title {
- font-size: 28rpx;
- font-weight: 600;
- color: #1F2937;
- margin-bottom: 20rpx;
- }
- .wuxing-tags {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- gap: 12rpx;
- margin-bottom: 16rpx;
- }
- .wuxing-tag {
- font-size: 24rpx;
- padding: 10rpx 20rpx;
- border-radius: 30rpx;
- color: #fff;
- font-weight: 500;
- }
- .wuxing-body { background: rgba(255, 140, 66, 0.85); }
- .wuxing-mind { background: rgba(255, 107, 157, 0.85); }
- .wuxing-wisdom { background: rgba(99, 102, 241, 0.85); }
- .wuxing-action { background: rgba(16, 185, 129, 0.85); }
- .wuxing-wealth { background: rgba(245, 158, 11, 0.85); }
- .wuxing-emoji {
- margin-right: 4rpx;
- }
- .wuxing-desc {
- font-size: 22rpx;
- color: #9CA3AF;
- }
- /* ===== 登录表单 ===== */
- .login-form {
- background: #fff;
- border-radius: 20rpx;
- padding: 40rpx;
- box-shadow: 0 4rpx 24rpx rgba(0,0,0,0.06);
- }
- .phone-section {
- margin-bottom: 28rpx;
- }
- .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: 24rpx;
- }
- .skip-btn {
- font-size: 28rpx;
- color: #F97316;
- font-weight: 500;
- padding: 12rpx 24rpx;
- background: rgba(249, 115, 22, 0.08);
- border-radius: 30rpx;
- }
- /* ===== 协议 ===== */
- .agreement {
- margin-top: 8rpx;
- text-align: center;
- font-size: 24rpx;
- line-height: 1.6;
- }
- .agreement checkbox {
- transform: scale(0.8);
- }
- .agreement-text {
- color: #9CA3AF;
- }
- .link {
- color: #5B9BD5;
- text-decoration: underline;
- }
- </style>
|