# All files index.ts

0% Statements 0/35
0% Branches 0/28
0% Functions 0/6
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105

     import { defineComponentHOC, Doraemon, Component, Prop, Watch } from '@doraemon-ui/miniprogram.core-js'
    const { classNames } = Doraemon.util

    @Component({
      props: {
        prefixCls: {
          type: String,
          default: 'dora-backdrop',
        },
      },
    })
    class Backdrop extends Doraemon {
      /**
       * 自定义类名前缀
       *
       * @type {string}
       * @memberof Backdrop
       */
      prefixCls!: string

      @Prop({
        type: Boolean,
        default: false,
      })
      transparent: boolean

      @Prop({
        type: Number,
        default: 1000,
      })
      zIndex: number

      @Prop({
        type: null,
        default: 'dora-animate--fadeIn',
      })
      classNames: string

      get classes () {
        const { prefixCls, transparent } = this
        const wrap = classNames(prefixCls, {
          [`${prefixCls}--transparent`]: transparent,
        })

        return {
          wrap,
        }
      }

      /**
       * 是否显示蒙层
       *
       * @type {boolean}
       * @memberof Backdrop
       */
      visible: boolean = false

      @Watch('visible')
      onVisibleChange (visible: boolean) {
        if (visible) {
          this.$emit('afterShow')
        } else {
          this.$emit('afterClose')
        }
      }

      /**
       * 锁定蒙层的次数
       *
       * @type {number}
       * @memberof Backdrop
       */
      backdropHolds: number = 0

      /**
       * 保持锁定
       *
       * @memberof Backdrop
       */
      retain() {
        this.backdropHolds = this.backdropHolds + 1
        if (this.backdropHolds === 1) {
          this.visible = true
        }
      }

      /**
       * 释放锁定
       *
       * @memberof Backdrop
       */
      release() {
        if (this.backdropHolds === 1) {
          this.visible = false
        }
        this.backdropHolds = Math.max(0, this.backdropHolds - 1)
      }

      onClick () {
        this.$emit('click')
      }
    }

    export default defineComponentHOC()(Backdrop)