Skip to content

Commit

Permalink
feature: 梳理了toolkey
Browse files Browse the repository at this point in the history
  • Loading branch information
AnsGoo committed May 14, 2024
1 parent 61ba44c commit b0b1bc2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
13 changes: 2 additions & 11 deletions packages/designer/src/editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import type { CustomComponent } from '@open-data-v/base'
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
import { clearCanvas, paste } from '@/toolbars'
import Area from '../editor/Area.vue'
import Grid from '../editor/Grid.vue'
import MarkLine from '../editor/MarkLine.vue'
Expand Down Expand Up @@ -82,17 +84,6 @@ const getShapeStyle = (style) => {
return filterStyle(style, ['top', 'left', 'width', 'height', 'rotate'])
}
const clearCanvas = () => {
canvasState.clearCanvas()
}
const paste = (_: HTMLElement, event: MouseEvent) => {
const editorRectInfo = document.querySelector('#editor')!.getBoundingClientRect()
const y = event.pageY - editorRectInfo.top
const x = event.pageX - editorRectInfo.left
clipBoardState.paste(true, x, y)
}
const contextMenus = (): ContextmenuItem[] => {
return [
{
Expand Down
12 changes: 2 additions & 10 deletions packages/designer/src/editor/Shape/Shape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { ComponentPublicInstance, PropType } from 'vue'
import { computed, defineComponent, onErrorCaptured, onMounted, ref, watch } from 'vue'

import { stretchedComponents } from '../../component'
import { useActionState, useCanvasState, useClipBoardState } from '../../state'
import { useActionState, useCanvasState } from '../../state'
import { copy, decompose } from '../../toolbars'
import type { ComponentStyle, ContextmenuItem, Vector } from '../../type'
import { copyText, mod360, systemLogger, throttleFrame } from '../../utils'
import styles from './shape.module.less'
Expand All @@ -26,11 +27,6 @@ export default defineComponent({
setup(props, { slots }) {
const canvasState = useCanvasState()
const actionState = useActionState()
const clipBoardState = useClipBoardState()

const copy = () => {
clipBoardState.copy(canvasState.activeComponent!)
}

const deleteComponent = () => {
canvasState.removeComponent(props.index!, props.info!.parent)
Expand Down Expand Up @@ -60,10 +56,6 @@ export default defineComponent({
canvasState.bottomComponent(props.index!, props.info!.parent)
}

const decompose = () => {
canvasState.decompose()
}

const contextmenus = (_: HTMLDivElement, event: MouseEvent): Optional<ContextmenuItem[]> => {
// 如果当前有选中组件,并且接受到contextmenu事件的组件正是当前组件,就停止事件冒泡
if (canvasState.activeComponent && canvasState.activeComponent.id === props.info!.id) {
Expand Down
4 changes: 3 additions & 1 deletion packages/designer/src/pane/LeftSideBar/Layer/Layer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { OMenu } from '@open-data-v/ui'
import { cloneDeep } from 'lodash-es'
import { computed, h, ref, watch } from 'vue'
import { decompose } from '@/toolbars'
import { ComponentGroupList } from '../../../enum'
import { useEmpty } from '../../../modules'
import { useCanvasState, useClipBoardState } from '../../../state'
Expand Down Expand Up @@ -213,7 +215,7 @@ const contextmenus = (index: string): ContextmenuItem[] => {
disable:
canvasState.getComponentByIndex(index.split('-').map((i) => Number(i)))?.component !==
'Group',
handler: () => canvasState.decompose()
handler: decompose
},
{
text: '删除',
Expand Down
24 changes: 23 additions & 1 deletion packages/designer/src/toolbars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,26 @@ const fullScreen = () => {
}
}

export { copy, decompose, exportCanvas, fullScreen, importCanvas, recoveryDraft, setShowEm, undo }
const paste = (_: HTMLElement, event: MouseEvent) => {
const editorRectInfo = document.querySelector('#editor')!.getBoundingClientRect()
const y = event.pageY - editorRectInfo.top
const x = event.pageX - editorRectInfo.left
clipBoardState.paste(true, x, y)
}

const clearCanvas = () => {
canvasState.clearCanvas()
}

export {
clearCanvas,
copy,
decompose,
exportCanvas,
fullScreen,
importCanvas,
paste,
recoveryDraft,
setShowEm,
undo
}

0 comments on commit b0b1bc2

Please sign in to comment.