index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="dialog-com">
  3. <el-dialog
  4. v-on="$listeners"
  5. v-bind="$attrs"
  6. :close-on-click-modal="closeOnClickModal"
  7. custom-class="dialog-com-el-dialog">
  8. <!-- <div > -->
  9. <el-scrollbar v-loading="loading" :style="oriHeight? ('height:'+ oriHeight) : ''">
  10. <div class="pr10 pb1"><slot></slot></div>
  11. </el-scrollbar>
  12. <div v-if="hasFooter" class="dialog-com-dialog-footer pt10 pr10" >
  13. <div slot="footer" v-if="!$scopedSlots['footer']">
  14. <el-button v-if="showCancelButton" @click="dialogOnClose">{{cancelButtonText}}</el-button>
  15. <el-button v-if="showConfirmButton" @click="$emit('onSubmit');" :type="confirmButtonType">{{confirmButtonText}}</el-button>
  16. </div>
  17. <div slot="footer" v-else>
  18. <slot name="footer"></slot>
  19. </div>
  20. </div>
  21. <!-- </div> -->
  22. </el-dialog>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. name: 'CustomDialog',
  28. props: {
  29. 'height':{},
  30. 'close-on-click-modal':{
  31. default: false
  32. },
  33. 'showConfirmButton': {
  34. default: true
  35. },
  36. 'showCancelButton': {
  37. default: true
  38. },
  39. 'confirmButtonText': {
  40. default: '确 定'
  41. },
  42. confirmButtonType: {
  43. default: 'primary'
  44. },
  45. 'cancelButtonText': {
  46. default: '取 消'
  47. },
  48. beforeClose: {
  49. },
  50. loading: {
  51. default: false
  52. }
  53. },
  54. computed:{
  55. hasFooter(){
  56. return this.showConfirmButton||this.showCancelButton||this.$scopedSlots['footer']
  57. }
  58. },
  59. data(){
  60. return {
  61. oriHeight: ''
  62. }
  63. },
  64. created(){
  65. if(this.height){
  66. if(typeof this.height == 'number'){
  67. this.oriHeight = this.height+ 'px'
  68. } else {
  69. this.oriHeight = this.height
  70. }
  71. }
  72. },
  73. mounted() {
  74. },
  75. methods: {
  76. dialogOnClose(){
  77. if(this.beforeClose){
  78. this.beforeClose().then(()=>{
  79. this.$emit('update:visible', false);
  80. })
  81. } else {
  82. this.$emit('update:visible', false);
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss">
  89. .el-dialog.dialog-com-el-dialog{
  90. position: absolute;
  91. left: 50%;
  92. top: 50%;
  93. transform: translateX(-50%) translateY(-50%);
  94. margin-top: 0!important;
  95. .el-dialog__body{
  96. padding: 10px 10px 10px 15px;
  97. >.el-scrollbar{
  98. .el-scrollbar__wrap{
  99. overflow-x: hidden;
  100. }
  101. }
  102. }
  103. .el-dialog__header{
  104. padding: 15px;
  105. padding-bottom: 10px;
  106. }
  107. .dialog-com-dialog-footer{
  108. text-align: right;
  109. border-top: 1px solid #ccc;
  110. }
  111. }
  112. </style>