Browse Source

大屏修改&菜谱添加菜品默认重量

main
kkerwin 1 year ago
parent
commit
c98e624f8f
  1. 6
      projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.ts
  2. 3
      projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html
  3. 9
      projects/cdk/src/services/api.service.ts
  4. 2
      projects/cdk/src/types/index.ts
  5. 9
      projects/client/src/app/pages/data-vis/data-vis.component.html
  6. 59
      projects/client/src/app/pages/data-vis/data-vis.component.ts

6
projects/cdk/src/ingredient/add-dish-to-ingredient/add-dish-to-ingredient.component.ts

@ -31,11 +31,12 @@ export class AddDishToIngredientComponent implements OnInit {
foods: FoodInDishInterface[] = [];
ngOnInit(): void {
console.log("this.peopleGroups", this.peopleGroups);
// console.log("this.peopleGroups", this.peopleGroups);
}
onDishChange(dish: any) {
if (dish) {
this.dish = dish;
this.mark = dish.marks;
this.getFoodNameByKeys(dish.ingredient);
}
@ -45,6 +46,7 @@ export class AddDishToIngredientComponent implements OnInit {
const keys = foods.map((i) => i.key);
this.api.getFoodList({ keys }).subscribe((res) => {
this.foods = res.body.map((i) => {
const value = this.dish?.ingredient?.find((f: any) => f["key"] === i.key)?.value ?? 0;
return {
foodName: i.name,
key: i.key,
@ -52,7 +54,7 @@ export class AddDishToIngredientComponent implements OnInit {
groupValues: this.peopleGroups.map((p) => {
return {
peopleName: p,
value: 0,
value,
};
}),
value: {},

3
projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html

@ -44,10 +44,7 @@
<th *ngFor="let p of peopleGroups">
{{p}}
</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let dish of mealDishs;let dishIndex = index">

9
projects/cdk/src/services/api.service.ts

@ -572,7 +572,12 @@ export class ApiService {
return this.http.get<ResponseType>(`/api/menu/analysis/types?${params}`);
}
getMenuDataVis() {
return this.http.get<ResponseType>(`/api/menu/dish`);
getCurrentDayDataVisList() {
return this.http.get<ResponseType>(`/api/menu/display`);
}
getMenuDataVis(menuId: number) {
// return this.http.get<ResponseType>(`/api/menu/dish`);
return this.http.get<ResponseType>(`/api/menu/display?menuId=${menuId}`);
}
}

2
projects/cdk/src/types/index.ts

@ -6,6 +6,8 @@ export type DecText = number | string;
export type Augmented<O extends object> = O & AnyObject;
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export type NutrientInterface = {
key: string;
measurement: string;

9
projects/client/src/app/pages/data-vis/data-vis.component.html

@ -14,7 +14,12 @@
<div class="flex-1 flex flex-col">
<div class="flex-1 overflow-hidden pb-2">
<div class="box">
<div class="tit">今日带量食谱</div>
<div class="tit">
今日带量食谱
<ng-container *ngIf="currentMenu">
【{{currentMenu.name}}】
</ng-container>
</div>
<div class="boxnav overflow-hidden" #tableEl>
<table class="w-full">
<thead>
@ -80,7 +85,7 @@
<span>
今日营养分析
</span>
<span>
<span *ngIf="peoples.length">
<select [(ngModel)]="people" class="select" (ngModelChange)="getAnalysis()">
<option *ngFor="let p of peoples" [value]="p">
{{p}}

59
projects/client/src/app/pages/data-vis/data-vis.component.ts

@ -3,6 +3,13 @@ import { ApiService } from "@cdk/services";
import { format } from "date-fns";
import { Subject, finalize, interval, takeUntil } from "rxjs";
interface MenuDisplayItem {
name: string;
id: number;
}
const changeTime = 1000 * 60 * 3;
@Component({
selector: "app-data-vis",
templateUrl: "./data-vis.component.html",
@ -37,10 +44,16 @@ export class DataVisComponent implements AfterViewInit {
people = "";
menuId!: string;
menuId?: string;
logo = "";
menus: MenuDisplayItem[] = [];
currentMenu: MenuDisplayItem | null = null;
lastTime: number = 0;
ngOnInit(): void {
this.api.getOrgInfo().subscribe((res) => {
const account = this.api.account;
@ -52,10 +65,42 @@ export class DataVisComponent implements AfterViewInit {
interval(1000)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
const now = new Date();
this.showTime = format(new Date(), "yyyy-MM-dd HH:mm:ss");
if (now.getTime() - this.lastTime > changeTime) {
const currentIndex = this.menus.findIndex((f) => f.id === this.currentMenu?.id);
let idx = currentIndex + 1;
if (idx > this.menus.length - 1) {
idx = 0;
}
this.currentMenu = this.menus[idx];
this.getDataVisData(this.currentMenu.id);
this.lastTime = now.getTime();
}
});
this.api.getMenuDataVis().subscribe((res) => {
this.api.getCurrentDayDataVisList().subscribe((r) => {
if (Array.isArray(r.body)) {
this.menus = r.body;
}
});
}
ngAfterViewInit(): void {}
ngOnDestroy(): void {
this.destroy$.next(null);
this.destroy$.complete();
}
getDataVisData(id: number) {
this.analysis = null;
this.peoples = [];
this.people = "";
this.dishs = {};
this.scroll = {};
this.api.getMenuDataVis(id).subscribe((res) => {
const dishs = res.body;
if (Array.isArray(dishs)) {
this.peoples = Object.keys(dishs?.[0]?.ingredient?.[0]?.value);
@ -93,13 +138,6 @@ export class DataVisComponent implements AfterViewInit {
});
}
ngAfterViewInit(): void {}
ngOnDestroy(): void {
this.destroy$.next(null);
this.destroy$.complete();
}
autoScroll(el: HTMLElement, scroll: string) {
const child = el.children[0];
if (!child) {
@ -123,6 +161,9 @@ export class DataVisComponent implements AfterViewInit {
}
getAnalysis() {
if (!this.menuId) {
return;
}
this.api
.getAnalysis(this.menuId, void 0, this.people)
.pipe(

Loading…
Cancel
Save