配餐项目前端文件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9 KiB

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