<template> <el-dialog :custom-class="customClass" :title="dialogVue.title + dialogVue.titleInfo" :visible.sync="dialogVue.visible" :width="sizeConfig.w" :height="sizeConfig.h" :modal-append-to-body="false" :append-to-body="dialogVue.appendToBody" :close-on-click-modal="false" :dragDialog="true" footer-border :fullscreen="dialogVue.isFullScreen" @opened="dialogVue.beforeOpenedDialog()" @close="dialogVue.cancelDialogShow()" @closed="dialogVue.closed()" :before-close="dialogVue.beforeClose()"> <scroll :parent="dialogVue"> <div v-if="$slots.comment" class="dialog__comment"> <el-alert type="info" :closable="false" show-icon> <template slot="title"> <slot name="comment"></slot> </template> </el-alert> </div> <el-form :model="dialogVue.modalData" :label-width="dialogVue.labelWidth" ref="modalDataForm" class="el-form"> <slot></slot> </el-form> <slot name="custom"></slot> <scroll> <template v-if="dialogVue.hasFooterSlot"> <div slot="footer"> <slot name="footer"> <el-button type="primary" @click="dialogVue.handleConfirmSet()">确定</el-button> <el-button type="info" @click="dialogVue.cancelDialogShow()">取消</el-button> </slot> </div> </template> </el-dialog></template><script>const SIZE_ENUM = { small: { w: '560px', h: '380px' }, medium: { w: '560px', h: '560px' }, medium: { w: '560px', h: '680px' }, custom: { w: '560px', h: '680px' }} const scroll = { render(h) { if (this.parent.hasScrollbar) { return h('el-scrollbar', { props: { scrollbarClass: 'scrollbar--specific' } }, this.$slots.default); } else { return h('div', { props: { class: 'el-dialog__body--noscroll' } }, this.$slots.default); } }, props: { parent: { type: Object } }}export default { components: { scroll }, props: { // 指定父组件的this parent: { type: Object } }, data() { return { dialogVue: this.parent || this.$parent, sizeConfig: {} } }, computed: { customClass() { let custom = this.dialogVue['custom-class']; if (!this.dialogVue.hasFooterSlot) { custom += ' no-footer-slot' } if (!this.dialogVue.hasTablePadding) { custom += ' has-table-padding' } return custom; } }, created() { this.sizeConfig = this.diaglog.size == 'custom' ? this.dialogVue.sizeCustom : SIZE_ENUM[this.dialogVue.size]; }, methods: { // 验证 validate(callback) { this.$refs.modalDataForm && this.$refs.modalDataForm.validate((valid) => { callback(valid); }); }, // 重置 resetFields() { this.$refs.modalDataForm && this.$refs.modalDataForm.resetFields(); }, clearValidate(props) { this.$refs.modalDataForm && this.$refs.modalDataForm.clearValidate(props); } }}</script>