ModalWrapper.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="mobile-modal" v-if="showModal" @click="$emit('closeAction')">
  3. <div class="mobile-modal-box mobile-modal-wrapper" @click="stopPropagation($event)">
  4. <div class="mobile-modal-header" v-if="!noHeader">{{title}}<i @click="$emit('closeAction')" class="icon-guanbi iconfont"></i></div>
  5. <slot name="header"></slot>
  6. <div ref="mobileModalBox" class="mobile-scroll-wrap" :style="[ComputedStyle]" >
  7. <div>
  8. <slot></slot>
  9. </div>
  10. </div>
  11. <slot name="footer"></slot>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. props: {
  18. showModal: {
  19. type: Boolean,
  20. default: false
  21. },
  22. title: {
  23. type: String,
  24. default: ''
  25. },
  26. noHeader: {
  27. type: Boolean,
  28. default: false
  29. },
  30. bgColor: {
  31. type: String,
  32. default: '#fff'
  33. },
  34. hasFooter: {
  35. type: Boolean,
  36. default: false
  37. },
  38. hasHeader: {
  39. type: Boolean,
  40. default: false
  41. }
  42. },
  43. watch: {
  44. showModal: {
  45. handler: function (val) {
  46. if (val) {
  47. this.init()
  48. } else {
  49. this.initScroll.destroy()
  50. this.initScroll = null
  51. }
  52. }
  53. }
  54. },
  55. methods: {
  56. init () {
  57. this.$nextTick(() => {
  58. this._initscroll()
  59. })
  60. }
  61. },
  62. computed: {
  63. ComputedStyle() {
  64. if (this.hasFooter) {
  65. return {
  66. height: '68%',
  67. background: this.bgColor,
  68. borderBottomLeftRadius: 0,
  69. borderBottomRightRadius: 0
  70. }
  71. } else {
  72. return {
  73. height: '100%',
  74. background: this.bgColor
  75. }
  76. }
  77. }
  78. },
  79. mounted() {
  80. this.init()
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .mobile-modal .mobile-modal-wrapper {
  86. top: 1.6rem;
  87. bottom: 1.6rem;
  88. left: 5%;
  89. right: 5%;
  90. }
  91. .mobile-scroll-wrap {
  92. overflow: hidden;
  93. height: 100%;
  94. background: #fff;
  95. border-bottom-left-radius: .07rem;
  96. border-bottom-right-radius: .07rem;
  97. }
  98. </style>