Files
YGChatCS/hooks/useGoLogin.js
2025-09-16 17:04:50 +08:00

42 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { loginAuth, bindPhone } from "@/manager/LoginManager";
// 引入base.js中的clientId
import { clientId } from "@/constant/base";
// 跳转登录
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
// 登录成功后,返回上一页
export const goBack = () => uni.navigateBack({ delta: 1 });
// 登录逻辑
export const onLogin = async (e) => {
return new Promise(async (resolve) => {
await loginAuth().then(async () => {
const { code } = e.detail;
console.info("onLogin code: ", code);
// 绑定手机号
const params = { wechatPhoneCode: code, clientId: clientId };
const res = await bindPhone(params);
if (res.data) {
resolve();
}
});
});
};
// 检测token
export const checkToken = async () => {
return new Promise((resolve) => {
const token = uni.getStorageSync("token");
if (!token) {
console.log("token不存在重新登录");
loginAuth().then(() => {
resolve();
});
return;
}
resolve();
});
};