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

禁止widget移出workbench画布边缘 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 29 additions & 3 deletions report-ui/src/views/bigscreenDesigner/designer/widget/widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export default {
data: {
setup: {},
data: {},
position: {}
position: {},
leftMargin: null,
topMargin: null
}
};
},
Expand All @@ -118,10 +120,10 @@ export default {
return this.value.position.height;
},
widgetsLeft() {
return this.value.position.left;
return this.value.position.left >= this.leftMargin ? this.leftMargin : this.value.position.left;
},
widgetsTop() {
return this.value.position.top;
return this.value.position.top >= this.topMargin ? this.topMargin : this.value.position.top;
},
widgetsZIndex() {
return this.value.position.zIndex || 1;
Expand All @@ -133,6 +135,30 @@ export default {
handleBlur({ index, left, top, width, height }) {
this.$emit("onActivated", { index, left, top, width, height });
this.$refs.draggable.setActive(true);
// 处理widget超出workbench的问题
this.handleBoundary({ index, left, top, width, height })
},
handleBoundary({ index, left, top, width, height }) {
// 计算workbench的X轴边界值
// 组件距离左侧宽度 + 组件宽度 > 大屏总宽度时,右侧边界值 = (大屏宽度 - 组件宽度);左侧边界值 = 0
const { bigscreenWidth, bigscreenHeight } = this.bigscreen;
const xBoundaryValue = (left + width) > bigscreenWidth ? bigscreenWidth - width : left < 0 ? 0 : left;
// 初始化X轴边界值
this.leftMargin = left;

// 计算Y轴边界值
const yBoundaryValue = (top + height) > bigscreenHeight ? bigscreenHeight - height : top < 0 ? 0 : top;
// 初始化Y轴边界值
this.topMargin = top;

// 若位置超出边界值则重新设置位置
if (this.leftMargin != xBoundaryValue || this.topMargin != yBoundaryValue) {
this.$nextTick(() => {
this.leftMargin = xBoundaryValue;
this.topMargin = yBoundaryValue;
this.$emit("onActivated", { index, left: xBoundaryValue, top: yBoundaryValue, width, height });
})
}
}
}
};
Expand Down