ConfirmDialog.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="confirm_dialog">
  3. <el-dialog
  4. :visible.sync="dialogVisible"
  5. width="400px"
  6. :show-close="false"
  7. :before-close="handleClose"
  8. class="confirm_dialog_custom"
  9. >
  10. <div class="confirm_dialog_content">
  11. <h3 class="confirm_dialog_title">
  12. <span>{{ title }}</span>
  13. <div class="modal-close" @click="handleClose">×</div>
  14. </h3>
  15. <p class="confirm_dialog_message" v-html="message"></p>
  16. </div>
  17. <div class="confirm_dialog_footer">
  18. <el-button @click="handleCancel" class="cancel_btn">{{ cancelText }}</el-button>
  19. <el-button type="primary" @click="handleConfirm" class="confirm_btn">{{ confirmText }}</el-button>
  20. </div>
  21. </el-dialog>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'ConfirmDialog',
  27. props: {
  28. visible: {
  29. type: Boolean,
  30. default: false
  31. },
  32. title: {
  33. type: String,
  34. default: ''
  35. },
  36. message: {
  37. type: String,
  38. default: ''
  39. },
  40. confirmText: {
  41. type: String,
  42. default: '确认'
  43. },
  44. cancelText: {
  45. type: String,
  46. default: '取消'
  47. }
  48. },
  49. data() {
  50. return {
  51. dialogVisible: this.visible
  52. }
  53. },
  54. watch: {
  55. visible: {
  56. handler(newVal) {
  57. this.dialogVisible = newVal;
  58. },
  59. immediate: true
  60. }
  61. },
  62. methods: {
  63. handleClose() {
  64. this.dialogVisible = false;
  65. this.$emit('update:visible', false);
  66. },
  67. handleCancel() {
  68. this.dialogVisible = false;
  69. this.$emit('update:visible', false);
  70. this.$emit('cancel');
  71. },
  72. handleConfirm() {
  73. this.dialogVisible = false;
  74. this.$emit('update:visible', false);
  75. this.$emit('confirm');
  76. }
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. .confirm_dialog_custom >>> .el-dialog {
  82. border-radius: 15px;
  83. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  84. }
  85. .confirm_dialog_custom >>> .el-dialog__header {
  86. display: none;
  87. }
  88. .confirm_dialog_custom >>> .el-dialog__body {
  89. padding: 20px;
  90. }
  91. .confirm_dialog_title {
  92. font-size: 18px;
  93. font-weight: bold;
  94. margin-bottom: 16px;
  95. display: flex;
  96. justify-content: space-between;
  97. align-items: center;
  98. }
  99. .modal-close {
  100. font-size: 24px;
  101. color: #909399;
  102. cursor: pointer;
  103. transition: color 0.3s;
  104. width: 30px;
  105. height: 30px;
  106. line-height: 30px;
  107. border-radius: 5px;
  108. text-align: center;
  109. font-weight: 500;
  110. }
  111. .modal-close:hover {
  112. /* color: #409eff; */
  113. background-color: #f3f4f6;
  114. }
  115. .confirm_dialog_message {
  116. font-size: 14px;
  117. line-height: 1.5;
  118. color: #666;
  119. margin-bottom: 24px;
  120. }
  121. .confirm_dialog_footer {
  122. display: flex;
  123. justify-content: flex-end;
  124. /* gap: 12px; */
  125. }
  126. .cancel_btn {
  127. border-radius: 10px;
  128. border: 1px solid #DCDFE6;
  129. background-color: #FFFFFF;
  130. color: #606266;
  131. }
  132. .confirm_btn {
  133. border-radius: 10px;
  134. background-color: #FF9400;
  135. border: none;
  136. color: #FFFFFF;
  137. }
  138. .confirm_btn:hover {
  139. background-color: #FFA500;
  140. }
  141. </style>