cwg-confirm-popup.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 @click="cancel">{{ cancelText }}</button>
  9. <button type="primary" @click="confirm">{{ confirmText }}</button>
  10. </template>
  11. </cwg-popup>
  12. </template>
  13. <script setup>
  14. import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
  15. import { useI18n } from 'vue-i18n';
  16. const { t } = useI18n();
  17. const title = ref(t('Msg.SystemPrompt'))
  18. const content = ref('')
  19. const confirmText = ref(t('Btn.Confirm'))
  20. const cancelText = ref(t('Btn.Cancel'))
  21. let currentEventId = null
  22. const handleShowConfirm = (options) => {
  23. title.value = options.title || title.value
  24. content.value = options.content || ''
  25. confirmText.value = options.confirmText || t('Btn.Confirm')
  26. cancelText.value = options.cancelText || t('Btn.Cancel')
  27. currentEventId = options.eventId
  28. visible.value = true
  29. }
  30. const closeAndResult = (result) => {
  31. visible.value = false
  32. if (currentEventId) {
  33. uni.$emit(`confirmResult_${currentEventId}`, result)
  34. currentEventId = null
  35. }
  36. }
  37. const confirm = () => closeAndResult(true)
  38. const cancel = () => closeAndResult(false)
  39. onMounted(() => {
  40. uni.$on('showConfirm', handleShowConfirm)
  41. })
  42. onUnmounted(() => {
  43. uni.$off('showConfirm', handleShowConfirm)
  44. })
  45. const visible = ref(false)
  46. watch(visible, (value) => {
  47. if (!value) closeAndResult(false)
  48. })
  49. </script>
  50. <style scoped lang="scss">
  51. @import "@/uni.scss";
  52. :deep(.cwg-dialog) {
  53. width: px2rpx(500);
  54. background-color: #fff;
  55. border-radius: px2rpx(16);
  56. text-align: center;
  57. box-shadow: 0 px2rpx(10) px2rpx(20) rgba(0, 0, 0, 0.1);
  58. }
  59. .confirm-title {
  60. font-size: px2rpx(24);
  61. font-weight: 600;
  62. color: #333;
  63. margin-bottom: px2rpx(30);
  64. }
  65. .confirm-content {
  66. font-size: px2rpx(20);
  67. color: #666;
  68. margin-bottom: px2rpx(30);
  69. line-height: 1.5;
  70. word-break: break-word;
  71. }
  72. </style>