| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <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">Care Family · 家庭健康成长俱乐部</text>
- </view>
- <!-- 平台简介 -->
- <view class="intro-section">
- <view class="intro-card">
- <view class="intro-title">🌏 给全家的一站式幸福提案</view>
- <view class="intro-desc">
- 围绕<span class="highlight">身、心、智、行、富</span>五个维度,用科技、智慧与温情,为您定制全生命周期解决方案。
- </view>
- <view class="dimension-tags">
- <view class="dim-tag dim-body">身 · 主动健康</view>
- <view class="dim-tag dim-mind">心 · 情绪丰盈</view>
- <view class="dim-tag dim-wisdom">智 · 赋能未来</view>
- <view class="dim-tag dim-action">行 · 知行合一</view>
- <view class="dim-tag dim-wealth">富 · 物质精神</view>
- </view>
- <view class="intro-powered">亿图腾科技出品</view>
- </view>
- </view>
- <!-- 手机号快捷登录 -->
- <view class="login-form">
- <view class="phone-section">
- <button
- class="phone-btn"
- :loading="loading"
- @click="handleWechatLogin"
- >
- <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 { wechatLogin, checkTeamInviteStatus, joinTeamByInvite, bindReferral } 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')
- }
- // 存储登录后跳转地址
- if (options.redirect) {
- this.redirectUrl = decodeURIComponent(options.redirect)
- }
- },
- 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' })
- },
- handleWechatLogin() {
- if (!this.agreed) {
- uni.showToast({ title: '请先同意用户协议', icon: 'none' })
- return
- }
- this.loading = true
- var self = this
- // 超时保护:10秒强制结束登录流程,避免 uni.login 挂死时按钮 loading 卡死
- var loginTimeout = new Promise(function(_, reject) {
- setTimeout(function() {
- reject(new Error('微信登录超时'))
- }, 10000)
- })
- Promise.race([loginTimeout, new Promise(function(resolve, reject) {
- uni.login({
- provider: 'weixin',
- success: function(loginRes) { resolve(loginRes) },
- fail: function() { reject(new Error('微信登录失败')) }
- })
- })]).then(function(loginRes) {
- // 静默登录:仅获取 openid,不强制索取手机号
- wechatLogin(loginRes.code, {
- nickname: self.nickname || '用户',
- avatar: self.avatar || ''
- }, '').then(function(res) {
- // 保存 token 和用户信息(只写一次)
- uni.setStorageSync('token', res.data.token)
- uni.setStorageSync('userId', res.data.userId)
- uni.setStorageSync('role', res.data.role)
- uni.setStorageSync('currentRole', res.data.role)
- uni.setStorageSync('isSwitchedChild', false)
- uni.setStorageSync('isSwitchedTeacher', false)
- if (res.data.openid) {
- uni.setStorageSync('openid', res.data.openid)
- }
- uni.setStorageSync('userInfo', {
- nickname: res.data.nickname,
- userId: res.data.userId
- })
- if (res.data.teacherStatus) {
- uni.setStorageSync('teacherStatus', res.data.teacherStatus)
- }
- if (res.data.teacherRejectReason) {
- uni.setStorageSync('teacherRejectReason', res.data.teacherRejectReason)
- }
- uni.showToast({ title: '登录成功', icon: 'success' })
- if (res.data.needsRoleSelect) {
- // 首次登录:跳过角色选择,默认 parent,直接进入信息补充页
- uni.redirectTo({
- url: '/pages/user-edit/user-edit?token=' + res.data.token + '&userId=' + res.data.userId + '&autoParent=true'
- })
- } else {
- self.handlePostLoginRouting()
- }
- }).catch(function(e) {
- uni.showToast({ title: e.message || '登录失败', icon: 'none' })
- self.loading = false
- })
- }).catch(function(e) {
- uni.showToast({ title: e.message || '微信登录失败', icon: 'none' })
- self.loading = false
- })
- },
- 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%, #F97316 100%);
- padding: 60rpx 40rpx;
- }
- /* ===== Logo 区 ===== */
- .logo-section {
- text-align: center;
- margin-bottom: 48rpx;
- }
- .logo {
- width: 160rpx;
- height: 160rpx;
- border-radius: 80rpx;
- background: #fff;
- }
- .app-name {
- display: block;
- font-size: 52rpx;
- font-weight: bold;
- color: #fff;
- margin-top: 20rpx;
- }
- .slogan {
- display: block;
- font-size: 26rpx;
- color: rgba(255, 255, 255, 0.8);
- margin-top: 10rpx;
- }
- /* ===== 平台简介卡片 ===== */
- .intro-section {
- margin-bottom: 48rpx;
- }
- .intro-card {
- background: rgba(255, 255, 255, 0.15);
- border: 1rpx solid rgba(255, 255, 255, 0.3);
- border-radius: 20rpx;
- padding: 32rpx 28rpx;
- backdrop-filter: blur(10px);
- }
- .intro-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #fff;
- text-align: center;
- margin-bottom: 16rpx;
- }
- .intro-desc {
- font-size: 24rpx;
- color: rgba(255, 255, 255, 0.9);
- line-height: 1.7;
- text-align: center;
- margin-bottom: 24rpx;
- }
- .intro-desc .highlight {
- color: #FFD700;
- font-weight: 600;
- }
- .dimension-tags {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- gap: 12rpx;
- margin-bottom: 20rpx;
- }
- .dim-tag {
- font-size: 22rpx;
- padding: 8rpx 16rpx;
- border-radius: 30rpx;
- background: rgba(255, 255, 255, 0.2);
- color: #fff;
- font-weight: 500;
- }
- .dim-body { background: rgba(91, 155, 213, 0.4); }
- .dim-mind { background: rgba(236, 72, 153, 0.4); }
- .dim-wisdom { background: rgba(139, 92, 246, 0.4); }
- .dim-action { background: rgba(16, 185, 129, 0.4); }
- .dim-wealth { background: rgba(245, 158, 11, 0.4); }
- .intro-powered {
- text-align: center;
- font-size: 20rpx;
- color: rgba(255, 255, 255, 0.6);
- }
- /* ===== 登录表单 ===== */
- .login-form {
- background: #fff;
- border-radius: 20rpx;
- padding: 40rpx;
- }
- .phone-section {
- margin-bottom: 32rpx;
- }
- .phone-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 10rpx;
- width: 100%;
- height: 88rpx;
- background: #07c160;
- color: #fff;
- border-radius: 44rpx;
- font-size: 32rpx;
- }
- /* ===== 跳过登录 ===== */
- .skip-section {
- text-align: center;
- margin-bottom: 20rpx;
- }
- .skip-btn {
- font-size: 28rpx;
- color: #999;
- text-decoration: underline;
- padding: 16rpx 0;
- }
- .agreement {
- margin-top: 16rpx;
- text-align: center;
- font-size: 24rpx;
- }
- .agreement-text {
- color: #666;
- }
- .link {
- color: #667eea;
- }
- .agreement-text.link {
- text-decoration: underline;
- }
- </style>
|