g-popup.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <uni-popup
  3. :safe-area="false"
  4. ref="popup"
  5. :type="type"
  6. :class="['u-poup', `popup-${type}`]"
  7. :is-mask-click="false"
  8. background-color="transparent"
  9. @maskClick="close"
  10. >
  11. <view class="popup-content">
  12. <slot></slot>
  13. <view v-if="showCancel" class="group-cancel hz-button-cancel" @click="close">{{ cancelTest }}</view>
  14. </view>
  15. </uni-popup>
  16. </template>
  17. <script setup lang="ts">
  18. import { watch } from "vue";
  19. import { ref, nextTick } from "vue";
  20. const popup = ref<PopupInstance | null>(null);
  21. const popopAnimationCompulete = ref(false);
  22. const emit = defineEmits<{
  23. (e: "update:showDialog", value: boolean): void;
  24. }>();
  25. const props = defineProps({
  26. showDialog: {
  27. type: Boolean,
  28. default: false,
  29. },
  30. type: {
  31. type: String,
  32. default: "bottom",
  33. },
  34. showCancel: {
  35. type: Boolean,
  36. default: true,
  37. },
  38. cancelTest: {
  39. type: String,
  40. default: "取消",
  41. },
  42. });
  43. watch(
  44. () => props.showDialog,
  45. (newVal, oldVal) => {
  46. if (newVal) {
  47. show();
  48. } else {
  49. close();
  50. }
  51. },
  52. {
  53. immediate: true,
  54. deep: true,
  55. },
  56. );
  57. function show() {
  58. if (!popup.value) {
  59. nextTick(() => {
  60. openPopup();
  61. });
  62. } else {
  63. openPopup();
  64. }
  65. }
  66. function openPopup() {
  67. popup.value?.open();
  68. popopAnimationCompulete.value = false;
  69. setTimeout(() => {
  70. popopAnimationCompulete.value = true;
  71. }, 400);
  72. }
  73. function close() {
  74. if (!popopAnimationCompulete.value) return;
  75. popup.value?.close();
  76. emit("update:showDialog", false);
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .popup-bottom {
  81. .popup-content {
  82. font-size: 30rpx;
  83. padding: 32rpx 32rpx 64rpx;
  84. position: relative;
  85. border-top-left-radius: 50rpx;
  86. border-top-right-radius: 50rpx;
  87. background-color: var(--theme-bg-color);
  88. color: var(--theme-primary-color);
  89. }
  90. }
  91. </style>