Modal 模态框

模态对话框,在浮层中显示,引导用户进行相关操作。

代码示例

				
<template>
	<zk-theme type="page" :padding="30" showBack navbarTitle="提示弹窗modal">
		<!-- 基础模态框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 30rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="基础模态框" />
			<zk-button @click="showBasicModal = true" type="primary" text="基础模态框" />
			<zk-modal :show="showBasicModal" @close="showBasicModal = false" title="基础模态框" content="这是一个基础的模态框示例"
				@confirm="handleBasicConfirm" @cancel="handleBasicCancel" />
		</zk-theme>

		<!-- 自定义内容模态框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 30rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="自定义内容模态框" />
			<zk-button @click="showCustomModal = true" type="success" text="自定义内容模态框" />
			<zk-modal :show="showCustomModal" @close="showCustomModal = false" title="自定义内容"
				@confirm="handleCustomConfirm" @cancel="handleCustomCancel">
				<view class="custom-content">
					<zk-text type="secondary" :size="28" margin="0 0 20rpx 0" text="这是自定义的内容区域" />
					<zk-input v-model="customInput" placeholder="请输入内容" :width="500" :height="80" />
				</view>
			</zk-modal>
		</zk-theme>

		<!-- 无标题模态框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 30rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="无标题模态框" />
			<zk-button @click="showNoTitleModal = true" type="info" text="无标题模态框" />
			<zk-modal :show="showNoTitleModal" @close="showNoTitleModal = false" content="这是一个没有标题的模态框"
				@confirm="handleNoTitleConfirm" @cancel="handleNoTitleCancel" />
		</zk-theme>

		<!-- 单按钮模态框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 30rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="单按钮模态框" />
			<zk-button @click="showSingleButtonModal = true" type="danger" text="单按钮模态框" />
			<zk-modal :show="showSingleButtonModal" @close="showSingleButtonModal = false" title="单按钮模态框"
				content="这个模态框只有一个确认按钮" :show-cancel-button="false" confirm-button-text="知道了"
				@confirm="handleSingleButtonConfirm" />
		</zk-theme>

		<!-- 自定义圆角模态框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 30rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="自定义圆角模态框" />
			<zk-button @click="showCustomRoundModal = true" type="primary" text="自定义圆角模态框" />
			<zk-modal :show="showCustomRoundModal" @close="showCustomRoundModal = false" title="自定义圆角"
				content="这个模态框使用了自定义的圆角大小" :round="true" round-size="32rpx" @confirm="handleCustomRoundConfirm"
				@cancel="handleCustomRoundCancel" />
		</zk-theme>

		<!-- 无圆角模态框 -->
		<zk-theme type="card" :padding="30" :radius="16" margin="0 0 30rpx 0">
			<zk-text type="secondary" :size="28" weight="bold" margin="0 0 20rpx 0" text="无圆角模态框" />
			<zk-button @click="showNoRoundModal = true" type="warning" text="无圆角模态框" />
			<zk-modal :show="showNoRoundModal" @close="showNoRoundModal = false" title="无圆角" content="这个模态框没有圆角"
				:round="false" @confirm="handleNoRoundConfirm" @cancel="handleNoRoundCancel" />
		</zk-theme>
	</zk-theme>
</template>

<script>
	export default {
		data() {
			return {
				showBasicModal: false,
				showCustomModal: false,
				showNoTitleModal: false,
				showSingleButtonModal: false,
				showCustomRoundModal: false,
				showNoRoundModal: false,
				customInput: ''
			}
		},
		methods: {
			handleBasicConfirm() {
				console.log('基础模态框:确认')
				this.showBasicModal = false
			},
			handleBasicCancel() {
				console.log('基础模态框:取消')
				this.showBasicModal = false
			},
			handleCustomConfirm() {
				console.log('自定义内容模态框:确认', this.customInput)
				this.showCustomModal = false
			},
			handleCustomCancel() {
				console.log('自定义内容模态框:取消')
				this.showCustomModal = false
			},
			handleNoTitleConfirm() {
				console.log('无标题模态框:确认')
				this.showNoTitleModal = false
			},
			handleNoTitleCancel() {
				console.log('无标题模态框:取消')
				this.showNoTitleModal = false
			},
			handleSingleButtonConfirm() {
				console.log('单按钮模态框:确认')
				this.showSingleButtonModal = false
			},
			handleCustomRoundConfirm() {
				console.log('自定义圆角模态框:确认')
				this.showCustomRoundModal = false
			},
			handleCustomRoundCancel() {
				console.log('自定义圆角模态框:取消')
				this.showCustomRoundModal = false
			},
			handleNoRoundConfirm() {
				console.log('无圆角模态框:确认')
				this.showNoRoundModal = false
			},
			handleNoRoundCancel() {
				console.log('无圆角模态框:取消')
				this.showNoRoundModal = false
			}
		}
	}
</script>
			

API

Props 属性

参数 说明 类型 可选值 默认值 是否必填
show 是否显示弹窗 boolean true / false false
title 标题 string - ''
content 内容 string - ''
showCancelButton 是否显示取消按钮 boolean true / false true
cancelButtonText 取消按钮文字 string - 取消
showConfirmButton 是否显示确认按钮 boolean true / false true
confirmButtonText 确认按钮文字 string - 确定
confirmButtonType 确认按钮类型 string primary / success / warning / danger primary
customStyle 自定义弹窗样式 object - {}
cancelButtonType 取消按钮类型 string default default
overlay 是否显示遮罩层 boolean true / false true
closeOnClickOverlay 是否在点击遮罩层后关闭 boolean true / false false
position 弹出位置 string center / top / bottom / left / right center
transition 是否显示过渡动画 boolean true / false true
zIndex z-index 层级 number - 2000

Events 事件

事件名 说明 回调参数
update:show 弹窗显示状态变化时触发 show: boolean
confirm 点击确认按钮时触发 -
cancel 点击取消按钮时触发 -
click-overlay 点击遮罩层时触发 -
close 弹窗关闭时触发 show: boolean

Slots 插槽

名称 说明
default 自定义内容
title 自定义标题