diff --git a/frontend/src/api/http/Axios.ts b/frontend/src/api/http/Axios.ts index 12eb18d323..4c1ac83742 100644 --- a/frontend/src/api/http/Axios.ts +++ b/frontend/src/api/http/Axios.ts @@ -81,7 +81,7 @@ export class MSAxios { /** * @description: 文件上传 */ - uploadFile(config: AxiosRequestConfig, params: UploadFileParams) { + uploadFile(config: AxiosRequestConfig, params: UploadFileParams): Promise { const formData = new window.FormData(); const fileName = params.fileList.length === 1 ? 'file' : 'files'; @@ -92,15 +92,44 @@ export class MSAxios { const requestData = JSON.stringify(params.request); formData.append('request', requestData); } - return this.axiosInstance.request({ - ...config, - method: 'POST', - data: formData, - headers: { - 'Content-type': ContentTypeEnum.FORM_DATA, - // @ts-ignore - 'ignoreCancelToken': true, // 文件上传请求不需要添加到pending中 - }, + return new Promise((resolve, reject) => { + this.axiosInstance + .request>({ + ...config, + method: 'POST', + data: formData, + headers: { + 'Content-type': ContentTypeEnum.FORM_DATA, + // @ts-ignore + 'ignoreCancelToken': true, // 文件上传请求不需要添加到pending中 + }, + }) + .then((res: AxiosResponse) => { + const transform = this.getTransform(); + const { requestOptions } = this.options; + const opt = { ...requestOptions }; + + const { transformRequestHook } = transform || {}; + // 请求成功后的处理 + if (transformRequestHook && isFunction(transformRequestHook)) { + try { + const ret = transformRequestHook(res, opt); + resolve(ret); + } catch (err) { + reject(err || new Error('request error!')); + } + return; + } + resolve(res as unknown as Promise); + }) + .catch((e: Error | AxiosError) => { + if (axios.isAxiosError(e)) { + // 在这可重写axios错误消息 + // eslint-disable-next-line no-console + console.log(e); + } + reject(e); + }); }); } diff --git a/frontend/src/api/modules/setting/user.ts b/frontend/src/api/modules/setting/user.ts index 8552fb3ecb..0e2e3385e2 100644 --- a/frontend/src/api/modules/setting/user.ts +++ b/frontend/src/api/modules/setting/user.ts @@ -1,16 +1,56 @@ import MSR from '@/api/http/index'; -import { GetUserListUrl, CreateUserUrl, UpdateUserUrl } from '@/api/requrls/setting/user'; -import type { UserListItem, CreateUserParams } from '@/models/setting/user'; +import { + GetUserListUrl, + CreateUserUrl, + UpdateUserUrl, + DeleteUserUrl, + ImportUserUrl, + EnableUserUrl, + GetSystemRoleUrl, +} from '@/api/requrls/setting/user'; +import type { + UserListItem, + CreateUserParams, + UpdateUserInfoParams, + UpdateUserStausParams, + DeleteUserParams, + ImportUserParams, + SystemRole, + ImportResult, +} from '@/models/setting/user'; import type { TableQueryParams } from '@/models/common'; +// 获取用户列表 export function getUserList(data: TableQueryParams) { return MSR.post({ url: GetUserListUrl, data }); } +// 批量创建用户 export function batchCreateUser(data: CreateUserParams) { return MSR.post({ url: CreateUserUrl, data }); } -export function updateUserInfo(data: UserListItem) { +// 更新用户信息 +export function updateUserInfo(data: UpdateUserInfoParams) { return MSR.post({ url: UpdateUserUrl, data }); } + +// 更新用户启用/禁用状态 +export function toggleUserStatus(data: UpdateUserStausParams) { + return MSR.post({ url: EnableUserUrl, data }); +} + +// 删除用户 +export function deleteUserInfo(data: DeleteUserParams) { + return MSR.post({ url: DeleteUserUrl, data }); +} + +// 导入用户 +export function importUserInfo(data: ImportUserParams) { + return MSR.uploadFile({ url: ImportUserUrl }, data); +} + +// 获取系统用户组 +export function getSystemRoles() { + return MSR.get({ url: GetSystemRoleUrl }); +} diff --git a/frontend/src/api/requrls/setting/user.ts b/frontend/src/api/requrls/setting/user.ts index 7cf61a7c20..1bd8e0649c 100644 --- a/frontend/src/api/requrls/setting/user.ts +++ b/frontend/src/api/requrls/setting/user.ts @@ -1,3 +1,7 @@ -export const GetUserListUrl = '/user/page'; -export const CreateUserUrl = '/user/add'; -export const UpdateUserUrl = '/user/update'; +export const GetUserListUrl = '/system/user/page'; +export const CreateUserUrl = '/system/user/add'; +export const UpdateUserUrl = '/system/user/update'; +export const DeleteUserUrl = '/system/user/delete'; +export const ImportUserUrl = '/system/user/import'; +export const EnableUserUrl = '/system/user/update/enable'; +export const GetSystemRoleUrl = '/system/user/get/global/system/role'; diff --git a/frontend/src/components/pure/ms-upload/index.vue b/frontend/src/components/pure/ms-upload/index.vue index feb4ad16f1..734a744fd3 100644 --- a/frontend/src/components/pure/ms-upload/index.vue +++ b/frontend/src/components/pure/ms-upload/index.vue @@ -4,6 +4,7 @@ v-model:file-list="fileList" :accept="UploadAcceptEnum[props.accept]" :multiple="props.multiple" + :disabled="props.disabled" @before-upload="beforeUpload" >