陈敬瑜 3 years ago
parent
commit
55c46239c2
  1. 2
      src/app/plan-management/entry-plan-look/entry-plan-look.component.ts
  2. 382
      src/app/ui/role/role.component.ts
  3. 2
      tsconfig.json

2
src/app/plan-management/entry-plan-look/entry-plan-look.component.ts

@ -732,7 +732,7 @@ export class EntryPlanLookComponent implements OnInit {
sessionStorage.setItem("buildingTypeId", this.unittypeId) sessionStorage.setItem("buildingTypeId", this.unittypeId)
sessionStorage.setItem("editable", "1") sessionStorage.setItem("editable", "1")
let companyId = sessionStorage.getItem("companyId") let companyId = sessionStorage.getItem("companyId")
window.open(`/keyUnit/editunitinfo?id=${companyId}`); window.open(`/keyUnit/editunitinfo?id=${companyId}&orName=${this.route.snapshot.queryParams.orName}&orId=${this.route.snapshot.queryParams.orId}`);
} }
} }
} }

382
src/app/ui/role/role.component.ts

@ -1,11 +1,11 @@
import { Component, OnInit, Inject } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import {FormControl} from '@angular/forms'; import { FormControl } from '@angular/forms';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { CacheTokenService } from '../../http-interceptors/cache-token.service' import { CacheTokenService } from '../../http-interceptors/cache-token.service'
// import format from 'date-fns/format'; // import format from 'date-fns/format';
import {MatTreeFlatDataSource, MatTreeFlattener} from '@angular/material/tree'; import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree';
import {FlatTreeControl} from '@angular/cdk/tree'; import { FlatTreeControl } from '@angular/cdk/tree';
import { TreeService } from '../../http-interceptors/tree.service' import { TreeService } from '../../http-interceptors/tree.service'
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
@ -25,37 +25,37 @@ export interface roledata {
}) })
export class RoleComponent implements OnInit { export class RoleComponent implements OnInit {
constructor(private http: HttpClient,public dialog: MatDialog,public createtime:CacheTokenService,private tree:TreeService,public snackBar: MatSnackBar) { } constructor(private http: HttpClient, public dialog: MatDialog, public createtime: CacheTokenService, private tree: TreeService, public snackBar: MatSnackBar) { }
displayedColumns: string[] = ['name','createtiome', 'edit']; displayedColumns: string[] = ['name', 'createtiome', 'edit'];
dataSource: any dataSource: any
public compare(property){ public compare(property) {
return function(a,b){ return function (a, b) {
var value1 = a[property]; var value1 = a[property];
var value2 = b[property]; var value2 = b[property];
return value1 - value2; return value1 - value2;
} }
} }
//获取角色列表并且给排头和排尾赋是否为首尾 //获取角色列表并且给排头和排尾赋是否为首尾
getlist(){ getlist() {
this.http.get('/api/Roles').subscribe( (data:Array<roledata>)=>{ this.http.get('/api/Roles').subscribe((data: Array<roledata>) => {
this.dataSource = data this.dataSource = data
this.dataSource[0].isTop = true; this.dataSource[0].isTop = true;
this.dataSource[this.dataSource.length-1].isBottom = true this.dataSource[this.dataSource.length - 1].isBottom = true
}) })
} }
//初始化视图 //初始化视图
ngOnInit() { ngOnInit() {
this.getlist() this.getlist()
} }
//向上按钮 //向上按钮
up(node){ up(node) {
let newdate = new Date(); let newdate = new Date();
function getDate(date){ function getDate(date) {
//date是传过来的时间戳,注意需为13位,10位需*1000 //date是传过来的时间戳,注意需为13位,10位需*1000
//也可以不传,获取的就是当前时间 //也可以不传,获取的就是当前时间
var time = new Date(date); var time = new Date(date);
var year= time.getFullYear() //年 var year = time.getFullYear() //年
var month = ("0" + (time.getMonth() + 1)).slice(-2); //月 var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
var day = ("0" + time.getDate()).slice(-2); //日 var day = ("0" + time.getDate()).slice(-2); //日
var mydate = year + "-" + month + "-" + day; var mydate = year + "-" + month + "-" + day;
@ -63,40 +63,50 @@ export class RoleComponent implements OnInit {
} }
let time = getDate(newdate) let time = getDate(newdate)
this.http.put(//把上一节点order换成点击的节点 this.http.put(//把上一节点order换成点击的节点
`/api/Roles/${this.dataSource[node.order -1].id}`, `/api/Roles/${this.dataSource[node.order - 1].id}`,
{ {
id:this.dataSource[node.order -1].id, id: this.dataSource[node.order - 1].id,
name: this.dataSource[node.order -1].name, name: this.dataSource[node.order - 1].name,
order: node.order, order: node.order,
enabled: true, enabled: true,
creationTime:time, creationTime: time,
} }
).subscribe(data=>{ ).subscribe(data => {
this.getlist() this.getlist()
}, err => {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open(err ? err : '内置角色不允许移动', '确定', config);
}) })
this.http.put(//把当前节点order换成上一点击的节点 this.http.put(//把当前节点order换成上一点击的节点
`/api/Roles/${node.id}`, `/api/Roles/${node.id}`,
{ {
id:node.id, id: node.id,
name: node.name, name: node.name,
order: node.order-1, order: node.order - 1,
enabled: true, enabled: true,
creationTime:time, creationTime: time,
} }
).subscribe(data=>{ ).subscribe(data => {
this.getlist() this.getlist()
}, err => {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open(err ? err : '内置角色不允许移动', '确定', config);
}) })
} }
//向下按钮 //向下按钮
down(node){ down(node) {
let newdate = new Date(); let newdate = new Date();
function getDate(date){ function getDate(date) {
//date是传过来的时间戳,注意需为13位,10位需*1000 //date是传过来的时间戳,注意需为13位,10位需*1000
//也可以不传,获取的就是当前时间 //也可以不传,获取的就是当前时间
var time = new Date(date); var time = new Date(date);
var year= time.getFullYear() //年 var year = time.getFullYear() //年
var month = ("0" + (time.getMonth() + 1)).slice(-2); //月 var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
var day = ("0" + time.getDate()).slice(-2); //日 var day = ("0" + time.getDate()).slice(-2); //日
var mydate = year + "-" + month + "-" + day; var mydate = year + "-" + month + "-" + day;
@ -104,78 +114,88 @@ export class RoleComponent implements OnInit {
} }
let time = getDate(newdate) let time = getDate(newdate)
this.http.put(//把下一节点order换成点击的节点 this.http.put(//把下一节点order换成点击的节点
`/api/Roles/${this.dataSource[node.order + 1].id}`, `/api/Roles/${this.dataSource[node.order + 1].id}`,
{ {
id:this.dataSource[node.order + 1].id, id: this.dataSource[node.order + 1].id,
name: this.dataSource[node.order + 1].name, name: this.dataSource[node.order + 1].name,
order: node.order, order: node.order,
enabled: true, enabled: true,
creationTime:time, creationTime: time,
} }
).subscribe(data=>{ ).subscribe(data => {
this.getlist() this.getlist()
}, err => {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open(err ? err : '内置角色不允许移动', '确定', config);
}) })
this.http.put(//把当前节点order换成下一点击的节点 this.http.put(//把当前节点order换成下一点击的节点
`/api/Roles/${node.id}`, `/api/Roles/${node.id}`,
{ {
id:node.id, id: node.id,
name: node.name, name: node.name,
order: node.order + 1, order: node.order + 1,
enabled: true, enabled: true,
creationTime:time, creationTime: time,
} }
).subscribe(data=>{ ).subscribe(data => {
this.getlist() this.getlist()
}, err => {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open(err ? err : '内置角色不允许移动', '确定', config);
}) })
} }
//创建按钮并且弹出对话框 //创建按钮并且弹出对话框
createuser(){ createuser() {
const dialogRef = this.dialog.open(CreateRole, {//调用open方法打开对话框并且携带参数过去 const dialogRef = this.dialog.open(CreateRole, {//调用open方法打开对话框并且携带参数过去
width: '600px', width: '600px',
height:'658px', height: '658px',
data: {name: this.createuser.name,data: this.dataSource,length:this.dataSource.length} data: { name: this.createuser.name, data: this.dataSource, length: this.dataSource.length }
}); });
dialogRef.afterClosed().subscribe( dialogRef.afterClosed().subscribe(
data=>{ data => {
this.getlist() this.getlist()
} }
); );
} }
//删除按钮 //删除按钮
deleteduser(roledata){ deleteduser(roledata) {
var isdeleted = confirm("确定要删除此用户吗?") var isdeleted = confirm("确定要删除此用户吗?")
if(isdeleted){ if (isdeleted) {
//请求删除接口 //请求删除接口
this.http.delete(`/api/Roles/${roledata.id}`).subscribe( data=>{ this.http.delete(`/api/Roles/${roledata.id}`).subscribe(data => {
this.getlist() this.getlist()
}) })
} }
} }
//编辑按钮 //编辑按钮
allot(roledata){ allot(roledata) {
const dialogRef = this.dialog.open(EditRole, {//调用open方法打开对话框并且携带参数过去 const dialogRef = this.dialog.open(EditRole, {//调用open方法打开对话框并且携带参数过去
width: '600px', width: '600px',
height:'658px', height: '658px',
data: {id:roledata.id,name:roledata.name,order:roledata.order}//把点击的id传过去 data: { id: roledata.id, name: roledata.name, order: roledata.order }//把点击的id传过去
}); });
dialogRef.afterClosed().subscribe( dialogRef.afterClosed().subscribe(
data=>{ data => {
this.getlist() this.getlist()
} }
); );
} }
//启用或禁用按钮 //启用或禁用按钮
open(roledata){ open(roledata) {
let newdate = new Date(); let newdate = new Date();
function getDate(date){ function getDate(date) {
//date是传过来的时间戳,注意需为13位,10位需*1000 //date是传过来的时间戳,注意需为13位,10位需*1000
//也可以不传,获取的就是当前时间 //也可以不传,获取的就是当前时间
var time = new Date(date); var time = new Date(date);
var year= time.getFullYear() //年 var year = time.getFullYear() //年
var month = ("0" + (time.getMonth() + 1)).slice(-2); //月 var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
var day = ("0" + time.getDate()).slice(-2); //日 var day = ("0" + time.getDate()).slice(-2); //日
var mydate = year + "-" + month + "-" + day; var mydate = year + "-" + month + "-" + day;
@ -183,21 +203,21 @@ export class RoleComponent implements OnInit {
} }
let time = getDate(newdate) let time = getDate(newdate)
this.http.put( this.http.put(
`/api/Roles/${roledata['id']}`, `/api/Roles/${roledata['id']}`,
{ {
id:roledata['id'], id: roledata['id'],
name: roledata.name, name: roledata.name,
order: roledata.order, order: roledata.order,
enabled: !roledata.enabled, enabled: !roledata.enabled,
creationTime: time, creationTime: time,
} }
).subscribe( ).subscribe(
data=>{ data => {
this.getlist() this.getlist()
} }
) )
} }
} }
@ -217,7 +237,7 @@ export class CreateRole {
expandable: !!node.children && node.children.length > 0, expandable: !!node.children && node.children.length > 0,
name: node.name, name: node.name,
level: level, level: level,
id:node.id id: node.id
}; };
} }
treeControl = new FlatTreeControl<any>( treeControl = new FlatTreeControl<any>(
@ -231,21 +251,21 @@ export class CreateRole {
myControl = new FormControl(); myControl = new FormControl();
//注入MatDialogRef,可以用来关闭对话框 //注入MatDialogRef,可以用来关闭对话框
//要访问对话框组件中的数据,必须使用MAT_DIALOG_DATA注入令牌 //要访问对话框组件中的数据,必须使用MAT_DIALOG_DATA注入令牌
constructor(private http: HttpClient,public dialogRef: MatDialogRef<CreateRole>,@Inject(MAT_DIALOG_DATA) public data,private tree:TreeService,public snackBar: MatSnackBar) {} constructor(private http: HttpClient, public dialogRef: MatDialogRef<CreateRole>, @Inject(MAT_DIALOG_DATA) public data, private tree: TreeService, public snackBar: MatSnackBar) { }
olddata =[] olddata = []
olddata2 = [] olddata2 = []
xxx = {} xxx = {}
jjj = {} jjj = {}
//用于存放选中的数组 //用于存放选中的数组
checkedMap = {} checkedMap = {}
//初始化两棵tree //初始化两棵tree
ngOnInit(){ ngOnInit() {
this.http.get('/api/Permissions').subscribe((data: any[])=>{ this.http.get('/api/Permissions').subscribe((data: any[]) => {
this.olddata =data this.olddata = data
this.dataSource.data = this.tree.toTree(data); this.dataSource.data = this.tree.toTree(data);
this.treeControl.expandAll() this.treeControl.expandAll()
this.dataSource.data.forEach(item=>{ this.dataSource.data.forEach(item => {
if(item.children){ if (item.children) {
var childarr = [] var childarr = []
item.children.forEach(n => { item.children.forEach(n => {
childarr.push(n.id) childarr.push(n.id)
@ -253,15 +273,15 @@ export class CreateRole {
this.xxx[item.id] = childarr this.xxx[item.id] = childarr
} }
}) })
}) })
this.http.get('/api/NavMenus').subscribe((data: any[])=>{ this.http.get('/api/NavMenus').subscribe((data: any[]) => {
this.olddata2 =data this.olddata2 = data
this.dataSource2.data = this.tree.toTree(data); this.dataSource2.data = this.tree.toTree(data);
this.treeControl.expandAll() this.treeControl.expandAll()
this.dataSource2.data.forEach(item=>{ this.dataSource2.data.forEach(item => {
if(item.children){ if (item.children) {
var childarr = [] var childarr = []
item.children.forEach(n => { item.children.forEach(n => {
childarr.push(n.id) childarr.push(n.id)
@ -273,25 +293,25 @@ export class CreateRole {
} }
//选中后子节点默认选中 //选中后子节点默认选中
selectedAll(event, node){ selectedAll(event, node) {
this.olddata.forEach(item=>{ this.olddata.forEach(item => {
if(item.parentId == node.id){ if (item.parentId == node.id) {
this.checkedMap[item.id] = event.checked; this.checkedMap[item.id] = event.checked;
} }
}) })
// console.log(this.olddata2,node ) // console.log(this.olddata2,node )
var menus =[] //导航菜单可能有三级 用于存储第二级 var menus = [] //导航菜单可能有三级 用于存储第二级
//选中一级菜单 //选中一级菜单
this.olddata2.forEach(item=>{ this.olddata2.forEach(item => {
if(item.parentId == node.id){ if (item.parentId == node.id) {
this.checkedMap[item.id] = event.checked; this.checkedMap[item.id] = event.checked;
menus.push(item) menus.push(item)
} }
}) })
//将二级菜单也选中 //将二级菜单也选中
menus.forEach(item=>{ menus.forEach(item => {
if(item.children){ if (item.children) {
item.children.forEach(n => { item.children.forEach(n => {
this.checkedMap[n.id] = event.checked; this.checkedMap[n.id] = event.checked;
}); });
@ -300,37 +320,37 @@ export class CreateRole {
} }
//数据权限tree的全选功能 //数据权限tree的全选功能
leftTreeAll(event,form){ leftTreeAll(event, form) {
const values = form.value; const values = form.value;
for (let key in values) { for (let key in values) {
if(key.indexOf("second")){ if (key.indexOf("second")) {
this.checkedMap[key.split('.')[1]] = event.checked; this.checkedMap[key.split('.')[1]] = event.checked;
} }
} }
} }
//菜单权限tree的全选功能 //菜单权限tree的全选功能
rightTreeAll(event,form){ rightTreeAll(event, form) {
const values = form.value; const values = form.value;
for (let key in values) { for (let key in values) {
if(key.indexOf("first")){ if (key.indexOf("first")) {
this.checkedMap[key.split('.')[1]] = event.checked; this.checkedMap[key.split('.')[1]] = event.checked;
} }
} }
} }
hasChild = (_: number, node: any) => node.expandable; hasChild = (_: number, node: any) => node.expandable;
onNoClick(): void { onNoClick(): void {
this.dialogRef.close(); this.dialogRef.close();
} }
//提交 //提交
onSubmit(value){ onSubmit(value) {
let newdate = new Date(); let newdate = new Date();
function getDate(date){ function getDate(date) {
//date是传过来的时间戳,注意需为13位,10位需*1000 //date是传过来的时间戳,注意需为13位,10位需*1000
//也可以不传,获取的就是当前时间 //也可以不传,获取的就是当前时间
var time = new Date(date); var time = new Date(date);
var year= time.getFullYear() //年 var year = time.getFullYear() //年
var month = ("0" + (time.getMonth() + 1)).slice(-2); //月 var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
var day = ("0" + time.getDate()).slice(-2); //日 var day = ("0" + time.getDate()).slice(-2); //日
var mydate = year + "-" + month + "-" + day; var mydate = year + "-" + month + "-" + day;
@ -338,84 +358,84 @@ export class CreateRole {
} }
let time = getDate(newdate) let time = getDate(newdate)
this.http.post( this.http.post(
'/api/Roles', '/api/Roles',
{ {
id:"", id: "",
name: value.name, name: value.name,
order: this.data.data[this.data.data.length - 1].order + 1, order: this.data.data[this.data.data.length - 1].order + 1,
enabled: true, enabled: true,
creationTime: time, creationTime: time,
} }
).subscribe( ).subscribe(
data=>{ data => {
var id = data['id'] var id = data['id']
// console.log(value) // console.log(value)
var keydata = [] //菜单权限id集合 var keydata = [] //菜单权限id集合
var keydata2 = [] //数据权限id集合 var keydata2 = [] //数据权限id集合
for(let i in value){ for (let i in value) {
if(value[i]){ if (value[i]) {
if(i.indexOf("first") && i!="name"){ if (i.indexOf("first") && i != "name") {
keydata.push(i.split('.')[1]) keydata.push(i.split('.')[1])
} }
if(i.indexOf("second") && i!="name"){ if (i.indexOf("second") && i != "name") {
keydata2.push(i.split('.')[1]) keydata2.push(i.split('.')[1])
} }
} }
} }
function includes(arr1, arr2) { function includes(arr1, arr2) {
return arr2.every(val => arr1.includes(val)); return arr2.every(val => arr1.includes(val));
} }
const orginalList = [...keydata2]; const orginalList = [...keydata2];
orginalList.forEach((item) => { // forEach 里面 splice 有问题,详见 https://blog.csdn.net/qq_38128179/article/details/92798157 orginalList.forEach((item) => { // forEach 里面 splice 有问题,详见 https://blog.csdn.net/qq_38128179/article/details/92798157
if (item in this.xxx) { // 根据 key,可以直接在 对象 里面获取数据 if (item in this.xxx) { // 根据 key,可以直接在 对象 里面获取数据
const datachildarrboxArr = this.xxx[item]; const datachildarrboxArr = this.xxx[item];
if (!includes(keydata2, datachildarrboxArr)) { // 如果不全部包含 if (!includes(keydata2, datachildarrboxArr)) { // 如果不全部包含
keydata2.splice(keydata2.findIndex(items => items == item), 1); keydata2.splice(keydata2.findIndex(items => items == item), 1);
}
} }
}
}); });
this.http.post( this.http.post(
`/api/Roles/${id}/Permissions`, `/api/Roles/${id}/Permissions`,
keydata2 keydata2
).subscribe( ).subscribe(
data=>{ data => {
this.http.post( this.http.post(
`/api/Roles/${id}/NavMenus`, `/api/Roles/${id}/NavMenus`,
keydata keydata
).subscribe( ).subscribe(
data=>{ data => {
this.dialogRef.close(); this.dialogRef.close();
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('创建成功','确定',config); this.snackBar.open('创建成功', '确定', config);
}, },
err=>{ err => {
this.dialogRef.close(); this.dialogRef.close();
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('创建菜单权限失败','确定',config); this.snackBar.open('创建菜单权限失败', '确定', config);
} }
) )
}, },
err=>{ err => {
this.dialogRef.close(); this.dialogRef.close();
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('创建数据权限失败','确定',config); this.snackBar.open('创建数据权限失败', '确定', config);
} }
) )
}, },
err=>{ err => {
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('角色名称不符合规范','确定',config); this.snackBar.open('角色名称不符合规范', '确定', config);
} }
) )
} }
@ -441,8 +461,8 @@ export class EditRole {
expandable: !!node.children && node.children.length > 0, expandable: !!node.children && node.children.length > 0,
name: node.name, name: node.name,
level: level, level: level,
id:node.id, id: node.id,
children:node.children children: node.children
}; };
} }
treeControl = new FlatTreeControl<any>( treeControl = new FlatTreeControl<any>(
@ -457,43 +477,43 @@ export class EditRole {
myControl = new FormControl(); myControl = new FormControl();
//注入MatDialogRef,可以用来关闭对话框 //注入MatDialogRef,可以用来关闭对话框
//要访问对话框组件中的数据,必须使用MAT_DIALOG_DATA注入令牌 //要访问对话框组件中的数据,必须使用MAT_DIALOG_DATA注入令牌
constructor(private http: HttpClient,public dialogRef: MatDialogRef<EditRole>,public snackBar: MatSnackBar,@Inject(MAT_DIALOG_DATA) public data,private tree:TreeService) {} constructor(private http: HttpClient, public dialogRef: MatDialogRef<EditRole>, public snackBar: MatSnackBar, @Inject(MAT_DIALOG_DATA) public data, private tree: TreeService) { }
olddata =[] //原始所有--数据权限 olddata = [] //原始所有--数据权限
olddata2 =[] //原始所有--菜单权限 olddata2 = [] //原始所有--菜单权限
newdata = [] newdata = []
newdata2 = [] newdata2 = []
placeholdername = this.data.name placeholdername = this.data.name
datachildarrbox = {} //数据权限存放有children的 父id:子id1 子id2 子id3 datachildarrbox = {} //数据权限存放有children的 父id:子id1 子id2 子id3
menuchildarrbox = {} //菜单权限存放有children的 父id:子id1 子id2 子id3 menuchildarrbox = {} //菜单权限存放有children的 父id:子id1 子id2 子id3
checkedMap = {} checkedMap = {}
ngOnInit(){ ngOnInit() {
//获得角色的数据权限,选中的checked为true //获得角色的数据权限,选中的checked为true
this.http.get(`/api/Roles/${this.data.id}/Permissions`).subscribe((data: any[])=>{ this.http.get(`/api/Roles/${this.data.id}/Permissions`).subscribe((data: any[]) => {
this.olddata =data this.olddata = data
this.newdata = this.tree.toTree(this.olddata) this.newdata = this.tree.toTree(this.olddata)
//如果子节点存在选中则父节点默认选中 //如果子节点存在选中则父节点默认选中
this.newdata.forEach(item=>{ this.newdata.forEach(item => {
if(item.children){ if (item.children) {
item.children.forEach(element => { item.children.forEach(element => {
if(element.checked){ if (element.checked) {
this.checkedMap[item.id] = true this.checkedMap[item.id] = true
} }
}); });
} }
}) })
data.forEach(item=>{ data.forEach(item => {
if(item.checked){ if (item.checked) {
this.checkedMap[item.id] = true; this.checkedMap[item.id] = true;
} }
}) })
this.dataSource.data = this.newdata; this.dataSource.data = this.newdata;
this.treeControl.expandAll() this.treeControl.expandAll()
this.dataSource.data.forEach(item=>{ this.dataSource.data.forEach(item => {
if(item.children){ if (item.children) {
var childarr = [] var childarr = []
item.children.forEach(n => { item.children.forEach(n => {
childarr.push(n.id) childarr.push(n.id)
@ -505,20 +525,20 @@ export class EditRole {
//获得角色的菜单权限,选中的checked为true //获得角色的菜单权限,选中的checked为true
this.http.get(`/api/Roles/${this.data.id}/NavMenus`).subscribe((data: any[])=>{ this.http.get(`/api/Roles/${this.data.id}/NavMenus`).subscribe((data: any[]) => {
this.olddata2 =data this.olddata2 = data
this.newdata2 = this.tree.toTree(this.olddata2) this.newdata2 = this.tree.toTree(this.olddata2)
data.forEach(item => { data.forEach(item => {
if(item.checked){ if (item.checked) {
this.checkedMap[item.id] = item.checked; this.checkedMap[item.id] = item.checked;
} }
}); });
this.dataSource2.data = this.newdata2; this.dataSource2.data = this.newdata2;
this.treeControl.expandAll() this.treeControl.expandAll()
this.dataSource2.data.forEach(item=>{ this.dataSource2.data.forEach(item => {
if(item.children){ if (item.children) {
var childarr = [] var childarr = []
item.children.forEach(n => { item.children.forEach(n => {
childarr.push(n.id) childarr.push(n.id)
@ -530,24 +550,24 @@ export class EditRole {
} }
//选中对应小组 //选中对应小组
selectedAll(event, node){ selectedAll(event, node) {
this.olddata.forEach(item=>{ this.olddata.forEach(item => {
if(item.parentId == node.id){ if (item.parentId == node.id) {
this.checkedMap[item.id] = event.checked; this.checkedMap[item.id] = event.checked;
} }
}) })
// console.log(this.olddata2,node ) // console.log(this.olddata2,node )
var menus =[] //导航菜单可能有三级 用于存储第二级 var menus = [] //导航菜单可能有三级 用于存储第二级
//选中一级菜单 //选中一级菜单
this.olddata2.forEach(item=>{ this.olddata2.forEach(item => {
if(item.parentId == node.id){ if (item.parentId == node.id) {
this.checkedMap[item.id] = event.checked; this.checkedMap[item.id] = event.checked;
menus.push(item) menus.push(item)
} }
}) })
//将二级菜单也选中 //将二级菜单也选中
menus.forEach(item=>{ menus.forEach(item => {
if(item.children){ if (item.children) {
item.children.forEach(n => { item.children.forEach(n => {
this.checkedMap[n.id] = event.checked; this.checkedMap[n.id] = event.checked;
}); });
@ -562,93 +582,93 @@ export class EditRole {
} }
onSubmit(value){ onSubmit(value) {
var keydata = [] //存储选中的菜单权限 var keydata = [] //存储选中的菜单权限
var keydata2 = [] //存储选中的数据权限 var keydata2 = [] //存储选中的数据权限
for(let i in value){ for (let i in value) {
if(value[i]){ if (value[i]) {
if(i.indexOf("first") && i!="name" && i!="order"){ if (i.indexOf("first") && i != "name" && i != "order") {
keydata.push(i.split('.')[1]) keydata.push(i.split('.')[1])
} }
if(i.indexOf("second") && i!="name" && i!="order"){ if (i.indexOf("second") && i != "name" && i != "order") {
keydata2.push(i.split('.')[1]) keydata2.push(i.split('.')[1])
} }
} }
} }
let newdate = new Date(); let newdate = new Date();
function getDate(date){ function getDate(date) {
//date是传过来的时间戳,注意需为13位,10位需*1000 //date是传过来的时间戳,注意需为13位,10位需*1000
//也可以不传,获取的就是当前时间 //也可以不传,获取的就是当前时间
var time = new Date(date); var time = new Date(date);
var year= time.getFullYear() //年 var year = time.getFullYear() //年
var month = ("0" + (time.getMonth() + 1)).slice(-2); //月 var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
var day = ("0" + time.getDate()).slice(-2); //日 var day = ("0" + time.getDate()).slice(-2); //日
var mydate = year + "-" + month + "-" + day; var mydate = year + "-" + month + "-" + day;
return mydate return mydate
} }
let time = getDate(newdate) let time = getDate(newdate)
if(this.data['id'] != "0" && this.data['id'] != "1"){ if (this.data['id'] != "0" && this.data['id'] != "1") {
this.http.put( this.http.put(
`/api/Roles/${this.data['id']}`, `/api/Roles/${this.data['id']}`,
{ {
id:this.data['id'], id: this.data['id'],
name: value.name, name: value.name,
order: this.data.order, order: this.data.order,
enabled: true, enabled: true,
creationTime:time, creationTime: time,
} }
).subscribe(data=>{ ).subscribe(data => {
}, },
err=>{ err => {
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('修改角色姓名请求失败','确定',config); this.snackBar.open('修改角色姓名请求失败', '确定', config);
}) })
function includes(arr1, arr2) { function includes(arr1, arr2) {
return arr2.every(val => arr1.includes(val)); return arr2.every(val => arr1.includes(val));
} }
const orginalList = [...keydata2]; const orginalList = [...keydata2];
orginalList.forEach((item) => { // forEach 里面 splice 有问题,详见 https://blog.csdn.net/qq_38128179/article/details/92798157 orginalList.forEach((item) => { // forEach 里面 splice 有问题,详见 https://blog.csdn.net/qq_38128179/article/details/92798157
if (item in this.datachildarrbox) { // 根据 key,可以直接在 对象 里面获取数据 if (item in this.datachildarrbox) { // 根据 key,可以直接在 对象 里面获取数据
const datachildarrboxArr = this.datachildarrbox[item]; const datachildarrboxArr = this.datachildarrbox[item];
if (!includes(keydata2, datachildarrboxArr)) { // 如果不全部包含 if (!includes(keydata2, datachildarrboxArr)) { // 如果不全部包含
keydata2.splice(keydata2.findIndex(items => items == item), 1); keydata2.splice(keydata2.findIndex(items => items == item), 1);
}
} }
}
}); });
this.http.post( this.http.post(
`/api/Roles/${this.data.id}/Permissions`, `/api/Roles/${this.data.id}/Permissions`,
keydata2 keydata2
).subscribe(data=>{ ).subscribe(data => {
}, },
err=>{ err => {
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('分配数据权限请求失败','确定',config); this.snackBar.open('分配数据权限请求失败', '确定', config);
}) })
} }
this.http.post( this.http.post(
`/api/Roles/${this.data.id}/NavMenus`, `/api/Roles/${this.data.id}/NavMenus`,
keydata keydata
).subscribe( ).subscribe(
data=>{ data => {
this.dialogRef.close(); this.dialogRef.close();
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('编辑成功','确定',config); this.snackBar.open('编辑成功', '确定', config);
}, },
err=>{ err => {
this.dialogRef.close(); this.dialogRef.close();
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open('分配菜单权限失败','确定',config); this.snackBar.open('分配菜单权限失败', '确定', config);
} }
) )
// this.http.put( // this.http.put(
@ -662,7 +682,7 @@ export class EditRole {
// } // }
// ).subscribe( // ).subscribe(
// data=>{ // data=>{
// }, // },
@ -674,7 +694,7 @@ export class EditRole {
// } // }
// ) // )
} }
} }

2
tsconfig.json

@ -10,7 +10,7 @@
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"importHelpers": true, "importHelpers": true,
"target": "es2015", "target": "es2015",//es6
"allowJs": true, "allowJs": true,
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"

Loading…
Cancel
Save