123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- <template>
- <div>
- <div v-if="needStart">{{
- countdownNumFormat
- }}</div>
- <div><el-avatar :src="faceCheckStu.logo_url || faceCheckStu.face_pic" @click="getChooseStudent" /></div>
- <div>{{ faceCheckStu.name }}</div>
- <div>成绩:{{ currentResultObj.count }} {{ unit }}</div>
- <div>得分:{{ currentResultObj.score }}</div>
- <div>
- <div v-if="['jumprope'].includes(parameter.project)">中断</div>
- <div v-else>犯规</div>
- <div>{{ currentResultObj.back_num }}</div>
- </div>
- <div v-if="backReason.length">
- <div>违规项</div>
- <div v-for="(item, index) in backReason" :key="index">{{ item }}</div>
- </div>
- <div>当前状态:({{ examState == 3 ? "初始化完成" : examState == 40 ? "创建测试" : examState == 41 ? "正在人脸识别"
- :
- examState ==
- 43 ? "停止人脸识别" : examState == 42 ? "正在测试" : "请初始化" }})</div>
- <div v-if="needStart">
- <div @click="getOpenOneTestAndStartFace" v-if="examState == 3 || examState == 40">1、开始识别</div>
- <div @click="getStopFace" v-if="examState == 41">2、停止人脸识别</div>
- <div @click="getStartOneTest" v-if="examState == 43">3、开始测试</div>
- </div>
- <div @click="getChooseStudent" v-if="examState == 41 || (examState == 43 && !faceCheckStu.student_id)">选择学生</div>
- <div @click="getRetestFace" v-if="examState == 43 || examState == 42">重新识别</div>
- <div @click="getAgain" v-if="examState == 42 || showTestAgain">再测一次</div>
- <div @click="confirmExit">退出</div>
- <FaceWindow ref="faceWindowRef" :faceCheckStu="faceCheckStu" />
- <ChooseStudent ref="chooseStudentRef" @returnData="returnStudent" />
- </div>
- </template>
- <script setup name="TrainTest" lang="ts">
- import { initSpeech, speckText, speckCancel, chineseNumber } from '@/utils/speech'
- import { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
- import dataDictionary from "@/utils/dataDictionary"
- const { proxy } = getCurrentInstance() as any;
- const router = useRouter();
- const route = useRoute();
- const faceWindowRef = ref();
- const chooseStudentRef = ref();
- const data = reactive<any>({
- timerManager: {},//计时器管理
- parameter: {},//参数
- time: {
- testTime: 60,//时长
- countdownNum: 0,//计时
- },
- userInfo: {},//用户信息
- examState: 0,//当前状态
- resultId: null,//测试ID
- currentResultObj: {},//成绩
- faceCheckStu: {},//人脸信息
- unit: "",//单位
- backReason: [],//犯规项
- needStart: false,//是否需要按钮
- showTestAgain: false,//再测一次按钮
- });
- const { timerManager, parameter, time, userInfo, examState, resultId, faceCheckStu, currentResultObj, unit, backReason, needStart, showTestAgain } = toRefs(data);
- /**
- * 接收消息
- */
- const getMessage = (e: any) => {
- //console.log("WS响应:", e)
- //实时状态
- if (e.cmd === 'exam_status') {
- examState.value = e.data;
- }
- //工作站状态
- if (e.cmd === 'init_result') {
- }
- //测试违规
- if (e.cmd === 'warning_result') {
- }
- //后端播报语音
- if (e.cmd === 'return_audio_msg') {
- }
- //错误提示
- if (e.cmd === 'info_result') {
- proxy?.$modal.msgError(e.data.message);
- }
- //错误提示
- if (e.cmd === 'error_result') {
- proxy?.$modal.msgError(e.data.message);
- }
- //测试中违规提示
- if (e.cmd === 'warning_notify') {
- }
- //断线状态
- if (e.cmd === 'disconnect_request') {
- if (e.data.message) {
- speckText(e.data.message);
- }
- getExit();
- }
- //状态变更
- if (e.cmd === 'set_exam_state') {
- examState.value = e.data;
- if (e.data === 3) {
- initProject();
- }
- if (e.data === 40) {
- cleanData();
- }
- if (e.data == 41) {
- getFaceWindow(true);
- }
- if (e.data == 43) {
- }
- if (e.data == 42) {
- }
- }
- //新建测试后返回信息,获取result_id
- if (e.cmd === 'open_one_test_ack') {
- resultId.value = e.data.result_id;
- }
- //人脸识别状态
- if (e.cmd === 'face_check_result') {
- faceCheckStu.value = e.data[0] || e.data;
- //工作站识别成功后停止识别并确定人脸
- getStopFace();
- }
- //测试结束结果
- if (e.cmd === 'oneresult') {
- if (e.data.length) {
- let data = e.data[0];
- getAchievement(data)
- }
- }
- //结果生成完成(视频图片)
- if (e.cmd === 'static_urls_finished') {
- }
- //选择学生或测试结束后返回的数据
- if (e.cmd === 'result_info') {
- }
- };
- /**
- * 开始识别
- */
- const getOpenOneTestAndStartFace = async () => {
- await openOneTest();
- await startFace();
- };
- /**
- * 停止人脸识别
- */
- const getStopFace = async () => {
- await stopFace();
- if (faceCheckStu.value.student_id) {
- getFaceConfirmOnly();
- }
- };
- /**
- * 确定人脸信息
- */
- const getFaceConfirmOnly = (data?: any) => {
- if (data) {
- faceCheckStu.value = data;
- }
- faceConfirmOnly({
- result_id: resultId.value,
- student_id: faceCheckStu.value.student_id,
- gender: faceCheckStu.value.gender
- }, () => {
- faceWindowRef.value?.close();
- //不需要按钮的自动进入下一步
- if (needStart.value == false) {
- getStartOneTest();
- }
- });
- };
- /**
- * 重新识别
- */
- const getRetestFace = () => {
- proxy?.$modal.confirm("确定重新识别吗?").then(() => {
- if (needStart.value == false) {
- //自动流程项目重新识别直接返回3
- closeOneTest();
- } else {
- //手动流程项目重新识别43返回41,42返回3
- if (examState.value == 43) {
- cleanData();
- startFace();
- } else {
- closeOneTest();
- }
- }
- }).finally(() => {
- });
- };
- /**
- * 开始测试
- */
- const getStartOneTest = () => {
- if (!faceCheckStu.value.student_id) {
- proxy?.$modal.msgError("请选择人员!");
- return false;
- }
- startOneTest(data == null, () => {
- //显示再测一次按钮
- showTestAgain.value = true;
- //停止播报;
- speckCancel()
- //计时项目才开
- if (needStart.value == true) {
- //时间为0的为正计时,大于0的为倒计时
- if (time.value.testTime == 0) {
- getCounting("+");
- } else {
- getCounting("-");
- }
- } else {
- speckText(faceCheckStu.value.name + ",请开始测试");
- }
- })
- };
- /**
- * 再测一次
- */
- const getAgain = async () => {
- //预存测试人员
- let student = JSON.parse(JSON.stringify(faceCheckStu.value));
- //测试中
- if (examState.value == 42) {
- await finishOneTest();
- }
- //重新走一次流程
- await openOneTest();
- await startFace();
- await stopFace();
- getFaceConfirmOnly(student);
- };
- /**
- * 确认退出
- */
- const confirmExit = () => {
- proxy?.$modal.confirm("确定退出吗?").then(() => {
- getExit();
- }).finally(() => {
- });
- };
- /**
- * 退出
- */
- const getExit = () => {
- getClearTimer();//清除计时器
- examEnds();//通知工作站关闭
- speckCancel()//停止播报;
- router.push({ path: '/' });//跳转
- };
- /**
- * 清空定时任务
- */
- const getClearTimer = (data?: any) => {
- if (data) {
- //清除指定
- clearInterval(timerManager.value[data])
- timerManager.value[data] = null;
- } else {
- //清除全部
- for (let key in timerManager.value) {
- if (timerManager.value.hasOwnProperty(key)) {
- clearInterval(timerManager.value[key])
- timerManager.value[key] = null;
- }
- }
- }
- };
- /**
- * 选择学生
- */
- const getChooseStudent = () => {
- if (examState.value == 41) {
- chooseStudentRef.value.open();
- }
- if (examState.value == 43) {
- getRetestFace();
- }
- };
- /**
- * 返回被选学生
- */
- const returnStudent = (data: any) => {
- faceCheckStu.value = data;
- faceWindowRef.value.open();
- getStopFace();
- };
- /**
- * 清除历史记录
- */
- const cleanData = () => {
- time.value.countdownNum = time.value.testTime;
- showTestAgain.value = false;
- faceCheckStu.value = {};
- currentResultObj.value = {};
- backReason.value = [];
- };
- /**
- * 自动初始化项目
- */
- const initProject = () => {
- //停止计时
- getClearTimer("countdownTimer");
- //自动项目定时进入下一步
- if (needStart.value == false) {
- let time = 0;
- //控制新建测试的时间,第一次快,之后就慢
- if (!faceCheckStu.value.student_id) {
- time = 1000;
- } else {
- time = 6000;
- }
- setTimeout(() => {
- //再加一个判断以免和再测一次冲突
- if (examState.value == 3) {
- getOpenOneTestAndStartFace();
- }
- }, time)
- }
- };
- /**
- * 时间转换
- */
- const countdownNumFormat = computed(() => {
- return proxy?.$utils.timeFormat(time.value.countdownNum);
- });
- /**
- * 倒计时
- */
- const getCounting = (type: string) => {
- timerManager.value.countdownTimer = setInterval(() => {
- //正计时
- if (type == "+") {
- time.value.countdownNum++;
- }
- //倒计时
- if (type == "-") {
- if (time.value.countdownNum <= 0) {
- getClearTimer("countdownTimer");
- } else {
- time.value.countdownNum--;
- }
- }
- }, 1000);
- };
- /**
- * 人脸窗口
- */
- const getFaceWindow = (data: boolean) => {
- let txt = parameter.value.gesture ? "请举手看摄像头人脸识别" : "请看摄像头进行人脸识别";
- speckText(txt);
- //data=true为弹出框,data=false为不要弹出框
- if (data) {
- faceWindowRef.value.open();
- //然后定时自动关闭
- setTimeout(() => {
- if (examState.value == 41 && faceWindowRef.value.faceState == true) {
- faceWindowRef.value?.close();
- }
- }, 3000)
- }
- //定时检查如果一直停留在人脸识别就提示
- timerManager.value.face = setInterval(() => {
- getClearTimer("face");
- if (examState.value == 41) {
- getFaceWindow(false);
- }
- }, 15000)
- };
- /**
- * 成绩
- */
- const getAchievement = (data: any) => {
- //console.log("成绩", data);
- let dic: any = dataDictionary;
- let type = parameter.value.project;
- let count =
- data?.[dic.typeResultKey[type]]?.toFixed(0);
- if (["trijump", "solidball", "shotput", "longjump"].includes(type)) {
- count =
- data?.[dic.typeResultKey[type]]?.toFixed(2);
- count = Math.round(count) / 100;
- }
- data.count = count || "0";
- data.score = data.score || "0";
- currentResultObj.value = data;
- //违规处理
- let arr = backReason.value;
- if (["situp", "pullup", "sidepullup", "jumprope", "jumpingjack", "jump", "longjump", "verticaljump"]
- .indexOf(type) > -1) {
- if (["pullup", "situp", "jumprope", "jumpingjack"].indexOf(type) > -1) {
- currentResultObj.value.back_num = data?.all_failed_num;
- }
- if (type === "sidepullup") {
- currentResultObj.value.back_num = data?.["0"]?.hip_failed_num;
- }
- if (['jump', 'longjump', 'verticaljump'].includes(type)) {
- if (data?.startline_check == 0) {
- let txt = "踩线违规";
- arr.push(txt)
- }
- if (data?.singleleg_jump_check == 0) {
- let txt = "单脚跳违规";
- arr.push(txt)
- }
- if (data?.outside_check == 0) {
- let txt = "跳出测试区违规";
- arr.push(txt)
- }
- }
- if (
- data?.elbow_check == false
- ) {
- let txt = "肘部违规";
- arr.push(txt);
- }
- if (
- ["situp", "pullup"].indexOf(type) > -1 &&
- data?.knee_check === false
- ) {
- let txt = "腿部违规";
- if (!arr.includes(txt)) {
- arr.push(txt);
- }
- }
- if (["situp"].indexOf(type) > -1 && data?.hand_check === false) {
- let txt = "手部违规";
- if (!arr.includes(txt)) {
- arr.push(txt);
- }
- }
- if (
- ["pullup"].indexOf(type) > -1 &&
- data?.["0"]?.elbow_check === false
- ) {
- let txt = "手部违规";
- if (!arr.includes(txt)) {
- arr.push(txt);
- }
- }
- if (["situp"].indexOf(type) > -1 && data?.["0"]?.back_check === false) {
- let txt = "背部违规";
- if (!arr.includes(txt)) {
- arr.push(txt);
- }
- }
- if (
- ["sidepullup", "situp"].indexOf(type) > -1 &&
- data?.["0"]?.hip_check === false
- ) {
- let txt = "臀部违规";
- if (!arr.includes(txt)) {
- arr.push(txt);
- }
- }
- }
- backReason.value = arr;
- if (data.isfinish) {
- if (['jump'].includes(type) && backReason.value.length) {
- speckText("请重新测试");
- return false;
- }
- speckText(faceCheckStu?.value.name + "成绩为" + (chineseNumber(count) || 0) + unit.value + ",请下一位准备!" || "");
- }
- };
- onMounted(() => {
- parameter.value = route.query;
- let project = parameter.value.project;
- let area = parameter.value.area;
- parameter.value.examId = `${project}_${area}`; //项目+区
- if (parameter.value.time) {
- time.value.testTime = parameter.value.time
- }
- time.value.countdownNum = time.value.testTime;
- let myInfo: any = localStorage.getItem("userInfo");
- userInfo.value = JSON.parse(myInfo);
- let dic: any = dataDictionary;
- unit.value = dic.unit[project];
- if (parameter.value.gesture == 'true') {
- parameter.value.gesture = true
- } else {
- parameter.value.gesture = false
- }
- //需要开始按钮的项目
- if (["jumprope", "skiprope", "jumpingjack", "situp"].includes(project)) {
- needStart.value = true;
- }
- //加载WS
- initWs({ parameter: parameter.value, testTime: time.value.testTime }, (data: any) => {
- getMessage(data);
- });
- initSpeech();
- })
- onUnmounted(() => {
- getExit();
- })
- </script>
- <style scoped lang="scss"></style>
|