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,56 @@
/**
* 对话页:语音输入(当前功能开关关闭,保留占位与思考态取消录音)。
*/
import { watch } from 'vue';
import { getVoiceUnavailableErrorKey, useAudioTranscription } from '@/shared/composables/useAudioTranscription';
import type { Ref } from 'vue';
const VOICE_INPUT_ENABLED = false;
export interface ChatPageVoiceContext {
input: Ref<string>;
isThinking: Ref<boolean>;
msg: { info: (text: string) => void; warning: (text: string) => void };
t: (key: string) => string;
}
export function useChatPageVoice(ctx: ChatPageVoiceContext) {
const {
isRecording: isVoiceRecording,
isTranscribing: isVoiceTranscribing,
toggle: toggleVoiceInput,
cancel: cancelVoiceInput,
} = useAudioTranscription({
onResult: (text) => {
ctx.input.value = text;
},
onError: (key) => {
ctx.msg.warning(ctx.t(key));
},
});
const handleVoiceFeatureClick = () => {
if (!VOICE_INPUT_ENABLED) {
ctx.msg.info(ctx.t('chat.devComingSoon'));
return;
}
if (ctx.isThinking.value || isVoiceTranscribing.value) return;
const unavailable = getVoiceUnavailableErrorKey();
if (unavailable) {
ctx.msg.warning(ctx.t(unavailable));
return;
}
toggleVoiceInput(ctx.input.value);
};
watch(ctx.isThinking, (thinking) => {
if (thinking) cancelVoiceInput();
});
return {
isVoiceRecording,
isVoiceTranscribing,
handleVoiceFeatureClick,
cancelVoiceInput,
};
}