|
|
|
import { UserDTO, UserRoleDTO } from "@admin/app/dtos/user.dto";
|
|
|
|
import { ApiService } from "@admin/app/services";
|
|
|
|
import { Component, Input, OnInit, TemplateRef, ViewChild } from "@angular/core";
|
|
|
|
import { FormControl, FormGroup } from "@angular/forms";
|
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
import { AnyObject, FormValidators, TableListOption, Utils } from "@cdk/public-api";
|
|
|
|
import { MD5 } from "crypto-js";
|
|
|
|
import { NzMessageService } from "ng-zorro-antd/message";
|
|
|
|
import { NzModalService } from "ng-zorro-antd/modal";
|
|
|
|
import { lastValueFrom } from "rxjs";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-user-list",
|
|
|
|
templateUrl: "./user-list.component.html",
|
|
|
|
styleUrls: ["./user-list.component.less"],
|
|
|
|
})
|
|
|
|
export class UserListComponent {
|
|
|
|
constructor(
|
|
|
|
private api: ApiService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private modal: NzModalService,
|
|
|
|
private msg: NzMessageService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
@ViewChild("userFormTpl") public userFormTpl!: TemplateRef<void>;
|
|
|
|
|
|
|
|
@Input() users: UserDTO[] = [];
|
|
|
|
|
|
|
|
@Input() role!: UserRoleDTO;
|
|
|
|
|
|
|
|
public userFrom = new FormGroup({
|
|
|
|
uid: new FormControl("", [FormValidators.required("请输入账号")]),
|
|
|
|
name: new FormControl("", [FormValidators.required("请输入姓名")]),
|
|
|
|
password: new FormControl("", [FormValidators.required("请输入密码")]),
|
|
|
|
});
|
|
|
|
|
|
|
|
ngOnInit(): void {}
|
|
|
|
|
|
|
|
deleteItem() {}
|
|
|
|
|
|
|
|
openForm(item?: any) {
|
|
|
|
this.modal.create({
|
|
|
|
nzTitle: item ? "编辑用户" : "新增用户",
|
|
|
|
nzContent: this.userFormTpl,
|
|
|
|
nzOnOk: async () => {
|
|
|
|
if (Utils.validateFormGroup(this.userFrom)) {
|
|
|
|
const user = { ...this.userFrom.value, roleId: this.role.id };
|
|
|
|
user["password"] = MD5(user.password!).toString().substring(16).toUpperCase();
|
|
|
|
// const check = await lastValueFrom(this.api.checkUid(user.uid!));
|
|
|
|
// if (check.body) {
|
|
|
|
const res = await lastValueFrom(this.api.saveUser(user));
|
|
|
|
this.msg.success(res.desc);
|
|
|
|
return true;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|