|
@@ -10,12 +10,12 @@ import {
|
|
|
TitleShapeData
|
|
|
} from 'api'
|
|
|
|
|
|
-import { RefObject, useEffect, useState } from "react"
|
|
|
+import { useEffect, useState } from "react"
|
|
|
import { Board, title } from "./board"
|
|
|
import type { SaveBoardProps } from 'api'
|
|
|
|
|
|
type HeaderProps = {
|
|
|
- board: RefObject<Board>
|
|
|
+ board: Board
|
|
|
type: BoardType
|
|
|
}
|
|
|
const Header = ({ board, type }: HeaderProps) => {
|
|
@@ -27,50 +27,43 @@ const Header = ({ board, type }: HeaderProps) => {
|
|
|
const pathType = path!.type as BoardType
|
|
|
const navigate = useNavigate()
|
|
|
const exportPng = async () => {
|
|
|
- if (board.current) {
|
|
|
- const blob = await board.current.export()
|
|
|
- saveAs(blob, '现场图.png')
|
|
|
- }
|
|
|
+ const blob = await board.export()
|
|
|
+ saveAs(blob, '现场图.png')
|
|
|
}
|
|
|
|
|
|
|
|
|
const save = async () => {
|
|
|
- if (board.current) {
|
|
|
- const store = board.current.getStore()
|
|
|
- const titleShape = store.shapes.find(shape => shape.type === title) as TitleShapeData
|
|
|
- const blob = await board.current.export()
|
|
|
- const isNew = pathId === -1
|
|
|
- const body: SaveBoardProps = {
|
|
|
- caseId,
|
|
|
- imgType: pathType,
|
|
|
- file: new File([blob], `${pathType}_${pathId}.png`),
|
|
|
- filesTitle: titleShape?.text || `${caseId}_${BoardTypeDesc[pathType]}`,
|
|
|
- content: board.current.getStore()
|
|
|
- }
|
|
|
- if (!isNew) {
|
|
|
- body.filesId = pathId
|
|
|
- }
|
|
|
- const data = await saveBoard(body)
|
|
|
+ const store = board.getStore()
|
|
|
+ const titleShape = store.shapes.find(shape => shape.type === title) as TitleShapeData
|
|
|
+ const blob = await board.export()
|
|
|
+ const isNew = pathId === -1
|
|
|
+ const body: SaveBoardProps = {
|
|
|
+ caseId,
|
|
|
+ imgType: pathType,
|
|
|
+ file: new File([blob], `${pathType}_${pathId}.png`),
|
|
|
+ filesTitle: titleShape?.text || `${caseId}_${BoardTypeDesc[pathType]}`,
|
|
|
+ content: board.getStore()
|
|
|
+ }
|
|
|
+ if (!isNew) {
|
|
|
+ body.filesId = pathId
|
|
|
+ }
|
|
|
+ const data = await saveBoard(body)
|
|
|
|
|
|
- if (isNew) {
|
|
|
- navigate(
|
|
|
- fillRoutePath(RoutePath.drawFile, { ...path as any, id: data.filesId.toString() }),
|
|
|
- { replace: true }
|
|
|
- )
|
|
|
- }
|
|
|
+ if (isNew) {
|
|
|
+ navigate(
|
|
|
+ fillRoutePath(RoutePath.drawFile, { ...path as any, id: data.filesId.toString() }),
|
|
|
+ { replace: true }
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
- const boardRef = board.current
|
|
|
- if (boardRef) {
|
|
|
- boardRef.bus.on('backDisabled', setBackDisabled)
|
|
|
- boardRef.bus.on('forwardDisabled', setForwradDisabled)
|
|
|
+ board.bus.on('backDisabled', setBackDisabled)
|
|
|
+ board.bus.on('forwardDisabled', setForwradDisabled)
|
|
|
|
|
|
- return () => {
|
|
|
- boardRef.bus.off('backDisabled', setBackDisabled)
|
|
|
- boardRef.bus.off('forwardDisabled', setForwradDisabled)
|
|
|
- }
|
|
|
+ return () => {
|
|
|
+ board.bus.off('backDisabled', setBackDisabled)
|
|
|
+ board.bus.off('forwardDisabled', setForwradDisabled)
|
|
|
}
|
|
|
}, [board])
|
|
|
|
|
@@ -89,11 +82,11 @@ const Header = ({ board, type }: HeaderProps) => {
|
|
|
<div className={style['df-header-action']}>
|
|
|
<ArrowLeftOutlined
|
|
|
className={backDisabled ? 'disabled': 'icon'}
|
|
|
- onClick={() => board.current?.back()}
|
|
|
+ onClick={() => board.back()}
|
|
|
/>
|
|
|
<ArrowRightOutlined
|
|
|
className={forwardDisabled ? 'disabled': 'icon'}
|
|
|
- onClick={() => board.current?.forward()}
|
|
|
+ onClick={() => board.forward()}
|
|
|
/>
|
|
|
</div>
|
|
|
<Button type="primary" size="middle" onClick={save}>保存</Button>
|