feat: 新增剪切

This commit is contained in:
MTrun
2022-02-04 12:17:50 +08:00
parent 47a7ce9d6e
commit abaf8f07ad
11 changed files with 224 additions and 45 deletions
@@ -1,26 +1,49 @@
import { isMac, addEventListener, removeEventListener } from '@/utils'
import { getChartEditStore } from './useStore.hook'
import { MenuEnum } from '@/views/chart/hooks/useContextMenu.hook'
const chartEditStore = getChartEditStore()
export const keyboardValue = {
[MenuEnum.COPY]: 'c',
[MenuEnum.CUT]: 'x',
[MenuEnum.PARSE]: 'v',
[MenuEnum.DELETE]: 'delete',
back: 'z',
}
const KeyboardHandle = (e: KeyboardEvent) => {
const ismacRes = isMac()
// 暂不支持mac,因为我没有😤👻
if(ismacRes) return
if (ismacRes) return
const key = e.key.toLowerCase()
if (key === 'delete') {
// 删除
if (key === keyboardValue.delete) {
chartEditStore.removeComponentList()
return
}
// 前进
if (e.ctrlKey && e.shiftKey && key == keyboardValue.back) {
chartEditStore.setForward()
return
}
if (e.ctrlKey) {
switch (key) {
// 复制
case 'c': chartEditStore.setCopy()
case keyboardValue.copy: chartEditStore.setCopy()
break;
// 剪切
case keyboardValue.cut: chartEditStore.setCut()
break;
// 粘贴
case 'v': chartEditStore.setParse()
case keyboardValue.parse: chartEditStore.setParse()
break;
// 撤回
case keyboardValue.back: chartEditStore.setBack()
break;
}
e.preventDefault()
+9 -2
View File
@@ -4,14 +4,15 @@ import { CreateComponentType } from '@/packages/index.d'
import { renderIcon, loadingError } from '@/utils'
import { icon } from '@/plugins'
const { CopyIcon, ClipboardOutlineIcon, TrashIcon, ChevronDownIcon, ChevronUpIcon } = icon.ionicons5
const { CopyIcon, CutIcon, ClipboardOutlineIcon, TrashIcon, ChevronDownIcon, ChevronUpIcon } = icon.ionicons5
const { UpToTopIcon, DownToBottomIcon } = icon.carbon
const chartEditStore = useChartEditStoreStore()
enum MenuEnum {
export enum MenuEnum {
DELETE = 'delete',
COPY = 'copy',
CUT = 'cut',
PARSE = 'parse',
TOP = 'top',
BOTTOM = 'bottom',
@@ -35,6 +36,12 @@ const defaultOptions: MenuOptionsItemType[] = [
icon: renderIcon(CopyIcon),
fnHandle: chartEditStore.setCopy
},
{
label: '剪切',
key: MenuEnum.CUT,
icon: renderIcon(CutIcon),
fnHandle: chartEditStore.setCut
},
{
label: '粘贴',
key: MenuEnum.PARSE,