'commit'
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
<link rel="stylesheet" href="physics_quiz.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 权限问题链接移到顶部 -->
|
||||
<div style="position: fixed; top: 10px; right: 10px; z-index: 9999; background: rgba(255,255,255,0.9); padding: 5px 10px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
|
||||
<a href="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/11%E3%80%81%E5%AD%A6%E4%BC%B4Chrome%E5%BD%95%E9%9F%B3%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9.pdf" style="color: #007bff; text-decoration: none; font-size: 14px;">有权限问题?</a>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>物理知识测验 - 万有引力定律</h1>
|
||||
@@ -105,9 +110,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/11%E3%80%81%E5%AD%A6%E4%BC%B4Chrome%E5%BD%95%E9%9F%B3%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9.pdf">有权限问题?</a>
|
||||
</div>
|
||||
<!-- 移除底部的权限问题链接,已经移到顶部 -->
|
||||
|
||||
<!-- 引入看板娘相关脚本 -->
|
||||
<script src="https://l2dwidget.js.org/lib/L2Dwidget.min.js"></script>
|
||||
|
@@ -51,6 +51,16 @@ const UIController = {
|
||||
this.toggleElement('stopRecordBtn', isRecording);
|
||||
},
|
||||
|
||||
// 禁用/启用帮我讲题按钮
|
||||
setStartRecordButtonEnabled(enabled) {
|
||||
const startBtn = document.getElementById('startRecordBtn');
|
||||
if (startBtn) {
|
||||
startBtn.disabled = !enabled;
|
||||
startBtn.style.opacity = enabled ? '1' : '0.5';
|
||||
startBtn.style.cursor = enabled ? 'pointer' : 'not-allowed';
|
||||
}
|
||||
},
|
||||
|
||||
// 更新播放按钮图标
|
||||
updatePlayButton(isPlaying) {
|
||||
const btn = document.getElementById('playAudioBtn');
|
||||
@@ -150,6 +160,12 @@ const ASRProcessor = {
|
||||
async processAudio(audioBlob) {
|
||||
console.log('开始上传音频到服务器');
|
||||
UIController.toggleElement('thinkingIndicator', true);
|
||||
// 禁用帮我讲题按钮,防止在思考过程中重复点击
|
||||
UIController.setStartRecordButtonEnabled(false);
|
||||
|
||||
// 创建AbortController用于超时控制
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 120000); // 120秒超时
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
@@ -157,14 +173,20 @@ const ASRProcessor = {
|
||||
|
||||
const response = await fetch('/api/xueban/upload-audio', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
body: formData,
|
||||
signal: controller.signal // 添加超时信号
|
||||
});
|
||||
|
||||
// 请求成功,清除超时定时器
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (!response.ok) throw new Error('服务器响应错误');
|
||||
|
||||
const data = await response.json();
|
||||
console.log('处理结果:', data);
|
||||
UIController.toggleElement('thinkingIndicator', false);
|
||||
// 思考结束,重新启用帮我讲题按钮
|
||||
UIController.setStartRecordButtonEnabled(true);
|
||||
|
||||
if (data.success) {
|
||||
ResultDisplay.showResults(data.data);
|
||||
@@ -172,9 +194,20 @@ const ASRProcessor = {
|
||||
alert('音频处理失败: ' + data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
// 清除超时定时器
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
console.error('上传音频失败:', error);
|
||||
UIController.toggleElement('thinkingIndicator', false);
|
||||
alert('上传音频失败: ' + error.message);
|
||||
// 发生错误时也要重新启用按钮
|
||||
UIController.setStartRecordButtonEnabled(true);
|
||||
|
||||
// 判断是否是超时错误
|
||||
if (error.name === 'AbortError') {
|
||||
alert('请求超时,服务器响应时间过长,请稍后再试');
|
||||
} else {
|
||||
alert('上传音频失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user