邵佳豪 2 years ago
parent
commit
8428ae5ce5
  1. 9
      src/app/system-management/role/addrole/addrole.component.html
  2. 13
      src/app/system-management/role/addrole/addrole.component.ts
  3. 8
      src/app/system-management/role/editrole/editrole.component.html
  4. 20
      src/app/system-management/role/editrole/editrole.component.ts
  5. 2
      src/app/system-management/role/role.component.html
  6. 30
      src/app/system-management/role/role.component.ts

9
src/app/system-management/role/addrole/addrole.component.html

@ -19,10 +19,10 @@
</ng-template> </ng-template>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
<!-- <nz-form-item> <nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzFor="菜单">菜单</nz-form-label> <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="菜单">菜单</nz-form-label>
<nz-form-control> <nz-form-control>
<nz-tree-select formControlName="menus" [nzNodes]="nodes" nzShowSearch nzCheckable nzPlaceHolder="请选择菜单" <nz-tree-select [nzCheckStrictly]="true" #nzTreeComponent formControlName="menus" [nzNodes]="nodes" nzShowSearch nzCheckable nzPlaceHolder="请选择菜单"
[nzExpandedIcon]="multiExpandedIconTpl"> [nzExpandedIcon]="multiExpandedIconTpl">
</nz-tree-select> </nz-tree-select>
</nz-form-control> </nz-form-control>
@ -30,9 +30,10 @@
<ng-container *ngIf="node.children.length == 0; else elseTemplate"> <ng-container *ngIf="node.children.length == 0; else elseTemplate">
</ng-container> </ng-container>
<ng-template #elseTemplate> <ng-template #elseTemplate>
<i nz-icon [nzType]="node.isExpanded ? 'caret-down' : 'caret-right'" class="ant-tree-switcher-line-icon"></i> <i nz-icon [nzType]="node.isExpanded ? 'caret-down' : 'caret-right'"
class="ant-tree-switcher-line-icon"></i>
</ng-template> </ng-template>
</ng-template> </ng-template>
</nz-form-item> --> </nz-form-item>
</form> </form>
</div> </div>

13
src/app/system-management/role/addrole/addrole.component.ts

