Skip to content

Commit 2c345f8

Browse files
committed
1. 修复手机端返回键无法关闭 Emoji 弹窗
1 parent d97b883 commit 2c345f8

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

vue/src/App.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ function handleBackButton() {
213213
} else if (uiStore.activeModal) {
214214
uiStore.hideModal();
215215
handled = true;
216+
// ✅ MODIFICATION START: Add check for EmojiPicker
217+
} else if (uiStore.isEmojiPickerVisible) {
218+
uiStore.toggleEmojiPicker(false);
219+
handled = true;
220+
// ✅ MODIFICATION END
216221
} else if (uiStore.isDetailsPanelOpen) {
217222
uiStore.toggleDetailsPanel(false);
218223
handled = true;

vue/src/components/ChatView/MessageInput.vue

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
</div>
101101
</div>
102102
<EmojiPicker
103-
:show="isEmojiPickerVisible"
103+
:show="uiStore.isEmojiPickerVisible"
104104
@select-emoji="insertEmoji"
105105
@select-sticker="sendSticker"
106106
/>
@@ -132,7 +132,9 @@ const uiStore = useUiStore();
132132
const newMessage = ref('');
133133
const textareaRef = ref(null);
134134
const fileInputRef = ref(null);
135-
const isEmojiPickerVisible = ref(false);
135+
// --- ❌ REMOVAL ---
136+
// const isEmojiPickerVisible = ref(false);
137+
// --- ❌ REMOVAL ---
136138
const preview = ref(null);
137139
const isRecording = ref(false);
138140
const recordingDuration = ref(0);
@@ -194,13 +196,27 @@ function send() {
194196
// ✅ MODIFICATION START: Handle stickerId instead of sticker object
195197
function sendSticker(stickerId) {
196198
chatStore.sendMessage({ stickerId });
197-
isEmojiPickerVisible.value = false;
199+
// ✅ MODIFICATION: Use store action to close
200+
uiStore.toggleEmojiPicker(false);
198201
}
199202
// ✅ MODIFICATION END
200203
201204
function insertEmoji(emoji) { const textarea = textareaRef.value; const start = textarea.selectionStart; const end = textarea.selectionEnd; newMessage.value = newMessage.value.substring(0, start) + emoji + newMessage.value.substring(end); nextTick(() => { textarea.selectionStart = textarea.selectionEnd = start + emoji.length; textarea.focus(); }); }
202-
function toggleEmojiPicker() { isEmojiPickerVisible.value = !isEmojiPickerVisible.value; }
203-
function closeEmojiPicker(event) { if (isEmojiPickerVisible.value && !event.target.closest('.picker-container, .input-container')) { isEmojiPickerVisible.value = false; } }
205+
206+
// ✅ MODIFICATION START: Use store action
207+
function toggleEmojiPicker() {
208+
uiStore.toggleEmojiPicker();
209+
}
210+
// ✅ MODIFICATION END
211+
212+
// ✅ MODIFICATION START: Use store state and action
213+
function closeEmojiPicker(event) {
214+
if (uiStore.isEmojiPickerVisible && !event.target.closest('.picker-container, .input-container')) {
215+
uiStore.toggleEmojiPicker(false);
216+
}
217+
}
218+
// ✅ MODIFICATION END
219+
204220
async function handleFileSelect(event) { const file = event.target.files[0]; if (file) await processFile(file); if(event.target) event.target.value = ''; }
205221
async function handlePaste(event) { const file = event.clipboardData.files[0]; if (file?.type.startsWith('image/')) { event.preventDefault(); await processFile(file); } }
206222
async function processFile(file) {

vue/src/stores/uiStore.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const useUiStore = defineStore('ui', () => {
2525
// const manualSdpText = ref('');
2626
// const commentModalContent = ref(null); // No longer needed
2727

28+
// ✅ MODIFICATION START: Add new state for EmojiPicker
29+
const isEmojiPickerVisible = ref(false);
30+
// ✅ MODIFICATION END
31+
2832
// --- ACTIONS ---
2933
function toggleDetailsPanel(forceState, content = 'info') {
3034
if (typeof forceState === 'boolean') {
@@ -37,6 +41,16 @@ export const useUiStore = defineStore('ui', () => {
3741
}
3842
}
3943

44+
// ✅ MODIFICATION START: Add new action to control EmojiPicker
45+
function toggleEmojiPicker(forceState) {
46+
if (typeof forceState === 'boolean') {
47+
isEmojiPickerVisible.value = forceState;
48+
} else {
49+
isEmojiPickerVisible.value = !isEmojiPickerVisible.value;
50+
}
51+
}
52+
// ✅ MODIFICATION END
53+
4054
function showModal(modalName, prefillData = {}) {
4155
modalPrefillData.value = prefillData;
4256
// --- [移除] ---
@@ -45,6 +59,11 @@ export const useUiStore = defineStore('ui', () => {
4559
}
4660

4761
function hideModal() {
62+
// ✅ MODIFICATION START: Also hide emoji picker when a modal is hidden
63+
if (isEmojiPickerVisible.value) {
64+
isEmojiPickerVisible.value = false;
65+
}
66+
// ✅ MODIFICATION END
4867
activeModal.value = null;
4968
activeOverlayModal.value = null;
5069
modalPrefillData.value = {};
@@ -134,6 +153,9 @@ export const useUiStore = defineStore('ui', () => {
134153
locationViewerContent,
135154
isPerformingDangerousAction,
136155
imageCropperContent,
156+
// ✅ MODIFICATION START: Expose new state and action
157+
isEmojiPickerVisible,
158+
// ✅ MODIFICATION END
137159
toggleDetailsPanel,
138160
showModal,
139161
hideModal,
@@ -146,5 +168,8 @@ export const useUiStore = defineStore('ui', () => {
146168
showMediaViewer,
147169
showLocationViewer,
148170
showImageCropperOverlay,
171+
// ✅ MODIFICATION START: Expose new state and action
172+
toggleEmojiPicker,
173+
// ✅ MODIFICATION END
149174
};
150175
});

0 commit comments

Comments
 (0)