Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions packages/canvas/src/components/container/CanvasMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<li
v-for="(item, index) in menus"
:key="index"
:class="item.items ? 'li-item' : ''"
:class="{
'li-item': item.items,
'li-item-disabled': actionDisabled(item)
}"
@click="doOperation(item)"
@mouseover="current = item"
@mouseover="onShowChildrenMenu(item)"
>
<div>
<span>{{ item.name }}</span>
Expand Down Expand Up @@ -98,7 +101,8 @@ export default {
items: [
{ name: '文字提示', code: 'wrap', value: 'TinyTooltip' },
{ name: '弹出框', code: 'wrap', value: 'TinyPopover' }
]
],
code: 'addParent'
},
{ name: '删除', code: 'del' },
{ name: '复制', code: 'copy' },
Expand All @@ -111,10 +115,10 @@ export default {

const operations = {
del() {
removeNodeById(getCurrent().schema.id)
removeNodeById(getCurrent().schema?.id)
},
copy() {
copyNode(getCurrent().schema.id)
copyNode(getCurrent().schema?.id)
},
config() {
useLayout().activeSetting('props')
Expand All @@ -128,17 +132,19 @@ export default {
wrap({ value, name }) {
const componentName = value || name
const { schema, parent } = getCurrent()
const index = parent.children.indexOf(schema)
const wrapSchema = {
componentName,
id: null,
props: {},
children: [schema]
if (schema && parent) {
const index = parent.children.indexOf(schema)
const wrapSchema = {
componentName,
id: null,
props: {},
children: [schema]
}

parent.children.splice(index, 1, wrapSchema)

getController().addHistory()
}

parent.children.splice(index, 1, wrapSchema)

getController().addHistory()
},
createBlock() {
if (useCanvas().isSaved()) {
Expand All @@ -152,16 +158,25 @@ export default {
}
}

const actionDisabled = (actionItem) => {
const actions = ['del', 'copy', 'addParent']
return actions.includes(actionItem.code) && !getCurrent().schema?.id
}

const onShowChildrenMenu = (menuItem) => {
current.value = !actionDisabled(menuItem) ? menuItem : null
}

const close = () => {
boxVisibility.value = false
}
const doOperation = (item) => {
if (item.check && !item.check?.()) {
if ((item.check && !item.check?.()) || actionDisabled(item)) {
return
}

if (item?.code) {
operations[item.code](item)
operations[item.code]?.(item)
closeMenu()
}
}
Expand All @@ -173,7 +188,9 @@ export default {
boxVisibility,
close,
current,
menuDom
menuDom,
actionDisabled,
onShowChildrenMenu
}
}
}
Expand All @@ -196,6 +213,10 @@ export default {
.li-item {
border-bottom: 1px solid var(--ti-lowcode-canvas-menu-border-color);
}
.li-item-disabled {
cursor: not-allowed;
color: var(--ti-lowcode-canvas-menu-item-disabled-color);
}
li {
& > div {
display: flex;
Expand Down
3 changes: 3 additions & 0 deletions packages/canvas/src/components/container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ export const addComponent = (data, position) => {
}

export const copyNode = (id) => {
if (!id) {
return
}
const { node, parent } = getNode(id, true)

inserAfter({ parent, node, data: copyObject(node) })
Expand Down