go-view/src/views/chart/ContentEdit/hooks/useKeyboard.hook.ts
2022-02-03 22:54:31 +08:00

37 lines
843 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { isMac, addEventListener, removeEventListener } from '@/utils'
import { getChartEditStore } from './useStore.hook'
const chartEditStore = getChartEditStore()
const KeyboardHandle = (e: KeyboardEvent) => {
const ismacRes = isMac()
// 暂不支持mac因为我没有😤👻
if(ismacRes) return
const key = e.key.toLowerCase()
if (key === 'delete') {
chartEditStore.removeComponentList()
return
}
if (e.ctrlKey) {
switch (key) {
// 复制
case 'c': chartEditStore.setCopy()
break;
// 粘贴
case 'v': chartEditStore.setParse()
break;
}
e.preventDefault()
}
}
export const useAddKeyboard = () => {
addEventListener(document, 'keyup', KeyboardHandle)
}
export const useRemoveKeyboard = () => {
removeEventListener(document, 'keyup', KeyboardHandle)
}