test.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. <template>
  2. <div class="test">
  3. <Header @confirmExit="confirmExit"></Header>
  4. <div class="main">
  5. <div class="main-left">
  6. <div class="main-left-top">
  7. <div class="top-left" @click="getChooseStudent">
  8. <div class="top-left-center">
  9. <div class="pic" :class="{ 'pic2': faceCheckStu.student_id }" v-if="faceCheckStu.student_id"> <img
  10. :src="faceCheckStu.face_pic || faceCheckStu.logo_url" /></div>
  11. <div class="pic" v-else>
  12. <img src="@/assets/images/test/profilePicture.png" />
  13. </div>
  14. <div class="name" :class="{ 'name2': faceCheckStu.student_id }">
  15. {{ faceCheckStu.student_id ? faceCheckStu.name : "虚位以待" }}
  16. </div>
  17. </div>
  18. </div>
  19. <div class="top-right">
  20. <Transition :enter-active-class="proxy?.animate.dialog.enter"
  21. :leave-active-class="proxy?.animate.dialog.leave">
  22. <div class="time" v-show="needStart && [42].includes(examState)">{{
  23. time.countdownNum
  24. }}</div>
  25. </Transition>
  26. <div class="tips" v-if="examState == 41">
  27. <img v-if="parameter.gesture" src="@/assets/images/test/ready1.png" />
  28. <img v-if="!parameter.gesture" src="@/assets/images/test/ready2.png" />
  29. </div>
  30. <div class="complete" :class="{ 'complete2': needStart && [42].includes(examState) }"
  31. v-if="faceCheckStu.student_id && time.ready <= 0 && examState != 43 && examState != 41">
  32. <div class="scoreBox" v-if="['basketballv1'].includes(parameter.project)">
  33. <div class="score">{{ currentResultObj.count || 0 }}</div>
  34. </div>
  35. <div class="scoreBox" v-else>
  36. <div class="score">{{ currentResultObj.count || 0 }}</div>
  37. <div class="unit" v-if="currentResultObj.count && !needStart">{{ unit }}</div>
  38. </div>
  39. <div class="fractionViolation">
  40. <div class="fraction">
  41. <div class="lable">得分:</div>
  42. <div class="value">{{ currentResultObj.score || "" }}</div>
  43. </div>
  44. <div class="violation">
  45. <div class="lable">{{ ['jumprope'].includes(parameter.project) ? '中断' : '犯规' }}</div>
  46. <div class="value">{{ currentResultObj.back_num || 0 }}</div>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="foulBox" v-if="examState == 42 && backReason.length">
  51. <Transition :enter-active-class="proxy?.animate.mask.enter"
  52. :leave-active-class="proxy?.animate.mask.leave">
  53. <div class="foul" v-show="backReasonStr ? true : false">
  54. <div class="lable">!</div>
  55. <div class="value">{{ backReasonStr }}</div>
  56. </div>
  57. </Transition>
  58. </div>
  59. <div v-show="examState == 43 && time.ready">
  60. <div class="readyBox">
  61. <div class="value" :class="{ 'transparent': time.ready > 5 }">{{ time.ready }}</div>
  62. <div class="lable">倒计时</div>
  63. </div>
  64. </div>
  65. <div v-show="examState == 43 && !time.ready && readyState">
  66. <div class="readyBoxBefore">
  67. <div class="item" v-if="parameter.handcontroller">
  68. <div><img src="@/assets/images/test/jushou.png" /></div>
  69. <div class="lable">
  70. <div>请举左手开始</div>
  71. </div>
  72. </div>
  73. <div class="item" v-else>
  74. <div> <img src="@/assets/images/test/bujushou.png" /></div>
  75. <div class="lable">
  76. <div>请点击开始</div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="btn" @click="getReady" v-if="needStart && examState == 43 && !time.ready && readyState">开 始
  82. </div>
  83. <!-- <div v-if="needStart"> -->
  84. <!-- <div class="btn" @click="getOpenOneTestAndStartFace" v-if="examState < 41">开始识别</div> -->
  85. <!-- <div class="btn" @click="getStopFace" v-if="examState == 41 && !parameter.gesture">停止人脸识别</div> -->
  86. <!-- <div class="btn" @click="getStartOneTest" v-if="examState == 43">开始测试</div> -->
  87. <!-- <div @click="getRetestFace" v-if="examState == 43 || examState == 42">重新识别</div> -->
  88. <!-- </div> -->
  89. <!-- <div>当前状态:({{ examState == 3 ? "初始化完成" : examState == 40 ? "创建测试" : examState == 41 ? "正在人脸识别":examState == 43 ? "停止人脸识别" : examState == 42 ? "正在测试" : "请初始化" }})</div> -->
  90. <!-- <div @click="getAgain" v-if="examState == 42 || showTestAgain">再测一次</div> -->
  91. </div>
  92. <i></i>
  93. </div>
  94. <div class="main-left-bottom">
  95. <div class="bottom-left">
  96. <div class="tips"><img src="/src/assets/images/test/tips.png" /></div>
  97. <div class="pic"><img :src="'static/images/tips/' + parameter.project + '.png'" /></div>
  98. </div>
  99. <div class="bottom-right" v-html="dic.projectNote[parameter.project]">
  100. </div>
  101. </div>
  102. </div>
  103. <div class="main-right">
  104. <ReportList ref="reportListRef" :parameter="parameter" :showQRCode="true" />
  105. </div>
  106. </div>
  107. <FaceWindow ref="faceWindowRef" :faceCheckStu="faceCheckStu" :gesture="parameter.gesture" />
  108. <ChooseStudent ref="chooseStudentRef" @returnData="returnStudent" />
  109. </div>
  110. </template>
  111. <script setup name="TrainTest" lang="ts">
  112. // import { useWs } from '@/utils/trainWs';
  113. import { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
  114. import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech'
  115. import { useWebSocket } from '@/utils/handWs';
  116. import dayjs from 'dayjs'
  117. import dataDictionary from "@/utils/dataDictionary"
  118. const { handWs } = useWebSocket();
  119. // const { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } = useWs();
  120. const { proxy } = getCurrentInstance() as any;
  121. const router = useRouter();
  122. const route = useRoute();
  123. const faceWindowRef = ref();
  124. const chooseStudentRef = ref();
  125. const reportListRef = ref();
  126. const myInfo: any = localStorage.getItem("userInfo");
  127. const dic: any = dataDictionary;
  128. const data = reactive<any>({
  129. timerManager: {},//计时器管理
  130. parameter: {},//参数
  131. time: {
  132. testTime: 60,//时长
  133. countdownNum: 0,//计时
  134. ready: 0,//预备
  135. exit: 0,//退出倒计时
  136. },
  137. userInfo: {},//用户信息
  138. examState: 0,//当前状态
  139. resultId: null,//测试ID
  140. currentResultObj: {},//成绩
  141. faceCheckStu: {},//人脸信息
  142. unit: "",//单位
  143. backReason: [],//犯规项
  144. backReasonStr: "",//犯规提示
  145. needStart: false,//是否需要按钮
  146. showTestAgain: false,//再测一次按钮
  147. readyState: true,//倒计时按钮状态
  148. exit: 0,//退出响应次数
  149. sid: null,//WS的id
  150. });
  151. const { timerManager, parameter, time, userInfo, examState, resultId, faceCheckStu, currentResultObj, unit, backReason, backReasonStr, needStart, showTestAgain, readyState, exit, sid } = toRefs(data);
  152. /**
  153. * 接收消息
  154. */
  155. const getMessage = (e: any) => {
  156. //console.log("WS响应:", e)
  157. //获取sid
  158. if (e.cmd === 'mySid') {
  159. console.log("e.data.sid", e.data.sid)
  160. sid.value = e.data.sid;
  161. }
  162. //实时状态
  163. if (e.cmd === 'exam_status') {
  164. examState.value = e.data;
  165. }
  166. //工作站状态
  167. if (e.cmd === 'init_result') {
  168. }
  169. //测试违规
  170. if (e.cmd === 'warning_result') {
  171. console.log("eeeeeeeeeee", e)
  172. if ((e.status + "")[0] === "2") {
  173. proxy?.$modal.msgError(e.data.message);
  174. speckText(e.data.message);
  175. }
  176. }
  177. //后端播报语音
  178. if (e.cmd === 'return_audio_msg') {
  179. if (e.data.message) {
  180. proxy?.$modal.msgError(e.data.message);
  181. speckText(e.data.message);
  182. }
  183. }
  184. //错误提示
  185. if (e.cmd === 'info_result') {
  186. proxy?.$modal.msgError(e.data.message);
  187. }
  188. //错误提示
  189. if (e.cmd === 'error_result') {
  190. proxy?.$modal.msgError(e.data.message);
  191. }
  192. //测试中违规提示
  193. if (e.cmd === 'warning_notify') {
  194. let message = e.data.message;
  195. if (message) {
  196. proxy?.$modal.msgError(message);
  197. speckText(message);
  198. }
  199. if (message == "工作站已断开!") {
  200. getExit();
  201. }
  202. }
  203. //断线状态
  204. if (e.cmd === 'disconnect_request') {
  205. let message = e.data.message;
  206. if (message) {
  207. proxy?.$modal.msgError(`${message}`);
  208. speckText(message);
  209. }
  210. getExit();
  211. }
  212. //状态变更
  213. if (e.cmd === 'set_exam_state') {
  214. examState.value = e.data;
  215. if (e.data === 3) {
  216. initProject();
  217. }
  218. if (e.data === 40) {
  219. cleanData();
  220. }
  221. if (e.data == 41) {
  222. getFaceWindow(true);
  223. }
  224. if (e.data == 43) {
  225. }
  226. if (e.data == 42) {
  227. getClearTimer("readyTimer");
  228. time.value.ready = 0;
  229. }
  230. }
  231. //新建测试后返回信息,获取result_id
  232. if (e.cmd === 'open_one_test_ack') {
  233. resultId.value = e.data.result_id;
  234. }
  235. //人脸识别状态
  236. if (e.cmd === 'face_check_result') {
  237. let myData = e.data[0] || e.data;
  238. returnStudent(myData);
  239. }
  240. //测试结束结果
  241. if (e.cmd === 'oneresult') {
  242. if (e.data.length) {
  243. let data = e.data[0];
  244. getAchievement(data)
  245. }
  246. }
  247. //结果生成完成(视频图片)
  248. if (e.cmd === 'static_urls_finished') {
  249. }
  250. //选择学生或测试结束后返回的数据
  251. if (e.cmd === 'result_info') {
  252. }
  253. };
  254. /**
  255. * 开始识别
  256. */
  257. const getOpenOneTestAndStartFace = async () => {
  258. if (examState.value > 3) {
  259. await closeOneTest();
  260. }
  261. await openOneTest();
  262. await startFace();
  263. };
  264. /**
  265. * 停止人脸识别
  266. */
  267. const getStopFace = async () => {
  268. // 旧版识别成功直接43了这里先屏蔽
  269. // if (examState.value != 41) {
  270. // return false;
  271. // }
  272. getClearTimer("face");
  273. if (needStart.value) {
  274. let txt = parameter.value.handcontroller === true ? ",请举左手开始测试" : ",请准备";
  275. speckText(faceCheckStu.value.name + txt);
  276. }
  277. if (examState.value == 41) {
  278. await stopFace();
  279. }
  280. if (faceCheckStu.value.student_id) {
  281. getFaceConfirmOnly();
  282. }
  283. };
  284. /**
  285. * 确定人脸信息
  286. */
  287. const getFaceConfirmOnly = (data?: any) => {
  288. if (data) {
  289. faceCheckStu.value = data;
  290. }
  291. faceConfirmOnly({
  292. result_id: resultId.value,
  293. student_id: faceCheckStu.value.student_id,
  294. gender: faceCheckStu.value.gender
  295. }, () => {
  296. faceWindowRef.value?.close();
  297. //不需要按钮的自动进入下一步
  298. if (needStart.value == false) {
  299. getStartOneTest();
  300. }
  301. });
  302. };
  303. /**
  304. * 重新识别
  305. */
  306. const getRetestFace = () => {
  307. proxy?.$modal.confirm("确定重新识别吗?").then(() => {
  308. if (needStart.value == false) {
  309. //自动流程项目重新识别直接返回3
  310. closeOneTest();
  311. } else {
  312. //手动流程项目重新识别43返回41,42返回3
  313. if (examState.value == 43) {
  314. cleanData();
  315. startFace();
  316. } else {
  317. closeOneTest();
  318. }
  319. }
  320. }).finally(() => {
  321. });
  322. };
  323. /**
  324. * 开始测试
  325. */
  326. const getStartOneTest = () => {
  327. if (examState.value != 43 || !faceCheckStu.value.student_id) {
  328. return false;
  329. }
  330. if (!faceCheckStu.value.student_id) {
  331. proxy?.$modal.msgWarning("请选择人员!");
  332. return false;
  333. }
  334. startOneTest(data == null, () => {
  335. //显示再测一次按钮
  336. showTestAgain.value = true;
  337. //停止播报;
  338. speckCancel();
  339. //计时项目才开
  340. if (needStart.value == true) {
  341. speckText("哨声");
  342. if (parameter.value.music) {
  343. playMusic(parameter.value.music);
  344. }
  345. //时间为0的为正计时,大于0的为倒计时
  346. if (time.value.testTime == 0) {
  347. getCounting("+");
  348. } else {
  349. getCounting("-");
  350. }
  351. } else {
  352. speckText(faceCheckStu.value.name + ",请开始测试");
  353. }
  354. })
  355. };
  356. /**
  357. * 再测一次
  358. */
  359. const getAgain = async () => {
  360. //预存测试人员
  361. let student = JSON.parse(JSON.stringify(faceCheckStu.value));
  362. //测试中
  363. if (examState.value == 42) {
  364. await finishOneTest();
  365. }
  366. //其他状态
  367. if (examState.value > 3) {
  368. await closeOneTest();
  369. }
  370. //重新走一次流程
  371. await openOneTest();
  372. await startFace();
  373. await stopFace();
  374. getFaceConfirmOnly(student);
  375. };
  376. /**
  377. * 确认退出
  378. */
  379. const confirmExit = () => {
  380. let handcontroller_id = parameter.value.handcontroller;
  381. proxy?.$modal.confirm(handcontroller_id ? `请举左手确认退出` : `确定退出吗?`).then(() => {
  382. getExit();
  383. }).finally(() => {
  384. });
  385. };
  386. /**
  387. * 退出
  388. */
  389. const getExit = () => {
  390. getClearTimer();//清除计时器
  391. examEnds();//通知工作站关闭
  392. speckCancel();//停止播报
  393. window.onbeforeunload = null;//移除事件处理器
  394. let handcontroller_id = parameter.value.handcontroller;
  395. if (handcontroller_id) {
  396. router.push({ path: '/gesture' });//跳转
  397. } else {
  398. router.push({ path: '/' });//跳转
  399. }
  400. };
  401. /**
  402. * 清空定时任务
  403. */
  404. const getClearTimer = (data?: any) => {
  405. if (data) {
  406. //清除指定
  407. clearInterval(timerManager.value[data])
  408. timerManager.value[data] = null;
  409. } else {
  410. //清除全部
  411. for (let key in timerManager.value) {
  412. if (timerManager.value.hasOwnProperty(key)) {
  413. clearInterval(timerManager.value[key])
  414. timerManager.value[key] = null;
  415. }
  416. }
  417. }
  418. };
  419. /**
  420. * 选择学生
  421. */
  422. const getChooseStudent = () => {
  423. if (examState.value < 41) {
  424. proxy?.$modal.msgWarning("请等待");
  425. }
  426. if (examState.value == 41) {
  427. chooseStudentRef.value.open();
  428. //然后定时自动关闭
  429. setTimeout(() => {
  430. faceWindowRef.value.close();
  431. }, 3000)
  432. }
  433. if (examState.value == 43) {
  434. getRetestFace();
  435. }
  436. };
  437. /**
  438. * 返回被选学生
  439. */
  440. const returnStudent = (data: any) => {
  441. speckCancel();
  442. chooseStudentRef.value.close();
  443. faceCheckStu.value = data;
  444. faceWindowRef.value.open();
  445. //然后定时自动关闭
  446. setTimeout(() => {
  447. faceWindowRef.value.close();
  448. }, 1000)
  449. getStopFace();
  450. };
  451. /**
  452. * 清除历史记录
  453. */
  454. const cleanData = () => {
  455. time.value.countdownNum = time.value.testTime;
  456. showTestAgain.value = false;
  457. faceCheckStu.value = {};
  458. currentResultObj.value = {};
  459. backReason.value = [];
  460. };
  461. /**
  462. * 自动初始化项目
  463. */
  464. const initProject = () => {
  465. //停止计时
  466. getClearTimer("countdownTimer");
  467. //恢复倒计时按钮状态
  468. readyState.value = true;
  469. //自动项目定时进入下一步
  470. let time = 0;
  471. //控制新建测试的时间,第一次快,之后就慢
  472. if (!faceCheckStu.value.student_id) {
  473. time = 1000;
  474. } else {
  475. time = 6000;
  476. }
  477. setTimeout(() => {
  478. //再加一个判断以免和再测一次冲突
  479. if (examState.value == 3) {
  480. getOpenOneTestAndStartFace();
  481. }
  482. }, time)
  483. };
  484. /**
  485. * 时间转换
  486. */
  487. // const countdownNumFormat = computed(() => {
  488. // return time.value.countdownNum;
  489. // //return proxy?.$utils.timeFormat(time.value.countdownNum);
  490. // });
  491. /**
  492. * 倒计时
  493. */
  494. const getCounting = (type: string) => {
  495. timerManager.value.countdownTimer = setInterval(() => {
  496. //正计时
  497. if (type == "+") {
  498. time.value.countdownNum++;
  499. }
  500. //倒计时
  501. if (type == "-") {
  502. if (time.value.countdownNum <= 0) {
  503. getClearTimer("countdownTimer");
  504. } else {
  505. time.value.countdownNum--;
  506. }
  507. }
  508. }, 1000);
  509. };
  510. /**
  511. * 人脸窗口
  512. */
  513. const getFaceWindow = (data: boolean, num: number = 0) => {
  514. let total = num + 1;//叠加三次后不再播放
  515. let txt = parameter.value.gesture === true ? "请举右手看摄像头人脸识别" : "请看摄像头进行人脸识别";
  516. speckText(txt);
  517. //data=true为弹出框,data=false为不要弹出框
  518. if (data) {
  519. faceWindowRef.value.open();
  520. //然后定时自动关闭
  521. setTimeout(() => {
  522. if (examState.value == 41 && faceWindowRef.value?.faceState == true) {
  523. faceWindowRef.value.close();
  524. }
  525. }, 3000)
  526. }
  527. //定时检查如果一直停留在人脸识别就提示
  528. let timeout = 16000;
  529. timerManager.value.face = setInterval(() => {
  530. getClearTimer("face");
  531. if (examState.value == 41 && total < 3) {
  532. getFaceWindow(false, total);
  533. }
  534. }, timeout)
  535. };
  536. /**
  537. * 成绩
  538. */
  539. const getAchievement = (data: any) => {
  540. //console.log("成绩", data);
  541. let type = parameter.value.project;
  542. let count =
  543. data?.[dic.typeResultKey[type]]?.toFixed(0);
  544. if (["trijump", "solidball", "shotput", "longjump"].includes(type)) {
  545. count =
  546. data?.[dic.typeResultKey[type]]?.toFixed(2);
  547. count = Math.round(count) / 100;
  548. }
  549. if (["basketballv1"].includes(type)) {
  550. count = proxy?.$utils.runTime(data?.[dic.typeResultKey[type]], true, 1)
  551. }
  552. data.count = count || "0";
  553. data.score = data.score || "0";
  554. currentResultObj.value = data;
  555. //违规处理
  556. let arr = backReason.value;
  557. if (["situp", "pullup", "sidepullup", "jumprope", "jumpingjack", "jump", "longjump", "verticaljump"]
  558. .indexOf(type) > -1) {
  559. if (["pullup", "situp", "jumprope", "jumpingjack"].indexOf(type) > -1) {
  560. currentResultObj.value.back_num = data?.all_failed_num;
  561. }
  562. if (type === "sidepullup") {
  563. currentResultObj.value.back_num = data?.["0"]?.hip_failed_num;
  564. }
  565. if (['jump', 'longjump', 'verticaljump'].includes(type)) {
  566. if (data?.startline_check == 0) {
  567. let txt = "踩线违规";
  568. speckText(txt);
  569. arr.push(txt)
  570. }
  571. if (data?.singleleg_jump_check == 0) {
  572. let txt = "单脚跳违规";
  573. speckText(txt);
  574. arr.push(txt)
  575. }
  576. if (data?.outside_check == 0) {
  577. let txt = "跳出测试区违规";
  578. speckText(txt);
  579. arr.push(txt)
  580. }
  581. }
  582. if (
  583. data?.elbow_check == false
  584. ) {
  585. let txt = "肘部违规";
  586. speckText(txt);
  587. arr.push(txt);
  588. }
  589. if (
  590. ["situp", "pullup"].indexOf(type) > -1 &&
  591. data?.knee_check === false
  592. ) {
  593. let txt = "腿部违规";
  594. speckText(txt);
  595. if (!arr.includes(txt)) { }
  596. arr.push(txt);
  597. }
  598. if (["situp"].indexOf(type) > -1 && data?.hand_check === false) {
  599. let txt = "手部违规";
  600. speckText(txt);
  601. if (!arr.includes(txt)) { }
  602. arr.push(txt);
  603. }
  604. if (
  605. ["pullup"].indexOf(type) > -1 &&
  606. data?.["0"]?.elbow_check === false
  607. ) {
  608. let txt = "手部违规";
  609. speckText(txt);
  610. if (!arr.includes(txt)) { }
  611. arr.push(txt);
  612. }
  613. if (["situp"].indexOf(type) > -1 && data?.["0"]?.back_check === false) {
  614. let txt = "背部违规";
  615. speckText(txt);
  616. if (!arr.includes(txt)) { }
  617. arr.push(txt);
  618. }
  619. if (
  620. ["sidepullup", "situp"].indexOf(type) > -1 &&
  621. data?.["0"]?.hip_check === false
  622. ) {
  623. let txt = "臀部违规";
  624. speckText(txt);
  625. if (!arr.includes(txt)) { }
  626. arr.push(txt);
  627. }
  628. }
  629. backReason.value = arr;
  630. if (data.isfinish) {
  631. if (['jump'].includes(type) && backReason.value.length) {
  632. speckText("请重新测试");
  633. return false;
  634. }
  635. if (["basketballv1"].includes(type)) {
  636. speckText(faceCheckStu?.value.name + "成绩为" + (chineseNumber(proxy?.$utils.runTime(count, false, 0,
  637. 1)) || 0) + ",请下一位准备!" || "");
  638. } else {
  639. speckText(faceCheckStu?.value.name + "成绩为" + (chineseNumber(count) || 0) + unit.value + ",请下一位准备!" || "");
  640. }
  641. reportListRef.value.getIniReportList();
  642. faceWindowRef.value.open("right");
  643. //然后定时自动关闭
  644. setTimeout(() => {
  645. faceWindowRef.value.close();
  646. }, 1000)
  647. }
  648. };
  649. /**
  650. * 准备开始
  651. */
  652. const getReady = () => {
  653. if (needStart.value && examState.value == 43 && !time.value.ready && readyState.value) {
  654. if (time.value.ready) {
  655. return false;
  656. }
  657. speckCancel();
  658. readyState.value = false;
  659. time.value.ready = 6;
  660. timerManager.value.readyTimer = setInterval(() => {
  661. time.value.ready--;
  662. speckText(time.value.ready);
  663. if (time.value.ready == 0) {
  664. getClearTimer("readyTimer");
  665. getStartOneTest();
  666. }
  667. }, 1000);
  668. }
  669. };
  670. /**
  671. * 加载手势WS
  672. */
  673. const initHand = () => {
  674. handWs((e: any) => {
  675. if (router.currentRoute.value.path != '/train/test'){
  676. return false;
  677. }
  678. //左滑动
  679. if (e?.data?.result == "next_item") {
  680. }
  681. //举左手
  682. if (e?.data?.result == "left_hand") {
  683. //开始识别
  684. if (needStart.value && examState.value < 41) {
  685. getOpenOneTestAndStartFace();
  686. }
  687. //停止人脸识别
  688. // if (needStart.value && examState.value == 41) {
  689. // getStopFace();
  690. // }
  691. //开始测试
  692. if (examState.value == 43) {
  693. if (needStart.value) {
  694. getReady()
  695. } else {
  696. getStartOneTest();
  697. }
  698. }
  699. if (exit.value) {
  700. exit.value = 0;
  701. //确认退出
  702. let keyEvent: any = null;
  703. keyEvent = new KeyboardEvent('keydown', {
  704. key: 'Enter', // 键值
  705. code: 'Enter', // 键盘代码
  706. keyCode: 13, // 旧的键盘代码
  707. which: 13, // 新的键盘代码
  708. shiftKey: false, // 是否按下Shift键
  709. ctrlKey: false, // 是否按下Ctrl键
  710. metaKey: false, // 是否按下Meta键(Win键或Command键)
  711. bubbles: true, // 事件是否冒泡
  712. cancelable: true // 是否可以取消事件的默认行为
  713. });
  714. document.activeElement?.dispatchEvent(keyEvent);
  715. }
  716. }
  717. //退出
  718. if (e?.data?.result == "exit") {
  719. console.log("exit.value", exit.value)
  720. if (exit.value == 0) {
  721. exit.value = 1
  722. speckText("请5秒内举左手确认退出");
  723. //第一次才弹出
  724. confirmExit();
  725. time.value.exit = 6;
  726. timerManager.value.exitTimer = setInterval(() => {
  727. time.value.exit--;
  728. console.log("取消倒计时", time.value.exit)
  729. proxy?.$modal.msgWarning(`取消倒计时:${time.value.exit}`)
  730. if (time.value.exit == 0) {
  731. exit.value = 0;
  732. getClearTimer("exitTimer");
  733. let keyEvent: any = null;
  734. keyEvent = new KeyboardEvent('keydown', {
  735. key: 'Escape', // 键值
  736. code: 'Escape', // 键盘代码
  737. keyCode: 27, // 旧的键盘代码
  738. which: 27, // 新的键盘代码
  739. shiftKey: false, // 是否按下Shift键
  740. ctrlKey: false, // 是否按下Ctrl键
  741. metaKey: false, // 是否按下Meta键(Win键或Command键)
  742. bubbles: true, // 事件是否冒泡
  743. cancelable: true // 是否可以取消事件的默认行为
  744. });
  745. document.activeElement?.dispatchEvent(keyEvent);
  746. }
  747. }, 1000);
  748. }
  749. }
  750. });
  751. };
  752. /**
  753. * 输出犯规
  754. */
  755. watch(() => backReason.value.length, (v) => {
  756. backReasonStr.value = backReason.value[backReason.value.length - 1];
  757. setTimeout(() => {
  758. backReasonStr.value = "";
  759. }, 1500)
  760. }, { immediate: true });
  761. /**
  762. * 播报时间
  763. */
  764. watch(() => time.value.countdownNum, (newData) => {
  765. if (examState.value != 42) {
  766. return false;
  767. }
  768. if (newData >= 30) {
  769. if (newData % 30 == 0) {
  770. speckText(
  771. `还有${newData}秒`
  772. );
  773. }
  774. }
  775. if (newData == 10) {
  776. speckText("还有10秒");
  777. }
  778. if (newData <= 5) {
  779. speckText(newData);
  780. }
  781. if (newData == 0) {
  782. speckText("哨声");
  783. }
  784. }, { immediate: true });
  785. /**
  786. * 成绩整数播报
  787. */
  788. watch(() => currentResultObj.value, (newData: any, oldData: any) => {
  789. if (examState.value != 42 || newData.count <= 0) {
  790. return false;
  791. }
  792. let project = parameter.value.project;
  793. //引体向上比较慢所以都播报
  794. if (
  795. ["pullup"].includes(project) &&
  796. newData.count > 0 &&
  797. oldData.back_num == oldData.back_num
  798. ) {
  799. speckText(newData.count);
  800. }
  801. if (
  802. ["situp", "sidepullup", "jumprope", "jumpingjack"].includes(project) &&
  803. newData.count > 0 &&
  804. newData.count % 10 == 0 &&
  805. oldData.back_num == oldData.back_num
  806. ) {
  807. speckText(newData.count);
  808. }
  809. }, { immediate: true });
  810. onBeforeMount(() => {
  811. parameter.value = route.query;
  812. let project = parameter.value.project;
  813. let area = parameter.value.area;
  814. parameter.value.examId = `${project}_${area}`; //项目+区
  815. if (parameter.value.time) {
  816. time.value.testTime = parameter.value.time
  817. }
  818. time.value.countdownNum = time.value.testTime;
  819. userInfo.value = JSON.parse(myInfo);
  820. unit.value = dic.unit[project];
  821. if (parameter.value.gesture == 'true') {
  822. parameter.value.gesture = true
  823. } else {
  824. parameter.value.gesture = false
  825. }
  826. //需要开始按钮的项目
  827. let myList = ['situp', 'jumprope', 'jumpingjack', 'footballv1', 'basketballv1', 'volleyball', 'pingpong'];
  828. if (myList.includes(project)) {
  829. needStart.value = true;
  830. }
  831. //加载WS
  832. initWs({ parameter: parameter.value, testTime: time.value.testTime }, (data: any) => {
  833. getMessage(data);
  834. });
  835. //初始化语音
  836. initSpeech();
  837. //初始化手势
  838. initHand();
  839. //刷新关闭
  840. window.onbeforeunload = function (e) {
  841. var confirmationMessage = "刷新/关闭页面将会关闭页面,是否确认退出页面?";
  842. (e || window.event).returnValue = confirmationMessage; // 兼容 Gecko + IE
  843. let bUrl = import.meta.env.VITE_APP_BASE_API;
  844. let classId = parameter.value.classes;
  845. let project = parameter.value.project;
  846. let area = parameter.value.area;
  847. let examId = `${project}_${area}`;
  848. let mySid = sid.value;
  849. let token: any = localStorage.getItem("token")
  850. let formData = new FormData();
  851. formData.append("exam_id", examId);
  852. formData.append("class_id", classId);
  853. formData.append("token", token);
  854. formData.append("sid", mySid);
  855. navigator.sendBeacon(bUrl + "/exam/close_exam", formData)
  856. return confirmationMessage; // 兼容 Gecko + Webkit, Safari, Chrome
  857. };
  858. })
  859. onBeforeUnmount(() => {
  860. getExit();
  861. })
  862. </script>
  863. <style lang="scss" scoped>
  864. $topPadding: 5.19rem;
  865. $waiPadding: 6.51rem;
  866. .main {
  867. width: calc(100% - ($waiPadding * 2));
  868. height: 78vh;
  869. padding-top: 10rem;
  870. margin: 0 auto;
  871. display: flex;
  872. justify-content: space-between;
  873. overflow: hidden;
  874. .main-left {
  875. width: 71.5%;
  876. display: flex;
  877. flex-direction: column;
  878. justify-content: space-between;
  879. .main-left-top {
  880. display: flex;
  881. justify-content: space-between;
  882. height: 55.8%;
  883. position: relative;
  884. .top-left {
  885. width: 37.4%;
  886. height: 100%;
  887. border-radius: 1.6rem;
  888. background: radial-gradient(122% 126% at 97% 6%, #35FFC6 0%, #00FFE8 100%);
  889. text-align: center;
  890. display: flex;
  891. align-items: center;
  892. justify-content: center;
  893. cursor: pointer;
  894. .top-left-center {
  895. .pic {
  896. width: 22.3vh;
  897. height: 22.3vh;
  898. border-radius: 50%;
  899. display: flex;
  900. justify-content: center;
  901. align-items: center;
  902. overflow: hidden;
  903. margin: 0 auto 2vh auto;
  904. img {
  905. width: 100%;
  906. }
  907. }
  908. .pic2 {
  909. box-sizing: border-box;
  910. border: 0.44rem solid rgba(26, 41, 58, 0.6315);
  911. }
  912. .name {
  913. width: 100%;
  914. color: #1A293A;
  915. font-size: 2.21rem;
  916. }
  917. .name2 {
  918. padding: 0 0.3rem;
  919. border-radius: 1.1rem;
  920. background: radial-gradient(96% 96% at 2% 32%, #FFFFFF 0%, #FCFDFD 54%, #E1E4E7 100%);
  921. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
  922. }
  923. }
  924. }
  925. .top-right {
  926. width: 62%;
  927. height: 100%;
  928. border-radius: 1.6rem;
  929. opacity: 1;
  930. background: #ffffff;
  931. box-sizing: border-box;
  932. border: 0.55rem solid #13ED84;
  933. display: flex;
  934. align-items: center;
  935. justify-content: center;
  936. flex-direction: column;
  937. position: relative;
  938. .time {
  939. width: 28vh;
  940. height: 28vh;
  941. line-height: 28vh;
  942. border-radius: 50%;
  943. color: #FF9402;
  944. font-size: 11vh;
  945. text-align: center;
  946. background-image: url("@/assets/images/test/time.png");
  947. background-position: center;
  948. background-repeat: no-repeat;
  949. background-size: 100% 100%;
  950. position: absolute;
  951. right: -1.5vh;
  952. top: -11vh;
  953. font-family: 'Saira-BlackItalic';
  954. }
  955. .tips {
  956. display: flex;
  957. justify-content: center;
  958. align-items: center;
  959. height: 100%;
  960. img {
  961. max-height: 80%;
  962. max-height: 80%;
  963. }
  964. }
  965. .complete {
  966. width: 100%;
  967. display: flex;
  968. justify-content: center;
  969. flex-direction: column;
  970. .scoreBox {
  971. height: 10vh;
  972. color: #1A293A;
  973. display: flex;
  974. align-items: center;
  975. justify-content: center;
  976. margin-bottom: 5vh;
  977. .score {
  978. font-size: 8.5rem;
  979. line-height: 8.5rem;
  980. font-family: 'Saira-BlackItalic';
  981. }
  982. .unit {
  983. font-size: 2rem;
  984. margin-left: 10px;
  985. }
  986. }
  987. .fractionViolation {
  988. height: 10vh;
  989. display: flex;
  990. align-items: center;
  991. justify-content: center;
  992. .fraction {
  993. height: 10vh;
  994. line-height: 10vh;
  995. border-radius: 5vh;
  996. display: flex;
  997. align-items: center;
  998. padding: 0 6%;
  999. background: linear-gradient(138deg, #38536C 21%, #1A293A 75%);
  1000. box-shadow: inset 0px 1px 13px 0px rgba(255, 255, 255, 0.9452);
  1001. .lable {
  1002. font-size: 4vh;
  1003. color: #13ED84;
  1004. }
  1005. .value {
  1006. font-size: 7vh;
  1007. color: #00FFE8;
  1008. font-family: 'Saira-BlackItalic';
  1009. min-width: 7vh;
  1010. }
  1011. }
  1012. .violation {
  1013. height: 6.1vh;
  1014. line-height: 6.1vh;
  1015. border-radius: 4vh;
  1016. border: 0.25rem solid #ED7905;
  1017. display: flex;
  1018. align-items: center;
  1019. margin-left: 11px;
  1020. padding: 3px;
  1021. box-sizing: content-box;
  1022. .lable {
  1023. font-size: 1.2rem;
  1024. color: #ffffff;
  1025. width: 6.1vh;
  1026. height: 6.1vh;
  1027. line-height: 6.1vh;
  1028. background: #ED7905;
  1029. border-radius: 50%;
  1030. text-align: center;
  1031. }
  1032. .value {
  1033. margin-left: 1.5vh;
  1034. font-size: 3.2rem;
  1035. color: #ED7905;
  1036. font-family: 'Saira-BlackItalic';
  1037. min-width: 6vh;
  1038. }
  1039. }
  1040. }
  1041. }
  1042. .complete2 {
  1043. padding-left: 20%;
  1044. padding-top: 5vh;
  1045. .scoreBox {
  1046. margin-bottom: 3vh;
  1047. justify-content: left;
  1048. }
  1049. .fractionViolation {
  1050. justify-content: left;
  1051. .fraction {
  1052. padding: 0 8%;
  1053. }
  1054. }
  1055. }
  1056. .foulBox {
  1057. height: calc(4.2vh + 0.5rem + 6px);
  1058. overflow: hidden;
  1059. display: flex;
  1060. align-items: center;
  1061. justify-content: center;
  1062. padding-top: 3vh;
  1063. .foul {
  1064. height: 4.2vh;
  1065. line-height: 4.2vh;
  1066. border-radius: 3vh;
  1067. border: 0.25rem solid #ED7905;
  1068. display: flex;
  1069. align-items: center;
  1070. margin-left: 11px;
  1071. padding: 3px;
  1072. box-sizing: content-box;
  1073. .lable {
  1074. font-size: 2rem;
  1075. color: #ffffff;
  1076. width: 4.2vh;
  1077. height: 4.2vh;
  1078. line-height: 4.2vh;
  1079. background: #ED7905;
  1080. border-radius: 50%;
  1081. text-align: center;
  1082. }
  1083. .value {
  1084. margin-left: 1.5vh;
  1085. font-size: 2rem;
  1086. color: #ED7905;
  1087. font-family: 'Saira-BlackItalic';
  1088. min-width: 6vh;
  1089. padding: 0 10px;
  1090. }
  1091. }
  1092. }
  1093. .readyBoxBefore {
  1094. display: flex;
  1095. justify-content: center;
  1096. font-size: 2.5rem;
  1097. color: #1A293A;
  1098. padding-top: 4vh;
  1099. line-height: 0;
  1100. margin-bottom: 2vh;
  1101. .item {
  1102. display: flex;
  1103. justify-content: center;
  1104. .lable {
  1105. display: flex;
  1106. align-items: center;
  1107. margin-left: 10px;
  1108. }
  1109. }
  1110. img {
  1111. height: 20vh;
  1112. }
  1113. }
  1114. .readyBox {
  1115. text-align: center;
  1116. color: #1A293A;
  1117. .value {
  1118. font-size: 8.5rem;
  1119. line-height: 8.5rem;
  1120. font-family: 'Saira-BlackItalic';
  1121. }
  1122. .lable {
  1123. font-size: 3.5rem;
  1124. }
  1125. .transparent {
  1126. opacity: 0;
  1127. }
  1128. }
  1129. .btn {
  1130. font-size: 2.21rem;
  1131. color: #FFFFFF;
  1132. text-align: center;
  1133. width: 50%;
  1134. line-height: 8vh;
  1135. line-height: 8vh;
  1136. border-radius: 15px;
  1137. opacity: 1;
  1138. background: radial-gradient(159% 126% at 5% 93%, #F99F02 0%, #ED7905 100%);
  1139. box-shadow: 3px 6px 4px 1px rgba(0, 0, 0, 0.1874), inset 0px 1px 0px 2px rgba(255, 255, 255, 0.3);
  1140. cursor: pointer;
  1141. }
  1142. }
  1143. i {
  1144. width: 4vw;
  1145. height: 4vw;
  1146. display: block;
  1147. position: absolute;
  1148. top: 50%;
  1149. left: 37.5%;
  1150. margin-top: calc(4vw * -0.5);
  1151. margin-left: calc(4vw * -0.5);
  1152. background-image: url("@/assets/images/test/yuan.png");
  1153. background-position: center;
  1154. background-repeat: no-repeat;
  1155. background-size: 100% 100%;
  1156. border-radius: 50%;
  1157. flex-shrink: 0;
  1158. transition: all 0.5s;
  1159. }
  1160. }
  1161. .main-left-bottom {
  1162. display: flex;
  1163. justify-content: space-between;
  1164. height: calc(100% - 55.8% - 3vh);
  1165. overflow: hidden;
  1166. .bottom-left {
  1167. width: 58%;
  1168. padding-right: 1rem;
  1169. display: flex;
  1170. flex-direction: column;
  1171. .tips {
  1172. height: 2.8vh;
  1173. img {
  1174. height: 100%;
  1175. }
  1176. }
  1177. .pic {
  1178. text-align: center;
  1179. width: 100%;
  1180. height: 100%;
  1181. display: flex;
  1182. justify-content: center;
  1183. overflow: hidden;
  1184. img {
  1185. max-width: 100%;
  1186. max-height: 100%;
  1187. }
  1188. }
  1189. }
  1190. .bottom-right {
  1191. width: 41%;
  1192. height: 100%;
  1193. overflow-y: scroll;
  1194. color: #F9F9F9;
  1195. font-size: 1.1rem;
  1196. line-height: 1.6rem;
  1197. &::-webkit-scrollbar {
  1198. width: 10px;
  1199. }
  1200. &::-webkit-scrollbar-thumb {
  1201. border-width: 2px;
  1202. border-radius: 4px;
  1203. border-style: dashed;
  1204. border-color: transparent;
  1205. background-color: rgba(26, 62, 78, 0.9);
  1206. background-clip: padding-box;
  1207. }
  1208. &::-webkit-scrollbar-button:hover {
  1209. border-radius: 6px;
  1210. background: rgba(26, 62, 78, 1);
  1211. }
  1212. }
  1213. }
  1214. }
  1215. .main-right {
  1216. width: 27%;
  1217. border-radius: 1.6rem;
  1218. background: linear-gradient(29deg, #092941 -82%, #2A484B 94%);
  1219. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.4);
  1220. display: flex;
  1221. flex-direction: column;
  1222. overflow: hidden;
  1223. }
  1224. }
  1225. </style>