ConfirmBox.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <script type="text/jsx">
  2. export default {
  3. name: 'ConfirmBox',
  4. props: {
  5. text: {
  6. type: String,
  7. default: ''
  8. },
  9. content: {
  10. type: String,
  11. default: ''
  12. },
  13. type: {
  14. type: String,
  15. default: 'confirm'
  16. },
  17. beforeConfirm: {
  18. type: Function,
  19. default () {
  20. return Promise.resolve(true)
  21. }
  22. },
  23. disabled: {
  24. type: Boolean,
  25. default: false
  26. }
  27. },
  28. data () {
  29. return {
  30. show: false,
  31. icons: {
  32. 'confirm': {
  33. icon: 'el-icon-warning',
  34. color: '#2842C8'
  35. },
  36. 'danger': {
  37. icon: 'el-icon-warning',
  38. color: '#FD5655'
  39. },
  40. 'warning': {
  41. icon: 'el-icon-warning',
  42. color: '#FF9000'
  43. }
  44. }
  45. }
  46. },
  47. methods: {
  48. async showConfirmBox () {
  49. if (this.disabled) {
  50. return
  51. }
  52. const checkOperate = await this.beforeConfirm()
  53. if (checkOperate) {
  54. const icon = this.icons[this.type].icon
  55. const color = this.icons[this.type].color
  56. const kEle = `<div class="confirm-box">
  57. <div>
  58. <i class="${icon}" style="color: ${color}"></i>
  59. <span>${this.text}</span>
  60. </div>
  61. <p>${this.content}</p>
  62. </div>`
  63. this.$confirm(`${kEle}`, {
  64. dangerouslyUseHTMLString: true,
  65. confirmButtonText: '确定',
  66. cancelButtonText: '取消',
  67. showClose: false,
  68. roundButton: true,
  69. closeOnClickModal: false,
  70. confirmButtonClass: 'button-confirm',
  71. cancelButtonClass: 'button-confirm',
  72. center: true
  73. }).then(() => {
  74. this.$emit('confirm')
  75. }).catch(() => {
  76. })
  77. }
  78. }
  79. },
  80. render () {
  81. const { showConfirmBox } = this
  82. return (
  83. <div onClick={showConfirmBox}>{this.$slots.default}</div>)
  84. }
  85. }
  86. </script>
  87. <style lang="scss">
  88. .confirm-box {
  89. text-align: center;
  90. margin-bottom: 20px;
  91. p {
  92. font-size: 14px;
  93. color: #a8acb4;
  94. margin: 15px 0 15px !important;
  95. span {
  96. font-size: 16px;
  97. font-weight: bold;
  98. margin-right: 10px;
  99. color: #31c37b;
  100. }
  101. }
  102. div {
  103. span {
  104. font-size: 18px;
  105. color: #1e1e1e;
  106. }
  107. i {
  108. font-size: 18px;
  109. font-weight: bold;
  110. }
  111. }
  112. }
  113. .el-message-box__btns .button-confirm {
  114. width: 60px;
  115. }
  116. </style>