优化从工具栏拖拽组件功能,只能拖拽到画布,防止拖拽后找不到新增的组件

tclqwl 3 years ago
parent 912f72d287
commit a666b5771c

@ -16,10 +16,12 @@
<!-- 左侧组件栏--> <!-- 左侧组件栏-->
<el-tab-pane label="工具栏"> <el-tab-pane label="工具栏">
<!-- <el-divider content-position="center">html</el-divider>--> <!-- <el-divider content-position="center">html</el-divider>-->
<draggable <li
v-for="widget in widgetTools" v-for="widget in widgetTools"
:key="widget.code" :key="widget.code"
@end="evt => widgetOnDragged(evt, widget.code)" draggable="true"
@dragstart="dragStart(widget.code)"
@dragend="dragEnd()"
> >
<div class="tools-item"> <div class="tools-item">
<span class="tools-item-icon"> <span class="tools-item-icon">
@ -27,7 +29,7 @@
</span> </span>
<span class="tools-item-text">{{ widget.label }}</span> <span class="tools-item-text">{{ widget.label }}</span>
</div> </div>
</draggable> </li>
</el-tab-pane> </el-tab-pane>
<!-- 左侧图层--> <!-- 左侧图层-->
<el-tab-pane label="图层"> <el-tab-pane label="图层">
@ -197,7 +199,7 @@
'background-origin': 'initial', 'background-origin': 'initial',
'background-clip': 'initial' 'background-clip': 'initial'
}" }"
@click.self="setOptionsOnClickScreen" @click.self="setOptionsOnClickScreen" @drop="widgetOnDragged($event)" @dragover="dragOver($event)"
> >
<div v-if="grade" class="bg-grid"></div> <div v-if="grade" class="bg-grid"></div>
<widget <widget
@ -330,6 +332,7 @@ export default {
}, },
// //
screenCode: "", screenCode: "",
dragWidgetCode:'', //code
// //
widgets: [ widgets: [
{ {
@ -660,14 +663,24 @@ export default {
getPXUnderScale(px) { getPXUnderScale(px) {
return this.bigscreenScaleInWorkbench * px; return this.bigscreenScaleInWorkbench * px;
}, },
dragStart( widgetCode) {
this.dragWidgetCode =widgetCode;
},
dragEnd() {
this.dragWidgetCode=''
},
dragOver(evt){
evt.preventDefault()
evt.stopPropagation()
evt.dataTransfer.dropEffect = 'copy'
},
// //
widgetOnDragged(evt, widgetCode) { widgetOnDragged(evt) {
let widgetType = widgetCode; let widgetType = this.dragWidgetCode;
// //
let eventX = evt.originalEvent.clientX; // x let eventX = evt.clientX; // x
let eventY = evt.originalEvent.clientY; // y let eventY = evt.clientY; // y
let workbenchPosition = this.getDomTopLeftById("workbench"); let workbenchPosition = this.getDomTopLeftById("workbench");
let widgetTopInWorkbench = eventY - workbenchPosition.top; let widgetTopInWorkbench = eventY - workbenchPosition.top;

Loading…
Cancel
Save