"">弹窗
当前位置:   article > 正文

微信小程序自定义弹窗,默认同意活动规则_"

""

微信小程序自定义弹窗,默认同意活动规则
index.wxml

  1. <button class="show-btn" bindtap="showDialogBtn">弹窗</button>
  2. <!--弹窗-->
  3. <view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
  4. <view class="modal-dialog" wx:if="{{showModal}}">
  5.     <view class="modal-title">同意活动协议</view>
  6.     <view class="modal-content">
  7.         <checkbox-group bindchange="bindAcceptRule">
  8.             <label class="checkbox" >
  9.                 <checkbox value="同意" class="checkbox-size" checked="checked" color="#FFA200" />
  10.             </label>
  11.         </checkbox-group>
  12.         <view class="size-24">我已经阅读并接受 <navigator url="" class="rule-text">《活动协议》</navigator>
  13.         </view>
  14.     </view>
  15.     <view class="modal-footer">
  16.         <view class="btn-cancel" bindtap="onCancel" data-status="cancel">取消</view>
  17.         <view class="btn-confirm" bindtap="onConfirm" data-status="confirm">确定</view>
  18.     </view>
  19. </view>


index.wxss

  1. .show-btn {
  2.   margin-top: 100rpx;
  3.   color: #22cc22;
  4. }
  5. .modal-mask {
  6.   width: 100%;
  7.   height: 100%;
  8.   position: fixed;
  9.   top: 0;
  10.   left: 0;
  11.   background: #000;
  12.   opacity: 0.5;
  13.   overflow: hidden;
  14.   z-index: 9000;
  15.   color: #fff;
  16. }
  17. .modal-dialog {
  18.   width: 540rpx;
  19.   overflow: hidden;
  20.   position: fixed;
  21.   top: 50%;
  22.   left: 0;
  23.   z-index: 9999;
  24.   background: #f9f9f9;
  25.   margin: -180rpx 105rpx;
  26.   border-radius: 36rpx;
  27. }
  28. .modal-title {
  29.   padding-top: 50rpx;
  30.   font-size: 36rpx;
  31.   color: #030303;
  32.   text-align: center;
  33. }
  34. .modal-content {
  35.   padding: 50rpx 32rpx;
  36. }
  37. .modal-input {
  38.   display: flex;
  39.   background: #fff;
  40.   border: 2rpx solid #ddd;
  41.   border-radius: 4rpx;
  42.   font-size: 28rpx;
  43. }
  44. .input {
  45.   width: 100%;
  46.   height: 82rpx;
  47.   font-size: 28rpx;
  48.   line-height: 28rpx;
  49.   padding: 0 20rpx;
  50.   box-sizing: border-box;
  51.   color: #333;
  52. }
  53. input-holder {
  54.   color: #666;
  55.   font-size: 28rpx;
  56. }
  57. .modal-footer {
  58.   display: flex;
  59.   flex-direction: row;
  60.   height: 86rpx;
  61.   border-top: 1px solid #dedede;
  62.   font-size: 34rpx;
  63.   line-height: 86rpx;
  64. }
  65. .btn-cancel {
  66.   width: 50%;
  67.   color: #666;
  68.   text-align: center;
  69.   border-right: 1px solid #dedede;
  70. }
  71. .btn-confirm {
  72.   width: 50%;
  73.   color: #ec5300;
  74.   text-align: center;
  75. }
  76. .size-24 {
  77.   font-size: 24rpx;
  78.   display: flex;
  79.   margin-left: 50rpx;
  80.   margin-top: -34rpx;
  81. }
  82. .rule-text {
  83.   color: rgb(87, 107, 149);
  84. }
  85. checkbox-group {
  86.   margin-top: 20rpx;
  87. }
  88. /* 默认状态 */
  89. .checkbox .wx-checkbox-input {
  90.   border-radius: 32rpx; /* 圆角 */
  91.   width: 32rpx; /* 背景的宽 */
  92.   height: 32rpx; /* 背景的高 */
  93.   border: 2px solid rgba(255, 129, 92, 1);
  94. }
  95. /* 不可点击 */
  96. .checkbox .wx-checkbox-input-disabled {
  97.   border-radius: 32rpx; /* 圆角 */
  98.   width: 32rpx; /* 背景的宽 */
  99.   height: 32rpx; /* 背景的高 */
  100.   background: #f3f3f3;
  101.   border: 1px solid rgba(201, 201, 201, 1);
  102. }
  103. /* 选择后 */
  104. .checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  105.   background: rgba(255, 129, 92, 1);
  106. }
  107. /* 打勾样式 */
  108. .checkbox  .wx-checkbox-input.wx-checkbox-input-checked::before {
  109.   width: 32rpx;
  110.   height: 32rpx;
  111.   line-height: 32rpx;
  112.   text-align: center;
  113.   font-size: 24rpx;
  114.   color: #fff;
  115.   background: transparent;
  116.   transform: translate(-50%, -50%) scale(1);
  117.   -webkit-transform: translate(-50%, -50%) scale(1);
  118. }


index.js

  1. var app = getApp()
  2. Page({
  3.   data: {
  4.     showModal: false,
  5.     acceptRule: true
  6.   },
  7.   onLoad: function () {
  8.   },
  9.   // 同意规则
  10.   bindAcceptRule: function(e) {
  11.     console.log('picker发送选择改变,携带值为', e.detail.value)
  12.       if (e.detail.value.length !== 0) {
  13.         this.data.acceptRule = true
  14.       }else{
  15.         this.data.acceptRule = false
  16.       }
  17.   },
  18.   /**
  19.    * 弹窗
  20.    */
  21.   showDialogBtn: function () {
  22.     this.setData({
  23.       showModal: true
  24.     })
  25.   },
  26.   /**
  27.    * 弹出框蒙层截断touchmove事件
  28.    */
  29.   preventTouchMove: function () {
  30.   },
  31.   /**
  32.    * 隐藏模态对话框
  33.    */
  34.   hideModal: function () {
  35.     this.setData({
  36.       showModal: false
  37.     });
  38.   },
  39.   /**
  40.    * 对话框取消按钮点击事件
  41.    */
  42.   onCancel: function () {
  43.     this.hideModal();
  44.   },
  45.   /**
  46.    * 对话框确认按钮点击事件
  47.    */
  48.   onConfirm: function () {
  49.     if(this.data.acceptRule){
  50.       this.hideModal();
  51.     }else{
  52.       wx.showToast({
  53.         title: '请同意活动协议',
  54.         icon: 'none',
  55.       })
  56.     }
  57.   }
  58. })

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签