feat: 个人中心(未完成)

This commit is contained in:
dap
2024-09-03 16:46:42 +08:00
parent 450a598b30
commit 71f137eda3
12 changed files with 463 additions and 93 deletions

View File

@@ -1,3 +1,5 @@
import type { GrantType } from '@vben/common-ui';
import { useAppConfig } from '@vben/hooks';
import { requestClient } from '#/api/request';
@@ -5,16 +7,56 @@ import { requestClient } from '#/api/request';
const { clientId } = useAppConfig(import.meta.env, import.meta.env.PROD);
export namespace AuthApi {
/** 登录接口参数 */
export interface LoginParams {
code?: string;
grantType: string;
password: string;
/**
* @description: 所有登录类型都需要用到的
* @param clientId 客户端ID 这里为必填项 但是在loginApi内部处理了 所以为可选
* @param grantType 授权/登录类型
* @param tenantId 租户id
*/
export interface BaseLoginParams {
clientId?: string;
grantType: GrantType;
tenantId: string;
username: string;
uuid?: string;
}
/**
* @description: oauth登录需要用到的参数
* @param socialCode 第三方参数
* @param socialState 第三方参数
* @param source 与后端的 justauth.type.xxx的回调地址的source对应
*/
export interface OAuthLoginParams extends BaseLoginParams {
socialCode: string;
socialState: string;
source: string;
}
/**
* @description: 验证码登录需要用到的参数
* @param code 验证码 可选(未开启验证码情况)
* @param uuid 验证码ID 可选(未开启验证码情况)
* @param username 用户名
* @param password 密码
*/
export interface SimpleLoginParams extends BaseLoginParams {
code?: string;
uuid?: string;
username: string;
password: string;
}
export type LoginParams = OAuthLoginParams | SimpleLoginParams;
// /** 登录接口参数 */
// export interface LoginParams {
// code?: string;
// grantType: string;
// password: string;
// tenantId: string;
// username: string;
// uuid?: string;
// }
/** 登录接口返回值 */
export interface LoginResult {
access_token: string;
@@ -76,6 +118,41 @@ export function tenantList() {
return requestClient.get<TenantResp>('/auth/tenant/list');
}
/**
* vben的 先不删除
* @returns string[]
*/
export async function getAccessCodesApi() {
return requestClient.get<string[]>('/auth/codes');
}
/**
* 绑定第三方账号
* @param source 绑定的来源
* @returns 跳转url
*/
export function authBinding(source: string, tenantId: string) {
return requestClient.get<string>(`/auth/binding/${source}`, {
params: {
domain: window.location.host,
tenantId,
},
});
}
/**
* 取消绑定
* @param id id
*/
export function authUnbinding(id: string) {
return requestClient.deleteWithMsg<void>(`/auth/unlock/${id}`);
}
/**
* oauth授权回调
* @param data oauth授权
* @returns void
*/
export function authCallback(data: AuthApi.OAuthLoginParams) {
return requestClient.post<void>('/auth/social/callback', data);
}

View File

@@ -0,0 +1,20 @@
import type { SocialInfo } from './model';
import { requestClient } from '#/api/request';
enum Api {
root = '/system/social',
socialList = '/system/social/list',
}
/**
* 获取绑定的社交信息列表
* @returns info
*/
export function socialList() {
return requestClient.get<SocialInfo[]>(Api.socialList);
}
export function socialInfo(id: number | string) {
return requestClient.get(`${Api.root}/${id}`);
}

View File

@@ -0,0 +1,26 @@
export interface SocialInfo {
id: string;
userId: number;
tenantId: string;
authId: string;
source: string;
accessToken: string;
expireIn: number;
refreshToken: string;
openId: string;
userName: string;
nickName: string;
email: string;
avatar: string;
accessCode?: any;
unionId?: any;
scope: string;
tokenType: string;
idToken?: any;
macAlgorithm?: any;
macKey?: any;
code?: any;
oauthToken?: any;
oauthTokenSecret?: any;
createTime: string;
}