README.md
3.54 KB
CustomPopup 公共弹窗组件
高度可配置的公共弹窗组件,支持多种定位模式、丰富的自定义选项及完善的交互体验。
过渡效果
- 遮罩:淡入淡出
- 居中弹窗:缩放 + 透明度(scale 0.9→1)
- 底部/顶部弹窗:垂直滑入滑出
- 左侧/右侧弹窗:水平滑入滑出
-
时长:通过
transitionDuration配置,默认 2000ms
使用方式
<template>
<custom-popup
v-model:visible="showPopup"
position="center"
title="提示"
@confirm="onConfirm"
@cancel="onCancel"
>
<text>弹窗内容</text>
</custom-popup>
</template>
<script setup lang="uts">
import { ref } from 'vue'
const showPopup = ref(false)
function onConfirm() {
// 确认逻辑
}
function onCancel() {
// 取消逻辑
}
</script>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| visible | boolean | false | 受控显示,支持 v-model:visible |
| position | 'center' \ | 'bottom' \ | 'top' \ |
| radiusPreset | 'sm' \ | 'md' \ | 'lg' \ |
| borderRadius | string | - | 自定义圆角值,优先级高于 radiusPreset |
| bottomHeight | string | '50%' | 底部/顶部弹窗高度 |
| sideWidth | string | '80%' | 侧边弹窗宽度 |
| showMask | boolean | true | 是否显示遮罩 |
| maskClosable | boolean | true | 遮罩点击是否关闭 |
| maskOpacity | number | 0.5 | 遮罩透明度 |
| showHeader | boolean | true | 是否显示标题栏 |
| title | string | '' | 标题文本 |
| showClose | boolean | true | 是否显示关闭按钮 |
| closePosition | 'top-right' \ | 'top-left' \ | 'bottom-right' \ |
| headerBorder | boolean | true | 标题栏底部分隔线 |
| showFooter | boolean | true | 是否显示底部按钮区 |
| showCancelBtn | boolean | true | 是否显示取消按钮 |
| cancelText | string | '取消' | 取消按钮文案 |
| confirmText | string | '确认' | 确认按钮文案 |
| confirmLoadingText | string | '加载中...' | 确认按钮加载中文案 |
| buttonOrder | 'cancel-first' \ | 'confirm-first' | 'cancel-first' |
| confirmLoading | boolean | false | 确认按钮加载中 |
| confirmDisabled | boolean | false | 确认按钮禁用 |
| cancelDisabled | boolean | false | 取消按钮禁用 |
| customStyle | object | null | 自定义容器样式 |
| transitionDuration | number | 2000 | 过渡时长(毫秒),遮罩与容器的动画时长 |
Slots
| 插槽名 | 说明 |
|---|---|
| default | 主体内容 |
| header | 自定义标题栏,替换默认标题+关闭 |
| close-icon | 自定义关闭图标 |
| footer | 自定义底部区域,替换默认按钮组 |
Events
| 事件 | 说明 |
|---|---|
| update:visible | v-model 同步 |
| close | 弹窗关闭时 |
| cancel | 点击取消按钮 |
| confirm | 点击确认按钮 |
方法(defineExpose)
| 方法 | 说明 |
|---|---|
| open() | 打开弹窗 |
| close() | 关闭弹窗 |
CSS 变量(主题化)
父级可通过以下变量覆盖样式:
-
--popup-primary-color主色 -
--popup-border-radius圆角 -
--popup-shadow阴影 -
--popup-spacing间距 -
--popup-font-size字体大小 -
--popup-mask-color遮罩颜色 -
--popup-mask-opacity遮罩透明度
结构类名
-
.popup-mask遮罩层 -
.popup-container弹窗容器 -
.popup-header标题栏 -
.popup-body内容区 -
.popup-footer底部操作区