mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-24 23:44:32 +08:00
refactor: 迁移requestClient到alovaInstance并移除旧版上传组件
重构项目中所有使用requestClient的API调用,替换为alovaInstance 移除已废弃的旧版上传组件及相关代码 调整上传组件类型定义以适配antdv-next更新 优化上传逻辑,移除不必要的进度事件和取消信号 更新类型定义文件,迁移axios配置到alova类型
This commit is contained in:
@@ -15,8 +15,6 @@ import { $t } from '@vben/locales';
|
||||
|
||||
import { notification } from 'antdv-next';
|
||||
|
||||
import { FileUploadOld, ImageUploadOld } from '#/components/upload-old';
|
||||
|
||||
const RichTextarea = defineAsyncComponent(() =>
|
||||
import('#/components/tinymce/index').then((res) => res.Tinymce),
|
||||
);
|
||||
@@ -149,10 +147,8 @@ export type ComponentType =
|
||||
| 'DefaultButton'
|
||||
| 'Divider'
|
||||
| 'FileUpload'
|
||||
| 'FileUploadOld'
|
||||
| 'IconPicker'
|
||||
| 'ImageUpload'
|
||||
| 'ImageUploadOld'
|
||||
| 'Input'
|
||||
| 'InputNumber'
|
||||
| 'InputPassword'
|
||||
@@ -250,8 +246,6 @@ async function initComponentAdapter() {
|
||||
ImageUpload,
|
||||
FileUpload,
|
||||
RichTextarea,
|
||||
ImageUploadOld,
|
||||
FileUploadOld,
|
||||
};
|
||||
|
||||
// 将组件注册到全局共享状态中
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { HttpResponse } from '@vben/request';
|
||||
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
const { clientId, sseEnable } = useAppConfig(
|
||||
import.meta.env,
|
||||
@@ -78,7 +78,7 @@ export namespace AuthApi {
|
||||
* 登录
|
||||
*/
|
||||
export async function loginApi(data: AuthApi.LoginParams) {
|
||||
return requestClient.post<AuthApi.LoginResult>(
|
||||
return alovaInstance.post<AuthApi.LoginResult>(
|
||||
'/auth/login',
|
||||
{ ...data, clientId },
|
||||
{
|
||||
@@ -92,7 +92,7 @@ export async function loginApi(data: AuthApi.LoginParams) {
|
||||
* @returns void
|
||||
*/
|
||||
export function doLogout() {
|
||||
return requestClient.post<HttpResponse<void>>('/auth/logout');
|
||||
return alovaInstance.post<HttpResponse<void>>('/auth/logout');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ export function seeConnectionClose() {
|
||||
if (!sseEnable) {
|
||||
return;
|
||||
}
|
||||
return requestClient.get<void>('/resource/sse/close');
|
||||
return alovaInstance.get<void>('/resource/sse/close');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ export interface TenantResp {
|
||||
* 获取租户列表 下拉框使用
|
||||
*/
|
||||
export function tenantList() {
|
||||
return requestClient.get<TenantResp>('/auth/tenant/list');
|
||||
return alovaInstance.get<TenantResp>('/auth/tenant/list');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +141,7 @@ export function tenantList() {
|
||||
* @returns string[]
|
||||
*/
|
||||
export async function getAccessCodesApi() {
|
||||
return requestClient.get<string[]>('/auth/codes');
|
||||
return alovaInstance.get<string[]>('/auth/codes');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +150,7 @@ export async function getAccessCodesApi() {
|
||||
* @returns 跳转url
|
||||
*/
|
||||
export function authBinding(source: string, tenantId: string) {
|
||||
return requestClient.get<string>(`/auth/binding/${source}`, {
|
||||
return alovaInstance.get<string>(`/auth/binding/${source}`, {
|
||||
params: {
|
||||
domain: window.location.host,
|
||||
tenantId,
|
||||
@@ -163,7 +163,7 @@ export function authBinding(source: string, tenantId: string) {
|
||||
* @param id id
|
||||
*/
|
||||
export function authUnbinding(id: string) {
|
||||
return requestClient.deleteWithMsg<void>(`/auth/unlock/${id}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`/auth/unlock/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,5 +172,5 @@ export function authUnbinding(id: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function authCallback(data: AuthApi.OAuthLoginParams) {
|
||||
return requestClient.post<void>('/auth/social/callback', data);
|
||||
return alovaInstance.post<void>('/auth/social/callback', data);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
@@ -6,7 +6,7 @@ import { requestClient } from '#/api/request';
|
||||
* @returns void
|
||||
*/
|
||||
export function sendSmsCode(phonenumber: string) {
|
||||
return requestClient.get<void>('/resource/sms/code', {
|
||||
return alovaInstance.get<void>('/resource/sms/code', {
|
||||
params: { phonenumber },
|
||||
});
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export function sendSmsCode(phonenumber: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function sendEmailCode(email: string) {
|
||||
return requestClient.get<void>('/resource/email/code', {
|
||||
return alovaInstance.get<void>('/resource/email/code', {
|
||||
params: { email },
|
||||
});
|
||||
}
|
||||
@@ -38,5 +38,5 @@ export interface CaptchaResponse {
|
||||
* @returns resp
|
||||
*/
|
||||
export function captchaImage() {
|
||||
return requestClient.get<CaptchaResponse>('/auth/code');
|
||||
return alovaInstance.get<CaptchaResponse>('/auth/code');
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* @description: 菜单meta
|
||||
@@ -41,5 +41,5 @@ export interface Menu {
|
||||
* 获取用户所有菜单
|
||||
*/
|
||||
export async function getAllMenusApi() {
|
||||
return requestClient.get<Menu[]>('/system/menu/getRouters');
|
||||
return alovaInstance.get<Menu[]>('/system/menu/getRouters');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AxiosRequestConfig } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* Axios上传进度事件
|
||||
@@ -20,24 +20,20 @@ export interface UploadResult {
|
||||
* 通过单文件上传接口
|
||||
* @param file 上传的文件
|
||||
* @param options 一些配置项
|
||||
* @param options.onUploadProgress 上传进度事件
|
||||
* @param options.signal 上传取消信号
|
||||
* @param options.otherData 其他请求参数 后端拓展可能会用到
|
||||
* @returns 上传结果
|
||||
*/
|
||||
export function uploadApi(
|
||||
file: Blob | File,
|
||||
options?: {
|
||||
onUploadProgress?: AxiosProgressEvent;
|
||||
otherData?: Record<string, any>;
|
||||
signal?: AbortSignal;
|
||||
},
|
||||
) {
|
||||
const { onUploadProgress, signal, otherData = {} } = options ?? {};
|
||||
return requestClient.upload<UploadResult>(
|
||||
const { otherData = {} } = options ?? {};
|
||||
return alovaInstance.post<UploadResult>(
|
||||
'/resource/oss/upload',
|
||||
{ file, ...otherData },
|
||||
{ onUploadProgress, signal, timeout: 60_000 },
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
export interface Role {
|
||||
dataScope: string;
|
||||
@@ -42,5 +42,5 @@ export interface UserInfoResp {
|
||||
* 存在返回null的情况(401) 不会抛出异常 需要手动抛异常
|
||||
*/
|
||||
export async function getUserInfoApi() {
|
||||
return requestClient.get<null | UserInfoResp>('/system/user/getInfo');
|
||||
return alovaInstance.get<null | UserInfoResp>('/system/user/getInfo');
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
import { requestClient } from './request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* @description: contentType
|
||||
@@ -23,8 +22,7 @@ export const ContentTypeEnum = {
|
||||
* @returns blob二进制
|
||||
*/
|
||||
export function commonExport(url: string, data: Record<string, any>) {
|
||||
return requestClient.post<Blob>(url, data, {
|
||||
data,
|
||||
return alovaInstance.post<Blob>(url, data, {
|
||||
headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
|
||||
isTransformResponse: false,
|
||||
responseType: 'blob',
|
||||
|
||||
4
apps/web-antd/src/api/monitor/cache/index.ts
vendored
4
apps/web-antd/src/api/monitor/cache/index.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
export interface CommandStats {
|
||||
name: string;
|
||||
@@ -20,5 +20,5 @@ export interface CacheInfo {
|
||||
* @returns redis信息
|
||||
*/
|
||||
export function redisCacheInfo() {
|
||||
return requestClient.get<CacheInfo>('/monitor/cache');
|
||||
return alovaInstance.get<CacheInfo>('/monitor/cache');
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { LoginLog } from './model';
|
||||
import type { IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
loginInfoClean = '/monitor/logininfor/clean',
|
||||
@@ -19,7 +19,7 @@ enum Api {
|
||||
* @returns list[]
|
||||
*/
|
||||
export function loginInfoList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<LoginLog>>(Api.loginInfoList, { params });
|
||||
return alovaInstance.get<PageResult<LoginLog>>(Api.loginInfoList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ export function loginInfoExport(data: any) {
|
||||
* @returns void
|
||||
*/
|
||||
export function loginInfoRemove(infoIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${infoIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${infoIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ export function loginInfoRemove(infoIds: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userUnlock(username: string) {
|
||||
return requestClient.get<void>(`${Api.userUnlock}/${username}`, {
|
||||
return alovaInstance.get<void>(`${Api.userUnlock}/${username}`, {
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
}
|
||||
@@ -56,5 +56,5 @@ export function userUnlock(username: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function loginInfoClean() {
|
||||
return requestClient.deleteWithMsg<void>(Api.loginInfoClean);
|
||||
return alovaInstance.deleteWithMsg<void>(Api.loginInfoClean);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { OnlineUser } from './model';
|
||||
|
||||
import type { PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
onlineList = '/monitor/online/list',
|
||||
@@ -14,7 +14,7 @@ enum Api {
|
||||
* @returns OnlineUser[]
|
||||
*/
|
||||
export function onlineDeviceList() {
|
||||
return requestClient.get<PageResult<OnlineUser>>(Api.root);
|
||||
return alovaInstance.get<PageResult<OnlineUser>>(Api.root);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ export function onlineDeviceList() {
|
||||
* @returns 结果
|
||||
*/
|
||||
export function onlineList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<OnlineUser>>(Api.onlineList, { params });
|
||||
return alovaInstance.get<PageResult<OnlineUser>>(Api.onlineList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ export function onlineList(params?: PageQuery) {
|
||||
* @returns void
|
||||
*/
|
||||
export function forceLogout(tokenId: string) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${tokenId}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${tokenId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,5 +41,5 @@ export function forceLogout(tokenId: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function forceLogout2(tokenId: string) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/myself/${tokenId}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/myself/${tokenId}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { OperationLog } from './model';
|
||||
import type { IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
operLogClean = '/monitor/operlog/clean',
|
||||
@@ -18,7 +18,7 @@ enum Api {
|
||||
* @returns 分页结果
|
||||
*/
|
||||
export function operLogList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<OperationLog>>(Api.operLogList, {
|
||||
return alovaInstance.get<PageResult<OperationLog>>(Api.operLogList, {
|
||||
params,
|
||||
});
|
||||
}
|
||||
@@ -28,14 +28,14 @@ export function operLogList(params?: PageQuery) {
|
||||
* @param operIds id/ids
|
||||
*/
|
||||
export function operLogDelete(operIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${operIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${operIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空全部分页日志
|
||||
*/
|
||||
export function operLogClean() {
|
||||
return requestClient.deleteWithMsg<void>(Api.operLogClean);
|
||||
return alovaInstance.deleteWithMsg<void>(Api.operLogClean);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,318 +0,0 @@
|
||||
/**
|
||||
* 该文件可自行根据业务逻辑进行调整
|
||||
*/
|
||||
|
||||
import type { HttpResponse } from '@vben/request';
|
||||
import type {
|
||||
BaseAsymmetricEncryption,
|
||||
BaseSymmetricEncryption,
|
||||
} from '@vben/utils';
|
||||
|
||||
import { BUSINESS_SUCCESS_CODE, UNAUTHORIZED_CODE } from '@vben/constants';
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
import { $t } from '@vben/locales';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import {
|
||||
authenticateResponseInterceptor,
|
||||
errorMessageResponseInterceptor,
|
||||
RequestClient,
|
||||
stringify,
|
||||
} from '@vben/request';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
import {
|
||||
AesEncryption,
|
||||
decodeBase64,
|
||||
encodeBase64,
|
||||
randomStr,
|
||||
RsaEncryption,
|
||||
} from '@vben/utils';
|
||||
|
||||
import { isEmpty, isNull } from 'lodash-es';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
import { handleUnauthorizedLogout } from './helper';
|
||||
|
||||
const { apiURL, clientId, enableEncrypt, rsaPublicKey, rsaPrivateKey } =
|
||||
useAppConfig(import.meta.env, import.meta.env.PROD);
|
||||
|
||||
/**
|
||||
* 使用非对称加密的实现 前端已经实现RSA/SM2
|
||||
*
|
||||
* 你可以使用Sm2Encryption来替换 后端也需要同步替换公私钥对
|
||||
*
|
||||
* 后端文件位置: ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/filter/DecryptRequestBodyWrapper.java
|
||||
*
|
||||
* 注意前端sm-crypto库只能支持04开头的公钥! 否则加密会有问题 你可以使用前端的import { logSm2KeyPair } from '@vben/utils';方法来生成
|
||||
* 如果你生成的公钥开头不是04 那么不能正常加密
|
||||
* 或者使用这个网站来生成: https://tool.hiofd.com/sm2-key-gen/
|
||||
*/
|
||||
const asymmetricEncryption: BaseAsymmetricEncryption = new RsaEncryption({
|
||||
publicKey: rsaPublicKey,
|
||||
privateKey: rsaPrivateKey,
|
||||
});
|
||||
|
||||
/**
|
||||
* 对称加密的实现 AES/SM4
|
||||
*/
|
||||
const symmetricEncryption: BaseSymmetricEncryption = new AesEncryption();
|
||||
|
||||
function createRequestClient(baseURL: string) {
|
||||
const client = new RequestClient({
|
||||
// 后端地址
|
||||
baseURL,
|
||||
// 消息提示类型
|
||||
errorMessageMode: 'message',
|
||||
// 是否返回原生响应 比如:需要获取响应头时使用该属性
|
||||
isReturnNativeResponse: false,
|
||||
// 需要对返回数据进行处理
|
||||
isTransformResponse: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* 重新认证逻辑
|
||||
*/
|
||||
async function doReAuthenticate() {
|
||||
console.warn('Access token or refresh token is invalid or expired. ');
|
||||
const accessStore = useAccessStore();
|
||||
const authStore = useAuthStore();
|
||||
accessStore.setAccessToken(null);
|
||||
if (
|
||||
preferences.app.loginExpiredMode === 'modal' &&
|
||||
accessStore.isAccessChecked
|
||||
) {
|
||||
accessStore.setLoginExpired(true);
|
||||
} else {
|
||||
await authStore.logout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新token逻辑
|
||||
*/
|
||||
async function doRefreshToken() {
|
||||
// 不需要
|
||||
// 保留此方法只是为了合并方便
|
||||
return '';
|
||||
}
|
||||
|
||||
function formatToken(token: null | string) {
|
||||
return token ? `Bearer ${token}` : null;
|
||||
}
|
||||
|
||||
client.addRequestInterceptor({
|
||||
fulfilled: (config) => {
|
||||
const accessStore = useAccessStore();
|
||||
// 添加token
|
||||
config.headers.Authorization = formatToken(accessStore.accessToken);
|
||||
/**
|
||||
* locale跟后台不一致 需要转换
|
||||
*/
|
||||
const language = preferences.app.locale.replace('-', '_');
|
||||
config.headers['Accept-Language'] = language;
|
||||
config.headers['Content-Language'] = language;
|
||||
/**
|
||||
* 添加全局clientId
|
||||
* 关于header的clientId被错误绑定到实体类
|
||||
* https://gitee.com/dapppp/ruoyi-plus-vben5/issues/IC0BDS
|
||||
*/
|
||||
config.headers.ClientID = clientId;
|
||||
/**
|
||||
* 格式化get/delete参数
|
||||
* 如果包含自定义的paramsSerializer则不走此逻辑
|
||||
*/
|
||||
if (
|
||||
['DELETE', 'GET'].includes(config.method?.toUpperCase() || '') &&
|
||||
config.params &&
|
||||
!config.paramsSerializer
|
||||
) {
|
||||
/**
|
||||
* 1. 格式化参数 微服务在传递区间时间选择(后端的params Map类型参数)需要格式化key 否则接收不到
|
||||
* 2. 数组参数需要格式化 后端才能正常接收 会变成arr=1&arr=2&arr=3的格式来接收
|
||||
*/
|
||||
config.paramsSerializer = (params) =>
|
||||
stringify(params, { arrayFormat: 'repeat' });
|
||||
}
|
||||
|
||||
const { encrypt } = config;
|
||||
// 全局开启请求加密功能 && 该请求开启 && 是post/put请求
|
||||
if (
|
||||
enableEncrypt &&
|
||||
encrypt &&
|
||||
['POST', 'PUT'].includes(config.method?.toUpperCase() || '')
|
||||
) {
|
||||
// sm4这里改为randomStr(16)
|
||||
const key = randomStr(32);
|
||||
const keyWithBase64 = encodeBase64(key);
|
||||
config.headers['encrypt-key'] =
|
||||
asymmetricEncryption.encrypt(keyWithBase64);
|
||||
/**
|
||||
* axios会默认给字符串前后加上引号 RSA可以正常解密(加不加都能解密) 但是SM2不行(大坑!!!)
|
||||
* 这里通过transformRequest强制返回原始内容
|
||||
*/
|
||||
config.transformRequest = (data) => data;
|
||||
|
||||
config.data =
|
||||
typeof config.data === 'object'
|
||||
? symmetricEncryption.encrypt(JSON.stringify(config.data), key)
|
||||
: symmetricEncryption.encrypt(config.data, key);
|
||||
}
|
||||
return config;
|
||||
},
|
||||
});
|
||||
|
||||
// 通用的错误处理, 如果没有进入上面的错误处理逻辑,就会进入这里
|
||||
// 主要处理http状态码不为200(如网络异常/离线)的情况 必须放在在下面的响应拦截器之前
|
||||
client.addResponseInterceptor(
|
||||
errorMessageResponseInterceptor((msg: string) => window.message.error(msg)),
|
||||
);
|
||||
|
||||
client.addResponseInterceptor<HttpResponse>({
|
||||
fulfilled: async (response) => {
|
||||
const encryptKey = (response.headers ?? {})['encrypt-key'];
|
||||
if (encryptKey) {
|
||||
/** RSA私钥解密 拿到解密秘钥的base64 */
|
||||
const base64Str = asymmetricEncryption.decrypt(encryptKey);
|
||||
/** base64 解码 得到请求头的 AES 秘钥 */
|
||||
const secret = decodeBase64(base64Str);
|
||||
/** 使用aesKey解密 responseData */
|
||||
const decryptData = symmetricEncryption.decrypt(
|
||||
response.data as unknown as string,
|
||||
secret,
|
||||
);
|
||||
/** 赋值 需要转为对象 */
|
||||
response.data = JSON.parse(decryptData);
|
||||
}
|
||||
|
||||
const { isReturnNativeResponse, isTransformResponse } = response.config;
|
||||
// 是否返回原生响应 比如:需要获取响应时使用该属性
|
||||
if (isReturnNativeResponse) {
|
||||
return response;
|
||||
}
|
||||
// 不进行任何处理,直接返回
|
||||
// 用于页面代码可能需要直接获取code,data,message这些信息时开启
|
||||
if (!isTransformResponse) {
|
||||
/**
|
||||
* @warning 注意 微服务版本在401(网关)会返回text/plain的头 所以这里代码会无效
|
||||
* 我建议你改后端而不是前端来做兼容
|
||||
*/
|
||||
// json数据的判断
|
||||
if (response.headers['content-type']?.includes?.('application/json')) {
|
||||
/**
|
||||
* 需要判断是否登录超时/401
|
||||
* 执行登出操作
|
||||
*/
|
||||
const resp = response.data as unknown as HttpResponse;
|
||||
// 抛出异常 不再执行
|
||||
if (
|
||||
typeof resp === 'object' &&
|
||||
Reflect.has(resp, 'code') &&
|
||||
resp.code === UNAUTHORIZED_CODE
|
||||
) {
|
||||
handleUnauthorizedLogout();
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要判断下载二进制的情况 正常是返回二进制 报错会返回json
|
||||
* 当type为blob且content-type为application/json时 则判断已经下载出错
|
||||
*/
|
||||
if (response.config.responseType === 'blob') {
|
||||
// 这时候的data为blob类型
|
||||
const blob = response.data as unknown as Blob;
|
||||
// 拿到字符串转json对象
|
||||
response.data = JSON.parse(await blob.text());
|
||||
// 然后按正常逻辑执行下面的代码(判断业务状态码)
|
||||
} else {
|
||||
// 其他类型数据 直接返回
|
||||
return response.data;
|
||||
}
|
||||
} else {
|
||||
// 非json数据 直接返回 不做校验
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
const axiosResponseData = response.data;
|
||||
if (!axiosResponseData) {
|
||||
throw new Error($t('http.apiRequestFailed'));
|
||||
}
|
||||
|
||||
// 后端并没有采用严格的{code, msg, data}模式
|
||||
const { code, data, msg, ...other } = axiosResponseData;
|
||||
|
||||
// 业务状态码为200 则请求成功
|
||||
const hasSuccess =
|
||||
Reflect.has(axiosResponseData, 'code') &&
|
||||
code === BUSINESS_SUCCESS_CODE;
|
||||
if (hasSuccess) {
|
||||
let successMsg = msg;
|
||||
|
||||
if (isNull(successMsg) || isEmpty(successMsg)) {
|
||||
successMsg = $t(`http.operationSuccess`);
|
||||
}
|
||||
|
||||
if (response.config.successMessageMode === 'modal') {
|
||||
window.modal.success({
|
||||
content: successMsg,
|
||||
title: $t('http.successTip'),
|
||||
});
|
||||
} else if (response.config.successMessageMode === 'message') {
|
||||
window.message.success(successMsg);
|
||||
}
|
||||
// 分页情况下为code msg rows total 并没有data字段
|
||||
// 如果有data 直接返回data 没有data将剩余参数(...other)封装为data返回
|
||||
// 需要考虑data为null的情况(比如查询为空) 所以这里直接判断undefined
|
||||
if (data !== undefined) {
|
||||
return data;
|
||||
}
|
||||
// 没有data 将其他参数包装为data
|
||||
return other;
|
||||
}
|
||||
// 在此处根据自己项目的实际情况对不同的code执行不同的操作
|
||||
// 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
|
||||
let timeoutMsg = '';
|
||||
switch (code) {
|
||||
// 登录超时
|
||||
case UNAUTHORIZED_CODE: {
|
||||
handleUnauthorizedLogout();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (msg) {
|
||||
timeoutMsg = msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// errorMessageMode='modal'的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
|
||||
// errorMessageMode='none' 一般是调用时明确表示不希望自动弹出错误提示
|
||||
if (response.config.errorMessageMode === 'modal') {
|
||||
window.modal.error({
|
||||
content: timeoutMsg,
|
||||
title: $t('http.errorTip'),
|
||||
});
|
||||
} else if (response.config.errorMessageMode === 'message') {
|
||||
window.message.error(timeoutMsg);
|
||||
}
|
||||
|
||||
throw new Error(timeoutMsg || $t('http.apiRequestFailed'));
|
||||
},
|
||||
});
|
||||
|
||||
// token过期的处理
|
||||
client.addResponseInterceptor(
|
||||
authenticateResponseInterceptor({
|
||||
client,
|
||||
doReAuthenticate,
|
||||
doRefreshToken,
|
||||
enableRefreshToken: preferences.app.enableRefreshToken,
|
||||
formatToken,
|
||||
}),
|
||||
);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
export const requestClient = createRequestClient(apiURL);
|
||||
|
||||
export const baseRequestClient = new RequestClient({ baseURL: apiURL });
|
||||
@@ -3,7 +3,7 @@ import type { Client } from './model';
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
clientChangeStatus = '/system/client/changeStatus',
|
||||
@@ -18,7 +18,7 @@ enum Api {
|
||||
* @returns 列表
|
||||
*/
|
||||
export function clientList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<Client>>(Api.clientList, { params });
|
||||
return alovaInstance.get<PageResult<Client>>(Api.clientList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ export function clientExport(data: Partial<Client>) {
|
||||
* @returns 详情
|
||||
*/
|
||||
export function clientInfo(id: ID) {
|
||||
return requestClient.get<Client>(`${Api.root}/${id}`);
|
||||
return alovaInstance.get<Client>(`${Api.root}/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ export function clientInfo(id: ID) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function clientAdd(data: Partial<Client>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ export function clientAdd(data: Partial<Client>) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function clientUpdate(data: Partial<Client>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ export function clientChangeStatus(data: any) {
|
||||
clientId: data.clientId,
|
||||
status: data.status,
|
||||
};
|
||||
return requestClient.putWithMsg<void>(Api.clientChangeStatus, requestData);
|
||||
return alovaInstance.putWithMsg<void>(Api.clientChangeStatus, requestData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,5 +71,5 @@ export function clientChangeStatus(data: any) {
|
||||
* @param ids id集合
|
||||
*/
|
||||
export function clientRemove(ids: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${ids}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${ids}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SysConfig } from './model';
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
configExport = '/system/config/export',
|
||||
@@ -19,11 +19,11 @@ enum Api {
|
||||
* @returns 列表
|
||||
*/
|
||||
export function configList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<SysConfig>>(Api.configList, { params });
|
||||
return alovaInstance.get<PageResult<SysConfig>>(Api.configList, { params });
|
||||
}
|
||||
|
||||
export function configInfo(configId: ID) {
|
||||
return requestClient.get<SysConfig>(`${Api.root}/${configId}`);
|
||||
return alovaInstance.get<SysConfig>(`${Api.root}/${configId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ export function configExport(data: Partial<SysConfig>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function configRefreshCache() {
|
||||
return requestClient.deleteWithMsg<void>(Api.configRefreshCache);
|
||||
return alovaInstance.deleteWithMsg<void>(Api.configRefreshCache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ export function configRefreshCache() {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function configUpdate(data: Partial<SysConfig>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ export function configUpdate(data: Partial<SysConfig>) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function configAdd(data: Partial<SysConfig>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ export function configAdd(data: Partial<SysConfig>) {
|
||||
* @param configIds ids
|
||||
*/
|
||||
export function configRemove(configIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${configIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${configIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,5 +72,5 @@ export function configRemove(configIds: IDS) {
|
||||
* @returns value
|
||||
*/
|
||||
export function configInfoByKey(configKey: string) {
|
||||
return requestClient.get<string>(`${Api.configInfoByKey}/${configKey}`);
|
||||
return alovaInstance.get<string>(`${Api.configInfoByKey}/${configKey}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Dept } from './model';
|
||||
|
||||
import type { ID } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
deptList = '/system/dept/list',
|
||||
@@ -15,7 +15,7 @@ enum Api {
|
||||
* @returns list
|
||||
*/
|
||||
export function deptList(params?: { deptName?: string; status?: string }) {
|
||||
return requestClient.get<Dept[]>(Api.deptList, { params });
|
||||
return alovaInstance.get<Dept[]>(Api.deptList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ export function deptList(params?: { deptName?: string; status?: string }) {
|
||||
* @returns void
|
||||
*/
|
||||
export function deptNodeList(deptId: ID) {
|
||||
return requestClient.get<Dept[]>(`${Api.deptNodeInfo}/${deptId}`);
|
||||
return alovaInstance.get<Dept[]>(`${Api.deptNodeInfo}/${deptId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ export function deptNodeList(deptId: ID) {
|
||||
* @returns 部门信息
|
||||
*/
|
||||
export function deptInfo(deptId: ID) {
|
||||
return requestClient.get<Dept>(`${Api.root}/${deptId}`);
|
||||
return alovaInstance.get<Dept>(`${Api.root}/${deptId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ export function deptInfo(deptId: ID) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function deptAdd(data: Partial<Dept>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ export function deptAdd(data: Partial<Dept>) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function deptUpdate(data: Partial<Dept>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,5 +58,5 @@ export function deptUpdate(data: Partial<Dept>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function deptRemove(deptId: ID) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${deptId}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${deptId}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { DictData } from './dict-data-model';
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
dictDataExport = '/system/dict/data/export',
|
||||
@@ -17,7 +17,7 @@ enum Api {
|
||||
* @returns 字典数据
|
||||
*/
|
||||
export function dictDataInfo(dictType: string) {
|
||||
return requestClient.get<DictData[]>(`${Api.root}/type/${dictType}`);
|
||||
return alovaInstance.get<DictData[]>(`${Api.root}/type/${dictType}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ export function dictDataInfo(dictType: string) {
|
||||
* @returns 字典数据列表
|
||||
*/
|
||||
export function dictDataList(params?: PageQuery) {
|
||||
return requestClient.get<DictData[]>(Api.dictDataList, { params });
|
||||
return alovaInstance.get<DictData[]>(Api.dictDataList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ export function dictDataExport(data: Partial<DictData>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictDataRemove(dictIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${dictIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${dictIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ export function dictDataRemove(dictIds: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictDataAdd(data: Partial<DictData>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ export function dictDataAdd(data: Partial<DictData>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictDataUpdate(data: Partial<DictData>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,5 +71,5 @@ export function dictDataUpdate(data: Partial<DictData>) {
|
||||
* @returns 字典数据
|
||||
*/
|
||||
export function dictDetailInfo(dictCode: ID) {
|
||||
return requestClient.get<DictData>(`${Api.root}/${dictCode}`);
|
||||
return alovaInstance.get<DictData>(`${Api.root}/${dictCode}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { DictType } from './dict-type-model';
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
dictOptionSelectList = '/system/dict/type/optionselect',
|
||||
@@ -19,7 +19,7 @@ enum Api {
|
||||
* @returns list
|
||||
*/
|
||||
export function dictTypeList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<DictType>>(Api.dictTypeList, { params });
|
||||
return alovaInstance.get<PageResult<DictType>>(Api.dictTypeList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ export function dictTypeExport(data: Partial<DictType>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictTypeRemove(dictIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${dictIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${dictIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ export function dictTypeRemove(dictIds: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function refreshDictTypeCache() {
|
||||
return requestClient.deleteWithMsg<void>(Api.dictTypeRefreshCache);
|
||||
return alovaInstance.deleteWithMsg<void>(Api.dictTypeRefreshCache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ export function refreshDictTypeCache() {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictTypeAdd(data: Partial<DictType>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ export function dictTypeAdd(data: Partial<DictType>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictTypeUpdate(data: Partial<DictType>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ export function dictTypeUpdate(data: Partial<DictType>) {
|
||||
* @returns 信息
|
||||
*/
|
||||
export function dictTypeInfo(dictId: ID) {
|
||||
return requestClient.get<DictType>(`${Api.root}/${dictId}`);
|
||||
return alovaInstance.get<DictType>(`${Api.root}/${dictId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,5 +81,5 @@ export function dictTypeInfo(dictId: ID) {
|
||||
* @returns options
|
||||
*/
|
||||
export function dictOptionSelectList() {
|
||||
return requestClient.get<DictType[]>(Api.dictOptionSelectList);
|
||||
return alovaInstance.get<DictType[]>(Api.dictOptionSelectList);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Menu, MenuOption, MenuQuery, MenuResp } from './model';
|
||||
|
||||
import type { ID, IDS } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
menuList = '/system/menu/list',
|
||||
@@ -18,7 +18,7 @@ enum Api {
|
||||
* @returns 列表
|
||||
*/
|
||||
export function menuList(params?: MenuQuery) {
|
||||
return requestClient.get<Menu[]>(Api.menuList, { params });
|
||||
return alovaInstance.get<Menu[]>(Api.menuList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ export function menuList(params?: MenuQuery) {
|
||||
* @returns 菜单详情
|
||||
*/
|
||||
export function menuInfo(menuId: ID) {
|
||||
return requestClient.get<Menu>(`${Api.root}/${menuId}`);
|
||||
return alovaInstance.get<Menu>(`${Api.root}/${menuId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ export function menuInfo(menuId: ID) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function menuAdd(data: Partial<Menu>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ export function menuAdd(data: Partial<Menu>) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function menuUpdate(data: Partial<Menu>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ export function menuUpdate(data: Partial<Menu>) {
|
||||
* @param menuIds ids
|
||||
*/
|
||||
export function menuRemove(menuIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${menuIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${menuIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ export function menuRemove(menuIds: IDS) {
|
||||
* @returns resp
|
||||
*/
|
||||
export function roleMenuTreeSelect(roleId: ID) {
|
||||
return requestClient.get<MenuResp>(`${Api.roleMenuTree}/${roleId}`);
|
||||
return alovaInstance.get<MenuResp>(`${Api.roleMenuTree}/${roleId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ export function roleMenuTreeSelect(roleId: ID) {
|
||||
* @returns []
|
||||
*/
|
||||
export function menuTreeSelect() {
|
||||
return requestClient.get<MenuOption[]>(Api.menuTreeSelect);
|
||||
return alovaInstance.get<MenuOption[]>(Api.menuTreeSelect);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ export function menuTreeSelect() {
|
||||
* @returns resp
|
||||
*/
|
||||
export function tenantPackageMenuTreeSelect(packageId: ID) {
|
||||
return requestClient.get<MenuResp>(
|
||||
return alovaInstance.get<MenuResp>(
|
||||
`${Api.tenantPackageMenuTreeselect}/${packageId}`,
|
||||
);
|
||||
}
|
||||
@@ -88,5 +88,5 @@ export function tenantPackageMenuTreeSelect(packageId: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function menuCascadeRemove(menuIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/cascade/${menuIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/cascade/${menuIds}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Notice } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
noticeList = '/system/notice/list',
|
||||
@@ -15,7 +15,7 @@ enum Api {
|
||||
* @returns 分页结果
|
||||
*/
|
||||
export function noticeList(params?: PageQuery) {
|
||||
return requestClient.get<Notice[]>(Api.noticeList, { params });
|
||||
return alovaInstance.get<Notice[]>(Api.noticeList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ export function noticeList(params?: PageQuery) {
|
||||
* @returns 详情
|
||||
*/
|
||||
export function noticeInfo(noticeId: ID) {
|
||||
return requestClient.get<Notice>(`${Api.root}/${noticeId}`);
|
||||
return alovaInstance.get<Notice>(`${Api.root}/${noticeId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ export function noticeInfo(noticeId: ID) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function noticeAdd(data: Partial<Notice>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ export function noticeAdd(data: Partial<Notice>) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function noticeUpdate(data: any) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,5 +48,5 @@ export function noticeUpdate(data: any) {
|
||||
* @param noticeIds ids
|
||||
*/
|
||||
export function noticeRemove(noticeIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${noticeIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${noticeIds}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { OssConfig } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
ossConfigChangeStatus = '/resource/oss/config/changeStatus',
|
||||
@@ -12,27 +12,27 @@ enum Api {
|
||||
|
||||
// 获取OSS配置列表
|
||||
export function ossConfigList(params?: PageQuery) {
|
||||
return requestClient.get<OssConfig[]>(Api.ossConfigList, { params });
|
||||
return alovaInstance.get<OssConfig[]>(Api.ossConfigList, { params });
|
||||
}
|
||||
|
||||
// 获取OSS配置的信息
|
||||
export function ossConfigInfo(ossConfigId: ID) {
|
||||
return requestClient.get<OssConfig>(`${Api.root}/${ossConfigId}`);
|
||||
return alovaInstance.get<OssConfig>(`${Api.root}/${ossConfigId}`);
|
||||
}
|
||||
|
||||
// 添加新的OSS配置
|
||||
export function ossConfigAdd(data: Partial<OssConfig>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
// 更新现有的OSS配置
|
||||
export function ossConfigUpdate(data: Partial<OssConfig>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
// 删除OSS配置
|
||||
export function ossConfigRemove(ossConfigIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${ossConfigIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${ossConfigIds}`);
|
||||
}
|
||||
|
||||
// 更改OSS配置的状态
|
||||
@@ -42,5 +42,5 @@ export function ossConfigChangeStatus(data: any) {
|
||||
status: data.status,
|
||||
configKey: data.configKey,
|
||||
};
|
||||
return requestClient.putWithMsg(Api.ossConfigChangeStatus, requestData);
|
||||
return alovaInstance.putWithMsg(Api.ossConfigChangeStatus, requestData);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import type { AxiosRequestConfig } from '@vben/request';
|
||||
|
||||
import type { OssFile } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { ContentTypeEnum } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
ossDownload = '/resource/oss/download',
|
||||
@@ -21,7 +19,7 @@ enum Api {
|
||||
* @returns 分页
|
||||
*/
|
||||
export function ossList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<OssFile>>(Api.ossList, { params });
|
||||
return alovaInstance.get<PageResult<OssFile>>(Api.ossList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +28,7 @@ export function ossList(params?: PageQuery) {
|
||||
* @returns 信息数组
|
||||
*/
|
||||
export function ossInfo(ossIds: ID | IDS) {
|
||||
return requestClient.get<OssFile[]>(`${Api.ossInfo}/${ossIds}`);
|
||||
return alovaInstance.get<OssFile[]>(`${Api.ossInfo}/${ossIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +39,7 @@ export function ossInfo(ossIds: ID | IDS) {
|
||||
export function ossUpload(file: Blob | File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return requestClient.postWithMsg(Api.ossUpload, formData, {
|
||||
return alovaInstance.postWithMsg(Api.ossUpload, formData, {
|
||||
headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
|
||||
timeout: 30 * 1000,
|
||||
});
|
||||
@@ -50,18 +48,13 @@ export function ossUpload(file: Blob | File) {
|
||||
/**
|
||||
* 下载文件 返回为二进制
|
||||
* @param ossId ossId
|
||||
* @param onDownloadProgress 下载进度(可选)
|
||||
* @returns blob
|
||||
*/
|
||||
export function ossDownload(
|
||||
ossId: ID,
|
||||
onDownloadProgress?: AxiosRequestConfig['onDownloadProgress'],
|
||||
) {
|
||||
return requestClient.get<Blob>(`${Api.ossDownload}/${ossId}`, {
|
||||
export function ossDownload(ossId: ID) {
|
||||
return alovaInstance.get<Blob>(`${Api.ossDownload}/${ossId}`, {
|
||||
responseType: 'blob',
|
||||
timeout: 30 * 1000,
|
||||
isTransformResponse: false,
|
||||
onDownloadProgress,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -74,7 +67,7 @@ export function ossDownload(
|
||||
* @returns void
|
||||
*/
|
||||
export function checkLoginBeforeDownload() {
|
||||
return requestClient.get<OssFile[]>(`${Api.ossInfo}/1`, {
|
||||
return alovaInstance.get<OssFile[]>(`${Api.ossInfo}/1`, {
|
||||
errorMessageMode: 'none',
|
||||
});
|
||||
}
|
||||
@@ -85,5 +78,5 @@ export function checkLoginBeforeDownload() {
|
||||
* @returns void
|
||||
*/
|
||||
export function ossRemove(ossIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${ossIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${ossIds}`);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Post } from './model';
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
postExport = '/system/post/export',
|
||||
@@ -19,7 +19,7 @@ enum Api {
|
||||
* @returns Post[]
|
||||
*/
|
||||
export function postList(params?: PageQuery) {
|
||||
return requestClient.get<Post[]>(Api.postList, { params });
|
||||
return alovaInstance.get<Post[]>(Api.postList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ export function postExport(data: Partial<Post>) {
|
||||
* @returns 岗位信息
|
||||
*/
|
||||
export function postInfo(postId: ID) {
|
||||
return requestClient.get<Post>(`${Api.root}/${postId}`);
|
||||
return alovaInstance.get<Post>(`${Api.root}/${postId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ export function postInfo(postId: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function postAdd(data: Partial<Post>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ export function postAdd(data: Partial<Post>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function postUpdate(data: Partial<Post>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ export function postUpdate(data: Partial<Post>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function postRemove(postIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${postIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${postIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ export function postRemove(postIds: IDS) {
|
||||
* @returns 岗位
|
||||
*/
|
||||
export function postOptionSelect(deptId: ID) {
|
||||
return requestClient.get<Post[]>(Api.postSelect, { params: { deptId } });
|
||||
return alovaInstance.get<Post[]>(Api.postSelect, { params: { deptId } });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,5 +81,5 @@ export function postOptionSelect(deptId: ID) {
|
||||
* @returns 部门树
|
||||
*/
|
||||
export function postDeptTreeSelect() {
|
||||
return requestClient.get<DeptTree[]>('/system/post/deptTree');
|
||||
return alovaInstance.get<DeptTree[]>('/system/post/deptTree');
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { FileCallBack, UpdatePasswordParam, UserProfile } from './model';
|
||||
|
||||
import { buildUUID } from '@vben/utils';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
root = '/system/user/profile',
|
||||
@@ -15,7 +15,7 @@ enum Api {
|
||||
* @returns userInformation
|
||||
*/
|
||||
export function userProfile() {
|
||||
return requestClient.get<UserProfile>(Api.root);
|
||||
return alovaInstance.get<UserProfile>(Api.root);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ export function userProfile() {
|
||||
* @returns void
|
||||
*/
|
||||
export function userProfileUpdate(data: any) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ export function userProfileUpdate(data: any) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userUpdatePassword(data: UpdatePasswordParam) {
|
||||
return requestClient.putWithMsg<void>(Api.updatePassword, data, {
|
||||
return alovaInstance.putWithMsg<void>(Api.updatePassword, data, {
|
||||
encrypt: true,
|
||||
});
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export function userUpdateAvatar(fileCallback: FileCallBack) {
|
||||
file = filename
|
||||
? new File([file], filename)
|
||||
: new File([file], `${buildUUID()}.png`);
|
||||
return requestClient.post(
|
||||
return alovaInstance.post(
|
||||
Api.updateAvatar,
|
||||
{
|
||||
avatarfile: file,
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { DeptResp, Role } from './model';
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
roleAllocatedList = '/system/role/authUser/allocatedList',
|
||||
@@ -27,7 +27,7 @@ enum Api {
|
||||
* @returns 分页列表
|
||||
*/
|
||||
export function roleList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<Role>>(Api.roleList, { params });
|
||||
return alovaInstance.get<PageResult<Role>>(Api.roleList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ export function roleExport(data: Partial<Role>) {
|
||||
* @returns 角色信息
|
||||
*/
|
||||
export function roleInfo(roleId: ID) {
|
||||
return requestClient.get<Role>(`${Api.root}/${roleId}`);
|
||||
return alovaInstance.get<Role>(`${Api.root}/${roleId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ export function roleInfo(roleId: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleAdd(data: Partial<Role>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ export function roleAdd(data: Partial<Role>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleUpdate(data: Partial<Role>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ export function roleChangeStatus(data: Partial<Role>) {
|
||||
roleId: data.roleId,
|
||||
status: data.status,
|
||||
};
|
||||
return requestClient.putWithMsg<void>(Api.roleChangeStatus, requestData);
|
||||
return alovaInstance.putWithMsg<void>(Api.roleChangeStatus, requestData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ export function roleChangeStatus(data: Partial<Role>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleRemove(roleIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${roleIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${roleIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,14 +94,14 @@ export function roleRemove(roleIds: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleDataScope(data: any) {
|
||||
return requestClient.putWithMsg<void>(Api.roleDataScope, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.roleDataScope, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 全局并没有用到这个方法
|
||||
*/
|
||||
export function roleOptionSelect(params?: any) {
|
||||
return requestClient.get(Api.roleOptionSelect, { params });
|
||||
return alovaInstance.get(Api.roleOptionSelect, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,7 @@ export function roleOptionSelect(params?: any) {
|
||||
* @returns 分页
|
||||
*/
|
||||
export function roleAllocatedList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<User>>(Api.roleAllocatedList, { params });
|
||||
return alovaInstance.get<PageResult<User>>(Api.roleAllocatedList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ export function roleAllocatedList(params?: PageQuery) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleUnallocatedList(params: any) {
|
||||
return requestClient.get<PageResult<User>>(Api.roleUnallocatedList, {
|
||||
return alovaInstance.get<PageResult<User>>(Api.roleUnallocatedList, {
|
||||
params,
|
||||
});
|
||||
}
|
||||
@@ -129,7 +129,7 @@ export function roleUnallocatedList(params: any) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleAuthCancel(data: { roleId: ID; userId: ID }) {
|
||||
return requestClient.putWithMsg<void>(Api.roleAuthCancel, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.roleAuthCancel, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +139,7 @@ export function roleAuthCancel(data: { roleId: ID; userId: ID }) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleAuthCancelAll(roleId: ID, userIds: IDS) {
|
||||
return requestClient.putWithMsg<void>(
|
||||
return alovaInstance.putWithMsg<void>(
|
||||
`${Api.roleAuthCancelAll}?roleId=${roleId}&userIds=${userIds.join(',')}`,
|
||||
);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ export function roleAuthCancelAll(roleId: ID, userIds: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function roleSelectAll(roleId: ID, userIds: IDS) {
|
||||
return requestClient.putWithMsg<void>(
|
||||
return alovaInstance.putWithMsg<void>(
|
||||
`${Api.roleAuthSelectAll}?roleId=${roleId}&userIds=${userIds.join(',')}`,
|
||||
);
|
||||
}
|
||||
@@ -162,5 +162,5 @@ export function roleSelectAll(roleId: ID, userIds: IDS) {
|
||||
* @returns DeptResp
|
||||
*/
|
||||
export function roleDeptTree(roleId: ID) {
|
||||
return requestClient.get<DeptResp>(`${Api.roleDeptTree}/${roleId}`);
|
||||
return alovaInstance.get<DeptResp>(`${Api.roleDeptTree}/${roleId}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { SocialInfo } from './model';
|
||||
|
||||
import type { ID } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
root = '/system/social',
|
||||
@@ -14,12 +14,12 @@ enum Api {
|
||||
* @returns info
|
||||
*/
|
||||
export function socialList() {
|
||||
return requestClient.get<SocialInfo[]>(Api.socialList);
|
||||
return alovaInstance.get<SocialInfo[]>(Api.socialList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 并没有用到这个方法
|
||||
*/
|
||||
export function socialInfo(id: ID) {
|
||||
return requestClient.get(`${Api.root}/${id}`);
|
||||
return alovaInstance.get(`${Api.root}/${id}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { TenantPackage } from './model';
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
packageChangeStatus = '/system/tenant/package/changeStatus',
|
||||
@@ -19,7 +19,7 @@ enum Api {
|
||||
* @returns 分页列表
|
||||
*/
|
||||
export function packageList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TenantPackage>>(Api.packageList, {
|
||||
return alovaInstance.get<PageResult<TenantPackage>>(Api.packageList, {
|
||||
params,
|
||||
});
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export function packageList(params?: PageQuery) {
|
||||
* @returns 下拉框
|
||||
*/
|
||||
export function packageSelectList() {
|
||||
return requestClient.get<TenantPackage[]>(Api.packageSelectList);
|
||||
return alovaInstance.get<TenantPackage[]>(Api.packageSelectList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ export function packageExport(data: Partial<TenantPackage>) {
|
||||
* @returns 信息
|
||||
*/
|
||||
export function packageInfo(id: ID) {
|
||||
return requestClient.get<TenantPackage>(`${Api.root}/${id}`);
|
||||
return alovaInstance.get<TenantPackage>(`${Api.root}/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ export function packageInfo(id: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function packageAdd(data: Partial<TenantPackage>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ export function packageAdd(data: Partial<TenantPackage>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function packageUpdate(data: Partial<TenantPackage>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ export function packageChangeStatus(data: Partial<TenantPackage>) {
|
||||
packageId: data.packageId,
|
||||
status: data.status,
|
||||
};
|
||||
return requestClient.putWithMsg<void>(Api.packageChangeStatus, packageId);
|
||||
return alovaInstance.putWithMsg<void>(Api.packageChangeStatus, packageId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,5 +87,5 @@ export function packageChangeStatus(data: Partial<TenantPackage>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function packageRemove(ids: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${ids}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${ids}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Tenant } from './model';
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
dictSync = '/system/tenant/syncTenantDict',
|
||||
@@ -22,7 +22,7 @@ enum Api {
|
||||
* @returns 分页
|
||||
*/
|
||||
export function tenantList(params?: PageQuery) {
|
||||
return requestClient.get<Tenant[]>(Api.tenantList, { params });
|
||||
return alovaInstance.get<Tenant[]>(Api.tenantList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ export function tenantExport(data: Partial<Tenant>) {
|
||||
* @returns 租户信息
|
||||
*/
|
||||
export function tenantInfo(id: ID) {
|
||||
return requestClient.get<Tenant>(`${Api.root}/${id}`);
|
||||
return alovaInstance.get<Tenant>(`${Api.root}/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ export function tenantInfo(id: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function tenantAdd(data: Partial<Tenant>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data, { encrypt: true });
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data, { encrypt: true });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ export function tenantAdd(data: Partial<Tenant>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function tenantUpdate(data: Partial<Tenant>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ export function tenantStatusChange(data: Partial<Tenant>) {
|
||||
tenantId: data.tenantId,
|
||||
status: data.status,
|
||||
};
|
||||
return requestClient.putWithMsg(Api.tenantStatus, requestData);
|
||||
return alovaInstance.putWithMsg(Api.tenantStatus, requestData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ export function tenantStatusChange(data: Partial<Tenant>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function tenantRemove(ids: IDS) {
|
||||
return requestClient.deleteWithMsg(`${Api.root}/${ids}`);
|
||||
return alovaInstance.deleteWithMsg(`${Api.root}/${ids}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ export function tenantRemove(ids: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function tenantDynamicToggle(tenantId: string) {
|
||||
return requestClient.get<void>(`${Api.tenantDynamic}/${tenantId}`);
|
||||
return alovaInstance.get<void>(`${Api.tenantDynamic}/${tenantId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ export function tenantDynamicToggle(tenantId: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function tenantDynamicClear() {
|
||||
return requestClient.get<void>(Api.tenantDynamicClear);
|
||||
return alovaInstance.get<void>(Api.tenantDynamicClear);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ export function tenantDynamicClear() {
|
||||
* @returns void
|
||||
*/
|
||||
export function tenantSyncPackage(tenantId: string, packageId: string) {
|
||||
return requestClient.get<void>(Api.tenantSyncPackage, {
|
||||
return alovaInstance.get<void>(Api.tenantSyncPackage, {
|
||||
params: { packageId, tenantId },
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
@@ -120,7 +120,7 @@ export function tenantSyncPackage(tenantId: string, packageId: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function dictSyncTenant(tenantId?: string) {
|
||||
return requestClient.get<void>(Api.dictSync, {
|
||||
return alovaInstance.get<void>(Api.dictSync, {
|
||||
params: { tenantId },
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
@@ -131,7 +131,7 @@ export function dictSyncTenant(tenantId?: string) {
|
||||
* @returns void
|
||||
*/
|
||||
export function syncTenantConfig() {
|
||||
return requestClient.get<void>('/system/tenant/syncTenantConfig', {
|
||||
return alovaInstance.get<void>('/system/tenant/syncTenantConfig', {
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import type {
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport, ContentTypeEnum } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
deptTree = '/system/user/deptTree',
|
||||
@@ -30,7 +30,7 @@ enum Api {
|
||||
* @returns User
|
||||
*/
|
||||
export function userList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<User>>(Api.userList, { params });
|
||||
return alovaInstance.get<PageResult<User>>(Api.userList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ export function userExport(data: Partial<User>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userImportData(data: UserImportParam) {
|
||||
return requestClient.post<{ code: number; msg: string }>(
|
||||
return alovaInstance.post<{ code: number; msg: string }>(
|
||||
Api.userImport,
|
||||
data,
|
||||
{
|
||||
@@ -65,7 +65,7 @@ export function userImportData(data: UserImportParam) {
|
||||
* @returns blob
|
||||
*/
|
||||
export function downloadImportTemplate() {
|
||||
return requestClient.post<Blob>(
|
||||
return alovaInstance.post<Blob>(
|
||||
Api.userImportTemplate,
|
||||
{},
|
||||
{
|
||||
@@ -83,7 +83,7 @@ export function downloadImportTemplate() {
|
||||
*/
|
||||
export function findUserInfo(userId?: ID) {
|
||||
const url = userId ? `${Api.root}/${userId}` : `${Api.root}/`;
|
||||
return requestClient.get<UserInfoResponse>(url);
|
||||
return alovaInstance.get<UserInfoResponse>(url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ export function findUserInfo(userId?: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userAdd(data: Partial<User>) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ export function userAdd(data: Partial<User>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userUpdate(data: Partial<User>) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
return alovaInstance.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ export function userStatusChange(data: Partial<User>) {
|
||||
userId: data.userId,
|
||||
status: data.status,
|
||||
};
|
||||
return requestClient.putWithMsg<void>(Api.userStatusChange, requestData);
|
||||
return alovaInstance.putWithMsg<void>(Api.userStatusChange, requestData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +123,7 @@ export function userStatusChange(data: Partial<User>) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userRemove(userIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`${Api.root}/${userIds}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`${Api.root}/${userIds}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ export function userRemove(userIds: IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userResetPassword(data: ResetPwdParam) {
|
||||
return requestClient.putWithMsg<void>(Api.userResetPassword, data, {
|
||||
return alovaInstance.putWithMsg<void>(Api.userResetPassword, data, {
|
||||
encrypt: true,
|
||||
});
|
||||
}
|
||||
@@ -143,7 +143,7 @@ export function userResetPassword(data: ResetPwdParam) {
|
||||
* @returns void
|
||||
*/
|
||||
export function getUserAuthRole(userId: ID) {
|
||||
return requestClient.get(`${Api.userAuthRole}/${userId}`);
|
||||
return alovaInstance.get(`${Api.userAuthRole}/${userId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +152,7 @@ export function getUserAuthRole(userId: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function userAuthRoleUpdate(userId: ID, roleIds: number[]) {
|
||||
return requestClient.putWithMsg(Api.userAuthRole, { roleIds, userId });
|
||||
return alovaInstance.putWithMsg(Api.userAuthRole, { roleIds, userId });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,12 +160,12 @@ export function userAuthRoleUpdate(userId: ID, roleIds: number[]) {
|
||||
* @returns 部门树数组
|
||||
*/
|
||||
export function getDeptTree() {
|
||||
return requestClient.get<DeptTree[]>(Api.deptTree);
|
||||
return alovaInstance.get<DeptTree[]>(Api.deptTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门下的所有用户信息
|
||||
*/
|
||||
export function listUserByDeptId(deptId: ID) {
|
||||
return requestClient.get<User[]>(`${Api.listDeptUsers}/${deptId}`);
|
||||
return alovaInstance.get<User[]>(`${Api.listDeptUsers}/${deptId}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { GenInfo } from './model';
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { ContentTypeEnum } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
batchGenCode = '/tool/gen/batchGenCode',
|
||||
@@ -20,22 +20,22 @@ enum Api {
|
||||
}
|
||||
// 查询代码生成列表
|
||||
export function generatedList(params?: PageQuery) {
|
||||
return requestClient.get(Api.generatedList, { params });
|
||||
return alovaInstance.get(Api.generatedList, { params });
|
||||
}
|
||||
|
||||
// 修改代码生成业务
|
||||
export function genInfo(tableId: ID) {
|
||||
return requestClient.get<GenInfo>(`${Api.root}/${tableId}`);
|
||||
return alovaInstance.get<GenInfo>(`${Api.root}/${tableId}`);
|
||||
}
|
||||
|
||||
// 查询数据库列表
|
||||
export function readyToGenList(params?: PageQuery) {
|
||||
return requestClient.get(Api.readyToGenList, { params });
|
||||
return alovaInstance.get(Api.readyToGenList, { params });
|
||||
}
|
||||
|
||||
// 查询数据表字段列表
|
||||
export function columnList(tableId: ID) {
|
||||
return requestClient.get(`${Api.columnList}/${tableId}`);
|
||||
return alovaInstance.get(`${Api.columnList}/${tableId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ export function columnList(tableId: ID) {
|
||||
* @returns ret
|
||||
*/
|
||||
export function importTable(tables: string | string[], dataName: string) {
|
||||
return requestClient.postWithMsg(
|
||||
return alovaInstance.postWithMsg(
|
||||
Api.importTable,
|
||||
{ dataName, tables },
|
||||
{
|
||||
@@ -56,41 +56,41 @@ export function importTable(tables: string | string[], dataName: string) {
|
||||
|
||||
// 修改保存代码生成业务
|
||||
export function editSave(data: any) {
|
||||
return requestClient.putWithMsg(Api.root, data);
|
||||
return alovaInstance.putWithMsg(Api.root, data);
|
||||
}
|
||||
|
||||
// 删除代码生成
|
||||
export function genRemove(tableIds: IDS) {
|
||||
return requestClient.deleteWithMsg(`${Api.root}/${tableIds}`);
|
||||
return alovaInstance.deleteWithMsg(`${Api.root}/${tableIds}`);
|
||||
}
|
||||
|
||||
// 预览代码
|
||||
export function previewCode(tableId: ID) {
|
||||
return requestClient.get<{ [key: string]: string }>(
|
||||
return alovaInstance.get<{ [key: string]: string }>(
|
||||
`${Api.preview}/${tableId}`,
|
||||
);
|
||||
}
|
||||
|
||||
// 生成代码(下载方式)
|
||||
export function genDownload(tableId: ID) {
|
||||
return requestClient.get<Blob>(`${Api.download}/${tableId}`);
|
||||
return alovaInstance.get<Blob>(`${Api.download}/${tableId}`);
|
||||
}
|
||||
|
||||
// 生成代码(自定义路径)
|
||||
export function genWithPath(tableId: ID) {
|
||||
return requestClient.get<void>(`${Api.genCode}/${tableId}`);
|
||||
return alovaInstance.get<void>(`${Api.genCode}/${tableId}`);
|
||||
}
|
||||
|
||||
// 同步数据库
|
||||
export function syncDb(tableId: ID) {
|
||||
return requestClient.get(`${Api.syncDb}/${tableId}`, {
|
||||
return alovaInstance.get(`${Api.syncDb}/${tableId}`, {
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
}
|
||||
|
||||
// 批量生成代码
|
||||
export function batchGenCode(tableIdStr: ID | IDS) {
|
||||
return requestClient.get<Blob>(Api.batchGenCode, {
|
||||
return alovaInstance.get<Blob>(Api.batchGenCode, {
|
||||
isTransformResponse: false,
|
||||
params: { tableIdStr },
|
||||
responseType: 'blob',
|
||||
@@ -99,5 +99,5 @@ export function batchGenCode(tableIdStr: ID | IDS) {
|
||||
|
||||
// 查询数据源名称列表
|
||||
export function getDataSourceNames() {
|
||||
return requestClient.get<string[]>(Api.dataSourceNames);
|
||||
return alovaInstance.get<string[]>(Api.dataSourceNames);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ import type {
|
||||
|
||||
import type { ID, IDS } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 获取流程分类树列表
|
||||
* @returns tree
|
||||
*/
|
||||
export function categoryTree() {
|
||||
return requestClient.get<CategoryTree[]>('/workflow/category/categoryTree');
|
||||
return alovaInstance.get<CategoryTree[]>('/workflow/category/categoryTree');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ export function categoryTree() {
|
||||
* @returns 流程分类列表
|
||||
*/
|
||||
export function categoryList(params?: CategoryQuery) {
|
||||
return requestClient.get<CategoryVO[]>(`/workflow/category/list`, { params });
|
||||
return alovaInstance.get<CategoryVO[]>(`/workflow/category/list`, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ export function categoryList(params?: CategoryQuery) {
|
||||
* @returns 流程分类详情
|
||||
*/
|
||||
export function categoryInfo(id: ID) {
|
||||
return requestClient.get<CategoryVO>(`/workflow/category/${id}`);
|
||||
return alovaInstance.get<CategoryVO>(`/workflow/category/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ export function categoryInfo(id: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function categoryAdd(data: CategoryForm) {
|
||||
return requestClient.postWithMsg<void>('/workflow/category', data);
|
||||
return alovaInstance.postWithMsg<void>('/workflow/category', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ export function categoryAdd(data: CategoryForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function categoryUpdate(data: CategoryForm) {
|
||||
return requestClient.putWithMsg<void>('/workflow/category', data);
|
||||
return alovaInstance.putWithMsg<void>('/workflow/category', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,5 +59,5 @@ export function categoryUpdate(data: CategoryForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function categoryRemove(id: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/workflow/category/${id}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`/workflow/category/${id}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ProcessDefinition } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 全部的流程定义
|
||||
@@ -10,7 +10,7 @@ import { requestClient } from '#/api/request';
|
||||
* @returns 分页
|
||||
*/
|
||||
export function workflowDefinitionList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<ProcessDefinition>>(
|
||||
return alovaInstance.get<PageResult<ProcessDefinition>>(
|
||||
'/workflow/definition/list',
|
||||
{ params },
|
||||
);
|
||||
@@ -22,7 +22,7 @@ export function workflowDefinitionList(params?: PageQuery) {
|
||||
* @returns 分页
|
||||
*/
|
||||
export function unPublishList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<ProcessDefinition>>(
|
||||
return alovaInstance.get<PageResult<ProcessDefinition>>(
|
||||
'/workflow/definition/unPublishList',
|
||||
{ params },
|
||||
);
|
||||
@@ -34,7 +34,7 @@ export function unPublishList(params?: PageQuery) {
|
||||
* @returns ProcessDefinition[]
|
||||
*/
|
||||
export function getHisListByKey(flowCode: string) {
|
||||
return requestClient.get<ProcessDefinition[]>(
|
||||
return alovaInstance.get<ProcessDefinition[]>(
|
||||
`/workflow/definition/getHisListByKey/${flowCode}`,
|
||||
);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ export function getHisListByKey(flowCode: string) {
|
||||
* @returns ProcessDefinition
|
||||
*/
|
||||
export function workflowDefinitionInfo(id: ID) {
|
||||
return requestClient.get<ProcessDefinition>(`/workflow/definition/${id}`);
|
||||
return alovaInstance.get<ProcessDefinition>(`/workflow/definition/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ export function workflowDefinitionInfo(id: ID) {
|
||||
* @param data
|
||||
*/
|
||||
export function workflowDefinitionAdd(data: any) {
|
||||
return requestClient.postWithMsg<void>('/workflow/definition', data);
|
||||
return alovaInstance.postWithMsg<void>('/workflow/definition', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ export function workflowDefinitionAdd(data: any) {
|
||||
* @param data
|
||||
*/
|
||||
export function workflowDefinitionUpdate(data: any) {
|
||||
return requestClient.putWithMsg<void>('/workflow/definition', data);
|
||||
return alovaInstance.putWithMsg<void>('/workflow/definition', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ export function workflowDefinitionUpdate(data: any) {
|
||||
* @returns boolean
|
||||
*/
|
||||
export function workflowDefinitionPublish(id: ID) {
|
||||
return requestClient.putWithMsg<boolean>(
|
||||
return alovaInstance.putWithMsg<boolean>(
|
||||
`/workflow/definition/publish/${id}`,
|
||||
);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export function workflowDefinitionPublish(id: ID) {
|
||||
* @returns boolean
|
||||
*/
|
||||
export function workflowDefinitionUnPublish(id: ID) {
|
||||
return requestClient.putWithMsg<boolean>(
|
||||
return alovaInstance.putWithMsg<boolean>(
|
||||
`/workflow/definition/unPublish/${id}`,
|
||||
);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ export function workflowDefinitionUnPublish(id: ID) {
|
||||
* @param ids idList
|
||||
*/
|
||||
export function workflowDefinitionDelete(ids: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/workflow/definition/${ids}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`/workflow/definition/${ids}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ export function workflowDefinitionDelete(ids: IDS) {
|
||||
* @param id id
|
||||
*/
|
||||
export function workflowDefinitionCopy(id: ID) {
|
||||
return requestClient.postWithMsg<void>(`/workflow/definition/copy/${id}`);
|
||||
return alovaInstance.postWithMsg<void>(`/workflow/definition/copy/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,7 @@ export function workflowDefinitionImport(data: {
|
||||
category: ID;
|
||||
file: Blob | File;
|
||||
}) {
|
||||
return requestClient.postWithMsg<boolean>(
|
||||
return alovaInstance.postWithMsg<boolean>(
|
||||
'/workflow/definition/importDef',
|
||||
data,
|
||||
{ headers: { 'Content-Type': 'multipart/form-data' } },
|
||||
@@ -123,7 +123,7 @@ export function workflowDefinitionImport(data: {
|
||||
* @returns blob
|
||||
*/
|
||||
export function workflowDefinitionExport(id: ID) {
|
||||
return requestClient.postWithMsg<Blob>(
|
||||
return alovaInstance.postWithMsg<Blob>(
|
||||
`/workflow/definition/exportDef/${id}`,
|
||||
{},
|
||||
{
|
||||
@@ -139,7 +139,7 @@ export function workflowDefinitionExport(id: ID) {
|
||||
* @returns xml
|
||||
*/
|
||||
export function workflowDefinitionXml(id: ID) {
|
||||
return requestClient.get<string>(`/workflow/definition/xmlString/${id}`);
|
||||
return alovaInstance.get<string>(`/workflow/definition/xmlString/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +149,7 @@ export function workflowDefinitionXml(id: ID) {
|
||||
* @returns boolean
|
||||
*/
|
||||
export function workflowDefinitionActive(id: ID, active: boolean) {
|
||||
return requestClient.putWithMsg<boolean>(
|
||||
return alovaInstance.putWithMsg<boolean>(
|
||||
`/workflow/definition/active/${id}?active=${active}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ import type { FlowInfoResponse, FlowInstanceVariableResp } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* @param businessId 业务ID
|
||||
* @returns TaskInfo
|
||||
*/
|
||||
export function getTaskByBusinessId(businessId: string) {
|
||||
return requestClient.get<TaskInfo>(
|
||||
return alovaInstance.get<TaskInfo>(
|
||||
`/workflow/instance/getInfo/${businessId}`,
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export function getTaskByBusinessId(businessId: string) {
|
||||
* @returns
|
||||
*/
|
||||
export function pageByRunning(params?: PageQuery) {
|
||||
return requestClient.get('/workflow/instance/pageByRunning', { params });
|
||||
return alovaInstance.get('/workflow/instance/pageByRunning', { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ export function pageByRunning(params?: PageQuery) {
|
||||
* @returns
|
||||
*/
|
||||
export function pageByFinish(params?: PageQuery) {
|
||||
return requestClient.get('/workflow/instance/pageByFinish', { params });
|
||||
return alovaInstance.get('/workflow/instance/pageByFinish', { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ export function pageByFinish(params?: PageQuery) {
|
||||
* @param businessIds 业务id
|
||||
*/
|
||||
export function deleteByBusinessIds(businessIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(
|
||||
return alovaInstance.deleteWithMsg<void>(
|
||||
`/workflow/instance/deleteByBusinessIds${businessIds}`,
|
||||
);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ export function deleteByBusinessIds(businessIds: IDS) {
|
||||
* @param instanceIds 实例id
|
||||
*/
|
||||
export function deleteByInstanceIds(instanceIds: IDS) {
|
||||
return requestClient.deleteWithMsg<void>(
|
||||
return alovaInstance.deleteWithMsg<void>(
|
||||
`/workflow/instance/deleteByInstanceIds/${instanceIds}`,
|
||||
);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export function deleteByInstanceIds(instanceIds: IDS) {
|
||||
* @param data
|
||||
*/
|
||||
export function cancelProcessApply(data: { businessId: ID; message?: string }) {
|
||||
return requestClient.putWithMsg<void>(
|
||||
return alovaInstance.putWithMsg<void>(
|
||||
'/workflow/instance/cancelProcessApply',
|
||||
data,
|
||||
);
|
||||
@@ -70,7 +70,7 @@ export function cancelProcessApply(data: { businessId: ID; message?: string }) {
|
||||
* @param active
|
||||
*/
|
||||
export function workflowInstanceActive(instanceId: ID, active: boolean) {
|
||||
return requestClient.putWithMsg<void>(
|
||||
return alovaInstance.putWithMsg<void>(
|
||||
`/workflow/instance/active/${instanceId}?active=${active}`,
|
||||
);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export function workflowInstanceActive(instanceId: ID, active: boolean) {
|
||||
* @returns PageResult<Flow>
|
||||
*/
|
||||
export function pageByCurrent(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TaskInfo>>(
|
||||
return alovaInstance.get<PageResult<TaskInfo>>(
|
||||
'/workflow/instance/pageByCurrent',
|
||||
{ params },
|
||||
);
|
||||
@@ -93,7 +93,7 @@ export function pageByCurrent(params?: PageQuery) {
|
||||
* @returns 流程图,流程记录
|
||||
*/
|
||||
export function flowInfo(businessId: string) {
|
||||
return requestClient.get<FlowInfoResponse>(
|
||||
return alovaInstance.get<FlowInfoResponse>(
|
||||
`/workflow/instance/flowHisTaskList/${businessId}`,
|
||||
);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export function flowInfo(businessId: string) {
|
||||
* @returns Map<string,any>
|
||||
*/
|
||||
export function instanceVariable(instanceId: string) {
|
||||
return requestClient.get<FlowInstanceVariableResp>(
|
||||
return alovaInstance.get<FlowInstanceVariableResp>(
|
||||
`/workflow/instance/instanceVariable/${instanceId}`,
|
||||
);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export function workflowInstanceInvalid(data: {
|
||||
comment?: string;
|
||||
id: string;
|
||||
}) {
|
||||
return requestClient.postWithMsg<void>('/workflow/instance/invalid', data);
|
||||
return alovaInstance.postWithMsg<void>('/workflow/instance/invalid', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ export function updateFlowVariable(data: {
|
||||
key: string;
|
||||
value: any;
|
||||
}) {
|
||||
return requestClient.putWithMsg<void>(
|
||||
return alovaInstance.putWithMsg<void>(
|
||||
'/workflow/instance/updateVariable',
|
||||
data,
|
||||
);
|
||||
|
||||
@@ -2,24 +2,24 @@ import type { Spel } from './model';
|
||||
|
||||
import type { ID, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
export function spelList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<Spel>>('/workflow/spel/list', { params });
|
||||
return alovaInstance.get<PageResult<Spel>>('/workflow/spel/list', { params });
|
||||
}
|
||||
|
||||
export function spelInfo(id: ID) {
|
||||
return requestClient.get<Spel>(`/workflow/spel/${id}`);
|
||||
return alovaInstance.get<Spel>(`/workflow/spel/${id}`);
|
||||
}
|
||||
|
||||
export function spelAdd(data: Partial<Spel>) {
|
||||
return requestClient.postWithMsg<Spel>('/workflow/spel', data);
|
||||
return alovaInstance.postWithMsg<Spel>('/workflow/spel', data);
|
||||
}
|
||||
|
||||
export function spelUpdate(data: Partial<Spel>) {
|
||||
return requestClient.putWithMsg<Spel>('/workflow/spel', data);
|
||||
return alovaInstance.putWithMsg<Spel>('/workflow/spel', data);
|
||||
}
|
||||
|
||||
export function spelDelete(ids: ID[]) {
|
||||
return requestClient.deleteWithMsg<Spel>(`/workflow/spel/${ids}`);
|
||||
return alovaInstance.deleteWithMsg<Spel>(`/workflow/spel/${ids}`);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ import type {
|
||||
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 启动任务
|
||||
* @param data
|
||||
*/
|
||||
export function startWorkFlow(data: StartWorkFlowReqData) {
|
||||
return requestClient.post<{
|
||||
return alovaInstance.post<{
|
||||
processInstanceId: string;
|
||||
taskId: string;
|
||||
}>('/workflow/task/startWorkFlow', data);
|
||||
@@ -27,7 +27,7 @@ export function startWorkFlow(data: StartWorkFlowReqData) {
|
||||
* @param data
|
||||
*/
|
||||
export function completeTask(data: CompleteTaskReqData) {
|
||||
return requestClient.postWithMsg<void>('/workflow/task/completeTask', data);
|
||||
return alovaInstance.postWithMsg<void>('/workflow/task/completeTask', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ export function completeTask(data: CompleteTaskReqData) {
|
||||
* @param params
|
||||
*/
|
||||
export function pageByTaskWait(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TaskInfo>>(
|
||||
return alovaInstance.get<PageResult<TaskInfo>>(
|
||||
'/workflow/task/pageByTaskWait',
|
||||
{ params },
|
||||
);
|
||||
@@ -46,7 +46,7 @@ export function pageByTaskWait(params?: PageQuery) {
|
||||
* @param params
|
||||
*/
|
||||
export function pageByTaskFinish(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TaskInfo>>(
|
||||
return alovaInstance.get<PageResult<TaskInfo>>(
|
||||
'/workflow/task/pageByTaskFinish',
|
||||
{ params },
|
||||
);
|
||||
@@ -57,7 +57,7 @@ export function pageByTaskFinish(params?: PageQuery) {
|
||||
* @param params
|
||||
*/
|
||||
export function pageByAllTaskWait(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TaskInfo>>(
|
||||
return alovaInstance.get<PageResult<TaskInfo>>(
|
||||
'/workflow/task/pageByAllTaskWait',
|
||||
{ params },
|
||||
);
|
||||
@@ -68,7 +68,7 @@ export function pageByAllTaskWait(params?: PageQuery) {
|
||||
* @param params
|
||||
*/
|
||||
export function pageByAllTaskFinish(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TaskInfo>>(
|
||||
return alovaInstance.get<PageResult<TaskInfo>>(
|
||||
'/workflow/task/pageByAllTaskFinish',
|
||||
{ params },
|
||||
);
|
||||
@@ -79,7 +79,7 @@ export function pageByAllTaskFinish(params?: PageQuery) {
|
||||
* @param params
|
||||
*/
|
||||
export function pageByTaskCopy(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<TaskInfo>>(
|
||||
return alovaInstance.get<PageResult<TaskInfo>>(
|
||||
'/workflow/task/pageByTaskCopy',
|
||||
{ params },
|
||||
);
|
||||
@@ -91,14 +91,14 @@ export function pageByTaskCopy(params?: PageQuery) {
|
||||
* @returns info
|
||||
*/
|
||||
export function getTaskByTaskId(taskId: string) {
|
||||
return requestClient.get<TaskInfo>(`/workflow/task/getTask/${taskId}`);
|
||||
return alovaInstance.get<TaskInfo>(`/workflow/task/getTask/${taskId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 终止任务
|
||||
*/
|
||||
export function terminationTask(data: { comment?: string; taskId: string }) {
|
||||
return requestClient.postWithMsg<void>(
|
||||
return alovaInstance.postWithMsg<void>(
|
||||
'/workflow/task/terminationTask',
|
||||
data,
|
||||
);
|
||||
@@ -113,7 +113,7 @@ export function taskOperation(
|
||||
taskOperationData: TaskOperationData,
|
||||
taskOperation: TaskOperationType,
|
||||
) {
|
||||
return requestClient.postWithMsg<void>(
|
||||
return alovaInstance.postWithMsg<void>(
|
||||
`/workflow/task/taskOperation/${taskOperation}`,
|
||||
taskOperationData,
|
||||
);
|
||||
@@ -125,7 +125,7 @@ export function taskOperation(
|
||||
* @param userId 办理人id
|
||||
*/
|
||||
export function updateAssignee(taskIdList: IDS, userId: ID) {
|
||||
return requestClient.putWithMsg<void>(
|
||||
return alovaInstance.putWithMsg<void>(
|
||||
`/workflow/task/updateAssignee/${userId}`,
|
||||
taskIdList,
|
||||
);
|
||||
@@ -136,7 +136,7 @@ export function updateAssignee(taskIdList: IDS, userId: ID) {
|
||||
* @param data 参数
|
||||
*/
|
||||
export function backProcess(data: any) {
|
||||
return requestClient.postWithMsg<void>('/workflow/task/backProcess', data);
|
||||
return alovaInstance.postWithMsg<void>('/workflow/task/backProcess', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ export function backProcess(data: any) {
|
||||
* @param nodeCode 当前节点编码
|
||||
*/
|
||||
export function getBackTaskNode(taskId: string, nodeCode: string) {
|
||||
return requestClient.get<{ nodeCode: string; nodeName: string }[]>(
|
||||
return alovaInstance.get<{ nodeCode: string; nodeName: string }[]>(
|
||||
`/workflow/task/getBackTaskNode/${taskId}/${nodeCode}`,
|
||||
);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export function getBackTaskNode(taskId: string, nodeCode: string) {
|
||||
* @param taskId 任务id
|
||||
*/
|
||||
export function currentTaskAllUser(taskId: ID) {
|
||||
return requestClient.get<any>(`/workflow/task/currentTaskAllUser/${taskId}`);
|
||||
return alovaInstance.get<any>(`/workflow/task/currentTaskAllUser/${taskId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +165,7 @@ export function currentTaskAllUser(taskId: ID) {
|
||||
* @returns NextNodeInfo
|
||||
*/
|
||||
export function getNextNodeList(data: { taskId: string }) {
|
||||
return requestClient.post<NextNodeInfo[]>(
|
||||
return alovaInstance.post<NextNodeInfo[]>(
|
||||
'/workflow/task/getNextNodeList',
|
||||
data,
|
||||
);
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
/**
|
||||
* @description: 旧版文件上传组件 使用FileUpload代替
|
||||
*/
|
||||
export { default as FileUploadOld } from './src/file-upload.vue';
|
||||
/**
|
||||
* @description: 旧版图片上传组件 使用ImageUpload代替
|
||||
*/
|
||||
export { default as ImageUploadOld } from './src/image-upload.vue';
|
||||
@@ -1,240 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { UploadFile, UploadProps } from 'antdv-next';
|
||||
import type { UploadRequestOption } from 'antdv-next/lib/vc-upload/interface';
|
||||
|
||||
import type { AxiosProgressEvent, UploadApi } from '#/api';
|
||||
|
||||
import { ref, toRefs, watch } from 'vue';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { UploadOutlined } from '@ant-design/icons-vue';
|
||||
import { Upload } from 'antdv-next';
|
||||
import { isArray, isFunction, isObject, isString } from 'lodash-es';
|
||||
|
||||
import { uploadApi } from '#/api';
|
||||
|
||||
import { checkFileType } from './helper';
|
||||
import { UploadResultStatus } from './typing';
|
||||
import { useUploadType } from './use-upload';
|
||||
|
||||
defineOptions({ name: 'FileUpload', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/**
|
||||
* 建议使用拓展名(不带.)
|
||||
* 或者文件头 image/png等(测试判断不准确) 不支持image/*类似的写法
|
||||
* 需自行改造 ./helper/checkFileType方法
|
||||
*/
|
||||
accept?: string[];
|
||||
api?: UploadApi;
|
||||
disabled?: boolean;
|
||||
helpText?: string;
|
||||
// 最大数量的文件,Infinity不限制
|
||||
maxNumber?: number;
|
||||
// 文件最大多少MB
|
||||
maxSize?: number;
|
||||
// 是否支持多选
|
||||
multiple?: boolean;
|
||||
// support xxx.xxx.xx
|
||||
// 返回的字段 默认url
|
||||
resultField?: 'fileName' | 'ossId' | 'url' | string;
|
||||
/**
|
||||
* 是否显示下面的描述
|
||||
*/
|
||||
showDescription?: boolean;
|
||||
value?: string[];
|
||||
}>(),
|
||||
{
|
||||
value: () => [],
|
||||
disabled: false,
|
||||
helpText: '',
|
||||
maxSize: 2,
|
||||
maxNumber: 1,
|
||||
accept: () => [],
|
||||
multiple: false,
|
||||
api: () => uploadApi,
|
||||
resultField: '',
|
||||
showDescription: true,
|
||||
},
|
||||
);
|
||||
const emit = defineEmits(['change', 'update:value', 'delete']);
|
||||
const { accept, helpText, maxNumber, maxSize } = toRefs(props);
|
||||
const isInnerOperate = ref<boolean>(false);
|
||||
const { getStringAccept } = useUploadType({
|
||||
acceptRef: accept,
|
||||
helpTextRef: helpText,
|
||||
maxNumberRef: maxNumber,
|
||||
maxSizeRef: maxSize,
|
||||
});
|
||||
|
||||
const fileList = ref<UploadProps['fileList']>([]);
|
||||
const isLtMsg = ref<boolean>(true);
|
||||
const isActMsg = ref<boolean>(true);
|
||||
const isFirstRender = ref<boolean>(true);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(v) => {
|
||||
if (isInnerOperate.value) {
|
||||
isInnerOperate.value = false;
|
||||
return;
|
||||
}
|
||||
let value: string[] = [];
|
||||
if (v) {
|
||||
if (isArray(v)) {
|
||||
value = v;
|
||||
} else {
|
||||
value.push(v);
|
||||
}
|
||||
fileList.value = value.map((item, i) => {
|
||||
if (item && isString(item)) {
|
||||
return {
|
||||
uid: `${-i}`,
|
||||
name: item.slice(Math.max(0, item.lastIndexOf('/') + 1)),
|
||||
status: 'done',
|
||||
url: item,
|
||||
};
|
||||
} else if (item && isObject(item)) {
|
||||
return item;
|
||||
}
|
||||
return null;
|
||||
}) as UploadProps['fileList'];
|
||||
}
|
||||
if (!isFirstRender.value) {
|
||||
emit('change', value);
|
||||
isFirstRender.value = false;
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
deep: true,
|
||||
},
|
||||
);
|
||||
|
||||
const handleRemove = async (file: UploadFile) => {
|
||||
if (fileList.value) {
|
||||
const index = fileList.value.findIndex((item) => item.uid === file.uid);
|
||||
index !== -1 && fileList.value.splice(index, 1);
|
||||
const value = getValue();
|
||||
isInnerOperate.value = true;
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
emit('delete', file);
|
||||
}
|
||||
};
|
||||
|
||||
const beforeUpload = async (file: File) => {
|
||||
const { maxSize, accept } = props;
|
||||
const isAct = await checkFileType(file, accept);
|
||||
if (!isAct) {
|
||||
window.message.error($t('component.upload.acceptUpload', [accept]));
|
||||
isActMsg.value = false;
|
||||
// 防止弹出多个错误提示
|
||||
setTimeout(() => (isActMsg.value = true), 1000);
|
||||
}
|
||||
const isLt = file.size / 1024 / 1024 > maxSize;
|
||||
if (isLt) {
|
||||
window.message.error($t('component.upload.maxSizeMultiple', [maxSize]));
|
||||
isLtMsg.value = false;
|
||||
// 防止弹出多个错误提示
|
||||
setTimeout(() => (isLtMsg.value = true), 1000);
|
||||
}
|
||||
return (isAct && !isLt) || Upload.LIST_IGNORE;
|
||||
};
|
||||
|
||||
async function customRequest(info: UploadRequestOption<any>) {
|
||||
const { api } = props;
|
||||
if (!api || !isFunction(api)) {
|
||||
console.warn('upload api must exist and be a function');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 进度条事件
|
||||
const progressEvent: AxiosProgressEvent = (e) => {
|
||||
const percent = Math.trunc((e.loaded / e.total!) * 100);
|
||||
info.onProgress!({ percent });
|
||||
};
|
||||
const res = await api?.(info.file as File, {
|
||||
onUploadProgress: progressEvent,
|
||||
});
|
||||
/**
|
||||
* 由getValue处理 传对象过去
|
||||
* 直接传string(id)会被转为Number
|
||||
* 内部的逻辑由requestClient.upload处理 这里不用判断业务状态码 不符合会自动reject
|
||||
*/
|
||||
info.onSuccess!(res);
|
||||
window.message.success($t('component.upload.uploadSuccess'));
|
||||
// 获取
|
||||
const value = getValue();
|
||||
isInnerOperate.value = true;
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
info.onError!(error);
|
||||
}
|
||||
}
|
||||
|
||||
function getValue() {
|
||||
const list = (fileList.value || [])
|
||||
.filter((item) => item?.status === UploadResultStatus.DONE)
|
||||
.map((item: any) => {
|
||||
if (item?.response && props?.resultField) {
|
||||
return item?.response?.[props.resultField];
|
||||
}
|
||||
// 适用于已经有图片 回显的情况 会默认在init处理为{url: 'xx'}
|
||||
if (item?.url) {
|
||||
return item.url;
|
||||
}
|
||||
// 注意这里取的key为 url
|
||||
return item?.response?.url;
|
||||
});
|
||||
return list;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Upload
|
||||
v-bind="$attrs"
|
||||
v-model:file-list="fileList"
|
||||
:accept="getStringAccept"
|
||||
:before-upload="beforeUpload"
|
||||
:custom-request="customRequest"
|
||||
:disabled="disabled"
|
||||
:max-count="maxNumber"
|
||||
:multiple="multiple"
|
||||
list-type="text"
|
||||
:progress="{ showInfo: true }"
|
||||
@remove="handleRemove"
|
||||
>
|
||||
<div v-if="fileList && fileList.length < maxNumber">
|
||||
<a-button>
|
||||
<UploadOutlined />
|
||||
{{ $t('component.upload.upload') }}
|
||||
</a-button>
|
||||
</div>
|
||||
<div v-if="showDescription" class="mt-2 flex flex-wrap items-center">
|
||||
请上传不超过
|
||||
<div class="mx-1 font-bold text-primary">{{ maxSize }}MB</div>
|
||||
的
|
||||
<div class="mx-1 font-bold text-primary">{{ accept.join('/') }}</div>
|
||||
格式文件
|
||||
</div>
|
||||
</Upload>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.ant-upload-select-picture-card i {
|
||||
font-size: 32px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.ant-upload-select-picture-card .ant-upload-text {
|
||||
margin-top: 8px;
|
||||
color: #666;
|
||||
}
|
||||
</style>
|
||||
@@ -1,51 +0,0 @@
|
||||
import { fileTypeFromBlob } from '@vben/utils';
|
||||
|
||||
/**
|
||||
* 不支持txt文件 @see https://github.com/sindresorhus/file-type/issues/55
|
||||
* 需要自行修改
|
||||
* @param file file对象
|
||||
* @param accepts 文件类型数组 包括拓展名(不带点) 文件头(image/png等 不包括泛写法即image/*)
|
||||
* @returns 是否通过文件类型校验
|
||||
*/
|
||||
export async function checkFileType(file: File, accepts: string[]) {
|
||||
if (!accepts || accepts?.length === 0) {
|
||||
return true;
|
||||
}
|
||||
console.log(file);
|
||||
const fileType = await fileTypeFromBlob(file);
|
||||
if (!fileType) {
|
||||
console.error('无法获取文件类型');
|
||||
return false;
|
||||
}
|
||||
console.log('文件类型', fileType);
|
||||
// 是否文件拓展名/文件头任意有一个匹配
|
||||
return accepts.includes(fileType.ext) || accepts.includes(fileType.mime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认图片类型
|
||||
*/
|
||||
export const defaultImageAccept = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
||||
/**
|
||||
* 判断文件类型是否符合要求
|
||||
* @param file file对象
|
||||
* @param accepts 文件类型数组 包括拓展名(不带点) 文件头(image/png等 不包括泛写法即image/*)
|
||||
* @returns 是否通过文件类型校验
|
||||
*/
|
||||
export async function checkImageFileType(file: File, accepts: string[]) {
|
||||
// 空的accepts 使用默认规则
|
||||
if (!accepts || accepts.length === 0) {
|
||||
accepts = defaultImageAccept;
|
||||
}
|
||||
const fileType = await fileTypeFromBlob(file);
|
||||
if (!fileType) {
|
||||
console.error('无法获取文件类型');
|
||||
return false;
|
||||
}
|
||||
console.log('文件类型', fileType);
|
||||
// 是否文件拓展名/文件头任意有一个匹配
|
||||
if (accepts.includes(fileType.ext) || accepts.includes(fileType.mime)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,323 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { UploadFile, UploadProps } from 'antdv-next';
|
||||
import type { UploadRequestOption } from 'antdv-next/lib/vc-upload/interface';
|
||||
|
||||
import type { AxiosProgressEvent, UploadApi } from '#/api';
|
||||
|
||||
import { ref, toRefs, watch } from 'vue';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { Modal, Upload } from 'antdv-next';
|
||||
import { isArray, isFunction, isObject, isString, uniqueId } from 'lodash-es';
|
||||
|
||||
import { uploadApi } from '#/api';
|
||||
import { ossInfo } from '#/api/system/oss';
|
||||
|
||||
import { checkImageFileType, defaultImageAccept } from './helper';
|
||||
import { UploadResultStatus } from './typing';
|
||||
import { useUploadType } from './use-upload';
|
||||
|
||||
defineOptions({ name: 'ImageUpload', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/**
|
||||
* 包括拓展名(不带点) 文件头(image/png等 不包括泛写法即image/*)
|
||||
*/
|
||||
accept?: string[];
|
||||
api?: UploadApi;
|
||||
disabled?: boolean;
|
||||
helpText?: string;
|
||||
|
||||
listType?: ListType;
|
||||
// 最大数量的文件,Infinity不限制
|
||||
maxNumber?: number;
|
||||
// 文件最大多少MB
|
||||
maxSize?: number;
|
||||
// 是否支持多选
|
||||
multiple?: boolean;
|
||||
// support xxx.xxx.xx
|
||||
// 返回的字段 默认url
|
||||
resultField?: 'fileName' | 'ossId' | 'url';
|
||||
/**
|
||||
* 是否显示下面的描述
|
||||
*/
|
||||
showDescription?: boolean;
|
||||
value?: string | string[];
|
||||
}>(),
|
||||
{
|
||||
value: () => [],
|
||||
disabled: false,
|
||||
listType: 'picture-card',
|
||||
helpText: '',
|
||||
maxSize: 2,
|
||||
maxNumber: 1,
|
||||
accept: () => defaultImageAccept,
|
||||
multiple: false,
|
||||
api: () => uploadApi,
|
||||
resultField: 'url',
|
||||
showDescription: true,
|
||||
},
|
||||
);
|
||||
const emit = defineEmits(['change', 'update:value', 'delete']);
|
||||
type ListType = 'picture' | 'picture-card' | 'text';
|
||||
const { accept, helpText, maxNumber, maxSize } = toRefs(props);
|
||||
const isInnerOperate = ref<boolean>(false);
|
||||
const { getStringAccept } = useUploadType({
|
||||
acceptRef: accept,
|
||||
helpTextRef: helpText,
|
||||
maxNumberRef: maxNumber,
|
||||
maxSizeRef: maxSize,
|
||||
});
|
||||
const previewOpen = ref<boolean>(false);
|
||||
const previewImage = ref<string>('');
|
||||
const previewTitle = ref<string>('');
|
||||
|
||||
const fileList = ref<UploadProps['fileList']>([]);
|
||||
const isLtMsg = ref<boolean>(true);
|
||||
const isActMsg = ref<boolean>(true);
|
||||
const isFirstRender = ref<boolean>(true);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
async (v) => {
|
||||
if (isInnerOperate.value) {
|
||||
isInnerOperate.value = false;
|
||||
return;
|
||||
}
|
||||
let value: string | string[] = [];
|
||||
if (v) {
|
||||
const _fileList: string[] = [];
|
||||
if (isString(v)) {
|
||||
_fileList.push(v);
|
||||
}
|
||||
if (isArray(v)) {
|
||||
_fileList.push(...v);
|
||||
}
|
||||
// 直接赋值 可能为string | string[]
|
||||
value = v;
|
||||
const withUrlList: UploadProps['fileList'] = [];
|
||||
for (const item of _fileList) {
|
||||
// ossId情况
|
||||
if (props.resultField === 'ossId') {
|
||||
const resp = await ossInfo([item]);
|
||||
if (item && isString(item)) {
|
||||
withUrlList.push({
|
||||
uid: item, // ossId作为uid 方便getValue获取
|
||||
name: item.slice(Math.max(0, item.lastIndexOf('/') + 1)),
|
||||
status: 'done',
|
||||
url: resp?.[0]?.url,
|
||||
});
|
||||
} else if (item && isObject(item)) {
|
||||
withUrlList.push({
|
||||
...(item as any),
|
||||
uid: item,
|
||||
url: resp?.[0]?.url,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 非ossId情况
|
||||
if (item && isString(item)) {
|
||||
withUrlList.push({
|
||||
uid: uniqueId(),
|
||||
name: item.slice(Math.max(0, item.lastIndexOf('/') + 1)),
|
||||
status: 'done',
|
||||
url: item,
|
||||
});
|
||||
} else if (item && isObject(item)) {
|
||||
withUrlList.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
fileList.value = withUrlList;
|
||||
}
|
||||
if (!isFirstRender.value) {
|
||||
emit('change', value);
|
||||
isFirstRender.value = false;
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
deep: true,
|
||||
},
|
||||
);
|
||||
|
||||
function getBase64<T extends ArrayBuffer | null | string>(file: File) {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.addEventListener('load', () => {
|
||||
resolve(reader.result as T);
|
||||
});
|
||||
reader.addEventListener('error', (error) => reject(error));
|
||||
});
|
||||
}
|
||||
|
||||
const handlePreview = async (file: UploadFile) => {
|
||||
if (!file.url && !file.preview) {
|
||||
file.preview = await getBase64<string>(file.originFileObj!);
|
||||
}
|
||||
previewImage.value = file.url || file.preview || '';
|
||||
previewOpen.value = true;
|
||||
previewTitle.value =
|
||||
file.name ||
|
||||
previewImage.value.slice(
|
||||
Math.max(0, previewImage.value.lastIndexOf('/') + 1),
|
||||
);
|
||||
};
|
||||
|
||||
const handleRemove = async (file: UploadFile) => {
|
||||
if (fileList.value) {
|
||||
const index = fileList.value.findIndex((item) => item.uid === file.uid);
|
||||
index !== -1 && fileList.value.splice(index, 1);
|
||||
const value = getValue();
|
||||
isInnerOperate.value = true;
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
emit('delete', file);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
previewOpen.value = false;
|
||||
previewTitle.value = '';
|
||||
};
|
||||
|
||||
const beforeUpload = async (file: File) => {
|
||||
const { maxSize, accept } = props;
|
||||
const isAct = await checkImageFileType(file, accept);
|
||||
if (!isAct) {
|
||||
window.message.error($t('component.upload.acceptUpload', [accept]));
|
||||
isActMsg.value = false;
|
||||
// 防止弹出多个错误提示
|
||||
setTimeout(() => (isActMsg.value = true), 1000);
|
||||
}
|
||||
const isLt = file.size / 1024 / 1024 > maxSize;
|
||||
if (isLt) {
|
||||
window.message.error($t('component.upload.maxSizeMultiple', [maxSize]));
|
||||
isLtMsg.value = false;
|
||||
// 防止弹出多个错误提示
|
||||
setTimeout(() => (isLtMsg.value = true), 1000);
|
||||
}
|
||||
return (isAct && !isLt) || Upload.LIST_IGNORE;
|
||||
};
|
||||
|
||||
async function customRequest(info: UploadRequestOption<any>) {
|
||||
const { api } = props;
|
||||
if (!api || !isFunction(api)) {
|
||||
console.warn('upload api must exist and be a function');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 进度条事件
|
||||
const progressEvent: AxiosProgressEvent = (e) => {
|
||||
const percent = Math.trunc((e.loaded / e.total!) * 100);
|
||||
info.onProgress!({ percent });
|
||||
};
|
||||
const res = await api?.(info.file as File, {
|
||||
onUploadProgress: progressEvent,
|
||||
});
|
||||
/**
|
||||
* 由getValue处理 传对象过去
|
||||
* 直接传string(id)会被转为Number
|
||||
* 内部的逻辑由requestClient.upload处理 这里不用判断业务状态码 不符合会自动reject
|
||||
*/
|
||||
info.onSuccess!(res);
|
||||
window.message.success($t('component.upload.uploadSuccess'));
|
||||
// 获取
|
||||
const value = getValue();
|
||||
isInnerOperate.value = true;
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
info.onError!(error);
|
||||
}
|
||||
}
|
||||
|
||||
function getValue() {
|
||||
console.log(fileList.value);
|
||||
const list = (fileList.value || [])
|
||||
.filter((item) => item?.status === UploadResultStatus.DONE)
|
||||
.map((item: any) => {
|
||||
if (item?.response && props?.resultField) {
|
||||
return item?.response?.[props.resultField];
|
||||
}
|
||||
// ossId兼容 uid为ossId直接返回
|
||||
if (props.resultField === 'ossId' && item.uid) {
|
||||
return item.uid;
|
||||
}
|
||||
// 适用于已经有图片 回显的情况 会默认在init处理为{url: 'xx'}
|
||||
if (item?.url) {
|
||||
return item.url;
|
||||
}
|
||||
// 注意这里取的key为 url
|
||||
return item?.response?.url;
|
||||
});
|
||||
// 只有一张图片 默认绑定string而非string[]
|
||||
if (props.maxNumber === 1 && list.length === 1) {
|
||||
return list[0];
|
||||
}
|
||||
// 只有一张图片 && 删除图片时 可自行修改
|
||||
if (props.maxNumber === 1 && list.length === 0) {
|
||||
return '';
|
||||
}
|
||||
return list;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Upload
|
||||
v-bind="$attrs"
|
||||
v-model:file-list="fileList"
|
||||
:accept="getStringAccept"
|
||||
:before-upload="beforeUpload"
|
||||
:custom-request="customRequest"
|
||||
:disabled="disabled"
|
||||
:list-type="listType"
|
||||
:max-count="maxNumber"
|
||||
:multiple="multiple"
|
||||
:progress="{ showInfo: true }"
|
||||
@preview="handlePreview"
|
||||
@remove="handleRemove"
|
||||
>
|
||||
<div v-if="fileList && fileList.length < maxNumber">
|
||||
<PlusOutlined />
|
||||
<div style="margin-top: 8px">{{ $t('component.upload.upload') }}</div>
|
||||
</div>
|
||||
</Upload>
|
||||
<div
|
||||
v-if="showDescription"
|
||||
class="mt-2 flex flex-wrap items-center text-[14px]"
|
||||
>
|
||||
请上传不超过
|
||||
<div class="mx-1 font-bold text-primary">{{ maxSize }}MB</div>
|
||||
的
|
||||
<div class="mx-1 font-bold text-primary">{{ accept.join('/') }}</div>
|
||||
格式文件
|
||||
</div>
|
||||
<Modal
|
||||
:footer="null"
|
||||
:open="previewOpen"
|
||||
:title="previewTitle"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<img :src="previewImage" alt="" style="width: 100%" />
|
||||
</Modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.ant-upload-select-picture-card i {
|
||||
font-size: 32px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.ant-upload-select-picture-card .ant-upload-text {
|
||||
margin-top: 8px;
|
||||
color: #666;
|
||||
}
|
||||
</style>
|
||||
@@ -1,37 +0,0 @@
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
export enum UploadResultStatus {
|
||||
DONE = 'done',
|
||||
ERROR = 'error',
|
||||
SUCCESS = 'success',
|
||||
UPLOADING = 'uploading',
|
||||
}
|
||||
|
||||
export interface FileItem {
|
||||
thumbUrl?: string;
|
||||
name: string;
|
||||
size: number | string;
|
||||
type?: string;
|
||||
percent: number;
|
||||
file: File;
|
||||
status?: UploadResultStatus;
|
||||
response?: Recordable<any> | { fileName: string; ossId: string; url: string };
|
||||
uuid: string;
|
||||
}
|
||||
|
||||
export interface Wrapper {
|
||||
record: FileItem;
|
||||
uidKey: string;
|
||||
valueKey: string;
|
||||
}
|
||||
|
||||
export interface BaseFileItem {
|
||||
uid: number | string;
|
||||
url: string;
|
||||
name?: string;
|
||||
}
|
||||
export interface PreviewFileItem {
|
||||
url: string;
|
||||
name: string;
|
||||
type: string;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
import { computed, unref } from 'vue';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
export function useUploadType({
|
||||
acceptRef,
|
||||
helpTextRef,
|
||||
maxNumberRef,
|
||||
maxSizeRef,
|
||||
}: {
|
||||
acceptRef: Ref<string[]>;
|
||||
helpTextRef: Ref<string>;
|
||||
maxNumberRef: Ref<number>;
|
||||
maxSizeRef: Ref<number>;
|
||||
}) {
|
||||
// 文件类型限制
|
||||
const getAccept = computed(() => {
|
||||
const accept = unref(acceptRef);
|
||||
if (accept && accept.length > 0) {
|
||||
return accept;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
const getStringAccept = computed(() => {
|
||||
return unref(getAccept)
|
||||
.map((item) => {
|
||||
return item.indexOf('/') > 0 || item.startsWith('.')
|
||||
? item
|
||||
: `.${item}`;
|
||||
})
|
||||
.join(',');
|
||||
});
|
||||
|
||||
// 支持jpg、jpeg、png格式,不超过2M,最多可选择10张图片,。
|
||||
const getHelpText = computed(() => {
|
||||
const helpText = unref(helpTextRef);
|
||||
if (helpText) {
|
||||
return helpText;
|
||||
}
|
||||
const helpTexts: string[] = [];
|
||||
|
||||
const accept = unref(acceptRef);
|
||||
if (accept.length > 0) {
|
||||
helpTexts.push($t('component.upload.accept', [accept.join(',')]));
|
||||
}
|
||||
|
||||
const maxSize = unref(maxSizeRef);
|
||||
if (maxSize) {
|
||||
helpTexts.push($t('component.upload.maxSize', [maxSize]));
|
||||
}
|
||||
|
||||
const maxNumber = unref(maxNumberRef);
|
||||
if (maxNumber && maxNumber !== Infinity) {
|
||||
helpTexts.push($t('component.upload.maxNumber', [maxNumber]));
|
||||
}
|
||||
return helpTexts.join(',');
|
||||
});
|
||||
return { getAccept, getStringAccept, getHelpText };
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
去除使用`file-type`库进行文件类型检测 在Safari无法使用
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { UploadListType } from 'antdv-next/es/upload/interface';
|
||||
import type { UploadProps } from 'antdv-next';
|
||||
|
||||
import type { BaseUploadProps, UploadEmits } from './props';
|
||||
|
||||
@@ -25,7 +25,7 @@ interface FileUploadProps extends BaseUploadProps {
|
||||
* 文件上传不适合用picture-card显示
|
||||
* @default text
|
||||
*/
|
||||
listType?: Exclude<UploadListType, 'picture-card'>;
|
||||
listType?: Exclude<UploadProps['listType'], 'picture-card'>;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<FileUploadProps>(), {
|
||||
@@ -118,7 +118,7 @@ Upload.Dragger只会影响样式
|
||||
>
|
||||
<template #size>
|
||||
<span
|
||||
class="text-primary mx-1 font-medium"
|
||||
class="mx-1 font-medium text-primary"
|
||||
:class="{ 'upload-text__disabled': disabled }"
|
||||
>
|
||||
{{ maxSize }}MB
|
||||
@@ -126,7 +126,7 @@ Upload.Dragger只会影响样式
|
||||
</template>
|
||||
<template #ext>
|
||||
<span
|
||||
class="text-primary mx-1 font-medium"
|
||||
class="mx-1 font-medium text-primary"
|
||||
:class="{ 'upload-text__disabled': disabled }"
|
||||
>
|
||||
{{ acceptStr }}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import type { UploadChangeParam, UploadFile } from 'antdv-next';
|
||||
import type { FileType } from 'antdv-next/es/upload/interface';
|
||||
import type {
|
||||
RcFile,
|
||||
UploadRequestOption,
|
||||
} from 'antdv-next/es/vc-upload/interface';
|
||||
import type { UploadChangeParam, UploadFile, UploadProps } from 'antdv-next';
|
||||
|
||||
import type { ModelRef } from 'vue';
|
||||
|
||||
@@ -15,7 +10,7 @@ import type {
|
||||
UploadType,
|
||||
} from './props';
|
||||
|
||||
import type { AxiosProgressEvent, UploadResult } from '#/api';
|
||||
import type { UploadResult } from '#/api';
|
||||
import type { OssFile } from '#/api/system/oss/model';
|
||||
|
||||
import { computed, onUnmounted, ref, watch } from 'vue';
|
||||
@@ -266,7 +261,7 @@ export function useUpload(
|
||||
* @param file file
|
||||
* @returns file | false
|
||||
*/
|
||||
function beforeUpload(file: FileType) {
|
||||
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
|
||||
const isLtMax = file.size / 1024 / 1024 < props.maxSize!;
|
||||
if (!isLtMax) {
|
||||
window.message.error($t('component.upload.maxSize', [props.maxSize]));
|
||||
@@ -274,40 +269,39 @@ export function useUpload(
|
||||
}
|
||||
// 大坑 Safari不支持file-type库 去除文件类型的校验
|
||||
return file;
|
||||
}
|
||||
};
|
||||
|
||||
const uploadAbort = new AbortController();
|
||||
/**
|
||||
* 自定义上传实现
|
||||
* @param info
|
||||
*/
|
||||
async function customRequest(info: UploadRequestOption<any>) {
|
||||
const customRequest: UploadProps['customRequest'] = async (info) => {
|
||||
const { api } = props;
|
||||
if (!isFunction(api)) {
|
||||
console.warn('upload api must exist and be a function');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 进度条事件
|
||||
const progressEvent: AxiosProgressEvent = (e) => {
|
||||
const percent = Math.trunc((e.loaded / e.total!) * 100);
|
||||
info.onProgress!({ percent });
|
||||
};
|
||||
const res = await api(info.file as File, {
|
||||
onUploadProgress: progressEvent,
|
||||
signal: uploadAbort.signal,
|
||||
const apiInstance = api(info.file as File, {
|
||||
otherData: props?.data,
|
||||
});
|
||||
// 进度条事件
|
||||
apiInstance.onUpload((e) => {
|
||||
const percent = Math.trunc((e.loaded / e.total!) * 100);
|
||||
info.onProgress!({ percent });
|
||||
});
|
||||
const res = await apiInstance;
|
||||
info.onSuccess!(res);
|
||||
if (props.showSuccessMsg) {
|
||||
window.message.success($t('component.upload.uploadSuccess'));
|
||||
}
|
||||
emit('success', info.file as RcFile, res);
|
||||
emit('success', info.file, res);
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
info.onError!(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
props.abortOnUnmounted && uploadAbort.abort();
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
去除使用`file-type`库进行文件类型检测 在Safari无法使用
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type {
|
||||
UploadFile,
|
||||
UploadListType,
|
||||
} from 'antdv-next/es/upload/interface';
|
||||
import type { UploadFile, UploadProps } from 'antdv-next';
|
||||
|
||||
import type { BaseUploadProps, UploadEmits } from './props';
|
||||
|
||||
@@ -26,7 +23,7 @@ interface ImageUploadProps extends BaseUploadProps {
|
||||
* 同antdv的listType
|
||||
* @default picture-card
|
||||
*/
|
||||
listType?: UploadListType;
|
||||
listType?: UploadProps['listType'];
|
||||
/**
|
||||
* 使用list-type: picture-card时 是否显示动画
|
||||
* 会有一个`弹跳`的效果 默认关闭
|
||||
@@ -127,7 +124,7 @@ function currentPreview(file: UploadFile) {
|
||||
>
|
||||
<template #size>
|
||||
<span
|
||||
class="text-primary mx-1 font-medium"
|
||||
class="mx-1 font-medium text-primary"
|
||||
:class="{ 'upload-text__disabled': disabled }"
|
||||
>
|
||||
{{ maxSize }}MB
|
||||
@@ -135,7 +132,7 @@ function currentPreview(file: UploadFile) {
|
||||
</template>
|
||||
<template #ext>
|
||||
<span
|
||||
class="text-primary mx-1 font-medium"
|
||||
class="mx-1 font-medium text-primary"
|
||||
:class="{ 'upload-text__disabled': disabled }"
|
||||
>
|
||||
{{ acceptStr }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AlovaMeta } from '#/../types/alova';
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
@@ -7,7 +7,7 @@ import { showAntdMessage } from './popup';
|
||||
export function checkStatus(
|
||||
status: number,
|
||||
msg: string,
|
||||
meta: AlovaMeta | undefined,
|
||||
meta: AxiosRequestConfig,
|
||||
): void {
|
||||
let errorMessage = msg;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AxiosError } from 'axios';
|
||||
import type { AxiosError, AxiosRequestConfig } from 'axios';
|
||||
|
||||
import type { HttpResponse } from '@vben/request';
|
||||
import type {
|
||||
@@ -6,8 +6,6 @@ import type {
|
||||
BaseSymmetricEncryption,
|
||||
} from '@vben/utils';
|
||||
|
||||
import type { AlovaMeta } from '#/../types/alova';
|
||||
|
||||
import { BUSINESS_SUCCESS_CODE, UNAUTHORIZED_CODE } from '@vben/constants';
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
import { preferences } from '@vben/preferences';
|
||||
@@ -58,7 +56,7 @@ const asymmetricEncryption: BaseAsymmetricEncryption = new RsaEncryption({
|
||||
*/
|
||||
const symmetricEncryption: BaseSymmetricEncryption = new AesEncryption();
|
||||
|
||||
const defaultMeta: AlovaMeta = {
|
||||
const axiosDefaultConfig: AxiosRequestConfig = {
|
||||
successMessageMode: 'none',
|
||||
errorMessageMode: 'message',
|
||||
withToken: true,
|
||||
@@ -81,16 +79,19 @@ const alovaInstance = createAlova({
|
||||
cacheFor: null,
|
||||
shareRequest: false,
|
||||
beforeRequest: (request) => {
|
||||
// 合并默认meta
|
||||
const { meta = {}, config } = request;
|
||||
const mergeMeta = merge({}, defaultMeta, meta);
|
||||
request.meta = mergeMeta;
|
||||
const { config } = request;
|
||||
/**
|
||||
* 合并默认axios配置
|
||||
* 在 axiosRequestAdapter 中添加无效 只能在这里手动合并
|
||||
*/
|
||||
const mergeMeta = merge({}, axiosDefaultConfig, config);
|
||||
Object.assign(config, mergeMeta);
|
||||
|
||||
// 全局开启token功能 && token存在
|
||||
const accessStore = useAccessStore();
|
||||
const token = accessStore.accessToken;
|
||||
// 添加token
|
||||
if (request.meta.withToken && token) {
|
||||
if (config.withToken && token) {
|
||||
config.headers.Authorization = token ? `Bearer ${token}` : null;
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ const alovaInstance = createAlova({
|
||||
stringify(params, { arrayFormat: 'repeat' });
|
||||
}
|
||||
|
||||
const { encrypt } = request.meta;
|
||||
const { encrypt } = config;
|
||||
// 全局开启请求加密功能 && 该请求开启 && 是post/put请求
|
||||
if (
|
||||
enableEncrypt &&
|
||||
@@ -175,8 +176,7 @@ const alovaInstance = createAlova({
|
||||
response.data = JSON.parse(decryptData);
|
||||
}
|
||||
|
||||
const { isReturnNativeResponse, isTransformResponse } =
|
||||
instance.meta as AlovaMeta;
|
||||
const { isReturnNativeResponse, isTransformResponse } = instance.config;
|
||||
// 是否返回原生响应 比如:需要获取响应时使用该属性
|
||||
if (isReturnNativeResponse) {
|
||||
return response;
|
||||
@@ -243,9 +243,11 @@ const alovaInstance = createAlova({
|
||||
successMsg = $t(`http.operationSuccess`);
|
||||
}
|
||||
|
||||
if (!['none', undefined].includes(instance.meta?.successMessageMode)) {
|
||||
if (
|
||||
!['none', undefined].includes(instance.config?.successMessageMode)
|
||||
) {
|
||||
showAntdMessage({
|
||||
meta: instance.meta,
|
||||
meta: instance.config,
|
||||
message: successMsg,
|
||||
type: 'success',
|
||||
});
|
||||
@@ -277,9 +279,9 @@ const alovaInstance = createAlova({
|
||||
|
||||
// errorMessageMode='modal'的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
|
||||
// errorMessageMode='none' 一般是调用时明确表示不希望自动弹出错误提示
|
||||
if (!['none', undefined].includes(instance.meta?.errorMessageMode)) {
|
||||
if (!['none', undefined].includes(instance.config?.errorMessageMode)) {
|
||||
showAntdMessage({
|
||||
meta: instance.meta,
|
||||
meta: instance.config,
|
||||
message: timeoutMsg,
|
||||
type: 'error',
|
||||
});
|
||||
@@ -304,9 +306,9 @@ const alovaInstance = createAlova({
|
||||
}
|
||||
|
||||
if (errMessage) {
|
||||
if (!['none', undefined].includes(method.meta?.errorMessageMode)) {
|
||||
if (!['none', undefined].includes(method.config?.errorMessageMode)) {
|
||||
showAntdMessage({
|
||||
meta: method.meta,
|
||||
meta: method.config,
|
||||
message: errMessage,
|
||||
type: 'error',
|
||||
});
|
||||
@@ -319,7 +321,7 @@ const alovaInstance = createAlova({
|
||||
|
||||
const msg: string = (response?.data as any)?.msg ?? '';
|
||||
// 根据httpStatus判断错误 弹窗提示
|
||||
checkStatus(error?.response?.status, msg, method.meta);
|
||||
checkStatus(error?.response?.status, msg, method.config);
|
||||
|
||||
return Promise.reject(error);
|
||||
},
|
||||
@@ -349,40 +351,28 @@ alovaInstance.delete = function (url, data, config) {
|
||||
alovaInstance.getWithMsg = function (url, options) {
|
||||
return this.Get(url, {
|
||||
...options,
|
||||
meta: {
|
||||
...options?.meta,
|
||||
successMessageMode: 'message',
|
||||
},
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
};
|
||||
|
||||
alovaInstance.postWithMsg = function (url, data, config) {
|
||||
return this.Post(url, data, {
|
||||
...config,
|
||||
meta: {
|
||||
...config?.meta,
|
||||
successMessageMode: 'message',
|
||||
},
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
};
|
||||
|
||||
alovaInstance.putWithMsg = function (url, data, config) {
|
||||
return this.Put(url, data, {
|
||||
...config,
|
||||
meta: {
|
||||
...config?.meta,
|
||||
successMessageMode: 'message',
|
||||
},
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
};
|
||||
|
||||
alovaInstance.deleteWithMsg = function (url, data, config) {
|
||||
return this.Delete(url, data, {
|
||||
...config,
|
||||
meta: {
|
||||
...config?.meta,
|
||||
successMessageMode: 'message',
|
||||
},
|
||||
successMessageMode: 'message',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { AlovaMeta } from '#/../types/alova';
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
|
||||
import { $t } from '#/locales';
|
||||
|
||||
interface ShowMessageOptions {
|
||||
meta?: AlovaMeta;
|
||||
meta?: AxiosRequestConfig;
|
||||
message: string;
|
||||
type: 'error' | 'success';
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { DemoForm, DemoQuery, DemoVO } from './model';
|
||||
import type { ID, IDS, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 查询测试单表列表
|
||||
@@ -11,7 +11,7 @@ import { requestClient } from '#/api/request';
|
||||
* @returns 测试单表列表
|
||||
*/
|
||||
export function demoList(params?: DemoQuery) {
|
||||
return requestClient.get<PageResult<DemoVO>>('/demo/demo/list', { params });
|
||||
return alovaInstance.get<PageResult<DemoVO>>('/demo/demo/list', { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ export function demoExport(params?: DemoQuery) {
|
||||
* @returns 测试单表详情
|
||||
*/
|
||||
export function demoInfo(id: ID) {
|
||||
return requestClient.get<DemoVO>(`/demo/demo/${id}`);
|
||||
return alovaInstance.get<DemoVO>(`/demo/demo/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ export function demoInfo(id: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function demoAdd(data: DemoForm) {
|
||||
return requestClient.postWithMsg<void>('/demo/demo', data);
|
||||
return alovaInstance.postWithMsg<void>('/demo/demo', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ export function demoAdd(data: DemoForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function demoUpdate(data: DemoForm) {
|
||||
return requestClient.putWithMsg<void>('/demo/demo', data);
|
||||
return alovaInstance.putWithMsg<void>('/demo/demo', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,5 +56,5 @@ export function demoUpdate(data: DemoForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function demoRemove(id: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/demo/demo/${id}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`/demo/demo/${id}`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { TreeForm, TreeQuery, TreeVO } from './model';
|
||||
|
||||
import type { ID, IDS } from '#/api/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 查询测试树列表
|
||||
@@ -10,7 +10,7 @@ import { requestClient } from '#/api/request';
|
||||
* @returns 测试树列表
|
||||
*/
|
||||
export function treeList(params?: TreeQuery) {
|
||||
return requestClient.get<TreeVO[]>('/demo/tree/list', { params });
|
||||
return alovaInstance.get<TreeVO[]>('/demo/tree/list', { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ export function treeList(params?: TreeQuery) {
|
||||
* @returns 测试树详情
|
||||
*/
|
||||
export function treeInfo(id: ID) {
|
||||
return requestClient.get<TreeVO>(`/demo/tree/${id}`);
|
||||
return alovaInstance.get<TreeVO>(`/demo/tree/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ export function treeInfo(id: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function treeAdd(data: TreeForm) {
|
||||
return requestClient.postWithMsg<void>('/demo/tree', data);
|
||||
return alovaInstance.postWithMsg<void>('/demo/tree', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ export function treeAdd(data: TreeForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function treeUpdate(data: TreeForm) {
|
||||
return requestClient.putWithMsg<void>('/demo/tree', data);
|
||||
return alovaInstance.putWithMsg<void>('/demo/tree', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,5 +46,5 @@ export function treeUpdate(data: TreeForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function treeRemove(id: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/demo/tree/${id}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`/demo/tree/${id}`);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { LeaveForm, LeaveQuery, LeaveVO } from './model';
|
||||
import type { ID, IDS, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
/**
|
||||
* 查询请假申请列表
|
||||
@@ -11,7 +11,7 @@ import { requestClient } from '#/api/request';
|
||||
* @returns 请假申请列表
|
||||
*/
|
||||
export function leaveList(params?: LeaveQuery) {
|
||||
return requestClient.get<PageResult<LeaveVO>>('/workflow/leave/list', {
|
||||
return alovaInstance.get<PageResult<LeaveVO>>('/workflow/leave/list', {
|
||||
params,
|
||||
});
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export function leaveExport(params?: LeaveQuery) {
|
||||
* @returns 请假申请详情
|
||||
*/
|
||||
export function leaveInfo(id: ID) {
|
||||
return requestClient.get<LeaveVO>(`/workflow/leave/${id}`);
|
||||
return alovaInstance.get<LeaveVO>(`/workflow/leave/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ export function leaveInfo(id: ID) {
|
||||
* @returns void
|
||||
*/
|
||||
export function leaveAdd(data: LeaveForm) {
|
||||
return requestClient.postWithMsg<LeaveVO>('/workflow/leave', data);
|
||||
return alovaInstance.postWithMsg<LeaveVO>('/workflow/leave', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ export function leaveAdd(data: LeaveForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function leaveUpdate(data: LeaveForm) {
|
||||
return requestClient.putWithMsg<LeaveVO>('/workflow/leave', data);
|
||||
return alovaInstance.putWithMsg<LeaveVO>('/workflow/leave', data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ export function leaveUpdate(data: LeaveForm) {
|
||||
* @returns void
|
||||
*/
|
||||
export function leaveRemove(id: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/workflow/leave/${id}`);
|
||||
return alovaInstance.deleteWithMsg<void>(`/workflow/leave/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ export function leaveRemove(id: ID | IDS) {
|
||||
* @returns void
|
||||
*/
|
||||
export function submitAndStartWorkflow(data: LeaveForm) {
|
||||
return requestClient.postWithMsg<void>(
|
||||
return alovaInstance.postWithMsg<void>(
|
||||
'/workflow/leave/submitAndFlowStart',
|
||||
data,
|
||||
);
|
||||
|
||||
@@ -6,12 +6,12 @@ import { JsonPreview, Page } from '@vben/common-ui';
|
||||
import { Alert, Card } from 'antdv-next';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
const requestData = ref<any>({});
|
||||
const requestData2 = ref<any>({});
|
||||
async function apiRequest(name: string) {
|
||||
const resp = await requestClient.post('/test/api/encrypt/request', name, {
|
||||
const resp = await alovaInstance.post('/test/api/encrypt/request', name, {
|
||||
encrypt: true,
|
||||
isReturnNativeResponse: true,
|
||||
});
|
||||
@@ -23,7 +23,7 @@ async function apiRequest(name: string) {
|
||||
const encryptData = ref<any>({});
|
||||
const response = ref<any>({});
|
||||
async function apiResponse() {
|
||||
const resp = await requestClient.get('/test/api/encrypt/response', {
|
||||
const resp = await alovaInstance.get('/test/api/encrypt/response', {
|
||||
isTransformResponse: false,
|
||||
transformResponse: (data) => {
|
||||
encryptData.value = data;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
enum Api {
|
||||
list = '/system/sse/list',
|
||||
@@ -8,19 +8,19 @@ enum Api {
|
||||
}
|
||||
|
||||
export function sseStatus() {
|
||||
return requestClient.get<boolean>(Api.status);
|
||||
return alovaInstance.get<boolean>(Api.status);
|
||||
}
|
||||
|
||||
export function sseSendAll(message: string) {
|
||||
return requestClient.postWithMsg<void>(`${Api.sendAll}?message=${message}`);
|
||||
return alovaInstance.postWithMsg<void>(`${Api.sendAll}?message=${message}`);
|
||||
}
|
||||
|
||||
export function sseSendByUserId(userId: string, message: string) {
|
||||
return requestClient.postWithMsg<void>(
|
||||
return alovaInstance.postWithMsg<void>(
|
||||
`${Api.send}/${userId}?message=${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function sseList() {
|
||||
return requestClient.get<any>(Api.list);
|
||||
return alovaInstance.get<any>(Api.list);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import { alovaInstance } from '#/utils/http';
|
||||
|
||||
export interface Temp {
|
||||
name: string;
|
||||
@@ -6,19 +6,19 @@ export interface Temp {
|
||||
}
|
||||
|
||||
export function visitList() {
|
||||
return requestClient.get<Temp[]>('/monitor/logininfor/visitsMap');
|
||||
return alovaInstance.get<Temp[]>('/monitor/logininfor/visitsMap');
|
||||
}
|
||||
|
||||
export function deviceInfoList() {
|
||||
return requestClient.get<Temp[]>('/monitor/logininfor/deviceInfoList');
|
||||
return alovaInstance.get<Temp[]>('/monitor/logininfor/deviceInfoList');
|
||||
}
|
||||
|
||||
export function browserInfoList() {
|
||||
return requestClient.get<Temp[]>('/monitor/logininfor/browserInfoList');
|
||||
return alovaInstance.get<Temp[]>('/monitor/logininfor/browserInfoList');
|
||||
}
|
||||
|
||||
export function ispInfoList() {
|
||||
return requestClient.get<Temp[]>('/monitor/logininfor/ispInfoList');
|
||||
return alovaInstance.get<Temp[]>('/monitor/logininfor/ispInfoList');
|
||||
}
|
||||
|
||||
export interface LoginLineResp {
|
||||
@@ -28,5 +28,5 @@ export interface LoginLineResp {
|
||||
}
|
||||
|
||||
export function loginLine() {
|
||||
return requestClient.get<LoginLineResp>('/monitor/logininfor/loginLine');
|
||||
return alovaInstance.get<LoginLineResp>('/monitor/logininfor/loginLine');
|
||||
}
|
||||
|
||||
63
apps/web-antd/types/alova.d.ts
vendored
63
apps/web-antd/types/alova.d.ts
vendored
@@ -13,32 +13,11 @@ type PostType = AlovaInstanceType['Post'];
|
||||
type PutType = AlovaInstanceType['Put'];
|
||||
type DeleteType = AlovaInstanceType['Delete'];
|
||||
|
||||
export type AlovaMeta = {
|
||||
/**
|
||||
* 是否需要对请求体进行加密
|
||||
*/
|
||||
encrypt?: boolean;
|
||||
/**
|
||||
* 错误弹窗类型
|
||||
*/
|
||||
errorMessageMode?: MessageType;
|
||||
/**
|
||||
* 是否返回原生axios响应
|
||||
*/
|
||||
isReturnNativeResponse?: boolean;
|
||||
/**
|
||||
* 是否需要转换响应 即只获取{code, msg, data}中的data
|
||||
*/
|
||||
isTransformResponse?: boolean;
|
||||
/**
|
||||
* 接口请求成功时的提示方式
|
||||
*/
|
||||
successMessageMode?: MessageType;
|
||||
/**
|
||||
* 是否需要在请求头中添加 token
|
||||
*/
|
||||
withToken?: boolean;
|
||||
};
|
||||
/**
|
||||
* 拓展自己的Meta
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
export type AlovaMeta = {};
|
||||
|
||||
declare module 'alova' {
|
||||
export interface AlovaCustomTypes {
|
||||
@@ -61,4 +40,36 @@ declare module 'alova' {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拓展axios的请求配置
|
||||
*/
|
||||
declare module 'axios' {
|
||||
interface AxiosRequestConfig {
|
||||
/**
|
||||
* 是否需要对请求体进行加密
|
||||
*/
|
||||
encrypt?: boolean;
|
||||
/**
|
||||
* 错误弹窗类型
|
||||
*/
|
||||
errorMessageMode?: MessageType;
|
||||
/**
|
||||
* 是否返回原生axios响应
|
||||
*/
|
||||
isReturnNativeResponse?: boolean;
|
||||
/**
|
||||
* 是否需要转换响应 即只获取{code, msg, data}中的data
|
||||
*/
|
||||
isTransformResponse?: boolean;
|
||||
/**
|
||||
* 接口请求成功时的提示方式
|
||||
*/
|
||||
successMessageMode?: MessageType;
|
||||
/**
|
||||
* 是否需要在请求头中添加 token
|
||||
*/
|
||||
withToken?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user