重写组件移动方法

2.0
咬轮猫 4 years ago
parent b6e730772e
commit eec9c89ff6

@ -54,7 +54,7 @@
v-for="(item,index) in svgLists" v-for="(item,index) in svgLists"
:key="item" :key="item"
:id=item.id :id=item.id
@mousedown="MousedownSvg(item.id,index)" @mousedown="MousedownSvg(item.id,index,item.svgPositionX,item.svgPositionY,$event)"
:title=item.title :title=item.title
:transform="'translate('+(item.svgPositionX)+','+(item.svgPositionY)+')' +'rotate('+item.angle+')' +'scale('+item.height+')'"> :transform="'translate('+(item.svgPositionX)+','+(item.svgPositionY)+')' +'rotate('+item.angle+')' +'scale('+item.height+')'">
<DynamicTest :svg_color=item.svgColor <DynamicTest :svg_color=item.svgColor
@ -106,9 +106,14 @@ export default {
Width: '',//svg Width: '',//svg
Angle: '',//svg Angle: '',//svg
}, },
moveSvg: { selectSvg: {
ID: '',//svg ID: '',//svg
Index: 0, Index: 0,
mouseStatus: 0, // 1 0
mPositionX: 0,//svgx
mPositionY: 0,//svgy
pointX: 0,//svgsvgx
pointY: 0,//svgsvgy
} }
, ,
selectSvgInfo: '', selectSvgInfo: '',
@ -162,35 +167,45 @@ export default {
} }
}, },
MouseMove (e) { MouseMove (e) {
if (e.offsetX == -1) { let _this = this;
return; // if (e.offsetX == -1) {
} // return;
if (e.target.nodeName == 'INPUT') { // }
return; // if (e.target.nodeName == 'INPUT') {
} // return;
if (e.offsetY == -1) { // }
return; // if (e.offsetY == -1) {
} // return;
if (this.moveSvg.ID == '') { // }
// if (this.selectSvg.ID == '') {
// return;
// }
if (this.selectSvg.mouseStatus == 0) {
return; return;
} }
this.mousePosition.positionX = e.offsetX; const { clientX, clientY } = e
this.mousePosition.positionY = e.offsetY; console.log("当前:" + clientX + " " + clientY);
if (this.mousePosition.positionX < 1) { // this.mousePosition.positionX += (clientX-this.selectSvg.mPositionX);
this.mousePosition.positionX = 10; // this.mousePosition.positionY += (clientY-this.selectSvg.mPositionY);
} // if (this.mousePosition.positionX < 1) {
if (this.mousePosition.positionY < 1) { // this.mousePosition.positionX = 10;
this.mousePosition.positionY = 10; // }
} // if (this.mousePosition.positionY < 1) {
let svgID = this.svgLists[this.moveSvg.Index].id; // this.mousePosition.positionY = 10;
// }
let svgID = this.svgLists[this.selectSvg.Index].id;
//svg //svg
let anyPositionList = this.svgLists.filter(function (list) { let anyPositionList = this.svgLists.filter(function (list) {
return list.id != svgID return list.id != svgID
}); });
console.log("点击:" + this.selectSvg.mPositionX + " " + this.selectSvg.mPositionY);
// //
let svgPositionX = this.mousePosition.positionX; let svgPositionX = this.selectSvg.pointX;
let svgPositionY = this.mousePosition.positionY; let svgPositionY = this.selectSvg.pointY;
let _this = this; svgPositionX += (clientX - this.selectSvg.mPositionX);
svgPositionY += (clientY - this.selectSvg.mPositionY);
console.log("计算:" + (clientX - this.selectSvg.mPositionX) + " " + (clientY - this.selectSvg.mPositionY));
console.log("结果:" + svgPositionX + " " + svgPositionY);
setTimeout(function () { setTimeout(function () {
// //
//x10 //x10
@ -207,8 +222,8 @@ export default {
if (exitsAdsorbY.length > 0) { if (exitsAdsorbY.length > 0) {
svgPositionY = exitsAdsorbY[0].svgPositionY; svgPositionY = exitsAdsorbY[0].svgPositionY;
} }
_this.svgLists[_this.moveSvg.Index].svgPositionX = svgPositionX; _this.svgLists[_this.selectSvg.Index].svgPositionX = svgPositionX;
_this.svgLists[_this.moveSvg.Index].svgPositionY = svgPositionY; _this.svgLists[_this.selectSvg.Index].svgPositionY = svgPositionY;
//x //x
let exitsNowX = anyPositionList.filter(function (list) { let exitsNowX = anyPositionList.filter(function (list) {
return list.svgPositionX === svgPositionX return list.svgPositionX === svgPositionX
@ -237,15 +252,19 @@ export default {
//console.log(''); //console.log('');
}, },
MousedownSvg (id, index) { MousedownSvg (id, index,pointX,pointY, e) {
global.CurrentlySelectedToolBarType = ''; this.CurrentlySelectedToolBar.Type = global.CurrentlySelectedToolBarType = '';
global.CurrentlySelectedToolBarTitle = ''; this.CurrentlySelectedToolBar.Title = global.CurrentlySelectedToolBarTitle = '';
this.CurrentlySelectedToolBar.Type = '';
this.CurrentlySelectedToolBar.Title = '';
//index //index
this.moveSvg.ID = id; this.selectSvg.ID = id;
this.moveSvg.Index = index; this.selectSvg.Index = index;
this.selectSvg.mouseStatus = 1;
this.selectSvg.mPositionX = e.clientX;
this.selectSvg.mPositionY = e.clientY;
this.selectSvg.pointX = pointX;
this.selectSvg.pointY = pointY;
this.selectSvgInfo = this.svgLists[index]; this.selectSvgInfo = this.svgLists[index];
//g //g
let gAnyList = document.querySelectorAll('g'); let gAnyList = document.querySelectorAll('g');
gAnyList.forEach(g => { gAnyList.forEach(g => {
@ -259,7 +278,8 @@ export default {
if (this.CurrentlySelectedToolBar.Title != '' || this.CurrentlySelectedToolBar.Type != '') { if (this.CurrentlySelectedToolBar.Title != '' || this.CurrentlySelectedToolBar.Type != '') {
return; return;
} }
this.moveSvg.ID = ''; // this.selectSvg.ID = '';
this.selectSvg.mouseStatus = 0;
}, },
MouseWheel (e) { MouseWheel (e) {
// //

Loading…
Cancel
Save