@ -1,18 +1,21 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input,ViewChild } from '@angular/core';
import { NzModalRef } from 'ng-zorro-antd/modal'; import { NzModalRef } from 'ng-zorro-antd/modal';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators, } from '@angular/forms';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { TreeService } from 'src/app/service/tree.service'; import { TreeService } from 'src/app/service/tree.service';
import { NzTreeComponent } from 'ng-zorro-antd/tree';
@Component({ @Component({
selector: 'app-addrole', selector: 'app-addrole',
templateUrl: './addrole.component.html', templateUrl: './addrole.component.html',
styleUrls: ['./addrole.component.scss'] styleUrls: ['./addrole.component.scss']
}) })
export class AddroleComponent implements OnInit { export class AddroleComponent implements OnInit {
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
@Input() data?: any;
@Input() nodes?: any;
@Input() title?: string; @Input() title?: string;
@Input() subtitle?: string; @Input() subtitle?: string;
@Input() nodes?: any;
validateForm!: FormGroup; validateForm!: FormGroup;
constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { } constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { }
@ -23,7 +26,7 @@ export class AddroleComponent implements OnInit {
this.validateForm = this.fb.group({ this.validateForm = this.fb.group({
name: [null, [Validators.required]], name: [null, [Validators.required]],
power: [null, [Validators.required]], power: [null, [Validators.required]],
// menus: [null] menus: [null]
}); });
} }

8
src/app/system-management/role/editrole/editrole.component.html

@ -16,12 +16,13 @@
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
<!-- <nz-form-item> <nz-form-item>
<nz-form-label [nzSm]="6" [nzXs]="24" nzFor="菜单">菜单</nz-form-label> <nz-form-label [nzSm]="6" [nzXs]="24" nzFor="菜单">菜单</nz-form-label>
<nz-form-control> <nz-form-control>
<nz-tree-select formControlName="menus" [nzNodes]="nodes" nzShowSearch nzCheckable nzPlaceHolder="请选择菜单" <nz-tree-select [nzCheckStrictly]="true" #nzTreeComponent formControlName="menus" [nzNodes]="nodes" nzShowSearch nzCheckable nzPlaceHolder="请选择菜单"
[nzExpandedIcon]="multiExpandedIconTpl"> [nzExpandedIcon]="multiExpandedIconTpl">
</nz-tree-select> </nz-tree-select>
</nz-form-control>
<ng-template #multiExpandedIconTpl let-node let-origin="origin"> <ng-template #multiExpandedIconTpl let-node let-origin="origin">
<ng-container *ngIf="node.children.length == 0; else elseTemplate"> <ng-container *ngIf="node.children.length == 0; else elseTemplate">
</ng-container> </ng-container>
@ -30,7 +31,6 @@
class="ant-tree-switcher-line-icon"></i> class="ant-tree-switcher-line-icon"></i>
</ng-template> </ng-template>
</ng-template> </ng-template>
</nz-form-control> </nz-form-item>
</nz-form-item> -->
</form> </form>
</div> </div>

20
src/app/system-management/role/editrole/editrole.component.ts

@ -20,15 +20,33 @@ export class EditroleComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.nodes.length != 0 ? null : this.getAllMenus() this.nodes.length != 0 ? null : this.getAllMenus()
this.multipleValue = this.data.grantedPermissions this.multipleValue = this.data.grantedPermissions
this.getMenus()
this.validateForm = this.fb.group({ this.validateForm = this.fb.group({
name: [null, [Validators.required]], name: [null, [Validators.required]],
power: [null, [Validators.required]], power: [null, [Validators.required]],
// menus: [null] menus: [null]
}); });
if (this.optionList.length == 0) { if (this.optionList.length == 0) {
this.loadMore() this.loadMore()
} }
} }
getMenus() {
let params = {
Id: this.data.id,
}
this.http.get('/api/services/app/Role/Get', {
params: params
}).subscribe((data: any) => {
// console.log(666, data)
let arr = []
data.result.menus.forEach(element => {
arr.push(element.id)
});
this.validateForm.patchValue({
menus: arr
});
})
}
totalCount totalCount
getAllMenus() { getAllMenus() {
let params = { let params = {

2
src/app/system-management/role/role.component.html

@ -29,7 +29,7 @@
</td> </td>
<td class="operation"> <td class="operation">
<a (click)="edit(data)">编辑</a> <a (click)="edit(data)">编辑</a>
<a (click)="allotMenus(data)">分配菜单</a> <!-- <a (click)="allotMenus(data)">分配菜单</a> -->
<a (click)="delete(data)">删除</a> <a (click)="delete(data)">删除</a>
</td> </td>
</tr> </tr>

30
src/app/system-management/role/role.component.ts

@ -52,7 +52,7 @@ export class RoleComponent implements OnInit {
this.http.get('/api/services/app/Menu/GetAll', { this.http.get('/api/services/app/Menu/GetAll', {
params: params params: params
}).subscribe((data: any) => { }).subscribe((data: any) => {
console.log(666, data) // console.log(666, data)
this.totalCount = data.result.totalCount this.totalCount = data.result.totalCount
data.result.items.forEach(element => { data.result.items.forEach(element => {
element.key = element.id element.key = element.id
@ -86,8 +86,20 @@ export class RoleComponent implements OnInit {
DisplayName: instance.validateForm.value.name, DisplayName: instance.validateForm.value.name,
grantedPermissions: arr grantedPermissions: arr
} }
this.http.post('/api/services/app/Role/Create', body).subscribe(data => { let body2=instance.validateForm.value.menus
this.http.post('/api/services/app/Role/Create', body).subscribe((data:any) => {
resolve(data) resolve(data)
this.http.post('/api/services/app/Role/SetRoleMenus', body2, {
params: {
roleId: data.result.id
}
}).subscribe(data => {
resolve(data)
// this.message.create('success', '分配成功!');
return true
})
this.message.create('success', '创建成功!'); this.message.create('success', '创建成功!');
this.getAllRoles() this.getAllRoles()
return true return true
@ -131,8 +143,20 @@ export class RoleComponent implements OnInit {
DisplayName: instance.validateForm.value.name, DisplayName: instance.validateForm.value.name,
grantedPermissions: arr grantedPermissions: arr
} }
this.http.put('/api/services/app/Role/Update', body).subscribe(data => { let body2=instance.validateForm.value.menus
this.http.put('/api/services/app/Role/Update', body).subscribe((data:any) => {
resolve(data) resolve(data)
this.http.post('/api/services/app/Role/SetRoleMenus', body2, {
params: {
roleId: data.result.id
}
}).subscribe(data => {
resolve(data)
// this.message.create('success', '分配成功!');
return true
})
this.message.create('success', '修改成功!'); this.message.create('success', '修改成功!');
this.getAllRoles() this.getAllRoles()
return true return true

Loading…
Cancel
Save