2024-08-25 23:40:52 +08:00
|
|
|
|
<script lang="ts" setup>
|
2025-04-01 15:10:18 +08:00
|
|
|
|
import { onBeforeUnmount } from 'vue';
|
2024-08-25 23:40:52 +08:00
|
|
|
|
|
2025-04-01 15:10:18 +08:00
|
|
|
|
import {
|
|
|
|
|
alert,
|
|
|
|
|
clearAllAlerts,
|
|
|
|
|
confirm,
|
|
|
|
|
Page,
|
|
|
|
|
prompt,
|
|
|
|
|
useVbenModal,
|
|
|
|
|
} from '@vben/common-ui';
|
|
|
|
|
|
|
|
|
|
import { Button, Card, Flex, message } from 'ant-design-vue';
|
2024-08-25 23:40:52 +08:00
|
|
|
|
|
2024-08-28 22:26:35 +08:00
|
|
|
|
import DocButton from '../doc-button.vue';
|
2024-08-25 23:40:52 +08:00
|
|
|
|
import AutoHeightDemo from './auto-height-demo.vue';
|
|
|
|
|
import BaseDemo from './base-demo.vue';
|
2025-01-11 23:37:17 +08:00
|
|
|
|
import BlurDemo from './blur-demo.vue';
|
2024-08-25 23:40:52 +08:00
|
|
|
|
import DragDemo from './drag-demo.vue';
|
|
|
|
|
import DynamicDemo from './dynamic-demo.vue';
|
2024-11-09 15:00:59 +08:00
|
|
|
|
import FormModalDemo from './form-modal-demo.vue';
|
2024-12-10 17:37:06 +08:00
|
|
|
|
import InContentModalDemo from './in-content-demo.vue';
|
2025-01-11 12:12:50 +08:00
|
|
|
|
import NestedDemo from './nested-demo.vue';
|
2024-08-25 23:40:52 +08:00
|
|
|
|
import SharedDataDemo from './shared-data-demo.vue';
|
|
|
|
|
|
2025-03-06 22:22:45 +08:00
|
|
|
|
defineOptions({ name: 'ModalExample' });
|
|
|
|
|
|
2024-08-25 23:40:52 +08:00
|
|
|
|
const [BaseModal, baseModalApi] = useVbenModal({
|
2024-08-28 22:26:35 +08:00
|
|
|
|
// 连接抽离的组件
|
2024-08-25 23:40:52 +08:00
|
|
|
|
connectedComponent: BaseDemo,
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-10 17:37:06 +08:00
|
|
|
|
const [InContentModal, inContentModalApi] = useVbenModal({
|
|
|
|
|
// 连接抽离的组件
|
|
|
|
|
connectedComponent: InContentModalDemo,
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-25 23:40:52 +08:00
|
|
|
|
const [AutoHeightModal, autoHeightModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: AutoHeightDemo,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [DragModal, dragModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: DragDemo,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [DynamicModal, dynamicModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: DynamicDemo,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [SharedDataModal, sharedModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: SharedDataDemo,
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-10 21:48:51 +08:00
|
|
|
|
const [FormModal, formModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: FormModalDemo,
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-11 12:12:50 +08:00
|
|
|
|
const [NestedModal, nestedModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: NestedDemo,
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-11 23:37:17 +08:00
|
|
|
|
const [BlurModal, blurModalApi] = useVbenModal({
|
|
|
|
|
connectedComponent: BlurDemo,
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-25 23:40:52 +08:00
|
|
|
|
function openBaseModal() {
|
|
|
|
|
baseModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 17:37:06 +08:00
|
|
|
|
function openInContentModal() {
|
|
|
|
|
inContentModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-25 23:40:52 +08:00
|
|
|
|
function openAutoHeightModal() {
|
|
|
|
|
autoHeightModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 20:43:03 +08:00
|
|
|
|
function openDragModal() {
|
2024-08-25 23:40:52 +08:00
|
|
|
|
dragModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openDynamicModal() {
|
|
|
|
|
dynamicModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openSharedModal() {
|
2025-01-11 10:56:54 +08:00
|
|
|
|
sharedModalApi
|
|
|
|
|
.setData({
|
|
|
|
|
content: '外部传递的数据 content',
|
|
|
|
|
payload: '外部传递的数据 payload',
|
|
|
|
|
})
|
|
|
|
|
.open();
|
2024-08-25 23:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-11 12:12:50 +08:00
|
|
|
|
function openNestedModal() {
|
|
|
|
|
nestedModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-11 23:37:17 +08:00
|
|
|
|
function openBlurModal() {
|
|
|
|
|
blurModalApi.open();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-25 23:40:52 +08:00
|
|
|
|
function handleUpdateTitle() {
|
2025-01-11 10:56:54 +08:00
|
|
|
|
dynamicModalApi.setState({ title: '外部动态标题' }).open();
|
2024-08-25 23:40:52 +08:00
|
|
|
|
}
|
2024-09-10 21:48:51 +08:00
|
|
|
|
|
|
|
|
|
function openFormModal() {
|
2025-01-11 10:56:54 +08:00
|
|
|
|
formModalApi
|
|
|
|
|
.setData({
|
|
|
|
|
// 表单值
|
2025-01-15 17:00:46 +08:00
|
|
|
|
values: { field1: 'abc', field2: '123' },
|
2025-01-11 10:56:54 +08:00
|
|
|
|
})
|
|
|
|
|
.open();
|
2024-09-10 21:48:51 +08:00
|
|
|
|
}
|
2025-04-01 15:10:18 +08:00
|
|
|
|
|
|
|
|
|
function openAlert() {
|
|
|
|
|
alert({
|
|
|
|
|
content: '这是一个弹窗',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
}).then(() => {
|
|
|
|
|
message.info('用户关闭了弹窗');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
// 清除所有弹窗
|
|
|
|
|
clearAllAlerts();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function openConfirm() {
|
|
|
|
|
confirm({
|
2025-04-01 22:55:29 +08:00
|
|
|
|
beforeClose({ isConfirm }) {
|
|
|
|
|
if (!isConfirm) return;
|
2025-04-01 15:10:18 +08:00
|
|
|
|
// 这里可以做一些异步操作
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
resolve(true);
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
},
|
2025-04-12 10:37:47 +08:00
|
|
|
|
centered: false,
|
2025-04-01 15:10:18 +08:00
|
|
|
|
content: '这是一个确认弹窗',
|
|
|
|
|
icon: 'question',
|
|
|
|
|
})
|
|
|
|
|
.then(() => {
|
|
|
|
|
message.success('用户确认了操作');
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
message.error('用户取消了操作');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function openPrompt() {
|
|
|
|
|
prompt<string>({
|
2025-04-01 22:55:29 +08:00
|
|
|
|
async beforeClose({ isConfirm, value }) {
|
|
|
|
|
if (isConfirm && value === '芝士') {
|
2025-04-01 15:10:18 +08:00
|
|
|
|
message.error('不能吃芝士');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
componentProps: { placeholder: '不能吃芝士...' },
|
|
|
|
|
content: '中午吃了什么?',
|
|
|
|
|
icon: 'question',
|
2025-04-12 10:37:47 +08:00
|
|
|
|
overlayBlur: 3,
|
2025-04-01 15:10:18 +08:00
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
message.success(`用户输入了:${res}`);
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
message.error('用户取消了输入');
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-08-25 23:40:52 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Page
|
2024-12-10 17:37:06 +08:00
|
|
|
|
auto-content-height
|
2024-08-28 22:26:35 +08:00
|
|
|
|
description="弹窗组件常用于在不离开当前页面的情况下,显示额外的信息、表单或操作提示,更多api请查看组件文档。"
|
2024-08-25 23:40:52 +08:00
|
|
|
|
title="弹窗组件示例"
|
|
|
|
|
>
|
2024-08-28 22:26:35 +08:00
|
|
|
|
<template #extra>
|
|
|
|
|
<DocButton path="/components/common-ui/vben-modal" />
|
|
|
|
|
</template>
|
2024-08-25 23:40:52 +08:00
|
|
|
|
<BaseModal />
|
2024-12-10 17:37:06 +08:00
|
|
|
|
<InContentModal />
|
2024-08-25 23:40:52 +08:00
|
|
|
|
<AutoHeightModal />
|
|
|
|
|
<DragModal />
|
|
|
|
|
<DynamicModal />
|
|
|
|
|
<SharedDataModal />
|
2024-09-10 21:48:51 +08:00
|
|
|
|
<FormModal />
|
2025-01-11 12:12:50 +08:00
|
|
|
|
<NestedModal />
|
2025-01-11 23:37:17 +08:00
|
|
|
|
<BlurModal />
|
2025-01-11 12:12:50 +08:00
|
|
|
|
<Flex wrap="wrap" class="w-full" gap="10">
|
|
|
|
|
<Card class="w-[300px]" title="基本使用">
|
|
|
|
|
<p>一个基础的弹窗示例</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openBaseModal">打开弹窗</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
2025-04-13 23:02:07 +08:00
|
|
|
|
<Card class="w-[300px]" title="指定容器+关闭后不销毁">
|
2025-01-11 12:12:50 +08:00
|
|
|
|
<p>在内容区域打开弹窗的示例</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openInContentModal">打开弹窗</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="内容高度自适应">
|
|
|
|
|
<p>可根据内容并自动调整高度</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openAutoHeightModal">
|
|
|
|
|
打开弹窗
|
|
|
|
|
</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="可拖拽示例">
|
|
|
|
|
<p>配置 draggable 可开启拖拽功能</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openDragModal"> 打开弹窗 </Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="动态配置示例">
|
|
|
|
|
<p>通过 setState 动态调整弹窗数据</p>
|
|
|
|
|
<template #extra>
|
|
|
|
|
<Button type="link" @click="openDynamicModal">打开弹窗</Button>
|
|
|
|
|
</template>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="handleUpdateTitle">
|
|
|
|
|
外部修改标题并打开
|
|
|
|
|
</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="内外数据共享示例">
|
|
|
|
|
<p>通过共享 sharedData 来进行数据交互</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openSharedModal">
|
|
|
|
|
打开弹窗并传递数据
|
|
|
|
|
</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="表单弹窗示例">
|
|
|
|
|
<p>弹窗与表单结合</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openFormModal"> 打开表单弹窗 </Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="嵌套弹窗示例">
|
|
|
|
|
<p>在已经打开的弹窗中再次打开弹窗</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openNestedModal">打开嵌套弹窗</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
2025-01-11 23:37:17 +08:00
|
|
|
|
|
|
|
|
|
<Card class="w-[300px]" title="遮罩模糊示例">
|
|
|
|
|
<p>遮罩层应用类似毛玻璃的模糊效果</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openBlurModal">打开弹窗</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
2025-04-01 15:10:18 +08:00
|
|
|
|
<Card class="w-[300px]" title="轻量提示弹窗">
|
2025-04-12 00:59:56 +08:00
|
|
|
|
<template #extra>
|
|
|
|
|
<DocButton path="/components/common-ui/vben-alert" />
|
|
|
|
|
</template>
|
2025-04-01 15:10:18 +08:00
|
|
|
|
<p>通过快捷方法创建动态提示弹窗,适合一些轻量的提示和确认、输入等</p>
|
|
|
|
|
<template #actions>
|
|
|
|
|
<Button type="primary" @click="openAlert">Alert</Button>
|
|
|
|
|
<Button type="primary" @click="openConfirm">Confirm</Button>
|
|
|
|
|
<Button type="primary" @click="openPrompt">Prompt</Button>
|
|
|
|
|
</template>
|
|
|
|
|
</Card>
|
2025-01-11 12:12:50 +08:00
|
|
|
|
</Flex>
|
2024-08-25 23:40:52 +08:00
|
|
|
|
</Page>
|
|
|
|
|
</template>
|