From bf7496f0d5c4df3a0e39827cc660c23324a50797 Mon Sep 17 00:00:00 2001 From: Netfan Date: Tue, 15 Apr 2025 00:00:05 +0800 Subject: [PATCH] feat: add `useAlertContext` for Alert component (#5947) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增Alert的子组件中获取弹窗上下文的能力 --- docs/src/components/common-ui/vben-alert.md | 19 +++++++++++ docs/src/demos/vben-alert/prompt/index.vue | 34 +++++++++++++------ .../ui-kit/popup-ui/src/alert/AlertBuilder.ts | 8 ++--- .../@core/ui-kit/popup-ui/src/alert/alert.ts | 27 +++++++++++++++ .../@core/ui-kit/popup-ui/src/alert/alert.vue | 21 +++++++++++- .../@core/ui-kit/popup-ui/src/alert/index.ts | 9 +++-- .../render-content/render-content.vue | 11 +++--- 7 files changed, 104 insertions(+), 25 deletions(-) diff --git a/docs/src/components/common-ui/vben-alert.md b/docs/src/components/common-ui/vben-alert.md index 295fecce..684a552a 100644 --- a/docs/src/components/common-ui/vben-alert.md +++ b/docs/src/components/common-ui/vben-alert.md @@ -12,6 +12,12 @@ Alert提供的功能与Modal类似,但只适用于简单应用场景。例如 ::: +::: tip 注意 + +Alert提供的快捷方法alert、confirm、prompt动态创建的弹窗在已打开的情况下,不支持HMR(热更新),代码变更后需要关闭这些弹窗后重新打开。 + +::: + ::: tip README 下方示例代码中的,存在一些主题色未适配、样式缺失的问题,这些问题只在文档内会出现,实际使用并不会有这些问题,可忽略,不必纠结。 @@ -32,6 +38,19 @@ Alert提供的功能与Modal类似,但只适用于简单应用场景。例如 +## useAlertContext + +当弹窗的content、footer、icon使用自定义组件时,在这些组件中可以使用 `useAlertContext` 获取当前弹窗的上下文对象,用来主动控制弹窗。 + +::: tip 注意 `useAlertContext`只能用在setup或者函数式组件中。::: + +### Methods + +| 方法 | 描述 | 类型 | 版本要求 | +| --------- | ------------------ | -------- | -------- | +| doConfirm | 调用弹窗的确认操作 | ()=>void | >5.5.4 | +| doCancel | 调用弹窗的取消操作 | ()=>void | >5.5.4 | + ## 类型说明 ```ts diff --git a/docs/src/demos/vben-alert/prompt/index.vue b/docs/src/demos/vben-alert/prompt/index.vue index 02a4ccc5..a1922134 100644 --- a/docs/src/demos/vben-alert/prompt/index.vue +++ b/docs/src/demos/vben-alert/prompt/index.vue @@ -1,7 +1,7 @@