Browse Source

图片逻辑修改

main
kkerwin 1 year ago
parent
commit
03588acf6f
  1. 8
      projects/admin/src/app/components/dish-form/dish-form.component.html
  2. 11
      projects/admin/src/app/components/dish-form/dish-form.component.ts
  3. 2
      projects/admin/src/app/pages/dish/dish.component.html
  4. 4
      projects/admin/src/app/pages/organization/organization-form/organization-form.component.html
  5. 15
      projects/admin/src/app/pages/organization/organization-form/organization-form.component.ts
  6. 2
      projects/cdk/src/dtos/enum.dto.ts
  7. 4
      projects/cdk/src/services/api.service.ts
  8. 8
      projects/client/src/app/components/dish-form/dish-form.component.html
  9. 13
      projects/client/src/app/components/dish-form/dish-form.component.ts
  10. 4
      projects/client/src/app/components/org-form/org-form.component.html
  11. 16
      projects/client/src/app/components/org-form/org-form.component.ts
  12. 4
      projects/client/src/app/pages/data-vis/data-vis.component.html
  13. 7
      projects/client/src/app/pages/data-vis/data-vis.component.ts
  14. 2
      projects/client/src/app/pages/dish/dish.component.html
  15. 2
      projects/client/src/app/pages/system/org-info/org-info.component.html
  16. 4
      proxy.conf.json

8
projects/admin/src/app/components/dish-form/dish-form.component.html

@ -50,8 +50,8 @@
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl">
<nz-select nzPlaceHolder="请选择烹饪方式" formControlName="poly" nzAllowClear> <nz-select nzPlaceHolder="请选择烹饪方式" formControlName="poly" nzAllowClear>
<nz-option *ngFor="let item of globalEnum.poly" [nzLabel]="item.key" <nz-option *ngFor="let item of globalEnum.poly" [nzLabel]="item.name"
[nzValue]="item.value"> [nzValue]="item.key">
</nz-option> </nz-option>
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
@ -74,8 +74,8 @@
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl">
<input type="hidden" formControlName="icon" /> <input type="hidden" formControlName="icon" />
<div class="mb-2" *ngIf="icon"> <div class="mb-2" *ngIf="iconPreview">
<img [src]="icon" class="h-20 w-20" /> <img [src]="iconPreview" class="h-20 w-20" />
</div> </div>
<button class="upload-btn " nz-button [nzLoading]="uploadLoading"> <button class="upload-btn " nz-button [nzLoading]="uploadLoading">
<i nz-icon nzType="upload"></i> <i nz-icon nzType="upload"></i>

11
projects/admin/src/app/components/dish-form/dish-form.component.ts

