feat: 授权后token刷新保持

This commit is contained in:
duanshuwen
2025-11-18 19:40:28 +08:00
parent de272b1160
commit de412aed9c
9 changed files with 40 additions and 45 deletions

View File

@@ -1,6 +1,8 @@
import { wxLogin } from "../request/api/LoginApi";
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
import { clientId } from "@/constant/base";
import { useAppStore } from "@/store";
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
// 跳转登录
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
@@ -57,3 +59,35 @@ export const checkToken = () => {
resolve();
});
};
// 刷新token
export const refreshToken = () => {
const token = uni.getStorageSync("token");
if (!token) {
return;
}
const appStore = useAppStore();
uni.login({
provider: "weixin", //使用微信登录
success: async ({ code }) => {
console.log("refreshToken", code);
const params = {
openIdCode: [code],
grant_type: "wechat",
scope: "server",
clientId: clientId,
};
console.log("获取到的微信授权params:", JSON.stringify(params));
const response = await wxLogin(params);
if (response.access_token) {
uni.setStorageSync("token", response.access_token);
// 登录成功后,触发登录成功事件
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
}
},
});
};