import { Button } from 'antd' import { useEffect, useState } from 'react' import { metas, labels, images } from './board' import { BoardType, BoardTypeDesc } from 'api' import { SelectMap, SelectFuse } from './modal' import shapes from './shapes' import style from './style.module.scss' import type { MetaShapeType, Board } from './board' import type { RefObject } from 'react' import type { Tagging } from 'api' type SliderProps = { board: RefObject type: BoardType caseId: number } export const DfSlider = ({ board, type, caseId }: SliderProps) => { const [selectMode, setSelectMode] = useState(false) const [currentShape, setCurrentShape] = useState() const getEle = (shapeType: MetaShapeType) => { const Shape = shapes[shapeType] return (
setCurrentShape(shapeType)} >

{metas[shapeType].desc}

) } const setBoardImage = async (blob: Blob | null, taggings: Tagging[]) => { if (blob) { const url = URL.createObjectURL(blob) board.current?.setImage(url) } } const SelectImage = type === BoardType.map ? SelectMap : SelectFuse const renderSelect = selectMode && setSelectMode(false)} onSave={setBoardImage} /> useEffect(() => { const boardRef = board.current if (currentShape && boardRef) { console.log('read add', currentShape) const cleaup = boardRef.readyAddShape( currentShape, () => setCurrentShape(void 0) ) const keyupHandler = (ev: KeyboardEvent) => { if (ev.key === 'Escape') { setCurrentShape(void 0) cleaup() } } document.documentElement.addEventListener('keyup', keyupHandler) return () => { document.documentElement.removeEventListener('keyup', keyupHandler) } } }, [currentShape, board]) return (
{ renderSelect }

户型图

标注

{ labels.map(getEle) }

图例

{ images.map(getEle) }
) } export default DfSlider