iT邦幫忙

2024 iThome 鐵人賽

DAY 26
1
佛心分享-SideProject30

收納規劃APP系列 第 26

Day26:家具依API展示

  • 分享至 

  • xImage
  •  

本來以為自己會順順的接上API,但是因為不是一氣呵成的寫,前後端模型有幾個欄位沒對應到,害我卡了一下,但還好追蹤問題跟調整問題還算快。

以下是動態生成的家具資料

https://ithelp.ithome.com.tw/upload/images/20241006/20162350XepnMawdxs.png

import { Component, ElementRef, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd/modal';
import { CRUD, EditType } from 'src/app/feature/enum/furniture.enum';
import { Furniture } from 'src/app/feature/interface/furniture.interface';
import { FurnitureModalComponent } from 'src/app/feature/modal/furniture-modal/furniture-modal.component';
import { StorageModalComponent } from 'src/app/feature/modal/storage-modal/storage-modal.component';
import { StorageService } from './service/storage.service';

@Component({
  selector: 'app-day18',
  templateUrl: './day18.component.html',
  styleUrls: ['./day18.component.scss']
})
export class Day18Component implements OnInit {

  @ViewChild('floorPlan') floorPlanRef!: ElementRef<SVGSVGElement>;
  @ViewChild('popover') popover!: ElementRef;
  editType: EditType = EditType.furniture;
  EditType = EditType;
  isPopoverVisible = false;
  isStorage = false;
  furnitureSetting!: Furniture;
  popoverX = 0;
  popoverY = 0;

  furnitureList: Furniture[] = [ ];

  constructor(
    private modal: NzModalService,
    private viewContainerRef: ViewContainerRef,
    private storageService: StorageService,
  ) {
  }

  private sortFurnitureByIndex() {
    this.furnitureList.sort((a, b) => a.zIndex - b.zIndex);
  }

  ngOnInit(): void {
    this.storageService.getFurnitureList('66fe483f2e043d4fa5a2de9c')
      .subscribe(res => {
        if (res) {
          this.furnitureList = res;
          console.log('furnitureList', this.furnitureList);
          this.sortFurnitureByIndex();
        }
      });
  }

  onDoubleClick(item: Furniture, event: MouseEvent): void {
    this.isPopoverVisible = true;
    this.isStorage = item.isStorage;
    this.popoverX = event.clientX;
    this.popoverY = event.clientY;
    this.furnitureSetting = item;
  }

  onPopoverClose() {
    this.isPopoverVisible = false;
  }

  onPopoverButtonClick(editType: EditType,) {
    switch (editType) {
      case EditType.furniture:
        this.isPopoverVisible = false;
        this.furnitureModal(this.furnitureSetting);

        break;
      case EditType.storage:
        this.isPopoverVisible = false;
        this.storageModal(this.furnitureSetting)
        break;

      default:
        break;
    }
  }

  updateFurniturePosition($event: Furniture) {

  }
  updateFurnitureRotation($event: Furniture) {

  }
  updateFurnitureSize($event: Furniture) {

  }
  private furnitureModal(item: Furniture): void {
    console.log('furnitureModal', item);
    const modal = this.modal.create({
      // nzTitle: tplTitle,
      nzContent: FurnitureModalComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzFooter: null,
      nzMaskClosable: false,
      nzClosable: false,
      nzData: {
        furniture: item,
        action: CRUD.update
      },
      nzOnOk: () => console.log('Click ok')
    });
  }

  private storageModal(item: Furniture): void {
    console.log('storageModal', item);
    this.modal.create({
      // nzTitle: tplTitle,
      nzContent: StorageModalComponent,
      nzFooter: null,
      nzWidth: '95vw',
      // nzMaskClosable: false,
      // nzClosable: false,
      // nzComponentParams: {
      //   // value: 'Template Context'
      // },
      nzOnOk: () => console.log('Click ok')
    });
  }
}


上一篇
Day25:Loading
下一篇
Day27:家具的修改
系列文
收納規劃APP32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言