@ -46,6 +46,8 @@ export class DishFormComponent {
addFoodVisible = false; addFoodVisible = false;
iconPreview = "";
get food(): FormArray { get food(): FormArray {
return this.formGroup.get("ingredient") as FormArray; return this.formGroup.get("ingredient") as FormArray;
} }
@ -119,6 +121,7 @@ export class DishFormComponent {
this.foodSelected.push(f.key); this.foodSelected.push(f.key);
} }
}); });
this.iconPreview = "/icon/" + this.data["icon"];
this.formGroup.patchValue({ this.formGroup.patchValue({
...this.data, ...this.data,
vendors: [this.data.vender], vendors: [this.data.vender],
@ -226,8 +229,14 @@ export class DishFormComponent {
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = () => { fileReader.onload = () => {
const base64 = fileReader.result as string; const base64 = fileReader.result as string;
this.formGroup.get("icon")?.setValue(base64); this.iconPreview = base64;
// this.formGroup.get("icon")?.setValue(base64);
}; };
fileReader.readAsDataURL(file); fileReader.readAsDataURL(file);
const formdata = new FormData();
formdata.append("file", file);
this.api.upload(formdata).subscribe((res) => {
this.formGroup.get("icon")?.setValue(res.body);
});
} }
} }

2
projects/admin/src/app/pages/dish/dish.component.html

@ -54,7 +54,7 @@
<ng-container *ngSwitchCase="'icon'"> <ng-container *ngSwitchCase="'icon'">
<div class="dish-img overflow-auto" <div class="dish-img overflow-auto"
*ngIf="data" *ngIf="data"
[ngStyle]="{'background-image':'url(' + data + ')'}"> [ngStyle]="{'background-image':'url(/icon/' + data + ')'}">
</div> </div>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'vender'"> <ng-container *ngSwitchCase="'vender'">

4
projects/admin/src/app/pages/organization/organization-form/organization-form.component.html

@ -27,8 +27,8 @@
单位Logo 单位Logo
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12"> <nz-form-control [nzErrorTip]="formControlErrorTpl" nzSpan="12">
<div class="mb-2" *ngIf="icon"> <div class="mb-2" *ngIf="iconPreview">
<img [src]="icon" class="h-20 w-20" /> <img [src]="iconPreview" class="h-20 w-20" />
</div> </div>
<button class="vlock upload-btn " nz-button [nzLoading]="uploadLoading"> <button class="vlock upload-btn " nz-button [nzLoading]="uploadLoading">
<i nz-icon nzType="upload"></i> <i nz-icon nzType="upload"></i>

15
projects/admin/src/app/pages/organization/organization-form/organization-form.component.ts

@ -41,6 +41,8 @@ export class OrganizationFormComponent {
globalEnum = this.api.globalEnum; globalEnum = this.api.globalEnum;
iconPreview = "";
get icon() { get icon() {
return this.formGroup.get("icon")?.value; return this.formGroup.get("icon")?.value;
} }
@ -60,6 +62,9 @@ export class OrganizationFormComponent {
email: this.fb.control("", []), email: this.fb.control("", []),
}); });
this.formGroup.patchValue(this.state); this.formGroup.patchValue(this.state);
if (this.state["icon"]) {
this.iconPreview = "/icon/" + this.state["icon"];
}
} }
async onSubmit() { async onSubmit() {
@ -93,10 +98,14 @@ export class OrganizationFormComponent {
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = () => { fileReader.onload = () => {
const base64 = fileReader.result as string; const base64 = fileReader.result as string;
this.formGroup.patchValue({ this.iconPreview = base64;
icon: base64, // this.formGroup.get("icon")?.setValue(base64);
});
}; };
fileReader.readAsDataURL(file); fileReader.readAsDataURL(file);
const formdata = new FormData();
formdata.append("file", file);
this.api.upload(formdata).subscribe((res) => {
this.formGroup.get("icon")?.setValue(res.body);
});
} }
} }

2
projects/cdk/src/dtos/enum.dto.ts

@ -7,7 +7,7 @@ export type GlobalEnum = {
venderType: CategoryDTO[]; venderType: CategoryDTO[];
mealType: OptionItemInterface[]; mealType: OptionItemInterface[];
menuStatus: OptionItemInterface[]; menuStatus: OptionItemInterface[];
poly: MarkDTO[]; poly: { key: string; name: string }[];
}; };
export type CategoryDTO = { export type CategoryDTO = {

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

@ -49,6 +49,10 @@ export class ApiService {
} }
} }
upload(data: FormData) {
return this.http.put<ResponseType>("/api/icon", data);
}
private _formatEnum(v: CategoryDTO[]): OptionItemInterface[] { private _formatEnum(v: CategoryDTO[]): OptionItemInterface[] {
return v.map((i) => ({ label: i.key, value: i.value })); return v.map((i) => ({ label: i.key, value: i.value }));
} }

8
projects/client/src/app/components/dish-form/dish-form.component.html

