SecurityController.ts 5.27 KB
// region 前端扩展导入包
import { TreeItem } from "autumn-vue/lib/core/bean/TreeItem";
import { Page } from "autumn-vue/lib/core/page/Page";
import { AxiosResponse, AxiosStatic } from "axios";
import { Role } from "lib/src/entity/security/entity/Role";
import { User } from "lib/src/entity/security/entity/User";

// endregion

/**
 */
export const SecurityController = {
	/**
	 * 添加角色
	 * @param role
	 * @return Role
	 * @throws IOException
	 * @throws FieldException
	 */
	addRole(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
		return axios.post("security/addRole", role);
	},

	/**
	 * 添加用户
	 * @param user
	 * @return User
	 * @throws FieldException
	 */
	addUser(axios: AxiosStatic, user: any): Promise<AxiosResponse<User>> {
		return axios.post("security/addUser", user);
	},

	/**
	 * 用户修改自己的密码
	 * @param userPassword
	 * @return boolean
	 */
	changePassword(axios: AxiosStatic, userPassword: any): Promise<AxiosResponse<boolean>> {
		return axios.post("security/changePassword", userPassword);
	},

	/**
	 */
	enableUser(axios: AxiosStatic, userId: number, enabled: boolean): Promise<AxiosResponse<boolean>> {
		return axios.post("security/enableUser", null, { params: { userId, enabled } });
	},

	/**
	 */
	enabledRole(axios: AxiosStatic, roleId: number, enabled: boolean): Promise<AxiosResponse<boolean>> {
		return axios.post("security/enabledRole", null, { params: { roleId, enabled } });
	},

	/**
	 */
	getEnabledRoles(axios: AxiosStatic): Promise<AxiosResponse<Role[]>> {
		return axios.get("security/getEnabledRoles");
	},

	/**
	 */
	getEnabledUsers(axios: AxiosStatic): Promise<AxiosResponse<User[]>> {
		return axios.get("security/getEnabledUsers");
	},

	/**
	 */
	getLoginUser(axios: AxiosStatic): Promise<AxiosResponse<User>> {
		return axios.get("security/getLoginUser");
	},

	/**
	 */
	getPrivilegeTreeByRoleId(axios: AxiosStatic, roleId: number): Promise<AxiosResponse<TreeItem[]>> {
		return axios.get("security/getPrivilegeTreeByRoleId", { params: { roleId } });
	},

	/**
	 */
	getRoleById(axios: AxiosStatic, roleId: number): Promise<AxiosResponse<Role>> {
		return axios.get("security/getRoleById", { params: { roleId } });
	},

	/**
	 * 根据用户ID获取用户
	 * @param userId
	 * @return User
	 */
	getUserById(axios: AxiosStatic, userId: number): Promise<AxiosResponse<User>> {
		return axios.get("security/getUserById", { params: { userId } });
	},

	/**
	 * 根据用户名获取用户
	 * @param userName
	 * @return User
	 */
	getUserByUserName(axios: AxiosStatic, userName: string): Promise<AxiosResponse<User>> {
		return axios.get("security/getUserByUserName", { params: { userName } });
	},

	/**
	 */
	pageRole(axios: AxiosStatic, pagination: any): Promise<AxiosResponse<Page<Role>>> {
		return axios.post("security/pageRole", pagination);
	},

	PAGE_ROLE : "security/pageRole",

	/**
	 * 分页查询用户
	 * @param pagination
	 * @return Page
	 */
	pageUser(axios: AxiosStatic, pagination: any): Promise<AxiosResponse<Page<User>>> {
		return axios.post("security/pageUser", pagination);
	},

	PAGE_USER : "security/pageUser",

	/**
	 * 删除角色
	 * @param roleId
	 * @return int
	 * @throws IOException
	 */
	removeRoleById(axios: AxiosStatic, roleId: number): Promise<AxiosResponse<number>> {
		return axios.delete("security/removeRoleById", { params: { roleId } });
	},

	/**
	 * 根据用户ID删除用户
	 * @param userId
	 */
	removeUserById(axios: AxiosStatic, userId: number): Promise<AxiosResponse<number>> {
		return axios.delete("security/removeUserById", { params: { userId } });
	},

	/**
	 * 管理员重置密码
	 * @param userPassword
	 * @return boolean
	 */
	resetPassword(axios: AxiosStatic, userPassword: any): Promise<AxiosResponse<boolean>> {
		return axios.post("security/resetPassword", userPassword);
	},

	/**
	 * 编辑个人信息
	 * @param user
	 * @return User
	 * @throws FieldException
	 */
	updateProfile(axios: AxiosStatic, user: any): Promise<AxiosResponse<User>> {
		return axios.post("security/updateProfile", user);
	},

	/**
	 * 修改角色
	 * @param role
	 * @return Role
	 * @throws FieldException
	 * @throws IOException
	 */
	updateRole(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
		return axios.post("security/updateRole", role);
	},

	/**
	 * 修改角色权限
	 * @param role
	 * @return Role
	 * @throws FieldException
	 * @throws IOException
	 */
	updateRolePrivileges(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
		return axios.post("security/updateRolePrivileges", role);
	},

	/**
	 */
	updateRoleSetting(axios: AxiosStatic, role: any): Promise<AxiosResponse<Role>> {
		return axios.post("security/updateRoleSetting", role);
	},

	/**
	 * 编辑用户
	 * @param user
	 * @return User
	 * @throws FieldException
	 */
	updateUser(axios: AxiosStatic, user: any): Promise<AxiosResponse<User>> {
		return axios.post("security/updateUser", user);
	},

	// region 前端扩展代码区
	/**
	 *
	 * @return Authenticity
	 */
	getUserAuthentication(axios: AxiosStatic, module: null | string | undefined): Promise<AxiosResponse> {
		return axios.get("security/getUserAuthentication", { params: { module } });
	},

	changeMobile(axios: AxiosStatic, mobile: string): Promise<AxiosResponse<User>> {
		return axios.post("security/changeMobile", null, { params: { mobile } });
	},

	// endregion
};