|
@@ -1,22 +1,26 @@
|
|
|
-import { closeToast, showLoadingToast, showToast, Toast } from "vant";
|
|
|
-import { defineComponent, onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
|
|
-import { getLeveByScoreMeasure, IEvaluatings } from "./evaluatResult";
|
|
|
+import { Snackbar } from "@varlet/ui";
|
|
|
+import { closeToast, showLoadingToast } from "vant";
|
|
|
+import { defineComponent, onBeforeMount, onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
|
|
+import { getLeveByScore, getLeveByScoreMeasure, IEvaluatings } from "./evaluatResult";
|
|
|
import {
|
|
|
+ cancelEvaluating,
|
|
|
endEvaluating,
|
|
|
endSoundCheck,
|
|
|
getEarphone,
|
|
|
- proxyServiceMessage,
|
|
|
+ api_proxyServiceMessage,
|
|
|
removeResult,
|
|
|
sendResult,
|
|
|
startEvaluating,
|
|
|
startRecording,
|
|
|
startSoundCheck,
|
|
|
+ api_openWebView,
|
|
|
} 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({
|
|
|
+ /** 评测模块是否加载完成 */
|
|
|
+ rendered: false,
|
|
|
earphone: false, // 是否插入耳机
|
|
|
soundEffect: false, // 是否效音
|
|
|
soundEffectFrequency: 0, // 效音频率
|
|
@@ -29,8 +33,26 @@ export const evaluatingData = reactive({
|
|
|
backtime: 0, // 延迟时间
|
|
|
/** 已经评测的数据 */
|
|
|
evaluatings: {} as IEvaluatings,
|
|
|
+ /** 评测结果 */
|
|
|
+ resultData: {} as any,
|
|
|
+ /** 评测结果弹窗 */
|
|
|
+ resulstMode: false
|
|
|
});
|
|
|
|
|
|
+/** 点击开始评测按钮 */
|
|
|
+export const handleStartEvaluat = () => {
|
|
|
+ if (state.modeType === 'evaluating') {
|
|
|
+ handleCancelEvaluat()
|
|
|
+ } else {
|
|
|
+ handleStopPlay()
|
|
|
+ }
|
|
|
+ state.modeType = state.modeType === 'evaluating' ? 'practise' : 'evaluating'
|
|
|
+ if (state.modeType !== 'evaluating') {
|
|
|
+ // 切换到练习模式,卸载评测模块
|
|
|
+ evaluatingData.rendered = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/** 开始播放发送延迟时间 */
|
|
|
export const sendEvaluatingOffsetTime = (currentTime: number) => {
|
|
|
const nowTime = Date.now();
|
|
@@ -41,7 +63,7 @@ export const sendEvaluatingOffsetTime = (currentTime: number) => {
|
|
|
console.log("真正播放延迟", delayTime);
|
|
|
// 蓝牙耳机延迟一点发送消息确保在录音后面
|
|
|
setTimeout(async () => {
|
|
|
- await proxyServiceMessage({
|
|
|
+ await api_proxyServiceMessage({
|
|
|
header: {
|
|
|
commond: "audioPlayStart",
|
|
|
type: "SOUND_COMPARE",
|
|
@@ -66,25 +88,25 @@ const checkSoundEffect = () => {
|
|
|
};
|
|
|
|
|
|
const handleSoundEffect = (res?: IPostMessage) => {
|
|
|
- if (res?.content) {
|
|
|
- const { header, body } = res.content;
|
|
|
- if (header.commond === "checking") {
|
|
|
- evaluatingData.soundEffectFrequency = body.frequency;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+ if (res?.content) {
|
|
|
+ const { header, body } = res.content;
|
|
|
+ if (header.commond === "checking") {
|
|
|
+ evaluatingData.soundEffectFrequency = body.frequency;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
* 开始录音
|
|
|
*/
|
|
|
const handleStartSoundCheck = () => {
|
|
|
- sendResult(handleSoundEffect)
|
|
|
- startSoundCheck();
|
|
|
-}
|
|
|
+ sendResult(handleSoundEffect);
|
|
|
+ startSoundCheck();
|
|
|
+};
|
|
|
/** 结束录音 */
|
|
|
export const handleEndSoundCheck = () => {
|
|
|
endSoundCheck();
|
|
|
- removeResult(handleSoundEffect);
|
|
|
+ removeResult(handleSoundEffect);
|
|
|
};
|
|
|
|
|
|
/** 连接websocket */
|
|
@@ -97,7 +119,7 @@ export const connectWebsocket = async (content: any) => {
|
|
|
if (res?.api === "startEvaluating") {
|
|
|
evaluatingData.websocketState = true;
|
|
|
} else {
|
|
|
- showToast("请在APP端进行评测");
|
|
|
+ Snackbar.error("请在APP端进行评测")
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -109,8 +131,12 @@ export const handlePerformDetection = async () => {
|
|
|
if (evaluatingData.checkStep === 0) {
|
|
|
// 检测耳机
|
|
|
const erji = await checkUseEarphone();
|
|
|
- evaluatingData.earphoneMode = !erji;
|
|
|
evaluatingData.checkStep = 1;
|
|
|
+ if (erji) {
|
|
|
+ handlePerformDetection();
|
|
|
+ } else {
|
|
|
+ evaluatingData.earphoneMode = true;
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
if (evaluatingData.checkStep === 1) {
|
|
@@ -126,36 +152,46 @@ export const handlePerformDetection = async () => {
|
|
|
if (evaluatingData.checkStep === 10) {
|
|
|
// 连接websocket
|
|
|
evaluatingData.checkEnd = true;
|
|
|
+ evaluatingData.checkStep = 0
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/** 记录小节分数 */
|
|
|
const addMeasureScore = (measureScore: any) => {
|
|
|
- evaluatingData.evaluatings[measureScore.measureRenderIndex] = {
|
|
|
- ...measureScore,
|
|
|
- leve: getLeveByScoreMeasure(measureScore.score)
|
|
|
- }
|
|
|
- console.log("🚀 ~ measureScore:", evaluatingData.evaluatings[measureScore.measureRenderIndex])
|
|
|
-}
|
|
|
+ evaluatingData.evaluatings[measureScore.measureRenderIndex] = {
|
|
|
+ ...measureScore,
|
|
|
+ leve: getLeveByScoreMeasure(measureScore.score),
|
|
|
+ show: true,
|
|
|
+ };
|
|
|
+ // 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()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+ if (res?.content) {
|
|
|
+ // console.log("🚀 ~ 评测返回:", res);
|
|
|
+ const { header, body } = res.content;
|
|
|
+ if (header?.commond === "measureScore") {
|
|
|
+ addMeasureScore(body);
|
|
|
+ }
|
|
|
+ if (header?.commond === "overall") {
|
|
|
+ // console.log("评测结束", body);
|
|
|
+ evaluatingData.resulstMode = true
|
|
|
+ evaluatingData.resultData = {
|
|
|
+ ...body,
|
|
|
+ ...getLeveByScore(body.score)
|
|
|
+ }
|
|
|
+ console.log("🚀 ~ evaluatingData.resultData:", evaluatingData.resultData)
|
|
|
+ removeResult(handleScoreResult);
|
|
|
+ closeToast();
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
/** 开始评测 */
|
|
|
export const handleStartBegin = async () => {
|
|
|
evaluatingData.startBegin = true;
|
|
|
+ evaluatingData.evaluatings = {};
|
|
|
+ evaluatingData.resultData = {};
|
|
|
sendResult(handleScoreResult);
|
|
|
await startRecording();
|
|
|
evaluatingData.backtime = Date.now();
|
|
@@ -171,18 +207,59 @@ export const handleEndBegin = (isEnd = false) => {
|
|
|
endEvaluating({
|
|
|
musicScoreId: state.examSongId,
|
|
|
});
|
|
|
- showLoadingToast({
|
|
|
- message: '评分中',
|
|
|
- duration: 0,
|
|
|
- forbidClick: true,
|
|
|
- })
|
|
|
-
|
|
|
- if (isEnd) return
|
|
|
+ showLoadingToast({
|
|
|
+ message: "评分中",
|
|
|
+ duration: 0,
|
|
|
+ forbidClick: true,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (isEnd) return;
|
|
|
handleStopPlay();
|
|
|
};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 取消评测
|
|
|
+ */
|
|
|
+export const handleCancelEvaluat = () => {
|
|
|
+ evaluatingData.evaluatings = {};
|
|
|
+ // 关闭提示
|
|
|
+ closeToast();
|
|
|
+ // 取消记录
|
|
|
+ api_proxyServiceMessage({
|
|
|
+ header: {
|
|
|
+ commond: "recordCancel",
|
|
|
+ type: "SOUND_COMPARE",
|
|
|
+ status: 200,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ // 取消评测
|
|
|
+ cancelEvaluating();
|
|
|
+ // 卸载评测监听
|
|
|
+ removeResult(handleScoreResult);
|
|
|
+ // 停止播放
|
|
|
+ handleStopPlay();
|
|
|
+};
|
|
|
+
|
|
|
+/** 查看报告 */
|
|
|
+export const handleViewReport = () => {
|
|
|
+ api_openWebView({
|
|
|
+ url: location.origin + "/accompany/#/report/" + evaluatingData.resultData?.recordId || "",
|
|
|
+ orientation: 0,
|
|
|
+ isHideTitle: true, // 此处兼容安卓,意思为隐藏全部头部
|
|
|
+ statusBarTextColor: false,
|
|
|
+ isOpenLight: true,
|
|
|
+ });
|
|
|
+};
|
|
|
export default defineComponent({
|
|
|
name: "evaluating",
|
|
|
setup() {
|
|
|
+ onBeforeMount(() => {
|
|
|
+ evaluatingData.resultData = {}
|
|
|
+ evaluatingData.evaluatings = {}
|
|
|
+ evaluatingData.soundEffectFrequency = 0
|
|
|
+ evaluatingData.checkStep = 0
|
|
|
+ evaluatingData.rendered = true
|
|
|
+ })
|
|
|
return () => <div></div>;
|
|
|
},
|
|
|
});
|