云链智安app
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

KBottomPopup.vue 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <script>
  2. export default {
  3. name: "KBottomPopup",
  4. options: {
  5. virtualHost: true,
  6. },
  7. // #ifndef VUE3
  8. model: {
  9. prop: "value",
  10. event: "input",
  11. },
  12. // #endif
  13. props: {
  14. // #ifndef VUE3
  15. value: {
  16. type: Boolean,
  17. default: false,
  18. },
  19. // #endif
  20. // #ifdef VUE3
  21. modelValue: {
  22. type: Boolean,
  23. default: false,
  24. },
  25. // #endif
  26. },
  27. data() {
  28. return {
  29. stopPropagation: false,
  30. zIndex: -10086,
  31. };
  32. },
  33. computed: {
  34. show() {
  35. // #ifdef VUE3
  36. return this.modelValue;
  37. // #endif
  38. // #ifndef VUE3
  39. return this.value;
  40. // #endif
  41. },
  42. },
  43. methods: {
  44. maskClick() {
  45. if (this.stopPropagation) {
  46. this.stopPropagation = false;
  47. return;
  48. }
  49. // #ifndef VUE3
  50. this.$emit("input", false);
  51. // #endif
  52. // #ifdef VUE3
  53. this.$emit("update:modelValue", false);
  54. // #endif
  55. },
  56. /** 阻止事件冒泡 */
  57. onTouchStart(e) {
  58. this.stopPropagation = true;
  59. },
  60. },
  61. watch: {
  62. show: {
  63. handler(n) {
  64. if (n) {
  65. this.zIndex = 10086;
  66. } else {
  67. setTimeout(() => {
  68. this.zIndex = -10086;
  69. }, 300);
  70. }
  71. },
  72. },
  73. },
  74. mounted() {},
  75. };
  76. </script>
  77. <template>
  78. <view
  79. :style="[
  80. {
  81. opacity: show ? 1 : 0,
  82. zIndex: zIndex,
  83. },
  84. ]"
  85. class="k-bottom-popup"
  86. @click="maskClick"
  87. >
  88. <view
  89. :class="{
  90. fade: !show,
  91. 'fade-out': show,
  92. }"
  93. class="tran-content"
  94. @touchstart="onTouchStart"
  95. @click="onTouchStart"
  96. >
  97. <slot></slot>
  98. </view>
  99. </view>
  100. </template>
  101. <style lang="scss">
  102. .k-bottom-popup {
  103. position: fixed;
  104. width: 100%;
  105. height: 100%;
  106. top: 0;
  107. left: 0;
  108. bottom: 0;
  109. right: 0;
  110. background-color: rgba(0, 0, 0, 0.4);
  111. opacity: 0;
  112. transition: opacity 0.3s ease-in-out;
  113. .fade {
  114. transform: translateY(100%);
  115. }
  116. .fade-out {
  117. transform: translateY(0);
  118. }
  119. .tran-content {
  120. position: absolute;
  121. right: 0;
  122. left: 0;
  123. bottom: 0;
  124. transition: transform 0.3s ease-in-out;
  125. }
  126. }
  127. </style>