vue-gantt-3
Version:
A gantt component for Vue 3
83 lines (82 loc) • 1.97 kB
JavaScript
import { defineComponent } from "vue";
const _sfc_main = defineComponent({
name: "common-expandable-box",
components: {},
props: {
draglineShow: {
type: Boolean,
default: true
},
initWidth: {
type: Number,
default: 244
},
minWidth: {
type: Number,
default: 154
},
maxWidth: {
type: Number,
required: true
},
contentClass: String
},
emits: ["width-change"],
data() {
return {
mouseStartX: 0,
width: this.initWidth,
originWidth: 0,
hasDragged: false,
indragging: false
};
},
computed: {
boxStyle() {
return {
width: this.width + "px"
};
}
},
watch: {
initWidth(val) {
if (this.hasDragged) return;
if (val > this.maxWidth) {
this.width = this.maxWidth;
} else if (val < this.minWidth) {
this.width = this.minWidth;
} else {
this.width = val;
}
}
},
mounted() {
this.$emit("width-change", this.width);
},
methods: {
handleMouseDown(event) {
this.mouseStartX = event.clientX;
this.originWidth = this.width;
this.indragging = true;
window.addEventListener("mousemove", this.handleMouseMove, true);
window.addEventListener("mouseup", this.handleMouseUp, true);
},
handleMouseUp() {
this.hasDragged = true;
this.indragging = false;
window.removeEventListener("mousemove", this.handleMouseMove, true);
window.removeEventListener("mouseup", this.handleMouseUp, true);
},
handleMouseMove(event) {
const mouseEndX = event.clientX;
let changeWidth = mouseEndX - this.mouseStartX;
let width = this.originWidth + changeWidth;
this.width = Math.max(this.minWidth, Math.min(this.maxWidth, width));
this.$emit("width-change", this.width);
}
}
});
export {
_sfc_main as default
};
//# sourceMappingURL=ExpandableBox.vue2.mjs.map