index.tsx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. import { Transition, defineComponent, onMounted, reactive, watch, defineAsyncComponent, computed, onUnmounted } from "vue";
  2. import { connectWebsocket, evaluatingData, handleEndBegin, handleStartBegin, handleStartEvaluat, handleViewReport, startCheckDelay, checkUseEarphone, handleCancelEvaluat, checkMinInterval, handleEndEvaluat } from "/src/view/evaluating";
  3. import Earphone from "./earphone";
  4. import styles from "./index.module.less";
  5. import SoundEffect from "./sound-effect";
  6. import state, { handleRessetState, resetPlaybackToStart, musicalInstrumentCodeInfo, clearSelection, initSetPlayRate, resetBaseRate } from "/src/state";
  7. import { storeData } from "/src/store";
  8. import { browser } from "/src/utils";
  9. import { getNoteByMeasuresSlursStart } from "/src/helpers/formateMusic";
  10. import { Icon, Popup, showToast, closeToast, showLoadingToast } from "vant";
  11. import EvaluatResult from "./evaluat-result";
  12. import EvaluatAudio from "./evaluat-audio";
  13. import { api_getDeviceDelay, api_openAdjustRecording, api_proxyServiceMessage, api_videoUpdate, getEarphone, api_back, api_startDelayCheck, api_cancelDelayCheck, api_remove_cancelDelayCheck, api_closeDelayCheck, api_finishDelayCheck, api_retryEvaluating, api_remove_finishDelayCheck, api_workUpdate } from "/src/helpers/communication";
  14. import EvaluatShare from "./evaluat-share";
  15. import { Vue3Lottie } from "vue3-lottie";
  16. import startData from "./data/start.json";
  17. import startingData from "./data/starting.json";
  18. import iconTastBg from "./icons/task-bg.svg";
  19. import iconEvaluat from "./icons/evaluating.json";
  20. import { headImg } from "/src/page-instrument/header-top/image";
  21. import { api_musicPracticeRecordVideoUpload } from "../api";
  22. import { headTopData } from "../header-top/index";
  23. import { getQuery } from "/src/utils/queryString";
  24. import Countdown from "./countdown";
  25. import { IPostMessage } from "/src/utils/native-message";
  26. import tipErjiBg from "./icons/tip_erji.png"
  27. import tipErjiBtn from "./icons/tip_btn.png"
  28. import SubmitNoDonePop from "./submit-nodone";
  29. import { selfSubmitWorkHome } from "../custom-plugins/work-index";
  30. // const DelayCheck = defineAsyncComponent(() =>
  31. // import('./delay-check')
  32. // )
  33. // frequency 频率, amplitude 振幅, decibels 分贝
  34. type TCriteria = "frequency" | "amplitude" | "decibels";
  35. /**
  36. * 节拍器时长
  37. * 评测模式时,应该传节拍器时长
  38. * 阶段评测时,判断是否从第一小节开始,并且曲子本身含有节拍器,需要传节拍器时长,否则传0
  39. */
  40. let actualBeatLength = 0;
  41. let calculateInfo: any = {};
  42. let checkErjiTimer: any = null
  43. export const reCheckDelay = () => {
  44. evaluatingData.onceErjiPopShow = false;
  45. evaluatingData.needCheckErjiStatus = true;
  46. headTopData.settingMode = false
  47. state.setting.soundEffect = false
  48. api_startDelayCheck({});
  49. }
  50. export default defineComponent({
  51. name: "evaluat-model",
  52. setup() {
  53. const query = getQuery();
  54. const evaluatModel = reactive({
  55. tips: true,
  56. evaluatUpdateAudio: false,
  57. isSaveVideo: state.setting.camera && state.setting.saveToAlbum,
  58. shareMode: false,
  59. showNoDonePop: false, // 提交作业显示未达标确认弹窗
  60. });
  61. /**
  62. * 检测返回
  63. */
  64. const handleDelayBack = () => {
  65. if (query.workRecord) {
  66. evaluatingData.soundEffectMode = false;
  67. api_back();
  68. } else {
  69. evaluatingData.soundEffectMode = false;
  70. // handleRessetState();
  71. // headTopData.modeType = "init";
  72. }
  73. };
  74. /**
  75. * 执行检测
  76. */
  77. const handlePerformDetection = async () => {
  78. console.log(evaluatingData.checkStep, evaluatingData, "检测123");
  79. // 检测完成不检测了
  80. if (evaluatingData.checkEnd) return;
  81. // 延迟检测
  82. if (evaluatingData.checkStep === 0) {
  83. evaluatingData.checkStep = 10;
  84. // 没有设备延迟数据 或 开启了效音 显示检测组件,并持续检测耳机状态
  85. if (state.setting.soundEffect) {
  86. evaluatingData.soundEffectMode = true;
  87. return;
  88. }
  89. // 判断只有开始了设备检测之后才去调用api
  90. if (state.setting.soundEffect) {
  91. const delayData = await api_getDeviceDelay();
  92. // console.log("🚀 ~ delayTime:", delayData);
  93. if (delayData && delayData.content?.value < 0) {
  94. evaluatingData.soundEffectMode = true;
  95. return;
  96. }
  97. }
  98. handlePerformDetection();
  99. return;
  100. }
  101. // 效验完成
  102. if (evaluatingData.checkStep === 10) {
  103. const erji = await checkUseEarphone();
  104. if (!erji) {
  105. evaluatingData.earphoneMode = true;
  106. }
  107. evaluatingData.checkEnd = true;
  108. console.log("检测结束,生成数据");
  109. handleConnect();
  110. }
  111. };
  112. const browserInfo = browser();
  113. /** 是否是节奏练习 */
  114. const isRhythmicExercises = () => {
  115. const examSongName = state.examSongName || "";
  116. return examSongName.indexOf("节奏练习") > -1;
  117. };
  118. /** 获取评测标准 */
  119. const getEvaluationCriteria = () => {
  120. let criteria: TCriteria = "frequency";
  121. // 声部打击乐
  122. if ([23, 113, 121].includes(state.subjectId)) {
  123. criteria = "amplitude";
  124. } else if (isRhythmicExercises()) {
  125. // 分类为节奏练习
  126. criteria = "decibels";
  127. }
  128. return criteria;
  129. };
  130. /** 校验耳机状态 */
  131. const checkEarphoneStatus = async (type?: string) => {
  132. clearTimeout(checkErjiTimer);
  133. checkErjiTimer = null;
  134. if (type !== "start") {
  135. // const erji = await checkUseEarphone();
  136. const res = await getEarphone();
  137. const erji = res?.content?.checkIsWired || false;
  138. // 是否已经提示过耳机弹窗,重新进入评测页面,重置该状态为false,手动关掉耳机弹窗,改变该状态为true,本次评测都不在提示耳机状态弹窗
  139. if (!evaluatingData.onceErjiPopShow) {
  140. evaluatingData.earphoneMode = true;
  141. } else {
  142. clearTimeout(checkErjiTimer);
  143. checkErjiTimer = null;
  144. return;
  145. }
  146. evaluatingData.earPhoneType = res?.content?.type || "";
  147. if (evaluatingData.earPhoneType === "有线耳机") {
  148. clearTimeout(checkErjiTimer);
  149. checkErjiTimer = null;
  150. setTimeout(() => {
  151. evaluatingData.earphoneMode = false;
  152. }, 1500);
  153. } else {
  154. // 如果没有佩戴有限耳机,需要持续检测耳机状态
  155. checkErjiTimer = setTimeout(() => {
  156. checkEarphoneStatus();
  157. }, 1000);
  158. }
  159. }
  160. console.log("检测结束,生成数据", evaluatingData.websocketState, evaluatingData.startBegin, evaluatingData.checkEnd);
  161. handleConnect();
  162. };
  163. /** 生成评测曲谱数据 */
  164. const formatTimes = () => {
  165. console.log('评测111')
  166. let starTime = 0;
  167. let ListenMode = false;
  168. let dontEvaluatingMode = false;
  169. let skip = false;
  170. const datas = [];
  171. let selectTimes = state.times;
  172. let unitTestIdx = 0;
  173. let preTime = 0;
  174. let preTimes = [];
  175. // 系统节拍器时长
  176. actualBeatLength = Math.round((state.times[0].fixtime * 1000) / 1);
  177. // 如果是阶段评测,选取该阶段的times
  178. if (state.isSelectMeasureMode && state.section.length) {
  179. const startIndex = state.times.findIndex((n: any) => n.noteId == state.section[0].noteId);
  180. let endIndex = state.times.findIndex((n: any) => n.noteId == state.section[1].noteId);
  181. endIndex = endIndex < state.section[1].i ? state.section[1].i : endIndex;
  182. if (startIndex > 1) {
  183. // firstNoteTime应该取预备小节的第一个音符的开始播放的时间
  184. const idx = startIndex - 1 - state.times[startIndex - 1].si;
  185. preTime = state.times[idx] ? state.times[idx].time * 1000 : 0;
  186. }
  187. actualBeatLength = startIndex == 0 && state.isOpenMetronome ? actualBeatLength : 0;
  188. // 妙极客的曲子,选择的第一小节,beatLength需要传递fixtime
  189. if (state.isEvxml && startIndex == 0) {
  190. actualBeatLength = Math.round((state.times[0].fixtime * 1000) / 1);
  191. }
  192. selectTimes = state.times.filter((n: any, index: number) => {
  193. return index >= startIndex && index <= endIndex;
  194. });
  195. preTimes = state.times.filter((n: any, index: number) => {
  196. return index < startIndex;
  197. });
  198. unitTestIdx = startIndex;
  199. starTime = selectTimes[0].sourceRelativeTime || selectTimes[0].relativeTime;
  200. }
  201. // 阶段评测beatLength需要加上预备小节的持续时长
  202. actualBeatLength = preTimes.length ? actualBeatLength + preTimes[preTimes.length - 1].relaMeasureLength * 1000 : actualBeatLength;
  203. // 如果是弱起,并且预备小节是第一节
  204. if (state.section.length && state.sectionFirst && state.sectionFirst.measureListIndex == 0 && !state.isEvxml) {
  205. actualBeatLength = actualBeatLength < Math.round((state.times[0].fixtime * 1000) / 1) ? Math.round((state.times[0].fixtime * 1000) / 1) : actualBeatLength;
  206. }
  207. let firstNoteTime = unitTestIdx > 1 ? preTime : 0;
  208. let measureIndex = -1;
  209. let recordMeasure = -1;
  210. // 如果有mp3节拍器,并且预备小节是第一节,并且从0开始播放,actualBeatLength需要加上mp3节拍器时间
  211. if (state.section.length === 2 && firstNoteTime === 0 && state.section[0]?.MeasureNumberXML === state.firstMeasureNumber + 1 && state.times[0].fixtime) {
  212. actualBeatLength = actualBeatLength + Math.round((state.times[0].fixtime * 1000) / 1)
  213. }
  214. for (let index = 0; index < selectTimes.length; index++) {
  215. const item = selectTimes[index];
  216. const note = getNoteByMeasuresSlursStart(item);
  217. // #8701 bug: 评测模式,是以曲谱本身的速度进行评测,所以rate取1,不需要转换
  218. // const rate = state.speed / state.originSpeed;
  219. const rate = state.basePlayRate * state.originAudioPlayRate; // 播放倍率
  220. // const difftime = item.difftime;
  221. const difftime = 0;
  222. const start = difftime + (item.sourceRelativeTime || item.relativeTime) - starTime;
  223. const end = difftime + (item.sourceRelaEndtime || item.relaEndtime) - starTime;
  224. const isStaccato = note.noteElement.voiceEntry.isStaccato();
  225. const noteRate = isStaccato ? 0.5 : 1;
  226. if (note.formatLyricsEntries.contains("Play") || note.formatLyricsEntries.contains("Play...")) {
  227. ListenMode = false;
  228. }
  229. if (note.formatLyricsEntries.contains("Listen")) {
  230. ListenMode = true;
  231. }
  232. if (note.formatLyricsEntries.contains("纯律结束")) {
  233. dontEvaluatingMode = false;
  234. }
  235. if (note.formatLyricsEntries.contains("纯律")) {
  236. dontEvaluatingMode = true;
  237. }
  238. const nextNote = selectTimes[index + 1];
  239. // console.log("noteinfo", note.noteElement.isRestFlag && !!note.stave && !!nextNote)
  240. if (skip && (note.stave || !item.noteElement.isRestFlag || (nextNote && !nextNote.noteElement.isRestFlag))) {
  241. skip = false;
  242. }
  243. if (note.noteElement.isRestFlag && !!note.stave && !!nextNote && nextNote.noteElement.isRestFlag) {
  244. skip = true;
  245. }
  246. // console.log(note.measureOpenIndex, item.measureOpenIndex, note);
  247. // console.log("skip", skip)
  248. // console.log(end,start,rate,noteRate, '评测')
  249. if (note.measureOpenIndex != recordMeasure) {
  250. measureIndex++;
  251. recordMeasure = note.measureOpenIndex;
  252. }
  253. // 是否是需要延续、不停顿演奏的音符
  254. let isTenutoSound = false;
  255. if (item?.noteElement?.tie && item.noteElement.tie?.StartNote) {
  256. const startId = item.noteElement.tie?.StartNote?.NoteToGraphicalNoteObjectId
  257. isTenutoSound = item.NoteToGraphicalNoteObjectId === startId ? false : true
  258. }
  259. // 音符是否不需要评测
  260. let noteNeedEvaluat = item.hasGraceNote || ListenMode || dontEvaluatingMode || !!item?.voiceEntry?.ornamentContainer || !!item.noteElement?.speedInfo?.startWord?.includes('rit.') || item.skipMode
  261. noteNeedEvaluat = noteNeedEvaluat == true ? true : false;
  262. const data = {
  263. timeStamp: (start * 1000) / rate,
  264. duration: ((end * 1000) / rate - (start * 1000) / rate) * noteRate,
  265. frequency: item.frequency,
  266. nextFrequency: item.nextFrequency,
  267. prevFrequency: item.prevFrequency,
  268. // 重复的情况index会自然累加,render的index是谱面渲染的index
  269. measureIndex: measureIndex,
  270. measureRenderIndex: item.measureListIndex,
  271. // item.MeasureNumberXML >= 1 ? item.MeasureNumberXML - 1 : note.noteElement.sourceMeasure.measureListIndex,
  272. dontEvaluating: noteNeedEvaluat,
  273. musicalNotesIndex: index,
  274. denominator: note.noteElement?.Length.denominator,
  275. // isOrnament: !!note?.voiceEntry?.ornamentContainer,
  276. isTenutoSound,
  277. isStaccato: item?.voiceEntry?.isStaccato ? true : false, // 是否是重音
  278. frequencyList: item.frequencyList, // 如果是和弦音符,需要添加多个音符的频率,用于评测
  279. };
  280. datas.push(data);
  281. }
  282. return {
  283. datas,
  284. firstNoteTime,
  285. };
  286. };
  287. /** 连接websocket */
  288. const handleConnect = async () => {
  289. const behaviorId = localStorage.getItem("behaviorId") || localStorage.getItem("BEHAVIORID") || undefined;
  290. // let rate = state.speed / state.originSpeed;
  291. const rate = state.basePlayRate * state.originAudioPlayRate; // 播放倍率
  292. // rate = parseFloat(rate.toFixed(2));
  293. console.log("速度比例", rate, "速度", state.speed);
  294. calculateInfo = formatTimes();
  295. // 评测的速度,如果是选段,则选选段开头小节的速度
  296. const evaluatSpeed = state.sectionStatus && state.section.length === 2 && state.section[0].measureSpeed ? state.section[0].measureSpeed * state.basePlayRate : state.speed;
  297. evaluatingData.evaluatSpeed = evaluatSpeed;
  298. const content = {
  299. musicXmlInfos: calculateInfo.datas,
  300. subjectId: state.musicalCode,
  301. detailId: state.detailId,
  302. examSongId: state.examSongId,
  303. xmlUrl: state.xmlUrl,
  304. partIndex: state.partIndex,
  305. behaviorId,
  306. platform: browserInfo.ios ? "IOS" : browserInfo.android ? "ANDROID" : "WEB",
  307. clientId: storeData.platformType === "STUDENT" ? "student" : storeData.platformType === "TEACHER" ? "teacher" : "education",
  308. hertz: state.setting.frequency,
  309. reactionTimeMs: state.setting.reactionTimeMs ? Number(state.setting.reactionTimeMs) : 0,
  310. speed: evaluatSpeed,
  311. heardLevel: state.setting.evaluationDifficulty,
  312. // beatLength: Math.round((state.fixtime * 1000) / rate),
  313. beatLength: actualBeatLength / rate,
  314. evaluationCriteria: state.evaluationStandard,
  315. speedRate: parseFloat(rate.toFixed(2)), // 播放倍率
  316. };
  317. await connectWebsocket(content);
  318. // state.playSource = "music";
  319. };
  320. /** 评测结果按钮处理 */
  321. const handleEvaluatResult = (type: "practise" | "tryagain" | "look" | "share" | "update" | "selfCancel" | "submitWork") => {
  322. if (type === "update") {
  323. if (state.isAppPlay) {
  324. evaluatModel.evaluatUpdateAudio = true;
  325. resetPlaybackToStart();
  326. return;
  327. } else if (evaluatingData.resultData?.recordIdStr || evaluatingData.resultData?.recordId) {
  328. const rate = state.basePlayRate * state.originAudioPlayRate; // 播放倍率
  329. // 上传云端
  330. // evaluatModel.evaluatUpdateAudio = true;
  331. api_openAdjustRecording({
  332. recordId: evaluatingData.resultData?.recordIdStr || evaluatingData.resultData?.recordId,
  333. title: state.examSongName || "曲谱演奏",
  334. coverImg: state.coverImg,
  335. speedRate: parseFloat(rate.toFixed(2)), // 播放倍率
  336. musicRenderType: state.musicRenderType,
  337. musicSheetId: state.examSongId,
  338. 'part-index': state.partIndex
  339. });
  340. return;
  341. }
  342. } else if (type === "share") {
  343. // 分享
  344. evaluatModel.shareMode = true;
  345. return;
  346. } else if (type === "look") {
  347. // 跳转
  348. handleViewReport("recordId", "instrument");
  349. return;
  350. } else if (type === "practise") {
  351. // 去练习
  352. handleStartEvaluat();
  353. } else if (type === "tryagain") {
  354. startBtnHandle();
  355. } else if (type === "selfCancel") {
  356. // 再来一次,需要手动取消评测,不生成评测记录,不显示评测结果弹窗
  357. evaluatingData.oneselfCancleEvaluating = true;
  358. // handleCancelEvaluat();
  359. handleEndEvaluat(false, 'selfCancel');
  360. // evaluatingData.isBeginMask = true;
  361. evaluatingData.evaluatings = {};
  362. state.playState = "paused";
  363. } else if (type === "submitWork") {
  364. // 作业模式,提交作业,作业没有达标时,提交作业需要弹窗提醒
  365. if (!state.isWorkDone) {
  366. evaluatModel.showNoDonePop = true;
  367. return;
  368. } else {
  369. submitWorkHome();
  370. }
  371. }
  372. resetPlaybackToStart();
  373. evaluatingData.resulstMode = false;
  374. };
  375. // 关闭提交作业确认弹窗
  376. const handleCloseSubmitPop = (type: "again" | "confirm") => {
  377. evaluatModel.showNoDonePop = false;
  378. if (type === "again") {
  379. handleEvaluatResult("tryagain");
  380. } else {
  381. submitWorkHome();
  382. resetPlaybackToStart();
  383. evaluatingData.resulstMode = false;
  384. }
  385. }
  386. // 提交作业
  387. const submitWorkHome = async () => {
  388. // 分为开了摄像头和没开摄像头的情况
  389. if (state.setting.camera) {
  390. const res = await api_workUpdate();
  391. console.log('提交作业回调',res)
  392. if (res) {
  393. if (res?.content?.type === "success") {
  394. handleSaveResult({
  395. id: evaluatingData.resultData?.recordId,
  396. videoFilePath: res?.content?.filePath,
  397. });
  398. // 手动提交评测作业
  399. selfSubmitWorkHome();
  400. } else if (res?.content?.type === "error") {
  401. showToast({
  402. message: res.content?.message || "上传失败",
  403. });
  404. }
  405. }
  406. } else {
  407. // 手动提交评测作业
  408. selfSubmitWorkHome();
  409. }
  410. }
  411. /** 上传音视频 */
  412. const hanldeUpdateVideoAndAudio = async (update = false) => {
  413. if (!update) {
  414. evaluatModel.evaluatUpdateAudio = false;
  415. return;
  416. }
  417. if (state.setting.camera && state.setting.saveToAlbum) {
  418. evaluatModel.evaluatUpdateAudio = false;
  419. api_videoUpdate((res: any) => {
  420. if (res) {
  421. if (res?.content?.type === "success") {
  422. handleSaveResult({
  423. id: evaluatingData.resultData?.recordId,
  424. videoFilePath: res?.content?.filePath,
  425. });
  426. } else if (res?.content?.type === "error") {
  427. showToast({
  428. message: res.content?.message || "上传失败",
  429. });
  430. }
  431. }
  432. });
  433. return;
  434. }
  435. evaluatModel.evaluatUpdateAudio = false;
  436. showToast("上传成功");
  437. };
  438. const handleSaveResult = async (_body: any) => {
  439. await api_musicPracticeRecordVideoUpload(_body);
  440. showToast("上传成功");
  441. };
  442. const startBtnHandle = async () => {
  443. // 如果打开了延迟检测开关,需要先发送开始检测的消息
  444. const delayData = await api_getDeviceDelay();
  445. console.log('设备的延迟值',delayData.content?.value)
  446. if (delayData && delayData.content?.value <= 0) {
  447. await api_startDelayCheck({});
  448. return;
  449. }
  450. evaluatingData.needReplayEvaluat = false;
  451. // 选段未完成时,清除选段状态
  452. if (state.sectionStatus && state.section.length < 2) {
  453. clearSelection();
  454. }
  455. // 如果是异常状态,先等待500ms再执行后续流程
  456. if (evaluatingData.isErrorState && !state.setting.soundEffect) {
  457. // console.log('异常流程1')
  458. // showLoadingToast({
  459. // message: "处理中",
  460. // duration: 1000,
  461. // overlay: true,
  462. // overlayClass: styles.scoreMode,
  463. // });
  464. state.loadingText = "处理中…";
  465. state.isLoading = true;
  466. await new Promise<void>((resolve) => {
  467. setTimeout(() => {
  468. // closeToast();
  469. state.isLoading = false;
  470. evaluatingData.isErrorState = false;
  471. // console.log('异常流程2')
  472. resolve();
  473. }, 1000);
  474. });
  475. }
  476. // console.log('异常流程3')
  477. // 非选段状态,从头开始评测,重置速度
  478. if (!state.sectionStatus && state.section.length === 0) {
  479. state.activeNoteIndex = 0;
  480. state.speed = state.times[0].measureSpeed * state.basePlayRate
  481. }
  482. initSetPlayRate();
  483. // 检测APP端socket状态
  484. const res: any = await startCheckDelay();
  485. if (res?.checked) {
  486. handleConnect();
  487. handleStartBegin(calculateInfo.firstNoteTime);
  488. evaluatingData.resulstMode = false;
  489. if (evaluatingData.isErrorState) {
  490. evaluatingData.isErrorState = false;
  491. // evaluatingData.resulstMode = false;
  492. }
  493. }
  494. };
  495. // 监听到APP取消延迟检测
  496. const handleCancelDelayCheck = async (res?: IPostMessage) => {
  497. console.log("监听取消延迟检测", res);
  498. if (res?.content) {
  499. // 关闭延迟检测页面,并返回到模式选择页面
  500. // await api_closeDelayCheck({});
  501. handleDelayBack();
  502. }
  503. };
  504. // 监听APP延迟成功的回调
  505. const handleFinishDelayCheck = async (res?: IPostMessage) => {
  506. console.log("监听延迟检测成功", res);
  507. evaluatingData.socketErrorPop = false;
  508. if (res?.content) {
  509. evaluatingData.checkEnd = true;
  510. state.setting.soundEffect = false;
  511. evaluatingData.tipErjiShow = true;
  512. }
  513. };
  514. // 监听重复评测消息
  515. const handRetryEvaluating = () => {
  516. handleEvaluatResult("tryagain");
  517. };
  518. const earPhonePopShow = computed(() => {
  519. return evaluatingData.earphoneMode && !state.isLoading && !state.hasDriverPop && !evaluatingData.showOpenCameraPop;
  520. });
  521. const tipErjiPopShow = computed(() => {
  522. return evaluatingData.tipErjiShow && !state.isLoading && !state.hasDriverPop && !evaluatingData.showOpenCameraPop;
  523. });
  524. // watch(
  525. // () => state.setting.soundEffect,
  526. // (val) => {
  527. // if (val) {
  528. // headTopData.settingMode = false
  529. // api_startDelayCheck({});
  530. // state.setting.soundEffect = false
  531. // }
  532. // }
  533. // );
  534. // 手动取消评测,需要自动再次评测
  535. // watch(
  536. // () => evaluatingData.needReplayEvaluat,
  537. // (val) => {
  538. // if (val && evaluatingData.oneselfCancleEvaluating) {
  539. // setTimeout(() => {
  540. // startBtnHandle();
  541. // }, 500);
  542. // }
  543. // }
  544. // );
  545. onMounted(async () => {
  546. // 如果打开了延迟检测开关,需要先发送开始检测的消息
  547. const delayData = await api_getDeviceDelay();
  548. console.log('设备的延迟值',delayData.content?.value)
  549. if (delayData && delayData.content?.value <= 0) {
  550. await api_startDelayCheck({});
  551. } else {
  552. evaluatingData.checkEnd = true;
  553. // 点击评测模式进入评测模块的需要检测耳机状态,通过返回按钮进入评测模块的,不检测耳机状态
  554. if (evaluatingData.needCheckErjiStatus) {
  555. checkEarphoneStatus();
  556. }
  557. }
  558. evaluatingData.isDisabledPlayMusic = true;
  559. // handlePerformDetection();
  560. api_cancelDelayCheck(handleCancelDelayCheck);
  561. api_finishDelayCheck(handleFinishDelayCheck);
  562. api_retryEvaluating(handRetryEvaluating);
  563. });
  564. onUnmounted(() => {
  565. api_remove_finishDelayCheck(handleFinishDelayCheck);
  566. api_remove_cancelDelayCheck(handleCancelDelayCheck);
  567. clearTimeout(checkErjiTimer);
  568. checkErjiTimer = null;
  569. });
  570. // 资源类型
  571. const isPad = navigator?.userAgent?.includes("UAWEIVRD-W09") || browserInfo?.iPad || browserInfo.isTablet;
  572. return () => (
  573. <div>
  574. <div class={styles.operatingBtn}>
  575. {!evaluatingData.startBegin && (
  576. <img
  577. class={[styles.iconBtn, "evaluting-1"]}
  578. src={headImg("icon_play.png")}
  579. onClick={() => {
  580. startBtnHandle();
  581. }}
  582. />
  583. )}
  584. {evaluatingData.startBegin && (
  585. <>
  586. <img class={styles.iconBtn} src={headImg("icon_reset.png")} onClick={() => {
  587. // 校验评测最小间隔时间
  588. const currentTime = +new Date();
  589. // 开始评测和结束评测的间隔时间小于800毫秒,则不处理
  590. if (currentTime - evaluatingData.recordingTime < 800) {
  591. return;
  592. }
  593. handleEvaluatResult("selfCancel")
  594. }} />
  595. <img class={styles.iconBtn} src={headImg("submit.png")} onClick={() => {
  596. // 校验评测最小间隔时间
  597. const currentTime = +new Date();
  598. // 开始评测和结束评测的间隔时间小于800毫秒,则不处理
  599. if (currentTime - evaluatingData.recordingTime < 800) {
  600. return;
  601. }
  602. handleEndBegin()
  603. }} />
  604. </>
  605. )}
  606. </div>
  607. {/* {evaluatingData.soundEffectMode && (
  608. <DelayCheck
  609. onClose={() => {
  610. evaluatingData.soundEffectMode = false;
  611. handlePerformDetection();
  612. }}
  613. onBack={() => handleDelayBack()}
  614. />
  615. )} */}
  616. {/* 倒计时 */}
  617. <Countdown />
  618. {/* 遮罩 */}
  619. {
  620. evaluatingData.isBeginMask && <div class={styles.beginMask}></div>
  621. }
  622. <Popup teleport="body" closeOnClickOverlay={false} class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={tipErjiPopShow.value}>
  623. <div class={[styles.earphoneBox, isPad && styles.ipadEarphoneBox]}>
  624. <img class={styles.earphoneBg} src={tipErjiBg} />
  625. <img class={styles.earphoneBtn} src={tipErjiBtn} onClick={() => {
  626. evaluatingData.tipErjiShow = false;
  627. checkEarphoneStatus();
  628. }} />
  629. </div>
  630. </Popup>
  631. <Popup teleport="body" closeOnClickOverlay={false} class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={earPhonePopShow.value}>
  632. <Earphone
  633. earphoneType={evaluatingData.earPhoneType}
  634. onClose={() => {
  635. evaluatingData.onceErjiPopShow = true;
  636. clearTimeout(checkErjiTimer);
  637. checkErjiTimer = null;
  638. // #11035,可能刚好关闭耳机弹窗的时候,第二次又出现了弹窗
  639. setTimeout(() => {
  640. evaluatingData.earphoneMode = false;
  641. }, 300);
  642. // handlePerformDetection();
  643. checkEarphoneStatus("start");
  644. }}
  645. />
  646. </Popup>
  647. {/* 评测作业,非完整评测不显示评测结果弹窗 */}
  648. {evaluatingData.hideResultModal ? (
  649. <EvaluatResult onClose={handleEvaluatResult} />
  650. ) : (
  651. <Popup teleport="body" closeOnClickOverlay={false} class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={evaluatingData.resulstMode}>
  652. <EvaluatResult onClose={handleEvaluatResult} />
  653. </Popup>
  654. )}
  655. <Popup teleport="body" closeOnClickOverlay={false} class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={evaluatModel.evaluatUpdateAudio}>
  656. <EvaluatAudio onClose={hanldeUpdateVideoAndAudio} />
  657. </Popup>
  658. <Popup teleport="body" class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={evaluatModel.shareMode}>
  659. <EvaluatShare onClose={() => (evaluatModel.shareMode = false)} />
  660. </Popup>
  661. <Popup teleport="body" class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={evaluatModel.showNoDonePop}>
  662. <SubmitNoDonePop onClose={handleCloseSubmitPop} />
  663. </Popup>
  664. </div>
  665. );
  666. },
  667. });