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

130 lines
2.9 KiB

import { HttpClient, HttpParams } from "@angular/common/http";
2 years ago
import { Injectable } from "@angular/core";
import {
Utils,
AnyObject,
ResponseType,
UserRoleDTO,
PermItemDTO,
UserDTO,
GlobalEnum,
OrgConfigDTO,
ClientAccountDTO,
} from "@cdk/public-api";
import { Observable, map, of, tap } from "rxjs";
2 years ago
@Injectable({
providedIn: "root",
})
2 years ago
export class ClientApiServicde {
constructor(private http: HttpClient) {
try {
const strageAccount = localStorage.getItem(this.accountKey);
if (strageAccount) {
this.account = JSON.parse(strageAccount);
}
} catch (error) {
console.error("获取用户信息失败", error);
}
}
public account!: ClientAccountDTO;
2 years ago
2 years ago
public accountKey = "CATERING_ACCOUNT";
2 years ago
globalEnum!: GlobalEnum;
2 years ago
page(v: {}, q: {}) {
return this.http.get<any>("https://jsonplaceholder.typicode.com/users", v).pipe(
map((r) => {
return {
total: 10,
content: r,
};
})
);
}
getAllEnum(force?: boolean): Observable<GlobalEnum> {
if (this.globalEnum && !force) {
return of(this.globalEnum);
}
return this.http.get<ResponseType<GlobalEnum>>("/api/basic/enum").pipe(
map((res) => {
return res.body;
}),
tap((r) => {
this.globalEnum = r;
})
);
}
login(v: {}) {
const params = Utils.objectToHttpParams(v);
return this.http.get<ResponseType>("/api/login", { params });
}
logout() {
return this.http.get<ResponseType>("/api/logout");
}
getRoleList() {
return this.http.get<ResponseType<UserRoleDTO[]>>("/api/role");
}
deleteRole(roleId: string) {
const params = new HttpParams().set("roleId", roleId);
return this.http.delete<ResponseType>("/api/role", {
params,
});
}
updateRole(rule: AnyObject) {
const body = Utils.objectToFormData(rule);
const method = rule["roleId"] ? "post" : "put";
return this.http[method]<ResponseType>("/api/role", body);
}
getRolePerms() {
return this.http.get<ResponseType<PermItemDTO[]>>("/api/role/item");
}
getUserList() {
return this.http.get<ResponseType<UserDTO[]>>("/api/user");
}
checkUid(uid: string) {
const params = new HttpParams().set("uid", uid);
return this.http.delete<ResponseType>("/api/user/check", {
params,
});
}
saveUser(user: AnyObject, edit: boolean) {
const body = Utils.objectToFormData(user);
const method = edit ? "post" : "put";
return this.http[method]<ResponseType>("/api/user", body);
}
deleteUser(uid: string) {
const params = new HttpParams().set("uid", uid);
return this.http.delete<ResponseType>("/api/user", {
params,
});
}
saveOrg(org: AnyObject) {
const body = Utils.objectToFormData(org);
return this.http.post<ResponseType>(" /api/vender", body);
}
getOrgConfig() {
return this.http.get<ResponseType<OrgConfigDTO>>("/api/vender/config");
}
saveOrgConfig(config: AnyObject) {
const body = Utils.objectToFormData(config);
return this.http.post<ResponseType>("/api/vender/config", body);
}
2 years ago
}