15 changed files with 509 additions and 28 deletions
@ -0,0 +1,172 @@ |
|||||
|
|
||||
|
# 食材部分 |
||||
|
|
||||
|
# 1. 查询食材 |
||||
|
|
||||
|
> GET /api/ingredient |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
pageSize=20 // 默认20, 全部非必填 |
||||
|
pageNo=0 // 默认0, 从0开始 |
||||
|
type=谷薯类 // 食材类型 |
||||
|
mark=常用 // 食材标记. 业务端用标记,管理端没用 |
||||
|
keyword=01 // 查询关键字 |
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"body": { |
||||
|
"content": [ |
||||
|
{ |
||||
|
"key": "011101", |
||||
|
"mark": "常用", |
||||
|
"name": "小麦", |
||||
|
"nutrient": { |
||||
|
"fat": 10, |
||||
|
"energy": 10, |
||||
|
"calcium": 12, |
||||
|
"protein": 15, |
||||
|
"vitamin-a": 23 |
||||
|
}, |
||||
|
"time": 1693759354000, |
||||
|
"type": "谷薯类" |
||||
|
} |
||||
|
], |
||||
|
"number": 0, |
||||
|
"size": 20, |
||||
|
"totalElements": 1, |
||||
|
"totalPages": 1 |
||||
|
}, |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
# 2. 添加食材(管理端接口) |
||||
|
|
||||
|
> PUT /api/ingredient |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type:application/x-www-form-urlencoded |
||||
|
key=010101 // 必填 |
||||
|
name=测试食材 // 必填 |
||||
|
type=粗粮 // 必填 全部必填 取值范围见(/api/basic/enum) category |
||||
|
nutrient={"fat": 10, "energy": 10, "calcium": 12, "protein": 15, "vitamin-a": 23} |
||||
|
// 必填 取值范围见(/api/basic/enum) nutrient |
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
# 3. 修改食材(管理端接口) |
||||
|
|
||||
|
> POST /api/ingredient |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type:application/x-www-form-urlencoded |
||||
|
key=010101 // 必填 |
||||
|
name=测试食材 |
||||
|
type=粗粮 |
||||
|
nutrient={"fat": 10, "energy": 10, "calcium": 12, "protein": 15, "vitamin-a": 23} |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
# 4. 删除食材(管理端接口) |
||||
|
|
||||
|
> DELETE /api/ingredient |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type:application/x-www-form-urlencoded |
||||
|
nutrients=010101,020202,030303 // 必填 |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
# 5. 食材打标(业务端接口) |
||||
|
|
||||
|
> PUT /api/ingredient/mark |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type:application/x-www-form-urlencoded |
||||
|
nutrient=010101 |
||||
|
mark=常用 // 必填, 取值: 常用/忌用 |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
# 6. 取消打标(业务端接口) |
||||
|
|
||||
|
> DELETE /api/ingredient/mark |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type:application/x-www-form-urlencoded |
||||
|
nutrient=010101 |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
# 7. 批量导入(管理端接口) |
||||
|
|
||||
|
> PUT /api/ingredient/mark |
||||
|
|
||||
|
### 输入: |
||||
|
``` |
||||
|
Content-Type: multipart/form-data |
||||
|
files // 必传 |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
### 输出: |
||||
|
``` |
||||
|
{ |
||||
|
"code": 200, |
||||
|
"desc": "成功", |
||||
|
"success": true |
||||
|
} |
||||
|
``` |
@ -1 +1,2 @@ |
|||||
export * from "./app-layout/app-layout.component"; |
export * from "./app-layout/app-layout.component"; |
||||
|
export * from "./org-form/org-form.component"; |
||||
|
@ -0,0 +1,69 @@ |
|||||
|
<form nz-form [formGroup]="formGroup" nzLayout="vertical"> |
||||
|
|
||||
|
<div> |
||||
|
<nz-form-item> |
||||
|
<nz-form-label nzRequired> |
||||
|
单位名称 |
||||
|
</nz-form-label> |
||||
|
<nz-form-control [nzErrorTip]="formControlErrorTpl"> |
||||
|
<input nz-input placeholder="请输入单位名称" formControlName="name" /> |
||||
|
</nz-form-control> |
||||
|
</nz-form-item> |
||||
|
<nz-form-item> |
||||
|
<nz-form-label> |
||||
|
单位Logo |
||||
|
</nz-form-label> |
||||
|
<nz-form-control [nzErrorTip]="formControlErrorTpl"> |
||||
|
<div class="mb-2" *ngIf="icon"> |
||||
|
<img [src]="icon" class="h-20 w-20" /> |
||||
|
</div> |
||||
|
<button class="vlock upload-btn " nz-button [nzLoading]="uploadLoading"> |
||||
|
<i nz-icon nzType="upload"></i> |
||||
|
上传图片 |
||||
|
<input type="file" (change)="onFileChange($event)" /> |
||||
|
<input type="hidden" formControlName="icon" (change)="onFileChange($event)" /> |
||||
|
</button> |
||||
|
</nz-form-control> |
||||
|
</nz-form-item> |
||||
|
<nz-form-item> |
||||
|
<nz-form-label> |
||||
|
地址 |
||||
|
</nz-form-label> |
||||
|
<nz-form-control [nzErrorTip]="formControlErrorTpl"> |
||||
|
<input nz-input placeholder="请输入单位地址" formControlName="address" /> |
||||
|
</nz-form-control> |
||||
|
</nz-form-item> |
||||
|
<nz-form-item> |
||||
|
<nz-form-label> |
||||
|
联系人 |
||||
|
</nz-form-label> |
||||
|
<nz-form-control [nzErrorTip]="formControlErrorTpl"> |
||||
|
<input nz-input placeholder="请输入联系人" formControlName="contacts" /> |
||||
|
</nz-form-control> |
||||
|
</nz-form-item> |
||||
|
<nz-form-item> |
||||
|
<nz-form-label> |
||||
|
联系电话 |
||||
|
</nz-form-label> |
||||
|
<nz-form-control [nzErrorTip]="formControlErrorTpl"> |
||||
|
<input nz-input placeholder="请输入联系电话" formControlName="phone" /> |
||||
|
</nz-form-control> |
||||
|
</nz-form-item> |
||||
|
<nz-form-item> |
||||
|
<nz-form-label> |
||||
|
邮箱 |
||||
|
</nz-form-label> |
||||
|
<nz-form-control [nzErrorTip]="formControlErrorTpl"> |
||||
|
<input nz-input placeholder="请输入邮箱" formControlName="email" /> |
||||
|
</nz-form-control> |
||||
|
</nz-form-item> |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
|
||||
|
</form> |
||||
|
|
||||
|
|
||||
|
<ng-template #formControlErrorTpl let-control> |
||||
|
<form-error-tips [control]="control"></form-error-tips> |
||||
|
</ng-template> |
@ -0,0 +1,88 @@ |
|||||
|
import { ApiService } from "@admin/app/services"; |
||||
|
import { Component, inject } from "@angular/core"; |
||||
|
import { FormBuilder, FormGroup } from "@angular/forms"; |
||||
|
import { Utils } from "@cdk/utils"; |
||||
|
import { FormValidators } from "@cdk/validators"; |
||||
|
import { MD5 } from "crypto-js"; |
||||
|
import { NzMessageService } from "ng-zorro-antd/message"; |
||||
|
import { lastValueFrom } from "rxjs"; |
||||
|
import { format } from "date-fns"; |
||||
|
import { ActivatedRoute, Router } from "@angular/router"; |
||||
|
import { AnyObject } from "@cdk/types"; |
||||
|
import { NZ_MODAL_DATA } from "ng-zorro-antd/modal"; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: "app-org-form", |
||||
|
templateUrl: "./org-form.component.html", |
||||
|
styleUrls: ["./org-form.component.less"], |
||||
|
}) |
||||
|
export class OrgFormComponent { |
||||
|
constructor( |
||||
|
private fb: FormBuilder, |
||||
|
private api: ApiService, |
||||
|
private msg: NzMessageService, |
||||
|
private router: Router |
||||
|
) {} |
||||
|
|
||||
|
state = inject<AnyObject>(NZ_MODAL_DATA); |
||||
|
|
||||
|
formGroup!: FormGroup; |
||||
|
|
||||
|
uploadLoading = false; |
||||
|
|
||||
|
get icon() { |
||||
|
return this.formGroup.get("icon")?.value; |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
console.log("this.state", this.state); |
||||
|
this.formGroup = this.fb.group({ |
||||
|
id: this.fb.control(""), |
||||
|
name: this.fb.control("", [FormValidators.required("单位名称不能为空")]), |
||||
|
icon: this.fb.control("", []), |
||||
|
address: this.fb.control("", []), |
||||
|
contacts: this.fb.control("", []), |
||||
|
phone: this.fb.control("", []), |
||||
|
email: this.fb.control("", []), |
||||
|
}); |
||||
|
this.formGroup.patchValue(this.state); |
||||
|
} |
||||
|
|
||||
|
async onSubmit() { |
||||
|
if (Utils.validateFormGroup(this.formGroup)) { |
||||
|
const org = { ...(this.state ?? {}), ...this.formGroup.value }; |
||||
|
org["password"] = MD5(org.password!).toString().substring(16).toUpperCase(); |
||||
|
org["expire"] = format(org["expire"], "yyyy-MM-dd"); |
||||
|
org["venderId"] = org.id; |
||||
|
// const account = await lastValueFrom(this.api.checkOrgAccount(org.account!));
|
||||
|
// const name = await lastValueFrom(this.api.checkOrgName(org.name!));
|
||||
|
|
||||
|
// if (!account.body) {
|
||||
|
// this.msg.error("账号重复");
|
||||
|
// return;
|
||||
|
// }
|
||||
|
// if (!name.body) {
|
||||
|
// this.msg.error("单位名称重复");
|
||||
|
// return;
|
||||
|
// }
|
||||
|
|
||||
|
const res = await lastValueFrom(this.api.saveOrg(org)); |
||||
|
this.msg.success(res.desc); |
||||
|
this.router.navigate(["/organization/list"]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
onFileChange(e: Event) { |
||||
|
const target = e.target as HTMLInputElement; |
||||
|
const file = target.files![0]; |
||||
|
target.value = ""; |
||||
|
const fileReader = new FileReader(); |
||||
|
fileReader.onload = () => { |
||||
|
const base64 = fileReader.result as string; |
||||
|
this.formGroup.patchValue({ |
||||
|
icon: base64, |
||||
|
}); |
||||
|
}; |
||||
|
fileReader.readAsDataURL(file); |
||||
|
} |
||||
|
} |
@ -1,10 +1,35 @@ |
|||||
import { Component } from '@angular/core'; |
import { Component, OnInit } from "@angular/core"; |
||||
|
import { ClientApiService } from "../../services"; |
||||
|
import { FormControl, FormGroup } from "@angular/forms"; |
||||
|
import { Utils } from "@cdk/utils"; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'app-meal-setting', |
selector: "app-meal-setting", |
||||
templateUrl: './meal-setting.component.html', |
templateUrl: "./meal-setting.component.html", |
||||
styleUrls: ['./meal-setting.component.less'] |
styleUrls: ["./meal-setting.component.less"], |
||||
}) |
}) |
||||
export class MealSettingComponent { |
export class MealSettingComponent implements OnInit { |
||||
|
constructor(private api: ClientApiService) {} |
||||
|
|
||||
|
account = this.api.account; |
||||
|
|
||||
|
formGroup = new FormGroup({ |
||||
|
breakfast: new FormControl(0, []), |
||||
|
dinner: new FormControl(0, []), |
||||
|
lunch: new FormControl(0, []), |
||||
|
}); |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.api.getOrgConfig().subscribe((res) => { |
||||
|
this.formGroup.patchValue(res.body); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
onSubmit() { |
||||
|
if (Utils.validateFormGroup(this.formGroup)) { |
||||
|
this.api.saveOrgConfig({ ...this.formGroup.value, vender: this.account.vender.id }).subscribe((res) => { |
||||
|
// this.formGroup.
|
||||
|
}); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
@ -0,0 +1,17 @@ |
|||||
|
import { inject } from "@angular/core"; |
||||
|
import { Router } from "@angular/router"; |
||||
|
import { map } from "rxjs"; |
||||
|
import { ClientApiService } from "./client-api.service"; |
||||
|
|
||||
|
export const authGuard = () => { |
||||
|
const router = inject(Router); |
||||
|
const api = inject(ClientApiService); |
||||
|
const stragedAccount = localStorage.getItem(api.accountKey); |
||||
|
|
||||
|
if (!stragedAccount) { |
||||
|
router.navigate(["/login"]); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return api.getAllEnum(); |
||||
|
}; |
Loading…
Reference in new issue