收藏
回答

page-container组件 怎么设置禁止点击遮盖层关闭?

page-container 默认点击遮盖层会关闭组件,怎么才能设置禁止点击遮盖层关闭组件?

回答关注问题邀请回答
收藏

8 个回答

  • 神经蛙
    神经蛙
    2022-01-20

    把 page-container 铺满整个页面,自己做遮罩层

    2022-01-20
    有用 1
    回复 6
    • 大雷老师🌅
      大雷老师🌅
      2022-05-22
      请教下,怎么铺满整个页面
      2022-05-22
      回复
    • ______Yu、帅气™💋
      ______Yu、帅气™💋
      2022-08-26回复大雷老师🌅
      2022-08-26
      1
      回复
    • 大雷老师🌅
      大雷老师🌅
      2022-08-30
      谢谢
      2022-08-30
      回复
    • 自来也大人
      自来也大人
      2023-06-08
      可以的
      2023-06-08
      回复
    • 生生
      生生
      2023-08-20回复______Yu、帅气™💋
      牛,正需要这个,感谢
      2023-08-20
      回复
    查看更多(1)
  • Sen
    Sen
    2024-07-31
    <!--components/w-popup/w-popup.wxml-->
    <view
     class="w-popup-wrapper"
     wx:if="{{showComputed}}"
    >
      <page-container
       custom-style="background-color: rgba(0, 0, 0, 0);"
       show="{{visable}}"
       overlay="{{false}}"
       z-index="{{zIndex}}"
       close-on-slide-down="{{false}}"
       bind:clickoverlay="closeOnMask"
       bind:beforeenter="beforeEnter"
       bind:afterleave="afterLeave"
       bind:beforeleave="beforeleave"
      >
        <view class="w-popup {{ show ? 'w-popup-show' : 'w-popup-close'}}">
          <view class="w-popup-content">
            <view
             class="w-popup-content-bottom-nav"
             wx:if="{{position === 'bottom' && showBottomNav }}"
            >
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-left"
               bind:tap="close"
              >
                取消
              </view>
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-right"
               bind:tap="confirm"
              >
                确定
              </view>
            </view>
            <view class="w-popup-content-bottom-slot">
              <slot/>
            </view>
          </view>
        </view>
      </page-container>
      <view
       bind:tap="closeOnMask"
       style="z-index: {{zIndex - 1}};"
       class="w-popup-overlay {{visable ? 'w-popup-overlay-show' : 'w-popup-overlay-close'}}"
      />
    </view>
    
    
    2024-07-31
    有用
    回复
  • Sen
    Sen
    2024-07-31
    <!--components/w-popup/w-popup.wxml-->
    <view
     class="w-popup-wrapper"
     wx:if="{{showComputed}}"
    >
      <page-container
       custom-style="background-color: rgba(0, 0, 0, 0);"
       show="{{visable}}"
       overlay="{{false}}"
       z-index="{{zIndex}}"
       close-on-slide-down="{{false}}"
       bind:clickoverlay="closeOnMask"
       bind:beforeenter="beforeEnter"
       bind:afterleave="afterLeave"
       bind:beforeleave="beforeleave"
      >
        <view class="w-popup {{ show ? 'w-popup-show' : 'w-popup-close'}}">
          <view class="w-popup-content">
            <view
             class="w-popup-content-bottom-nav"
             wx:if="{{position === 'bottom' && showBottomNav }}"
            >
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-left"
               bind:tap="close"
              >
                取消
              </view>
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-right"
               bind:tap="confirm"
              >
                确定
              </view>
            </view>
            <view class="w-popup-content-bottom-slot">
              <slot/>
            </view>
          </view>
        </view>
      </page-container>
      <view
       bind:tap="closeOnMask"
       style="z-index: {{zIndex - 1}};"
       class="w-popup-overlay {{visable ? 'w-popup-overlay-show' : 'w-popup-overlay-close'}}"
      />
    </view>
    
    
    
    
    
    2024-07-31
    有用
    回复
  • Sen
    Sen
    2024-07-31

    代码片段

    2024-07-31
    有用
    回复
  • Sen
    Sen
    2024-07-31
    <!--components/w-popup/w-popup.wxml-->
    <view
     class="w-popup-wrapper"
     wx:if="{{showComputed}}"
    >
      <page-container
       custom-style="background-color: rgba(0, 0, 0, 0);"
       show="{{visable}}"
       overlay="{{false}}"
       z-index="{{zIndex}}"
       close-on-slide-down="{{false}}"
       bind:clickoverlay="closeOnMask"
       bind:beforeenter="beforeEnter"
       bind:afterleave="afterLeave"
       bind:beforeleave="beforeleave"
      >
        <view class="w-popup {{ show ? 'w-popup-show' : 'w-popup-close'}}">
          <view class="w-popup-content">
            <view
             class="w-popup-content-bottom-nav"
             wx:if="{{position === 'bottom' && showBottomNav }}"
            >
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-left"
               bind:tap="close"
              >
                取消
              </view>
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-right"
               bind:tap="confirm"
              >
                确定
              </view>
            </view>
            <view class="w-popup-content-bottom-slot">
              <slot/>
            </view>
          </view>
        </view>
      </page-container>
      <view
       bind:tap="closeOnMask"
       style="z-index: {{zIndex - 1}};"
       class="w-popup-overlay {{visable ? 'w-popup-overlay-show' : 'w-popup-overlay-close'}}"
      />
    </view>
    
    
    
    2024-07-31
    有用
    回复
  • Sen
    Sen
    2024-07-31
    <!--components/w-popup/w-popup.wxml-->
    <view
     class="w-popup-wrapper"
     wx:if="{{showComputed}}"
    >
      <page-container
       custom-style="background-color: rgba(0, 0, 0, 0);"
       show="{{visable}}"
       overlay="{{false}}"
       z-index="{{zIndex}}"
       close-on-slide-down="{{false}}"
       bind:clickoverlay="closeOnMask"
       bind:beforeenter="beforeEnter"
       bind:afterleave="afterLeave"
       bind:beforeleave="beforeleave"
      >
        <view class="w-popup {{ show ? 'w-popup-show' : 'w-popup-close'}}">
          <view class="w-popup-content">
            <view
             class="w-popup-content-bottom-nav"
             wx:if="{{position === 'bottom' && showBottomNav }}"
            >
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-left"
               bind:tap="close"
              >
                取消
              </view>
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-right"
               bind:tap="confirm"
              >
                确定
              </view>
            </view>
            <view class="w-popup-content-bottom-slot">
              <slot/>
            </view>
          </view>
        </view>
      </page-container>
      <view
       bind:tap="closeOnMask"
       style="z-index: {{zIndex - 1}};"
       class="w-popup-overlay {{visable ? 'w-popup-overlay-show' : 'w-popup-overlay-close'}}"
      />
    </view>
    
    import { ComponentWithComputed } from 'miniprogram-computed'
    
    
    // components/w-popup/w-popup.ts
    ComponentWithComputed({
    
    
      /**
       * 组件的属性列表
       */
      properties: {
        show: {
          type: Boolean,
          value: false
        },
        position: {
          type: String,
          value: 'bottom'
        },
        closeOnClickMask: {
          type: Boolean,
          value: true
        },
        showBottomNav: {
          type: Boolean,
          value: true
        },
        zIndex: {
          type: Number,
          value: 500
        }
      },
    
    
      computed: {
        showComputed(data) {
          return data.visable || data.closing
        }
      },
    
    
      watch: {
        show() {
          const closing = !this.data.show
          const data = Object.assign({}, { visable: this.data.show }, !this.data.show ? { closing } : {})
          this.setData(data)
        }
      },
    
    
      /**
       * 组件的初始数据
       */
      data: {
        visable: false,
        closing: false
      },
    
    
      /**
       * 组件的方法列表
       */
      methods: {
        async close() {
          this.beforeleave()
        },
        confirm() {
          this.triggerEvent('confirm')
        },
        closeOnMask() {
          this.triggerEvent('clickOverlay')
          if (this.data.closeOnClickMask) this.close()
        },
        beforeEnter() {
          this.triggerEvent('beforeEnter')
        },
        afterLeave() {
          this.setData({ closing: false })
          this.triggerEvent('closed', false)
          this.triggerEvent('afterLeave')
        },
        beforeleave() {
          if (this.data.visable) {
            this.triggerEvent('close', false)
            this.triggerEvent('beforeleave', false)
          }
        }
      }
    })
    
    /* components/w-popup/w-popup.wxss */
    .w-popup {
      position: relative;
      @keyframes identifier {
        0% {
          opacity: 0;
        }
        100% {
          opacity: 1;
        }
      }
      z-index: 10;
      &-overlay {
        position: fixed;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0, 0.7);
        transition: all 300ms;
        animation: identifier 300ms forwards;
        &-close {
          opacity: 0;
        }
      }
      &-content {
        width: 100%;
        background: var(--background);
        transition: all 300ms;
        border-radius: 28rpx 28rpx 0 0;
        overflow: hidden;
        .hover {
          opacity: var(--active-opacity);
        }
        &-bottom {
          &-nav {
            display: flex;
            justify-content: space-between;
            padding: 56rpx 34rpx;
            & > view {
              &:active {
                opacity: var(--active-opacity);
              }
            }
            &-left {
              color: var(--text-color-lighter);
            }
            &-right {
              color: var(--primary);
            }
          }
          &-slot {
            height: fit-content;
          }
        }
      }
    }
    
    
    
    
    2024-07-31
    有用
    回复
  • Sen
    Sen
    2024-07-31
    <!--components/w-popup/w-popup.wxml-->
    <view
     class="w-popup-wrapper"
     wx:if="{{showComputed}}"
    >
      <page-container
       custom-style="background-color: rgba(0, 0, 0, 0);"
       show="{{visable}}"
       overlay="{{false}}"
       z-index="{{zIndex}}"
       close-on-slide-down="{{false}}"
       bind:clickoverlay="closeOnMask"
       bind:beforeenter="beforeEnter"
       bind:afterleave="afterLeave"
       bind:beforeleave="beforeleave"
      >
        <view class="w-popup {{ show ? 'w-popup-show' : 'w-popup-close'}}">
          <view class="w-popup-content">
            <view
             class="w-popup-content-bottom-nav"
             wx:if="{{position === 'bottom' && showBottomNav }}"
            >
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-left"
               bind:tap="close"
              >
                取消
              </view>
              <view
               hover-class="hover"
               hover-start-time="{{20}}"
               hover-stay-time="{{100}}"
               class="w-popup-content-bottom-nav-right"
               bind:tap="confirm"
              >
                确定
              </view>
            </view>
            <view class="w-popup-content-bottom-slot">
              <slot/>
            </view>
          </view>
        </view>
      </page-container>
      <view
       bind:tap="closeOnMask"
       style="z-index: {{zIndex - 1}};"
       class="w-popup-overlay {{visable ? 'w-popup-overlay-show' : 'w-popup-overlay-close'}}"
      />
    </view>
    
    import { ComponentWithComputed } from 'miniprogram-computed'
    
    
    // components/w-popup/w-popup.ts
    ComponentWithComputed({
    
    
      /**
       * 组件的属性列表
       */
      properties: {
        show: {
          type: Boolean,
          value: false
        },
        position: {
          type: String,
          value: 'bottom'
        },
        closeOnClickMask: {
          type: Boolean,
          value: true
        },
        showBottomNav: {
          type: Boolean,
          value: true
        },
        zIndex: {
          type: Number,
          value: 500
        }
      },
    
    
      computed: {
        showComputed(data) {
          return data.visable || data.closing
        }
      },
    
    
      watch: {
        show() {
          const closing = !this.data.show
          const data = Object.assign({}, { visable: this.data.show }, !this.data.show ? { closing } : {})
          this.setData(data)
        }
      },
    
    
      /**
       * 组件的初始数据
       */
      data: {
        visable: false,
        closing: false
      },
    
    
      /**
       * 组件的方法列表
       */
      methods: {
        async close() {
          this.beforeleave()
        },
        confirm() {
          this.triggerEvent('confirm')
        },
        closeOnMask() {
          this.triggerEvent('clickOverlay')
          if (this.data.closeOnClickMask) this.close()
        },
        beforeEnter() {
          this.triggerEvent('beforeEnter')
        },
        afterLeave() {
          this.setData({ closing: false })
          this.triggerEvent('closed', false)
          this.triggerEvent('afterLeave')
        },
        beforeleave() {
          if (this.data.visable) {
            this.triggerEvent('close', false)
            this.triggerEvent('beforeleave', false)
          }
        }
      }
    })
    
    /* components/w-popup/w-popup.wxss */
    .w-popup {
      position: relative;
      @keyframes identifier {
        0% {
          opacity: 0;
        }
        100% {
          opacity: 1;
        }
      }
      z-index: 10;
      &-overlay {
        position: fixed;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0, 0.7);
        transition: all 300ms;
        animation: identifier 300ms forwards;
        &-close {
          opacity: 0;
        }
      }
      &-content {
        width: 100%;
        background: var(--background);
        transition: all 300ms;
        border-radius: 28rpx 28rpx 0 0;
        overflow: hidden;
        .hover {
          opacity: var(--active-opacity);
        }
        &-bottom {
          &-nav {
            display: flex;
            justify-content: space-between;
            padding: 56rpx 34rpx;
            & > view {
              &:active {
                opacity: var(--active-opacity);
              }
            }
            &-left {
              color: var(--text-color-lighter);
            }
            &-right {
              color: var(--primary);
            }
          }
          &-slot {
            height: fit-content;
          }
        }
      }
    }
    
    
    
    
    2024-07-31
    有用
    回复
  • 算黄算割
    算黄算割
    2023-06-16

    真是奇技淫巧。。

    2023-06-16
    有用
    回复
登录 后发表内容