Browse Source

复制标准&大屏修改&食谱优化

main
kkerwin 1 year ago
parent
commit
166d2c1091
  1. 216
      projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts
  2. 23
      projects/admin/src/app/pages/standard/standard-list/standard-list.component.ts
  3. 4
      projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts
  4. 26
      projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.html
  5. 2
      projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts
  6. 10
      projects/cdk/src/services/api.service.ts
  7. 19
      projects/client/src/app/pages/data-vis/data-vis.component.html
  8. 6
      projects/client/src/app/pages/data-vis/data-vis.component.less
  9. 84
      projects/client/src/app/pages/data-vis/data-vis.component.ts

216
projects/admin/src/app/pages/ingredients/ingredient-list/ingredient-list.component.ts

@ -1,18 +1,18 @@
import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core"; import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'
import { FormControl, FormGroup } from "@angular/forms"; import { FormControl, FormGroup } from '@angular/forms'
import { NzDrawerRef, NzDrawerService } from "ng-zorro-antd/drawer"; import { NzDrawerRef, NzDrawerService } from 'ng-zorro-antd/drawer'
import { AnyObject, OrgDTO, TableListOption } from "@cdk/public-api"; import { AnyObject, OrgDTO, TableListOption } from '@cdk/public-api'
import { ApiService } from "@cdk/services"; import { ApiService } from '@cdk/services'
import { NzModalService } from "ng-zorro-antd/modal"; import { NzModalService } from 'ng-zorro-antd/modal'
import { lastValueFrom, tap } from "rxjs"; import { lastValueFrom, tap } from 'rxjs'
import { NzMessageService } from "ng-zorro-antd/message"; import { NzMessageService } from 'ng-zorro-antd/message'
import { MyResponse } from "@cdk/types"; import { MyResponse } from '@cdk/types'
import { Router } from "@angular/router"; import { Router } from '@angular/router'
@Component({ @Component({
selector: "app-ingredient-list", selector: 'app-ingredient-list',
templateUrl: "./ingredient-list.component.html", templateUrl: './ingredient-list.component.html',
styleUrls: ["./ingredient-list.component.less"], styleUrls: ['./ingredient-list.component.less'],
}) })
export class IngredientListComponent { export class IngredientListComponent {
constructor( constructor(
@ -20,77 +20,77 @@ export class IngredientListComponent {
private api: ApiService, private api: ApiService,
private modal: NzModalService, private modal: NzModalService,
private msg: NzMessageService, private msg: NzMessageService,
private router: Router private router: Router,
) {} ) {}
globalEnum = this.api.globalEnum; globalEnum = this.api.globalEnum
statusTextMap: Record<string, string> = {}; statusTextMap: Record<string, string> = {}
@ViewChild("releaseStartTimeTpl") releaseStartTimeTpl!: TemplateRef<{}>; @ViewChild('releaseStartTimeTpl') releaseStartTimeTpl!: TemplateRef<{}>
private drawerRef?: NzDrawerRef; private drawerRef?: NzDrawerRef
public tableList = new TableListOption(this.fetchData.bind(this), { public tableList = new TableListOption(this.fetchData.bind(this), {
frontPagination: false, frontPagination: false,
}); })
public queryForm = new FormGroup({ public queryForm = new FormGroup({
name: new FormControl(""), name: new FormControl(''),
vender: new FormControl(""), vender: new FormControl(''),
status: new FormControl(""), status: new FormControl(''),
}); })
startTime: Date | null = null; startTime: Date | null = null
tableOrg: { [k: number]: OrgDTO } = {}; tableOrg: { [k: number]: OrgDTO } = {}
monthText = { monthText = {
1: "一月", 1: '一月',
2: "二月", 2: '二月',
3: "三月", 3: '三月',
4: "四月", 4: '四月',
5: "五月", 5: '五月',
6: "六月", 6: '六月',
7: "七月", 7: '七月',
8: "八月", 8: '八月',
9: "九月", 9: '九月',
10: "十月", 10: '十月',
11: "十一月", 11: '十一月',
12: "十二月", 12: '十二月',
} as any; } as any
ngOnInit(): void { ngOnInit(): void {
this.statusTextMap = this.globalEnum.menuStatus.reduce((a, c) => { this.statusTextMap = this.globalEnum.menuStatus.reduce((a, c) => {
return { return {
...a, ...a,
[String(c.label)]: c.value, [String(c.label)]: c.value,
}; }
}, {} as Record<string, string>); }, {} as Record<string, string>)
this.initTableList(); this.initTableList()
} }
initTableList() { initTableList() {
this.tableList.scroll = { x: "900px" }; this.tableList.scroll = { x: '900px' }
this.tableList = this.tableList.setColumns([ this.tableList = this.tableList.setColumns([
{ key: "name", title: "食谱名称", width: "200px" }, { key: 'name', title: '食谱名称', width: '200px' },
{ key: "vender", title: "单位", width: "200px" }, { key: 'vender', title: '单位', width: '200px' },
{ key: "meals", title: "包含餐次", width: "180px" }, { key: 'meals', title: '包含餐次', width: '180px' },
{ key: "month", title: "适用月份" }, { key: 'month', title: '适用月份' },
{ key: "day", title: "周期" }, { key: 'day', title: '周期' },
{ key: "status", title: "状态", width: "120px" }, { key: 'status', title: '状态', width: '120px' },
{ key: "modify", title: "更新时间", width: "170px" }, { key: 'modify', title: '更新时间', width: '170px' },
{ key: "operate", title: "创建人", width: "160px" }, { key: 'operate', title: '创建人', width: '160px' },
]); ])
this.tableList = this.tableList.setOptions([ this.tableList = this.tableList.setOptions([
{ {
title: "详情", title: '详情',
premissions: [], premissions: [],
onClick: this.preview.bind(this), onClick: this.preview.bind(this),
}, },
{ {
title: "导出", title: '导出',
premissions: [], premissions: [],
onClick: this.export.bind(this), onClick: this.export.bind(this),
@ -109,11 +109,11 @@ export class IngredientListComponent {
// }, // },
// }, // },
{ {
title: "发布", title: '发布',
premissions: [], premissions: [],
onClick: this.release.bind(this), onClick: this.release.bind(this),
visible(v) { visible(v) {
return [0, 2].includes(v.status); return [0, 2].includes(v.status)
}, },
}, },
// { // {
@ -124,35 +124,40 @@ export class IngredientListComponent {
// return [2].includes(v.status); // return [2].includes(v.status);
// }, // },
// }, // },
// {
// title: '复制',
// premissions: [],
// onClick: this.copy.bind(this),
// },
{ {
title: "编辑", title: '编辑',
premissions: [], premissions: [],
onClick: (v) => { onClick: (v) => {
this.router.navigate([`/ingredient/item/form/${v["id"]}`]); this.router.navigate([`/ingredient/item/form/${v['id']}`])
}, },
visible(v) { visible(v) {
return [0, 3, 4].includes(v.status); return [0, 3, 4].includes(v.status)
}, },
}, },
{ {
title: "删除", title: '删除',
premissions: [], premissions: [],
onClick: this.deleteItem.bind(this), onClick: this.deleteItem.bind(this),
}, },
]); ])
} }
fetchData(query: AnyObject, pager: AnyObject) { fetchData(query: AnyObject, pager: AnyObject) {
return this.api.getMenuPage(pager, query).pipe( return this.api.getMenuPage(pager, query).pipe(
tap((res) => { tap((res) => {
this.getTableColumData(res); this.getTableColumData(res)
}) }),
); )
} }
getTableColumData(res: MyResponse) { getTableColumData(res: MyResponse) {
if (Array.isArray(res.body.content)) { if (Array.isArray(res.body.content)) {
const vendors = res.body.content.map((i: any) => i.vender); const vendors = res.body.content.map((i: any) => i.vender)
if (vendors.length > 0) { if (vendors.length > 0) {
this.api.getOrgList({ vendors }).subscribe((org) => { this.api.getOrgList({ vendors }).subscribe((org) => {
@ -161,83 +166,102 @@ export class IngredientListComponent {
return { return {
...a, ...a,
[c.id]: c, [c.id]: c,
};
}, {} as AnyObject);
} }
}); }, {} as AnyObject)
}
})
} }
} }
} }
preview({ id }: any) { preview({ id }: any) {
window.open(`/ingredient/preview?id=${id}`); window.open(`/ingredient/preview?id=${id}`)
} }
export({ id }: any) { export({ id }: any) {
this.msg.loading("导出中..."); this.msg.loading('导出中...')
this.api.exportMenu(id).subscribe(() => { this.api.exportMenu(id).subscribe(() => {
setTimeout(() => { setTimeout(() => {
this.msg.remove(); this.msg.remove()
}, 1500); }, 1500)
}); })
} }
cancelFoodForm() { cancelFoodForm() {
this.drawerRef?.close(); this.drawerRef?.close()
}
copy(v: AnyObject) {
this.modal.confirm({
nzTitle: '警告',
nzContent: '是否要复制该食谱?',
nzOnOk: async () => {
const res = await lastValueFrom(
this.api.saveMenu({
name: v['name'] + '【复制】',
nutrient: v['nutrient'],
vendors: v['vendors'],
month: v,
}),
)
this.msg.success(res.desc)
this.tableList.run()
},
})
} }
shenhe({ id }: any) { shenhe({ id }: any) {
this.modal.confirm({ this.modal.confirm({
nzTitle: "警告", nzTitle: '警告',
nzContent: `是否要将该食谱提交审核?`, nzContent: `是否要将该食谱提交审核?`,
nzOnOk: async () => { nzOnOk: async () => {
const res = await lastValueFrom(this.api.submitMenuForReview(id)); const res = await lastValueFrom(this.api.submitMenuForReview(id))
this.msg.success(res.desc); this.msg.success(res.desc)
this.tableList.run(); this.tableList.run()
}, },
}); })
} }
release({ id, day }: any) { release({ id, day }: any) {
this.modal.create({ this.modal.create({
nzTitle: "发布食谱", nzTitle: '发布食谱',
nzContent: this.releaseStartTimeTpl, nzContent: this.releaseStartTimeTpl,
nzOnOk: async () => { nzOnOk: async () => {
if (!this.startTime) { if (!this.startTime) {
this.msg.error("请选择发布日期"); this.msg.error('请选择发布日期')
return false; return false
} }
const res = await lastValueFrom(this.api.release(id, this.startTime, day)); const res = await lastValueFrom(this.api.release(id, this.startTime, day))
this.msg.success(res.desc); this.msg.success(res.desc)
this.tableList.run(); this.tableList.run()
return true; return true
}, },
}); })
} }
deleteItem({ id }: any) { deleteItem({ id }: any) {
this.modal.confirm({ this.modal.confirm({
nzTitle: "警告", nzTitle: '警告',
nzContent: `是否要删除该食谱?`, nzContent: `是否要删除该食谱?`,
nzOkDanger: true, nzOkDanger: true,
nzOnOk: async () => { nzOnOk: async () => {
const res = await lastValueFrom(this.api.deleteMenu(id)); const res = await lastValueFrom(this.api.deleteMenu(id))
this.msg.success(res.desc); this.msg.success(res.desc)
this.tableList.run(); this.tableList.run()
}, },
}); })
} }
disableMenu({ id }: any) { disableMenu({ id }: any) {
this.modal.confirm({ this.modal.confirm({
nzTitle: "警告", nzTitle: '警告',
nzContent: `是否要禁用该食谱?`, nzContent: `是否要禁用该食谱?`,
nzOkDanger: true, nzOkDanger: true,
nzOnOk: async () => { nzOnOk: async () => {
const res = await lastValueFrom(this.api.disableMenu(id)); const res = await lastValueFrom(this.api.disableMenu(id))
this.msg.success(res.desc); this.msg.success(res.desc)
this.tableList.run(); this.tableList.run()
}, },
}); })
} }
} }

