|
@@ -1,10 +1,12 @@
|
|
|
-import { showToast } from "vant";
|
|
|
+import { closeToast, showLoadingToast, showToast, Toast } from "vant";
|
|
|
import { defineComponent, onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
|
|
+import { getLeveByScoreMeasure, IEvaluatings } from "./evaluatResult";
|
|
|
import {
|
|
|
endEvaluating,
|
|
|
endSoundCheck,
|
|
|
getEarphone,
|
|
|
proxyServiceMessage,
|
|
|
+ removeResult,
|
|
|
sendResult,
|
|
|
startEvaluating,
|
|
|
startRecording,
|
|
@@ -12,6 +14,7 @@ import {
|
|
|
} from "/src/helpers/communication";
|
|
|
import _event, { EventEnum } from "/src/helpers/eventemitter";
|
|
|
import state, { handleStopPlay, togglePlay } from "/src/state";
|
|
|
+import { IPostMessage } from "/src/utils/native-message";
|
|
|
|
|
|
export const evaluatingData = reactive({
|
|
|
earphone: false, // 是否插入耳机
|
|
@@ -24,17 +27,16 @@ export const evaluatingData = reactive({
|
|
|
websocketState: false, // websocket连接状态
|
|
|
startBegin: false, // 开始
|
|
|
backtime: 0, // 延迟时间
|
|
|
- measureIndex: -1,
|
|
|
- measureRenderIndex: -1,
|
|
|
- score: 0, // 评测分数
|
|
|
+ /** 已经评测的数据 */
|
|
|
+ evaluatings: {} as IEvaluatings,
|
|
|
});
|
|
|
|
|
|
/** 开始播放发送延迟时间 */
|
|
|
export const sendEvaluatingOffsetTime = (currentTime: number) => {
|
|
|
const nowTime = Date.now();
|
|
|
- console.log("第一次播放时间", nowTime);
|
|
|
- console.log("已播放时长: ", currentTime * 1000);
|
|
|
- console.log("不减掉已播放时间: ", nowTime - evaluatingData.backtime);
|
|
|
+ // console.log("第一次播放时间", nowTime);
|
|
|
+ // console.log("已播放时长: ", currentTime, currentTime * 1000);
|
|
|
+ // console.log("不减掉已播放时间: ", nowTime - evaluatingData.backtime);
|
|
|
const delayTime = nowTime - evaluatingData.backtime - currentTime * 1000;
|
|
|
console.log("真正播放延迟", delayTime);
|
|
|
// 蓝牙耳机延迟一点发送消息确保在录音后面
|
|
@@ -45,7 +47,7 @@ export const sendEvaluatingOffsetTime = (currentTime: number) => {
|
|
|
type: "SOUND_COMPARE",
|
|
|
},
|
|
|
body: {
|
|
|
- offsetTime: delayTime,
|
|
|
+ offsetTime: delayTime < 0 ? 0 : delayTime,
|
|
|
},
|
|
|
});
|
|
|
evaluatingData.backtime = 0;
|
|
@@ -63,24 +65,26 @@ const checkSoundEffect = () => {
|
|
|
return state.setting.soundEffect;
|
|
|
};
|
|
|
|
|
|
+const handleSoundEffect = (res?: IPostMessage) => {
|
|
|
+ if (res?.content) {
|
|
|
+ const { header, body } = res.content;
|
|
|
+ if (header.commond === "checking") {
|
|
|
+ evaluatingData.soundEffectFrequency = body.frequency;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 开始录音
|
|
|
*/
|
|
|
-const useSoundEffect = () => {
|
|
|
- handleEndSoundCheck();
|
|
|
- sendResult((res) => {
|
|
|
- if (res?.content) {
|
|
|
- const { header, body } = res.content;
|
|
|
- if (header.commond === "checking") {
|
|
|
- evaluatingData.soundEffectFrequency = body.frequency;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- startSoundCheck();
|
|
|
-};
|
|
|
+const handleStartSoundCheck = () => {
|
|
|
+ sendResult(handleSoundEffect)
|
|
|
+ startSoundCheck();
|
|
|
+}
|
|
|
/** 结束录音 */
|
|
|
export const handleEndSoundCheck = () => {
|
|
|
endSoundCheck();
|
|
|
+ removeResult(handleSoundEffect);
|
|
|
};
|
|
|
|
|
|
/** 连接websocket */
|
|
@@ -114,7 +118,7 @@ export const handlePerformDetection = async () => {
|
|
|
// 是否需要开启效音
|
|
|
if (checkSoundEffect()) {
|
|
|
evaluatingData.soundEffectMode = true;
|
|
|
- useSoundEffect();
|
|
|
+ handleStartSoundCheck();
|
|
|
}
|
|
|
evaluatingData.checkStep = 10;
|
|
|
return;
|
|
@@ -125,19 +129,34 @@ export const handlePerformDetection = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+/** 记录小节分数 */
|
|
|
+const addMeasureScore = (measureScore: any) => {
|
|
|
+ evaluatingData.evaluatings[measureScore.measureRenderIndex] = {
|
|
|
+ ...measureScore,
|
|
|
+ leve: getLeveByScoreMeasure(measureScore.score)
|
|
|
+ }
|
|
|
+ console.log("🚀 ~ measureScore:", evaluatingData.evaluatings[measureScore.measureRenderIndex])
|
|
|
+}
|
|
|
+
|
|
|
+const handleScoreResult = (res?: IPostMessage) => {
|
|
|
+ if (res?.content) {
|
|
|
+ // console.log("🚀 ~ 评测返回:", res);
|
|
|
+ const { header, body } = res.content;
|
|
|
+ if (header?.commond === 'measureScore'){
|
|
|
+ addMeasureScore(body)
|
|
|
+ }
|
|
|
+ if (header?.commond === 'overall'){
|
|
|
+ console.log('评测结束', body)
|
|
|
+ removeResult(handleSoundEffect);
|
|
|
+ closeToast()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/** 开始评测 */
|
|
|
export const handleStartBegin = async () => {
|
|
|
evaluatingData.startBegin = true;
|
|
|
- sendResult((res) => {
|
|
|
- if (res?.content) {
|
|
|
- // console.log("🚀 ~ 评测返回:", res);
|
|
|
- const { header } = res.content;
|
|
|
- if (["measureScore", "overall"].includes(header.commond)) {
|
|
|
- // console.log('评测返回1', new Date().toLocaleString())
|
|
|
- _event.emit(EventEnum.sendResultScore, res.content)
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ sendResult(handleScoreResult);
|
|
|
await startRecording();
|
|
|
evaluatingData.backtime = Date.now();
|
|
|
togglePlay("play");
|
|
@@ -152,6 +171,12 @@ export const handleEndBegin = (isEnd = false) => {
|
|
|
endEvaluating({
|
|
|
musicScoreId: state.examSongId,
|
|
|
});
|
|
|
+ showLoadingToast({
|
|
|
+ message: '评分中',
|
|
|
+ duration: 0,
|
|
|
+ forbidClick: true,
|
|
|
+ })
|
|
|
+
|
|
|
if (isEnd) return
|
|
|
handleStopPlay();
|
|
|
};
|