feat: 用户页面部分接口&uploadFile接口返回调整&上传组件调整

This commit is contained in:
baiqi 2023-07-26 16:38:56 +08:00 committed by fit2-zhao
parent 3d82476c09
commit bf3eb37148
9 changed files with 901 additions and 667 deletions

View File

@ -81,7 +81,7 @@ export class MSAxios {
/**
* @description:
*/
uploadFile<T = any>(config: AxiosRequestConfig, params: UploadFileParams) {
uploadFile<T = any>(config: AxiosRequestConfig, params: UploadFileParams): Promise<T> {
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<T>({
...config,
method: 'POST',
data: formData,
headers: {
'Content-type': ContentTypeEnum.FORM_DATA,
// @ts-ignore
'ignoreCancelToken': true, // 文件上传请求不需要添加到pending中
},
return new Promise((resolve, reject) => {
this.axiosInstance
.request<any, AxiosResponse<Result>>({
...config,
method: 'POST',
data: formData,
headers: {
'Content-type': ContentTypeEnum.FORM_DATA,
// @ts-ignore
'ignoreCancelToken': true, // 文件上传请求不需要添加到pending中
},
})
.then((res: AxiosResponse<Result>) => {
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<T>);
})
.catch((e: Error | AxiosError) => {
if (axios.isAxiosError(e)) {
// 在这可重写axios错误消息
// eslint-disable-next-line no-console
console.log(e);
}
reject(e);
});
});
}

View File

@ -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<UserListItem[]>({ 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<ImportResult>({ url: ImportUserUrl }, data);
}
// 获取系统用户组
export function getSystemRoles() {
return MSR.get<SystemRole>({ url: GetSystemRoleUrl });
}

View File

@ -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';

View File

@ -4,6 +4,7 @@
v-model:file-list="fileList"
:accept="UploadAcceptEnum[props.accept]"
:multiple="props.multiple"
:disabled="props.disabled"
@before-upload="beforeUpload"
>
<template #upload-button>
@ -56,6 +57,7 @@
multiple: boolean;
imagePreview: boolean;
showFileList: boolean;
disabled: boolean;
iconType: string;
maxSize: number; // MB
[key: string]: any;
@ -71,6 +73,13 @@
const fileList = ref<FileItem[]>(props.fileList);
watch(
() => props.fileList,
(val) => {
fileList.value = val;
}
);
watch(
() => fileList.value,
(val) => {

View File

@ -1,253 +1,254 @@
import { mock } from '@/utils/setup-mock';
import { RequestEnum } from '@/enums/httpEnum';
// import { mock } from '@/utils/setup-mock';
// import { RequestEnum } from '@/enums/httpEnum';
const getUserList = () => {
return [
{
id: '103423',
name: '大家的',
email: 'dehihu@kds.sd',
enable: true,
createTime: 1686905750716,
updateTime: 0,
lastOrganizationId: 'string',
phone: '18473647583',
source: 'string',
lastProjectId: 'string',
createUser: 'string',
updateUser: 'string',
organizationList: [
{
id: 'string',
num: 0,
name: '组织 1',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
{
id: 'string',
num: 0,
name: '组织 2',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
{
id: 'string',
num: 0,
name: '组织 3',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
{
id: 'string',
num: 0,
name: '组织 4',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
],
userRoleList: [
{
id: 'string',
name: '角色 1',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
{
id: 'string',
name: '角色 2',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
{
id: 'string',
name: '角色 3',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
{
id: 'string',
name: '角色 4',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
],
},
{
id: '103233',
name: '发热发热',
email: 'dehihu@kds.sd',
enable: false,
createTime: 1686905750716,
updateTime: 0,
lastOrganizationId: 'string',
phone: '18473647583',
source: 'string',
lastProjectId: 'string',
createUser: 'string',
updateUser: 'string',
organizationList: [
{
id: 'string',
num: 0,
name: '组织 1',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
{
id: 'string',
num: 0,
name: '组织 2',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
{
id: 'string',
num: 0,
name: '组织 3',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
{
id: 'string',
num: 0,
name: '组织 4',
description: 'blabla',
createTime: 0,
updateTime: 0,
createUser: 'string',
updateUser: 'string',
deleted: true,
deleteUser: 'string',
deleteTime: 0,
enable: true,
},
],
userRoleList: [
{
id: 'string',
name: '角色 1',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
{
id: 'string',
name: '角色 2',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
{
id: 'string',
name: '角色 3',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
{
id: 'string',
name: '角色 4',
description: 'sdadasd',
internal: true,
type: 'string',
createTime: 0,
updateTime: 0,
createUser: 'string',
scopeId: 'string',
pos: 0,
},
],
},
];
};
// const getUserList = () => {
// return [
// {
// id: '103423',
// name: '大家的',
// email: 'dehihu@kds.sd',
// enable: true,
// createTime: 1686905750716,
// updateTime: 0,
// lastOrganizationId: 'string',
// phone: '18473647583',
// source: 'string',
// lastProjectId: 'string',
// createUser: 'string',
// updateUser: 'string',
// organizationList: [
// {
// id: 'string',
// num: 0,
// name: '组织 1',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// {
// id: 'string',
// num: 0,
// name: '组织 2',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// {
// id: 'string',
// num: 0,
// name: '组织 3',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// {
// id: 'string',
// num: 0,
// name: '组织 4',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// ],
// userRoleList: [
// {
// id: 'string',
// name: '角色 1',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// {
// id: 'string',
// name: '角色 2',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// {
// id: 'string',
// name: '角色 3',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// {
// id: 'string',
// name: '角色 4',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// ],
// },
// {
// id: '103233',
// name: '发热发热',
// email: 'dehihu@kds.sd',
// enable: false,
// createTime: 1686905750716,
// updateTime: 0,
// lastOrganizationId: 'string',
// phone: '18473647583',
// source: 'string',
// lastProjectId: 'string',
// createUser: 'string',
// updateUser: 'string',
// organizationList: [
// {
// id: 'string',
// num: 0,
// name: '组织 1',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// {
// id: 'string',
// num: 0,
// name: '组织 2',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// {
// id: 'string',
// num: 0,
// name: '组织 3',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// {
// id: 'string',
// num: 0,
// name: '组织 4',
// description: 'blabla',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// updateUser: 'string',
// deleted: true,
// deleteUser: 'string',
// deleteTime: 0,
// enable: true,
// },
// ],
// userRoleList: [
// {
// id: 'string',
// name: '角色 1',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// {
// id: 'string',
// name: '角色 2',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// {
// id: 'string',
// name: '角色 3',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// {
// id: 'string',
// name: '角色 4',
// description: 'sdadasd',
// internal: true,
// type: 'string',
// createTime: 0,
// updateTime: 0,
// createUser: 'string',
// scopeId: 'string',
// pos: 0,
// },
// ],
// },
// ];
// };
mock(RequestEnum.POST, '/user/page', getUserList(), 200, true);
// mock(RequestEnum.POST, '/user/page', getUserList(), 200, true);
export default {};

View File

@ -1,16 +1,16 @@
// 用户所属用户组模型
export interface UserRoleListItem {
id: string;
name: string;
description: string;
internal: boolean;
type: string;
internal: boolean; // 是否内置用户组
type: string; // 所属类型 SYSTEM ORGANIZATION PROJECT
createTime: number;
updateTime: number;
createUser: string;
scopeId: string;
pos: number;
scopeId: string; // 应用范围
}
// 用户所属组织模型
export interface OrganizationListItem {
id: string;
num: number;
@ -20,12 +20,13 @@ export interface OrganizationListItem {
updateTime: number;
createUser: string;
updateUser: string;
deleted: boolean;
deleted: boolean; // 是否删除
deleteUser: string;
deleteTime: number;
enable: boolean;
enable: boolean; // 是否启用
}
// 用户模型
export interface UserListItem {
id: string;
name: string;
@ -34,15 +35,15 @@ export interface UserListItem {
enable: boolean;
createTime: number;
updateTime: number;
language: string;
lastOrganizationId: string;
language: string; // 语言
lastOrganizationId: string; // 当前组织ID
phone: string;
source: string;
lastProjectId: string;
source: string; // 来源LOCAL OIDC CAS OAUTH2
lastProjectId: string; // 当前项目ID
createUser: string;
updateUser: string;
organizationList: OrganizationListItem[];
userRoleList: UserRoleListItem[];
organizationList: OrganizationListItem[]; // 用户所属组织
userRoleList: UserRoleListItem[]; // 用户所属用户组
}
export interface Filter {
@ -54,13 +55,44 @@ export interface Sort {
}
// 创建用户模型
export interface CreateUserInfo {
export interface SimpleUserInfo {
id?: string;
name: string;
email: string;
phone?: string;
}
export interface CreateUserParams {
userInfoList: CreateUserInfo[];
export interface UpdateUserInfoParams extends SimpleUserInfo {
id: string;
userRoleIdList: string[];
}
export interface CreateUserParams {
userInfoList: SimpleUserInfo[];
userRoleIdList: string[];
}
export interface UpdateUserStausParams {
userIdList: string[];
enable: boolean;
}
export interface ImportUserParams {
fileList: (File | undefined)[];
}
export interface DeleteUserParams {
userIdList: string[];
}
export interface SystemRole {
id: string;
name: string;
selected: boolean;
closeable: boolean;
}
export interface ImportResult {
importCount: number;
successCount: number;
errorMessages: Record<string, any>;
}

File diff suppressed because it is too large Load Diff

View File

@ -11,28 +11,34 @@ export default {
'system.user.tableEnable': 'Enabled',
'system.user.tableDisable': 'Disabled',
'system.user.deleteUserTip': 'Are you sure to delete the user `{name}` ?',
'system.user.batchDeleteUserTip': 'Are you sure you want to delete the {count} users selected?',
'system.user.deleteUserContent': "Only delete user information, does not handle the user's system data",
'system.user.deleteUserConfirm': 'Delete',
'system.user.deleteUserCancel': 'Cancel',
'system.user.deleteUserSuccess': 'Delete successful',
'system.user.deleteUserSuccess': 'Delete successfully',
'system.user.disableUserTip': 'Are you sure to disable the user `{name}` ?',
'system.user.batchDisableUserTip': 'Are you sure to disable the {count} selected users?',
'system.user.disableUserContent': "Disabled users can't log in to the system",
'system.user.disableUserConfirm': 'Disabled',
'system.user.disableUserCancel': 'Cancel',
'system.user.disableUserSuccess': 'Disabled successful',
'system.user.disableUserSuccess': 'Disabled successfully',
'system.user.enableUserTip': 'Are you sure to enable the user `{name}` ?',
'system.user.batchEnableUserTip': 'Are you sure to enable the {count} selected users?',
'system.user.enableUserContent': 'Enabled users can log in to the system',
'system.user.enableUserConfirm': 'Enable',
'system.user.enableUserCancel': 'Cancel',
'system.user.enableUserSuccess': 'Enable successful',
'system.user.enableUserSuccess': 'Enable successfully',
'system.user.resetPswStart': 'Reset the password of',
'system.user.resetPswTip': 'Reset the password of `{name}` to its initial password?',
'system.user.batchResetPswTip': 'Reset the passwords of the selected {count} users to their initial passwords?',
'system.user.resetPswContent': "The initial password is the user's mailbox, which will take effect at the next login",
'system.user.resetPswConfirm': 'Reset',
'system.user.resetPswCancel': 'Cancel',
'system.user.resetPswSuccess': 'Reset successful',
'system.user.resetPswSuccess': 'Reset successfully',
'system.user.createUserModalTitle': 'Create a user',
'system.user.addUser': 'Add user',
'system.user.addUserSuccess': 'Added successfully',
'system.user.updateUserSuccess': 'Updated successfully',
'system.user.createUserName': 'Name',
'system.user.createUserNameNotNull': 'Name cannot be blank',
'system.user.createUserNameOverLength': 'Name length cannot exceed 50',
@ -59,7 +65,7 @@ export default {
'system.user.inviteCancel': 'Cancel',
'system.user.inviteEmailPlaceholder': 'Enter multiple email addresses, separated by spaces or carriage returns',
'system.user.inviteSendEmail': 'SendEmail',
'system.user.inviteSuccess': 'Invitation successful',
'system.user.inviteSuccess': 'Invitation successfully',
'system.user.importModalTitle': 'Import user',
'system.user.importDownload': 'Download the template',
'system.user.importModalTip': 'User groups only support adding user groups that exist in the system',

View File

@ -11,27 +11,33 @@ export default {
'system.user.tableEnable': '正常',
'system.user.tableDisable': '禁用',
'system.user.deleteUserTip': '确认删除 `{name}` 这个用户吗?',
'system.user.batchDeleteUserTip': '确认删除已选中的 {count} 个用户吗?',
'system.user.deleteUserContent': '仅删除用户信息,不处理该用户的系统数据',
'system.user.deleteUserConfirm': '确认删除',
'system.user.deleteUserCancel': '取消',
'system.user.deleteUserSuccess': '删除成功',
'system.user.disableUserTip': '确认禁用 `{name}` 这个用户吗?',
'system.user.batchDisableUserTip': '确认禁用已选中的 {count} 个用户吗?',
'system.user.disableUserContent': '禁用的用户无法登录系统',
'system.user.disableUserConfirm': '确认禁用',
'system.user.disableUserCancel': '取消',
'system.user.disableUserSuccess': '禁用成功',
'system.user.enableUserTip': '确认启用 `{name}` 这个用户吗?',
'system.user.batchEnableUserTip': '确认启用已选中的 {count} 个用户吗?',
'system.user.enableUserContent': '启用后用户可以登录系统',
'system.user.enableUserConfirm': '确认启用',
'system.user.enableUserCancel': '取消',
'system.user.enableUserSuccess': '启用成功',
'system.user.resetPswTip': '是否将 `{name}` 的密码重置为初始密码?',
'system.user.batchResetPswTip': '是否将选中的 {count} 个用户的密码重置为初始密码?',
'system.user.resetPswContent': '初始的密码为用户邮箱,下次登录时生效',
'system.user.resetPswConfirm': '确认重置',
'system.user.resetPswCancel': '取消',
'system.user.resetPswSuccess': '重置成功',
'system.user.createUserModalTitle': '创建用户',
'system.user.addUser': '添加用户',
'system.user.addUserSuccess': '添加成功',
'system.user.updateUserSuccess': '更新成功',
'system.user.createUserName': '姓名',
'system.user.createUserNameNotNull': '姓名不能为空',
'system.user.createUserNameOverLength': '姓名长度不能超过50',