Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
feat: 现在可以剪切节点
Browse files Browse the repository at this point in the history
  • Loading branch information
hellowuxin committed May 14, 2021
1 parent c5fbd7b commit 3db4349
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/components/Mindmap/listener/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const onContextmenu = (e: MouseEvent): void => {
if (!classList.contains(style.selected)) { selectGNode(gNode as SVGGElement) }
ctm.addItem.value.disabled = collapseFlag
ctm.deleteItem.value.disabled = isRoot
ctm.cutItem.value.disabled = isRoot
ctm.addSiblingItem.value.disabled = isRoot
ctm.addSiblingBeforeItem.value.disabled = isRoot
ctm.addParentItem.value.disabled = isRoot
Expand Down Expand Up @@ -127,6 +128,15 @@ export const onClickMenu = (name: MenuEvent): void => {
const d = addParent(seleData.id, '')
if (d) { edit(d) }
} break
case 'cut': {
const { id } = getSelectedGData()
const rawdata = mmdata.find(id)?.rawData
if (rawdata) {
// navigator.clipboard.write
navigator.clipboard.writeText(JSON.stringify(rawdata))
}
del(id)
} break
case 'copy': {
const seleData = getSelectedGData()
const rawdata = mmdata.find(seleData.id)?.rawData
Expand Down
5 changes: 3 additions & 2 deletions src/components/Mindmap/variable/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { scaleExtent, zoomTransform } from '.'

export type MenuEvent = 'zoomin' | 'zoomout' | 'zoomfit' | 'add' | 'delete' |
'selectall' | 'collapse' | 'expand' | 'add-sibling' | 'add-sibling-before' |
'add-parent' | 'copy' | 'paste'
'add-parent' | 'copy' | 'paste' | 'cut'
export interface MenuItem {
title: string
name: string
Expand All @@ -18,13 +18,14 @@ export const addItem: Ref<MenuItem> = ref({ title: '新建子节点', name: 'add
export const addParentItem: Ref<MenuItem> = ref({ title: '新建父节点', name: 'add-parent', disabled: false })
export const addSiblingItem: Ref<MenuItem> = ref({ title: '新建兄弟节点', name: 'add-sibling', disabled: false })
export const addSiblingBeforeItem: Ref<MenuItem> = ref({ title: '在此之前新建兄弟节点', name: 'add-sibling-before', disabled: true })
export const cutItem: Ref<MenuItem> = ref({ title: '剪切', name: 'cut', disabled: false })
export const copyItem: Ref<MenuItem> = ref({ title: '拷贝', name: 'copy', disabled: false })
export const pasteItem: Ref<MenuItem> = ref({ title: '粘贴', name: 'paste', disabled: false })


const nodeMenu = computed<MenuItem[][]>(() => [
[ addItem.value, addParentItem.value, addSiblingItem.value, addSiblingBeforeItem.value ],
[ copyItem.value, pasteItem.value, deleteItem.value ],
[ cutItem.value, copyItem.value, pasteItem.value, deleteItem.value ],
[ { title: '全选', name: 'selectall', disabled: true } ],
[ collapseItem.value, expandItem.value ]
])
Expand Down

0 comments on commit 3db4349

Please sign in to comment.