|
|
|
@ -1,60 +1,78 @@
|
|
|
|
|
import { Component, OnInit, TemplateRef, ViewContainerRef } from '@angular/core'; |
|
|
|
|
import { |
|
|
|
|
Component, |
|
|
|
|
OnInit, |
|
|
|
|
TemplateRef, |
|
|
|
|
ViewContainerRef, |
|
|
|
|
} from '@angular/core'; |
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
|
|
import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree'; |
|
|
|
|
import { |
|
|
|
|
NzFormatEmitEvent, |
|
|
|
|
NzTreeComponent, |
|
|
|
|
NzTreeNodeOptions, |
|
|
|
|
} from 'ng-zorro-antd/tree'; |
|
|
|
|
import { NzModalService } from 'ng-zorro-antd/modal'; |
|
|
|
|
import { AdduserComponent } from './adduser/adduser.component'; |
|
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message'; |
|
|
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
|
|
import { EdituserComponent } from './edituser/edituser.component'; |
|
|
|
|
import { TreeService } from 'src/app/service/tree.service'; |
|
|
|
|
import { sm4 } from 'sm-crypto'; |
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-user', |
|
|
|
|
templateUrl: './user.component.html', |
|
|
|
|
styleUrls: ['./user.component.scss'] |
|
|
|
|
styleUrls: ['./user.component.scss'], |
|
|
|
|
}) |
|
|
|
|
export class UserComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
constructor(private fb: FormBuilder, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { } |
|
|
|
|
constructor( |
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
private modal: NzModalService, |
|
|
|
|
private viewContainerRef: ViewContainerRef, |
|
|
|
|
private message: NzMessageService, |
|
|
|
|
private http: HttpClient, |
|
|
|
|
private toTree: TreeService |
|
|
|
|
) {} |
|
|
|
|
searchForm = { |
|
|
|
|
Username: '', |
|
|
|
|
RoleName: '', |
|
|
|
|
name: '', |
|
|
|
|
or: '' |
|
|
|
|
} |
|
|
|
|
or: '', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
loading |
|
|
|
|
userList = [] |
|
|
|
|
loading; |
|
|
|
|
userList = []; |
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
this.getAllRoles() |
|
|
|
|
this.getAllOrganization(); |
|
|
|
|
this.getAllRoles(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取角色列表
|
|
|
|
|
roleList |
|
|
|
|
roleList; |
|
|
|
|
getAllRoles() { |
|
|
|
|
let params = { |
|
|
|
|
PageNumber: 1, |
|
|
|
|
PageSize: 100 |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Roles', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
this.roleList = data.items |
|
|
|
|
}) |
|
|
|
|
PageSize: 100, |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.get('/api/Roles', { |
|
|
|
|
params: params, |
|
|
|
|
}) |
|
|
|
|
.subscribe((data: any) => { |
|
|
|
|
this.roleList = data.items; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pageChange($event) { |
|
|
|
|
this.PageNumber = $event |
|
|
|
|
this.getAllUsers() |
|
|
|
|
this.PageNumber = $event; |
|
|
|
|
this.getAllUsers(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取用户列表
|
|
|
|
|
isLoading = false |
|
|
|
|
totalCount |
|
|
|
|
PageNumber = 1 |
|
|
|
|
PageSize = 16 |
|
|
|
|
isLoading = false; |
|
|
|
|
totalCount; |
|
|
|
|
PageNumber = 1; |
|
|
|
|
PageSize = 16; |
|
|
|
|
async getAllUsers() { |
|
|
|
|
this.isLoading = true |
|
|
|
|
this.isLoading = true; |
|
|
|
|
let params = { |
|
|
|
|
Username: this.searchForm.Username, |
|
|
|
|
RoleName: this.searchForm.RoleName, |
|
|
|
@ -62,73 +80,90 @@ export class UserComponent implements OnInit {
|
|
|
|
|
OrganizationId: this.searchForm.or, |
|
|
|
|
PageNumber: this.PageNumber, |
|
|
|
|
PageSize: this.PageSize, |
|
|
|
|
ContainsChildren: 'true' |
|
|
|
|
} |
|
|
|
|
ContainsChildren: 'true', |
|
|
|
|
}; |
|
|
|
|
await new Promise<void>((resolve, reject) => { |
|
|
|
|
this.http.get('/api/Users', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
this.userList = data.items |
|
|
|
|
this.totalCount = data.totalCount |
|
|
|
|
console.log('用户列表', data) |
|
|
|
|
resolve(data) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
this.http |
|
|
|
|
.get('/api/Users', { |
|
|
|
|
params: params, |
|
|
|
|
responseType: 'text', |
|
|
|
|
}) |
|
|
|
|
.subscribe((res: any) => { |
|
|
|
|
const key = '258e0ec35ea5c5d2479156be98e9b3e2'; |
|
|
|
|
function base64ToHex(base64: string): string { |
|
|
|
|
const binary = atob(base64); // Base64 解码成二进制字符串
|
|
|
|
|
return Array.from(binary) // 转换成字节数组
|
|
|
|
|
.map((byte) => ('0' + byte.charCodeAt(0).toString(16)).slice(-2)) // 转16进制
|
|
|
|
|
.join(''); |
|
|
|
|
} |
|
|
|
|
const publicKeyHex = base64ToHex(res); |
|
|
|
|
const data = JSON.parse(sm4.decrypt(publicKeyHex, key) as any); |
|
|
|
|
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
this.userList = data.items; |
|
|
|
|
this.totalCount = data.totalCount; |
|
|
|
|
console.log('用户列表', data); |
|
|
|
|
resolve(data); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
search() { |
|
|
|
|
this.PageNumber = 1 |
|
|
|
|
this.getAllUsers() |
|
|
|
|
this.PageNumber = 1; |
|
|
|
|
this.getAllUsers(); |
|
|
|
|
} |
|
|
|
|
reset() { |
|
|
|
|
this.PageNumber = 1 |
|
|
|
|
this.PageNumber = 1; |
|
|
|
|
this.searchForm = { |
|
|
|
|
Username: '', |
|
|
|
|
RoleName: '', |
|
|
|
|
name: '', |
|
|
|
|
or: JSON.parse(sessionStorage.getItem('userData')).organizationId |
|
|
|
|
} |
|
|
|
|
this.getAllUsers() |
|
|
|
|
or: JSON.parse(sessionStorage.getItem('userData')).organizationId, |
|
|
|
|
}; |
|
|
|
|
this.getAllUsers(); |
|
|
|
|
} |
|
|
|
|
expandKeys |
|
|
|
|
defaultOrId: string |
|
|
|
|
expandKeys; |
|
|
|
|
defaultOrId: string; |
|
|
|
|
//获取所有组织机构
|
|
|
|
|
nodes: any = [] |
|
|
|
|
nodes: any = []; |
|
|
|
|
getAllOrganization() { |
|
|
|
|
let organizationId = JSON.parse(sessionStorage.getItem('userData')).organizationId |
|
|
|
|
let organizationId = JSON.parse( |
|
|
|
|
sessionStorage.getItem('userData') |
|
|
|
|
).organizationId; |
|
|
|
|
let params = { |
|
|
|
|
ContainsChildren: "true", |
|
|
|
|
ContainsChildren: 'true', |
|
|
|
|
PageNumber: 1, |
|
|
|
|
PageSize: 9999, |
|
|
|
|
code: '0000' |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Organizations', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
console.log(data.items) |
|
|
|
|
data.items.forEach(element => { |
|
|
|
|
|
|
|
|
|
if (element.id == organizationId) { |
|
|
|
|
element.parentId = null |
|
|
|
|
} |
|
|
|
|
element.key = element.id |
|
|
|
|
element.title = element.name |
|
|
|
|
if (element.level == 'squadron') { |
|
|
|
|
element.isLeaf = true |
|
|
|
|
} |
|
|
|
|
code: '0000', |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.get('/api/Organizations', { |
|
|
|
|
params: params, |
|
|
|
|
}) |
|
|
|
|
.subscribe((data: any) => { |
|
|
|
|
console.log(data.items); |
|
|
|
|
data.items.forEach((element) => { |
|
|
|
|
if (element.id == organizationId) { |
|
|
|
|
element.parentId = null; |
|
|
|
|
} |
|
|
|
|
element.key = element.id; |
|
|
|
|
element.title = element.name; |
|
|
|
|
if (element.level == 'squadron') { |
|
|
|
|
element.isLeaf = true; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.nodes = [...this.toTree.toTree(data.items)]; |
|
|
|
|
this.searchForm.or = JSON.parse( |
|
|
|
|
sessionStorage.getItem('userData') |
|
|
|
|
).organizationId; |
|
|
|
|
this.getAllUsers(); |
|
|
|
|
}); |
|
|
|
|
this.nodes = [...this.toTree.toTree(data.items)] |
|
|
|
|
this.searchForm.or = JSON.parse(sessionStorage.getItem('userData')).organizationId |
|
|
|
|
this.getAllUsers() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//新增用户
|
|
|
|
|
addUser(): void { |
|
|
|
|
if (this.nodes.length == 0) { |
|
|
|
|
this.message.create('warning', '请组织机构加载完毕后重试'); |
|
|
|
|
return |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const modal = this.modal.create({ |
|
|
|
|
nzTitle: '新增用户', |
|
|
|
@ -138,7 +173,7 @@ export class UserComponent implements OnInit {
|
|
|
|
|
nzMaskClosable: false, |
|
|
|
|
nzComponentParams: { |
|
|
|
|
nodes: this.nodes, |
|
|
|
|
roleList: this.roleList |
|
|
|
|
roleList: this.roleList, |
|
|
|
|
}, |
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
if (instance.validateForm.valid) { |
|
|
|
@ -150,38 +185,40 @@ export class UserComponent implements OnInit {
|
|
|
|
|
organizationId: instance.validateForm.value.organization, |
|
|
|
|
roleIds: instance.validateForm.value.role, |
|
|
|
|
posts: instance.validateForm.value.posts, |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.http.post('/api/Users', body).subscribe({ |
|
|
|
|
next: async (data) => { |
|
|
|
|
this.message.create('success', '创建成功'); |
|
|
|
|
resolve(data) |
|
|
|
|
await this.getAllUsers() |
|
|
|
|
return true |
|
|
|
|
resolve(data); |
|
|
|
|
await this.getAllUsers(); |
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
this.isLoading = false; |
|
|
|
|
this.message.create('warning', '创建失败'); |
|
|
|
|
reject(err) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
reject(err); |
|
|
|
|
return false; |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
|
return false |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const instance = modal.getContentComponent(); |
|
|
|
|
modal.afterOpen.subscribe(() => console.log('[afterOpen] emitted!')); |
|
|
|
|
modal.afterClose.subscribe(result => console.log('[afterClose] The result is:', result)); |
|
|
|
|
modal.afterClose.subscribe((result) => |
|
|
|
|
console.log('[afterClose] The result is:', result) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//编辑用户
|
|
|
|
|
editUser(item): void { |
|
|
|
|
if (this.nodes.length == 0) { |
|
|
|
|
this.message.create('warning', '请组织机构加载完毕后重试'); |
|
|
|
|
return |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const modal = this.modal.create({ |
|
|
|
|
nzTitle: '编辑用户', |
|
|
|
@ -192,11 +229,12 @@ export class UserComponent implements OnInit {
|
|
|
|
|
nzComponentParams: { |
|
|
|
|
nodes: this.nodes, |
|
|
|
|
data: JSON.parse(JSON.stringify(item)), |
|
|
|
|
roleList: this.roleList |
|
|
|
|
roleList: this.roleList, |
|
|
|
|
}, |
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
if (instance.validateForm.valid) { |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
await new Promise((resolve) => { |
|
|
|
|
let phoneArr = instance.phone.map((v) => v.num); |
|
|
|
|
let body = { |
|
|
|
|
username: instance.validateForm.value.account, |
|
|
|
|
name: instance.validateForm.value.name, |
|
|
|
@ -204,26 +242,27 @@ export class UserComponent implements OnInit {
|
|
|
|
|
organizationId: instance.validateForm.value.organization, |
|
|
|
|
roleIds: instance.validateForm.value.role, |
|
|
|
|
posts: instance.validateForm.value.posts, |
|
|
|
|
} |
|
|
|
|
phone: phoneArr, |
|
|
|
|
}; |
|
|
|
|
this.http.patch(`/api/Users/${item.id}`, body).subscribe({ |
|
|
|
|
next: async (data) => { |
|
|
|
|
this.message.create('success', '创建成功'); |
|
|
|
|
resolve(data) |
|
|
|
|
await this.getAllUsers() |
|
|
|
|
return true |
|
|
|
|
this.message.create('success', '编辑成功'); |
|
|
|
|
resolve(data); |
|
|
|
|
await this.getAllUsers(); |
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
this.message.create('warning', '创建失败'); |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
this.isLoading = false; |
|
|
|
|
this.message.create('warning', '编辑失败'); |
|
|
|
|
return true; |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
|
return false |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const instance = modal.getContentComponent(); |
|
|
|
|
} |
|
|
|
@ -235,31 +274,31 @@ export class UserComponent implements OnInit {
|
|
|
|
|
nzOkText: '确定', |
|
|
|
|
nzOkType: 'primary', |
|
|
|
|
nzOnOk: () => { |
|
|
|
|
this.http.patch(`/api/Users/${item.id}/Password`, null).subscribe(data => { |
|
|
|
|
this.message.create('success', '重置成功!'); |
|
|
|
|
}) |
|
|
|
|
this.http |
|
|
|
|
.patch(`/api/Users/${item.id}/Password`, null) |
|
|
|
|
.subscribe((data) => { |
|
|
|
|
this.message.create('success', '重置成功!'); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
nzCancelText: '取消', |
|
|
|
|
nzOnCancel: () => { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
nzOnCancel: () => {}, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//禁用
|
|
|
|
|
cancel(item, type) { |
|
|
|
|
this.isLoading = true |
|
|
|
|
this.isLoading = true; |
|
|
|
|
let body = { |
|
|
|
|
enabled: type |
|
|
|
|
} |
|
|
|
|
enabled: type, |
|
|
|
|
}; |
|
|
|
|
this.http.patch(`/api/Users/${item.id}`, body).subscribe({ |
|
|
|
|
next: (data) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
item.enabled = type |
|
|
|
|
this.isLoading = false; |
|
|
|
|
item.enabled = type; |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
this.isLoading = false; |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
delete(item) { |
|
|
|
|
this.modal.confirm({ |
|
|
|
@ -267,12 +306,12 @@ export class UserComponent implements OnInit {
|
|
|
|
|
nzOkText: '确定', |
|
|
|
|
nzOkType: 'default', |
|
|
|
|
nzOnOk: () => { |
|
|
|
|
this.http.delete(`/api/Users/${item.id}`).subscribe(data => { |
|
|
|
|
this.http.delete(`/api/Users/${item.id}`).subscribe((data) => { |
|
|
|
|
this.message.create('success', '删除成功!'); |
|
|
|
|
this.getAllUsers() |
|
|
|
|
}) |
|
|
|
|
this.getAllUsers(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
nzCancelText: '取消' |
|
|
|
|
nzCancelText: '取消', |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -283,22 +322,23 @@ export class UserComponent implements OnInit {
|
|
|
|
|
Name: this.searchForm.name, |
|
|
|
|
OrganizationId: this.searchForm.or, |
|
|
|
|
ContainsChildren: 'true', |
|
|
|
|
ExportToExcel: 'true' |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Users', { |
|
|
|
|
params: params, |
|
|
|
|
responseType: 'blob' as 'json' |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
const link = document.createElement('a'); |
|
|
|
|
const blob = new Blob([data], { type: 'application/vnd.ms-excel' }); |
|
|
|
|
link.setAttribute('href', window.URL.createObjectURL(blob)); |
|
|
|
|
link.setAttribute('download', '用户列表' + '.xls'); |
|
|
|
|
link.style.visibility = 'hidden'; |
|
|
|
|
document.body.appendChild(link); |
|
|
|
|
link.click(); |
|
|
|
|
document.body.removeChild(link); |
|
|
|
|
this.message.create('success', '导出成功!'); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
ExportToExcel: 'true', |
|
|
|
|
}; |
|
|
|
|
this.http |
|
|
|
|
.get('/api/Users', { |
|
|
|
|
params: params, |
|
|
|
|
responseType: 'blob' as 'json', |
|
|
|
|
}) |
|
|
|
|
.subscribe((data: any) => { |
|
|
|
|
const link = document.createElement('a'); |
|
|
|
|
const blob = new Blob([data], { type: 'application/vnd.ms-excel' }); |
|
|
|
|
link.setAttribute('href', window.URL.createObjectURL(blob)); |
|
|
|
|
link.setAttribute('download', '用户列表' + '.xls'); |
|
|
|
|
link.style.visibility = 'hidden'; |
|
|
|
|
document.body.appendChild(link); |
|
|
|
|
link.click(); |
|
|
|
|
document.body.removeChild(link); |
|
|
|
|
this.message.create('success', '导出成功!'); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|