@ -26,8 +26,8 @@
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl">
<nz-select nzPlaceHolder="请选择烹饪方式" formControlName="poly" nzAllowClear> <nz-select nzPlaceHolder="请选择烹饪方式" formControlName="poly" nzAllowClear>
<nz-option *ngFor="let item of globalEnum.poly" [nzLabel]="item.key" <nz-option *ngFor="let item of globalEnum.poly" [nzLabel]="item.name"
[nzValue]="item.value"> [nzValue]="item.key">
</nz-option> </nz-option>
</nz-select> </nz-select>
</nz-form-control> </nz-form-control>
@ -47,8 +47,8 @@
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl">
<input type="hidden" formControlName="icon" /> <input type="hidden" formControlName="icon" />
<div class="mb-2" *ngIf="icon"> <div class="mb-2" *ngIf="iconPreview">
<img [src]="icon" class="h-20 w-20" /> <img [src]="iconPreview" class="h-20 w-20" />
</div> </div>
<button class="upload-btn " nz-button [nzLoading]="uploadLoading"> <button class="upload-btn " nz-button [nzLoading]="uploadLoading">
<i nz-icon nzType="upload"></i> <i nz-icon nzType="upload"></i>

13
projects/client/src/app/components/dish-form/dish-form.component.ts

@ -46,6 +46,8 @@ export class DishFormComponent {
addFoodVisible = false; addFoodVisible = false;
iconPreview = "";
get food(): FormArray { get food(): FormArray {
return this.formGroup.get("ingredient") as FormArray; return this.formGroup.get("ingredient") as FormArray;
} }
@ -122,6 +124,9 @@ export class DishFormComponent {
...this.data, ...this.data,
mark: this.data.marks, mark: this.data.marks,
}); });
if (this.data["icon"]) {
this.iconPreview = "/icon/" + this.data["icon"];
}
} }
} }
@ -224,8 +229,14 @@ export class DishFormComponent {
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = () => { fileReader.onload = () => {
const base64 = fileReader.result as string; const base64 = fileReader.result as string;
this.formGroup.get("icon")?.setValue(base64); this.iconPreview = base64;
// this.formGroup.get("icon")?.setValue(base64);
}; };
fileReader.readAsDataURL(file); fileReader.readAsDataURL(file);
const formdata = new FormData();
formdata.append("file", file);
this.api.upload(formdata).subscribe((res) => {
this.formGroup.get("icon")?.setValue(res.body);
});
} }
} }

4
projects/client/src/app/components/org-form/org-form.component.html

@ -14,8 +14,8 @@
单位Logo 单位Logo
</nz-form-label> </nz-form-label>
<nz-form-control [nzErrorTip]="formControlErrorTpl"> <nz-form-control [nzErrorTip]="formControlErrorTpl">
<div class="mb-2" *ngIf="icon"> <div class="mb-2" *ngIf="iconPreview">
<img [src]="icon" class="h-20 w-20" /> <img [src]="iconPreview" class="h-20 w-20" />
</div> </div>
<button class="vlock upload-btn " nz-button [nzLoading]="uploadLoading"> <button class="vlock upload-btn " nz-button [nzLoading]="uploadLoading">
<i nz-icon nzType="upload"></i> <i nz-icon nzType="upload"></i>

16
projects/client/src/app/components/org-form/org-form.component.ts

