From 5eee0b4fce94bbeb3d3b4417e0597fd5f001472d Mon Sep 17 00:00:00 2001 From: kely Date: Tue, 12 Dec 2023 09:59:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=96=E6=B2=B9=E7=9B=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=20=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projects/cdk/src/services/api.service.ts | 16 ++ projects/client/src/app/app-routing.module.ts | 148 +++++++++------- projects/client/src/app/app.module.ts | 46 ++--- projects/client/src/app/pages/index.ts | 25 +-- .../salt-oil-sugar.component.html | 147 ++++++++++++++++ .../salt-oil-sugar.component.less | 0 .../salt-oil-sugar.component.ts | 163 ++++++++++++++++++ 7 files changed, 444 insertions(+), 101 deletions(-) create mode 100644 projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.html create mode 100644 projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.less create mode 100644 projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.ts diff --git a/projects/cdk/src/services/api.service.ts b/projects/cdk/src/services/api.service.ts index 950e80f..ca89299 100644 --- a/projects/cdk/src/services/api.service.ts +++ b/projects/cdk/src/services/api.service.ts @@ -595,4 +595,20 @@ export class ApiService { // return this.http.get(`/api/menu/dish`); return this.http.get(`/api/menu/display?menuId=${menuId}&day=${day}`) } + + getSaltOilSugarPage(p: {}, q: {}) { + const params = Utils.objectStringify({ ...p, ...q }) + return this.http.get>(`/api/menu?${params}`) + } + + saveSaltOilSugar(v: AnyObject) { + const body = Utils.objectToFormData(v) + const method = v['id'] ? 'post' : 'put' + return this.http[method]('/api/dish', body) + } + + deleteSaltOilSugar(id: string | number) { + const params = Utils.objectToFormData({ id }) + return this.http.delete(`/api/menu`, { body: params }) + } } diff --git a/projects/client/src/app/app-routing.module.ts b/projects/client/src/app/app-routing.module.ts index 92217b6..a7572a3 100644 --- a/projects/client/src/app/app-routing.module.ts +++ b/projects/client/src/app/app-routing.module.ts @@ -1,5 +1,5 @@ -import { NgModule } from "@angular/core"; -import { RouterModule, Routes } from "@angular/router"; +import { NgModule } from '@angular/core' +import { RouterModule, Routes } from '@angular/router' import { DashboardComponent, DataVisComponent, @@ -13,180 +13,194 @@ import { IngredientListComponent, IngredientPreviewPageComponent, IngredientReleaseComponent, -} from "./pages"; -import { AppLayoutComponent } from "./components"; -import { authGuard } from "./services/auth.guard"; -import { PermissionLoadGuard } from "./services/permisson.guard"; -import { ForbiddenComponent, NotfoundComponent } from "@cdk/shared/components"; -import { ngxPermissionsGuard } from "ngx-permissions"; + SaltOilSugarComponent, +} from './pages' +import { AppLayoutComponent } from './components' +import { authGuard } from './services/auth.guard' +import { PermissionLoadGuard } from './services/permisson.guard' +import { ForbiddenComponent, NotfoundComponent } from '@cdk/shared/components' +import { ngxPermissionsGuard } from 'ngx-permissions' const routes: Routes = [ - { path: "login", component: LoginComponent }, - { path: "forbidden", component: ForbiddenComponent }, + { path: 'login', component: LoginComponent }, + { path: 'forbidden', component: ForbiddenComponent }, { - path: "", + path: '', component: AppLayoutComponent, canActivate: [authGuard, PermissionLoadGuard], children: [ { - path: "", - pathMatch: "full", - redirectTo: "dashboard", + path: '', + pathMatch: 'full', + redirectTo: 'dashboard', }, { - path: "dashboard", - title: "使用流程", + path: 'dashboard', + title: '使用流程', component: DashboardComponent, canActivate: [ngxPermissionsGuard], data: { permissions: { - only: ["18"], - redirectTo: "/forbidden", + only: ['18'], + redirectTo: '/forbidden', }, }, }, { - path: "meal-setting", + path: 'salt-oil-sugar', + component: SaltOilSugarComponent, + title: '盐油糖管理', + canActivate: [ngxPermissionsGuard], + data: { + permissions: { + only: ['18'], + redirectTo: '/forbidden', + }, + }, + }, + { + path: 'meal-setting', component: MealSettingComponent, canActivate: [ngxPermissionsGuard], data: { permissions: { - only: ["21", "22"], - redirectTo: "/forbidden", + only: ['21', '22'], + redirectTo: '/forbidden', }, }, }, { - path: "data-vis", + path: 'data-vis', component: DataVisComponent, canActivate: [ngxPermissionsGuard], data: { permissions: { - only: ["19", "20"], - redirectTo: "/forbidden", + only: ['19', '20'], + redirectTo: '/forbidden', }, }, }, { - path: "food", + path: 'food', component: FoodComponent, canActivate: [ngxPermissionsGuard], - title: "食材管理", + title: '食材管理', data: { permissions: { - only: ["23", "24"], - redirectTo: "/forbidden", + only: ['23', '24'], + redirectTo: '/forbidden', }, }, }, { - path: "dish", + path: 'dish', component: DishComponent, canActivate: [ngxPermissionsGuard], - title: "菜品管理", + title: '菜品管理', data: { permissions: { - only: ["25", "26"], - redirectTo: "/forbidden", + only: ['25', '26'], + redirectTo: '/forbidden', }, }, }, { - path: "ingredient", - title: "食谱管理", + path: 'ingredient', + title: '食谱管理', canActivate: [ngxPermissionsGuard], data: { permissions: { - only: ["27", "28", "29", "30", "31"], - redirectTo: "/forbidden", + only: ['27', '28', '29', '30', '31'], + redirectTo: '/forbidden', }, }, children: [ { - path: "", - pathMatch: "full", - redirectTo: "item", + path: '', + pathMatch: 'full', + redirectTo: 'item', }, { - path: "item", - title: "食谱库", + path: 'item', + title: '食谱库', canActivate: [ngxPermissionsGuard], data: { permissions: { - only: ["27", "28"], - redirectTo: "/forbidden", + only: ['27', '28'], + redirectTo: '/forbidden', }, }, children: [ { - path: "", - pathMatch: "full", - redirectTo: "list", + path: '', + pathMatch: 'full', + redirectTo: 'list', }, { - path: "list", + path: 'list', component: IngredientListComponent, }, { - path: "form/:id", + path: 'form/:id', component: IngredientFormComponent, }, ], }, { - path: "preview", - title: "食谱预览", + path: 'preview', + title: '食谱预览', component: IngredientPreviewPageComponent, }, { - path: "release", - title: "食谱发布计划", + path: 'release', + title: '食谱发布计划', canActivate: [ngxPermissionsGuard], component: IngredientReleaseComponent, data: { permissions: { - only: ["30", "31"], - redirectTo: "/forbidden", + only: ['30', '31'], + redirectTo: '/forbidden', }, }, }, ], }, + { - path: "system", + path: 'system', canActivate: [ngxPermissionsGuard], data: { permissions: { - only: ["33", "34", "35", "36", "37"], - redirectTo: "/forbidden", + only: ['33', '34', '35', '36', '37'], + redirectTo: '/forbidden', }, }, children: [ { - path: "org", + path: 'org', component: OrgInfoComponent, canActivate: [ngxPermissionsGuard], - title: "单位信息设置", + title: '单位信息设置', data: { permissions: { - only: ["33", "34"], - redirectTo: "/forbidden", + only: ['33', '34'], + redirectTo: '/forbidden', }, }, }, { - path: "user", + path: 'user', component: ClientUserManageComponent, canActivate: [ngxPermissionsGuard], - title: "用户管理", + title: '用户管理', data: { permissions: { - only: ["35", "36", "37"], - redirectTo: "/forbidden", + only: ['35', '36', '37'], + redirectTo: '/forbidden', }, }, }, @@ -196,10 +210,10 @@ const routes: Routes = [ }, { - path: "**", + path: '**', component: NotfoundComponent, }, -]; +] @NgModule({ imports: [RouterModule.forRoot(routes)], diff --git a/projects/client/src/app/app.module.ts b/projects/client/src/app/app.module.ts index 9bcd91c..03b6f75 100644 --- a/projects/client/src/app/app.module.ts +++ b/projects/client/src/app/app.module.ts @@ -1,25 +1,25 @@ -import { NgModule } from "@angular/core"; -import { BrowserModule } from "@angular/platform-browser"; +import { NgModule } from '@angular/core' +import { BrowserModule } from '@angular/platform-browser' -import { NZ_I18N } from "ng-zorro-antd/i18n"; -import { zh_CN } from "ng-zorro-antd/i18n"; -import { registerLocaleData } from "@angular/common"; -import zh from "@angular/common/locales/zh"; -import { FormsModule } from "@angular/forms"; -import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http"; -import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { NZ_I18N } from 'ng-zorro-antd/i18n' +import { zh_CN } from 'ng-zorro-antd/i18n' +import { registerLocaleData } from '@angular/common' +import zh from '@angular/common/locales/zh' +import { FormsModule } from '@angular/forms' +import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' -import { AppRoutingModule } from "./app-routing.module"; -import { AppComponent } from "./app.component"; -import { IconsProviderModule, PROJECT_NAME, TableListModule } from "@cdk/public-api"; -import { SharedModule } from "@cdk/shared/shared.module"; +import { AppRoutingModule } from './app-routing.module' +import { AppComponent } from './app.component' +import { IconsProviderModule, PROJECT_NAME, TableListModule } from '@cdk/public-api' +import { SharedModule } from '@cdk/shared/shared.module' import { AppLayoutComponent, OrgFormComponent, UserListComponent, RolePermissionComponent, DishFormComponent, -} from "./components"; +} from './components' import { DashboardComponent, LoginComponent, @@ -33,14 +33,15 @@ import { IngredientListComponent, IngredientPreviewPageComponent, IngredientReleaseComponent, -} from "./pages"; -import { HTTPInterceptor } from "./services/http.interceptor"; -import { IngredientModule } from "@cdk/ingredient/ingredient.module"; -import { NgxPermissionsModule } from "ngx-permissions"; -import { TemplatePageTitleStrategy } from "./services/title.service"; -import { TitleStrategy } from "@angular/router"; + SaltOilSugarComponent, +} from './pages' +import { HTTPInterceptor } from './services/http.interceptor' +import { IngredientModule } from '@cdk/ingredient/ingredient.module' +import { NgxPermissionsModule } from 'ngx-permissions' +import { TemplatePageTitleStrategy } from './services/title.service' +import { TitleStrategy } from '@angular/router' -registerLocaleData(zh); +registerLocaleData(zh) @NgModule({ declarations: [ @@ -63,6 +64,7 @@ registerLocaleData(zh); IngredientListComponent, IngredientPreviewPageComponent, IngredientReleaseComponent, + SaltOilSugarComponent, ], imports: [ BrowserModule, @@ -78,7 +80,7 @@ registerLocaleData(zh); NgxPermissionsModule.forRoot(), ], providers: [ - { provide: PROJECT_NAME, useValue: "client" }, + { provide: PROJECT_NAME, useValue: 'client' }, { provide: NZ_I18N, useValue: zh_CN }, { provide: HTTP_INTERCEPTORS, useClass: HTTPInterceptor, multi: true }, { provide: TitleStrategy, useClass: TemplatePageTitleStrategy }, diff --git a/projects/client/src/app/pages/index.ts b/projects/client/src/app/pages/index.ts index db7acb9..07bebbf 100644 --- a/projects/client/src/app/pages/index.ts +++ b/projects/client/src/app/pages/index.ts @@ -1,14 +1,15 @@ -export * from "./dashboard/dashboard.component"; -export * from "./login/login.component"; -export * from "./meal-setting/meal-setting.component"; -export * from "./data-vis/data-vis.component"; -export * from "./food/food.component"; -export * from "./dish/dish.component"; +export * from './dashboard/dashboard.component' +export * from './login/login.component' +export * from './meal-setting/meal-setting.component' +export * from './data-vis/data-vis.component' +export * from './food/food.component' +export * from './dish/dish.component' -export * from "./system/org-info/org-info.component"; -export * from "./system/user-manage/user-manage.component"; +export * from './system/org-info/org-info.component' +export * from './system/user-manage/user-manage.component' -export * from "./ingredients/ingredient-list/ingredient-list.component"; -export * from "./ingredients/ingredient-form/ingredient-form.component"; -export * from "./ingredients/ingredient-preview-page/ingredient-preview-page.component"; -export * from "./ingredients/ingredient-release/ingredient-release.component"; +export * from './ingredients/ingredient-list/ingredient-list.component' +export * from './ingredients/ingredient-form/ingredient-form.component' +export * from './ingredients/ingredient-preview-page/ingredient-preview-page.component' +export * from './ingredients/ingredient-release/ingredient-release.component' +export * from './salt-oil-sugar/salt-oil-sugar.component' diff --git a/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.html b/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.html new file mode 100644 index 0000000..44e7b23 --- /dev/null +++ b/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.html @@ -0,0 +1,147 @@ + + + + + + + 新增记录 + + + +
+ + + + + + + + + + + + + {{ data | date : 'yyyy-MM-dd HH:mm:ss' }} + + + {{ tableOrg[data] ? tableOrg[data].name : '-' }} + + + + {{ item }} + + 周{{ data }} + + {{ statusTextMap[data] }} + + +
+ + 全年 + + + + {{ item }} + + +
+
+ + {{ data }} + +
+
+
+
+
+
+ + +
+ + 选择周 + + + + + + 供餐天数 + + + + + + + + + + + + + + 糖用量(周) + + + + + + + + 油用量(周) + + + + + + + + 盐用量(周) + + + + + + + +
+
+ + + + + + +
+
+ +
+
+ +
+
+
+
diff --git a/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.less b/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.less new file mode 100644 index 0000000..e69de29 diff --git a/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.ts b/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.ts new file mode 100644 index 0000000..eeeb149 --- /dev/null +++ b/projects/client/src/app/pages/salt-oil-sugar/salt-oil-sugar.component.ts @@ -0,0 +1,163 @@ +import { Component, ElementRef, OnInit, TemplateRef, ViewChild } from '@angular/core' +import { FormControl, FormGroup } from '@angular/forms' +import { NzDrawerRef, NzDrawerService } from 'ng-zorro-antd/drawer' +import { AnyObject, FormValidators, OrgDTO, TableListOption, Utils } from '@cdk/public-api' +import { ApiService } from '@cdk/services' +import { NzModalService } from 'ng-zorro-antd/modal' +import { lastValueFrom, tap } from 'rxjs' +import { NzMessageService } from 'ng-zorro-antd/message' +import { Router } from '@angular/router' +import { format, getWeek } from 'date-fns' +import { EChartsType, init } from 'echarts' + +@Component({ + selector: 'app-salt-oil-sugar', + templateUrl: './salt-oil-sugar.component.html', + styleUrls: ['./salt-oil-sugar.component.less'], +}) +export class SaltOilSugarComponent { + constructor(private api: ApiService, private modal: NzModalService, private msg: NzMessageService) {} + + globalEnum = this.api.globalEnum + + statusTextMap: Record = {} + + @ViewChild('formTpl') formTpl!: TemplateRef<{}> + + @ViewChild('trendTpl') trendTpl!: TemplateRef<{}> + + @ViewChild('trendElementTpl') trendElementTpl!: ElementRef + + sugerRef?: EChartsType + + public tableList = new TableListOption(this.fetchData.bind(this), { + frontPagination: false, + }) + + public queryForm = new FormGroup({ + date: new FormControl([]), + }) + + public recordForm = new FormGroup({ + week: new FormControl('', [FormValidators.required('请选择周')]), + day: new FormControl(5, [FormValidators.required('请选择供餐天数')]), + sugar: new FormControl('', []), + oil: new FormControl('', []), + salt: new FormControl('', []), + }) + + startTime: Date | null = null + + tableOrg: { [k: number]: OrgDTO } = {} + + ngOnInit(): void { + this.statusTextMap = this.globalEnum.menuStatus.reduce((a, c) => { + return { + ...a, + [String(c.label)]: c.value, + } + }, {} as Record) + this.initTableList() + } + + initTableList() { + this.tableList.scroll = { x: '900px' } + this.tableList = this.tableList.setColumns([ + { key: 'name', title: '周' }, + + { key: 'meals', title: '日期' }, + { key: 'month', title: '供餐天数' }, + { key: 'day', title: '糖用量(周)/日均用量' }, + { key: 'status', title: '油用量(周)/日均用量' }, + { key: 'modify', title: '盐用量(周)/日均用量' }, + ]) + + this.tableList = this.tableList.setOptions([ + { + title: '编辑', + premissions: [], + onClick: this.openModal.bind(this), + }, + + { + title: '删除', + premissions: [], + onClick: this.deleteItem.bind(this), + }, + ]) + } + + fetchData(query: AnyObject, pager: AnyObject) { + return this.api.getSaltOilSugarPage(pager, query).pipe() + } + + openModal(record?: any) { + this.modal.create({ + nzTitle: record ? '编辑记录' : '新增记录', + nzContent: this.formTpl, + nzOnOk: async () => { + if (Utils.validateFormGroup(this.recordForm)) { + const res = await lastValueFrom( + this.api.saveSaltOilSugar({ + ...this.recordForm.value, + week: format(this.recordForm.value.week as unknown as Date, 'yyyy-ww'), + }), + ) + this.msg.success(res.desc) + this.tableList.run() + } + + return false + }, + }) + } + + deleteItem({ id }: any) { + this.modal.confirm({ + nzTitle: '警告', + nzContent: `是否要删除该记录?`, + nzOkDanger: true, + nzOnOk: async () => { + const res = await lastValueFrom(this.api.deleteSaltOilSugar(id)) + this.msg.success(res.desc) + this.tableList.run() + }, + }) + } + + trend() { + this.modal.create({ + nzTitle: '糖油盐趋势', + nzContent: this.trendTpl, + nzWidth: 800, + nzFooter: null, + }) + } + + saveToImage() {} + + genEchart() { + // const xAxis: string[] = Object.keys(this.suger['oil']).map((i: any) => weekdayMap[i]) + // const series: any[] = [] + // Object.entries(this.suger).forEach(([k, v]) => { + // if (k !== 'crow') { + // series.push({ + // type: 'line', + // name: sugerMap.get(k), + // data: Object.values(v as any), + // }) + // } + // }) + // const option = { + // legend: {}, + // tooltip: { trigger: 'axis' }, + // xAxis: { type: 'category', data: xAxis }, + // yAxis: {}, + // series, + // } + // if (!this.sugerRef) { + // this.sugerRef = init(this.trendElementTpl.nativeElement) + // } + // this.sugerRef.setOption(option) + } +}