mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-23 15:44:31 +08:00
feat(http): 实现基于alova的HTTP请求模块
添加HTTP请求核心模块,包括异常处理、状态码检查、消息提示等功能 - 新增alova实例配置,支持请求加密、token添加等特性 - 实现401状态码自动处理及登出逻辑 - 添加多种消息提示方式(message/modal/notification) - 支持请求成功/失败的统一处理 - 添加WithMessage方法简化成功提示 - 更新相关依赖配置
This commit is contained in:
49
apps/web-antd/src/utils/http/popup.ts
Normal file
49
apps/web-antd/src/utils/http/popup.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { AlovaMeta } from '#/../types/alova';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
|
||||
interface ShowMessageOptions {
|
||||
meta?: AlovaMeta;
|
||||
message: string;
|
||||
type: 'error' | 'success';
|
||||
}
|
||||
|
||||
export function showAntdMessage(options: ShowMessageOptions) {
|
||||
const { meta = {}, message, type } = options;
|
||||
|
||||
if (meta.showErrorMessage === 'message' && type === 'error') {
|
||||
window.message[type](message);
|
||||
}
|
||||
if (meta.showSuccessMessage === 'message' && type === 'success') {
|
||||
window.message[type](message);
|
||||
}
|
||||
|
||||
if (meta.showErrorMessage === 'modal' && type === 'error') {
|
||||
window.modal.error({
|
||||
content: message,
|
||||
title: $t('http.errorTip'),
|
||||
centered: true,
|
||||
okButtonProps: { danger: true },
|
||||
});
|
||||
}
|
||||
if (meta.showSuccessMessage === 'modal' && type === 'success') {
|
||||
window.modal.success({
|
||||
content: message,
|
||||
title: $t('http.successTip'),
|
||||
centered: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (meta.showErrorMessage === 'notification' && type === 'error') {
|
||||
window.notification.error({
|
||||
description: message,
|
||||
title: $t('http.errorTip'),
|
||||
});
|
||||
}
|
||||
if (meta.showSuccessMessage === 'notification' && type === 'success') {
|
||||
window.notification.success({
|
||||
description: message,
|
||||
title: $t('http.successTip'),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user