feat: add login by code
This commit is contained in:
parent
cdc92fa9b8
commit
7cdbdfe9f5
@ -38,7 +38,7 @@ export class QueryLogin {
|
|||||||
setQuery(query: Query) {
|
setQuery(query: Query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
}
|
}
|
||||||
async init() {
|
private async init() {
|
||||||
await this.cache.init();
|
await this.cache.init();
|
||||||
this.load = true;
|
this.load = true;
|
||||||
this.onLoad?.();
|
this.onLoad?.();
|
||||||
@ -60,6 +60,20 @@ export class QueryLogin {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 手机号登录
|
||||||
|
* @param data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async loginByCode(data: { phone: string; code: string }) {
|
||||||
|
const res = await this.post<QueryLoginResult>({ 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
|
* @param param0
|
||||||
@ -82,6 +96,11 @@ export class QueryLogin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 刷新token
|
||||||
|
* @param refreshToken
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
async queryRefreshToken(refreshToken?: string) {
|
async queryRefreshToken(refreshToken?: string) {
|
||||||
const _refreshToken = refreshToken || this.cache.getRefreshToken();
|
const _refreshToken = refreshToken || this.cache.getRefreshToken();
|
||||||
let data = { refreshToken: _refreshToken };
|
let data = { refreshToken: _refreshToken };
|
||||||
@ -212,6 +231,11 @@ export class QueryLogin {
|
|||||||
this.cache.del();
|
this.cache.del();
|
||||||
return this.post<Result>({ key: 'logout' });
|
return this.post<Result>({ key: 'logout' });
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 检查用户名的组,这个用户是否存在
|
||||||
|
* @param username
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
async hasUser(username: string) {
|
async hasUser(username: string) {
|
||||||
const that = this;
|
const that = this;
|
||||||
return this.post<Result>(
|
return this.post<Result>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user