Dialog.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <el-dialog
  3. class="custom-dialog"
  4. :custom-class="customClass"
  5. v-bind="$props"
  6. :show-close="showClose"
  7. :visible="visible"
  8. :before-close="beforeClose"
  9. @update:visible="update"
  10. v-component-change-mount="{ selector: comMount }"
  11. @open="$emit('open')"
  12. @opened="$emit('opened')"
  13. @close="$emit('close')"
  14. @closed="$emit('closed')"
  15. >
  16. <slot name="default"></slot>
  17. <span slot="footer" v-if="showFooter" class="dialog-footer">
  18. <slot name="footer">
  19. <button class="action-button cancel" @click="onClickCancel">
  20. 取消
  21. </button>
  22. <button
  23. class="action-button confirm"
  24. :disabled="disabled"
  25. @click="onClickConfirm"
  26. >
  27. 确定
  28. </button>
  29. </slot>
  30. </span>
  31. </el-dialog>
  32. </template>
  33. <script>
  34. import { Dialog, Button } from 'element-ui'
  35. export default {
  36. name: 'CustomDialog',
  37. components: {
  38. [Dialog.name]: Dialog,
  39. [Button.name]: Button
  40. },
  41. props: {
  42. visible: Boolean,
  43. showClose: Boolean,
  44. beforeClose: Function,
  45. comMount: {
  46. type: String,
  47. default: ''
  48. },
  49. showFooter: {
  50. type: Boolean,
  51. default() {
  52. return true
  53. }
  54. },
  55. top: String,
  56. title: {
  57. type: String,
  58. default: ''
  59. },
  60. width: {
  61. type: String,
  62. default: '30%'
  63. },
  64. 'show-close': {
  65. type: Boolean,
  66. default: false
  67. },
  68. center: {
  69. type: Boolean,
  70. default: true
  71. },
  72. customClass: {
  73. type: String,
  74. default: ''
  75. },
  76. disabled: Boolean
  77. },
  78. methods: {
  79. update(e) {
  80. this.$emit('update:visible', e)
  81. },
  82. onClickCancel() {
  83. this.$emit('cancel')
  84. },
  85. onClickConfirm() {
  86. this.$emit('confirm')
  87. }
  88. }
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. ::v-deep {
  93. .el-dialog {
  94. border-radius: 8px;
  95. }
  96. .el-dialog__body {
  97. color: #686868;
  98. font-size: 14px;
  99. line-height: 22px;
  100. }
  101. .el-dialog__body,
  102. .el-dialog__footer {
  103. padding-left: 32px;
  104. padding-right: 32px;
  105. }
  106. .el-dialog__footer {
  107. padding-top: 6px;
  108. }
  109. .dialog-footer {
  110. display: flex;
  111. align-items: center;
  112. justify-content: space-between;
  113. }
  114. .action-button {
  115. display: flex;
  116. align-items: center;
  117. justify-content: center;
  118. flex: 1;
  119. height: 36px;
  120. border-radius: 6px;
  121. &.cancel {
  122. border: 1px solid #e0e0e0;
  123. background-color: #fff;
  124. color: #686868;
  125. }
  126. &.confirm {
  127. border: 1px solid $color_main;
  128. background-color: $color_main;
  129. color: #fff;
  130. &:disabled {
  131. opacity: 0.5;
  132. }
  133. }
  134. &:not(:last-of-type) {
  135. margin-right: 48px;
  136. }
  137. }
  138. }
  139. .text-center {
  140. ::v-deep {
  141. .el-dialog__body {
  142. text-align: center;
  143. }
  144. }
  145. }
  146. </style>