import { ref } from 'vue'; import { useOperationVoiceBroadcast } from './useOperationVoiceBroadcast'; export type ScanFeedbackType = 'idle' | 'success' | 'error' | 'warning'; /** * 扫描页左侧反馈区 + 语音播报。 */ export function useOperationScanFeedback(pageKey: string) { const { voiceEnabled, speak, stopSpeak } = useOperationVoiceBroadcast(pageKey); const feedbackType = ref('idle'); const feedbackMessage = ref(''); function clearFeedback() { feedbackType.value = 'idle'; feedbackMessage.value = ''; } function showFeedback(type: ScanFeedbackType, message: string, withVoice = true) { feedbackType.value = type; feedbackMessage.value = message; if (withVoice && (type === 'error' || type === 'success' || type === 'warning')) { speak(message); } } function showError(message: string, withVoice = true) { showFeedback('error', message, withVoice); } function showSuccess(message: string, withVoice = true) { showFeedback('success', message, withVoice); } function showWarning(message: string, withVoice = true) { showFeedback('warning', message, withVoice); } return { voiceEnabled, feedbackType, feedbackMessage, speak, stopSpeak, clearFeedback, showFeedback, showError, showSuccess, showWarning, }; }