Blame view

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