Commit 577a2aba by Jaxon

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

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