diff --git a/apps/vben5/packages/@abp/identity/src/api/claim-types.ts b/apps/vben5/packages/@abp/identity/src/api/claim-types.ts deleted file mode 100644 index b42816c5c..000000000 --- a/apps/vben5/packages/@abp/identity/src/api/claim-types.ts +++ /dev/null @@ -1,85 +0,0 @@ -import type { ListResultDto, PagedResultDto } from '@abp/core'; - -import type { - GetIdentityClaimTypePagedListInput, - IdentityClaimTypeCreateDto, - IdentityClaimTypeDto, - IdentityClaimTypeUpdateDto, -} from '../types/claim-types'; - -import { requestClient } from '@abp/request'; - -/** - * 新增用户声明 - * @param input 参数 - * @returns 用户声明实体数据传输对象 - */ -export function createApi( - input: IdentityClaimTypeCreateDto, -): Promise { - return requestClient.post( - '/api/identity/claim-types', - input, - ); -} - -/** - * 删除用户声明 - * @param id 用户声明id - */ -export function deleteApi(id: string): Promise { - return requestClient.delete(`/api/identity/claim-types/${id}`); -} - -/** - * 查询用户声明 - * @param id 用户声明id - * @returns 用户声明实体数据传输对象 - */ -export function getApi(id: string): Promise { - return requestClient.get( - `/api/identity/claim-types/${id}`, - ); -} - -/** - * 更新用户声明 - * @param id 用户声明id - * @returns 用户声明实体数据传输对象 - */ -export function updateApi( - id: string, - input: IdentityClaimTypeUpdateDto, -): Promise { - return requestClient.put( - `/api/identity/claim-types/${id}`, - input, - ); -} - -/** - * 查询用户声明分页列表 - * @param input 过滤参数 - * @returns 用户声明实体数据传输对象分页列表 - */ -export function getPagedListApi( - input?: GetIdentityClaimTypePagedListInput, -): Promise> { - return requestClient.get>( - `/api/identity/claim-types`, - { - params: input, - }, - ); -} - -/** - * 获取可用的声明类型列表 - */ -export function getAssignableClaimsApi(): Promise< - ListResultDto -> { - return requestClient.get>( - `/api/identity/claim-types/actived-list`, - ); -} diff --git a/apps/vben5/packages/@abp/identity/src/api/index.ts b/apps/vben5/packages/@abp/identity/src/api/index.ts index c422a50dc..a1d18a620 100644 --- a/apps/vben5/packages/@abp/identity/src/api/index.ts +++ b/apps/vben5/packages/@abp/identity/src/api/index.ts @@ -1,6 +1,6 @@ -export * as claimTypesApi from './claim-types'; -export * as organizationUnitsApi from './organization-units'; -export * as rolesApi from './roles'; -export * as securityLogsApi from './security-logs'; -export * as usersApi from './users'; -export * as userLookupApi from './users-lookup'; +export * as useClaimTypesApi from './useClaimTypesApi'; +export * as useOrganizationUnitsApi from './useOrganizationUnitsApi'; +export * as useRolesApi from './useRolesApi'; +export * as useSecurityLogsApi from './useSecurityLogsApi'; +export * as useUserLookup from './useUserLookup'; +export * as useUsersApi from './useUsersApi'; diff --git a/apps/vben5/packages/@abp/identity/src/api/organization-units.ts b/apps/vben5/packages/@abp/identity/src/api/organization-units.ts deleted file mode 100644 index aba2b746e..000000000 --- a/apps/vben5/packages/@abp/identity/src/api/organization-units.ts +++ /dev/null @@ -1,227 +0,0 @@ -import type { ListResultDto, PagedResultDto } from '@abp/core'; - -import type { IdentityRoleDto, IdentityUserDto } from '../types'; -import type { - GetIdentityRolesInput, - GetIdentityUsersInput, - GetOrganizationUnitPagedListInput, - GetUnaddedRoleListInput, - GetUnaddedUserListInput, - OrganizationUnitAddRoleDto, - OrganizationUnitAddUserDto, - OrganizationUnitCreateDto, - OrganizationUnitDto, - OrganizationUnitGetChildrenDto, - OrganizationUnitUpdateDto, -} from '../types/organization-units'; - -import { requestClient } from '@abp/request'; - -/** - * 新增组织机构 - * @param input 参数 - * @returns 组织机构实体数据传输对象 - */ -export function createApi( - input: OrganizationUnitCreateDto, -): Promise { - return requestClient.post( - '/api/identity/organization-units', - input, - ); -} - -/** - * 删除组织机构 - * @param id 组织机构id - */ -export function deleteApi(id: string): Promise { - return requestClient.delete(`/api/identity/organization-units/${id}`); -} - -/** - * 查询组织机构 - * @param id 组织机构id - * @returns 组织机构实体数据传输对象 - */ -export function getApi(id: string): Promise { - return requestClient.get( - `/api/identity/organization-units/${id}`, - ); -} - -/** - * 更新组织机构 - * @param id 组织机构id - * @returns 组织机构实体数据传输对象 - */ -export function updateApi( - id: string, - input: OrganizationUnitUpdateDto, -): Promise { - return requestClient.put( - `/api/identity/organization-units/${id}`, - input, - ); -} - -/** - * 查询组织机构分页列表 - * @param input 过滤参数 - * @returns 组织机构实体数据传输对象分页列表 - */ -export function getPagedListApi( - input?: GetOrganizationUnitPagedListInput, -): Promise> { - return requestClient.get>( - `/api/identity/organization-units`, - { - params: input, - }, - ); -} - -/** - * 查询根组织机构列表 - * @returns 组织机构实体数据传输对象列表 - */ -export function getRootListApi(): Promise> { - return requestClient.get>( - `/api/identity/organization-units/root-node`, - ); -} - -/** - * 查询组织机构列表 - * @returns 组织机构实体数据传输对象列表 - */ -export function getAllListApi(): Promise> { - return requestClient.get>( - `/api/identity/organization-units/all`, - ); -} - -/** - * 查询下级组织机构列表 - * @param input 查询参数 - * @returns 组织机构实体数据传输对象列表 - */ -export function getChildrenApi( - input: OrganizationUnitGetChildrenDto, -): Promise> { - return requestClient.get>( - `/api/identity/organization-units/find-children`, - { - params: input, - }, - ); -} - -/** - * 查询组织机构用户列表 - * @param id 组织机构id - * @param input 查询过滤参数 - * @returns 用户实体数据传输对象分页列表 - */ -export function getUserListApi( - id: string, - input?: GetIdentityUsersInput, -): Promise> { - return requestClient.get>( - `/api/identity/organization-units/${id}/users`, - { - params: input, - }, - ); -} - -/** - * 查询未加入组织机构的用户列表 - * @param input 查询过滤参数 - * @returns 用户实体数据传输对象分页列表 - */ -export function getUnaddedUserListApi( - input: GetUnaddedUserListInput, -): Promise> { - return requestClient.get>( - `/api/identity/organization-units/${input.id}/unadded-users`, - { - params: input, - }, - ); -} - -/** - * 用户添加到组织机构 - * @param id 组织机构id - * @param input 用户id列表 - */ -export function addMembers( - id: string, - input: OrganizationUnitAddUserDto, -): Promise { - return requestClient.post( - `/api/identity/organization-units/${id}/users`, - input, - ); -} - -/** - * 查询组织机构角色列表 - * @param id 组织机构id - * @param input 查询过滤参数 - * @returns 角色实体数据传输对象分页列表 - */ -export function getRoleListApi( - id: string, - input?: GetIdentityRolesInput, -): Promise> { - return requestClient.get>( - `/api/identity/organization-units/${id}/roles`, - { - params: input, - }, - ); -} - -/** - * 查询未加入组织机构的角色列表 - * @param input 查询过滤参数 - * @returns 角色实体数据传输对象分页列表 - */ -export function getUnaddedRoleListApi( - input: GetUnaddedRoleListInput, -): Promise> { - return requestClient.get>( - `/api/identity/organization-units/${input.id}/unadded-roles`, - { - params: input, - }, - ); -} - -/** - * 角色添加到组织机构 - * @param id 组织机构id - * @param input 角色id列表 - */ -export function addRoles( - id: string, - input: OrganizationUnitAddRoleDto, -): Promise { - return requestClient.post( - `/api/identity/organization-units/${id}/roles`, - input, - ); -} - -/** - * 移动组织机构 - * @param id 组织机构id - * @param parentId 父级组织机构id - */ -export function moveTo(id: string, parentId?: string): Promise { - return requestClient.put(`api/identity/organization-units/${id}/move`, { - parentId, - }); -} diff --git a/apps/vben5/packages/@abp/identity/src/api/roles.ts b/apps/vben5/packages/@abp/identity/src/api/roles.ts deleted file mode 100644 index 652cd79b5..000000000 --- a/apps/vben5/packages/@abp/identity/src/api/roles.ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { ListResultDto, PagedResultDto } from '@abp/core'; - -import type { - IdentityClaimCreateDto, - IdentityClaimDeleteDto, - IdentityClaimDto, - IdentityClaimUpdateDto, -} from '../types/claims'; -import type { - GetRolePagedListInput, - IdentityRoleCreateDto, - IdentityRoleDto, - IdentityRoleUpdateDto, -} from '../types/roles'; - -import { requestClient } from '@abp/request'; - -/** - * 新增角色 - * @param input 参数 - * @returns 角色实体数据传输对象 - */ -export function createApi( - input: IdentityRoleCreateDto, -): Promise { - return requestClient.post('/api/identity/roles', input); -} - -/** - * 删除角色 - * @param id 角色id - */ -export function deleteApi(id: string): Promise { - return requestClient.delete(`/api/identity/roles/${id}`); -} - -/** - * 查询角色 - * @param id 角色id - * @returns 角色实体数据传输对象 - */ -export function getApi(id: string): Promise { - return requestClient.get(`/api/identity/roles/${id}`); -} - -/** - * 更新角色 - * @param id 角色id - * @returns 角色实体数据传输对象 - */ -export function updateApi( - id: string, - input: IdentityRoleUpdateDto, -): Promise { - return requestClient.put(`/api/identity/roles/${id}`, input); -} - -/** - * 查询角色分页列表 - * @param input 过滤参数 - * @returns 角色实体数据传输对象分页列表 - */ -export function getPagedListApi( - input?: GetRolePagedListInput, -): Promise> { - return requestClient.get>( - `/api/identity/roles`, - { - params: input, - }, - ); -} - -/** - * 从组织机构中移除角色 - * @param id 角色id - * @param ouId 组织机构id - */ -export function removeOrganizationUnitApi( - id: string, - ouId: string, -): Promise { - return requestClient.delete( - `/api/identity/roles/${id}/organization-units/${ouId}`, - ); -} - -/** - * 获取角色声明列表 - * @param id 角色id - */ -export function getClaimsApi( - id: string, -): Promise> { - return requestClient.get>( - `/api/identity/roles/${id}/claims`, - ); -} - -/** - * 删除角色声明 - * @param id 角色id - * @param input 角色声明dto - */ -export function deleteClaimApi( - id: string, - input: IdentityClaimDeleteDto, -): Promise { - return requestClient.delete(`/api/identity/roles/${id}/claims`, { - params: input, - }); -} - -/** - * 创建角色声明 - * @param id 角色id - * @param input 角色声明dto - */ -export function createClaimApi( - id: string, - input: IdentityClaimCreateDto, -): Promise { - return requestClient.post(`/api/identity/roles/${id}/claims`, input); -} - -/** - * 更新角色声明 - * @param id 角色id - * @param input 用户角色dto - */ -export function updateClaimApi( - id: string, - input: IdentityClaimUpdateDto, -): Promise { - return requestClient.put(`/api/identity/roles/${id}/claims`, input); -} diff --git a/apps/vben5/packages/@abp/identity/src/api/security-logs.ts b/apps/vben5/packages/@abp/identity/src/api/security-logs.ts deleted file mode 100644 index 686f612b5..000000000 --- a/apps/vben5/packages/@abp/identity/src/api/security-logs.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { PagedResultDto } from '@abp/core'; - -import type { - GetSecurityLogPagedRequest, - SecurityLogDto, -} from '../types/security-logs'; - -import { requestClient } from '@abp/request'; - -/** - * 删除安全日志 - * @param id id - */ -export function deleteApi(id: string): Promise { - return requestClient.delete(`/api/auditing/security-log/${id}`); -} - -/** - * 查询安全日志 - * @param id id - * @returns 安全日志实体数据传输对象 - */ -export function getApi(id: string): Promise { - return requestClient.get(`/api/auditing/security-log/${id}`); -} - -/** - * 查询安全日志分页列表 - * @param input 过滤参数 - * @returns 安全日志实体数据传输对象分页列表 - */ -export function getPagedListApi( - input?: GetSecurityLogPagedRequest, -): Promise> { - return requestClient.get>( - `/api/auditing/security-log`, - { - params: input, - }, - ); -} diff --git a/apps/vben5/packages/@abp/identity/src/api/useClaimTypesApi.ts b/apps/vben5/packages/@abp/identity/src/api/useClaimTypesApi.ts new file mode 100644 index 000000000..0fe0bdd7b --- /dev/null +++ b/apps/vben5/packages/@abp/identity/src/api/useClaimTypesApi.ts @@ -0,0 +1,105 @@ +import type { ListResultDto, PagedResultDto } from '@abp/core'; + +import type { + GetIdentityClaimTypePagedListInput, + IdentityClaimTypeCreateDto, + IdentityClaimTypeDto, + IdentityClaimTypeUpdateDto, +} from '../types'; + +import { useRequest } from '@abp/request'; + +export function useClaimTypesApi() { + const { cancel, request } = useRequest(); + + /** + * 新增用户声明 + * @param input 参数 + * @returns 用户声明实体数据传输对象 + */ + function createApi( + input: IdentityClaimTypeCreateDto, + ): Promise { + return request('/api/identity/claim-types', { + data: input, + method: 'POST', + }); + } + + /** + * 删除用户声明 + * @param id 用户声明id + */ + function deleteApi(id: string): Promise { + return request(`/api/identity/claim-types/${id}`, { + method: 'DELETE', + }); + } + + /** + * 查询用户声明 + * @param id 用户声明id + * @returns 用户声明实体数据传输对象 + */ + function getApi(id: string): Promise { + return request(`/api/identity/claim-types/${id}`, { + method: 'GET', + }); + } + + /** + * 更新用户声明 + * @param id 用户声明id + * @returns 用户声明实体数据传输对象 + */ + function updateApi( + id: string, + input: IdentityClaimTypeUpdateDto, + ): Promise { + return request(`/api/identity/claim-types/${id}`, { + data: input, + method: 'PUT', + }); + } + + /** + * 查询用户声明分页列表 + * @param input 过滤参数 + * @returns 用户声明实体数据传输对象分页列表 + */ + function getPagedListApi( + input?: GetIdentityClaimTypePagedListInput, + ): Promise> { + return request>( + `/api/identity/claim-types`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 获取可用的声明类型列表 + */ + function getAssignableClaimsApi(): Promise< + ListResultDto + > { + return request>( + `/api/identity/claim-types/actived-list`, + { + method: 'GET', + }, + ); + } + + return { + cancel, + createApi, + deleteApi, + getApi, + getAssignableClaimsApi, + getPagedListApi, + updateApi, + }; +} diff --git a/apps/vben5/packages/@abp/identity/src/api/useOrganizationUnitsApi.ts b/apps/vben5/packages/@abp/identity/src/api/useOrganizationUnitsApi.ts new file mode 100644 index 000000000..adba78017 --- /dev/null +++ b/apps/vben5/packages/@abp/identity/src/api/useOrganizationUnitsApi.ts @@ -0,0 +1,271 @@ +import type { ListResultDto, PagedResultDto } from '@abp/core'; + +import type { IdentityRoleDto, IdentityUserDto } from '../types'; +import type { + GetIdentityRolesInput, + GetIdentityUsersInput, + GetOrganizationUnitPagedListInput, + GetUnaddedRoleListInput, + GetUnaddedUserListInput, + OrganizationUnitAddRoleDto, + OrganizationUnitAddUserDto, + OrganizationUnitCreateDto, + OrganizationUnitDto, + OrganizationUnitGetChildrenDto, + OrganizationUnitUpdateDto, +} from '../types/organization-units'; + +import { useRequest } from '@abp/request'; + +export function useOrganizationUnitsApi() { + const { cancel, request } = useRequest(); + + /** + * 新增组织机构 + * @param input 参数 + * @returns 组织机构实体数据传输对象 + */ + function createApi( + input: OrganizationUnitCreateDto, + ): Promise { + return request('/api/identity/organization-units', { + data: input, + method: 'GET', + }); + } + + /** + * 删除组织机构 + * @param id 组织机构id + */ + function deleteApi(id: string): Promise { + return request(`/api/identity/organization-units/${id}`, { + method: 'DELETE', + }); + } + + /** + * 查询组织机构 + * @param id 组织机构id + * @returns 组织机构实体数据传输对象 + */ + function getApi(id: string): Promise { + return request( + `/api/identity/organization-units/${id}`, + { + method: 'GET', + }, + ); + } + + /** + * 更新组织机构 + * @param id 组织机构id + * @returns 组织机构实体数据传输对象 + */ + function updateApi( + id: string, + input: OrganizationUnitUpdateDto, + ): Promise { + return request( + `/api/identity/organization-units/${id}`, + { + data: input, + method: 'PUT', + }, + ); + } + + /** + * 查询组织机构分页列表 + * @param input 过滤参数 + * @returns 组织机构实体数据传输对象分页列表 + */ + function getPagedListApi( + input?: GetOrganizationUnitPagedListInput, + ): Promise> { + return request>( + `/api/identity/organization-units`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 查询根组织机构列表 + * @returns 组织机构实体数据传输对象列表 + */ + function getRootListApi(): Promise> { + return request>( + `/api/identity/organization-units/root-node`, + { + method: 'GET', + }, + ); + } + + /** + * 查询组织机构列表 + * @returns 组织机构实体数据传输对象列表 + */ + function getAllListApi(): Promise> { + return request>( + `/api/identity/organization-units/all`, + { + method: 'GET', + }, + ); + } + + /** + * 查询下级组织机构列表 + * @param input 查询参数 + * @returns 组织机构实体数据传输对象列表 + */ + function getChildrenApi( + input: OrganizationUnitGetChildrenDto, + ): Promise> { + return request>( + `/api/identity/organization-units/find-children`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 查询组织机构用户列表 + * @param id 组织机构id + * @param input 查询过滤参数 + * @returns 用户实体数据传输对象分页列表 + */ + function getUserListApi( + id: string, + input?: GetIdentityUsersInput, + ): Promise> { + return request>( + `/api/identity/organization-units/${id}/users`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 查询未加入组织机构的用户列表 + * @param input 查询过滤参数 + * @returns 用户实体数据传输对象分页列表 + */ + function getUnaddedUserListApi( + input: GetUnaddedUserListInput, + ): Promise> { + return request>( + `/api/identity/organization-units/${input.id}/unadded-users`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 用户添加到组织机构 + * @param id 组织机构id + * @param input 用户id列表 + */ + function addMembers( + id: string, + input: OrganizationUnitAddUserDto, + ): Promise { + return request(`/api/identity/organization-units/${id}/users`, { + data: input, + method: 'POST', + }); + } + + /** + * 查询组织机构角色列表 + * @param id 组织机构id + * @param input 查询过滤参数 + * @returns 角色实体数据传输对象分页列表 + */ + function getRoleListApi( + id: string, + input?: GetIdentityRolesInput, + ): Promise> { + return request>( + `/api/identity/organization-units/${id}/roles`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 查询未加入组织机构的角色列表 + * @param input 查询过滤参数 + * @returns 角色实体数据传输对象分页列表 + */ + function getUnaddedRoleListApi( + input: GetUnaddedRoleListInput, + ): Promise> { + return request>( + `/api/identity/organization-units/${input.id}/unadded-roles`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 角色添加到组织机构 + * @param id 组织机构id + * @param input 角色id列表 + */ + function addRoles( + id: string, + input: OrganizationUnitAddRoleDto, + ): Promise { + return request(`/api/identity/organization-units/${id}/roles`, { + data: input, + method: 'GET', + }); + } + + /** + * 移动组织机构 + * @param id 组织机构id + * @param parentId 父级组织机构id + */ + function moveTo(id: string, parentId?: string): Promise { + return request(`api/identity/organization-units/${id}/move`, { + data: { parentId }, + method: 'PUT', + }); + } + + return { + addMembers, + addRoles, + cancel, + createApi, + deleteApi, + getAllListApi, + getApi, + getChildrenApi, + getPagedListApi, + getRoleListApi, + getRootListApi, + getUnaddedRoleListApi, + getUnaddedUserListApi, + getUserListApi, + moveTo, + updateApi, + }; +} diff --git a/apps/vben5/packages/@abp/identity/src/api/useRolesApi.ts b/apps/vben5/packages/@abp/identity/src/api/useRolesApi.ts new file mode 100644 index 000000000..993d1cf3b --- /dev/null +++ b/apps/vben5/packages/@abp/identity/src/api/useRolesApi.ts @@ -0,0 +1,164 @@ +import type { ListResultDto, PagedResultDto } from '@abp/core'; + +import type { + IdentityClaimCreateDto, + IdentityClaimDeleteDto, + IdentityClaimDto, + IdentityClaimUpdateDto, +} from '../types/claims'; +import type { + GetRolePagedListInput, + IdentityRoleCreateDto, + IdentityRoleDto, + IdentityRoleUpdateDto, +} from '../types/roles'; + +import { useRequest } from '@abp/request'; + +export function useRolesApi() { + const { cancel, request } = useRequest(); + /** + * 新增角色 + * @param input 参数 + * @returns 角色实体数据传输对象 + */ + function createApi(input: IdentityRoleCreateDto): Promise { + return request('/api/identity/roles', { + data: input, + method: 'POST', + }); + } + + /** + * 删除角色 + * @param id 角色id + */ + function deleteApi(id: string): Promise { + return request(`/api/identity/roles/${id}`, { + method: 'DELETE', + }); + } + + /** + * 查询角色 + * @param id 角色id + * @returns 角色实体数据传输对象 + */ + function getApi(id: string): Promise { + return request(`/api/identity/roles/${id}`, { + method: 'GET', + }); + } + + /** + * 更新角色 + * @param id 角色id + * @returns 角色实体数据传输对象 + */ + function updateApi( + id: string, + input: IdentityRoleUpdateDto, + ): Promise { + return request(`/api/identity/roles/${id}`, { + data: input, + method: 'PUT', + }); + } + + /** + * 查询角色分页列表 + * @param input 过滤参数 + * @returns 角色实体数据传输对象分页列表 + */ + function getPagedListApi( + input?: GetRolePagedListInput, + ): Promise> { + return request>(`/api/identity/roles`, { + method: 'GET', + params: input, + }); + } + + /** + * 从组织机构中移除角色 + * @param id 角色id + * @param ouId 组织机构id + */ + function removeOrganizationUnitApi(id: string, ouId: string): Promise { + return request(`/api/identity/roles/${id}/organization-units/${ouId}`, { + method: 'DELETE', + }); + } + + /** + * 获取角色声明列表 + * @param id 角色id + */ + function getClaimsApi(id: string): Promise> { + return request>( + `/api/identity/roles/${id}/claims`, + { + method: 'GET', + }, + ); + } + + /** + * 删除角色声明 + * @param id 角色id + * @param input 角色声明dto + */ + function deleteClaimApi( + id: string, + input: IdentityClaimDeleteDto, + ): Promise { + return request(`/api/identity/roles/${id}/claims`, { + method: 'DELETE', + params: input, + }); + } + + /** + * 创建角色声明 + * @param id 角色id + * @param input 角色声明dto + */ + function createClaimApi( + id: string, + input: IdentityClaimCreateDto, + ): Promise { + return request(`/api/identity/roles/${id}/claims`, { + data: input, + method: 'POST', + }); + } + + /** + * 更新角色声明 + * @param id 角色id + * @param input 用户角色dto + */ + function updateClaimApi( + id: string, + input: IdentityClaimUpdateDto, + ): Promise { + return request(`/api/identity/roles/${id}/claims`, { + data: input, + method: 'PUT', + }); + } + + return { + cancel, + createApi, + createClaimApi, + deleteApi, + deleteClaimApi, + getApi, + getClaimsApi, + getPagedListApi, + removeOrganizationUnitApi, + updateApi, + updateClaimApi, + }; +} diff --git a/apps/vben5/packages/@abp/identity/src/api/useSecurityLogsApi.ts b/apps/vben5/packages/@abp/identity/src/api/useSecurityLogsApi.ts new file mode 100644 index 000000000..3bb99497b --- /dev/null +++ b/apps/vben5/packages/@abp/identity/src/api/useSecurityLogsApi.ts @@ -0,0 +1,57 @@ +import type { PagedResultDto } from '@abp/core'; + +import type { + GetSecurityLogPagedRequest, + SecurityLogDto, +} from '../types/security-logs'; + +import { useRequest } from '@abp/request'; + +export function useSecurityLogsApi() { + const { cancel, request } = useRequest(); + + /** + * 删除安全日志 + * @param id id + */ + function deleteApi(id: string): Promise { + return request(`/api/auditing/security-log/${id}`, { + method: 'DELETE', + }); + } + + /** + * 查询安全日志 + * @param id id + * @returns 安全日志实体数据传输对象 + */ + function getApi(id: string): Promise { + return request(`/api/auditing/security-log/${id}`, { + method: 'GET', + }); + } + + /** + * 查询安全日志分页列表 + * @param input 过滤参数 + * @returns 安全日志实体数据传输对象分页列表 + */ + function getPagedListApi( + input?: GetSecurityLogPagedRequest, + ): Promise> { + return request>( + `/api/auditing/security-log`, + { + method: 'GET', + params: input, + }, + ); + } + + return { + cancel, + deleteApi, + getApi, + getPagedListApi, + }; +} diff --git a/apps/vben5/packages/@abp/identity/src/api/useUserLookup.ts b/apps/vben5/packages/@abp/identity/src/api/useUserLookup.ts new file mode 100644 index 000000000..df1c698f7 --- /dev/null +++ b/apps/vben5/packages/@abp/identity/src/api/useUserLookup.ts @@ -0,0 +1,74 @@ +import type { ListResultDto } from '@abp/core'; + +import type { + IdentityUserDto, + UserLookupCountInput, + UserLookupSearchInput, +} from '../types/users'; + +import { useRequest } from '@abp/request'; + +export function useUserLookup() { + const { cancel, request } = useRequest(); + + /** + * 通过id查询用户 + * @param id 用户id + * @returns 用户实体数据传输对象 + */ + function findByIdApi(id: string): Promise { + return request(`/api/identity/users/lookup/${id}`, { + method: 'GET', + }); + } + + /** + * 通过用户名查询用户 + * @param userName 用户名 + * @returns 用户实体数据传输对象 + */ + function findByUserNameApi(userName: string): Promise { + return request( + `/api/identity/users/lookup/by-username/${userName}`, + { + method: 'GET', + }, + ); + } + + /** + * 搜索用户列表 + * @param input 搜索过滤条件 + * @returns 用户实体数据传输对象列表 + */ + function searchApi( + input?: UserLookupSearchInput, + ): Promise> { + return request>( + `/api/identity/users/lookup/search`, + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 搜索用户数量 + * @param input 搜索过滤条件 + */ + function countApi(input?: UserLookupCountInput): Promise { + return request(`/api/identity/users/lookup/count`, { + method: 'GET', + params: input, + }); + } + + return { + cancel, + countApi, + findByIdApi, + findByUserNameApi, + searchApi, + }; +} diff --git a/apps/vben5/packages/@abp/identity/src/api/useUsersApi.ts b/apps/vben5/packages/@abp/identity/src/api/useUsersApi.ts new file mode 100644 index 000000000..482cf167d --- /dev/null +++ b/apps/vben5/packages/@abp/identity/src/api/useUsersApi.ts @@ -0,0 +1,249 @@ +import type { ListResultDto, PagedResultDto } from '@abp/core'; + +import type { IdentityRoleDto, OrganizationUnitDto } from '../types'; +import type { + IdentityClaimCreateDto, + IdentityClaimDeleteDto, + IdentityClaimDto, + IdentityClaimUpdateDto, +} from '../types/claims'; +import type { + ChangeUserPasswordInput, + GetUserPagedListInput, + IdentityUserCreateDto, + IdentityUserDto, + IdentityUserUpdateDto, +} from '../types/users'; + +import { useRequest } from '@abp/request'; + +export function useUserApi() { + const { cancel, request } = useRequest(); + + /** + * 新增用户 + * @param input 参数 + * @returns 用户实体数据传输对象 + */ + function createApi(input: IdentityUserCreateDto): Promise { + return request('/api/identity/users', { + data: input, + method: 'POST', + }); + } + + /** + * 删除用户 + * @param id 用户id + */ + function deleteApi(id: string): Promise { + return request(`/api/identity/users/${id}`, { + method: 'DELETE', + }); + } + + /** + * 查询用户 + * @param id 用户id + * @returns 用户实体数据传输对象 + */ + function getApi(id: string): Promise { + return request(`/api/identity/users/${id}`, { + method: 'GET', + }); + } + + /** + * 更新用户 + * @param id 用户id + * @returns 用户实体数据传输对象 + */ + function updateApi( + id: string, + input: IdentityUserUpdateDto, + ): Promise { + return request(`/api/identity/users/${id}`, { + data: input, + method: 'PUT', + }); + } + + /** + * 查询用户分页列表 + * @param input 过滤参数 + * @returns 用户实体数据传输对象分页列表 + */ + function getPagedListApi( + input?: GetUserPagedListInput, + ): Promise> { + return request>(`/api/identity/users`, { + method: 'GET', + params: input, + }); + } + + /** + * 从组织机构中移除用户 + * @param id 用户id + * @param ouId 组织机构id + */ + function removeOrganizationUnitApi(id: string, ouId: string): Promise { + return request(`/api/identity/users/${id}/organization-units/${ouId}`, { + method: 'DELETE', + }); + } + + /** + * 获取用户组织机构列表 + * @param id 用户id + */ + function getOrganizationUnitsApi( + id: string, + ): Promise> { + return request>( + `/api/identity/users/${id}/organization-units`, + { + method: 'GET', + }, + ); + } + + /** + * 锁定用户 + * @param id 用户id + * @param seconds 锁定时长(秒) + */ + function lockApi(id: string, seconds: number): Promise { + return request(`/api/identity/users/${id}/lock/${seconds}`, { + method: 'PUT', + }); + } + + /** + * 解锁用户 + * @param id 用户id + */ + function unLockApi(id: string): Promise { + return request(`/api/identity/users/${id}/unlock`, { + method: 'PUT', + }); + } + + /** + * 更改用户密码 + * @param id 用户id + * @param input 密码变更dto + */ + function changePasswordApi( + id: string, + input: ChangeUserPasswordInput, + ): Promise { + return request(`/api/identity/users/change-password?id=${id}`, { + data: input, + method: 'PUT', + }); + } + + /** + * 获取可用的角色列表 + */ + function getAssignableRolesApi(): Promise> { + return request>( + `/api/identity/users/assignable-roles`, + { + method: 'GET', + }, + ); + } + + /** + * 获取用户角色列表 + * @param id 用户id + */ + function getRolesApi(id: string): Promise> { + return request>( + `/api/identity/users/${id}/roles`, + { + method: 'GET', + }, + ); + } + + /** + * 获取用户声明列表 + * @param id 用户id + */ + function getClaimsApi(id: string): Promise> { + return request>( + `/api/identity/users/${id}/claims`, + { + method: 'GET', + }, + ); + } + + /** + * 删除用户声明 + * @param id 用户id + * @param input 用户声明dto + */ + function deleteClaimApi( + id: string, + input: IdentityClaimDeleteDto, + ): Promise { + return request(`/api/identity/users/${id}/claims`, { + method: 'DELETE', + params: input, + }); + } + + /** + * 创建用户声明 + * @param id 用户id + * @param input 用户声明dto + */ + function createClaimApi( + id: string, + input: IdentityClaimCreateDto, + ): Promise { + return request(`/api/identity/users/${id}/claims`, { + data: input, + method: 'POST', + }); + } + + /** + * 更新用户声明 + * @param id 用户id + * @param input 用户声明dto + */ + function updateClaimApi( + id: string, + input: IdentityClaimUpdateDto, + ): Promise { + return request(`/api/identity/users/${id}/claims`, { + data: input, + method: 'PUT', + }); + } + + return { + cancel, + changePasswordApi, + createApi, + createClaimApi, + deleteApi, + deleteClaimApi, + getApi, + getAssignableRolesApi, + getClaimsApi, + getOrganizationUnitsApi, + getPagedListApi, + getRolesApi, + lockApi, + removeOrganizationUnitApi, + unLockApi, + updateApi, + updateClaimApi, + }; +} diff --git a/apps/vben5/packages/@abp/identity/src/api/users-lookup.ts b/apps/vben5/packages/@abp/identity/src/api/users-lookup.ts deleted file mode 100644 index 443970ece..000000000 --- a/apps/vben5/packages/@abp/identity/src/api/users-lookup.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { ListResultDto } from '@abp/core'; - -import type { - IdentityUserDto, - UserLookupCountInput, - UserLookupSearchInput, -} from '../types/users'; - -import { requestClient } from '@abp/request'; - -/** - * 通过id查询用户 - * @param id 用户id - * @returns 用户实体数据传输对象 - */ -export function findByIdApi(id: string): Promise { - return requestClient.get(`/api/identity/users/lookup/${id}`); -} - -/** - * 通过用户名查询用户 - * @param userName 用户名 - * @returns 用户实体数据传输对象 - */ -export function findByUserNameApi(userName: string): Promise { - return requestClient.get( - `/api/identity/users/lookup/by-username/${userName}`, - ); -} - -/** - * 搜索用户列表 - * @param input 搜索过滤条件 - * @returns 用户实体数据传输对象列表 - */ -export function searchApi( - input?: UserLookupSearchInput, -): Promise> { - return requestClient.get>( - `/api/identity/users/lookup/search`, - { - params: input, - }, - ); -} - -/** - * 搜索用户数量 - * @param input 搜索过滤条件 - */ -export function countApi(input?: UserLookupCountInput): Promise { - return requestClient.get(`/api/identity/users/lookup/count`, { - params: input, - }); -} diff --git a/apps/vben5/packages/@abp/identity/src/api/users.ts b/apps/vben5/packages/@abp/identity/src/api/users.ts deleted file mode 100644 index 56848c068..000000000 --- a/apps/vben5/packages/@abp/identity/src/api/users.ts +++ /dev/null @@ -1,205 +0,0 @@ -import type { ListResultDto, PagedResultDto } from '@abp/core'; - -import type { IdentityRoleDto, OrganizationUnitDto } from '../types'; -import type { - IdentityClaimCreateDto, - IdentityClaimDeleteDto, - IdentityClaimDto, - IdentityClaimUpdateDto, -} from '../types/claims'; -import type { - ChangeUserPasswordInput, - GetUserPagedListInput, - IdentityUserCreateDto, - IdentityUserDto, - IdentityUserUpdateDto, -} from '../types/users'; - -import { requestClient } from '@abp/request'; - -/** - * 新增用户 - * @param input 参数 - * @returns 用户实体数据传输对象 - */ -export function createApi( - input: IdentityUserCreateDto, -): Promise { - return requestClient.post('/api/identity/users', input); -} - -/** - * 删除用户 - * @param id 用户id - */ -export function deleteApi(id: string): Promise { - return requestClient.delete(`/api/identity/users/${id}`); -} - -/** - * 查询用户 - * @param id 用户id - * @returns 用户实体数据传输对象 - */ -export function getApi(id: string): Promise { - return requestClient.get(`/api/identity/users/${id}`); -} - -/** - * 更新用户 - * @param id 用户id - * @returns 用户实体数据传输对象 - */ -export function updateApi( - id: string, - input: IdentityUserUpdateDto, -): Promise { - return requestClient.put(`/api/identity/users/${id}`, input); -} - -/** - * 查询用户分页列表 - * @param input 过滤参数 - * @returns 用户实体数据传输对象分页列表 - */ -export function getPagedListApi( - input?: GetUserPagedListInput, -): Promise> { - return requestClient.get>( - `/api/identity/users`, - { - params: input, - }, - ); -} - -/** - * 从组织机构中移除用户 - * @param id 用户id - * @param ouId 组织机构id - */ -export function removeOrganizationUnitApi( - id: string, - ouId: string, -): Promise { - return requestClient.delete( - `/api/identity/users/${id}/organization-units/${ouId}`, - ); -} - -/** - * 获取用户组织机构列表 - * @param id 用户id - */ -export function getOrganizationUnitsApi( - id: string, -): Promise> { - return requestClient.get>( - `/api/identity/users/${id}/organization-units`, - ); -} - -/** - * 锁定用户 - * @param id 用户id - * @param seconds 锁定时长(秒) - */ -export function lockApi(id: string, seconds: number): Promise { - return requestClient.put(`/api/identity/users/${id}/lock/${seconds}`); -} - -/** - * 解锁用户 - * @param id 用户id - */ -export function unLockApi(id: string): Promise { - return requestClient.put(`/api/identity/users/${id}/unlock`); -} - -/** - * 更改用户密码 - * @param id 用户id - * @param input 密码变更dto - */ -export function changePasswordApi( - id: string, - input: ChangeUserPasswordInput, -): Promise { - return requestClient.put( - `/api/identity/users/change-password?id=${id}`, - input, - ); -} - -/** - * 获取可用的角色列表 - */ -export function getAssignableRolesApi(): Promise< - ListResultDto -> { - return requestClient.get>( - `/api/identity/users/assignable-roles`, - ); -} - -/** - * 获取用户角色列表 - * @param id 用户id - */ -export function getRolesApi( - id: string, -): Promise> { - return requestClient.get>( - `/api/identity/users/${id}/roles`, - ); -} - -/** - * 获取用户声明列表 - * @param id 用户id - */ -export function getClaimsApi( - id: string, -): Promise> { - return requestClient.get>( - `/api/identity/users/${id}/claims`, - ); -} - -/** - * 删除用户声明 - * @param id 用户id - * @param input 用户声明dto - */ -export function deleteClaimApi( - id: string, - input: IdentityClaimDeleteDto, -): Promise { - return requestClient.delete(`/api/identity/users/${id}/claims`, { - params: input, - }); -} - -/** - * 创建用户声明 - * @param id 用户id - * @param input 用户声明dto - */ -export function createClaimApi( - id: string, - input: IdentityClaimCreateDto, -): Promise { - return requestClient.post(`/api/identity/users/${id}/claims`, input); -} - -/** - * 更新用户声明 - * @param id 用户id - * @param input 用户声明dto - */ -export function updateClaimApi( - id: string, - input: IdentityClaimUpdateDto, -): Promise { - return requestClient.put(`/api/identity/users/${id}/claims`, input); -} diff --git a/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeModal.vue b/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeModal.vue index 754e08fe7..17ed126ba 100644 --- a/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeModal.vue @@ -18,7 +18,7 @@ import { Textarea, } from 'ant-design-vue'; -import { createApi, getApi, updateApi } from '../../api/claim-types'; +import { useClaimTypesApi } from '../../api/useClaimTypesApi'; import { ValueType } from '../../types/claim-types'; defineOptions({ @@ -55,12 +55,16 @@ const valueTypeOptions = reactive([ }, ]); +const { cancel, createApi, getApi, updateApi } = useClaimTypesApi(); const [Modal, modalApi] = useVbenModal({ draggable: true, fullscreenButton: false, onCancel() { modalApi.close(); }, + onClosed() { + cancel('ClaimType Modal has closed!'); + }, onConfirm: async () => { await form.value?.validate(); const api = formModel.value.id diff --git a/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeTable.vue b/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeTable.vue index 174f5ef52..6a8ba2ae9 100644 --- a/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeTable.vue +++ b/apps/vben5/packages/@abp/identity/src/components/claim-types/ClaimTypeTable.vue @@ -14,7 +14,7 @@ import { useVbenVxeGrid } from '@abp/ui'; import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue'; import { Button, message, Modal } from 'ant-design-vue'; -import { deleteApi, getPagedListApi } from '../../api/claim-types'; +import { useClaimTypesApi } from '../../api/useClaimTypesApi'; import { IdentityClaimTypePermissions } from '../../constants/permissions'; import { ValueType } from '../../types/claim-types'; @@ -29,6 +29,7 @@ const CheckIcon = createIconifyIcon('ant-design:check-outlined'); const CloseIcon = createIconifyIcon('ant-design:close-outlined'); const { hasAccessByCodes } = useAccess(); +const { cancel, deleteApi, getPagedListApi } = useClaimTypesApi(); const formOptions: VbenFormProps = { // 默认展开 @@ -165,6 +166,9 @@ const handleDelete = (row: IdentityClaimTypeDto) => { Modal.confirm({ centered: true, content: $t('AbpIdentity.WillDeleteClaim', [row.name]), + onCancel: () => { + cancel('User closed delete modal.'); + }, onOk: async () => { await deleteApi(row.id); message.success($t('AbpUi.SuccessfullyDeleted')); diff --git a/apps/vben5/packages/@abp/identity/src/components/claims/ClaimModal.vue b/apps/vben5/packages/@abp/identity/src/components/claims/ClaimModal.vue index 4709cd7e4..029479902 100644 --- a/apps/vben5/packages/@abp/identity/src/components/claims/ClaimModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/claims/ClaimModal.vue @@ -5,7 +5,7 @@ import type { ClaimEditModalProps } from './types'; import { useVbenForm, useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { getAssignableClaimsApi } from '../../api/claim-types'; +import { useClaimTypesApi } from '../../api/useClaimTypesApi'; defineOptions({ name: 'ClaimModal', @@ -15,7 +15,7 @@ const { createApi, updateApi } = defineProps(); const emits = defineEmits<{ (event: 'change', data: IdentityClaimDto): void; }>(); - +const { cancel, getAssignableClaimsApi } = useClaimTypesApi(); const [Form, formApi] = useVbenForm({ commonConfig: { // 所有表单项 @@ -43,6 +43,9 @@ const [Form, formApi] = useVbenForm({ const [Modal, modalApi] = useVbenModal({ draggable: true, fullscreenButton: false, + onClosed() { + cancel('Claim modal has closed!'); + }, async onConfirm() { await formApi.validateAndSubmitForm(); }, diff --git a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitModal.vue b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitModal.vue index e9e25200e..7b9fcbf2f 100644 --- a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitModal.vue @@ -10,7 +10,7 @@ import { $t } from '@vben/locales'; import { useVbenForm } from '@abp/ui'; -import { createApi, getApi, updateApi } from '../../api/organization-units'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; defineOptions({ name: 'OrganizationUnitModal', @@ -23,6 +23,7 @@ const defaultModel = { displayName: '', } as OrganizationUnitDto; +const { cancel, createApi, getApi, updateApi } = useOrganizationUnitsApi(); const [Form, formApi] = useVbenForm({ handleSubmit: onSubmit, schema: [ @@ -65,6 +66,9 @@ const [Modal, modalApi] = useVbenModal({ onCancel() { modalApi.close(); }, + onClosed() { + cancel('Organization Unit Modal has closed!'); + }, onConfirm: async () => { await formApi.validateAndSubmitForm(); }, @@ -97,13 +101,13 @@ const [Modal, modalApi] = useVbenModal({ }); async function onSubmit(input: Record) { - const api = input.id - ? updateApi(input.id, input as OrganizationUnitUpdateDto) - : createApi(input as OrganizationUnitCreateDto); try { modalApi.setState({ confirmLoading: true, }); + const api = input.id + ? updateApi(input.id, input as OrganizationUnitUpdateDto) + : createApi(input as OrganizationUnitCreateDto); const dto = await api; emits('change', dto); modalApi.close(); diff --git a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitRoleTable.vue b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitRoleTable.vue index 3f50eb0bc..6d55021d2 100644 --- a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitRoleTable.vue +++ b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitRoleTable.vue @@ -15,8 +15,8 @@ import { import { DeleteOutlined, PlusOutlined } from '@ant-design/icons-vue'; import { Button, Modal } from 'ant-design-vue'; -import { addRoles, getRoleListApi } from '../../api/organization-units'; -import { removeOrganizationUnitApi } from '../../api/roles'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; +import { useRolesApi } from '../../api/useRolesApi'; import { OrganizationUnitPermissions } from '../../constants/permissions'; defineOptions({ @@ -32,6 +32,8 @@ const SelectRoleModal = defineAsyncComponent( ); const { hasAccessByCodes } = useAccess(); +const { addRoles, getRoleListApi } = useOrganizationUnitsApi(); +const { cancel, removeOrganizationUnitApi } = useRolesApi(); const getAddRoleEnabled = computed(() => { return ( @@ -100,7 +102,7 @@ const [RoleModal, roleModalApi] = useVbenModal({ }); const onRefresh = () => { - nextTick(query); + return nextTick(query); }; const onDelete = (row: IdentityRoleDto) => { @@ -109,11 +111,17 @@ const onDelete = (row: IdentityRoleDto) => { content: $t('AbpIdentity.OrganizationUnit:AreYouSureRemoveRole', [ row.name, ]), - onOk: () => { - setLoading(true); - return removeOrganizationUnitApi(row.id, props.selectedKey!) - .then(onRefresh) - .finally(() => setLoading(false)); + onCancel: () => { + cancel('User closed cancel delete modal.'); + }, + onOk: async () => { + try { + setLoading(true); + await removeOrganizationUnitApi(row.id, props.selectedKey!); + await onRefresh(); + } finally { + setLoading(false); + } }, title: $t('AbpUi.AreYouSure'), }); @@ -126,24 +134,23 @@ const onShowRole = () => { roleModalApi.open(); }; -const onCreateRole = (roles: IdentityRoleDto[]) => { - roleModalApi.setState({ - closable: false, - confirmLoading: true, - }); - addRoles(props.selectedKey!, { - roleIds: roles.map((item) => item.id), - }) - .then(() => { - roleModalApi.close(); - query(); - }) - .finally(() => { - roleModalApi.setState({ - closable: true, - confirmLoading: false, - }); +const onCreateRole = async (roles: IdentityRoleDto[]) => { + try { + roleModalApi.setState({ + closable: false, + confirmLoading: true, + }); + await addRoles(props.selectedKey!, { + roleIds: roles.map((item) => item.id), + }); + roleModalApi.close(); + await query(); + } finally { + roleModalApi.setState({ + closable: true, + confirmLoading: false, }); + } }; watch(() => props.selectedKey, onRefresh); diff --git a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitTree.vue b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitTree.vue index e4e7034ac..99f53aca3 100644 --- a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitTree.vue +++ b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitTree.vue @@ -29,13 +29,7 @@ import { Tree, } from 'ant-design-vue'; -import { - deleteApi, - getApi, - getChildrenApi, - getRootListApi, - moveTo, -} from '../../api/organization-units'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; defineOptions({ name: 'OrganizationUnitTree', @@ -45,6 +39,9 @@ const emits = defineEmits<{ (event: 'selected', id?: string): void; }>(); +const { deleteApi, getApi, getChildrenApi, getRootListApi, moveTo } = + useOrganizationUnitsApi(); + const MenuItem = Menu.Item; const PermissionsOutlined = createIconifyIcon('icon-park-outline:permissions'); const OrganizationUnitModal = defineAsyncComponent( @@ -169,9 +166,9 @@ function onDrop(info: AntTreeNodeDropEvent) { const eventKey = String(info.dragNode.eventKey); const api = info.dropPosition === -1 - ? moveTo(eventKey) // parent + ? moveTo(eventKey, undefined) // parent : moveTo(eventKey, String(info.node.eventKey)); // children - api.then(() => onRefresh()); + api.then(onRefresh); } onMounted(onRefresh); diff --git a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitUserTable.vue b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitUserTable.vue index 250105026..f304696a6 100644 --- a/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitUserTable.vue +++ b/apps/vben5/packages/@abp/identity/src/components/organization-units/OrganizationUnitUserTable.vue @@ -13,8 +13,8 @@ import { useVbenVxeGrid } from '@abp/ui'; import { DeleteOutlined, PlusOutlined } from '@ant-design/icons-vue'; import { Button, Modal } from 'ant-design-vue'; -import { addMembers, getUserListApi } from '../../api/organization-units'; -import { removeOrganizationUnitApi } from '../../api/users'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; +import { useUserApi } from '../../api/useUsersApi'; import { OrganizationUnitPermissions } from '../../constants/permissions'; defineOptions({ @@ -24,6 +24,8 @@ defineOptions({ const props = defineProps<{ selectedKey?: string; }>(); +const { cancel, removeOrganizationUnitApi } = useUserApi(); +const { addMembers, getUserListApi } = useOrganizationUnitsApi(); const SelectMemberModal = defineAsyncComponent( () => import('./SelectMemberModal.vue'), @@ -111,6 +113,9 @@ const onDelete = (row: IdentityUserDto) => { content: $t('AbpIdentity.OrganizationUnit:AreYouSureRemoveUser', [ row.userName, ]), + onCancel: () => { + cancel('User closed cancel delete modal.'); + }, onOk: () => { setLoading(true); return removeOrganizationUnitApi(row.id, props.selectedKey!) diff --git a/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectMemberModal.vue b/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectMemberModal.vue index 7980d2edf..c60fedc98 100644 --- a/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectMemberModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectMemberModal.vue @@ -10,7 +10,7 @@ import { $t } from '@vben/locales'; import { useVbenVxeGrid } from '@abp/ui'; -import { getUnaddedUserListApi } from '../../api/organization-units'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; defineOptions({ name: 'SelectMemberModal', @@ -18,6 +18,7 @@ defineOptions({ const emits = defineEmits<{ (event: 'confirm', items: IdentityUserDto[]): void; }>(); +const { cancel, getUnaddedUserListApi } = useOrganizationUnitsApi(); const selectedUsers = ref([]); @@ -52,6 +53,9 @@ const [Modal, modalApi] = useVbenModal({ onCancel() { modalApi.close(); }, + onClosed() { + cancel(); + }, onConfirm: async () => { emits('confirm', toValue(selectedUsers)); }, diff --git a/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectRoleModal.vue b/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectRoleModal.vue index 218818fc0..2ccea7392 100644 --- a/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectRoleModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/organization-units/SelectRoleModal.vue @@ -12,7 +12,7 @@ import { type VxeGridProps, } from '@abp/ui'; -import { getUnaddedRoleListApi } from '../../api/organization-units'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; defineOptions({ name: 'SelectRoleModal', @@ -20,6 +20,7 @@ defineOptions({ const emits = defineEmits<{ (event: 'confirm', items: IdentityRoleDto[]): void; }>(); +const { cancel, getUnaddedRoleListApi } = useOrganizationUnitsApi(); const selectedRoles = ref([]); @@ -54,6 +55,9 @@ const [Modal, modalApi] = useVbenModal({ onCancel() { modalApi.close(); }, + onClosed() { + cancel(); + }, onConfirm: async () => { emits('confirm', toValue(selectedRoles)); }, diff --git a/apps/vben5/packages/@abp/identity/src/components/roles/RoleClaimModal.vue b/apps/vben5/packages/@abp/identity/src/components/roles/RoleClaimModal.vue index 6fcc1c115..417745deb 100644 --- a/apps/vben5/packages/@abp/identity/src/components/roles/RoleClaimModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/roles/RoleClaimModal.vue @@ -11,12 +11,7 @@ import { defineAsyncComponent } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { - createClaimApi, - deleteClaimApi, - getClaimsApi, - updateClaimApi, -} from '../../api/roles'; +import { useRolesApi } from '../../api/useRolesApi'; import { IdentityRolePermissions } from '../../constants/permissions'; defineOptions({ @@ -27,12 +22,17 @@ const ClaimTable = defineAsyncComponent( () => import('../claims/ClaimTable.vue'), ); +const { cancel, createClaimApi, deleteClaimApi, getClaimsApi, updateClaimApi } = + useRolesApi(); const [Modal, modalApi] = useVbenModal({ draggable: true, fullscreenButton: false, onCancel() { modalApi.close(); }, + onClosed() { + cancel('Role Claim modal has closed!'); + }, onConfirm: async () => {}, showCancelButton: false, showConfirmButton: false, diff --git a/apps/vben5/packages/@abp/identity/src/components/roles/RoleModal.vue b/apps/vben5/packages/@abp/identity/src/components/roles/RoleModal.vue index 2a94f5b4d..b4739a371 100644 --- a/apps/vben5/packages/@abp/identity/src/components/roles/RoleModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/roles/RoleModal.vue @@ -10,7 +10,7 @@ import { $t } from '@vben/locales'; import { Checkbox, Form, Input, message } from 'ant-design-vue'; -import { createApi, getApi, updateApi } from '../../api/roles'; +import { useRolesApi } from '../../api/useRolesApi'; defineOptions({ name: 'RoleModal', @@ -30,12 +30,16 @@ const defaultModel = { const form = ref(); const formModel = ref({ ...defaultModel }); +const { cancel, createApi, getApi, updateApi } = useRolesApi(); const [Modal, modalApi] = useVbenModal({ draggable: true, fullscreenButton: false, onCancel() { modalApi.close(); }, + onClosed() { + cancel('Role modal has closed!'); + }, onConfirm: async () => { await form.value?.validate(); const api = formModel.value.id diff --git a/apps/vben5/packages/@abp/identity/src/components/roles/RoleTable.vue b/apps/vben5/packages/@abp/identity/src/components/roles/RoleTable.vue index e9c78dfb0..699d037e6 100644 --- a/apps/vben5/packages/@abp/identity/src/components/roles/RoleTable.vue +++ b/apps/vben5/packages/@abp/identity/src/components/roles/RoleTable.vue @@ -22,7 +22,7 @@ import { } from '@ant-design/icons-vue'; import { Button, Dropdown, Menu, message, Modal, Tag } from 'ant-design-vue'; -import { deleteApi, getPagedListApi } from '../../api/roles'; +import { useRolesApi } from '../../api/useRolesApi'; import { IdentityRolePermissions } from '../../constants/permissions'; defineOptions({ @@ -39,6 +39,8 @@ const RoleModal = defineAsyncComponent(() => import('./RoleModal.vue')); const ClaimModal = defineAsyncComponent(() => import('./RoleClaimModal.vue')); const abpStore = useAbpStore(); const { hasAccessByCodes } = useAccess(); +const { cancel, deleteApi, getPagedListApi } = useRolesApi(); + const [RolePermissionModal, permissionModalApi] = useVbenModal({ connectedComponent: PermissionModal, }); @@ -134,6 +136,9 @@ const handleDelete = (row: IdentityRoleDto) => { Modal.confirm({ centered: true, content: $t('AbpIdentity.RoleDeletionConfirmationMessage', [row.name]), + onCancel: () => { + cancel('User closed cancel delete modal.'); + }, onOk: async () => { await deleteApi(row.id); message.success($t('AbpUi.SuccessfullyDeleted')); diff --git a/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogDrawer.vue b/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogDrawer.vue index 39cd7f6ce..3ff85694c 100644 --- a/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogDrawer.vue +++ b/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogDrawer.vue @@ -9,7 +9,7 @@ import { $t } from '@vben/locales'; import { formatToDateTime } from '@abp/core'; import { Descriptions } from 'ant-design-vue'; -import { getApi } from '../../api/security-logs'; +import { useSecurityLogsApi } from '../../api/useSecurityLogsApi'; defineOptions({ name: 'SecurityLogDrawer', @@ -19,8 +19,13 @@ const DescriptionsItem = Descriptions.Item; const formModel = ref({} as SecurityLogDto); +const { cancel, getApi } = useSecurityLogsApi(); + const [Drawer, drawerApi] = useVbenDrawer({ class: 'w-auto', + onBeforeClose() { + cancel('Security log drawer has closed!'); + }, onCancel() { drawerApi.close(); }, diff --git a/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue b/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue index 77448e6f1..4cf9b08d0 100644 --- a/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue +++ b/apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue @@ -13,13 +13,14 @@ import { useVbenVxeGrid } from '@abp/ui'; import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue'; import { Button, message, Modal, Tag } from 'ant-design-vue'; -import { deleteApi, getPagedListApi } from '../../api/security-logs'; +import { useSecurityLogsApi } from '../../api/useSecurityLogsApi'; import { SecurityLogPermissions } from '../../constants/permissions'; defineOptions({ name: 'SecurityLogTable', }); +const { cancel, deleteApi, getPagedListApi } = useSecurityLogsApi(); const formOptions: VbenFormProps = { // 默认展开 collapsed: false, @@ -182,6 +183,7 @@ const gridOptions: VxeGridProps = { const gridEvents: VxeGridListeners = { sortChange: onSort, }; + const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridEvents, @@ -202,6 +204,9 @@ function onDelete(row: SecurityLogDto) { Modal.confirm({ centered: true, content: $t('AbpUi.ItemWillBeDeletedMessage'), + onCancel: () => { + cancel('User closed cancel delete modal.'); + }, onOk: async () => { await deleteApi(row.id); message.success($t('AbpUi.SuccessfullyDeleted')); diff --git a/apps/vben5/packages/@abp/identity/src/components/users/UserClaimModal.vue b/apps/vben5/packages/@abp/identity/src/components/users/UserClaimModal.vue index 1ce9b43e2..0b602428d 100644 --- a/apps/vben5/packages/@abp/identity/src/components/users/UserClaimModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/users/UserClaimModal.vue @@ -11,12 +11,7 @@ import { defineAsyncComponent } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { - createClaimApi, - deleteClaimApi, - getClaimsApi, - updateClaimApi, -} from '../../api/users'; +import { useUserApi } from '../../api/useUsersApi'; import { IdentityUserPermissions } from '../../constants/permissions'; defineOptions({ @@ -27,13 +22,17 @@ const ClaimTable = defineAsyncComponent( () => import('../claims/ClaimTable.vue'), ); +const { cancel, createClaimApi, deleteClaimApi, getClaimsApi, updateClaimApi } = + useUserApi(); const [Modal, modalApi] = useVbenModal({ draggable: true, fullscreenButton: false, onCancel() { modalApi.close(); }, - onConfirm: async () => {}, + onClosed() { + cancel('User claim modal has closed!'); + }, showCancelButton: false, showConfirmButton: false, title: $t('AbpIdentity.ManageClaim'), diff --git a/apps/vben5/packages/@abp/identity/src/components/users/UserLockModal.vue b/apps/vben5/packages/@abp/identity/src/components/users/UserLockModal.vue index 235a7c03b..2a5b778d1 100644 --- a/apps/vben5/packages/@abp/identity/src/components/users/UserLockModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/users/UserLockModal.vue @@ -5,7 +5,7 @@ import { $t } from '@vben/locales'; import { useVbenForm } from '@abp/ui'; -import { lockApi } from '../../api/users'; +import { useUserApi } from '../../api/useUsersApi'; defineOptions({ name: 'UserLockModal', @@ -23,6 +23,7 @@ enum LockType { Years = 32_140_800, // 按31*12天计算 } +const { cancel, lockApi } = useUserApi(); const [Form, formApi] = useVbenForm({ commonConfig: { // 所有表单项 @@ -77,6 +78,9 @@ const [Modal, modalApi] = useVbenModal({ onCancel() { modalApi.close(); }, + onClosed() { + cancel('User lock modal has closed!'); + }, onConfirm: async () => { await formApi.validateAndSubmitForm(); }, diff --git a/apps/vben5/packages/@abp/identity/src/components/users/UserModal.vue b/apps/vben5/packages/@abp/identity/src/components/users/UserModal.vue index e0b7b3023..d56e643e7 100644 --- a/apps/vben5/packages/@abp/identity/src/components/users/UserModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/users/UserModal.vue @@ -23,15 +23,8 @@ import { Tree, } from 'ant-design-vue'; -import { getChildrenApi, getRootListApi } from '../../api/organization-units'; -import { - createApi, - getApi, - getAssignableRolesApi, - getOrganizationUnitsApi, - getRolesApi, - updateApi, -} from '../../api/users'; +import { useOrganizationUnitsApi } from '../../api/useOrganizationUnitsApi'; +import { useUserApi } from '../../api/useUsersApi'; defineOptions({ name: 'UserModal', @@ -62,12 +55,25 @@ const formModel = ref({ ...defaultModel }); const { isTrue } = useSettings(); const { hasAccessByCodes } = useAccess(); +const { + cancel, + createApi, + getApi, + getAssignableRolesApi, + getOrganizationUnitsApi, + getRolesApi, + updateApi, +} = useUserApi(); +const { getChildrenApi, getRootListApi } = useOrganizationUnitsApi(); const [Modal, modalApi] = useVbenModal({ draggable: true, fullscreenButton: false, onCancel() { modalApi.close(); }, + onClosed() { + cancel('User modal has closed!'); + }, onConfirm: async () => { await form.value?.validate(); const api = formModel.value.id @@ -99,12 +105,16 @@ const [Modal, modalApi] = useVbenModal({ const userDto = modalApi.getData(); const manageRolePolicy = checkManageRolePolicy(); if (userDto?.id) { - await initUserInfo(userDto.id); - manageRolePolicy && (await initUserRoles(userDto.id)); - checkManageOuPolicy() && (await initOrganizationUnitTree(userDto.id)); + await Promise.all([ + initUserInfo(userDto.id), + manageRolePolicy && initUserRoles(userDto.id), + manageRolePolicy && initAssignableRoles(), + checkManageOuPolicy() && initOrganizationUnitTree(userDto.id), + ]); modalApi.setState({ title: `${$t('AbpIdentity.Users')} - ${userDto.userName}`, }); + return; } manageRolePolicy && (await initAssignableRoles()); } finally { @@ -165,7 +175,10 @@ async function initAssignableRoles() { * @param userId 用户id */ async function initOrganizationUnitTree(userId: string) { - const ouResult = await getRootListApi(); + const [ouResult, userOuResult] = await Promise.all([ + getRootListApi(), + getOrganizationUnitsApi(userId), + ]); organizationUnits.value = ouResult.items.map((item) => { return { isLeaf: false, @@ -174,7 +187,6 @@ async function initOrganizationUnitTree(userId: string) { children: [], }; }); - const userOuResult = await getOrganizationUnitsApi(userId); checkedOuKeys.value = userOuResult.items.map((item) => item.id); } diff --git a/apps/vben5/packages/@abp/identity/src/components/users/UserPasswordModal.vue b/apps/vben5/packages/@abp/identity/src/components/users/UserPasswordModal.vue index 7b25e3e6e..b516ee8f1 100644 --- a/apps/vben5/packages/@abp/identity/src/components/users/UserPasswordModal.vue +++ b/apps/vben5/packages/@abp/identity/src/components/users/UserPasswordModal.vue @@ -7,7 +7,7 @@ import { $t } from '@vben/locales'; import { Button, message } from 'ant-design-vue'; -import { changePasswordApi } from '../../api/users'; +import { useUserApi } from '../../api/useUsersApi'; import { useRandomPassword } from '../../hooks'; defineOptions({ @@ -18,6 +18,7 @@ const emits = defineEmits<{ }>(); const { generatePassword } = useRandomPassword(); +const { cancel, changePasswordApi } = useUserApi(); const [Form, formApi] = useVbenForm({ commonConfig: { @@ -62,6 +63,9 @@ const [Modal, modalApi] = useVbenModal({ onCancel() { modalApi.close(); }, + onClosed() { + cancel('User password modal has closed!'); + }, onConfirm: async () => { try { modalApi.setState({ confirmLoading: true }); diff --git a/apps/vben5/packages/@abp/identity/src/components/users/UserTable.vue b/apps/vben5/packages/@abp/identity/src/components/users/UserTable.vue index 97000c259..f4e579c6b 100644 --- a/apps/vben5/packages/@abp/identity/src/components/users/UserTable.vue +++ b/apps/vben5/packages/@abp/identity/src/components/users/UserTable.vue @@ -25,7 +25,7 @@ import { } from '@ant-design/icons-vue'; import { Button, Dropdown, Menu, message, Modal } from 'ant-design-vue'; -import { deleteApi, getPagedListApi, unLockApi } from '../../api/users'; +import { useUserApi } from '../../api/useUsersApi'; import { IdentityUserPermissions } from '../../constants/permissions'; defineOptions({ @@ -64,6 +64,7 @@ const getLockEnd = computed(() => { const abpStore = useAbpStore(); const { hasAccessByCodes } = useAccess(); +const { cancel, deleteApi, getPagedListApi, unLockApi } = useUserApi(); const formOptions: VbenFormProps = { // 默认展开 @@ -184,6 +185,9 @@ const handleDelete = (row: IdentityUserDto) => { Modal.confirm({ centered: true, content: $t('AbpIdentity.UserDeletionConfirmationMessage', [row.userName]), + onCancel: () => { + cancel('User closed cancel delete modal.'); + }, onOk: async () => { await deleteApi(row.id); message.success($t('AbpUi.SuccessfullyDeleted')); diff --git a/apps/vben5/packages/@abp/request/package.json b/apps/vben5/packages/@abp/request/package.json index edaf1f8ab..e409b6b2b 100644 --- a/apps/vben5/packages/@abp/request/package.json +++ b/apps/vben5/packages/@abp/request/package.json @@ -22,6 +22,8 @@ "dependencies": { "@abp/core": "workspace:*", "@vben/hooks": "workspace:*", - "@vben/request": "workspace:*" + "@vben/request": "workspace:*", + "axios": "catalog:", + "vue": "catalog:" } } diff --git a/apps/vben5/packages/@abp/request/src/hooks/index.ts b/apps/vben5/packages/@abp/request/src/hooks/index.ts new file mode 100644 index 000000000..46b76416d --- /dev/null +++ b/apps/vben5/packages/@abp/request/src/hooks/index.ts @@ -0,0 +1 @@ +export * from './useRequest'; diff --git a/apps/vben5/packages/@abp/request/src/hooks/useRequest.ts b/apps/vben5/packages/@abp/request/src/hooks/useRequest.ts new file mode 100644 index 000000000..723e05352 --- /dev/null +++ b/apps/vben5/packages/@abp/request/src/hooks/useRequest.ts @@ -0,0 +1,60 @@ +import type { AxiosRequestConfig } from 'axios'; + +import { onUnmounted } from 'vue'; + +import { requestClient } from '@abp/request'; + +type HttpMethod = + | 'CONNECT' + | 'DELETE' + | 'GET' + | 'HEAD' + | 'OPTIONS' + | 'PATCH' + | 'POST' + | 'PURGE' + | 'PUT' + | 'TRACE'; + +interface RequestConfig extends AxiosRequestConfig { + method: HttpMethod; +} + +interface RequestLifeCycle { + /** 是否自动销毁令牌 */ + autoDestroy?: boolean; +} + +export function useRequest(options?: RequestLifeCycle) { + const controllers = new Set(); + + function request(url: string, config: RequestConfig): Promise { + const controller = new AbortController(); + controllers.add(controller); + return requestClient + .request(url, { + ...config, + signal: controller.signal, + }) + .finally(() => { + controllers.delete(controller); + }); + } + + function cancel(message?: string) { + controllers.forEach((controller) => controller.abort(message)); + controllers.clear(); + } + + onUnmounted(() => { + if (options?.autoDestroy === false) { + return; + } + cancel('The Component has Unmounted!'); + }); + + return { + cancel, + request, + }; +} diff --git a/apps/vben5/packages/@abp/request/src/index.ts b/apps/vben5/packages/@abp/request/src/index.ts index 680d6d093..7afea27eb 100644 --- a/apps/vben5/packages/@abp/request/src/index.ts +++ b/apps/vben5/packages/@abp/request/src/index.ts @@ -5,6 +5,9 @@ import { useAppConfig } from '@vben/hooks'; import { RequestClient } from '@vben/request'; +export * from './hooks'; +export * from './types'; + const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD); function createRequestClient(baseURL: string) { diff --git a/apps/vben5/packages/@abp/request/src/types/index.ts b/apps/vben5/packages/@abp/request/src/types/index.ts new file mode 100644 index 000000000..f0417c8db --- /dev/null +++ b/apps/vben5/packages/@abp/request/src/types/index.ts @@ -0,0 +1 @@ +export type { CancelToken as CancellationToken } from 'axios';