|
@@ -1,5 +1,5 @@
|
|
|
import { ArrowLeftOutlined } from "@ant-design/icons"
|
|
|
-import { Button } from "antd"
|
|
|
+import { Button, Form, Input, Popover } from "antd"
|
|
|
import { useNavigate, fillRoutePath, RoutePath, usePathData } from "router"
|
|
|
import { saveAs } from 'utils'
|
|
|
import style from './style.module.scss'
|
|
@@ -14,6 +14,23 @@ import { useEffect, useState } from "react"
|
|
|
import { Board, title } from "./board"
|
|
|
import type { SaveBoardProps } from 'api'
|
|
|
|
|
|
+const Shortcut = () => (
|
|
|
+ <Form labelCol={{flex: '100px'}} labelAlign="left">
|
|
|
+ <Form.Item label="撤销">
|
|
|
+ <Input value="Ctrl + Z" disabled />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="重做">
|
|
|
+ <Input value="Ctrl + Y" disabled />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="删除">
|
|
|
+ <Input value="Backspace、Delete" disabled />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="中心定位">
|
|
|
+ <Input value="Space" disabled />
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+)
|
|
|
+
|
|
|
type HeaderProps = {
|
|
|
board: Board
|
|
|
type: BoardType
|
|
@@ -71,13 +88,30 @@ const Header = ({ board, type }: HeaderProps) => {
|
|
|
const keydownHandler = (ev: KeyboardEvent) => {
|
|
|
if (ev.keyCode === 32) {
|
|
|
board.viewInit()
|
|
|
+ } else if (['Control', 'Ctrl'].includes(ev.key)) {
|
|
|
+ const downKey = ev.key
|
|
|
+ const secondaryHandler = (ev: KeyboardEvent) => {
|
|
|
+ console.log(ev.key)
|
|
|
+ if (ev.key.toUpperCase() === 'Y' && !forwardDisabled) {
|
|
|
+ board.forward()
|
|
|
+ } else if (ev.key.toUpperCase() === 'Z' && !backDisabled) {
|
|
|
+ board.back()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ window.addEventListener('keydown', secondaryHandler)
|
|
|
+ window.addEventListener('keyup', function upHandler(ev) {
|
|
|
+ if (ev.key === downKey) {
|
|
|
+ window.removeEventListener('keydown', secondaryHandler)
|
|
|
+ window.removeEventListener('keyup', upHandler)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
window.addEventListener('keydown', keydownHandler)
|
|
|
return () => {
|
|
|
window.removeEventListener('keydown', keydownHandler)
|
|
|
}
|
|
|
- }, [board])
|
|
|
+ }, [board, forwardDisabled, backDisabled])
|
|
|
|
|
|
return (
|
|
|
<>
|
|
@@ -98,7 +132,9 @@ const Header = ({ board, type }: HeaderProps) => {
|
|
|
<i className={`iconfont icon-recover ${forwardDisabled ? 'disabled': 'icon'} `}
|
|
|
onClick={() => board.forward()}
|
|
|
/>
|
|
|
- <i className="iconfont icon-keyboard" />
|
|
|
+ <Popover trigger="hover" content={<Shortcut />} title={<h4>快捷键</h4>}>
|
|
|
+ <i className="iconfont icon-keyboard" />
|
|
|
+ </Popover>
|
|
|
</div>
|
|
|
<Button type="primary" size="middle" onClick={save}>保存</Button>
|
|
|
<Button type="default" size="middle" onClick={exportPng}>导出</Button>
|