2023-04-02 01:01:56 +08:00
|
|
|
import { DeptVO } from './../dept/types';
|
|
|
|
import { RoleVO } from '@/api/system/role/types';
|
|
|
|
import request from '@/utils/request';
|
|
|
|
import { AxiosPromise } from 'axios';
|
|
|
|
import { UserForm, UserQuery, UserVO, UserInfoVO } from './types';
|
|
|
|
import { parseStrEmpty } from '@/utils/ruoyi';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询用户列表
|
|
|
|
* @param query
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const listUser = (query: UserQuery): AxiosPromise<UserVO[]> => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/list',
|
|
|
|
method: 'get',
|
|
|
|
params: query
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取用户详情
|
|
|
|
* @param userId
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const getUser = (userId?: string | number): AxiosPromise<UserInfoVO> => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/' + parseStrEmpty(userId),
|
|
|
|
method: 'get'
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增用户
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const addUser = (data: UserForm) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user',
|
|
|
|
method: 'post',
|
|
|
|
data: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 修改用户
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const updateUser = (data: UserForm) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user',
|
|
|
|
method: 'put',
|
|
|
|
data: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除用户
|
|
|
|
* @param userId 用户ID
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const delUser = (userId: Array<string | number> | string | number) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/' + userId,
|
|
|
|
method: 'delete'
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户密码重置
|
|
|
|
* @param userId 用户ID
|
|
|
|
* @param password 密码
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const resetUserPwd = (userId: string | number, password: string) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
const data = {
|
|
|
|
userId,
|
|
|
|
password
|
|
|
|
};
|
|
|
|
return request({
|
|
|
|
url: '/system/user/resetPwd',
|
|
|
|
method: 'put',
|
2023-08-14 10:36:59 +08:00
|
|
|
headers: {
|
|
|
|
isEncrypt: true
|
|
|
|
},
|
2023-04-03 00:05:09 +08:00
|
|
|
data: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户状态修改
|
|
|
|
* @param userId 用户ID
|
|
|
|
* @param status 用户状态
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const changeUserStatus = (userId: number | string, status: string) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
const data = {
|
|
|
|
userId,
|
|
|
|
status
|
|
|
|
};
|
|
|
|
return request({
|
|
|
|
url: '/system/user/changeStatus',
|
|
|
|
method: 'put',
|
|
|
|
data: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询用户个人信息
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const getUserProfile = (): AxiosPromise<UserInfoVO> => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/profile',
|
|
|
|
method: 'get'
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 修改用户个人信息
|
|
|
|
* @param data 用户信息
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const updateUserProfile = (data: UserForm) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/profile',
|
|
|
|
method: 'put',
|
|
|
|
data: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户密码重置
|
|
|
|
* @param oldPassword 旧密码
|
|
|
|
* @param newPassword 新密码
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const updateUserPwd = (oldPassword: string, newPassword: string) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
const data = {
|
|
|
|
oldPassword,
|
|
|
|
newPassword
|
|
|
|
};
|
|
|
|
return request({
|
|
|
|
url: '/system/user/profile/updatePwd',
|
|
|
|
method: 'put',
|
2023-08-14 10:36:59 +08:00
|
|
|
headers: {
|
|
|
|
isEncrypt: true
|
|
|
|
},
|
2023-04-03 00:05:09 +08:00
|
|
|
params: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户头像上传
|
|
|
|
* @param data 头像文件
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const uploadAvatar = (data: FormData) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/profile/avatar',
|
|
|
|
method: 'post',
|
|
|
|
data: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询授权角色
|
|
|
|
* @param userId 用户ID
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const getAuthRole = (userId: string | number): AxiosPromise<{ user: UserVO; roles: RoleVO[] }> => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/authRole/' + userId,
|
|
|
|
method: 'get'
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 保存授权角色
|
|
|
|
* @param data 用户ID
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const updateAuthRole = (data: { userId: string; roleIds: string }) => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/authRole',
|
|
|
|
method: 'put',
|
|
|
|
params: data
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
2023-04-02 01:01:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询部门下拉树结构
|
|
|
|
*/
|
2023-06-06 20:55:50 +08:00
|
|
|
export const deptTreeSelect = (): AxiosPromise<DeptVO[]> => {
|
2023-04-03 00:05:09 +08:00
|
|
|
return request({
|
|
|
|
url: '/system/user/deptTree',
|
|
|
|
method: 'get'
|
|
|
|
});
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
listUser,
|
|
|
|
getUser,
|
|
|
|
addUser,
|
|
|
|
updateUser,
|
|
|
|
delUser,
|
|
|
|
resetUserPwd,
|
|
|
|
changeUserStatus,
|
|
|
|
getUserProfile,
|
|
|
|
updateUserProfile,
|
|
|
|
updateUserPwd,
|
|
|
|
uploadAvatar,
|
|
|
|
getAuthRole,
|
|
|
|
updateAuthRole,
|
2023-08-25 15:31:40 +08:00
|
|
|
deptTreeSelect
|
2023-06-06 20:55:50 +08:00
|
|
|
};
|