42 changed files with 844 additions and 265 deletions
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
public class IdentityRoleAddOrRemoveOrganizationUnitDto |
||||
|
{ |
||||
|
[Required] |
||||
|
public Guid[] OrganizationUnitIds { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
public class IdentityUserOrganizationUnitUpdateDto |
||||
|
{ |
||||
|
[Required] |
||||
|
public Guid[] OrganizationUnitIds { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
public interface IIdentityRoleAppService : IApplicationService |
||||
|
{ |
||||
|
Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id); |
||||
|
Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
public interface IIdentityUserAppService : IApplicationService |
||||
|
{ |
||||
|
Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id); |
||||
|
Task UpdateOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
[Authorize(IdentityPermissions.Roles.ManageOrganizationUnits)] |
||||
|
public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService |
||||
|
{ |
||||
|
protected IIdentityRoleRepository IdentityRoleRepository { get; } |
||||
|
protected OrganizationUnitManager OrganizationUnitManager { get; } |
||||
|
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
||||
|
public IdentityRoleAppService( |
||||
|
IIdentityRoleRepository roleRepository, |
||||
|
OrganizationUnitManager organizationUnitManager) |
||||
|
{ |
||||
|
OrganizationUnitManager = organizationUnitManager; |
||||
|
IdentityRoleRepository = roleRepository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id) |
||||
|
{ |
||||
|
var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id); |
||||
|
|
||||
|
return new ListResultDto<OrganizationUnitDto>( |
||||
|
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input) |
||||
|
{ |
||||
|
var origanizationUnits = await IdentityRoleRepository.GetOrganizationUnitsAsync(id, true); |
||||
|
|
||||
|
var notInRoleOuIds = input.OrganizationUnitIds.Where(ouid => !origanizationUnits.Any(ou => ou.Id.Equals(ouid))); |
||||
|
|
||||
|
foreach (var ouId in notInRoleOuIds) |
||||
|
{ |
||||
|
await OrganizationUnitManager.AddRoleToOrganizationUnitAsync(id, ouId); |
||||
|
} |
||||
|
|
||||
|
var removeRoleOriganzationUnits = origanizationUnits.Where(ou => !input.OrganizationUnitIds.Contains(ou.Id)); |
||||
|
foreach (var origanzationUnit in removeRoleOriganzationUnits) |
||||
|
{ |
||||
|
origanzationUnit.RemoveRole(id); |
||||
|
} |
||||
|
|
||||
|
await CurrentUnitOfWork.SaveChangesAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
[Authorize(IdentityPermissions.Users.ManageOrganizationUnits)] |
||||
|
public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppService |
||||
|
{ |
||||
|
protected IdentityUserManager UserManager { get; } |
||||
|
public IdentityUserAppService( |
||||
|
IdentityUserManager userManager) |
||||
|
{ |
||||
|
UserManager = userManager; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id) |
||||
|
{ |
||||
|
var user = await UserManager.GetByIdAsync(id); |
||||
|
|
||||
|
var origanizationUnits = await UserManager.GetOrganizationUnitsAsync(user); |
||||
|
|
||||
|
return new ListResultDto<OrganizationUnitDto>( |
||||
|
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task UpdateOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input) |
||||
|
{ |
||||
|
var user = await UserManager.GetByIdAsync(id); |
||||
|
|
||||
|
await UserManager.SetOrganizationUnitsAsync(user, input.OrganizationUnitIds); |
||||
|
|
||||
|
await CurrentUnitOfWork.SaveChangesAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Volo.Abp.Identity.Domain" Version="3.0.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
[DependsOn(typeof(Volo.Abp.Identity.AbpIdentityDomainModule))] |
||||
|
public class AbpIdentityDomainModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
public interface IIdentityRoleRepository : Volo.Abp.Identity.IIdentityRoleRepository |
||||
|
{ |
||||
|
Task<List<OrganizationUnit>> GetOrganizationUnitsAsync( |
||||
|
Guid id, |
||||
|
bool includeDetails = false, |
||||
|
CancellationToken cancellationToken = default); |
||||
|
|
||||
|
Task<List<IdentityRole>> GetRolesInOrganizationUnitAsync( |
||||
|
Guid organizationUnitId, |
||||
|
CancellationToken cancellationToken = default |
||||
|
); |
||||
|
Task<List<IdentityRole>> GetRolesInOrganizationsListAsync( |
||||
|
List<Guid> organizationUnitIds, |
||||
|
CancellationToken cancellationToken = default |
||||
|
); |
||||
|
|
||||
|
Task<List<IdentityRole>> GetRolesInOrganizationUnitWithChildrenAsync( |
||||
|
string code, |
||||
|
CancellationToken cancellationToken = default |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Volo.Abp.Identity.EntityFrameworkCore" Version="3.0.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,20 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Identity.EntityFrameworkCore; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity.EntityFrameworkCore |
||||
|
{ |
||||
|
[DependsOn(typeof(LINGYUN.Abp.Identity.AbpIdentityDomainModule))] |
||||
|
[DependsOn(typeof(Volo.Abp.Identity.EntityFrameworkCore.AbpIdentityEntityFrameworkCoreModule))] |
||||
|
public class AbpIdentityEntityFrameworkCoreModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddAbpDbContext<IdentityDbContext>(options => |
||||
|
{ |
||||
|
options.AddRepository<IdentityRole, EfCoreIdentityRoleRepository>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Internal; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Dynamic.Core; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Identity.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity.EntityFrameworkCore |
||||
|
{ |
||||
|
public class EfCoreIdentityRoleRepository : Volo.Abp.Identity.EntityFrameworkCore.EfCoreIdentityRoleRepository, IIdentityRoleRepository |
||||
|
{ |
||||
|
public EfCoreIdentityRoleRepository( |
||||
|
IDbContextProvider<IIdentityDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync( |
||||
|
Guid id, |
||||
|
bool includeDetails = false, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var query = from roleOU in DbContext.Set<OrganizationUnitRole>() |
||||
|
join ou in DbContext.OrganizationUnits.IncludeDetails(includeDetails) on roleOU.OrganizationUnitId equals ou.Id |
||||
|
where roleOU.RoleId == id |
||||
|
select ou; |
||||
|
|
||||
|
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<IdentityRole>> GetRolesInOrganizationsListAsync( |
||||
|
List<Guid> organizationUnitIds, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var query = from roleOu in DbContext.Set<OrganizationUnitRole>() |
||||
|
join user in DbSet on roleOu.RoleId equals user.Id |
||||
|
where organizationUnitIds.Contains(roleOu.OrganizationUnitId) |
||||
|
select user; |
||||
|
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<IdentityRole>> GetRolesInOrganizationUnitAsync( |
||||
|
Guid organizationUnitId, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var query = from roleOu in DbContext.Set<OrganizationUnitRole>() |
||||
|
join user in DbSet on roleOu.RoleId equals user.Id |
||||
|
where roleOu.OrganizationUnitId == organizationUnitId |
||||
|
select user; |
||||
|
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<IdentityRole>> GetRolesInOrganizationUnitWithChildrenAsync( |
||||
|
string code, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var query = from roleOU in DbContext.Set<OrganizationUnitRole>() |
||||
|
join user in DbSet on roleOU.RoleId equals user.Id |
||||
|
join ou in DbContext.Set<OrganizationUnit>() on roleOU.OrganizationUnitId equals ou.Id |
||||
|
where ou.Code.StartsWith(code) |
||||
|
select user; |
||||
|
return await query.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
[RemoteService(true, Name = IdentityRemoteServiceConsts.RemoteServiceName)] |
||||
|
[Area("identity")] |
||||
|
[ControllerName("Role")] |
||||
|
[Route("api/identity/roles")] |
||||
|
public class IIdentityRoleController : AbpController, IIdentityRoleAppService |
||||
|
{ |
||||
|
protected IIdentityRoleAppService RoleAppService { get; } |
||||
|
public IIdentityRoleController( |
||||
|
IIdentityRoleAppService roleAppService) |
||||
|
{ |
||||
|
RoleAppService = roleAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("organization-units/{id}")] |
||||
|
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id) |
||||
|
{ |
||||
|
return await RoleAppService.GetOrganizationUnitsAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("organization-units/{id}")] |
||||
|
public virtual async Task SetOrganizationUnitsAsync(Guid id, IdentityRoleAddOrRemoveOrganizationUnitDto input) |
||||
|
{ |
||||
|
await RoleAppService.SetOrganizationUnitsAsync(id, input); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Identity |
||||
|
{ |
||||
|
[RemoteService(true, Name = IdentityRemoteServiceConsts.RemoteServiceName)] |
||||
|
[Area("identity")] |
||||
|
[ControllerName("User")] |
||||
|
[Route("api/identity/users")] |
||||
|
public class IIdentityUserController : AbpController, IIdentityUserAppService |
||||
|
{ |
||||
|
protected IIdentityUserAppService UserAppService { get; } |
||||
|
public IIdentityUserController( |
||||
|
IIdentityUserAppService userAppService) |
||||
|
{ |
||||
|
UserAppService = userAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("organization-units/{id}")] |
||||
|
public virtual async Task<ListResultDto<OrganizationUnitDto>> GetOrganizationUnitsAsync(Guid id) |
||||
|
{ |
||||
|
return await UserAppService.GetOrganizationUnitsAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
[Route("organization-units/{id}")] |
||||
|
public virtual async Task UpdateOrganizationUnitsAsync(Guid id, IdentityUserOrganizationUnitUpdateDto input) |
||||
|
{ |
||||
|
await UserAppService.UpdateOrganizationUnitsAsync(id, input); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,108 @@ |
|||||
|
<template> |
||||
|
<el-tree |
||||
|
ref="organizationUnitTree" |
||||
|
show-checkbox |
||||
|
node-key="id" |
||||
|
:props="organizationUnitProps" |
||||
|
:load="loadOrganizationUnit" |
||||
|
lazy |
||||
|
draggable |
||||
|
highlight-current |
||||
|
:default-checked-keys="checkedOrganizationUnits" |
||||
|
@check="onOrganizationUnitsChecked" |
||||
|
/> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts"> |
||||
|
import { Component, Prop, Watch, Vue } from 'vue-property-decorator' |
||||
|
import { ListResultDto } from '@/api/types' |
||||
|
import OrganizationUnitService, { OrganizationUnit } from '@/api/organizationunit' |
||||
|
|
||||
|
class OrganizationUnitTree { |
||||
|
id?: string |
||||
|
parentId?: string |
||||
|
code!: string |
||||
|
displayName!: string |
||||
|
isLeaf!: boolean |
||||
|
children?: OrganizationUnitTree[] |
||||
|
|
||||
|
constructor() { |
||||
|
this.isLeaf = false |
||||
|
this.children = new Array<OrganizationUnitTree>() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Component({ |
||||
|
name: 'OrganizationUnitTree', |
||||
|
data() { |
||||
|
return { |
||||
|
organizationUnitProps: { |
||||
|
label: 'displayName', |
||||
|
isLeaf: 'isLeaf', |
||||
|
children: 'children' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
|
export default class extends Vue { |
||||
|
@Prop({ default: () => { return new Array<string>() } }) |
||||
|
private checkedOrganizationUnits!: string[] |
||||
|
|
||||
|
private selectionOrganizationUnits = new Array<string>() |
||||
|
|
||||
|
@Watch('checkedOrganizationUnits') |
||||
|
private onOrganizationUnitsChanged() { |
||||
|
const elTree = this.$refs.organizationUnitTree as any |
||||
|
elTree.setCheckedKeys(this.checkedOrganizationUnits) |
||||
|
} |
||||
|
|
||||
|
private onOrganizationUnitsChecked(data: any, treeCheckData: any) { |
||||
|
const checkKeys = treeCheckData.checkedKeys |
||||
|
const valiadOuId = checkKeys.findIndex((key: string) => key === undefined) |
||||
|
if (valiadOuId !== -1) { |
||||
|
checkKeys.splice(valiadOuId, 1) |
||||
|
} |
||||
|
this.$emit('onOrganizationUnitsChanged', checkKeys) |
||||
|
} |
||||
|
|
||||
|
private async loadOrganizationUnit(node: any, resolve: any) { |
||||
|
if (node.level === 0) { |
||||
|
const rootOrganizationUnit = new OrganizationUnitTree() |
||||
|
rootOrganizationUnit.id = undefined |
||||
|
rootOrganizationUnit.parentId = undefined |
||||
|
rootOrganizationUnit.code = 'root' |
||||
|
rootOrganizationUnit.displayName = '组织机构' |
||||
|
return resolve([rootOrganizationUnit]) |
||||
|
} |
||||
|
let organizationUnitItems = new ListResultDto<OrganizationUnit>() |
||||
|
if (node.data.id === undefined) { |
||||
|
// 根节点 |
||||
|
organizationUnitItems = await OrganizationUnitService.getRootOrganizationUnits() |
||||
|
} else { |
||||
|
// 子节点 |
||||
|
organizationUnitItems = await OrganizationUnitService.findOrganizationUnitChildren(node.data.id, undefined) |
||||
|
} |
||||
|
if (organizationUnitItems.items.length !== 0) { |
||||
|
const organizationUnits = new Array<OrganizationUnitTree>() |
||||
|
organizationUnitItems.items.map((item) => { |
||||
|
const organizationUnit = new OrganizationUnitTree() |
||||
|
organizationUnit.id = item.id |
||||
|
organizationUnit.parentId = item.parentId |
||||
|
organizationUnit.code = item.code |
||||
|
organizationUnit.displayName = item.displayName |
||||
|
organizationUnits.push(organizationUnit) |
||||
|
const children = node.data.children as OrganizationUnitTree[] |
||||
|
if (!children.every(x => x.id === item.id)) { |
||||
|
children.push(organizationUnit) |
||||
|
} |
||||
|
}) |
||||
|
return resolve(organizationUnits) |
||||
|
} |
||||
|
return resolve([]) |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
|
||||
|
</style> |
||||
@ -0,0 +1,196 @@ |
|||||
|
<template> |
||||
|
<el-form |
||||
|
ref="formEditRole" |
||||
|
label-width="110px" |
||||
|
:model="role" |
||||
|
:rules="roleRules" |
||||
|
> |
||||
|
<el-tabs v-model="roleTabItem"> |
||||
|
<el-tab-pane |
||||
|
:label="$t('roles.basic')" |
||||
|
name="basic" |
||||
|
> |
||||
|
<el-form-item |
||||
|
prop="name" |
||||
|
:label="$t('roles.name')" |
||||
|
> |
||||
|
<el-input |
||||
|
v-model="role.name" |
||||
|
:disabled="role.isStatic" |
||||
|
:placeholder="$t('global.pleaseInputBy', {key: $t('roles.name')})" |
||||
|
/> |
||||
|
</el-form-item> |
||||
|
</el-tab-pane> |
||||
|
<el-tab-pane |
||||
|
:label="$t('roles.organizationUnits')" |
||||
|
name="organizationUnits" |
||||
|
> |
||||
|
<organization-unit-tree |
||||
|
:checked-organization-units="roleOrganizationUnits" |
||||
|
@onOrganizationUnitsChanged="onOrganizationUnitsChanged" |
||||
|
/> |
||||
|
</el-tab-pane> |
||||
|
<el-tab-pane |
||||
|
v-if="rolePermissionLoaded" |
||||
|
:label="$t('roles.permission')" |
||||
|
name="permissions" |
||||
|
> |
||||
|
<permission-tree |
||||
|
ref="permissionTree" |
||||
|
:expanded="false" |
||||
|
:readonly="!checkPermission(['AbpIdentity.Roles.ManagePermissions'])" |
||||
|
:permission="rolePermission" |
||||
|
@onPermissionChanged="onPermissionChanged" |
||||
|
/> |
||||
|
</el-tab-pane> |
||||
|
</el-tabs> |
||||
|
<el-form-item> |
||||
|
<el-button |
||||
|
class="cancel" |
||||
|
style="width:100px" |
||||
|
@click="onCancel" |
||||
|
> |
||||
|
{{ $t('global.cancel') }} |
||||
|
</el-button> |
||||
|
<el-button |
||||
|
class="confirm" |
||||
|
type="primary" |
||||
|
style="width:100px" |
||||
|
@click="onConfirm" |
||||
|
> |
||||
|
{{ $t('global.confirm') }} |
||||
|
</el-button> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts"> |
||||
|
import { IPermission } from '@/api/types' |
||||
|
import { checkPermission } from '@/utils/permission' |
||||
|
import { Component, Prop, Watch, Vue } from 'vue-property-decorator' |
||||
|
import RoleService, { RoleDto, UpdateRoleDto } from '@/api/roles' |
||||
|
import PermissionTree from '@/components/PermissionTree/index.vue' |
||||
|
import OrganizationUnitTree from '@/components/OrganizationUnitTree/index.vue' |
||||
|
import PermissionService, { PermissionDto, UpdatePermissionsDto } from '@/api/permission' |
||||
|
import { ChangeUserOrganizationUnitDto } from '@/api/users' |
||||
|
|
||||
|
@Component({ |
||||
|
name: 'RoleEditForm', |
||||
|
components: { |
||||
|
PermissionTree, |
||||
|
OrganizationUnitTree |
||||
|
}, |
||||
|
methods: { |
||||
|
checkPermission |
||||
|
} |
||||
|
}) |
||||
|
export default class extends Vue { |
||||
|
@Prop({ default: '' }) |
||||
|
private roleId!: string |
||||
|
|
||||
|
private roleTabItem = 'basic' |
||||
|
private role = new RoleDto() |
||||
|
/** 是否加载用户权限 */ |
||||
|
private rolePermissionLoaded = false |
||||
|
private roleOrganizationUnitChanged = false |
||||
|
private roleOrganizationUnits = new Array<string>() |
||||
|
|
||||
|
/** 角色权限数据 */ |
||||
|
private rolePermission = new PermissionDto() |
||||
|
/** 角色权限已变更 */ |
||||
|
private rolePermissionChanged = false |
||||
|
/** 变更角色权限数据 */ |
||||
|
private editRolePermissions = new Array<IPermission>() |
||||
|
|
||||
|
private roleRules = { |
||||
|
name: [ |
||||
|
{ required: true, message: this.l('global.pleaseInputBy', { key: this.l('roles.name') }), trigger: 'blur' }, |
||||
|
{ min: 3, max: 20, message: this.l('global.charLengthRange', { min: 3, max: 20 }), trigger: 'blur' } |
||||
|
] |
||||
|
} |
||||
|
|
||||
|
@Watch('roleId', { immediate: true }) |
||||
|
private onRoleIdChanged() { |
||||
|
if (this.roleId) { |
||||
|
RoleService.getRoleById(this.roleId).then(role => { |
||||
|
this.role = role |
||||
|
this.handledGetRoleOrganizationUnits(role.id) |
||||
|
this.handleGetRolePermissions(role.name) |
||||
|
}) |
||||
|
} |
||||
|
this.roleOrganizationUnitChanged = false |
||||
|
this.roleOrganizationUnits = new Array<string>() |
||||
|
} |
||||
|
|
||||
|
private handledGetRoleOrganizationUnits(roleId: string) { |
||||
|
RoleService.getRoleOrganizationUnits(roleId).then(res => { |
||||
|
this.roleOrganizationUnits = res.items.map(ou => ou.id) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
private handleGetRolePermissions(roleName: string) { |
||||
|
PermissionService.getPermissionsByKey('R', roleName).then(permission => { |
||||
|
this.rolePermission = permission |
||||
|
this.rolePermissionLoaded = true |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
private onOrganizationUnitsChanged(checkedKeys: string[]) { |
||||
|
this.roleOrganizationUnitChanged = true |
||||
|
this.roleOrganizationUnits = checkedKeys |
||||
|
} |
||||
|
|
||||
|
private onPermissionChanged(permissions: IPermission[]) { |
||||
|
this.rolePermissionChanged = true |
||||
|
this.editRolePermissions = permissions |
||||
|
} |
||||
|
|
||||
|
private onConfirm() { |
||||
|
const frmRole = this.$refs.formEditRole as any |
||||
|
frmRole.validate(async(valid: boolean) => { |
||||
|
if (valid) { |
||||
|
const roleUpdateDto = new UpdateRoleDto() |
||||
|
roleUpdateDto.name = this.role.name |
||||
|
roleUpdateDto.isPublic = this.role.isPublic |
||||
|
roleUpdateDto.isDefault = this.role.isDefault |
||||
|
roleUpdateDto.concurrencyStamp = this.role.concurrencyStamp |
||||
|
if (this.rolePermissionChanged) { |
||||
|
const setRolePermissions = new UpdatePermissionsDto() |
||||
|
setRolePermissions.permissions = this.editRolePermissions |
||||
|
await PermissionService.setPermissionsByKey('R', this.rolePermission.entityDisplayName, setRolePermissions) |
||||
|
} |
||||
|
if (this.roleOrganizationUnitChanged) { |
||||
|
const roleOrganizationUnitDto = new ChangeUserOrganizationUnitDto() |
||||
|
roleOrganizationUnitDto.organizationUnitIds = this.roleOrganizationUnits |
||||
|
await RoleService.changeRoleOrganizationUnits(this.roleId, roleOrganizationUnitDto) |
||||
|
} |
||||
|
RoleService.updateRole(this.roleId, roleUpdateDto).then(role => { |
||||
|
this.$message.success(this.l('roles.updateRoleSuccess', { name: role.name })) |
||||
|
this.onCancel() |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
private onCancel() { |
||||
|
this.rolePermissionLoaded = false |
||||
|
this.roleTabItem = 'basic' |
||||
|
this.$emit('onClosed') |
||||
|
} |
||||
|
|
||||
|
private l(name: string, values?: any[] | { [key: string]: any }) { |
||||
|
return this.$t(name, values).toString() |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
.confirm { |
||||
|
position: absolute; |
||||
|
right: 10px; |
||||
|
} |
||||
|
.cancel { |
||||
|
position: absolute; |
||||
|
right: 120px; |
||||
|
} |
||||
|
</style> |
||||
Loading…
Reference in new issue