Compare commits
No commits in common. "9c3775624f149ab47384b7460fcc4d1c37349d72" and "a63fdd91d39e89078dca4c31039cd185841a9f1e" have entirely different histories.
9c3775624f
...
a63fdd91d3
@ -5,12 +5,6 @@ export function wechatLogin(code, invite_code) {
|
|||||||
return request({ url: '/api/app/users/weixin/login', method: 'POST', data })
|
return request({ url: '/api/app/users/weixin/login', method: 'POST', data })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 抖音小程序登录
|
|
||||||
export function toutiaoLogin(code, invite_code) {
|
|
||||||
const data = invite_code ? { code, invite_code } : { code }
|
|
||||||
return request({ url: '/api/app/users/toutiao/login', method: 'POST', data })
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 短信登录 API
|
// 短信登录 API
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|||||||
@ -17,26 +17,15 @@
|
|||||||
<view class="login-card glass-card">
|
<view class="login-card glass-card">
|
||||||
<!-- 切换Tab -->
|
<!-- 切换Tab -->
|
||||||
<view class="tab-bar">
|
<view class="tab-bar">
|
||||||
<!-- #ifdef MP-WEIXIN -->
|
<view
|
||||||
<view
|
class="tab-item"
|
||||||
class="tab-item"
|
|
||||||
:class="{ active: loginMode === 'wechat' }"
|
:class="{ active: loginMode === 'wechat' }"
|
||||||
@tap="switchMode('wechat')"
|
@tap="switchMode('wechat')"
|
||||||
>
|
>
|
||||||
<text class="tab-text">微信快捷登录</text>
|
<text class="tab-text">手机号快捷登录</text>
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
<view
|
||||||
<!-- #ifdef MP-TOUTIAO -->
|
class="tab-item"
|
||||||
<view
|
|
||||||
class="tab-item"
|
|
||||||
:class="{ active: loginMode === 'toutiao' }"
|
|
||||||
@tap="switchMode('toutiao')"
|
|
||||||
>
|
|
||||||
<text class="tab-text">抖音快捷登录</text>
|
|
||||||
</view>
|
|
||||||
<!-- #endif -->
|
|
||||||
<view
|
|
||||||
class="tab-item"
|
|
||||||
:class="{ active: loginMode === 'sms' }"
|
:class="{ active: loginMode === 'sms' }"
|
||||||
@tap="switchMode('sms')"
|
@tap="switchMode('sms')"
|
||||||
>
|
>
|
||||||
@ -48,7 +37,6 @@
|
|||||||
<!-- 内容区域 -->
|
<!-- 内容区域 -->
|
||||||
<view class="content-area">
|
<view class="content-area">
|
||||||
<!-- 微信登录 -->
|
<!-- 微信登录 -->
|
||||||
<!-- #ifdef MP-WEIXIN -->
|
|
||||||
<view v-if="loginMode === 'wechat'" class="login-panel wechat-panel">
|
<view v-if="loginMode === 'wechat'" class="login-panel wechat-panel">
|
||||||
<view class="panel-icon-wrap">
|
<view class="panel-icon-wrap">
|
||||||
<view class="panel-icon wechat-icon">
|
<view class="panel-icon wechat-icon">
|
||||||
@ -57,39 +45,24 @@
|
|||||||
</view>
|
</view>
|
||||||
<text class="panel-title">一键获取手机号</text>
|
<text class="panel-title">一键获取手机号</text>
|
||||||
<text class="panel-desc">授权获取本机手机号,安全快速登录</text>
|
<text class="panel-desc">授权获取本机手机号,安全快速登录</text>
|
||||||
|
|
||||||
<button
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
|
<button
|
||||||
class="btn-primary btn-login"
|
class="btn-primary btn-login"
|
||||||
open-type="getPhoneNumber"
|
open-type="getPhoneNumber"
|
||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
@getphonenumber="onGetPhoneNumber"
|
@getphonenumber="onGetPhoneNumber"
|
||||||
>
|
>
|
||||||
{{ loading ? '获取中...' : '一键获取手机号' }}
|
{{ loading ? '获取中...' : '一键获取手机号' }}
|
||||||
</button>
|
</button>
|
||||||
</view>
|
<!-- #endif -->
|
||||||
<!-- #endif -->
|
|
||||||
|
<!-- #ifndef MP-WEIXIN -->
|
||||||
<!-- 抖音登录 -->
|
<button class="btn-primary btn-login" disabled>
|
||||||
<!-- #ifdef MP-TOUTIAO -->
|
当前环境不支持
|
||||||
<view v-if="loginMode === 'toutiao'" class="login-panel toutiao-panel">
|
|
||||||
<view class="panel-icon-wrap">
|
|
||||||
<view class="panel-icon toutiao-icon">
|
|
||||||
<text class="icon-emoji">🎵</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
<text class="panel-title">一键获取手机号</text>
|
|
||||||
<text class="panel-desc">授权获取本机手机号,安全快速登录</text>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="btn-primary btn-login"
|
|
||||||
open-type="getPhoneNumber"
|
|
||||||
:disabled="loading"
|
|
||||||
@getphonenumber="onToutiaoGetPhoneNumber"
|
|
||||||
>
|
|
||||||
{{ loading ? '获取中...' : '一键获取手机号' }}
|
|
||||||
</button>
|
</button>
|
||||||
|
<!-- #endif -->
|
||||||
</view>
|
</view>
|
||||||
<!-- #endif -->
|
|
||||||
|
|
||||||
<!-- 短信登录 -->
|
<!-- 短信登录 -->
|
||||||
<view v-else class="login-panel sms-panel">
|
<view v-else class="login-panel sms-panel">
|
||||||
@ -175,31 +148,21 @@
|
|||||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { request } from '../../utils/request'
|
import { request } from '../../utils/request'
|
||||||
import { wechatLogin, toutiaoLogin, bindPhone, getUserStats, getPointsBalance, sendSmsCode, smsLogin } from '../../api/appUser'
|
import { wechatLogin, bindPhone, getUserStats, getPointsBalance, sendSmsCode, smsLogin } from '../../api/appUser'
|
||||||
import { vibrateShort } from '@/utils/vibrate.js'
|
import { vibrateShort } from '@/utils/vibrate.js'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const agreementChecked = ref(false)
|
const agreementChecked = ref(false)
|
||||||
|
|
||||||
// 登录模式:根据平台设置默认值
|
// 登录模式
|
||||||
// #ifdef MP-WEIXIN
|
|
||||||
const loginMode = ref('wechat')
|
const loginMode = ref('wechat')
|
||||||
// #endif
|
|
||||||
// #ifdef MP-TOUTIAO
|
|
||||||
const loginMode = ref('toutiao')
|
|
||||||
// #endif
|
|
||||||
// #ifndef MP-WEIXIN || MP-TOUTIAO
|
|
||||||
const loginMode = ref('sms')
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// 静默获取 OpenID
|
// 静默获取 OpenID
|
||||||
async function ensureOpenID() {
|
async function ensureOpenID() {
|
||||||
const current = uni.getStorageSync('openid')
|
const current = uni.getStorageSync('openid')
|
||||||
if (current) return
|
if (current) return
|
||||||
|
|
||||||
console.log('[DEBUG] 本地缺少 openid, 尝试静默获取...')
|
console.log('[DEBUG] 本地缺少 openid, 尝试静默获取...')
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: 'weixin',
|
provider: 'weixin',
|
||||||
success: async (loginRes) => {
|
success: async (loginRes) => {
|
||||||
@ -218,28 +181,6 @@ async function ensureOpenID() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// #endif
|
|
||||||
|
|
||||||
// #ifdef MP-TOUTIAO
|
|
||||||
uni.login({
|
|
||||||
provider: 'toutiao',
|
|
||||||
success: async (loginRes) => {
|
|
||||||
try {
|
|
||||||
const res = await request({
|
|
||||||
url: '/api/app/common/openid',
|
|
||||||
method: 'POST',
|
|
||||||
data: { code: loginRes.code, platform: 'toutiao' }
|
|
||||||
})
|
|
||||||
if (res && res.openid) {
|
|
||||||
console.log('[DEBUG] 静默获取 openid 成功:', res.openid)
|
|
||||||
uni.setStorageSync('openid', res.openid)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[DEBUG] 静默获取 openid 失败:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// #endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
@ -378,24 +319,24 @@ function onGetPhoneNumber(e) {
|
|||||||
vibrateShort()
|
vibrateShort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const phoneCode = e.detail.code
|
const phoneCode = e.detail.code
|
||||||
if (!phoneCode) {
|
if (!phoneCode) {
|
||||||
uni.showToast({ title: '需要授权手机号', icon: 'none' })
|
uni.showToast({ title: '需要授权手机号', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: 'weixin',
|
provider: 'weixin',
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
try {
|
try {
|
||||||
const inviterCode = uni.getStorageSync('inviter_code')
|
const inviterCode = uni.getStorageSync('inviter_code')
|
||||||
const data = await wechatLogin(res.code, inviterCode)
|
const data = await wechatLogin(res.code, inviterCode)
|
||||||
|
|
||||||
saveUserData(data)
|
saveUserData(data)
|
||||||
|
|
||||||
// 绑定手机号 (仅当后端反馈未绑定时调用)
|
// 绑定手机号 (仅当后端反馈未绑定时调用)
|
||||||
const isBound = data.phone || data.phone_number || data.mobile
|
const isBound = data.phone || data.phone_number || data.mobile
|
||||||
if (!isBound) {
|
if (!isBound) {
|
||||||
@ -403,60 +344,10 @@ function onGetPhoneNumber(e) {
|
|||||||
await bindPhone(data.user_id, phoneCode)
|
await bindPhone(data.user_id, phoneCode)
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 后台获取数据
|
// 后台获取数据
|
||||||
fetchExtraData(data.user_id)
|
fetchExtraData(data.user_id)
|
||||||
|
|
||||||
uni.showToast({ title: '✨ 登录成功!', icon: 'none', duration: 1200 })
|
|
||||||
setTimeout(() => uni.reLaunch({ url: '/pages/mine/index' }), 600)
|
|
||||||
} catch (err) {
|
|
||||||
uni.showToast({ title: err.message || '登录失败', icon: 'none' })
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: () => {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 抖音登录
|
|
||||||
function onToutiaoGetPhoneNumber(e) {
|
|
||||||
if (!agreementChecked.value) {
|
|
||||||
uni.showToast({ title: '请先同意用户协议', icon: 'none' })
|
|
||||||
vibrateShort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const phoneCode = e.detail.code
|
|
||||||
if (!phoneCode) {
|
|
||||||
uni.showToast({ title: '需要授权手机号', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
loading.value = true
|
|
||||||
|
|
||||||
uni.login({
|
|
||||||
provider: 'toutiao',
|
|
||||||
success: async (res) => {
|
|
||||||
try {
|
|
||||||
const inviterCode = uni.getStorageSync('inviter_code')
|
|
||||||
const data = await toutiaoLogin(res.code, inviterCode)
|
|
||||||
|
|
||||||
saveUserData(data)
|
|
||||||
|
|
||||||
// 绑定手机号 (仅当后端反馈未绑定时调用)
|
|
||||||
const isBound = data.phone || data.phone_number || data.mobile
|
|
||||||
if (!isBound) {
|
|
||||||
try {
|
|
||||||
await bindPhone(data.user_id, phoneCode)
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 后台获取数据
|
|
||||||
fetchExtraData(data.user_id)
|
|
||||||
|
|
||||||
uni.showToast({ title: '✨ 登录成功!', icon: 'none', duration: 1200 })
|
uni.showToast({ title: '✨ 登录成功!', icon: 'none', duration: 1200 })
|
||||||
setTimeout(() => uni.reLaunch({ url: '/pages/mine/index' }), 600)
|
setTimeout(() => uni.reLaunch({ url: '/pages/mine/index' }), 600)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -636,11 +527,11 @@ function fetchExtraData(userId) {
|
|||||||
.wechat-panel {
|
.wechat-panel {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding-top: 32rpx;
|
padding-top: 32rpx;
|
||||||
|
|
||||||
.panel-icon-wrap {
|
.panel-icon-wrap {
|
||||||
margin-bottom: 32rpx;
|
margin-bottom: 32rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-icon {
|
.panel-icon {
|
||||||
width: 120rpx;
|
width: 120rpx;
|
||||||
height: 120rpx;
|
height: 120rpx;
|
||||||
@ -648,29 +539,24 @@ function fetchExtraData(userId) {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
&.wechat-icon {
|
&.wechat-icon {
|
||||||
background: linear-gradient(135deg, #07c160 0%, #06ad56 100%);
|
background: linear-gradient(135deg, #07c160 0%, #06ad56 100%);
|
||||||
box-shadow: 0 12rpx 32rpx rgba(7, 193, 96, 0.3);
|
box-shadow: 0 12rpx 32rpx rgba(7, 193, 96, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.toutiao-icon {
|
|
||||||
background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
|
|
||||||
box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
.icon-emoji {
|
.icon-emoji {
|
||||||
font-size: 56rpx;
|
font-size: 56rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-title {
|
.panel-title {
|
||||||
font-size: 36rpx;
|
font-size: 36rpx;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: $text-main;
|
color: $text-main;
|
||||||
margin-bottom: 12rpx;
|
margin-bottom: 12rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-desc {
|
.panel-desc {
|
||||||
font-size: 26rpx;
|
font-size: 26rpx;
|
||||||
color: $text-sub;
|
color: $text-sub;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user