cwg-confirm-popup.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <cwg-popup v-model:visible="visible" type="center" :mask-click="false" :show-footers="true">
  3. <view class="popup-content">
  4. <view class="confirm-title">{{ title }}</view>
  5. <view class="confirm-content">{{ content }}</view>
  6. </view>
  7. <template #footer>
  8. <button hover-class="" @click="handleCancel">{{ cancelText }}</button>
  9. <button hover-class="" class="btn btn-secondary btn-shadow waves-effect" @click="handleConfirm">{{ confirmText
  10. }}</button>
  11. </template>
  12. </cwg-popup>
  13. </template>
  14. <script setup>
  15. import { ref, onMounted, onUnmounted, watch } from 'vue'
  16. import { useI18n } from 'vue-i18n'
  17. const { t } = useI18n()
  18. const visible = ref(false)
  19. let currentEventId = null
  20. let isShowing = false // 单例锁,永远只弹一个
  21. const title = ref('')
  22. const content = ref('')
  23. const confirmText = ref('')
  24. const cancelText = ref('')
  25. // 显示弹窗
  26. const handleShowConfirm = (options) => {
  27. if (isShowing || visible.value) return
  28. isShowing = true
  29. currentEventId = options.eventId
  30. title.value = options.title || t('Msg.SystemPrompt')
  31. content.value = options.content || ''
  32. confirmText.value = options.confirmText || t('Btn.Confirm')
  33. cancelText.value = options.cancelText || t('Btn.Cancel')
  34. visible.value = true
  35. }
  36. // 关闭并返回结果 + 强制清空所有状态
  37. const close = (result) => {
  38. visible.value = false
  39. isShowing = false
  40. if (currentEventId) {
  41. uni.$emit(`confirmResult_${currentEventId}`, result)
  42. }
  43. // 🔥 强制清空,永不残留
  44. currentEventId = null
  45. title.value = ''
  46. content.value = ''
  47. confirmText.value = ''
  48. cancelText.value = ''
  49. }
  50. const handleConfirm = () => close(true)
  51. const handleCancel = () => close(false)
  52. onMounted(() => {
  53. uni.$on('showConfirm', handleShowConfirm)
  54. })
  55. onUnmounted(() => {
  56. uni.$off('showConfirm', handleShowConfirm)
  57. visible.value = false
  58. isShowing = false
  59. currentEventId = null
  60. })
  61. </script>
  62. <style scoped lang="scss">
  63. @import "@/uni.scss";
  64. :deep(.cwg-dialog) {
  65. width: px2rpx(500);
  66. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  67. border-radius: px2rpx(16);
  68. text-align: center;
  69. box-shadow: 0 px2rpx(10) px2rpx(20) rgba(0, 0, 0, 0.1);
  70. }
  71. .confirm-title {
  72. font-size: px2rpx(24);
  73. font-weight: 600;
  74. color: var(--bs-heading-color);
  75. margin-bottom: px2rpx(30);
  76. }
  77. .confirm-content {
  78. font-size: px2rpx(20);
  79. color: var(--bs-heading-color);
  80. margin-bottom: px2rpx(30);
  81. line-height: 1.5;
  82. word-break: break-word;
  83. }
  84. </style>