index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <div>
  3. <div>{{ area }}</div>
  4. <div><el-avatar :src="faceCheckStu.logo_url || faceCheckStu.face_pic" @click="getChooseStudent" /></div>
  5. <div>{{ faceCheckStu.name }}</div>
  6. <div>成绩:{{ currentResultObj.count }} {{ unit }}</div>
  7. <div>得分:{{ currentResultObj.score }}</div>
  8. <div>
  9. <div v-if="['jumprope'].includes(project)">中断</div>
  10. <div v-else>犯规</div>
  11. <div>{{ currentResultObj.back_num }}</div>
  12. </div>
  13. <div v-if="backReason.length">
  14. <div>违规项</div>
  15. <div v-for="(item, index) in backReason" :key="index">{{ item }}</div>
  16. </div>
  17. <div>当前状态:({{ examState == 3 ? "初始化完成" : examState == 40 ? "创建测试" : examState == 41 ? "正在人脸识别"
  18. :
  19. examState ==
  20. 43 ? "停止人脸识别" : examState == 42 ? "正在测试" : "请初始化" }})</div>
  21. <div @click="getChooseStudent" v-if="examState == 41 || (examState == 43 && !faceCheckStu.student_id)">选择学生</div>
  22. <div @click="getRetestFace" v-if="examState == 43">重新识别</div>
  23. <ChooseStudent ref="chooseStudentRef" @returnData="returnStudent" />
  24. </div>
  25. </template>
  26. <script setup lang="ts">
  27. import { initSpeech, speckText, speckCancel, chineseNumber } from '@/utils/speech'
  28. import { openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
  29. import dataDictionary from "@/utils/dataDictionary"
  30. const route = useRoute();
  31. const { proxy } = getCurrentInstance() as any;
  32. const chooseStudentRef = ref();
  33. const emit = defineEmits(['returnData']);
  34. //父值
  35. const props = defineProps({
  36. area: {
  37. type: String,
  38. default: ""
  39. },
  40. examState: {
  41. type: Number,
  42. default: ""
  43. },
  44. needStart: {
  45. type: Boolean,
  46. default: false
  47. },
  48. });
  49. let project: any = route.query.project;
  50. let area: any = props.area;
  51. let examId: string = `${project}_${area}`; //项目+区
  52. const data = reactive<any>({
  53. examState: 0,//当前状态
  54. resultId: null,//测试ID
  55. currentResultObj: {},//成绩
  56. faceCheckStu: {},//人脸信息
  57. unit: "",//单位
  58. backReason: [],//犯规项
  59. });
  60. const { examState, resultId, faceCheckStu, currentResultObj, unit, backReason } = toRefs(data);
  61. /**
  62. * 接收消息
  63. */
  64. const getMessage = (e: any) => {
  65. //console.log("WS响应:", e)
  66. //实时状态
  67. if (e.cmd === 'exam_status') {
  68. examState.value = e.data;
  69. }
  70. //工作站状态
  71. if (e.cmd === 'init_result') {
  72. }
  73. //测试违规
  74. if (e.cmd === 'warning_result') {
  75. }
  76. //后端播报语音
  77. if (e.cmd === 'return_audio_msg') {
  78. }
  79. //错误提示
  80. if (e.cmd === 'info_result') {
  81. proxy?.$modal.msgError(e.data.message);
  82. }
  83. //错误提示
  84. if (e.cmd === 'error_result') {
  85. proxy?.$modal.msgError(e.data.message);
  86. }
  87. //测试中违规提示
  88. if (e.cmd === 'warning_notify') {
  89. }
  90. //断线状态
  91. if (e.cmd === 'disconnect_request') {
  92. if (e.data.message) {
  93. speckText(e.data.message);
  94. }
  95. }
  96. //状态变更
  97. if (e.cmd === 'set_exam_state') {
  98. examState.value = e.data;
  99. if (e.data === 3) {
  100. initProject();
  101. }
  102. if (e.data === 40) {
  103. cleanData();
  104. }
  105. if (e.data == 41) {
  106. }
  107. if (e.data == 43) {
  108. }
  109. if (e.data == 42) {
  110. }
  111. }
  112. //新建测试后返回信息,获取result_id
  113. if (e.cmd === 'open_one_test_ack') {
  114. resultId.value = e.data.result_id;
  115. }
  116. //人脸识别状态
  117. if (e.cmd === 'face_check_result') {
  118. let myData = e.data[0] || e.data;
  119. returnStudent(myData);
  120. }
  121. //测试结束结果
  122. if (e.cmd === 'oneresult') {
  123. if (e.data.length) {
  124. let data = e.data[0];
  125. getAchievement(data)
  126. }
  127. }
  128. //结果生成完成(视频图片)
  129. if (e.cmd === 'static_urls_finished') {
  130. }
  131. //选择学生或测试结束后返回的数据
  132. if (e.cmd === 'result_info') {
  133. }
  134. };
  135. /**
  136. * 开始识别
  137. */
  138. const getOpenOneTestAndStartFace = async () => {
  139. console.log("examId", examId)
  140. if (examState.value > 3) {
  141. await closeOneTest(examId);
  142. }
  143. await openOneTest(examId);
  144. await startFace(examId);
  145. };
  146. /**
  147. * 停止人脸识别
  148. */
  149. const getStopFace = async () => {
  150. if (examState.value != 41) {
  151. return false;
  152. }
  153. await stopFace(examId);
  154. if (faceCheckStu.value.student_id) {
  155. getFaceConfirmOnly();
  156. }
  157. };
  158. /**
  159. * 确定人脸信息
  160. */
  161. const getFaceConfirmOnly = (data?: any) => {
  162. if (data) {
  163. faceCheckStu.value = data;
  164. }
  165. faceConfirmOnly({
  166. exam_id: examId,
  167. result_id: resultId.value,
  168. student_id: faceCheckStu.value.student_id,
  169. gender: faceCheckStu.value.gender
  170. }, () => {
  171. });
  172. };
  173. /**
  174. * 重新识别
  175. */
  176. const getRetestFace = () => {
  177. if (props.examState == 42) {
  178. return false;
  179. }
  180. proxy?.$modal.confirm("确定重新识别吗?").then(() => {
  181. if (props.needStart == false) {
  182. //自动流程项目重新识别直接返回3
  183. closeOneTest(examId);
  184. } else {
  185. //手动流程项目重新识别43返回41,42返回3
  186. if (examState.value == 43) {
  187. cleanData();
  188. startFace(examId);
  189. } else {
  190. closeOneTest(examId);
  191. }
  192. }
  193. }).finally(() => {
  194. });
  195. };
  196. /**
  197. * 开始测试
  198. */
  199. const getStartOneTest = () => {
  200. if (examState.value != 43 || !faceCheckStu.value.student_id) {
  201. return false;
  202. }
  203. startOneTest(examId, () => { })
  204. };
  205. /**
  206. * 再测一次
  207. */
  208. const getAgain = async () => {
  209. //预存测试人员
  210. let student = JSON.parse(JSON.stringify(faceCheckStu.value));
  211. //测试中
  212. if (examState.value == 42) {
  213. await finishOneTest(examId);
  214. }
  215. //其他状态
  216. if (examState.value > 3) {
  217. await closeOneTest(examId);
  218. }
  219. //重新走一次流程
  220. await openOneTest(examId);
  221. await startFace(examId);
  222. await stopFace(examId);
  223. getFaceConfirmOnly(student);
  224. };
  225. /**
  226. * 选择学生
  227. */
  228. const getChooseStudent = () => {
  229. if (examState.value == 41) {
  230. chooseStudentRef.value.open();
  231. }
  232. if (examState.value == 43) {
  233. getRetestFace();
  234. }
  235. };
  236. /**
  237. * 返回被选学生
  238. */
  239. const returnStudent = (data: any) => {
  240. faceCheckStu.value = data;
  241. getStopFace();
  242. };
  243. /**
  244. * 清除历史记录
  245. */
  246. const cleanData = () => {
  247. faceCheckStu.value = {};
  248. currentResultObj.value = {};
  249. backReason.value = [];
  250. };
  251. /**
  252. * 自动初始化项目
  253. */
  254. const initProject = () => {
  255. //自动项目定时进入下一步
  256. if (props.needStart == false) {
  257. let time = 0;
  258. //控制新建测试的时间,第一次快,之后就慢
  259. if (!faceCheckStu.value.student_id) {
  260. time = 1000;
  261. } else {
  262. time = 6000;
  263. }
  264. setTimeout(() => {
  265. //再加一个判断以免和再测一次冲突
  266. if (examState.value == 3) {
  267. getOpenOneTestAndStartFace();
  268. }
  269. }, time)
  270. }
  271. };
  272. /**
  273. * 成绩
  274. */
  275. const getAchievement = (data: any) => {
  276. //console.log("成绩", data);
  277. let dic: any = dataDictionary;
  278. let type = project;
  279. let count =
  280. data?.[dic.typeResultKey[type]]?.toFixed(0);
  281. if (["trijump", "solidball", "shotput", "longjump"].includes(type)) {
  282. count =
  283. data?.[dic.typeResultKey[type]]?.toFixed(2);
  284. count = Math.round(count) / 100;
  285. }
  286. data.count = count || "0";
  287. data.score = data.score || "0";
  288. currentResultObj.value = data;
  289. //违规处理
  290. let arr = backReason.value;
  291. if (["situp", "pullup", "sidepullup", "jumprope", "jumpingjack", "jump", "longjump", "verticaljump"]
  292. .indexOf(type) > -1) {
  293. if (["pullup", "situp", "jumprope", "jumpingjack"].indexOf(type) > -1) {
  294. currentResultObj.value.back_num = data?.all_failed_num;
  295. }
  296. if (type === "sidepullup") {
  297. currentResultObj.value.back_num = data?.["0"]?.hip_failed_num;
  298. }
  299. if (['jump', 'longjump', 'verticaljump'].includes(type)) {
  300. if (data?.startline_check == 0) {
  301. let txt = "踩线违规";
  302. arr.push(txt)
  303. }
  304. if (data?.singleleg_jump_check == 0) {
  305. let txt = "单脚跳违规";
  306. arr.push(txt)
  307. }
  308. if (data?.outside_check == 0) {
  309. let txt = "跳出测试区违规";
  310. arr.push(txt)
  311. }
  312. }
  313. if (
  314. data?.elbow_check == false
  315. ) {
  316. let txt = "肘部违规";
  317. arr.push(txt);
  318. }
  319. if (
  320. ["situp", "pullup"].indexOf(type) > -1 &&
  321. data?.knee_check === false
  322. ) {
  323. let txt = "腿部违规";
  324. if (!arr.includes(txt)) {
  325. arr.push(txt);
  326. }
  327. }
  328. if (["situp"].indexOf(type) > -1 && data?.hand_check === false) {
  329. let txt = "手部违规";
  330. if (!arr.includes(txt)) {
  331. arr.push(txt);
  332. }
  333. }
  334. if (
  335. ["pullup"].indexOf(type) > -1 &&
  336. data?.["0"]?.elbow_check === false
  337. ) {
  338. let txt = "手部违规";
  339. if (!arr.includes(txt)) {
  340. arr.push(txt);
  341. }
  342. }
  343. if (["situp"].indexOf(type) > -1 && data?.["0"]?.back_check === false) {
  344. let txt = "背部违规";
  345. if (!arr.includes(txt)) {
  346. arr.push(txt);
  347. }
  348. }
  349. if (
  350. ["sidepullup", "situp"].indexOf(type) > -1 &&
  351. data?.["0"]?.hip_check === false
  352. ) {
  353. let txt = "臀部违规";
  354. if (!arr.includes(txt)) {
  355. arr.push(txt);
  356. }
  357. }
  358. }
  359. backReason.value = arr;
  360. if (data.isfinish) {
  361. // if (['jump'].includes(type) && backReason.value.length) {
  362. // speckText("请重新测试");
  363. // return false;
  364. // }
  365. // speckText(faceCheckStu?.value.name + "成绩为" + (chineseNumber(count) || 0) + unit.value + ",请下一位准备!" || "");
  366. }
  367. };
  368. /**
  369. * 状态抛给父组件
  370. */
  371. watch(() => examState.value, (newVal, oldVal) => {
  372. emit('returnData', { examState: examState.value, area: area });
  373. }, { deep: true });
  374. /**
  375. * 人脸信息抛给父组件
  376. */
  377. watch(() => faceCheckStu.value, (newVal, oldVal) => {
  378. emit('returnData', { faceCheckStu: faceCheckStu.value, area: area });
  379. }, { deep: true });
  380. onMounted(() => {
  381. let dic: any = dataDictionary;
  382. unit.value = dic.unit[project];
  383. })
  384. //暴露给父组件用
  385. defineExpose({
  386. getMessage,
  387. getOpenOneTestAndStartFace,
  388. getStopFace,
  389. getStartOneTest,
  390. getAgain,
  391. })
  392. </script>
  393. <style scoped lang="scss"></style>