MyDialog.vue 2.7 KB
<template>
  <div class="my-popup" v-if="isShow">
    <div class="mask-view"></div>
    <div class="popup-content">
      <div class="popup-title">{{ title }}</div>
      <div class="popup-description" v-if="descriptionType === ''">{{ description }}</div>
      <div class="popup-description" v-if="descriptionType === 'html'" v-html="description"></div>
      <div class="popup-btn-list">
        <div class="btn" v-if="showCancelBtn" @click="_cancel">{{ cancelBtnText }}</div>
        <div class="btn" v-if="showOkBtn" @click="_ok">{{ okBtnText }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyPopup',
  props: {
    showPopup: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    title: {
      type: String,
      default: '提示'
    },
    description: {
      type: String,
      default: '内容'
    },
    descriptionType: {
      type: String,
      default: ''
    },
    showOkBtn: {
      type: Boolean,
      default: () => {
        return true
      }
    },
    showCancelBtn: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    okBtnText: {
      type: String,
      default: '确定'
    },
    cancelBtnText: {
      type: String,
      default: '取消'
    },
    okClose: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  watch: {
    showPopup(newVal) {
      this.isShow = newVal
    }
  },
  created() {
    this.isShow = this.showPopup
  },
  data() {
    return {
      isShow: false
    }
  },
  methods: {
    _ok() {
      if (this.okClose) {
        this.isShow = false
      }
      this.$emit('ok')
    },
    _cancel() {
      this.isShow = false
      // this.$emit('cancel')
    }
  }
}
</script>

<style lang="scss" scoped>
.my-popup {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 999;
  .mask-view {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: #000;
    opacity: 0.5;
    z-index: 10;
  }
  .popup-content {
    position: fixed;
    left: 20px;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background-color: #fff;
    border-radius: 14px;
    z-index: 11;
    .popup-title {
      font-size: 16px;
      font-weight: bold;
      height: 44px;
      line-height: 44px;
      text-align: center;
      border-bottom: 1px solid #ededed;
    }
    .popup-description {
      padding: 15px;
    }
    .popup-btn-list {
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-top: 1px solid #ededed;
      .btn {
        flex: 1;
        text-align: center;
        height: 44px;
        line-height: 44px;
        font-size: 14px;
      }
    }
  }
}
</style>