Dialog.vue 2.6 KB

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