test.vue 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  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" :leave-active-class="proxy?.animate.mask.leave">
  52. <div class="foul" v-show="backReasonStr ? true : false">
  53. <div class="lable">!</div>
  54. <div class="value">{{ backReasonStr }}</div>
  55. </div>
  56. </Transition>
  57. </div>
  58. <div v-show="examState == 43 && time.ready">
  59. <div class="readyBox">
  60. <div class="value" :class="{ 'transparent': time.ready > 5 }">{{ time.ready }}</div>
  61. <div class="lable">倒计时</div>
  62. </div>
  63. </div>
  64. <div v-show="examState == 43 && !time.ready && readyState">
  65. <div class="readyBoxBefore">
  66. <div class="item" v-if="parameter.handcontroller">
  67. <div><img src="@/assets/images/test/jushou.png" /></div>
  68. <div class="lable">
  69. <div>请举左手开始</div>
  70. </div>
  71. </div>
  72. <div class="item" v-else>
  73. <div> <img src="@/assets/images/test/bujushou.png" /></div>
  74. <div class="lable">
  75. <div>请点击开始</div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="btn" @click="getReady" v-if="needStart && examState == 43 && !time.ready && readyState">开 始
  81. </div>
  82. <!-- <div v-if="needStart"> -->
  83. <!-- <div class="btn" @click="getOpenOneTestAndStartFace" v-if="examState < 41">开始识别</div> -->
  84. <!-- <div class="btn" @click="getStopFace" v-if="examState == 41 && !parameter.gesture">停止人脸识别</div> -->
  85. <!-- <div class="btn" @click="getStartOneTest" v-if="examState == 43">开始测试</div> -->
  86. <!-- <div @click="getRetestFace" v-if="examState == 43 || examState == 42">重新识别</div> -->
  87. <!-- </div> -->
  88. <!-- <div>当前状态:({{ examState == 3 ? "初始化完成" : examState == 40 ? "创建测试" : examState == 41 ? "正在人脸识别":examState == 43 ? "停止人脸识别" : examState == 42 ? "正在测试" : "请初始化" }})</div> -->
  89. <!-- <div @click="getAgain" v-if="examState == 42 || showTestAgain">再测一次</div> -->
  90. </div>
  91. <i></i>
  92. </div>
  93. <div class="main-left-bottom">
  94. <div class="bottom-left">
  95. <div class="tips"><img src="/src/assets/images/test/tips.png" /></div>
  96. <div class="pic"><img :src="'static/images/tips/' + parameter.project + '.png'" /></div>
  97. </div>
  98. <div class="bottom-right" v-html="dic.projectNote[parameter.project]">
  99. </div>
  100. </div>
  101. </div>
  102. <div class="main-right">
  103. <ReportList ref="reportListRef" :parameter="parameter" :showQRCode="true" />
  104. </div>
  105. </div>
  106. <FaceWindow ref="faceWindowRef" :faceCheckStu="faceCheckStu" :gesture="parameter.gesture" />
  107. <ChooseStudent ref="chooseStudentRef" @returnData="returnStudent" />
  108. </div>
  109. </template>
  110. <script setup name="TrainTest" lang="ts">
  111. // import { useWs } from '@/utils/trainWs';
  112. import { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
  113. import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech'
  114. import { useWebSocket } from '@/utils/handWs';
  115. import dayjs from 'dayjs'
  116. import dataDictionary from "@/utils/dataDictionary"
  117. const { handWs, startDevice, startHand, stateHand } = useWebSocket();
  118. // const { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } = useWs();
  119. const { proxy } = getCurrentInstance() as any;
  120. const router = useRouter();
  121. const route = useRoute();
  122. const faceWindowRef = ref();
  123. const chooseStudentRef = ref();
  124. const reportListRef = ref();
  125. const myInfo: any = localStorage.getItem("userInfo");
  126. const dic: any = dataDictionary;
  127. const data = reactive<any>({
  128. timerManager: {},//计时器管理
  129. parameter: {},//参数
  130. time: {
  131. testTime: 60,//时长
  132. countdownNum: 0,//计时
  133. ready: 0,//预备
  134. exit: 0,//退出倒计时
  135. },
  136. userInfo: {},//用户信息
  137. examState: 0,//当前状态
  138. resultId: null,//测试ID
  139. currentResultObj: {},//成绩
  140. faceCheckStu: {},//人脸信息
  141. unit: "",//单位
  142. backReason: [],//犯规项
  143. backReasonStr: "",//犯规提示
  144. needStart: false,//是否需要按钮
  145. showTestAgain: false,//再测一次按钮
  146. readyState: true,//倒计时按钮状态
  147. exit: 0,//退出响应次数
  148. sid: null,//WS的id
  149. device_info: {},//设备信息
  150. });
  151. const { timerManager, parameter, time, userInfo, examState, resultId, faceCheckStu, currentResultObj, unit, backReason, backReasonStr, needStart, showTestAgain, readyState, exit, sid, device_info } = 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 ? ",请举左手开始测试" : ",请准备";
  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. * 获取设备项目
  672. */
  673. const getDevice = async () => {
  674. let deviceid = localStorage.getItem("deviceid") || '';
  675. if (deviceid) {
  676. startDevice({ deviceid: deviceid })
  677. } else {
  678. proxy?.$modal.msgError(`缺少设备信息请重新登录!`);
  679. await proxy?.$http.common.logout({}).then((res: any) => {
  680. });
  681. proxy?.$modal?.closeLoading()
  682. //清空缓存
  683. localStorage.clear();
  684. //跳转
  685. router.push({ path: '/login/qrcode' });
  686. }
  687. };
  688. /**
  689. * 加载手势WS
  690. */
  691. const initHand = () => {
  692. handWs((e: any) => {
  693. if (router.currentRoute.value.path != '/train/test' || parameter.value.handcontroller == undefined || examState.value == 0) {
  694. return false;
  695. }
  696. console.log("eeeee", e)
  697. if (e?.wksid) {
  698. //获取设备项目
  699. getDevice()
  700. }
  701. //接收设备信息
  702. if (e?.device_info) {
  703. device_info.value = e.device_info;
  704. let handcontroller_id = device_info.value.handcontroller_id;
  705. stateHand(handcontroller_id);
  706. }
  707. //获取手势状态
  708. if (e?.cmd == 'get_handcontroller_state' && e?.state == 0) {
  709. let handcontroller_id = device_info.value.handcontroller_id;
  710. startHand(handcontroller_id);
  711. }
  712. //刷新
  713. if (e?.data?.result == "refresh") {
  714. getExit();
  715. //刷新
  716. window.location.reload()
  717. }
  718. //没初始化完成不监听手势动作
  719. if(examState.value == 0){
  720. return false;
  721. }
  722. //左滑动
  723. if (e?.data?.result == "next_item") {
  724. }
  725. //举左手
  726. if (e?.data?.result == "left_hand") {
  727. if (exit.value) {
  728. exit.value = 0;
  729. //确认退出
  730. let keyEvent: any = null;
  731. keyEvent = new KeyboardEvent('keydown', {
  732. key: 'Enter', // 键值
  733. code: 'Enter', // 键盘代码
  734. keyCode: 13, // 旧的键盘代码
  735. which: 13, // 新的键盘代码
  736. shiftKey: false, // 是否按下Shift键
  737. ctrlKey: false, // 是否按下Ctrl键
  738. metaKey: false, // 是否按下Meta键(Win键或Command键)
  739. bubbles: true, // 事件是否冒泡
  740. cancelable: true // 是否可以取消事件的默认行为
  741. });
  742. document.activeElement?.dispatchEvent(keyEvent);
  743. return false;
  744. }
  745. //开始识别
  746. if (needStart.value && examState.value < 41) {
  747. getOpenOneTestAndStartFace();
  748. return false;
  749. }
  750. //停止人脸识别
  751. // if (needStart.value && examState.value == 41) {
  752. // getStopFace();
  753. // }
  754. //开始测试
  755. if (examState.value == 43) {
  756. if (needStart.value) {
  757. getReady()
  758. } else {
  759. getStartOneTest();
  760. }
  761. return false;
  762. }
  763. }
  764. //退出
  765. if (e?.data?.result == "exit") {
  766. console.log("exit.value", exit.value)
  767. if (exit.value == 0) {
  768. exit.value = 1
  769. speckText("请5秒内举左手确认退出");
  770. //第一次才弹出
  771. confirmExit();
  772. time.value.exit = 6;
  773. timerManager.value.exitTimer = setInterval(() => {
  774. time.value.exit--;
  775. console.log("取消倒计时", time.value.exit)
  776. proxy?.$modal.msgWarning(`取消倒计时:${time.value.exit}`)
  777. if (time.value.exit == 0) {
  778. exit.value = 0;
  779. getClearTimer("exitTimer");
  780. let keyEvent: any = null;
  781. keyEvent = new KeyboardEvent('keydown', {
  782. key: 'Escape', // 键值
  783. code: 'Escape', // 键盘代码
  784. keyCode: 27, // 旧的键盘代码
  785. which: 27, // 新的键盘代码
  786. shiftKey: false, // 是否按下Shift键
  787. ctrlKey: false, // 是否按下Ctrl键
  788. metaKey: false, // 是否按下Meta键(Win键或Command键)
  789. bubbles: true, // 事件是否冒泡
  790. cancelable: true // 是否可以取消事件的默认行为
  791. });
  792. document.activeElement?.dispatchEvent(keyEvent);
  793. }
  794. }, 1000);
  795. }
  796. }
  797. });
  798. };
  799. /**
  800. * 输出犯规
  801. */
  802. watch(() => backReason.value.length, (v) => {
  803. backReasonStr.value = backReason.value[backReason.value.length - 1];
  804. setTimeout(() => {
  805. backReasonStr.value = "";
  806. }, 1500)
  807. }, { immediate: true });
  808. /**
  809. * 播报时间
  810. */
  811. watch(() => time.value.countdownNum, (newData) => {
  812. if (examState.value != 42) {
  813. return false;
  814. }
  815. if (newData >= 30) {
  816. if (newData % 30 == 0) {
  817. speckText(
  818. `还有${newData}秒`
  819. );
  820. }
  821. }
  822. if (newData == 10) {
  823. speckText("还有10秒");
  824. }
  825. if (newData <= 5) {
  826. speckText(newData);
  827. }
  828. if (newData == 0) {
  829. speckText("哨声");
  830. }
  831. }, { immediate: true });
  832. /**
  833. * 成绩整数播报
  834. */
  835. watch(() => currentResultObj.value, (newData: any, oldData: any) => {
  836. if (examState.value != 42 || newData.count <= 0) {
  837. return false;
  838. }
  839. let project = parameter.value.project;
  840. //引体向上比较慢所以都播报
  841. if (
  842. ["pullup"].includes(project) &&
  843. newData.count > 0 &&
  844. oldData.back_num == oldData.back_num
  845. ) {
  846. speckText(newData.count);
  847. }
  848. if (
  849. ["situp", "sidepullup", "jumprope", "jumpingjack"].includes(project) &&
  850. newData.count > 0 &&
  851. newData.count % 10 == 0 &&
  852. oldData.back_num == oldData.back_num
  853. ) {
  854. speckText(newData.count);
  855. }
  856. }, { immediate: true });
  857. onBeforeMount(() => {
  858. parameter.value = route.query;
  859. let project = parameter.value.project;
  860. let area = parameter.value.area;
  861. parameter.value.examId = `${project}_${area}`; //项目+区
  862. if (parameter.value.time) {
  863. time.value.testTime = parameter.value.time
  864. }
  865. time.value.countdownNum = time.value.testTime;
  866. userInfo.value = JSON.parse(myInfo);
  867. unit.value = dic.unit[project];
  868. if (parameter.value.gesture == 'true') {
  869. parameter.value.gesture = true
  870. } else {
  871. parameter.value.gesture = false
  872. }
  873. //需要开始按钮的项目
  874. let myList = ['situp', 'jumprope', 'jumpingjack', 'footballv1', 'basketballv1', 'volleyball', 'pingpong'];
  875. if (myList.includes(project)) {
  876. needStart.value = true;
  877. }
  878. //加载WS
  879. initWs({ parameter: parameter.value, testTime: time.value.testTime }, (data: any) => {
  880. getMessage(data);
  881. });
  882. //初始化语音
  883. initSpeech();
  884. //初始化手势
  885. initHand();
  886. //刷新关闭
  887. window.onbeforeunload = function (e) {
  888. var confirmationMessage = "刷新/关闭页面将会关闭页面,是否确认退出页面?";
  889. (e || window.event).returnValue = confirmationMessage; // 兼容 Gecko + IE
  890. let bUrl = import.meta.env.VITE_APP_BASE_API;
  891. let classId = parameter.value.classes;
  892. let project = parameter.value.project;
  893. let area = parameter.value.area;
  894. let examId = `${project}_${area}`;
  895. let mySid = sid.value;
  896. let token: any = localStorage.getItem("token")
  897. let formData = new FormData();
  898. formData.append("exam_id", examId);
  899. formData.append("class_id", classId);
  900. formData.append("token", token);
  901. formData.append("sid", mySid);
  902. navigator.sendBeacon(bUrl + "/exam/close_exam", formData)
  903. return confirmationMessage; // 兼容 Gecko + Webkit, Safari, Chrome
  904. };
  905. })
  906. onBeforeUnmount(() => {
  907. getExit();
  908. })
  909. </script>
  910. <style lang="scss" scoped>
  911. $topPadding: 5.19rem;
  912. $waiPadding: 6.51rem;
  913. .main {
  914. width: calc(100% - ($waiPadding * 2));
  915. height: 78vh;
  916. padding-top: 10rem;
  917. margin: 0 auto;
  918. display: flex;
  919. justify-content: space-between;
  920. overflow: hidden;
  921. .main-left {
  922. width: 71.5%;
  923. display: flex;
  924. flex-direction: column;
  925. justify-content: space-between;
  926. .main-left-top {
  927. display: flex;
  928. justify-content: space-between;
  929. height: 55.8%;
  930. position: relative;
  931. .top-left {
  932. width: 37.4%;
  933. height: 100%;
  934. border-radius: 1.6rem;
  935. background: radial-gradient(122% 126% at 97% 6%, #35FFC6 0%, #00FFE8 100%);
  936. text-align: center;
  937. display: flex;
  938. align-items: center;
  939. justify-content: center;
  940. cursor: pointer;
  941. .top-left-center {
  942. .pic {
  943. width: 22.3vh;
  944. height: 22.3vh;
  945. border-radius: 50%;
  946. display: flex;
  947. justify-content: center;
  948. align-items: center;
  949. overflow: hidden;
  950. margin: 0 auto 2vh auto;
  951. img {
  952. width: 100%;
  953. }
  954. }
  955. .pic2 {
  956. box-sizing: border-box;
  957. border: 0.44rem solid rgba(26, 41, 58, 0.6315);
  958. }
  959. .name {
  960. width: 100%;
  961. color: #1A293A;
  962. font-size: 2.21rem;
  963. }
  964. .name2 {
  965. padding: 0 0.3rem;
  966. border-radius: 1.1rem;
  967. background: radial-gradient(96% 96% at 2% 32%, #FFFFFF 0%, #FCFDFD 54%, #E1E4E7 100%);
  968. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
  969. }
  970. }
  971. }
  972. .top-right {
  973. width: 62%;
  974. height: 100%;
  975. border-radius: 1.6rem;
  976. opacity: 1;
  977. background: #ffffff;
  978. box-sizing: border-box;
  979. border: 0.55rem solid #13ED84;
  980. display: flex;
  981. align-items: center;
  982. justify-content: center;
  983. flex-direction: column;
  984. position: relative;
  985. .time {
  986. width: 28vh;
  987. height: 28vh;
  988. line-height: 28vh;
  989. border-radius: 50%;
  990. color: #FF9402;
  991. font-size: 11vh;
  992. text-align: center;
  993. background-image: url("@/assets/images/test/time.png");
  994. background-position: center;
  995. background-repeat: no-repeat;
  996. background-size: 100% 100%;
  997. position: absolute;
  998. right: -1.5vh;
  999. top: -11vh;
  1000. font-family: 'Saira-BlackItalic';
  1001. }
  1002. .tips {
  1003. display: flex;
  1004. justify-content: center;
  1005. align-items: center;
  1006. height: 100%;
  1007. img {
  1008. max-height: 80%;
  1009. max-height: 80%;
  1010. }
  1011. }
  1012. .complete {
  1013. width: 100%;
  1014. display: flex;
  1015. justify-content: center;
  1016. flex-direction: column;
  1017. .scoreBox {
  1018. height: 10vh;
  1019. color: #1A293A;
  1020. display: flex;
  1021. align-items: center;
  1022. justify-content: center;
  1023. margin-bottom: 5vh;
  1024. .score {
  1025. font-size: 8.5rem;
  1026. line-height: 8.5rem;
  1027. font-family: 'Saira-BlackItalic';
  1028. }
  1029. .unit {
  1030. font-size: 2rem;
  1031. margin-left: 10px;
  1032. }
  1033. }
  1034. .fractionViolation {
  1035. height: 10vh;
  1036. display: flex;
  1037. align-items: center;
  1038. justify-content: center;
  1039. .fraction {
  1040. height: 10vh;
  1041. line-height: 10vh;
  1042. border-radius: 5vh;
  1043. display: flex;
  1044. align-items: center;
  1045. padding: 0 6%;
  1046. background: linear-gradient(138deg, #38536C 21%, #1A293A 75%);
  1047. box-shadow: inset 0px 1px 13px 0px rgba(255, 255, 255, 0.9452);
  1048. .lable {
  1049. font-size: 4vh;
  1050. color: #13ED84;
  1051. }
  1052. .value {
  1053. font-size: 7vh;
  1054. color: #00FFE8;
  1055. font-family: 'Saira-BlackItalic';
  1056. min-width: 7vh;
  1057. }
  1058. }
  1059. .violation {
  1060. height: 6.1vh;
  1061. line-height: 6.1vh;
  1062. border-radius: 4vh;
  1063. border: 0.25rem solid #ED7905;
  1064. display: flex;
  1065. align-items: center;
  1066. margin-left: 11px;
  1067. padding: 3px;
  1068. box-sizing: content-box;
  1069. .lable {
  1070. font-size: 1.2rem;
  1071. color: #ffffff;
  1072. width: 6.1vh;
  1073. height: 6.1vh;
  1074. line-height: 6.1vh;
  1075. background: #ED7905;
  1076. border-radius: 50%;
  1077. text-align: center;
  1078. }
  1079. .value {
  1080. margin-left: 1.5vh;
  1081. font-size: 3.2rem;
  1082. color: #ED7905;
  1083. font-family: 'Saira-BlackItalic';
  1084. min-width: 6vh;
  1085. }
  1086. }
  1087. }
  1088. }
  1089. .complete2 {
  1090. padding-left: 20%;
  1091. padding-top: 5vh;
  1092. .scoreBox {
  1093. margin-bottom: 3vh;
  1094. justify-content: left;
  1095. }
  1096. .fractionViolation {
  1097. justify-content: left;
  1098. .fraction {
  1099. padding: 0 8%;
  1100. }
  1101. }
  1102. }
  1103. .foulBox {
  1104. height: calc(4.2vh + 0.5rem + 6px);
  1105. overflow: hidden;
  1106. display: flex;
  1107. align-items: center;
  1108. justify-content: center;
  1109. padding-top: 3vh;
  1110. .foul {
  1111. height: 4.2vh;
  1112. line-height: 4.2vh;
  1113. border-radius: 3vh;
  1114. border: 0.25rem solid #ED7905;
  1115. display: flex;
  1116. align-items: center;
  1117. margin-left: 11px;
  1118. padding: 3px;
  1119. box-sizing: content-box;
  1120. .lable {
  1121. font-size: 2rem;
  1122. color: #ffffff;
  1123. width: 4.2vh;
  1124. height: 4.2vh;
  1125. line-height: 4.2vh;
  1126. background: #ED7905;
  1127. border-radius: 50%;
  1128. text-align: center;
  1129. }
  1130. .value {
  1131. margin-left: 1.5vh;
  1132. font-size: 2rem;
  1133. color: #ED7905;
  1134. font-family: 'Saira-BlackItalic';
  1135. min-width: 6vh;
  1136. padding: 0 10px;
  1137. }
  1138. }
  1139. }
  1140. .readyBoxBefore {
  1141. display: flex;
  1142. justify-content: center;
  1143. font-size: 2.5rem;
  1144. color: #1A293A;
  1145. padding-top: 4vh;
  1146. line-height: 0;
  1147. margin-bottom: 2vh;
  1148. .item {
  1149. display: flex;
  1150. justify-content: center;
  1151. .lable {
  1152. display: flex;
  1153. align-items: center;
  1154. margin-left: 10px;
  1155. }
  1156. }
  1157. img {
  1158. height: 20vh;
  1159. }
  1160. }
  1161. .readyBox {
  1162. text-align: center;
  1163. color: #1A293A;
  1164. .value {
  1165. font-size: 8.5rem;
  1166. line-height: 8.5rem;
  1167. font-family: 'Saira-BlackItalic';
  1168. }
  1169. .lable {
  1170. font-size: 3.5rem;
  1171. }
  1172. .transparent {
  1173. opacity: 0;
  1174. }
  1175. }
  1176. .btn {
  1177. font-size: 2.21rem;
  1178. color: #FFFFFF;
  1179. text-align: center;
  1180. width: 50%;
  1181. line-height: 8vh;
  1182. line-height: 8vh;
  1183. border-radius: 15px;
  1184. opacity: 1;
  1185. background: radial-gradient(159% 126% at 5% 93%, #F99F02 0%, #ED7905 100%);
  1186. box-shadow: 3px 6px 4px 1px rgba(0, 0, 0, 0.1874), inset 0px 1px 0px 2px rgba(255, 255, 255, 0.3);
  1187. cursor: pointer;
  1188. }
  1189. }
  1190. i {
  1191. width: 4vw;
  1192. height: 4vw;
  1193. display: block;
  1194. position: absolute;
  1195. top: 50%;
  1196. left: 37.5%;
  1197. margin-top: calc(4vw * -0.5);
  1198. margin-left: calc(4vw * -0.5);
  1199. background-image: url("@/assets/images/test/yuan.png");
  1200. background-position: center;
  1201. background-repeat: no-repeat;
  1202. background-size: 100% 100%;
  1203. border-radius: 50%;
  1204. flex-shrink: 0;
  1205. transition: all 0.5s;
  1206. }
  1207. }
  1208. .main-left-bottom {
  1209. display: flex;
  1210. justify-content: space-between;
  1211. height: calc(100% - 55.8% - 3vh);
  1212. overflow: hidden;
  1213. .bottom-left {
  1214. width: 58%;
  1215. padding-right: 1rem;
  1216. display: flex;
  1217. flex-direction: column;
  1218. .tips {
  1219. height: 2.8vh;
  1220. img {
  1221. height: 100%;
  1222. }
  1223. }
  1224. .pic {
  1225. text-align: center;
  1226. width: 100%;
  1227. height: 100%;
  1228. display: flex;
  1229. justify-content: center;
  1230. overflow: hidden;
  1231. img {
  1232. max-width: 100%;
  1233. max-height: 100%;
  1234. }
  1235. }
  1236. }
  1237. .bottom-right {
  1238. width: 41%;
  1239. height: 100%;
  1240. overflow-y: scroll;
  1241. color: #F9F9F9;
  1242. font-size: 1.1rem;
  1243. line-height: 1.6rem;
  1244. &::-webkit-scrollbar {
  1245. width: 10px;
  1246. }
  1247. &::-webkit-scrollbar-thumb {
  1248. border-width: 2px;
  1249. border-radius: 4px;
  1250. border-style: dashed;
  1251. border-color: transparent;
  1252. background-color: rgba(26, 62, 78, 0.9);
  1253. background-clip: padding-box;
  1254. }
  1255. &::-webkit-scrollbar-button:hover {
  1256. border-radius: 6px;
  1257. background: rgba(26, 62, 78, 1);
  1258. }
  1259. }
  1260. }
  1261. }
  1262. .main-right {
  1263. width: 27%;
  1264. border-radius: 1.6rem;
  1265. background: linear-gradient(29deg, #092941 -82%, #2A484B 94%);
  1266. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.4);
  1267. display: flex;
  1268. flex-direction: column;
  1269. overflow: hidden;
  1270. }
  1271. }
  1272. </style>