1. <template>
    2. <el-dialog
    3. :custom-class="customClass"
    4. :title="dialogVue.title + dialogVue.titleInfo"
    5. :visible.sync="dialogVue.visible"
    6. :width="sizeConfig.w"
    7. :height="sizeConfig.h"
    8. :modal-append-to-body="false"
    9. :append-to-body="dialogVue.appendToBody"
    10. :close-on-click-modal="false"
    11. :dragDialog="true"
    12. footer-border
    13. :fullscreen="dialogVue.isFullScreen"
    14. @opened="dialogVue.beforeOpenedDialog()"
    15. @close="dialogVue.cancelDialogShow()"
    16. @closed="dialogVue.closed()"
    17. :before-close="dialogVue.beforeClose()">
    18. <scroll :parent="dialogVue">
    19. <div v-if="$slots.comment" class="dialog__comment">
    20. <el-alert type="info" :closable="false" show-icon>
    21. <template slot="title">
    22. <slot name="comment"></slot>
    23. </template>
    24. </el-alert>
    25. </div>
    26. <el-form :model="dialogVue.modalData" :label-width="dialogVue.labelWidth" ref="modalDataForm" class="el-form">
    27. <slot></slot>
    28. </el-form>
    29. <slot name="custom"></slot>
    30. <scroll>
    31. <template v-if="dialogVue.hasFooterSlot">
    32. <div slot="footer">
    33. <slot name="footer">
    34. <el-button type="primary" @click="dialogVue.handleConfirmSet()">确定</el-button>
    35. <el-button type="info" @click="dialogVue.cancelDialogShow()">取消</el-button>
    36. </slot>
    37. </div>
    38. </template>
    39. </el-dialog>
    40. </template>
    41. <script>
    42. const SIZE_ENUM = {
    43. small: {
    44. w: '560px',
    45. h: '380px'
    46. },
    47. medium: {
    48. w: '560px',
    49. h: '560px'
    50. },
    51. medium: {
    52. w: '560px',
    53. h: '680px'
    54. },
    55. custom: {
    56. w: '560px',
    57. h: '680px'
    58. }
    59. }
    60. const scroll = {
    61. render(h) {
    62. if (this.parent.hasScrollbar) {
    63. return h('el-scrollbar', {
    64. props: {
    65. scrollbarClass: 'scrollbar--specific'
    66. }
    67. }, this.$slots.default);
    68. } else {
    69. return h('div', {
    70. props: {
    71. class: 'el-dialog__body--noscroll'
    72. }
    73. }, this.$slots.default);
    74. }
    75. },
    76. props: {
    77. parent: {
    78. type: Object
    79. }
    80. }
    81. }
    82. export default {
    83. components: {
    84. scroll
    85. },
    86. props: {
    87. // 指定父组件的this
    88. parent: {
    89. type: Object
    90. }
    91. },
    92. data() {
    93. return {
    94. dialogVue: this.parent || this.$parent,
    95. sizeConfig: {}
    96. }
    97. },
    98. computed: {
    99. customClass() {
    100. let custom = this.dialogVue['custom-class'];
    101. if (!this.dialogVue.hasFooterSlot) {
    102. custom += ' no-footer-slot'
    103. }
    104. if (!this.dialogVue.hasTablePadding) {
    105. custom += ' has-table-padding'
    106. }
    107. return custom;
    108. }
    109. },
    110. created() {
    111. this.sizeConfig = this.diaglog.size == 'custom' ? this.dialogVue.sizeCustom : SIZE_ENUM[this.dialogVue.size];
    112. },
    113. methods: {
    114. // 验证
    115. validate(callback) {
    116. this.$refs.modalDataForm &&
    117. this.$refs.modalDataForm.validate((valid) => {
    118. callback(valid);
    119. });
    120. },
    121. // 重置
    122. resetFields() {
    123. this.$refs.modalDataForm && this.$refs.modalDataForm.resetFields();
    124. },
    125. clearValidate(props) {
    126. this.$refs.modalDataForm && this.$refs.modalDataForm.clearValidate(props);
    127. }
    128. }
    129. }
    130. </script>