uni-pay-popup.uvue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="popup-root" :class="'popup-'+type" v-if="isOpen" v-show="isShow" @click="clickMask">
  3. <view @click.stop class="popup-box">
  4. <slot></slot>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. emits: ["close", "clickMask"],
  11. data() {
  12. return {
  13. isShow: false,
  14. isOpen: false
  15. }
  16. },
  17. props: {
  18. maskClick: {
  19. type: Boolean,
  20. default: true
  21. },
  22. type: {
  23. type: String,
  24. default: "center"
  25. }
  26. },
  27. watch: {
  28. // 设置show = true 时,如果没有 open 需要设置为 open
  29. isShow: {
  30. handler(newVal : boolean) {
  31. if (newVal && this.isOpen == false) {
  32. this.isOpen = true;
  33. }
  34. },
  35. immediate: true
  36. },
  37. // 设置isOpen = true 时,如果没有 isShow 需要设置为 isShow
  38. isOpen: {
  39. handler(newVal : boolean) {
  40. if (newVal && this.isShow == false) {
  41. this.isShow = true;
  42. }
  43. },
  44. immediate: true
  45. }
  46. },
  47. methods: {
  48. open() {
  49. this.isOpen = true;
  50. },
  51. clickMask() {
  52. if (this.maskClick == true) {
  53. this.$emit('clickMask');
  54. this.close();
  55. }
  56. },
  57. close() : void {
  58. this.isOpen = false;
  59. this.$emit('close');
  60. },
  61. hiden() {
  62. this.isShow = false;
  63. },
  64. show() {
  65. this.isShow = true;
  66. }
  67. }
  68. }
  69. </script>
  70. <style>
  71. .popup-root {
  72. position: fixed;
  73. top: 0;
  74. left: 0;
  75. width: 100%;
  76. height: 100%;
  77. flex: 1;
  78. background-color: rgba(0, 0, 0, 0.4);
  79. justify-content: center;
  80. align-items: center;
  81. z-index: 99;
  82. }
  83. .popup-box {
  84. width: 100%;
  85. justify-content: center;
  86. align-items: center;
  87. }
  88. .popup-bottom {
  89. justify-content: flex-end;
  90. }
  91. </style>