Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复空页面执行右键删除和右键复制时控制台报错的问题 #103

Merged
merged 11 commits into from
Nov 30, 2023
29 changes: 24 additions & 5 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 @@ -107,6 +111,15 @@ export default {

const boxVisibility = ref(false)

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 operations = {
Expand Down Expand Up @@ -163,7 +176,7 @@ export default {
}

if (item?.code) {
operations[item.code](item)
operations[item.code]?.(item)
gargameljyh marked this conversation as resolved.
Show resolved Hide resolved
closeMenu()
}
}
Expand All @@ -175,7 +188,9 @@ export default {
boxVisibility,
close,
current,
menuDom
menuDom,
actionDisabled,
onShowChildrenMenu
}
}
}
Expand All @@ -198,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
Loading