feat: add query by login web wechat

This commit is contained in:
熊潇 2025-03-27 10:58:59 +08:00
parent e0bf83f062
commit 05f0373834

View File

@ -86,6 +86,32 @@ export class QueryLogin {
} }
return res; return res;
} }
async loginByWechat(data: { code: string }) {
const res = await this.post<QueryLoginResult>({ path: 'wx', key: 'open-login', code: data.code });
if (res.code === 200) {
const { accessToken, refreshToken } = res?.data || {};
this.storage.setItem('token', accessToken || '');
await this.beforeSetLoginUser({ accessToken, refreshToken });
}
return res;
}
/**
* onSuccessonError
* @param param0
*/
async checkWechat({ onSuccess, onError }: { onSuccess?: (res: QueryLoginResult) => void; onError?: (res: any) => void }) {
const url = new URL(window.location.href);
const code = url.searchParams.get('code');
const state = url.searchParams.get('state');
if (code && state) {
const res = await this.loginByWechat({ code });
if (res.code === 200) {
onSuccess?.(res.data);
} else {
onError?.(res);
}
}
}
/** /**
* *
* @param param0 * @param param0
@ -177,7 +203,7 @@ export class QueryLogin {
/** /**
* 401 401token, refreshToken不存在401 * 401 401token, refreshToken不存在401
* refetch , bug使 * refetch , bug使
* TODO: * TODO:
* @param response * @param response
* @param ctx * @param ctx
* @param opts * @param opts