Browse Source

新增角色级别

beijing
jingbowen 2 years ago
parent
commit
d1c637f60f
  1. 109
      src/app/system-management/role/addrole/addrole.component.ts
  2. 141
      src/app/system-management/role/editrole/editrole.component.ts

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

@ -1,82 +1,87 @@
import { Component, OnInit, Input,ViewChild } from '@angular/core';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { FormBuilder, FormGroup, Validators, } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { TreeService } from 'src/app/service/tree.service';
import { NzTreeComponent } from 'ng-zorro-antd/tree';
import { Component, OnInit, Input, ViewChild } from "@angular/core";
import { NzModalRef } from "ng-zorro-antd/modal";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { HttpClient } from "@angular/common/http";
import { TreeService } from "src/app/service/tree.service";
import { NzTreeComponent } from "ng-zorro-antd/tree";
@Component({
selector: 'app-addrole',
templateUrl: './addrole.component.html',
styleUrls: ['./addrole.component.scss']
selector: "app-addrole",
templateUrl: "./addrole.component.html",
styleUrls: ["./addrole.component.scss"],
})
export class AddroleComponent implements OnInit {
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
@ViewChild("nzTreeComponent", { static: false })
nzTreeComponent!: NzTreeComponent;
@Input() data?: any;
@Input() nodes?: any;
@Input() title?: string;
@Input() subtitle?: string;
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
) {}
ngOnInit(): void {
this.nodes.length != 0 ? null : this.getAllMenus()
this.nodes.length != 0 ? null : this.getAllMenus();
this.loadMore();
let level=JSON.parse(sessionStorage.getItem('userdata')).organization.level
let levelList=[
{level:0,name:'无'},
{level:1,name:'销售公司'},
{level:2,name:'省公司'},
{level:3,name:'区域'},
{level:4,name:'油站'},
]
// this.levelList=[]
levelList.forEach(e=>{
if(e.level>=level||e.level==0){
this.levelList.push(e)
}
})
let level = JSON.parse(sessionStorage.getItem("userdata")).organization
.level;
this.levelList = this.levelList.filter((e) => {
return e.level > level || e.level == 0;
});
this.validateForm = this.fb.group({
name: [null, [Validators.required]],
power: [null],
menus: [null],
organizationsLevel:[null]
organizationsLevel: [null],
});
}
totalCount
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
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)];
});
this.nodes = [...this.toTree.toTree(data.result.items)]
})
}
destroyModal(): void {
this.modal.destroy({ data: 'this the result data' });
this.modal.destroy({ data: "this the result data" });
}
optionList = [];
levelList=[]
levelList = [
{ level: 0, name: "无" },
{ level: 1, name: "销售公司" },
{ level: 2, name: "省公司" },
{ level: 3, name: "区域" },
{ level: 4, name: "油站" },
];
isLoading = false;
//获取权限列表
loadMore() {
this.isLoading = true;
this.http.get('/api/services/app/Role/GetAllPermissions').subscribe((data: any) => {
this.isLoading = false;
this.optionList = data.result.items
console.log('所有权限', data)
})
this.http
.get("/api/services/app/Role/GetAllPermissions")
.subscribe((data: any) => {
this.isLoading = false;
this.optionList = data.result.items;
console.log("所有权限", data);
});
}
}

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

@ -1,100 +1,107 @@
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';
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']
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) { }
levelList=[]
multipleValue: any
levelValue
constructor(
private modal: NzModalRef,
private fb: FormBuilder,
private http: HttpClient,
private toTree: TreeService
) {}
levelList = [
{ level: 0, name: "无" },
{ level: 1, name: "销售公司" },
{ level: 2, name: "省公司" },
{ level: 3, name: "区域" },
{ level: 4, name: "油站" },
];
multipleValue: any;
levelValue;
ngOnInit(): void {
console.log(this.data)
console.log(6666,this.optionList)
this.nodes.length != 0 ? null : this.getAllMenus()
this.multipleValue = this.data.grantedPermissions
this.levelValue=this.data.organizationsLevel
let level=JSON.parse(sessionStorage.getItem('userdata')).organization.level
let levelList=[
{level:0,name:'无'},
{level:1,name:'销售公司'},
{level:2,name:'省公司'},
{level:3,name:'区域'},
{level:4,name:'油站'},
]
levelList.forEach(e=>{
if(e.level>=level||e.level==0){
this.levelList.push(e)
}
})
this.getMenus()
console.log(this.data);
console.log(6666, this.optionList);
this.nodes.length != 0 ? null : this.getAllMenus();
this.multipleValue = this.data.grantedPermissions;
this.levelValue = this.data.organizationsLevel;
let level = JSON.parse(sessionStorage.getItem("userdata")).organization
.level;
this.levelList = this.levelList.filter((e) => {
return e.level > level || e.level == 0;
});
this.getMenus();
this.validateForm = this.fb.group({
name: [null, [Validators.required]],
power: [null],
menus: [null],
organizationsLevel:[null]
organizationsLevel: [null],
});
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) => {
let arr = []
data.result.menus.forEach(element => {
arr.push(element.id)
});
this.validateForm.patchValue({
menus: arr
};
this.http
.get("/api/services/app/Role/Get", {
params: params,
})
.subscribe((data: any) => {
let arr = [];
data.result.menus.forEach((element) => {
arr.push(element.id);
});
this.validateForm.patchValue({
menus: arr,
});
});
})
}
totalCount
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
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)];
});
this.nodes = [...this.toTree.toTree(data.result.items)]
})
}
destroyModal(): void {
this.modal.destroy({ data: 'this the result data' });
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)
})
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)
});
}
}

Loading…
Cancel
Save