popup.vue 1.58 KB
Newer Older
mengcuiguang's avatar
mengcuiguang committed
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
<template>
  <view :class="'popup-mask ' + (showClone ? 'popup-mask-active' : '')" @click.stop.prevent="">
    <view class="popup-content">
      <view class="popup-body"><slot></slot></view>
      <icons v-if="close" icon="close" size="64" color="white" @click="handleClose" />
    </view>
  </view>
</template>

<script>
export default {
  name: 'popup',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    close: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      showClone: false
    };
  },
  methods: {
    handleClose() {
      this.showClone = false;
      this.$emit('close');
    }
  },
  watch: {
    show: {
      handler: function(newVal, oldVal) {
        this.showClone = newVal;
      },
      immediate: true
    }
  }
};
</script>

<style lang="scss">
.popup {
  position: fixed;
  z-index: 1002;
  left: 75rpx;
  right: 75rpx;
  top: 50%;
  padding: 0;
  display: none;
  transform: translate(0, -50%);
  backface-visibility: hidden;

  &-content {
    position: relative;
    top: 50%;
    transform: translateY(-50%);
    text-align: center;
  }

  &-body {
    border-radius: 32rpx;
    // overflow: hidden;
    // background-color: #323231;
    margin-bottom: 40rpx;
    position: relative;
    z-index: -1;
  }

  &-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    background-color: rgba(0, 0, 0, 0.8);
    opacity: 0;
    transform: scale3d(1, 1, 0);
    transition: all 0.3s;
    padding: 77rpx;
    &-active {
      opacity: 1;
      transform: scale3d(1, 1, 1);
    }
  }
}
</style>