import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Component, OnInit, Input } from '@angular/core'; import { NzModalRef } from 'ng-zorro-antd/modal'; import { HttpClient } from '@angular/common/http'; import { TreeService } from 'src/app/service/tree.service'; @Component({ selector: 'app-editrole', templateUrl: './editrole.component.html', styleUrls: ['./editrole.component.scss'] }) export class EditroleComponent implements OnInit { @Input() data?: any; @Input() optionList?: any; @Input() nodes?: any; validateForm!: FormGroup; constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient, private toTree: TreeService) { } multipleValue: any ngOnInit(): void { this.nodes.length != 0 ? null : this.getAllMenus() this.multipleValue = this.data.grantedPermissions this.getMenus() this.validateForm = this.fb.group({ name: [null, [Validators.required]], power: [null], menus: [null] }); if (this.optionList.length == 0) { 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 getAllMenus() { let params = { SkipCount: '0', MaxResultCount: '999' } this.http.get('/api/services/app/Menu/GetAll', { params: params }).subscribe((data: any) => { console.log(666, data) this.totalCount = data.result.totalCount data.result.items.forEach(element => { element.key = element.id element.title = element.name element.selectable = false }); this.nodes = [...this.toTree.toTree(data.result.items)] }) } destroyModal(): void { this.modal.destroy({ data: 'this the result data' }); } // optionList = []; //获取权限列表 loadMore() { this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data: any) => { this.optionList = data.result.items this.modal.containerInstance.config.nzOkLoading = false // console.log('所有权限',data) }) } }