cwg-global-popup.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <cwg-popup v-model:visible="popupState.visible" type="center" :mask-click="false" :show-footers="showFooters" width="400px">
  3. <view class="popup-content">
  4. <view class="confirm-title">{{ popupState.title }}</view>
  5. <view class="confirm-content">{{ popupState.content }}</view>
  6. </view>
  7. <template #footer>
  8. <button v-if="popupState.showCancel && !popupState.autoClose" @click="close">{{ popupState.cancelText }}</button>
  9. <button v-if="!popupState.autoClose" class="btn btn-secondary btn-shadow waves-effect" @click="handleConfirm">{{ popupState.confirmText }}</button>
  10. </template>
  11. </cwg-popup>
  12. </template>
  13. <script setup>
  14. import { watch, ref, computed, onUnmounted } from 'vue'
  15. import { usePopup } from '@/hooks/usePopup'
  16. const { popupState, close, handleConfirm } = usePopup()
  17. const popupRef = ref(null)
  18. let autoCloseTimer = null
  19. const showFooters = computed(() => !popupState.value.autoClose)
  20. watch(() => popupState.value.visible, (val) => {
  21. if (val) {
  22. popupRef.value?.open()
  23. if (popupState.value.autoClose) {
  24. autoCloseTimer = setTimeout(() => {
  25. close()
  26. }, popupState.value.autoCloseDelay)
  27. }
  28. } else {
  29. popupRef.value?.close()
  30. if (autoCloseTimer) {
  31. clearTimeout(autoCloseTimer)
  32. autoCloseTimer = null
  33. }
  34. }
  35. }, { immediate: true })
  36. onUnmounted(() => {
  37. if (autoCloseTimer) {
  38. clearTimeout(autoCloseTimer)
  39. }
  40. })
  41. </script>
  42. <style scoped lang="scss">
  43. @import "@/uni.scss";
  44. :deep(.cwg-dialog) {
  45. width: px2rpx(500);
  46. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  47. border-radius: px2rpx(16);
  48. text-align: center;
  49. box-shadow: 0 px2rpx(10) px2rpx(20) rgba(0, 0, 0, 0.1);
  50. }
  51. .confirm-title {
  52. font-size: px2rpx(24);
  53. font-weight: 600;
  54. color: var(--bs-heading-color);
  55. margin-bottom: px2rpx(30);
  56. }
  57. .confirm-content {
  58. font-size: px2rpx(20);
  59. color: var(--bs-heading-color);
  60. margin-bottom: px2rpx(30);
  61. line-height: 1.5;
  62. word-break: break-word;
  63. }
  64. </style>