commonModal.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <a-modal
  3. centered
  4. v-drag
  5. class="common-modal"
  6. :footer="null"
  7. :maskClosable="false"
  8. v-model="isShow"
  9. :title="modalTit"
  10. :bodyStyle="bodyPadding?{padding:bodyPadding,background:'#f8f8f8'}:{padding: modalTit?'25px 32px 20px':'50px 32px 15px',background:'#f8f8f8'}"
  11. @cancel="isShow=false"
  12. :width="width">
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <div class="common-main" v-html="modalHtml"></div>
  15. <slot></slot>
  16. <div class="btn-box" v-if="showFooter">
  17. <a-button @click="handleCommonCancel" v-if="isCancel">{{ cancelText }}</a-button>
  18. <a-button type="primary" @click="handleCommonOk">{{ okText }}</a-button>
  19. </div>
  20. </a-spin>
  21. </a-modal>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'CommonModal',
  26. props: {
  27. openModal: { // 弹框显示状态
  28. type: Boolean,
  29. default: false
  30. },
  31. width: {
  32. type: String,
  33. default: '500px'
  34. },
  35. modalTit: { // 弹框标题
  36. type: String,
  37. default: null
  38. },
  39. modalHtml: {
  40. type: String,
  41. default: ''
  42. },
  43. okText: { // 确定 按钮文字
  44. type: String,
  45. default: '确定'
  46. },
  47. cancelText: { // 取消 按钮文字
  48. type: String,
  49. default: '取消'
  50. },
  51. isCancel: { // 是否显示 取消 按钮
  52. type: Boolean,
  53. default: true
  54. },
  55. spinning: { // 加载中
  56. type: Boolean,
  57. default: false
  58. },
  59. bodyPadding: {
  60. type: String,
  61. default: ''
  62. },
  63. showFooter: {
  64. type: Boolean,
  65. default: true
  66. }
  67. },
  68. data () {
  69. return {
  70. isShow: this.openModal // 是否打开弹框
  71. }
  72. },
  73. methods: {
  74. // 确定
  75. handleCommonOk () {
  76. this.$emit('ok')
  77. },
  78. // 取消
  79. handleCommonCancel () {
  80. this.$emit('cancel')
  81. }
  82. },
  83. watch: {
  84. // 父页面传过来的弹框状态
  85. openModal (newValue, oldValue) {
  86. this.isShow = newValue
  87. },
  88. // 重定义的弹框状态
  89. isShow (newValue, oldValue) {
  90. if (!newValue) {
  91. this.$emit('cancel')
  92. }
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="less">
  98. .common-modal{
  99. .common-main{
  100. display: flex;
  101. line-height: 20px;
  102. .common-cont{
  103. .common-tit{
  104. color: rgba(0, 0, 0);
  105. font-weight: 500;
  106. font-size: 16px;
  107. line-height: 1.4;
  108. margin: 0;
  109. }
  110. .common-txt{
  111. margin: 8px 0 0;
  112. color: rgba(0, 0, 0);
  113. font-size: 14px;
  114. line-height: 1.5;
  115. }
  116. }
  117. }
  118. .btn-box{
  119. text-align: center;
  120. margin-top: 30px;
  121. .ant-btn{
  122. margin:0 10px;
  123. }
  124. }
  125. }
  126. </style>