Browse Source

上边缘左边缘吸附

master
1549469775 4 years ago
parent
commit
05e9ff7360
  1. 6
      src/api/request/index.js
  2. 44
      src/ui/editor/MakeLine.vue

6
src/api/request/index.js

@ -16,7 +16,7 @@ const checkERR = (err, type) => {
}; };
// 静默执行 // 静默执行
export function request_(type = "GET", url, data = {},contentType=0,sendToken = true) { export function request_(type = "GET", url, data = {}) {
var __data = {}; var __data = {};
if (type.toUpperCase() == "GET") { if (type.toUpperCase() == "GET") {
__data.params = data; __data.params = data;
@ -34,10 +34,6 @@ export function request_(type = "GET", url, data = {},contentType=0,sendToken =
url: realUrl, url: realUrl,
method: type, method: type,
...__data, ...__data,
headers:{
$type: contentType,
$token: sendToken,
},
responseType: "json", responseType: "json",
}) })
.then((res) => { .then((res) => {

44
src/ui/editor/MakeLine.vue

@ -46,22 +46,34 @@ export default {
}; };
}, },
methods: { methods: {
removeAll(){ removeAll() {
this.lineLeft = []; this.lineLeft = [];
this.lineTop = []; this.lineTop = [];
}, },
listenerChange(list, index,cb) { listenerChange(list, index, cb) {
const activeStyle = list[index].style; const activeStyle = list[index].style;
//
if (Math.abs(activeStyle.top) <= value) {
activeStyle.top = 0;
cb && cb(list[index], index);
}
//
if (Math.abs(activeStyle.left) <= value) {
activeStyle.left = 0;
cb && cb(list[index], index);
}
if (list.length==1) {
return
}
list.forEach((item, jndex) => { list.forEach((item, jndex) => {
if (jndex !== index) { if (jndex !== index) {
let curStyle = item.style; let curStyle = item.style;
let curBottom = curStyle.top+curStyle.height let curBottom = curStyle.top + curStyle.height;
let curRight = curStyle.left+curStyle.width let curRight = curStyle.left + curStyle.width;
let actRight = activeStyle.left+activeStyle.width let actRight = activeStyle.left + activeStyle.width;
let actBottom = activeStyle.top+activeStyle.height let actBottom = activeStyle.top + activeStyle.height;
this.removeLine(curStyle.top, curStyle.left); this.removeLine(curStyle.top, curStyle.left);
this.removeLine(curBottom, curRight); this.removeLine(curBottom, curRight);
// TODO // TODO
@ -69,49 +81,49 @@ export default {
if (Math.abs(activeStyle.top - curStyle.top) <= value) { if (Math.abs(activeStyle.top - curStyle.top) <= value) {
activeStyle.top = curStyle.top; activeStyle.top = curStyle.top;
this.makeTop2Bottom(curStyle.top); this.makeTop2Bottom(curStyle.top);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(actBottom - curBottom) <= value) { if (Math.abs(actBottom - curBottom) <= value) {
activeStyle.top = curBottom - activeStyle.height; activeStyle.top = curBottom - activeStyle.height;
this.makeTop2Bottom(curBottom); this.makeTop2Bottom(curBottom);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(activeStyle.top - curBottom) <= value) { if (Math.abs(activeStyle.top - curBottom) <= value) {
activeStyle.top = curBottom; activeStyle.top = curBottom;
this.makeTop2Bottom(curBottom); this.makeTop2Bottom(curBottom);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(activeStyle.left - curStyle.left) <= value) { if (Math.abs(activeStyle.left - curStyle.left) <= value) {
activeStyle.left = curStyle.left; activeStyle.left = curStyle.left;
this.makeLeft2Right(curStyle.left); this.makeLeft2Right(curStyle.left);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(activeStyle.left - curRight) <= value) { if (Math.abs(activeStyle.left - curRight) <= value) {
activeStyle.left = curRight activeStyle.left = curRight;
this.makeLeft2Right(curRight); this.makeLeft2Right(curRight);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(actRight - curRight) <= value) { if (Math.abs(actRight - curRight) <= value) {
activeStyle.left = curRight - activeStyle.width; activeStyle.left = curRight - activeStyle.width;
this.makeLeft2Right(curRight); this.makeLeft2Right(curRight);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(actBottom - curStyle.top) <= value) { if (Math.abs(actBottom - curStyle.top) <= value) {
activeStyle.top = curStyle.top - activeStyle.height; activeStyle.top = curStyle.top - activeStyle.height;
this.makeTop2Bottom(curStyle.top); this.makeTop2Bottom(curStyle.top);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
// -- // --
if (Math.abs(actRight - curStyle.left) <= value) { if (Math.abs(actRight - curStyle.left) <= value) {
activeStyle.left = curStyle.left - activeStyle.width; activeStyle.left = curStyle.left - activeStyle.width;
this.makeLeft2Right(curStyle.left); this.makeLeft2Right(curStyle.left);
cb&&cb(list[index],index) cb && cb(list[index], index);
} }
} }
}); });

Loading…
Cancel
Save