From 2b84c7c6c7add3c01ef902751dcc91859247e76b Mon Sep 17 00:00:00 2001 From: jmal Date: Thu, 16 Apr 2020 22:35:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=BB=E5=8C=BA=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 113 ++++++++++++++++----------- 1 file changed, 68 insertions(+), 45 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index d80b4cb..5ad2b13 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -610,6 +610,7 @@ selectEnd: -1,// 选择终点 selectPin: false,// 默认false,不按住 dragElementList: [], + drawFlag: false, } }, computed: { @@ -761,7 +762,9 @@ } }, gridItemClick(row) { - this.fileClick(row) + if(!this.drawFlag){ + this.fileClick(row) + } }, containerResize() { let clientWidth = document.querySelector(".dashboard-container").clientWidth @@ -777,11 +780,14 @@ console.log('draw',draw) let wId = "rectangle1" let startX = 0, startY = 0 - let flag = false + // let flag = false let retcLeft = 0, retcTop = 0, retcHeight = 0, retcWidth = 0 draw.onmousedown = function(e){ - flag = true let evt = window.event || e + if(evt.button !== 0){ + return + } + console.log('onmousedown',evt.button) let scrollTop = draw.scrollTop || draw.scrollTop let scrollLeft = draw.scrollLeft || draw.scrollLeft startX = evt.clientX + scrollLeft @@ -800,7 +806,9 @@ div.style.overflow = 'hidden' draw.appendChild(div) document.onmousemove = function(e){ - if(flag){ + console.log('onmousemove') + _this.drawFlag = true + if(_this.drawFlag){ let evt = window.event || e let scrollTop = document.body.scrollTop || document.documentElement.scrollTop let scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft @@ -814,50 +822,51 @@ drawRectangle.style.width = retcWidth + 'px' drawRectangle.style.height = retcHeight + 'px' drawRectangle.style.backgroundColor = '#f2f5fa55' - _this.$refs.fileListTable.clearSelection() - console.log(89) - // _this.dragElementList.forEach(element => { - // if(checkTouch(element,$$(wId))){ - // _this.$refs.fileListTable.toggleRowSelection([{row:_this.fileList[element.rowIndex],selected: true}]) - // } - // }) + if(!drawSelecting){ + drawSelect({x:retcLeft,y:retcTop,w:retcWidth,h:retcHeight}) + } + // drawSelect() + } + } + document.onmouseup = function(e){ + document.onmousemove = null; + document.onmouseup = null; + console.log('onmouseup') + setTimeout(function () { + _this.drawFlag = false + },50) + if($$(wId)){ + draw.removeChild($$(wId)) } } } - document.onmouseup = function(e){ - flag = false - if($$(wId)){ - draw.removeChild($$(wId)) - } - } - + let drawSelecting = false + let drawSelect = function(drawNode){ + drawSelecting = true + _this.dragElementList.forEach(element => { + if(checkTouch(element,drawNode)){ + _this.$refs.fileListTable.toggleRowSelection([{row:_this.fileList[element.rowIndex],selected: true}]) + }else{ + _this.$refs.fileListTable.toggleRowSelection([{row:_this.fileList[element.rowIndex],selected: false}]) + } + }) + setTimeout(function () { + drawSelecting = false + },150) + } //检查两个DIV是否有接触 - let checkTouch = function(o1,o2){ + let checkTouch = function(item,draw){ //得到左上角的绝对坐标 - let p1=getObjPos(o1); - let p2=getObjPos(o2); - let x1=p1.x - let y1=p1.y - let x2=p2.x - let y2=p2.y - let w1=o1.offsetWidth; - let h1=o1.offsetHeight; - let w2=o2.offsetWidth; - let h2=o2.offsetHeight; - return ((x1-x2<=0)&&(x2-x1=0)&&(x1-x2=0)&&(y1-y2=0)&&(x1-x2=0)&&(y1-y2