|
|
@ -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( |
|
|
|