This commit is contained in:
2025-09-25 19:35:27 +08:00
4 changed files with 21 additions and 13 deletions

View File

@@ -10,10 +10,17 @@ export const goBack = () => uni.navigateBack({ delta: 1 });
// 登录逻辑
export const onLogin = async (e) => {
return new Promise(async (resolve) => {
await loginAuth().then(async () => {
console.info("onLogin code: ", e.detail);
return new Promise(async (resolve, reject) => {
// 判断用户拒绝
if (e.detail.errno === 104) {
reject();
return;
}
await loginAuth(e).then(async () => {
const { code } = e.detail;
console.info("onLogin code: ", code);
// 绑定手机号
const params = { wechatPhoneCode: code, clientId: clientId };

View File

@@ -1,4 +1,4 @@
export const getWeChatAuthCode = () => {
export const getWeChatAuthCode = (e) => {
return new Promise((resolve, reject) => {
// 条件编译微信小程序、抖音小程序
let provider = "";
@@ -10,10 +10,16 @@ export const getWeChatAuthCode = () => {
provider = "toutiao";
// #endif
// 判断用户拒绝授权
if (e.detail.errMsg === "getPhoneNumber:fail user deny") {
reject();
return;
}
uni.login({
provider,
onlyAuthorize: true,
success: (res) => {
console.log("微信登录成功", res);
resolve(res.code);
},
fail: (err) => {

View File

@@ -8,13 +8,13 @@ import { useAppStore } from "@/store";
import { clientId } from "@/constant/base";
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
const loginAuth = () => {
const loginAuth = (e) => {
uni.setStorageSync("token", "");
const appStore = useAppStore();
appStore.setHasToken(false);
return new Promise(async (resolve, reject) => {
const openIdCode = await getWeChatAuthCode();
const openIdCode = await getWeChatAuthCode(e);
console.log("获取到的微信授权code:", openIdCode);
const params = {
openIdCode: [openIdCode],

View File

@@ -111,12 +111,7 @@ const getPhoneNumber = (e) => {
});
goBack();
})
.catch(() => {
uni.showToast({
title: "登录失败",
icon: "none",
});
});
.catch(() => {});
};
// 处理同意协议点击事件