|
@@ -1,39 +1,23 @@
|
|
|
import { Layout } from 'antd'
|
|
|
-import { useRef, forwardRef, useImperativeHandle, memo, useCallback, useEffect } from 'react'
|
|
|
+import { useRef, forwardRef, useImperativeHandle, memo, useCallback, useEffect, useState } from 'react'
|
|
|
import { usePathData } from 'router'
|
|
|
-import { inRevise } from 'utils'
|
|
|
import style from './style.module.scss'
|
|
|
import boardFactory from './board'
|
|
|
import DfSlider from './slider'
|
|
|
import DfHeader from './header'
|
|
|
import EShape from './eshape'
|
|
|
-import {
|
|
|
- currentBoard,
|
|
|
- useDispatch,
|
|
|
- useSelector,
|
|
|
- fetchBoard,
|
|
|
- copyBoard,
|
|
|
- BoardType
|
|
|
-} from 'store'
|
|
|
+import { useDispatch } from 'store'
|
|
|
+import { getBoardById, BoardType, BoardData } from 'api'
|
|
|
|
|
|
import type { Board } from './board'
|
|
|
|
|
|
const { Header, Sider, Content } = Layout
|
|
|
|
|
|
-const DfBoard = memo(forwardRef((_: {}, ref) => {
|
|
|
- const boardData = useSelector(currentBoard)
|
|
|
+const DfBoard = memo(forwardRef(({ data: boardData }: { data: BoardData }, ref) => {
|
|
|
const board = useRef<Board>()
|
|
|
- const dispatch = useDispatch()
|
|
|
-
|
|
|
const createBoard = useCallback((dom: HTMLCanvasElement | null) => {
|
|
|
if (dom) {
|
|
|
- const boardRef = boardFactory(copyBoard(boardData), dom)
|
|
|
- boardRef.bus.on('storeChange', () => {
|
|
|
- dispatch({
|
|
|
- type: 'board/push',
|
|
|
- payload: copyBoard(boardRef.getCurrentStore())
|
|
|
- })
|
|
|
- })
|
|
|
+ const boardRef = boardFactory(boardData, dom)
|
|
|
board.current = boardRef
|
|
|
} else if (board.current) {
|
|
|
board.current.destroy()
|
|
@@ -42,12 +26,6 @@ const DfBoard = memo(forwardRef((_: {}, ref) => {
|
|
|
}, [])
|
|
|
useImperativeHandle(ref, () => board.current)
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (board.current && inRevise(board.current.getCurrentStore(), boardData)) {
|
|
|
- board.current.drawStore(copyBoard(boardData))
|
|
|
- }
|
|
|
- }, [boardData, board])
|
|
|
-
|
|
|
return (
|
|
|
<div className={style['df-board']}>
|
|
|
<div className={style['df-board-content']}>
|
|
@@ -63,16 +41,22 @@ export const DrawFile = () => {
|
|
|
const pathId = Number(path!.id)
|
|
|
const caseId = Number(path!.caseId)
|
|
|
const pathType = path!.type as BoardType
|
|
|
- const boardData = useSelector(currentBoard)
|
|
|
+ const [boardData, setBoardData] = useState<BoardData>()
|
|
|
const board = useRef<Board>(null)
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (pathId !== boardData.id) {
|
|
|
+ if (!boardData || pathId !== boardData.id) {
|
|
|
+ console.log(pathId, boardData?.id)
|
|
|
if (pathId !== -1) {
|
|
|
- dispatch(fetchBoard({ id: pathId, type: pathType }))
|
|
|
+ getBoardById({ id: pathId }).then((data) => setBoardData({ ...data.content, id: data.filesId! }))
|
|
|
+ } else {
|
|
|
+ setBoardData({
|
|
|
+ id: -1,
|
|
|
+ shapes: []
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
- }, [pathId, pathType, boardData.id, dispatch])
|
|
|
+ }, [pathId, boardData?.id, boardData])
|
|
|
|
|
|
useEffect(() => () => {
|
|
|
dispatch({ type: 'board/destory' })
|
|
@@ -89,7 +73,7 @@ export const DrawFile = () => {
|
|
|
</Sider>
|
|
|
<Content className={style['def-content']}>
|
|
|
{ <EShape board={ board } /> }
|
|
|
- { pathId === boardData.id && <DfBoard ref={board} /> }
|
|
|
+ { pathId === boardData?.id && <DfBoard data={boardData} ref={board} /> }
|
|
|
</Content>
|
|
|
</Layout>
|
|
|
</Layout>
|