优化DrawerOverlay组件支持底部显示动态改变尺寸
This commit is contained in:
parent
0c2e56271b
commit
be3677cfa8
@ -13,7 +13,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<ResizeLine v-if="resize && placement == 'right'" class="overlay-resize" v-model="width" :min-width="100" :max-width="0" reverse/>
|
<ResizeLine v-if="resize" class="overlay-resize" :placement="placement" v-model="dynamicSize" :min="minSize" :max="0" reverse/>
|
||||||
<div class="overlay-content"><slot/></div>
|
<div class="overlay-content"><slot/></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -51,7 +51,11 @@
|
|||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: "100%"
|
default: "100%"
|
||||||
},
|
},
|
||||||
resize: { // only placement:right
|
minSize: {
|
||||||
|
type: Number,
|
||||||
|
default: 300
|
||||||
|
},
|
||||||
|
resize: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
@ -63,7 +67,7 @@
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
width: 0,
|
dynamicSize: 0,
|
||||||
zIndex: 0,
|
zIndex: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -86,7 +90,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
bodyStyle() {
|
bodyStyle() {
|
||||||
let size = this.width;
|
let size = this.dynamicSize;
|
||||||
size = size <= 100 ? `${size}%` : `${size}px`
|
size = size <= 100 ? `${size}%` : `${size}px`
|
||||||
if (this.placement == 'right') {
|
if (this.placement == 'right') {
|
||||||
return {
|
return {
|
||||||
@ -125,7 +129,7 @@
|
|||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
handler(val) {
|
handler(val) {
|
||||||
this.width = parseInt(val);
|
this.dynamicSize = parseInt(val);
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="component-resize-line" :class="{resizing}" @mousedown.left.stop.prevent="resizeDown"></div>
|
<div class="component-resize-line" :class="[resizing ? 'resizing' : '', placement]" @mousedown.left.stop.prevent="resizeDown"></div>
|
||||||
</template>
|
</template>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.component-resize-line {
|
.component-resize-line {
|
||||||
@ -19,6 +19,12 @@
|
|||||||
cursor: col-resize;
|
cursor: col-resize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
&.bottom {
|
||||||
|
cursor: row-resize;
|
||||||
|
&:after {
|
||||||
|
cursor: row-resize;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
@ -28,14 +34,20 @@
|
|||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
},
|
},
|
||||||
minWidth: {
|
min: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 100,
|
default: 100,
|
||||||
},
|
},
|
||||||
maxWidth: {
|
max: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 600,
|
default: 600,
|
||||||
},
|
},
|
||||||
|
placement: {
|
||||||
|
validator (value) {
|
||||||
|
return ['right', 'bottom'].includes(value)
|
||||||
|
},
|
||||||
|
default: 'bottom'
|
||||||
|
},
|
||||||
reverse: {
|
reverse: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
@ -51,7 +63,7 @@
|
|||||||
|
|
||||||
offset: {},
|
offset: {},
|
||||||
|
|
||||||
tmpWidth: undefined,
|
tmpSize: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -70,7 +82,7 @@
|
|||||||
};
|
};
|
||||||
this.resizing = true;
|
this.resizing = true;
|
||||||
if (typeof this.value === 'number') {
|
if (typeof this.value === 'number') {
|
||||||
this.tmpWidth = this.value;
|
this.tmpSize = this.value;
|
||||||
}
|
}
|
||||||
this.$emit('on-change', {
|
this.$emit('on-change', {
|
||||||
event: 'down',
|
event: 'down',
|
||||||
@ -82,13 +94,18 @@
|
|||||||
}
|
}
|
||||||
let diffX = (e.pageX || e.clientX + document.documentElement.scrollLeft) - this.mouseX;
|
let diffX = (e.pageX || e.clientX + document.documentElement.scrollLeft) - this.mouseX;
|
||||||
let diffY = (e.pageY || e.clientY + document.documentElement.scrollTop) - this.mouseY;
|
let diffY = (e.pageY || e.clientY + document.documentElement.scrollTop) - this.mouseY;
|
||||||
if (typeof this.tmpWidth === 'number') {
|
if (typeof this.tmpSize === 'number') {
|
||||||
let value = this.reverse ? (this.tmpWidth - diffX) : (this.tmpWidth + diffX);
|
let value;
|
||||||
if (this.minWidth > 0) {
|
if (this.placement == 'bottom') {
|
||||||
value = Math.max(this.minWidth, value);
|
value = this.reverse ? (this.tmpSize - diffY) : (this.tmpSize + diffY);
|
||||||
|
} else {
|
||||||
|
value = this.reverse ? (this.tmpSize - diffX) : (this.tmpSize + diffX);
|
||||||
}
|
}
|
||||||
if (this.maxWidth > 0) {
|
if (this.min > 0) {
|
||||||
value = Math.min(this.maxWidth, value);
|
value = Math.max(this.min, value);
|
||||||
|
}
|
||||||
|
if (this.max > 0) {
|
||||||
|
value = Math.min(this.max, value);
|
||||||
}
|
}
|
||||||
this.$emit("input", value);
|
this.$emit("input", value);
|
||||||
}
|
}
|
||||||
@ -103,7 +120,7 @@
|
|||||||
},
|
},
|
||||||
handleUp() {
|
handleUp() {
|
||||||
this.resizing = false;
|
this.resizing = false;
|
||||||
this.tmpWidth = undefined;
|
this.tmpSize = undefined;
|
||||||
this.$emit('on-change', {
|
this.$emit('on-change', {
|
||||||
event: 'up',
|
event: 'up',
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user