@ -30,12 +30,13 @@ export class OrgFormComponent {
uploadLoading = false; uploadLoading = false;
iconPreview = "";
get icon() { get icon() {
return this.formGroup.get("icon")?.value; return this.formGroup.get("icon")?.value;
} }
ngOnInit(): void { ngOnInit(): void {
console.log("this.state", this.state);
this.formGroup = this.fb.group({ this.formGroup = this.fb.group({
id: this.fb.control(""), id: this.fb.control(""),
name: this.fb.control("", [FormValidators.required("单位名称不能为空")]), name: this.fb.control("", [FormValidators.required("单位名称不能为空")]),
@ -46,6 +47,9 @@ export class OrgFormComponent {
email: this.fb.control("", []), email: this.fb.control("", []),
}); });
this.formGroup.patchValue(this.state); this.formGroup.patchValue(this.state);
if (this.state["icon"]) {
this.iconPreview = "/icon/" + this.state["icon"];
}
} }
async onSubmit() { async onSubmit() {
@ -79,10 +83,14 @@ export class OrgFormComponent {
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = () => { fileReader.onload = () => {
const base64 = fileReader.result as string; const base64 = fileReader.result as string;
this.formGroup.patchValue({ this.iconPreview = base64;
icon: base64, // this.formGroup.get("icon")?.setValue(base64);
});
}; };
fileReader.readAsDataURL(file); fileReader.readAsDataURL(file);
const formdata = new FormData();
formdata.append("file", file);
this.api.upload(formdata).subscribe((res) => {
this.formGroup.get("icon")?.setValue(res.body);
});
} }
} }

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

@ -1,7 +1,7 @@
<div class="body flex flex-col"> <div class="body flex flex-col">
<div class="head clearfix"> <div class="head clearfix">
<div class="logo"> <div class="logo">
<img src="/assets/images/jl-logo.png" /> <img *ngIf="logo" [attr.src]="'/icon/' + logo" />
</div> </div>
<h1 class="title">{{orgName}}食谱营养报告</h1> <h1 class="title">{{orgName}}食谱营养报告</h1>
<div class="time">{{showTime}}</div> <div class="time">{{showTime}}</div>
@ -65,7 +65,7 @@
<div class="boxnav"> <div class="boxnav">
<div class="p-4"> <div class="p-4">
<div nz-row [nzGutter]="[12,12]"> <div nz-row [nzGutter]="[12,12]">
<div nz-col nzSpan="6" *ngFor="let type of analysis.types | keyvalue"> <div nz-col nzSpan="6" *ngFor="let type of analysis?.types | keyvalue">
{{type.key}} : <b>{{type.value}}</b> {{type.key}} : <b>{{type.value}}</b>
</div> </div>
</div> </div>

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

@ -39,8 +39,13 @@ export class DataVisComponent implements AfterViewInit {
menuId!: number; menuId!: number;
logo = "";
ngOnInit(): void { ngOnInit(): void {
this.orgName = this.api.account?.vender?.name ?? ""; const account = this.api.account;
this.orgName = account?.vender?.name ?? "";
this.logo = account?.vender?.icon ?? "";
interval(1000) interval(1000)
.pipe(takeUntil(this.destroy$)) .pipe(takeUntil(this.destroy$))
.subscribe(() => { .subscribe(() => {

2
projects/client/src/app/pages/dish/dish.component.html

@ -60,7 +60,7 @@
<ng-container *ngSwitchCase="'icon'"> <ng-container *ngSwitchCase="'icon'">
<div class="dish-img overflow-auto" <div class="dish-img overflow-auto"
*ngIf="data" *ngIf="data"
[ngStyle]="{'background-image':'url(' + data + ')'}"> [ngStyle]="{'background-image':'url(/icon/' + data + ')'}">
</div> </div>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'vender'"> <ng-container *ngSwitchCase="'vender'">

2
projects/client/src/app/pages/system/org-info/org-info.component.html

@ -25,7 +25,7 @@
</nz-form-label> </nz-form-label>
<nz-form-control> <nz-form-control>
<div class="w-20 h-20" *ngIf="org.icon"> <div class="w-20 h-20" *ngIf="org.icon">
<img [src]="org.icon" class=" w-full h-full" /> <img [src]="'/icon/' + org.icon" class=" w-full h-full" />
</div> </div>
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>

4
proxy.conf.json

@ -2,5 +2,9 @@
"/api": { "/api": {
"target": "http://47.109.27.8:9527", "target": "http://47.109.27.8:9527",
"secure": false "secure": false
},
"/icon": {
"target": "http://47.109.27.8:9527",
"secure": false
} }
} }

Loading…
Cancel
Save