refactor(frontend): 重构前端第二版

This commit is contained in:
sophie committed 2026-06-11 13:47:06 +08:00
1 parent 2631f78b00
commit 4b562cfa82
205 files changed
+15399 -12015

No files matched your search

@@ -0,0 +1,69 @@
/**
* 对话页:删除确认弹窗、消息反馈弹窗状态。
*/
import { computed, ref } from 'vue';
import type { ChatMessage } from '../types/chat.types';
import type { Ref } from 'vue';
export function useChatPageDialogs(messages: Ref<ChatMessage[]>) {
const showDeleteConfirmDialog = ref(false);
const deleteConfirmMessage = ref('');
let pendingDeleteAction: (() => Promise<void> | void) | null = null;
const openDeleteConfirmDialog = (
message: string,
onConfirm: () => Promise<void> | void,
) => {
deleteConfirmMessage.value = message;
pendingDeleteAction = onConfirm;
showDeleteConfirmDialog.value = true;
};
const closeDeleteConfirmDialog = () => {
showDeleteConfirmDialog.value = false;
deleteConfirmMessage.value = '';
pendingDeleteAction = null;
};
const handleDeleteConfirm = async () => {
if (!pendingDeleteAction) return;
await pendingDeleteAction();
closeDeleteConfirmDialog();
};
const showGeneralFeedbackDialog = ref(false);
const activeFeedbackMessageIndex = ref<number | null>(null);
const handleOpenFeedback = (index: number) => {
activeFeedbackMessageIndex.value = index;
showGeneralFeedbackDialog.value = true;
};
const currentGeneralFeedbackChatLogId = computed(() => {
if (activeFeedbackMessageIndex.value !== null) {
const msgItem = messages.value[activeFeedbackMessageIndex.value];
const id = Number(msgItem?.chat_log_id);
if (Number.isInteger(id) && id > 0) return id;
}
for (let i = messages.value.length - 1; i >= 0; i--) {
const msgItem = messages.value[i];
if (msgItem?.role === 'assistant') {
const id = Number(msgItem?.chat_log_id);
if (Number.isInteger(id) && id > 0) return id;
}
}
return null;
});
return {
showDeleteConfirmDialog,
deleteConfirmMessage,
openDeleteConfirmDialog,
closeDeleteConfirmDialog,
handleDeleteConfirm,
showGeneralFeedbackDialog,
activeFeedbackMessageIndex,
handleOpenFeedback,
currentGeneralFeedbackChatLogId,
};
}