|
@@ -50,7 +50,7 @@ export default {
|
|
},
|
|
},
|
|
minWidth: {
|
|
minWidth: {
|
|
type: Number,
|
|
type: Number,
|
|
- default: 0,
|
|
|
|
|
|
+ default: 30,
|
|
validator(val) {
|
|
validator(val) {
|
|
return val >= 0;
|
|
return val >= 0;
|
|
}
|
|
}
|
|
@@ -64,7 +64,7 @@ export default {
|
|
},
|
|
},
|
|
minHeight: {
|
|
minHeight: {
|
|
type: Number,
|
|
type: Number,
|
|
- default: 0,
|
|
|
|
|
|
+ default: 30,
|
|
validator(val) {
|
|
validator(val) {
|
|
return val >= 0;
|
|
return val >= 0;
|
|
}
|
|
}
|
|
@@ -81,6 +81,17 @@ export default {
|
|
default() {
|
|
default() {
|
|
return ["w", "h"];
|
|
return ["w", "h"];
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ isCompact: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false
|
|
|
|
+ },
|
|
|
|
+ transformFit: {
|
|
|
|
+ type: Function
|
|
|
|
+ },
|
|
|
|
+ elementPk: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: ""
|
|
}
|
|
}
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
@@ -91,12 +102,14 @@ export default {
|
|
w: 0,
|
|
w: 0,
|
|
h: 0
|
|
h: 0
|
|
},
|
|
},
|
|
|
|
+ offsetTopOrigin: 0,
|
|
sizePos: {
|
|
sizePos: {
|
|
x: 0,
|
|
x: 0,
|
|
y: 0,
|
|
y: 0,
|
|
w: 0,
|
|
w: 0,
|
|
h: 0
|
|
h: 0
|
|
},
|
|
},
|
|
|
|
+ lastSizePos: {},
|
|
initOver: false,
|
|
initOver: false,
|
|
controlPoints: [],
|
|
controlPoints: [],
|
|
positionType: "static",
|
|
positionType: "static",
|
|
@@ -123,7 +136,8 @@ export default {
|
|
"element-resize",
|
|
"element-resize",
|
|
{
|
|
{
|
|
"element-resize-move": this.move,
|
|
"element-resize-move": this.move,
|
|
- "element-resize-init": this.initOver
|
|
|
|
|
|
+ "element-resize-init": this.initOver,
|
|
|
|
+ "element-resize-compact": this.isCompact
|
|
}
|
|
}
|
|
];
|
|
];
|
|
},
|
|
},
|
|
@@ -166,42 +180,79 @@ export default {
|
|
const resizeDom = this.$el.childNodes[0];
|
|
const resizeDom = this.$el.childNodes[0];
|
|
this.positionType = window.getComputedStyle(resizeDom).position;
|
|
this.positionType = window.getComputedStyle(resizeDom).position;
|
|
this.sizePos = { ...this.value };
|
|
this.sizePos = { ...this.value };
|
|
- this.sizePosOrigin = { ...this.sizePos };
|
|
|
|
|
|
+ this.lastSizePos = { ...this.value };
|
|
|
|
+ this.sizePosOrigin = { ...this.value };
|
|
|
|
+ if (this.positionType === "relative")
|
|
|
|
+ this.offsetTopOrigin = this.$el.offsetTop;
|
|
this.initOver = true;
|
|
this.initOver = true;
|
|
},
|
|
},
|
|
- checkValidSizePos(sizePos) {
|
|
|
|
- if (
|
|
|
|
- sizePos.w < this.minWidth ||
|
|
|
|
- (this.maxWidth !== 0 && sizePos.w > this.maxWidth)
|
|
|
|
- )
|
|
|
|
- return false;
|
|
|
|
|
|
+ fetchValidSizePos(sizePos, actionType) {
|
|
|
|
+ if (sizePos.w <= this.minWidth) {
|
|
|
|
+ sizePos.w = this.minWidth;
|
|
|
|
+ }
|
|
|
|
+ if (this.maxWidth !== 0 && sizePos.w >= this.maxWidth) {
|
|
|
|
+ sizePos.w = this.maxWidth;
|
|
|
|
+ }
|
|
|
|
|
|
- if (
|
|
|
|
- sizePos.h < this.minHeight ||
|
|
|
|
- (this.maxHeight !== 0 && sizePos.h > this.maxHeight)
|
|
|
|
- )
|
|
|
|
- return false;
|
|
|
|
|
|
+ if (sizePos.h <= this.minHeight) {
|
|
|
|
+ sizePos.h = this.minHeight;
|
|
|
|
+ }
|
|
|
|
+ if (this.maxHeight !== 0 && sizePos.h >= this.maxHeight) {
|
|
|
|
+ sizePos.h = this.maxHeight;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!this.fitParent.length) {
|
|
|
|
+ this.lastSizePos = { ...sizePos };
|
|
|
|
+ return sizePos;
|
|
|
|
+ }
|
|
|
|
|
|
// 不同的定位方式,计算方式有差异
|
|
// 不同的定位方式,计算方式有差异
|
|
- const elOffsetTop =
|
|
|
|
- this.positionType === "relative" ? this.$el.offsetTop : sizePos.y;
|
|
|
|
this.parentNodeSize = {
|
|
this.parentNodeSize = {
|
|
w: this.$el.offsetParent.offsetWidth,
|
|
w: this.$el.offsetParent.offsetWidth,
|
|
h: this.$el.offsetParent.offsetHeight
|
|
h: this.$el.offsetParent.offsetHeight
|
|
};
|
|
};
|
|
|
|
|
|
- if (!this.fitParent.length) return true;
|
|
|
|
|
|
+ if (this.fitParentTypeWidth) {
|
|
|
|
+ if (sizePos.x <= 0) {
|
|
|
|
+ sizePos.x = 0;
|
|
|
|
+ if (actionType.includes("left")) sizePos.w = this.lastSizePos.w;
|
|
|
|
+ }
|
|
|
|
|
|
- if (sizePos.x < 0 || elOffsetTop < 0) return false;
|
|
|
|
|
|
+ if (sizePos.x + sizePos.w > this.parentNodeSize.w) {
|
|
|
|
+ sizePos.x = this.lastSizePos.x;
|
|
|
|
+ sizePos.w = this.parentNodeSize.w - sizePos.x;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- const wValid =
|
|
|
|
- !this.fitParentTypeWidth ||
|
|
|
|
- sizePos.x + sizePos.w <= this.parentNodeSize.w;
|
|
|
|
- const hValid =
|
|
|
|
- !this.fitParentTypeHeight ||
|
|
|
|
- elOffsetTop + sizePos.h <= this.parentNodeSize.h;
|
|
|
|
|
|
+ if (this.fitParentTypeHeight) {
|
|
|
|
+ if (this.positionType === "relative") {
|
|
|
|
+ const elOffsetTop = this.$el.offsetTop;
|
|
|
|
+ if (this.sizePosOrigin.y - sizePos.y >= this.offsetTopOrigin) {
|
|
|
|
+ sizePos.h = this.lastSizePos.h;
|
|
|
|
+ sizePos.y = this.sizePosOrigin.y - this.offsetTopOrigin;
|
|
|
|
+ }
|
|
|
|
+ if (elOffsetTop + sizePos.h >= this.parentNodeSize.h) {
|
|
|
|
+ sizePos.y = this.lastSizePos.y;
|
|
|
|
+ sizePos.h = this.lastSizePos.h;
|
|
|
|
+ // TODO:这里如果拖动太快,会有问题
|
|
|
|
+ // console.log(this.parentNodeSize.h, elOffsetTop, sizePos.h);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (sizePos.y <= 0) {
|
|
|
|
+ sizePos.y = 0;
|
|
|
|
+ if (actionType.includes("top")) sizePos.h = this.lastSizePos.h;
|
|
|
|
+ }
|
|
|
|
+ if (sizePos.y + sizePos.h > this.parentNodeSize.h) {
|
|
|
|
+ sizePos.y = this.lastSizePos.y;
|
|
|
|
+ sizePos.h = this.parentNodeSize.h - sizePos.y;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- return wValid && hValid;
|
|
|
|
|
|
+ this.lastSizePos = { ...sizePos };
|
|
|
|
+ return this.transformFit
|
|
|
|
+ ? this.transformFit({ id: this.elementPk, ...sizePos }, actionType)
|
|
|
|
+ : sizePos;
|
|
},
|
|
},
|
|
getLeftSize(left) {
|
|
getLeftSize(left) {
|
|
return {
|
|
return {
|
|
@@ -227,31 +278,23 @@ export default {
|
|
},
|
|
},
|
|
moveLeftPoint({ left }) {
|
|
moveLeftPoint({ left }) {
|
|
const sp = { ...this.sizePos, ...this.getLeftSize(left) };
|
|
const sp = { ...this.sizePos, ...this.getLeftSize(left) };
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "left") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveRightPoint({ left }) {
|
|
moveRightPoint({ left }) {
|
|
const sp = { ...this.sizePos, ...this.getRightSize(left) };
|
|
const sp = { ...this.sizePos, ...this.getRightSize(left) };
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "right") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveTopPoint({ top }) {
|
|
moveTopPoint({ top }) {
|
|
const sp = { ...this.sizePos, ...this.getTopSize(top) };
|
|
const sp = { ...this.sizePos, ...this.getTopSize(top) };
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "top") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveBottomPoint({ top }) {
|
|
moveBottomPoint({ top }) {
|
|
const sp = { ...this.sizePos, ...this.getBottomSize(top) };
|
|
const sp = { ...this.sizePos, ...this.getBottomSize(top) };
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "bottom") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveLeftTopPoint({ left, top }) {
|
|
moveLeftTopPoint({ left, top }) {
|
|
const sp = {
|
|
const sp = {
|
|
@@ -259,10 +302,8 @@ export default {
|
|
...this.getLeftSize(left),
|
|
...this.getLeftSize(left),
|
|
...this.getTopSize(top)
|
|
...this.getTopSize(top)
|
|
};
|
|
};
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "left-top") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveRightTopPoint({ left, top }) {
|
|
moveRightTopPoint({ left, top }) {
|
|
const sp = {
|
|
const sp = {
|
|
@@ -270,10 +311,8 @@ export default {
|
|
...this.getRightSize(left),
|
|
...this.getRightSize(left),
|
|
...this.getTopSize(top)
|
|
...this.getTopSize(top)
|
|
};
|
|
};
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "right-top") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveLeftBottomPoint({ left, top }) {
|
|
moveLeftBottomPoint({ left, top }) {
|
|
const sp = {
|
|
const sp = {
|
|
@@ -281,10 +320,8 @@ export default {
|
|
...this.getLeftSize(left),
|
|
...this.getLeftSize(left),
|
|
...this.getBottomSize(top)
|
|
...this.getBottomSize(top)
|
|
};
|
|
};
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "left-bottom") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveRightBottomPoint({ left, top }) {
|
|
moveRightBottomPoint({ left, top }) {
|
|
const sp = {
|
|
const sp = {
|
|
@@ -292,14 +329,15 @@ export default {
|
|
...this.getRightSize(left),
|
|
...this.getRightSize(left),
|
|
...this.getBottomSize(top)
|
|
...this.getBottomSize(top)
|
|
};
|
|
};
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "right-bottom") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveOver() {
|
|
moveOver() {
|
|
this.sizePosOrigin = { ...this.sizePos };
|
|
this.sizePosOrigin = { ...this.sizePos };
|
|
- this.$emit("resize-over");
|
|
|
|
|
|
+ this.lastSizePos = { ...this.sizePos };
|
|
|
|
+ if (this.positionType === "relative")
|
|
|
|
+ this.offsetTopOrigin = this.$el.offsetTop < 0 ? 0 : this.$el.offsetTop;
|
|
|
|
+ this.$emit("resize-over", this.sizePos);
|
|
},
|
|
},
|
|
moveStart() {
|
|
moveStart() {
|
|
this.$emit("on-click");
|
|
this.$emit("on-click");
|
|
@@ -314,10 +352,8 @@ export default {
|
|
y: top + this.sizePosOrigin.y
|
|
y: top + this.sizePosOrigin.y
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- if (this.checkValidSizePos(sp)) {
|
|
|
|
- this.sizePos = { ...sp };
|
|
|
|
- this.emitChange();
|
|
|
|
- }
|
|
|
|
|
|
+ this.sizePos = { ...this.fetchValidSizePos(sp, "move") };
|
|
|
|
+ this.emitChange();
|
|
},
|
|
},
|
|
moveElementOver() {
|
|
moveElementOver() {
|
|
if (!this.move) return;
|
|
if (!this.move) return;
|
|
@@ -514,5 +550,26 @@ export default {
|
|
border-top: 1px solid #4794b3;
|
|
border-top: 1px solid #4794b3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ &-compact {
|
|
|
|
+ .control-line {
|
|
|
|
+ &-left {
|
|
|
|
+ left: 0;
|
|
|
|
+ border-left: 1px dashed #bbb;
|
|
|
|
+ }
|
|
|
|
+ &-right {
|
|
|
|
+ right: 0;
|
|
|
|
+ border-left: 1px dashed #bbb;
|
|
|
|
+ }
|
|
|
|
+ &-top {
|
|
|
|
+ top: 0;
|
|
|
|
+ border-top: 1px dashed #bbb;
|
|
|
|
+ }
|
|
|
|
+ &-bottom {
|
|
|
|
+ bottom: 0;
|
|
|
|
+ border-top: 1px dashed #bbb;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|