23
projects/admin/src/app/pages/standard/standard-list/standard-list.component.ts

@ -51,6 +51,11 @@ export class StandardListComponent {
premissions: [], premissions: [],
onClick: this.toSetting.bind(this), onClick: this.toSetting.bind(this),
}, },
{
title: '复制',
premissions: [],
onClick: this.copy.bind(this),
},
{ {
title: '编辑', title: '编辑',
premissions: [], premissions: [],
@ -68,6 +73,24 @@ export class StandardListComponent {
return this.api.getStandardPage(pager, query) return this.api.getStandardPage(pager, query)
} }
copy(standard: AnyObject) {
this.modal.confirm({
nzTitle: '警告',
nzContent: '是否要复制该标准?',
nzOnOk: async () => {
const res = await lastValueFrom(
this.api.saveStandard({
...standard,
name: standard['name'] + '【复制】',
id: null,
}),
)
this.msg.success(res.desc)
this.tableList.run()
},
})
}
toEdit(d: AnyObject) { toEdit(d: AnyObject) {
// this.standard.settingData$.next(d) // this.standard.settingData$.next(d)
this.router.navigate([`/standard/form/${d['id']}`], { this.router.navigate([`/standard/form/${d['id']}`], {

4
projects/cdk/src/ingredient/ingredient-dish/ingredient-dish.component.ts

@ -107,14 +107,16 @@ export class IngredientDishComponent implements OnChanges {
const meals = this.menuBaisc.meals as string[] const meals = this.menuBaisc.meals as string[]
console.log('this.menuBaisc', this.menuBaisc) console.log('this.menuBaisc', this.menuBaisc)
const day = this.menuBaisc.day as number[] const day = this.menuBaisc.day as number[]
this.days = day.map((i) => { this.days = day.map((i, idx) => {
const d = weekdayMap[i] const d = weekdayMap[i]
this.selectDay.push({ this.selectDay.push({
label: d, label: d,
value: String(i), value: String(i),
}) })
this.mealCurrentIndex[i] = 0 this.mealCurrentIndex[i] = 0
if (idx === 0) {
this.expanded.add(i) this.expanded.add(i)
}
// if (!this.menuObject) { // if (!this.menuObject) {
// this.menuObject = {}; // this.menuObject = {};
// } // }

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

@ -17,20 +17,16 @@
</tr> --> </tr> -->
<tr> <tr>
<th nzWidth="300px" class="placeholder-th">&nbsp;</th> <th nzWidth="200px" nzLeft class="placeholder-th">&nbsp;</th>
<th nzWidth="200px"> <th nzWidth="200px" nzLeft>
<span class="absolute top-2 left-[500px] z-10 w-[150px] h-[40px]">重量/克</span> <span class="absolute top-2 left-[500px] z-10 w-[150px] h-[40px]">重量/克</span>
</th> </th>
<th <th *ngFor="let p of peopleGroups; let last = last" [ngClass]="{ 'placeholder-th': !last }"></th>
*ngFor="let p of peopleGroups; let last = last"
[ngClass]="{ 'placeholder-th': !last }"
nzWidth="150px"
></th>
</tr> </tr>
<tr> <tr>
<th nzWidth="300px">菜品</th> <th nzWidth="200px" nzLeft>菜品</th>
<th nzWidth="200px">食材</th> <th nzWidth="200px" nzLeft>食材</th>
<th *ngFor="let p of peopleGroups"> <th *ngFor="let p of peopleGroups">
{{ p }} {{ p }}
</th> </th>
@ -39,16 +35,16 @@
<tbody> <tbody>
<ng-container *ngFor="let dish of mealDishs; let dishIndex = index"> <ng-container *ngFor="let dish of mealDishs; let dishIndex = index">
<ng-container *ngIf="dish['mealIndex'] === mealIndex && dish['day'] === day"> <ng-container *ngIf="dish['mealIndex'] === mealIndex && dish['day'] === day">
<ng-container *ngFor="let food of dish['items']; let first = first"> <ng-container *ngFor="let food of dish['items']; let first = first; let last = last">
<tr> <tr>
<td *ngIf="first" [rowSpan]="dish['items'].length"> <td nzLeft [ngStyle]="last ? {} : { 'border-bottom': 'none' }">
<div class="flex justify-between"> <div class="flex justify-between" *ngIf="first">
<div class="flex-1"> <div class="flex-1">
<div> <div>
{{ dish['dishName'] }} {{ dish['dishName'] }}
</div> </div>
<div> <div>
<nz-tag nzColor="blue" *ngFor="let lb of dish['dishLabel'] ?? []"> <nz-tag nzColor="blue" *ngFor="let lb of dish['label'] ?? []">
{{ lb }} {{ lb }}
</nz-tag> </nz-tag>
</div> </div>
@ -65,7 +61,7 @@
</nz-dropdown-menu> --> </nz-dropdown-menu> -->
</div> </div>
</td> </td>
<td> <td nzLeft>
<div class="flex justify-between"> <div class="flex justify-between">
<span> <span>
{{ food['foodName'] }} {{ food['foodName'] }}
@ -89,7 +85,7 @@
</ng-container> </ng-container>
</ng-container> </ng-container>
<tr class="total"> <tr class="total">
<td colSpan="2" class="text-center">本餐生重总量</td> <td [attr.colSpan]="2" nzLeft class="text-center">本餐生重总量</td>
<td *ngFor="let p of peopleGroups"> <td *ngFor="let p of peopleGroups">
{{ $any(totalObj[p])?.toFixed(2) }} {{ $any(totalObj[p])?.toFixed(2) }}
</td> </td>

2
projects/cdk/src/ingredient/ingredient-meals/ingredient-meals.component.ts

@ -126,7 +126,7 @@ export class IngredientMealsComponent implements OnChanges, OnInit {
const { dish, foods } = this.drawerRef.getContentComponent() as AddDishToIngredientComponent const { dish, foods } = this.drawerRef.getContentComponent() as AddDishToIngredientComponent
this.mealDishs.push({ this.mealDishs.push({
dishLabel: dish.dishLabel, label: dish.dishLabel,
day: this.day, day: this.day,
mealIndex: this.mealIndex, mealIndex: this.mealIndex,
meal: this.meals[this.mealIndex], meal: this.meals[this.mealIndex],

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

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

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

@ -4,7 +4,18 @@
<img *ngIf="logo" [attr.src]="'/api/icon/' + logo" /> <img *ngIf="logo" [attr.src]="'/api/icon/' + logo" />
</div> </div>
<h1 class="title">{{ orgName }}食谱营养报告</h1> <h1 class="title">{{ orgName }}食谱营养报告</h1>
<div class="time">{{ showTime }}</div> <div class="time">
<span *ngIf="weeks.length">
<select [(ngModel)]="day" class="select week" (ngModelChange)="dayChange()">
<option *ngFor="let w of weeks" [value]="w">
{{ weekdayMap[w] }}
</option>
</select>
</span>
<span>
{{ showTime }}
</span>
</div>
</div> </div>
<div class="mainbox flex flex-1"> <div class="mainbox flex flex-1">
<!-- <div class="boxnav mapc"> <!-- <div class="boxnav mapc">
@ -43,7 +54,11 @@
{{ item.name }} {{ item.name }}
</div> </div>
</td> </td>
<td>123</td> <td>
<nz-tag nzColor="blue" *ngFor="let lb of item['label'] ?? []">
{{ lb }}
</nz-tag>
</td>
<td *ngFor="let p of peoples"> <td *ngFor="let p of peoples">
<div class="td">{{ item.people[p] }}g</div> <div class="td">{{ item.people[p] }}g</div>
</td> </td>

6
projects/client/src/app/pages/data-vis/data-vis.component.less

@ -232,6 +232,12 @@ i {
border: none; border: none;
outline: none; outline: none;
&.week {
margin-right: 12px;
border-radius: 4px;
padding: 2px 12px;
}
option { option {
background-color: #fff; background-color: #fff;
color: #012059; color: #012059;

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

@ -1,7 +1,9 @@
import { AfterViewInit, Component, ElementRef, Renderer2, ViewChild } from '@angular/core' import { AfterViewInit, Component, ElementRef, HostListener, Renderer2, ViewChild } from '@angular/core'
import { weekdayMap } from '@cdk/ingredient/ingredient-form-basic/ingredient-form-basic.component'
import { ApiService } from '@cdk/services' import { ApiService } from '@cdk/services'
import { format } from 'date-fns' import { format } from 'date-fns'
import { Subject, Subscription, finalize, interval, takeUntil } from 'rxjs' import { NzMessageService } from 'ng-zorro-antd/message'
import { Subject, Subscription, filter, finalize, interval, takeUntil } from 'rxjs'
interface MenuDisplayItem { interface MenuDisplayItem {
name: string name: string
@ -16,7 +18,7 @@ const changeTime = 1000 * 60 * 3
styleUrls: ['./data-vis.component.less'], styleUrls: ['./data-vis.component.less'],
}) })
export class DataVisComponent implements AfterViewInit { export class DataVisComponent implements AfterViewInit {
constructor(private api: ApiService, private rd2: Renderer2) {} constructor(private api: ApiService, private rd2: Renderer2, private msg: NzMessageService) {}
@ViewChild('tableEl') tableEl!: ElementRef<HTMLElement> @ViewChild('tableEl') tableEl!: ElementRef<HTMLElement>
@ -34,6 +36,10 @@ export class DataVisComponent implements AfterViewInit {
peoples: string[] = [] peoples: string[] = []
weeks: number[] = []
day?: number
globalEnum = this.api.globalEnum globalEnum = this.api.globalEnum
analysisLoading = false analysisLoading = false
@ -54,10 +60,13 @@ export class DataVisComponent implements AfterViewInit {
lastTime: number = 0 lastTime: number = 0
weekdayMap = weekdayMap
scrollFlag = true
ngOnInit(): void { ngOnInit(): void {
this.api.getOrgInfo().subscribe((res) => { this.api.getOrgInfo().subscribe((res) => {
const account = this.api.account const account = this.api.account
this.orgName = account?.vender?.name ?? '' this.orgName = account?.vender?.name ?? ''
this.logo = account?.vender?.icon ?? '' this.logo = account?.vender?.icon ?? ''
}) })
@ -75,15 +84,25 @@ export class DataVisComponent implements AfterViewInit {
} }
this.currentMenu = this.menus[idx] this.currentMenu = this.menus[idx]
if (this.currentMenu) { if (this.currentMenu) {
this.getDataVisData(this.currentMenu.id)
this.lastTime = now.getTime() this.lastTime = now.getTime()
this.getDataVisData(this.currentMenu.id)
} }
} }
}) })
this.api.getCurrentDayDataVisList().subscribe((r) => { this.api.getCurrentWeekdays().subscribe((r) => {
if (Array.isArray(r.body)) { if (Array.isArray(r.body)) {
this.menus = r.body this.weeks = r.body
if (this.weeks.length > 0) {
const day = new Date().getDay()
const currentWeekDay = day === 0 ? 7 : day
if (this.weeks.includes(currentWeekDay)) {
this.day = currentWeekDay
this.getMenuListByDay()
} else {
this.msg.error('今天没有食谱')
}
}
} }
}) })
} }
@ -95,14 +114,34 @@ export class DataVisComponent implements AfterViewInit {
this.destroy$.complete() this.destroy$.complete()
} }
getMenuListByDay() {
if (!this.day) {
this.msg.error('请选择星期')
return
}
this.api.getMenusByDay(this.day).subscribe((res) => {
this.menus = res.body
//重置轮播时间
this.lastTime = new Date('2023-01-01').getTime()
})
}
dayChange() {
this.getMenuListByDay()
}
getDataVisData(id: number) { getDataVisData(id: number) {
this.analysis = null this.analysis = null
this.peoples = [] this.peoples = []
this.people = '' this.people = ''
this.dishs = {} this.dishs = {}
this.scroll = {} this.scroll = {}
if (!this.day) {
this.api.getMenuDataVis(id).subscribe((res) => { this.msg.error('请选择星期')
return
}
this.scrollFlag = false
this.api.getMenuDataVis(id, this.day).subscribe((res) => {
const dishs = res.body const dishs = res.body
if (Array.isArray(dishs)) { if (Array.isArray(dishs)) {
this.peoples = Object.keys(dishs?.[0]?.ingredient?.[0]?.value) this.peoples = Object.keys(dishs?.[0]?.ingredient?.[0]?.value)
@ -134,34 +173,51 @@ export class DataVisComponent implements AfterViewInit {
} }
}) })
setTimeout(() => { setTimeout(() => {
this.autoScroll(this.tableEl.nativeElement, '1') this.scrollFlag = true
}, 1000) this.autoScroll()
})
} }
}) })
} }
scrollSubs$?: Subscription scrollSubs$?: Subscription
autoScroll(el: HTMLElement, scroll: string) { @HostListener('window:resize')
onResize() {
this.autoScroll()
}
autoScroll() {
const el = this.tableEl.nativeElement
const scroll = '1'
this.scrollSubs$?.unsubscribe() this.scrollSubs$?.unsubscribe()
const child = el.children[0] const child = el.children[0]
if (!child) { if (!child) {
return return
} }
this.rd2.setStyle(child, 'transform', `translateY(0px)`)
const elHeight = el.clientHeight const elHeight = el.clientHeight
const childHeight = child.clientHeight const childHeight = child.clientHeight
console.log(childHeight, elHeight)
if (childHeight <= elHeight) { if (childHeight <= elHeight) {
return return
} }
this.scrollSubs$ = interval(60) this.scrollSubs$ = interval(60)
.pipe(takeUntil(this.destroy$)) .pipe(
.subscribe(() => { takeUntil(this.destroy$),
filter(() => this.scrollFlag),
)
.subscribe({
next: () => {
this.scroll[scroll] = (this.scroll[scroll] ?? 0) + 1 this.scroll[scroll] = (this.scroll[scroll] ?? 0) + 1
const paddingBottom = 100 const paddingBottom = 100
if (this.scroll[scroll] - paddingBottom > childHeight - el.clientHeight) { if (this.scroll[scroll] - paddingBottom > childHeight - el.clientHeight) {
this.scroll[scroll] = 0 this.scroll[scroll] = 0
} }
// console.log('this.scroll', this.scroll)
this.rd2.setStyle(child, 'transform', `translateY(-${this.scroll[scroll]}px)`) this.rd2.setStyle(child, 'transform', `translateY(-${this.scroll[scroll]}px)`)
},
}) })
} }

Loading…
Cancel
Save