popup.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="popup" :class="[value ? 'show': '', classStyl]" :value="value" @touchmove.stop.prevent="move">
  3. <div class="popup-dialogs">
  4. <slot>
  5. </slot>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. props: {
  12. value: {
  13. type: Boolean,
  14. default: false
  15. },
  16. location: {
  17. type: String,
  18. default: 'bottom'
  19. },
  20. locked: {
  21. type: Boolean,
  22. default: false
  23. }
  24. },
  25. data () {
  26. return {
  27. showPopupVisible: this.value
  28. }
  29. },
  30. watch: {
  31. showPopupVisible (val) {
  32. this.$emit('input', val)
  33. },
  34. value(val) {
  35. this.showPopupVisible = val
  36. }
  37. },
  38. computed: {
  39. classStyl () {
  40. let transform = ''
  41. switch (this.location) {
  42. case 'top':
  43. transform = 'popup-top'
  44. break
  45. case 'center':
  46. transform = 'popup-center'
  47. break
  48. default:
  49. transform = 'bottom-modal'
  50. }
  51. return transform
  52. }
  53. },
  54. methods: {
  55. close () {
  56. this.showPopupVisible = false
  57. },
  58. move (e) {
  59. },
  60. hide () {
  61. if (this.locked) {
  62. this.value = false
  63. } else {
  64. return false
  65. }
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. .popup {
  72. position: fixed;
  73. top: 0;
  74. right: 0;
  75. bottom: 0;
  76. left: 0;
  77. z-index: 1110;
  78. opacity: 0;
  79. outline: 0;
  80. text-align: center;
  81. backface-visibility: hidden;
  82. perspective: 2000upx;
  83. background: rgba(0, 0, 0, 0.6);
  84. transition: all 0.3s ease-in-out 0s;
  85. pointer-events: none;
  86. }
  87. .popup-dialogs {
  88. position: relative;
  89. display: inline-block;
  90. vertical-align: middle;
  91. margin-left: auto;
  92. margin-right: auto;
  93. width: 100%;
  94. min-height: 400upx;
  95. max-width: 100%;
  96. background-color: transparent;
  97. overflow: hidden;
  98. }
  99. .popup-center{
  100. -ms-transform: scale(1.185);
  101. transform: scale(1.185);
  102. &.show{
  103. -ms-transform: scale(1);
  104. transform: scale(1);
  105. }
  106. &::after{
  107. content: "\200B";
  108. display: inline-block;
  109. height: 100%;
  110. vertical-align: middle;
  111. }
  112. }
  113. .popup.show {
  114. opacity: 1;
  115. transition-duration: 0.3s;
  116. overflow-x: hidden;
  117. overflow-y: auto;
  118. pointer-events: auto;
  119. }
  120. .popup.bottom-modal::before {
  121. vertical-align: bottom;
  122. }
  123. .popup.bottom-modal .cu-dialog {
  124. width: 100%;
  125. border-radius: 0;
  126. }
  127. .popup.bottom-modal {
  128. margin-bottom: -1000upx;
  129. &::after{
  130. content: "\200B";
  131. display: inline-block;
  132. height: 100%;
  133. vertical-align: bottom;
  134. }
  135. }
  136. .popup.bottom-modal.show {
  137. margin-bottom: 0;
  138. }
  139. .popup.popup-top{
  140. margin-top: -1000px;
  141. &.show{
  142. margin-top: 0;
  143. }
  144. }
  145. </style>