From 7cdbdfe9f532a9c5b052ae843941e79f5315b70c Mon Sep 17 00:00:00 2001 From: abearxiong Date: Fri, 21 Mar 2025 22:21:54 +0800 Subject: [PATCH] feat: add login by code --- src/query-login.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/query-login.ts b/src/query-login.ts index 8257edd..4459dbe 100644 --- a/src/query-login.ts +++ b/src/query-login.ts @@ -38,7 +38,7 @@ export class QueryLogin { setQuery(query: Query) { this.query = query; } - async init() { + private async init() { await this.cache.init(); this.load = true; this.onLoad?.(); @@ -60,6 +60,20 @@ export class QueryLogin { } return res; } + /** + * 手机号登录 + * @param data + * @returns + */ + async loginByCode(data: { phone: string; code: string }) { + const res = await this.post({ path: 'sms', key: 'login', data }); + if (res.code === 200) { + const { accessToken, refreshToken } = res?.data || {}; + this.storage.setItem('token', accessToken || ''); + await this.beforeSetLoginUser({ accessToken, refreshToken }); + } + return res; + } /** * 登陆成功,需要获取用户信息进行缓存 * @param param0 @@ -82,6 +96,11 @@ export class QueryLogin { } } } + /** + * 刷新token + * @param refreshToken + * @returns + */ async queryRefreshToken(refreshToken?: string) { const _refreshToken = refreshToken || this.cache.getRefreshToken(); let data = { refreshToken: _refreshToken }; @@ -212,6 +231,11 @@ export class QueryLogin { this.cache.del(); return this.post({ key: 'logout' }); } + /** + * 检查用户名的组,这个用户是否存在 + * @param username + * @returns + */ async hasUser(username: string) { const that = this; return this.post(