Commit 015269c8 authored by wangqinghua's avatar wangqinghua

update

parent 0a769e8f
<!--添加资源--> <!--添加资源-->
<nz-modal [nzWidth]="1080" [(nzVisible)]="isVisible" [nzTitle]="title" (nzOnCancel)="handleEditCancel()" (nzOnOk)="handEditleOk()"> <nz-modal [nzWidth]="780" [(nzVisible)]="isVisible" [nzTitle]="title" (nzOnCancel)="handleEditCancel()" (nzOnOk)="handEditleOk()">
<nz-table #basicTable [nzData]="dataSet"> <nz-table #basicTable [nzData]="dataSet" nzPageSize="5">
<thead> <thead>
<tr> <tr>
<th nzShowCheckbox [(nzChecked)]="allChecked" [nzIndeterminate]="indeterminate" (nzCheckedChange)="checkAll($event)"></th>
<th>角色名称</th> <th>角色名称</th>
<th>说明</th> <th>角色说明</th>
<th>权限模块</th>
<th>资源权限</th>
<th>有效</th>
<th>操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let data of basicTable.data"> <tr *ngFor="let data of basicTable.data">
<td nzShowCheckbox (nzCheckedChange)="selectItem($event,data)" [(nzChecked)]="data.checked"></td>
<td>{{data.name}}</td> <td>{{data.name}}</td>
<td>{{data.comments}}</td> <td>{{data.comments}}</td>
<td>{{data.key3}}</td>
<td>{{data.key4}}</td>
<td>
<ng-container *ngIf="data.status == 0">
<i class="anticon anticon-check"></i>
</ng-container>
</td>
<td class="handle">
<span (click)="grantUser(data)">授予用户</span>
<span>查看</span>
<span (click)="showEditModal(data.id)">编辑</span>
<span (click)="deleteRole(data)">删除</span>
</td>
</tr> </tr>
</tbody> </tbody>
</nz-table> </nz-table>
......
import { Component, OnInit } from '@angular/core'; import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {SystemService} from '../../system/system.service';
@Component({ @Component({
selector: 'smart-select-role', selector: 'smart-select-role',
templateUrl: './select-role.component.html', templateUrl: './select-role.component.html',
styles: [] styles: []
}) })
export class SelectRoleComponent implements OnInit { export class SelectRoleComponent implements OnInit {
@Output() done = new EventEmitter<any>();
title; dataSet: any = [];
isVisible = false; title;
constructor() { } selectList = [];
isVisible = false;
allChecked = false;
checkedNumber = 0;
disabledButton = true;
indeterminate = false;
displayData: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }> = [];
constructor(private systemSer: SystemService) {
}
ngOnInit() { checkAll(value: boolean): void {
} this.displayData.forEach(data => data.checked = value);
this.refreshStatus();
}
showModal(title){ currentPageDataChange($event: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }>): void {
this.title = title; this.displayData = $event;
this.isVisible = true; }
}
getRoleList(){ selectItem(event,item){
if(event){
this.selectList.push(item);
}else{
this.selectList.forEach((value,index)=>{
if(value.id == item.id){
this.selectList.splice(index,1)
}
})
}
this.refreshStatus()
}
} refreshStatus(): void {
const allChecked = this.displayData.every(value => value.checked === true);
const allUnChecked = this.displayData.every(value => !value.checked);
this.allChecked = allChecked;
this.indeterminate = (!allChecked) && (!allUnChecked);
this.disabledButton = !this.dataSet.some(value => value.checked);
this.checkedNumber = this.dataSet.filter(value => value.checked).length;
}
ngOnInit() {
}
showModal(title) {
this.title = title;
this.isVisible = true;
this.getRole();
}
getRole() {
this.systemSer.role().subscribe(
(res) => {
this.dataSet = res.data;
}
);
}
handleEditCancel(){
this.isVisible = false;
}
handEditleOk(){
console.log(this.selectList);
this.done.emit(this.selectList);
this.isVisible = false;
}
} }
...@@ -83,5 +83,5 @@ ...@@ -83,5 +83,5 @@
<!--新增部门--> <!--新增部门-->
<smart-group-modal #smartGroupModal></smart-group-modal> <smart-group-modal #smartGroupModal></smart-group-modal>
<!--授予角色--> <!--授予角色-->
<smart-select-role #smartSelectRole ></smart-select-role> <smart-select-role #smartSelectRole (done)="setRole($event)"></smart-select-role>
...@@ -25,6 +25,7 @@ export class GroupComponent implements OnInit { ...@@ -25,6 +25,7 @@ export class GroupComponent implements OnInit {
checkedNumber = 0; checkedNumber = 0;
nodes: any[]; nodes: any[];
isVisible = true; isVisible = true;
userId;
displayData: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }> = []; displayData: Array<{ key1: string; key2: number; key3: string; key4: string; checked: boolean }> = [];
constructor(private systemSer: SystemService, private message: NzMessageService, constructor(private systemSer: SystemService, private message: NzMessageService,
...@@ -145,7 +146,31 @@ export class GroupComponent implements OnInit { ...@@ -145,7 +146,31 @@ export class GroupComponent implements OnInit {
//授予角色 //授予角色
grantRole(data){ grantRole(data){
this.userId = data.id;
this.smartSelectRole.showModal("选择角色"); this.smartSelectRole.showModal("选择角色");
} }
setRole(event){
console.log(event);
let str ="";
event.forEach(res=>{
str += res.id +",";
});
str = str.substring(0,str.length-1);
const data = {
userId:this.userId,
roleIds:str
};
this.systemSer.batchGrantRoleToUser(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.message.success("授予角色成功");
}else{
this.message.error(res.errMsg);
}
}
)
}
} }
...@@ -74,4 +74,9 @@ export class SystemService { ...@@ -74,4 +74,9 @@ export class SystemService {
batchGrantUserToRole(data): Observable<any>{ batchGrantUserToRole(data): Observable<any>{
return this.http.post(SERVER_API_URL + '/role/batchGrantUserToRole',data); return this.http.post(SERVER_API_URL + '/role/batchGrantUserToRole',data);
} }
//对单一用户批量授权角色
batchGrantRoleToUser(data): Observable<any>{
return this.http.post(SERVER_API_URL + '/role/batchGrantRoleToUser',data);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment