fix:多平台兼容

This commit is contained in:
2026-03-16 11:52:27 +08:00
parent b3836b8bf2
commit a79cf10bd4
18 changed files with 358 additions and 295 deletions
+15 -15
View File
@@ -131,18 +131,18 @@
}
// 微信快捷登录入口(备用,目前主流程使用一键手机号登录)
const onWeChatLogin = async () => {
try {
await checkAgreement()
await wxLogin()
uni.showToast({ title: t('auth.loginSuccess'), icon: 'success' })
await navigateAfterLogin()
} catch (error) {
if (error.message !== t('auth.pleaseAgreeToTerms')) {
uni.showToast({ title: error.message || t('auth.loginFailed'), icon: 'none' })
}
}
}
// const onWeChatLogin = async () => {
// try {
// await checkAgreement()
// await wxLogin()
// uni.showToast({ title: t('auth.loginSuccess'), icon: 'success' })
// await navigateAfterLogin()
// } catch (error) {
// if (error.message !== t('auth.pleaseAgreeToTerms')) {
// uni.showToast({ title: error.message || t('auth.loginFailed'), icon: 'none' })
// }
// }
// }
// 支付宝快捷登录入口(支付宝小程序)
const onAlipayLogin = async () => {
@@ -165,12 +165,12 @@
uni.showToast({ title: t('auth.phoneCancelled'), icon: 'none' })
return
}
console.log(e);
try {
// 先完成微信登录(/app/user/quickLogin,后端建立/查询 WECHAT_MINI 用户)
await wxLogin()
await wxLogin(e.detail.code)
// 再用微信返回的临时 code 换取手机号(后端按文档更新 phone 字段)
await getUserPhoneNumber(e.detail.code)
// await getUserPhoneNumber(e.detail.code)
uni.showToast({ title: t('auth.loginSuccess'), icon: 'success' })
await navigateAfterLogin()
} catch (error) {
+12 -2
View File
@@ -69,7 +69,8 @@
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { sendVerifyCode, loginWithCode } from '@/config/api/user.js'
import { sendVerifyCode, quickLogin } from '@/config/api/user.js'
import { appid } from '@/config/url.js'
import { fetchAndCacheCustomerPhone } from '@/util/index.js'
import { useI18n } from '@/utils/i18n.js'
@@ -163,7 +164,16 @@
try {
uni.showLoading({ title: t('common.loggingIn') })
const res = await loginWithCode(phone.value, verifyCode.value)
const res = await quickLogin({
loginType: 'SMS',
appid,
phonenumber: phone.value,
smsCode: verifyCode.value
})
if (res && res.code !== 200) {
throw new Error(res.msg || res.message || t('auth.loginFailed'))
}
// 保存token和client_id
// 兼容多种返回格式:res.data.token, res.token, res.data.access_token
+8 -1
View File
@@ -186,9 +186,16 @@
// 获取广告图片
const getBannerImages = async () => {
try {
let appPlatform;
// #ifdef MP-WEIXIN
appPlatform = 'wechat'
// #endif
// #ifdef MP-ALIPAY
appPlatform = 'ali'
// #endif
// 调用接口获取广告内容
const res = await getCurrentAdvertisement({
appPlatform: 'wechat', // 微信平台
appPlatform: appPlatform, // 微信平台
appType: 'user', // 用户端
pictureLocation:'userProfile_banner'
})