Blame view

src/components/DialogBox/dialogBox.vue 2.98 KB
任超 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
  <el-dialog :visible.sync="dialogVisible" v-if="dialogVisible" :width="width" :fullscreen="fullscreen" top="0"
    :append-to-body="appendToBody" :lock-scroll="true" :close-on-click-modal="false" @close="closeDialog" :key="key"
    :custom-class="isMain ? 'mainCenter dialogBox' : 'contentCenter dialogBox'" :destroy-on-close="true" ref="dialogBox"
    id="dialogBox">
    <div slot="title">
      <div class="dialog_title">
        <b>{{ title }}</b>
        <div v-if="isFullscreen" class="dialog_full">
          <i class="el-icon-rank" v-if="fullscreen" @click="handleFullscreen"></i>
          <i class="el-icon-full-screen" v-else @click="handleFullscreen" />
        </div>
      </div>
    </div>
任超 committed
15
    <div class="dialogBox-content" :style="{ height: scrollerHeight }">
任超 committed
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
      <slot></slot>
    </div>
    <div slot="footer" class="dialog_footer" v-if="isButton">
      <el-button @click="closeDialog" v-if="isReset">取消</el-button>
      <el-button type="primary" plain @click="submitForm" v-if="isSave" :disabled="btnDisabled" :loading="saveloding">
        {{ saveButton }}</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  props: {
    value: { type: Boolean, default: false },
    isMain: {
      type: Boolean,
      default: false
    },
    appendToBody: {
      type: Boolean,
      default: true
    },
    isButton: {
      type: Boolean,
      default: true,
    },
    width: {
      type: String,
      default: '70%',
    },
    title: {
      type: String,
      default: '',
    },
    isFullscreen: {
      type: Boolean,
      default: true,
    },
    isSave: {
      type: Boolean,
      default: true,
    },
    saveButton: {
      type: String,
      default: '提交',
    },
    isReset: {
      type: Boolean,
      default: true,
    },
    saveloding: {
      type: Boolean,
      default: false,
    },
    btnDisabled: {
      type: Boolean,
      default: false
任超 committed
72 73 74 75
    },
    height: {
      type: String,
      default: ''
任超 committed
76 77 78 79 80 81 82
    }
  },
  data () {
    return {
      key: 0,
      dialogVisible: false,
      fullscreen: false,
任超 committed
83
      scrollerHeight: ''
任超 committed
84 85 86 87 88
    }
  },
  watch: {
    value (val) {
      this.dialogVisible = val
任超 committed
89
      this.height && (this.scrollerHeight = this.height + 'px')
任超 committed
90 91 92
    }
  },
  methods: {
任超 committed
93
    handleFullscreen () {
任超 committed
94 95
      this.fullscreen = !this.fullscreen
      if (!this.fullscreen) {
任超 committed
96
        this.scrollerHeight = ''
任超 committed
97
      } else {
任超 committed
98
        this.scrollerHeight = (window.innerHeight - 120) + 'px'
任超 committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
      }
    },
    submitForm () {
      if (this.isButton) {
        this.$emit('submitForm');
      }
    },
    closeDialog () {
      this.key++
      this.$emit('input', false)
      this.$emit('closeDialog')
    }
  },
}
</script>
<style rel="stylesheet/scss" lang="scss" >
@import "~@/styles/mixin.scss";
任超 committed
116
@import "~@/styles/dialogBox.scss";
任超 committed
117 118 119 120 121 122 123 124 125
</style>
<style rel="stylesheet/scss" scoped lang="scss" >
/deep/.is-fullscreen {
  position: absolute;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
}
</style>