微信小程序弹框之cover-view

微信小程序弹框之cover-view
1: 最近商户端小程序有个需求涉及到textarea,在textarea上方会有个弹框的交互效果,因为textarea是原生组件,层级比较高,一般的设置view的z-index是没有效果的,会造成如下的情况 (会导致点击textarea的时候,依旧可以点击):
1.jpeg
2.jpeg
2: 如果想在页面上,设置更高层级的视图且保证不被textarea覆盖,那么就需要使用cover-view了。由于项目需求是点击提价预约按钮,显示弹窗提示,预期效果如下:
3.jpeg
3: cover-view简述
cover-view 在小程序中是比较特殊的组件,与 view 的最大区别在于,它能覆盖在原生组件 map、video、canvas、camera、textarea 之上,且只能嵌套 cover-view 和 cover-image, 如果项目有这张需求,cover-view是一种行之有效的解决方法.
4: 针对上面的描述, 具体的代码如下

(1) wxml代码如下

<textarea name="{{item.name}}" class="textarea_02" bindblur="onRemarkInput" bindinput="textAreaChange" value="{{user_note}}" placeholder-class="fs28 lh20" style="margin-top: {{systemPlatform =='iOS' ? '-12rpx':'0'}}" placeholder="输入您想说的话">

     <template is="paybulletCoverView" data="{{orders: orders, isShow:isShow}}"></template>

</textarea>
<template name="paybulletCoverView">

    <cover-view class="pop-up-textarea-bg" wx:if="{{isShow}}"> 
       <cover-view class="pop-up-textarea-container">
            <cover-view class="top-view">
                <cover-view class="title">支付</cover-view>
                <cover-image bindtap="onCancelOrderPay" class="cancel" src="https://yunshang.365jia.cn/assets/images/weixin_product_ico/ico_grep_delete.png"></cover-image>
            </cover-view>
            <cover-view class="top-line-view"></cover-view>
            <cover-view class="pay-money-title">储值卡支付金额</cover-view>
            <cover-view class="pay-money-view">
                <cover-view class="symbol">¥</cover-view>
                <cover-view class="price">{{orders.total_price}}</cover-view>
            </cover-view>
            <cover-view class="line-view"></cover-view>
            <cover-view class="pet-card-view">
                <cover-image class="icon" src="{{orders.logo}}"></cover-image>
                <cover-view class="title">储值卡</cover-view>
            </cover-view>
            <cover-view class="line-view"></cover-view>
            <cover-view bindtap="onSubmitOrder" class="bottom-make-sure-button"> 确认支付</cover-view>
        </cover-view>
    </cover-view>
</template>

(2) wxss代码如下:

.pop-up-textarea-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.pop-up-textarea-container {
  position: fixed;
  top: 300rpx;
  left: 85rpx;
  width: 580rpx;
  height: 560rpx;
  background-color: #fff;
  border-radius: 8rpx;
  color: #666;
  font-size: 28rpx;
}

.top-view {
  height: 98rpx;
  width: 100%;
  display: flex;
  position: relative;
  align-items: center;
  justify-content: center;
  background-color: #fff;
}

.top-view .title {
  height: 98rpx;
  line-height: 98rpx;
  width: 100%;
  font-size: 36rpx;
  text-align: center;
}

.top-view .cancel {
  position: absolute;
  width: 60rpx;
  height: 60rpx;
  right: 20rpx;
  top:50%;
  transform: translateY(-50%);
}

.line-view, .top-line-view {
  width: 100%;
  height: 2rpx;
  background-color: #eeeeee
}

.top-line-view {
  background-color: #39cc6a
}

.pay-money-title {
  width: 100%;
  height: 98rpx;
  line-height: 98rpx;
  color: #333333;
  font-size: 32;
  text-align: center;
}

.pay-money-view {
  height: 60rpx;
  margin: 36rpx 30rpx 20rpx;
  justify-content: center;
  display: flex;
}

.pay-money-view .symbol {
  width: 33%;
  height: 40rpx;
  line-height: 40rpx;
  margin-top: 20rpx;
  font-size: 30rpx;
  text-align: right;
}

.pay-money-view .price {
  width: 67%;
  height: 60rpx;
  line-height: 60rpx;
  margin-left: 10rpx;
  color: #000;
  font-size: 60rpx;
  text-align: left;
}

.pet-card-view {
  height: 86rpx;
  margin-left: 30rpx;
  margin-right: 30rpx;
  align-items: center;
  display: flex;
}

.pet-card-view .icon{
  width:46rpx;
  height:46rpx;
  border-radius:23rpx
}

.pet-card-view .title{
  width: 200rpx;
  height: 46rpx;
  line-height: 46rpx;
  margin: 20rpx;
  color: #6E726E;
  text-align: left;
}

.bottom-make-sure-button {
  height: 92rpx;
  line-height: 92rpx;
  margin: 40rpx 30rpx 20rpx;
  background-color: #06C160;
  border-radius: 8rpx;
  color: #fff;
  justify-content: center;
  align-items: center;
  text-align: center;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容