From 8fad24ecb42328b625a1a93ed766c08b2277f4b3 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 14 Dec 2025 10:05:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdui_patched/components/dialog/index.js | 71 +++++++++++++++++++++---- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/mdui_patched/components/dialog/index.js b/mdui_patched/components/dialog/index.js index 29b9a08..b884cf6 100644 --- a/mdui_patched/components/dialog/index.js +++ b/mdui_patched/components/dialog/index.js @@ -103,6 +103,7 @@ let Dialog = class Dialog extends MduiElement { ]); // 打开 // 要区分是否首次渲染,首次渲染不触发事件,不执行动画;非首次渲染,触发事件,执行动画 + this.panelRef.value.style.transformOrigin = 'center center'; if (this.open) { if (hasUpdated) { const eventProceeded = this.emit('open', { cancelable: true }); @@ -136,8 +137,34 @@ let Dialog = class Dialog extends MduiElement { this.panelRef.value.focus({ preventScroll: true }); } }); - const duration = getDuration(this, 'medium4'); + // const duration = getDuration(this, 'medium4'); + const duration = hasUpdated ? getDuration(this, 'medium4') : 0; await Promise.all([ + // 遮罩层淡入 + animateTo(this.overlayRef.value, [ + { opacity: 0 }, + { opacity: 1 } + ], { + duration: hasUpdated ? duration * 0.7 : 0, + easing: easingLinear, + }), + + // 面板缩放淡入 + animateTo(this.panelRef.value, [ + { + opacity: 0, + transform: 'scale(0.8)', + }, + { + opacity: 1, + transform: 'scale(1)' + } + ], { + duration: hasUpdated ? duration : 0, + easing: easingEmphasizedDecelerate, + }), + ]); + /* await Promise.all([ animateTo(this.overlayRef.value, [{ opacity: 0 }, { opacity: 1, offset: 0.3 }, { opacity: 1 }], { duration: hasUpdated ? duration : 0, easing: easingLinear, @@ -162,7 +189,7 @@ let Dialog = class Dialog extends MduiElement { duration: hasUpdated ? duration : 0, easing: easingLinear, })), - ]); + ]); */ if (hasUpdated) { this.emit('opened'); } @@ -174,8 +201,32 @@ let Dialog = class Dialog extends MduiElement { } this.modalHelper.deactivate(); await stopAnimation(); - const duration = getDuration(this, 'short4'); + // const duration = getDuration(this, 'short4'); + const duration = getDuration(this, 'short3'); await Promise.all([ + // 遮罩层淡出 + animateTo(this.overlayRef.value, [ + { opacity: 1 }, + { opacity: 0 } + ], { + duration, + easing: easingLinear, + }), + + // 面板缩放淡出 + animateTo(this.panelRef.value, [ + { + opacity: 1, + }, + { + opacity: 0, + } + ], { + duration, + easing: easingEmphasizedAccelerate, + }), + ]); + /* await Promise.all([ animateTo(this.overlayRef.value, [{ opacity: 1 }, { opacity: 0 }], { duration, easing: easingLinear, @@ -186,7 +237,7 @@ let Dialog = class Dialog extends MduiElement { ], { duration, easing: easingEmphasizedAccelerate }), animateTo(this.panelRef.value, [{ opacity: 1 }, { opacity: 1, offset: 0.75 }, { opacity: 0 }], { duration, easing: easingLinear }), ...children.map((child) => animateTo(child, [{ opacity: 1 }, { opacity: 0, offset: 0.75 }, { opacity: 0 }], { duration, easing: easingLinear })), - ]); + ]); */ this.style.display = 'none'; unlockScreen(this); // 对话框关闭后,恢复焦点到原有的元素上 @@ -222,11 +273,11 @@ let Dialog = class Dialog extends MduiElement { const hasHeader = hasIcon || hasHeadline || this.hasSlotController.test('header'); const hasBody = hasDescription || hasDefaultSlot; // modify: 移除了 tabindex="0", 换为 tabindex - return html `
${when(hasHeader, () => html `${when(hasIcon, () => this.renderIcon())} ${when(hasHeadline, () => this.renderHeadline())}`)} ${when(hasBody, () => html `
${when(hasDescription, () => this.renderDescription())}
`)} ${when(hasActionSlot, () => html ``)}
`; + })}" tabindex>${when(hasHeader, () => html`${when(hasIcon, () => this.renderIcon())} ${when(hasHeadline, () => this.renderHeadline())}`)} ${when(hasBody, () => html`
${when(hasDescription, () => this.renderDescription())}
`)} ${when(hasActionSlot, () => html``)}`; } onOverlayClick() { this.emit('overlay-click'); @@ -236,15 +287,15 @@ let Dialog = class Dialog extends MduiElement { this.open = false; } renderIcon() { - return html `${this.icon - ? html `` + return html`${this.icon + ? html`` : nothingTemplate}`; } renderHeadline() { - return html `${this.headline}`; + return html`${this.headline}`; } renderDescription() { - return html `${this.description}`; + return html`${this.description}`; } }; Dialog.styles = [componentStyle, style];