Skip to content

Commit f0e9e55

Browse files
authored
feat: alert support customize footer (#5940)
* Alert组件支持自定义footer
1 parent ff88274 commit f0e9e55

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

docs/src/components/common-ui/vben-alert.md

+6
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ export type AlertProps = {
6969
contentClass?: string;
7070
/** 执行beforeClose回调期间,在内容区域显示一个loading遮罩*/
7171
contentMasking?: boolean;
72+
/** 弹窗底部内容(与按钮在同一个容器中) */
73+
footer?: Component | string;
7274
/** 弹窗的图标(在标题的前面) */
7375
icon?: Component | IconType;
76+
/**
77+
* 弹窗遮罩模糊效果
78+
*/
79+
overlayBlur?: number;
7480
/** 是否显示取消按钮 */
7581
showCancel?: boolean;
7682
/** 弹窗标题 */

docs/src/demos/vben-alert/confirm/index.vue

+33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script lang="ts" setup>
2+
import { h, ref } from 'vue';
3+
24
import { alert, confirm, VbenButton } from '@vben/common-ui';
35
6+
import { Checkbox, message } from 'ant-design-vue';
7+
48
function showConfirm() {
59
confirm('This is an alert message')
610
.then(() => {
@@ -18,6 +22,34 @@ function showIconConfirm() {
1822
});
1923
}
2024
25+
function showfooterConfirm() {
26+
const checked = ref(false);
27+
confirm({
28+
cancelText: '不要虾扯蛋',
29+
confirmText: '是的,我们都是NPC',
30+
content:
31+
'刚才发生的事情,为什么我似乎早就经历过一般?\n我甚至能在事情发生过程中潜意识里预知到接下来会发生什么。\n\n听起来挺玄乎的,你有过这种感觉吗?',
32+
footer: () =>
33+
h(
34+
Checkbox,
35+
{
36+
checked: checked.value,
37+
class: 'flex-1',
38+
'onUpdate:checked': (v) => (checked.value = v),
39+
},
40+
'不再提示',
41+
),
42+
icon: 'question',
43+
title: '未解之谜',
44+
}).then(() => {
45+
if (checked.value) {
46+
message.success('我不会再拿这个问题烦你了');
47+
} else {
48+
message.info('下次还要继续问你哟');
49+
}
50+
});
51+
}
52+
2153
function showAsyncConfirm() {
2254
confirm({
2355
beforeClose({ isConfirm }) {
@@ -37,6 +69,7 @@ function showAsyncConfirm() {
3769
<div class="flex gap-4">
3870
<VbenButton @click="showConfirm">Confirm</VbenButton>
3971
<VbenButton @click="showIconConfirm">Confirm With Icon</VbenButton>
72+
<VbenButton @click="showfooterConfirm">Confirm With Footer</VbenButton>
4073
<VbenButton @click="showAsyncConfirm">Async Confirm</VbenButton>
4174
</div>
4275
</template>

packages/@core/ui-kit/popup-ui/src/alert/alert.ts

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export type AlertProps = {
3434
contentClass?: string;
3535
/** 执行beforeClose回调期间,在内容区域显示一个loading遮罩*/
3636
contentMasking?: boolean;
37+
/** 弹窗底部内容(与按钮在同一个容器中) */
38+
footer?: Component | string;
3739
/** 弹窗的图标(在标题的前面) */
3840
icon?: Component | IconType;
3941
/**

packages/@core/ui-kit/popup-ui/src/alert/alert.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ async function handleOpenChange(val: boolean) {
157157
</div>
158158
<VbenLoading v-if="loading && contentMasking" :spinning="loading" />
159159
</AlertDialogDescription>
160-
<div class="flex justify-end gap-x-2" :class="`justify-${buttonAlign}`">
160+
<div
161+
class="flex items-center justify-end gap-x-2"
162+
:class="`justify-${buttonAlign}`"
163+
>
164+
<VbenRenderContent :content="footer" />
161165
<AlertDialogCancel v-if="showCancel" as-child>
162166
<component
163167
:is="components.DefaultButton || VbenButton"

0 commit comments

Comments
 (0)