feat: 完善 ele 的请求、路由、百度统计、概览、登录

This commit is contained in:
puhui999
2025-05-09 17:57:44 +08:00
parent 61dc7a45a1
commit 0155198f4e
88 changed files with 5563 additions and 699 deletions

View File

@@ -0,0 +1,57 @@
import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request';
export namespace SystemOAuth2ClientApi {
/** OAuth2.0 客户端信息 */
export interface OAuth2Client {
id?: number;
clientId: string;
secret: string;
name: string;
logo: string;
description: string;
status: number;
accessTokenValiditySeconds: number;
refreshTokenValiditySeconds: number;
redirectUris: string[];
autoApprove: boolean;
authorizedGrantTypes: string[];
scopes: string[];
authorities: string[];
resourceIds: string[];
additionalInformation: string;
isAdditionalInformationJson: boolean;
createTime?: Date;
}
}
/** 查询 OAuth2.0 客户端列表 */
export function getOAuth2ClientPage(params: PageParam) {
return requestClient.get<PageResult<SystemOAuth2ClientApi.OAuth2Client>>(
'/system/oauth2-client/page',
{ params },
);
}
/** 查询 OAuth2.0 客户端详情 */
export function getOAuth2Client(id: number) {
return requestClient.get<SystemOAuth2ClientApi.OAuth2Client>(
`/system/oauth2-client/get?id=${id}`,
);
}
/** 新增 OAuth2.0 客户端 */
export function createOAuth2Client(data: SystemOAuth2ClientApi.OAuth2Client) {
return requestClient.post('/system/oauth2-client/create', data);
}
/** 修改 OAuth2.0 客户端 */
export function updateOAuth2Client(data: SystemOAuth2ClientApi.OAuth2Client) {
return requestClient.put('/system/oauth2-client/update', data);
}
/** 删除 OAuth2.0 客户端 */
export function deleteOAuth2Client(id: number) {
return requestClient.delete(`/system/oauth2-client/delete?id=${id}`);
}

View File

@@ -0,0 +1,58 @@
import { requestClient } from '#/api/request';
/** OAuth2.0 授权信息响应 */
export namespace SystemOAuth2ClientApi {
/** 授权信息 */
export interface AuthorizeInfoRespVO {
client: {
logo: string;
name: string;
};
scopes: {
key: string;
value: boolean;
}[];
}
}
/** 获得授权信息 */
export function getAuthorize(clientId: string) {
return requestClient.get<SystemOAuth2ClientApi.AuthorizeInfoRespVO>(
`/system/oauth2/authorize?clientId=${clientId}`,
);
}
/** 发起授权 */
export function authorize(
responseType: string,
clientId: string,
redirectUri: string,
state: string,
autoApprove: boolean,
checkedScopes: string[],
uncheckedScopes: string[],
) {
// 构建 scopes
const scopes: Record<string, boolean> = {};
for (const scope of checkedScopes) {
scopes[scope] = true;
}
for (const scope of uncheckedScopes) {
scopes[scope] = false;
}
// 发起请求
return requestClient.post<string>('/system/oauth2/authorize', null, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
params: {
response_type: responseType,
client_id: clientId,
redirect_uri: redirectUri,
state,
auto_approve: autoApprove,
scope: JSON.stringify(scopes),
},
});
}

View File

@@ -0,0 +1,34 @@
import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request';
export namespace SystemOAuth2TokenApi {
/** OAuth2.0 令牌信息 */
export interface OAuth2Token {
id?: number;
accessToken: string;
refreshToken: string;
userId: number;
userType: number;
clientId: string;
createTime?: Date;
expiresTime?: Date;
}
}
/** 查询 OAuth2.0 令牌列表 */
export function getOAuth2TokenPage(params: PageParam) {
return requestClient.get<PageResult<SystemOAuth2TokenApi.OAuth2Token>>(
'/system/oauth2-token/page',
{
params,
},
);
}
/** 删除 OAuth2.0 令牌 */
export function deleteOAuth2Token(accessToken: string) {
return requestClient.delete(
`/system/oauth2-token/delete?accessToken=${accessToken}`,
);
}