|
@@ -1,79 +1,97 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <cwg-popup v-model:visible="visible" type="center" :mask-click="false" :show-footers="true">
|
|
|
|
|
- <view class="popup-content">
|
|
|
|
|
- <view class="confirm-title">{{ title }}</view>
|
|
|
|
|
- <view class="confirm-content">{{ content }}</view>
|
|
|
|
|
- </view>
|
|
|
|
|
- <template #footer>
|
|
|
|
|
- <button @click="cancel">{{ cancelText }}</button>
|
|
|
|
|
- <button type="primary" @click="confirm">{{ confirmText }}</button>
|
|
|
|
|
- </template>
|
|
|
|
|
- </cwg-popup>
|
|
|
|
|
|
|
+ <cwg-popup v-model:visible="visible" type="center" :mask-click="false" :show-footers="true">
|
|
|
|
|
+ <view class="popup-content">
|
|
|
|
|
+ <view class="confirm-title">{{ title }}</view>
|
|
|
|
|
+ <view class="confirm-content">{{ content }}</view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <template #footer>
|
|
|
|
|
+ <button @click="handleCancel">{{ cancelText }}</button>
|
|
|
|
|
+ <button type="primary" @click="handleConfirm">{{ confirmText }}</button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </cwg-popup>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
+
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
|
|
|
|
|
-import { useI18n } from 'vue-i18n';
|
|
|
|
|
-const { t } = useI18n();
|
|
|
|
|
-const title = ref(t('Msg.SystemPrompt'))
|
|
|
|
|
-const content = ref('')
|
|
|
|
|
-const confirmText = ref(t('Btn.Confirm'))
|
|
|
|
|
-const cancelText = ref(t('Btn.Cancel'))
|
|
|
|
|
|
|
+import { ref, onMounted, onUnmounted } from 'vue'
|
|
|
|
|
+import { useI18n } from 'vue-i18n'
|
|
|
|
|
+const { t } = useI18n()
|
|
|
|
|
+
|
|
|
|
|
+const visible = ref(false)
|
|
|
let currentEventId = null
|
|
let currentEventId = null
|
|
|
|
|
+let isShowing = false // 单例锁,永远只弹一个
|
|
|
|
|
|
|
|
|
|
+const title = ref('')
|
|
|
|
|
+const content = ref('')
|
|
|
|
|
+const confirmText = ref('')
|
|
|
|
|
+const cancelText = ref('')
|
|
|
|
|
+
|
|
|
|
|
+// 显示弹窗
|
|
|
const handleShowConfirm = (options) => {
|
|
const handleShowConfirm = (options) => {
|
|
|
- title.value = options.title || title.value
|
|
|
|
|
- content.value = options.content || ''
|
|
|
|
|
- confirmText.value = options.confirmText || t('Btn.Confirm')
|
|
|
|
|
- cancelText.value = options.cancelText || t('Btn.Cancel')
|
|
|
|
|
- currentEventId = options.eventId
|
|
|
|
|
- visible.value = true
|
|
|
|
|
|
|
+ if (isShowing || visible.value) return
|
|
|
|
|
+
|
|
|
|
|
+ isShowing = true
|
|
|
|
|
+ currentEventId = options.eventId
|
|
|
|
|
+
|
|
|
|
|
+ title.value = options.title || t('Msg.SystemPrompt')
|
|
|
|
|
+ content.value = options.content || ''
|
|
|
|
|
+ confirmText.value = options.confirmText || t('Btn.Confirm')
|
|
|
|
|
+ cancelText.value = options.cancelText || t('Btn.Cancel')
|
|
|
|
|
+
|
|
|
|
|
+ visible.value = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const closeAndResult = (result) => {
|
|
|
|
|
- visible.value = false
|
|
|
|
|
- if (currentEventId) {
|
|
|
|
|
- uni.$emit(`confirmResult_${currentEventId}`, result)
|
|
|
|
|
- currentEventId = null
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// 关闭并返回结果 + 强制清空所有状态
|
|
|
|
|
+const close = (result) => {
|
|
|
|
|
+ visible.value = false
|
|
|
|
|
+ isShowing = false
|
|
|
|
|
+
|
|
|
|
|
+ if (currentEventId) {
|
|
|
|
|
+ uni.$emit(`confirmResult_${currentEventId}`, result)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 🔥 强制清空,永不残留
|
|
|
|
|
+ currentEventId = null
|
|
|
|
|
+ title.value = ''
|
|
|
|
|
+ content.value = ''
|
|
|
|
|
+ confirmText.value = ''
|
|
|
|
|
+ cancelText.value = ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const confirm = () => closeAndResult(true)
|
|
|
|
|
-const cancel = () => closeAndResult(false)
|
|
|
|
|
|
|
+const handleConfirm = () => close(true)
|
|
|
|
|
+const handleCancel = () => close(false)
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
- uni.$on('showConfirm', handleShowConfirm)
|
|
|
|
|
|
|
+ uni.$on('showConfirm', handleShowConfirm)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
|
- uni.$off('showConfirm', handleShowConfirm)
|
|
|
|
|
-})
|
|
|
|
|
-const visible = ref(false)
|
|
|
|
|
-watch(visible, (value) => {
|
|
|
|
|
- if (!value) closeAndResult(false)
|
|
|
|
|
|
|
+ uni.$off('showConfirm', handleShowConfirm)
|
|
|
|
|
+ visible.value = false
|
|
|
|
|
+ isShowing = false
|
|
|
|
|
+ currentEventId = null
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
<style scoped lang="scss">
|
|
|
@import "@/uni.scss";
|
|
@import "@/uni.scss";
|
|
|
:deep(.cwg-dialog) {
|
|
:deep(.cwg-dialog) {
|
|
|
- width: px2rpx(500);
|
|
|
|
|
- background-color: #fff;
|
|
|
|
|
- border-radius: px2rpx(16);
|
|
|
|
|
- text-align: center;
|
|
|
|
|
- box-shadow: 0 px2rpx(10) px2rpx(20) rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
+ width: px2rpx(500);
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: px2rpx(16);
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ box-shadow: 0 px2rpx(10) px2rpx(20) rgba(0, 0, 0, 0.1);
|
|
|
}
|
|
}
|
|
|
.confirm-title {
|
|
.confirm-title {
|
|
|
- font-size: px2rpx(24);
|
|
|
|
|
- font-weight: 600;
|
|
|
|
|
- color: #333;
|
|
|
|
|
- margin-bottom: px2rpx(30);
|
|
|
|
|
|
|
+ font-size: px2rpx(24);
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ color: #333;
|
|
|
|
|
+ margin-bottom: px2rpx(30);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
.confirm-content {
|
|
.confirm-content {
|
|
|
- font-size: px2rpx(20);
|
|
|
|
|
- color: #666;
|
|
|
|
|
- margin-bottom: px2rpx(30);
|
|
|
|
|
- line-height: 1.5;
|
|
|
|
|
- word-break: break-word;
|
|
|
|
|
|
|
+ font-size: px2rpx(20);
|
|
|
|
|
+ color: #666;
|
|
|
|
|
+ margin-bottom: px2rpx(30);
|
|
|
|
|
+ line-height: 1.5;
|
|
|
|
|
+ word-break: break-word;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-</style>
|
|
|
|
|
|
|
+</style>
|