test.vue 32 KB

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