123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <template>
- <view class="container">
- <uni-card is-full :is-shadow="false">
- <text class="uni-h6">弹出层组件用于弹出一个覆盖到页面上的内容,使用场景如:底部弹出分享弹窗、页面插屏广告等。</text>
- </uni-card>
- <uni-section title="基本示例" type="line" sub-title="自定义顶部圆角">
- <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>
- <uni-section title="提示消息" type="line">
- <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>
- <uni-section title="对话框示例" type="line" class="hideOnPc">
- <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>
- <uni-section title="输入框示例" type="line" padding>
- <view class="dialog-box">
- <text class="dialog-text">输入内容:{{ value }}</text>
- </view>
- <button class="button" type="primary" @click="inputDialogToggle"><text class="button-text">输入对话框</text></button>
- </uni-section>
- <uni-section title="底部分享示例" type="line" padding>
- <button class="button" type="primary" @click="shareToggle"><text class="button-text">分享模版示例</text></button>
- </uni-section>
- <view>
- <!-- 普通弹窗 -->
- <uni-popup ref="popup" background-color="#fff" @change="change" border-radius="10px 10px 0 0">
- <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 :showClose="showClose" :type="msgType" cancelText="关闭" confirmText="同意" 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" :maxlength="10" mode="input" title="输入内容" v-model="value"
- placeholder="请输入内容,限制10个字" @confirm="dialogInputConfirm"></uni-popup-dialog>
- </uni-popup>
- </view>
- <view>
- <!-- 分享示例 -->
- <uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
- <uni-popup-share></uni-popup-share>
- </uni-popup>
- </view>
- </view>
- </template>
- <script setup>
- import { ref, reactive } from 'vue';
- // 定义响应式数据
- const state = reactive({
- type: 'center',
- msgType: 'success',
- messageText: '这是一条成功提示',
- showClose: true,
- });
- // 定义普通响应式变量
- const value = ref('');
- // 获取对uni-popup组件的引用
- const popup = ref(null);
- const message = ref(null);
- const alertDialog = ref(null);
- const inputDialog = ref(null);
- const share = ref(null);
- // 定义方法
- const change = (e) => {
- console.log('当前模式:' + e.type + ',状态:' + e.show);
- };
- const toggle = (type) => {
- state.type = type;
- // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
- popup.value.open(type);
- };
- const messageToggle = (type) => {
- state.msgType = type;
- state.messageText = `这是一条${type}消息提示`;
- message.value.open();
- };
- const dialogToggle = (type) => {
- state.msgType = type;
- alertDialog.value.open();
- };
- const dialogConfirm = () => {
- console.log('点击确认');
- state.messageText = `点击确认了 ${state.msgType} 窗口`;
- message.value.open();
- };
- const inputDialogToggle = () => {
- inputDialog.value.open();
- };
- const dialogClose = () => {
- console.log('点击关闭');
- };
- const dialogInputConfirm = (val) => {
- uni.showLoading({ title: '3秒后会关闭' });
- console.log(val); // 注意这里改为直接打印传入的值
- setTimeout(() => {
- uni.hideLoading();
- value.value = val;
- // 关闭窗口后,恢复默认内容
- inputDialog.value.close();
- }, 3000);
- };
- const shareToggle = () => {
- share.value.open();
- };
- </script>
- <style lang="scss">
- @mixin flex {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- }
- @mixin height {
- /* #ifndef APP-NVUE */
- height: 100%;
- /* #endif */
- /* #ifdef APP-NVUE */
- flex: 1;
- /* #endif */
- }
- .box {
- @include flex;
- }
- .button {
- @include flex;
- align-items: center;
- justify-content: center;
- flex: 1;
- height: 35px;
- margin: 0 5px;
- border-radius: 5px;
- }
- .example-body {
- background-color: #fff;
- padding: 10px 0;
- }
- .button-text {
- color: #fff;
- font-size: 12px;
- }
- .popup-content {
- @include flex;
- align-items: center;
- justify-content: center;
- padding: 15px;
- height: 50px;
- }
- .popup-height {
- @include height;
- 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-box {
- padding: 10px;
- }
- .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>
|