配餐项目前端文件
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

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