feat(http): 实现基于alova的HTTP请求模块

添加HTTP请求核心模块,包括异常处理、状态码检查、消息提示等功能
- 新增alova实例配置,支持请求加密、token添加等特性
- 实现401状态码自动处理及登出逻辑
- 添加多种消息提示方式(message/modal/notification)
- 支持请求成功/失败的统一处理
- 添加WithMessage方法简化成功提示
- 更新相关依赖配置
This commit is contained in:
dap
2026-01-19 19:05:37 +08:00
parent c713828037
commit 8b0cf671b5
9 changed files with 639 additions and 3 deletions

59
apps/web-antd/types/alova.d.ts vendored Normal file
View File

@@ -0,0 +1,59 @@
/* eslint-disable unicorn/require-module-specifiers */
import type { AlovaInstanceType } from '#/utils/http';
import 'alova';
/**
* 接口请求message提示方式
*/
export type MessageType = 'message' | 'modal' | 'none' | 'notification';
type GetType = AlovaInstanceType['Get'];
type PostType = AlovaInstanceType['Post'];
type PutType = AlovaInstanceType['Put'];
type DeleteType = AlovaInstanceType['Delete'];
export type AlovaMeta = {
/**
* 是否需要对请求体进行加密
*/
encrypt?: boolean;
/**
* 是否返回原生axios响应
*/
isReturnNativeResponse?: boolean;
/**
* 是否需要转换响应 即只获取{code, msg, data}中的data
*/
isTransformResponse?: boolean;
/**
* 接口请求失败时的提示方式
*/
showErrorMessage?: MessageType;
/**
* 接口请求成功时的提示方式
*/
showSuccessMessage?: MessageType;
/**
* 是否需要在请求头中添加 token
*/
withToken?: boolean;
};
declare module 'alova' {
export interface AlovaCustomTypes {
meta: AlovaMeta;
}
/**
* 添加withMessage方法 用于success弹窗
*/
interface Alova {
GetWithMessage: GetType;
PostWithMessage: PostType;
PutWithMessage: PutType;
DeleteWithMessage: DeleteType;
}
}
export {};