You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
349 lines
8.2 KiB
349 lines
8.2 KiB
<template> |
|
<view> |
|
<text class="example-info">弹出层组件用于弹出一个覆盖到页面上的内容,使用场景如:底部弹出分享弹窗、页面插屏广告等。</text> |
|
<uni-section title="基本示例" type="line"></uni-section> |
|
<view class="example-body box"> |
|
<button class="button" type="primary" @click="toggle('top')"><text class="button-text">顶部</text></button> |
|
<button class="button" type="primary" @click="toggle('bottom')"><text class="button-text">底部</text></button> |
|
<button class="button" type="primary" @click="toggle('center')"><text class="button-text">居中</text></button> |
|
<button class="button" type="primary" @click="toggle('left')"><text class="button-text">左侧</text></button> |
|
<button class="button" type="primary" @click="toggle('right')"><text class="button-text">右侧</text></button> |
|
</view> |
|
|
|
<uni-section title="提示消息" type="line"></uni-section> |
|
<view class="example-body box"> |
|
<button class="button popup-success" @click="messageToggle('success')"><text class="button-text success-text">成功</text></button> |
|
<button class="button popup-error" @click="messageToggle('error')"><text class="button-text error-text">失败</text></button> |
|
<button class="button popup-warn" @click="messageToggle('warn')"><text class="button-text warn-text">警告</text></button> |
|
<button class="button popup-info" @click="messageToggle('info')"><text class="button-text info-text">信息</text></button> |
|
</view> |
|
|
|
<uni-section title="对话框示例" type="line" class="hideOnPc"></uni-section> |
|
|
|
<view class="example-body box"> |
|
<button class="button popup-success" @click="dialogToggle('success')"><text class="button-text success-text">成功</text></button> |
|
<button class="button popup-error" @click="dialogToggle('error')"><text class="button-text error-text">失败</text></button> |
|
<button class="button popup-warn" @click="dialogToggle('warn')"><text class="button-text warn-text">警告</text></button> |
|
<button class="button popup-info" @click="dialogToggle('info')"><text class="button-text info-text">信息</text></button> |
|
</view> |
|
<uni-section title="输入框示例" type="line" class="hideOnPc"></uni-section> |
|
<view class="example-body dialog"> |
|
<view class="dialog-box"> |
|
<text class="dialog-text">输入内容:{{ value }}</text> |
|
</view> |
|
<button class="button" type="primary" @click="inputDialogToggle"><text class="button-text">输入对话框</text></button> |
|
</view> |
|
|
|
<uni-section title="底部分享示例" type="line" class="hideOnPc"></uni-section> |
|
<view class="example-body share hideOnPc"> |
|
<button class="button" type="primary" @click="shareToggle"><text class="button-text">分享模版示例</text></button> |
|
</view> |
|
|
|
<view> |
|
<!-- 普通弹窗 --> |
|
<uni-popup ref="popup" background-color="#fff" @change="change"> |
|
<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }"><text class="text">popup 内容</text></view> |
|
</uni-popup> |
|
</view> |
|
|
|
<view> |
|
<!-- 提示信息弹窗 --> |
|
<uni-popup ref="message" type="message"> |
|
<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message> |
|
</uni-popup> |
|
</view> |
|
|
|
<view> |
|
<!-- 提示窗示例 --> |
|
<uni-popup ref="alertDialog" type="dialog"> |
|
<uni-popup-dialog :type="msgType" title="通知" content="欢迎使用 uni-popup!" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog> |
|
</uni-popup> |
|
</view> |
|
|
|
<view> |
|
<!-- 输入框示例 --> |
|
<uni-popup ref="inputDialog" type="dialog"> |
|
<uni-popup-dialog ref="inputClose" mode="input" title="输入内容" value="对话框预置提示内容!" :beforeClose="true" placeholder="请输入内容" @confirm="dialogInputConfirm"></uni-popup-dialog> |
|
</uni-popup> |
|
</view> |
|
|
|
<view> |
|
<!-- 分享示例 --> |
|
<uni-popup ref="share" background-color="#fff" type="share"> |
|
<uni-popup-share></uni-popup-share> |
|
</uni-popup> |
|
</view> |
|
</view> |
|
</template> |
|
|
|
<script> |
|
export default { |
|
data() { |
|
return { |
|
type: 'center', |
|
msgType: 'success', |
|
messageText: '这是一条成功提示', |
|
value: '' |
|
} |
|
}, |
|
onReady() {}, |
|
methods: { |
|
change(e) { |
|
console.log('当前模式:' + e.type + ',状态:' + e.show); |
|
}, |
|
toggle(type) { |
|
this.type = type |
|
// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性 |
|
this.$refs.popup.open(type) |
|
}, |
|
messageToggle(type) { |
|
this.msgType = type |
|
this.messageText = `这是一条${type}消息提示` |
|
this.$refs.message.open() |
|
}, |
|
dialogToggle(type) { |
|
this.msgType = type |
|
this.$refs.alertDialog.open() |
|
}, |
|
dialogConfirm() { |
|
console.log('点击确认') |
|
this.messageText = `点击确认了 ${this.msgType} 窗口` |
|
this.$refs.message.open() |
|
}, |
|
inputDialogToggle() { |
|
this.$refs.inputDialog.open() |
|
}, |
|
dialogClose() { |
|
console.log('点击关闭') |
|
}, |
|
dialogInputConfirm(val) { |
|
uni.showLoading({ |
|
title: '3秒后会关闭' |
|
}) |
|
|
|
setTimeout(() => { |
|
uni.hideLoading() |
|
console.log(val) |
|
this.value = val |
|
// 关闭窗口后,恢复默认内容 |
|
this.$refs.inputDialog.close() |
|
}, 3000) |
|
}, |
|
shareToggle() { |
|
this.$refs.share.open() |
|
} |
|
} |
|
} |
|
</script> |
|
<style> |
|
@charset "UTF-8"; |
|
|
|
/* 头条小程序组件内不能引入字体 */ |
|
/* #ifdef MP-TOUTIAO */ |
|
@font-face { |
|
font-family: uniicons; |
|
font-weight: normal; |
|
font-style: normal; |
|
src: url("~@/static/uni.ttf") format("truetype"); |
|
} |
|
|
|
/* #endif */ |
|
/* #ifndef APP-NVUE */ |
|
page { |
|
display: flex; |
|
flex-direction: column; |
|
box-sizing: border-box; |
|
background-color: #efeff4; |
|
min-height: 100%; |
|
height: auto; |
|
} |
|
|
|
view { |
|
font-size: 14px; |
|
line-height: inherit; |
|
} |
|
|
|
.example { |
|
padding: 0 15px 15px; |
|
} |
|
|
|
.example-info { |
|
padding: 15px; |
|
color: #3b4144; |
|
background: #ffffff; |
|
} |
|
|
|
.example-body { |
|
/* #ifndef APP-NVUE */ |
|
display: flex; |
|
/* #endif */ |
|
flex-direction: row; |
|
flex-wrap: wrap; |
|
justify-content: center; |
|
padding: 0; |
|
font-size: 14px; |
|
background-color: #ffffff; |
|
} |
|
|
|
/* #endif */ |
|
.example { |
|
padding: 0 15px; |
|
} |
|
|
|
.example-info { |
|
/* #ifndef APP-NVUE */ |
|
display: block; |
|
/* #endif */ |
|
padding: 15px; |
|
color: #3b4144; |
|
background-color: #ffffff; |
|
font-size: 14px; |
|
line-height: 20px; |
|
} |
|
|
|
.example-info-text { |
|
font-size: 14px; |
|
line-height: 20px; |
|
color: #3b4144; |
|
} |
|
|
|
.example-body { |
|
flex-direction: column; |
|
padding: 15px; |
|
background-color: #ffffff; |
|
} |
|
|
|
.word-btn-white { |
|
font-size: 18px; |
|
color: #FFFFFF; |
|
} |
|
|
|
.word-btn { |
|
/* #ifndef APP-NVUE */ |
|
display: flex; |
|
/* #endif */ |
|
flex-direction: row; |
|
align-items: center; |
|
justify-content: center; |
|
border-radius: 6px; |
|
height: 48px; |
|
margin: 15px; |
|
background-color: #007AFF; |
|
} |
|
|
|
.word-btn--hover { |
|
background-color: #4ca2ff; |
|
} |
|
|
|
.box { |
|
/* #ifndef APP-NVUE */ |
|
display: flex; |
|
/* #endif */ |
|
flex-direction: row; |
|
} |
|
|
|
.button { |
|
/* #ifndef APP-NVUE */ |
|
display: flex; |
|
/* #endif */ |
|
flex-direction: row; |
|
align-items: center; |
|
justify-content: center; |
|
flex: 1; |
|
height: 35px; |
|
margin: 0 5px; |
|
border-radius: 5px; |
|
} |
|
|
|
.button-text { |
|
color: #fff; |
|
font-size: 12px; |
|
} |
|
|
|
.popup-content { |
|
/* #ifndef APP-NVUE */ |
|
display: flex; |
|
/* #endif */ |
|
flex-direction: row; |
|
align-items: center; |
|
justify-content: center; |
|
padding: 15px; |
|
height: 50px; |
|
background-color: #fff; |
|
} |
|
|
|
.popup-height { |
|
/* #ifndef APP-NVUE */ |
|
height: 100%; |
|
/* #endif */ |
|
/* #ifdef APP-NVUE */ |
|
flex: 1; |
|
/* #endif */ |
|
width: 200px; |
|
} |
|
|
|
.text { |
|
font-size: 12px; |
|
color: #333; |
|
} |
|
|
|
.popup-success { |
|
color: #fff; |
|
background-color: #e1f3d8; |
|
} |
|
|
|
.popup-warn { |
|
color: #fff; |
|
background-color: #faecd8; |
|
} |
|
|
|
.popup-error { |
|
color: #fff; |
|
background-color: #fde2e2; |
|
} |
|
|
|
.popup-info { |
|
color: #fff; |
|
background-color: #f2f6fc; |
|
} |
|
|
|
.success-text { |
|
color: #09bb07; |
|
} |
|
|
|
.warn-text { |
|
color: #e6a23c; |
|
} |
|
|
|
.error-text { |
|
color: #f56c6c; |
|
} |
|
|
|
.info-text { |
|
color: #909399; |
|
} |
|
|
|
.dialog, |
|
.share { |
|
/* #ifndef APP-NVUE */ |
|
display: flex; |
|
/* #endif */ |
|
flex-direction: column; |
|
} |
|
|
|
.dialog .button, |
|
.share .button { |
|
/* #ifndef APP-NVUE */ |
|
width: 100%; |
|
/* #endif */ |
|
margin: 0; |
|
margin-top: 10px; |
|
padding: 3px 0; |
|
flex: 1; |
|
} |
|
|
|
.dialog-text { |
|
font-size: 14px; |
|
color: #333; |
|
} |
|
</style> |