123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- <template>
- <view>
- <text class="example-info">弹出层组件用于弹出一个覆盖到页面上的内容,使用场景如:底部弹出分享弹窗、页面插屏广告等。</text>
- <uni-section title="基本示例" type="line"></uni-section>
- <view class="example-body message">
- <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>
- </view>
- <uni-section title="自定义弹出层(dialog + message) 示例" type="line"></uni-section>
- <view class="example-body message">
- <button class="button popup__success" @click="toggleMessage('success')"><text class="button-text">成功</text></button>
- <button class="button popup__error" @click="toggleMessage('error')"><text class="button-text">错误</text></button>
- <button class="button popup__warn" @click="toggleMessage('warn')"><text class="button-text">警告</text></button>
- <button class="button popup__info" @click="toggleMessage('info')"><text class="button-text">信息</text></button>
- </view>
- <uni-section title="提交信息 (input + 延迟关闭)" type="line"></uni-section>
- <view class="example-body dialog">
- <view class="dialog-box">
- <text class="dialog-text">输入内容:{{value}}</text>
- </view>
- <button class="button" type="primary" @click="confirmDialog"><text class="button-text">输入对话框</text></button>
- </view>
- <uni-section title="底部分享示例" type="line"></uni-section>
- <view class="example-body share">
- <button class="button" type="primary" @click="confirmShare"><text class="button-text">分享模版示例</text></button>
- </view>
- <!-- 基本示例 -->
- <uni-popup id="popup" ref="popup" :type="type" :animation="false" @change="change">
- <view class="popup-content">popup 内容,此示例没有动画效果</view>
- </uni-popup>
- <!-- 消息提示 -->
- <uni-popup id="popupMessage" ref="popupMessage" type="message" @change="change">
- <uni-popup-message :type="msgType" :message="message" :duration="2000"></uni-popup-message>
- </uni-popup>
- <!-- 对话框 -->
- <uni-popup id="popupDialog" ref="popupDialog" type="dialog" @change="change">
- <uni-popup-dialog :type="msgType" title="通知" content="欢迎使用 uni-popup!" :before-close="true" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
- </uni-popup>
- <!-- 提交信息 -->
- <uni-popup id="dialogInput" ref="dialogInput" type="dialog" @change="change">
- <uni-popup-dialog mode="input" title="输入内容" value="对话框预置提示内容!" placeholder="请输入内容" @confirm="dialogInputConfirm"></uni-popup-dialog>
- </uni-popup>
- <!-- 分享示例 -->
- <uni-popup id="popupShare" ref="popupShare" type="share" @change="change">
- <uni-popup-share title="分享到" @select="select"></uni-popup-share>
- </uni-popup>
- </view>
- </template>
- <script>
- // import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
- // import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
- // import uniPopupShare from '@/components/uni-popup/uni-popup-share.vue'
- export default {
- // components: {
- // uniPopupMessage,
- // uniPopupDialog,
- // uniPopupShare
- // },
- data() {
- return {
- type: 'top',
- msgType: 'success',
- message: '这是一条成功消息提示',
- value: '默认输入的内容'
- }
- },
- onReady() {
- // 页面打开自动打开对话框
- setTimeout(() => {
- this.msgType = 'success'
- this.$refs.popupDialog.open()
- }, 500)
- },
- methods: {
- /**
- * 打开基础内容
- */
- toggle(type) {
- this.type = type
- this.$refs.popup.open()
- },
- /**
- * 打开消息提示
- * @param {Object} type
- */
- toggleMessage(type) {
- this.msgType = type
- switch (type) {
- case 'success':
- this.message = '这是一条成功消息提示'
- break
- case 'warn':
- this.message = '这是一条警告消息提示'
- break
- case 'info':
- this.message = '这是一条消息提示'
- break
- case 'error':
- this.message = '这是一条错误消息提示'
- break
- }
- this.$refs.popupDialog.open()
- },
- /**
- * 打开提交信息
- */
- confirmDialog() {
- this.$refs.dialogInput.open()
- },
- /**
- * 分享模版
- */
- confirmShare() {
- this.$refs.popupShare.open()
- },
- /**
- * 选择内容
- */
- select(e, done) {
- uni.showToast({
- title: `您选择了第${e.index+1}项:${e.item.text}`,
- icon: 'none'
- })
- done()
- },
- /**
- * 对话框点击确认按钮
- */
- dialogConfirm(done) {
- this.$refs.popupMessage.open()
- console.log('点击确认');
- // 需要执行 done 才能关闭对话框
- done()
- },
- /**
- * 输入对话框的确定事件
- */
- dialogInputConfirm(done, val) {
- uni.showLoading({
- title: '3秒后会关闭'
- })
- console.log(val);
- this.value = val
- setTimeout(() => {
- uni.hideLoading()
- // 关闭窗口后,恢复默认内容
- done()
- }, 3000)
- },
- /**
- * 对话框取消按钮
- */
- dialogClose(done) {
- this.msgType = 'info'
- this.message = '点击了对话框的取消按钮'
- this.$refs.popupMessage.open()
- // 需要执行 done 才能关闭对话框
- done()
- },
- /**
- * popup 状态发生变化触发
- * @param {Object} e
- */
- change(e) {
- console.log('popup ' + e.type + ' 状态', e.show)
- },
- },
- /**
- * 拦截应用返回事件,仅仅 app 端生效
- */
- onBackPress() {
- }
- }
- </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;
- }
- .example-body {
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- padding: 5px 15px;
- }
- .popup-content {
- background-color: #fff;
- padding: 15px;
- }
- /* #ifndef APP-NVUE */
- .button {
- margin: 0;
- padding: 0;
- line-height: 1;
- }
- /* #endif */
- .button {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- align-items: center;
- justify-content: center;
- flex: 1;
- height: 40px;
- margin: 0 15px;
- }
- .button-text {
- color: #fff;
- font-size: 14px;
- }
- .message {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- justify-content: center;
- padding: 15px 0;
- }
- .dialog {
- padding: 15px 0;
- }
- .dialog-box {
- margin-left: 15px;
- margin-bottom: 15px;
- }
- .dialog-text {
- font-size: 14px;
- color: #666;
- }
- .share {
- padding: 15px 0;
- }
- .popup__success {
- color: #fff;
- background-color: #4cd964;
- }
- .popup__warn {
- color: #fff;
- background-color: #f0ad4e;
- }
- .popup__error {
- color: #fff;
- background-color: #dd524d;
- }
- .popup__info {
- color: #fff;
- background-color: #909399;
- }
- </style>
|