feat: 增加 file 文件上传 50%

This commit is contained in:
YunaiV
2025-04-17 23:30:34 +08:00
parent 54f9d0c10f
commit f6e2dc55ff
11 changed files with 390 additions and 2 deletions

View File

@@ -1,5 +1,9 @@
import { requestClient } from '#/api/request';
import type { PageParam, PageResult } from '@vben/request';
import type { AxiosRequestConfig } from '@vben/request';
/** Axios 上传进度事件 */
export type AxiosProgressEvent = AxiosRequestConfig['onUploadProgress'];
export namespace InfraFileApi {
/** 文件信息 */
@@ -46,7 +50,8 @@ export function createFile(data: InfraFileApi.InfraFile) {
return requestClient.post('/infra/file/create', data);
}
// TODO @芋艿:需要 data 自定义个类型;
/** 上传文件 */
export function uploadFile(data: any) {
return requestClient.upload('/infra/file/upload', data);
export function uploadFile(data: any, onUploadProgress?: AxiosProgressEvent) {
return requestClient.upload('/infra/file/upload', data, { onUploadProgress });
}

View File

@@ -0,0 +1,53 @@
import { requestClient } from '#/api/request';
/** OAuth2.0 授权信息响应 */
export interface OAuth2OpenAuthorizeInfoRespVO {
client: {
name: string;
logo: string;
};
scopes: {
key: string;
value: boolean;
}[];
}
/** 获得授权信息 */
export function getAuthorize(clientId: string) {
return requestClient.get<OAuth2OpenAuthorizeInfoRespVO>(`/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: state,
auto_approve: autoApprove,
scope: JSON.stringify(scopes)
}
});
}