Commit 577a2aba by Jaxon

fix(venusDialog): 修复组件销毁时拖拽事件未清理的问题并统一代码格式

将vue2项目中错误的beforeUnmount钩子替换为标准的beforeDestroy,为所有条件判断添加缺失的花括号,统一代码风格。
1 parent 50b04606
......@@ -200,18 +200,21 @@ export default {
}
}
},
beforeUnmount() {
beforeDestroy() {
this.destroyDrag();
},
methods: {
formatSize(val) {
if (val === "" || val === undefined || val === null)
if (val === "" || val === undefined || val === null) {
return "";
if (typeof val === "number")
}
if (typeof val === "number") {
return `${val}px`;
}
if (typeof val === "string") {
if (/^\d+$/.test(val))
if (/^\d+$/.test(val)) {
return `${val}px`;
}
return val;
}
return val;
......@@ -222,12 +225,14 @@ export default {
// Just ensure we do our own initialization.
},
centerDialog() {
if (this.innerFullscreen)
if (this.innerFullscreen) {
return;
}
this.$nextTick(() => {
const dialogWrapper = this.$refs.elDialog?.$el;
if (!dialogWrapper)
if (!dialogWrapper) {
return;
}
const dragDom = dialogWrapper.querySelector(".el-dialog");
if (dragDom) {
// Reset inline styles first
......@@ -292,15 +297,17 @@ export default {
this.$emit("confirm");
},
initDrag() {
if (!this.draggable)
if (!this.draggable) {
return;
}
const dialogWrapper = this.$refs.elDialog.$el;
const dialogHeaderEl = dialogWrapper.querySelector(".el-dialog__header");
const dragDom = dialogWrapper.querySelector(".el-dialog");
if (!dialogHeaderEl || !dragDom)
if (!dialogHeaderEl || !dragDom) {
return;
}
dialogHeaderEl.style.cursor = "move";
......@@ -315,12 +322,14 @@ export default {
this.dragEvent = (e) => {
// Disable drag if fullscreen is active
if (this.innerFullscreen)
if (this.innerFullscreen) {
return;
}
// Prevent drag when clicking on header buttons
if (e.target.closest("button"))
if (e.target.closest("button")) {
return;
}
// Ensure transform is cleared and converted to absolute left/top BEFORE drag starts
// This prevents the jump when dragging starts from the centered position
......@@ -378,11 +387,13 @@ export default {
dialogHeaderEl.addEventListener("mousedown", this.dragEvent);
},
destroyDrag() {
if (!this.dragEvent)
if (!this.dragEvent) {
return;
}
const dialogWrapper = this.$refs.elDialog?.$el;
if (!dialogWrapper)
if (!dialogWrapper) {
return;
}
const dialogHeaderEl = dialogWrapper.querySelector(".el-dialog__header");
if (dialogHeaderEl) {
dialogHeaderEl.removeEventListener("mousedown", this.dragEvent);
......@@ -392,8 +403,9 @@ export default {
},
resetPosition() {
const dialogWrapper = this.$refs.elDialog?.$el;
if (!dialogWrapper)
if (!dialogWrapper) {
return;
}
const dragDom = dialogWrapper.querySelector(".el-dialog");
if (dragDom) {
dragDom.style.left = "50%";
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!