# All files index.ts

0% Statements 0/37
0% Branches 0/30
0% Functions 0/7
0% Lines 0/32

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
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142

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

    export type BackdropExpose = {
      backdropHolds: number
      retain: () => void
      release: () => void
    }

    export interface BackdropProps {
      prefixCls: string
      transparent: boolean
      zIndex: number
      classNames: string
      wrapStyle: object
    }

    export type BackdropInstance = ComponentPublicInstance<
      Backdrop,
      BackdropProps,
      BackdropExpose
    >

    @Component({
      props: {
        prefixCls: {
          type: String,
          default: 'dora-backdrop',
        },
      },
      expose: ['backdropHolds', 'retain', 'release']
    })
    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

      @Prop({
        type: Object,
        default: null,
      })
      wrapStyle: object

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

        return {
          wrap,
        }
      }

      /**
       * 组件样式
       *
       * @readonly
       * @memberof Backdrop
       */
      get extStyle () {
        return this.wrapStyle ? { ...this.wrapStyle, zIndex: this.zIndex } : { zIndex: this.zIndex }
      }

      /**
       * 是否显示蒙层
       *
       * @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)