index.vue 3.94 KB
<template>
  <el-dialog id="baseDialog"
             top="15vh"
             :close-on-click-modal="false"
             :close-on-press-escape="true"
             :title="dialogConfig.title"
             :width="dialogConfig.width"
             :visible.sync="visible"
             :show-close="config.showClose"
             class="noborder"
             :append-to-body="config.appendToBody">
    <slot />
    <div slot="footer"
         v-if="config.isShowFooter">
      <el-button type="primary"
                 @click="confirmBtn"
                 :loading="$store.state.d2admin.loading.value || btnLoding">
        {{ config.confirm_name }}
      </el-button>
      <el-button v-preventReClick
                 @click="visible = false">
        {{ config.cancel_name }}
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: 'BaseDialog',
  directives: {
    // 函数节流 监控输入框 提高性能
    throttle: {
      // 指令的定义
      inserted: function (el, obj) {
        let timerId = null
        let flag = true
        el.addEventListener('click', function () {
          if (!flag) return
          flag = false
          timerId && clearTimeout(timerId)
          timerId = setTimeout(function () {
            flag = true
            // 调用绑定在v-throttle上的方法search
            obj.value()
          }, 1000)
        })
      }
    }
  },
  props: {
    dialogConfig: {
      required: false,
      type: Object,
      default: function () {
        return {
          title: '提示',
          width: '480px'
        }
      }
    },
    config: {
      required: false,
      type: Object,
      default: function () {
        return {
          showClose: true,
          appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
          isShowFooter: true,
          cancel_name: '取 消',
          confirm_name: '确 定'
        }
      }
    },
    isShow: {
      // 弹窗是否展示
      type: Boolean,
      default: false
    },
    btnLoding: {
      // 手动设置确定按钮loding
      type: Boolean,
      default: false
    }
    // width: {
    //   //弹窗宽度
    //   type: String,
    //   default: '',
    // },
    // cancel_name: {
    //   //取消按钮名称
    //   type: String,
    //   default: '取 消',
    // },
    // confirm_name: {
    //   //确定按钮名称
    //   type: String,
    //   default: '确 定',
    // },
    // isShowFooter: {
    //   //是否自定底部
    //   type: Boolean,
    //   default: true,
    // },
    // closeClick: {
    //   type: Boolean,
    //   default: false,
    // },
    // appendToBody: {
    //   // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
    //   type: Boolean,
    //   default: false,
    // },
  },
  data() {
    return {}
  },
  computed: {
    visible: {
      get() {
        return this.isShow
      },
      set(val) {
        this.$emit('update:isShow', false)
      }
    }
  },

  methods: {
    confirmBtn() {
      // 触发保存
      this.$emit('handleClick')
    }
  },
  created() {
    // console.log('baseDialog')
  },
  mounted() { }
}
</script>
<style scoped lang="scss">
::v-deep .el-dialog {
  // height: 90vh;
  border-radius: 6px;
  // padding: 0;
  overflow: hidden;

  .el-dialog__header {
    border-bottom: solid 1px #e6e6e6;
    border-radius: 6px 6px 0px 0px;
    padding: 18px 20px 18px 25px;

    .el-dialog__title {
      // color: #212121;
      color: #333333;
      font-family: PingFangSC-Medium;
      font-size: 20px;
      font-weight: 600;
      // font-weight: 16px;
    }

    .el-dialog__close {
      color: #666;
      font-weight: 600;
      font-size: 20px;
    }
  }

  .el-dialog__body {
    box-sizing: border-box;
    // padding-left: 25px;
    padding: 15px 20px 30px;
    color: #333;
    max-height: calc(100% - 121px);
    // height: calc(100% - 121px);
  }

  .roleTitle {
    margin-right: 40px;
  }
}
</style>