修改语音不显示秒数,修复一直按着发送自动交卷的问题

This commit is contained in:
田岩
2025-09-23 18:11:12 +08:00
parent 6f2dd37f01
commit ced4aeb2f4
8 changed files with 62 additions and 31 deletions
+2 -1
View File
@@ -176,12 +176,12 @@
};
const playVoice = () => {
// isPlaying.value = true;
console.log('点击播放');
innerAudio.playAudio();
};
let unsubscribe = () => {};
onMounted(() => {
console.log('question的onMounted');
// 2. 监听 Store 中 isPlaying 的变化,实时同步
// unsubscribe = innerAudio.$subscribe((mutation, state) => {
// isPlaying.value = state.isPlaying;
@@ -214,6 +214,7 @@
console.log('去下载oss内容333', props.dataInfo);
if (newVal === '' && props.dataInfo.ossKey) {
// 去下载oss内容
console.log('真下载oss内容');
downloadFile(props.dataInfo.ossKey).then((res) => {
voiceTime.value = '';
innerAudio.setAudioSrc(res.tempFilePath);
+19 -6
View File
@@ -73,7 +73,7 @@
</template>
<script setup>
import {ref, computed, onMounted, nextTick, watch, reactive } from 'vue';
import { ref, computed, onMounted, nextTick, watch, reactive } from 'vue';
import common from '@/common/common';
import permission from '@/common/permission.js';
import { getPhoneEnvBool } from '@/common/common.js';
@@ -133,7 +133,11 @@
const startTimer = ref(null); // 延迟启动的定时器ID
const startFlag = ref(1);
const startRecord = async (obj) => {
try {await initRecord()}catch(err) {return;}
try {
await initRecord();
} catch (err) {
return;
}
if (props.isDisabled) return;
// 开始录音
console.log('开始录音', recordingStatus.value);
@@ -163,9 +167,10 @@
const endTime = Date.now();
const times = Math.max(500 - endTime + startTime, 0);
setTimeout(() => {
popupRef.value.close();
console.log('停止录音');
recorderManager.stop();
recorderManager?.stop();
popupRef.value?.close();
}, times);
}
nextTick(() => (recordingStatus.value = 'not_started'));
@@ -184,7 +189,7 @@
return;
}
popupRef.value?.close();
recordingStatus.value = 'not_started'
recordingStatus.value = 'not_started';
// stopRecord(true); // 在去主动执行一次关闭
console.log('录音结束,时长:', recordDuration, '秒');
emit('submit', 'voice', res.tempFilePath);
@@ -215,6 +220,7 @@
const btnHeight = (windowInfo.screenWidth / 750) * 234;
return touchY.value < safeArea.bottom - btnHeight;
});
const activeNum = ref(1);
const handleMove = (obj) => {
touchY.value = obj.changedTouches[0].pageY;
@@ -224,7 +230,7 @@
inputText.value = text;
return old_text;
};
defineExpose({ clearinputText });
// 发送文本
const showKeyboard = () => {
if (keyboardIsShow.value) {
@@ -249,6 +255,13 @@
console.log('禁用时点击给的提示');
if (props.isDisabled) common.msg(props.disabledText);
};
// 外面调用放弃这次
const give_up = () => {
console.log('调用结束语音回答');
stopRecord(false)
};
defineExpose({ clearinputText, give_up });
</script>
<style lang="scss" scoped>
+10 -5
View File
@@ -12,7 +12,7 @@ const audioStopFun = ref(null)
export const useAudio = () => {
const audioInstance = uni.createInnerAudioContext();
const callbacks = reactive({
onEnded: null, // 播放完成回调
@@ -20,17 +20,23 @@ export const useAudio = () => {
onLoaded: null, // 音频加载完成回调(可获取时长)
onStop: null
})
let isInitialized = false;
const isPlaying = ref(false)
// 加载状态
const isLoading = ref(false)
// 当前播放的音频地址
const currentSrc = ref('')
const errorMsg = ref('')
// 初始化音频实例(确保全局唯一)
const initAudio = () => {
console.log('初始化音频实例(确保全局唯一)');
// if (isInitialized) return;
// isInitialized = true;
bindAudioEvents();
}
const bindAudioEvents = () => {
if (!audioInstance) return;
@@ -101,7 +107,7 @@ export const useAudio = () => {
const setAudioSrc = (src) => {
console.log('预设置音频地址并加载', src);
if (!src || src === currentSrc.value) return; // 地址不变则不重复加载
initAudio();
isLoading.value = true;
currentSrc.value = src;
errorMsg.value = '';
@@ -185,7 +191,6 @@ export const useAudio = () => {
callbacks.onEnded = callback;
}
}
// 注册播放错误回调
const onAudioError = (callback) => {
if (typeof callback === 'function') {
@@ -203,7 +208,7 @@ export const useAudio = () => {
callbacks.onStop = callback;
}
}
initAudio();
return {
isPlaying,
@@ -1,8 +1,8 @@
<template>
<view>
<image :src="imgUrlShow" :mode="mode" @click="showDetail" style="width: 100%; height: 100%"></image>
<uni-popup ref="PopupRef" class="popup" mask-background-color="rgba(0,0,0,.2)" @change="changeShow">
<view class="overlay-box" @click="closePopup">
<uni-popup ref="PopupRef" class="popup" mask-background-color="rgba(0,0,0,.2)" background-color="rgba(0,0,0,.2)" @change="changeShow">
<view class="overlay-box" @click="closePopup" @touchmove.stop>
<image class="detail-img" :src="imgUrlShow" :mode="mode"></image>
</view>
</uni-popup>