feat: 新增复制粘贴功能

This commit is contained in:
MTrun
2022-02-03 22:54:31 +08:00
parent 0cda041315
commit ad8cc8a003
22 changed files with 519 additions and 129 deletions
@@ -29,7 +29,7 @@ export const handleDrop = async (e: DragEvent) => {
let newComponent:CreateComponentType = await createComponent(dropData)
newComponent.setPosition(e.offsetX - newComponent.attr.w / 2, e.offsetY - newComponent.attr.h / 2)
chartEditStore.addComponentList(newComponent)
chartEditStore.addComponentList(newComponent, false, true)
chartEditStore.setTargetSelectChart(newComponent.id)
loadingFinish()
} catch (error) {
@@ -0,0 +1,36 @@
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)
}