|
|
|
@ -14,56 +14,146 @@ import { TreeService } from 'src/app/service/tree.service';
|
|
|
|
|
}) |
|
|
|
|
export class UserComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
validateForm!: FormGroup; |
|
|
|
|
constructor(private fb: FormBuilder, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private message: NzMessageService, private http: HttpClient, private toTree: TreeService) { } |
|
|
|
|
searchForm = { |
|
|
|
|
id: '', |
|
|
|
|
name: '', |
|
|
|
|
or: '' |
|
|
|
|
} |
|
|
|
|
usersNum |
|
|
|
|
|
|
|
|
|
loading |
|
|
|
|
usersLIst = [1] |
|
|
|
|
userList = [] |
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
this.getAllRoles() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取角色列表
|
|
|
|
|
roleList |
|
|
|
|
getAllRoles() { |
|
|
|
|
let params = { |
|
|
|
|
PageNumber: 1, |
|
|
|
|
PageSize: 100 |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Roles', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
this.roleList = data.items |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pageChange($event) { |
|
|
|
|
this.PageNumber = $event |
|
|
|
|
this.getAllUsers() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取用户列表
|
|
|
|
|
isLoading = false |
|
|
|
|
totalCount |
|
|
|
|
PageNumber = 1 |
|
|
|
|
PageSize = 16 |
|
|
|
|
async getAllUsers() { |
|
|
|
|
this.isLoading = true |
|
|
|
|
let params = { |
|
|
|
|
Name: this.searchForm.name, |
|
|
|
|
OrganizationId: this.searchForm.or, |
|
|
|
|
PageNumber: this.PageNumber, |
|
|
|
|
PageSize: this.PageSize, |
|
|
|
|
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) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
search() { |
|
|
|
|
this.PageNumber = 1 |
|
|
|
|
this.getAllUsers() |
|
|
|
|
} |
|
|
|
|
reset() { |
|
|
|
|
this.PageNumber = 1 |
|
|
|
|
this.searchForm = { |
|
|
|
|
name: '', |
|
|
|
|
or: JSON.parse(sessionStorage.getItem('userData')).organizationId |
|
|
|
|
} |
|
|
|
|
this.getAllUsers() |
|
|
|
|
} |
|
|
|
|
expandKeys |
|
|
|
|
defaultOrId: string |
|
|
|
|
//获取所有组织机构
|
|
|
|
|
nodes: any = [] |
|
|
|
|
getAllOrganization() { |
|
|
|
|
let organizationId = JSON.parse(sessionStorage.getItem('userData')).organizationId |
|
|
|
|
let params = { |
|
|
|
|
OrganizationId: organizationId || '', |
|
|
|
|
ContainsChildren: "true", |
|
|
|
|
PageNumber: 1, |
|
|
|
|
PageSize: 9999 |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Organizations', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
console.log('xxx', data) |
|
|
|
|
data.items.forEach(element => { |
|
|
|
|
if (element.id == organizationId) { |
|
|
|
|
element.parentId = null |
|
|
|
|
} |
|
|
|
|
element.key = element.id |
|
|
|
|
element.title = element.name |
|
|
|
|
}); |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
const modal = this.modal.create({ |
|
|
|
|
nzTitle: '新增用户', |
|
|
|
|
nzContent: AdduserComponent, |
|
|
|
|
nzViewContainerRef: this.viewContainerRef, |
|
|
|
|
nzWidth: 460, |
|
|
|
|
nzWidth: 485, |
|
|
|
|
nzMaskClosable: false, |
|
|
|
|
nzComponentParams: { |
|
|
|
|
title: '', |
|
|
|
|
subtitle: '' |
|
|
|
|
nodes: this.nodes, |
|
|
|
|
roleList: this.roleList |
|
|
|
|
}, |
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
if (instance.validateForm.valid) { |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
let roleNames = [...instance.validateForm.value.role, ...instance.validateForm.value.role2] |
|
|
|
|
await new Promise((resolve, reject) => { |
|
|
|
|
let body = { |
|
|
|
|
userName: instance.validateForm.value.account, |
|
|
|
|
username: instance.validateForm.value.account, |
|
|
|
|
name: instance.validateForm.value.name, |
|
|
|
|
organizationUnitId: Number(instance.validateForm.value.organization), |
|
|
|
|
roleNames: roleNames, |
|
|
|
|
phoneNumber: instance.validateForm.value.phonenum, |
|
|
|
|
isActive: true |
|
|
|
|
email: instance.validateForm.value.email, |
|
|
|
|
organizationId: instance.validateForm.value.organization, |
|
|
|
|
roleIds: instance.validateForm.value.role, |
|
|
|
|
} |
|
|
|
|
// this.http.post(this.addUrl, body).subscribe(data => {
|
|
|
|
|
// resolve(data)
|
|
|
|
|
// this.message.create('success', '创建成功!');
|
|
|
|
|
// this.SkipCount = 0
|
|
|
|
|
// this.getAllUsers()
|
|
|
|
|
// return true
|
|
|
|
|
// }, err => {
|
|
|
|
|
// resolve(err)
|
|
|
|
|
// this.message.create('warning', err.error.error.message);
|
|
|
|
|
// return false
|
|
|
|
|
// })
|
|
|
|
|
this.http.post('/api/Users', body).subscribe({ |
|
|
|
|
next: async (data) => { |
|
|
|
|
this.message.create('success', '创建成功'); |
|
|
|
|
resolve(data) |
|
|
|
|
await this.getAllUsers() |
|
|
|
|
return true |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
this.message.create('warning', '创建失败'); |
|
|
|
|
reject(err) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
@ -77,48 +167,45 @@ export class UserComponent implements OnInit {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//编辑用户
|
|
|
|
|
editUser(data): void { |
|
|
|
|
console.log(data) |
|
|
|
|
editUser(item): void { |
|
|
|
|
if (this.nodes.length == 0) { |
|
|
|
|
this.message.create('warning', '请组织机构加载完毕后重试'); |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
const modal = this.modal.create({ |
|
|
|
|
nzTitle: '编辑用户', |
|
|
|
|
nzContent: EdituserComponent, |
|
|
|
|
nzViewContainerRef: this.viewContainerRef, |
|
|
|
|
nzWidth: 460, |
|
|
|
|
nzWidth: 485, |
|
|
|
|
nzMaskClosable: false, |
|
|
|
|
nzComponentParams: { |
|
|
|
|
data: data |
|
|
|
|
nodes: this.nodes, |
|
|
|
|
data: JSON.parse(JSON.stringify(item)), |
|
|
|
|
roleList: this.roleList |
|
|
|
|
}, |
|
|
|
|
nzOnOk: async () => { |
|
|
|
|
if (instance.validateForm.valid) { |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
|
|
|
|
|
for (let index = 0; index < instance.validateForm.value.role2.length; index++) { |
|
|
|
|
const element = instance.validateForm.value.role2[index]; |
|
|
|
|
if (element.indexOf('HANDLE') != -1) { |
|
|
|
|
instance.validateForm.value.role2.splice(index, 1) |
|
|
|
|
index-- |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let roleNames = [...instance.validateForm.value.role, ...instance.validateForm.value.role2] |
|
|
|
|
let body = { |
|
|
|
|
id: data.id, |
|
|
|
|
userName: instance.validateForm.value.account, |
|
|
|
|
username: instance.validateForm.value.account, |
|
|
|
|
name: instance.validateForm.value.name, |
|
|
|
|
organizationUnitId: instance.validateForm.value.organization, |
|
|
|
|
roleNames: roleNames, |
|
|
|
|
phoneNumber: instance.validateForm.value.phonenum, |
|
|
|
|
isActive: true |
|
|
|
|
email: instance.validateForm.value.email, |
|
|
|
|
organizationId: instance.validateForm.value.organization, |
|
|
|
|
roleIds: instance.validateForm.value.role, |
|
|
|
|
} |
|
|
|
|
// this.http.put(this.editUrl, body).subscribe(data => {
|
|
|
|
|
// resolve(data)
|
|
|
|
|
// this.message.create('success', '编辑成功!');
|
|
|
|
|
// this.getAllUsers()
|
|
|
|
|
// return true
|
|
|
|
|
// }, err => {
|
|
|
|
|
// resolve(err)
|
|
|
|
|
// this.message.create('warning', '编辑失败');
|
|
|
|
|
// return false
|
|
|
|
|
// })
|
|
|
|
|
this.http.patch(`/api/Users/${item.id}`, body).subscribe({ |
|
|
|
|
next: async (data) => { |
|
|
|
|
this.message.create('success', '创建成功'); |
|
|
|
|
resolve(data) |
|
|
|
|
await this.getAllUsers() |
|
|
|
|
return true |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.isLoading = false |
|
|
|
|
this.message.create('warning', '创建失败'); |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.message.create('warning', '请填写完整!'); |
|
|
|
@ -131,16 +218,12 @@ export class UserComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
//重置密码
|
|
|
|
|
resetPassword(item) { |
|
|
|
|
console.log(item) |
|
|
|
|
this.modal.confirm({ |
|
|
|
|
nzTitle: `确定要重置${item.userName}这个账户的密码吗?`, |
|
|
|
|
nzTitle: `确定要重置${item.name}这个账户的密码吗?`, |
|
|
|
|
nzOkText: '确定', |
|
|
|
|
nzOkType: 'primary', |
|
|
|
|
nzOnOk: () => { |
|
|
|
|
let body = { |
|
|
|
|
userId: item.id |
|
|
|
|
} |
|
|
|
|
this.http.post('/api/services/app/User/ResetPassword', body).subscribe(data => { |
|
|
|
|
this.http.patch(`/api/Users/${item.id}/Password`, null).subscribe(data => { |
|
|
|
|
this.message.create('success', '重置成功!'); |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
@ -150,10 +233,22 @@ export class UserComponent implements OnInit {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//禁用
|
|
|
|
|
cancel(item, type) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
delete(item) { |
|
|
|
|
|
|
|
|
|
this.modal.confirm({ |
|
|
|
|
nzTitle: `确定要删除${item.name}这个用户吗?`, |
|
|
|
|
nzOkText: '确定', |
|
|
|
|
nzOkType: 'default', |
|
|
|
|
nzOnOk: () => { |
|
|
|
|
this.http.delete(`/api/Users/${item.id}`).subscribe(data => { |
|
|
|
|
this.message.create('success', '删除成功!'); |
|
|
|
|
this.getAllUsers() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
nzCancelText: '取消' |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|