123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- <template>
- <div class="li">
- <div class="userInfo" @click="getChooseStudent">
- <div class="userInfo-center">
- <Transition :enter-active-class="proxy?.animate.dialog.enter">
- <div class="pic" :class="{ 'pic2': faceCheckStu.student_id }" v-if="faceCheckStu.student_id"> <img
- :src="faceCheckStu.face_pic || faceCheckStu.logo_url" /></div>
- <div class="pic" v-else>
- <div class="area">{{ area }}</div>
- <img src="@/assets/images/test/profilePicture2.png" />
- </div>
- </Transition>
- <div class="name" :class="{ 'name2': faceCheckStu.student_id }">
- {{ faceCheckStu.student_id ? faceCheckStu.name : area ? "虚位以待" : "未启用" }}
- </div>
- </div>
- </div>
- <div class="score">
- {{ currentResultObj.count
- || 0 }}
- </div>
- <!-- <div>当前状态:({{ examState == 3 ? "初始化完成" : examState == 40 ? "创建测试" : examState == 41 ? "正在人脸识别" :examState == 43 ? "停止人脸识别" : examState == 42 ? "正在测试" : "离线状态" }})</div> -->
- <ChooseStudent ref="chooseStudentRef" @returnData="returnStudent" />
- </div>
- </template>
- <script setup lang="ts">
- import { initSpeech, speckText, speckCancel, chineseNumber } from '@/utils/speech'
- import { openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
- import dataDictionary from "@/utils/dataDictionary"
- const route = useRoute();
- const { proxy } = getCurrentInstance() as any;
- const chooseStudentRef = ref();
- const emit = defineEmits(['returnData']);
- //父值
- const props = defineProps({
- area: {
- type: String,
- default: ""
- },
- examState: {
- type: Number,
- default: null
- },
- needStart: {
- type: Boolean,
- default: false
- },
- styleType: {
- type: Number,
- default: null
- },
- });
- let project: any = route.query.project;
- let area: any = props.area;
- let examId: string = `${project}_${area}`; //项目+区
- const data = reactive<any>({
- examState: 0,//当前状态
- resultId: null,//测试ID
- currentResultObj: {},//成绩
- faceCheckStu: {},//人脸信息
- unit: "",//单位
- backReason: [],//犯规项
- });
- const { examState, resultId, faceCheckStu, currentResultObj, unit, backReason } = 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(`【${area}】${e.data.message}`);
- }
- //错误提示
- if (e.cmd === 'error_result') {
- proxy?.$modal.msgError(`【${area}】${e.data.message}`);
- }
- //测试中违规提示
- if (e.cmd === 'warning_notify') {
- }
- //断线状态
- if (e.cmd === 'disconnect_request') {
- examState.value = 0;
- emit('returnData', { examState: examState.value, area: area });
- let message = e.data.message;
- if (message) {
- proxy?.$modal.msgError(`【${area}】${message}`);
- //speckText(e.data.message);
- }
- }
- //状态变更
- if (e.cmd === 'set_exam_state') {
- examState.value = e.data;
- if (e.data === 3) {
- initProject();
- }
- if (e.data === 40) {
- cleanData();
- }
- if (e.data == 41) {
- }
- 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') {
- let myData = e.data[0] || e.data;
- returnStudent(myData);
- }
- //测试结束结果
- 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 () => {
- console.log("examId", examId)
- if (examState.value > 3) {
- await closeOneTest(examId);
- }
- await openOneTest(examId);
- await startFace(examId);
- };
- /**
- * 停止人脸识别
- */
- const getStopFace = async () => {
- if (examState.value != 41) {
- return false;
- }
- await stopFace(examId);
- if (faceCheckStu.value.student_id) {
- getFaceConfirmOnly();
- }
- };
- /**
- * 确定人脸信息
- */
- const getFaceConfirmOnly = (data?: any) => {
- if (data) {
- faceCheckStu.value = data;
- }
- faceConfirmOnly({
- exam_id: examId,
- // result_id: resultId.value,
- student_id: faceCheckStu.value.student_id,
- gender: faceCheckStu.value.gender
- }, () => {
- });
- };
- /**
- * 重新识别
- */
- const getRetestFace = () => {
- if (props.examState == 42) {
- return false;
- }
- proxy?.$modal.confirm("确定重新识别吗?").then(() => {
- if (props.needStart == false) {
- //自动流程项目重新识别直接返回3
- closeOneTest(examId);
- } else {
- //手动流程项目重新识别43返回41,42返回3
- if (examState.value == 43) {
- cleanData();
- startFace(examId);
- } else {
- closeOneTest(examId);
- }
- }
- }).finally(() => {
- });
- };
- /**
- * 开始测试
- */
- const getStartOneTest = () => {
- if (examState.value != 43 || !faceCheckStu.value.student_id) {
- return false;
- }
- startOneTest(examId, () => { })
- };
- /**
- * 再测一次
- */
- const getAgain = async () => {
- //预存测试人员
- let student = JSON.parse(JSON.stringify(faceCheckStu.value));
- //测试中
- if (examState.value == 42) {
- await finishOneTest(examId);
- }
- //其他状态
- if (examState.value > 3) {
- await closeOneTest(examId);
- }
- //重新走一次流程
- await openOneTest(examId);
- await startFace(examId);
- await stopFace(examId);
- getFaceConfirmOnly(student);
- };
- /**
- * 选择学生
- */
- const getChooseStudent = () => {
- if (!area) {
- proxy?.$modal.msgWarning(`未启用`);
- return false;
- }
- console.log("examState.value", examState.value)
- if (examState.value == 0) {
- proxy?.$modal.msgWarning(`当前状态:${examState.value}`);
- return false;
- }
- if (examState.value == 3) {
- if (!props.needStart) {
- proxy?.$modal.msgWarning(`当前状态:${examState.value}`);
- }
- if (props.needStart) {
- proxy?.$modal.msgWarning(`请点击开始识别按钮`);
- }
- return false;
- }
- if (examState.value == 41) {
- chooseStudentRef.value.open();
- }
- if (examState.value == 43) {
- getRetestFace();
- }
- if (props.examState == 42) {
- proxy?.$modal.msgWarning(`【${area}】正在测试请结束后再操作`);
- return false;
- }
- };
- /**
- * 返回被选学生
- */
- const returnStudent = (data: any) => {
- faceCheckStu.value = data;
- getStopFace();
- };
- /**
- * 清除历史记录
- */
- const cleanData = () => {
- faceCheckStu.value = {};
- currentResultObj.value = {};
- backReason.value = [];
- };
- /**
- * 自动初始化项目
- */
- const initProject = () => {
- if (!area) {
- return false;
- }
- //自动项目定时进入下一步
- if (props.needStart == false) {
- let time = 0;
- //控制新建测试的时间,第一次快,之后就慢
- if (!faceCheckStu.value.student_id) {
- time = 500;
- } else {
- time = 7000;
- }
- setTimeout(() => {
- //再加一个判断以免和再测一次冲突
- if (examState.value == 3 || examState.value == 43) {
- console.log("执行了执行了执行了执行了执行了")
- getOpenOneTestAndStartFace();
- }
- }, time)
- }
- };
- /**
- * 成绩
- */
- const getAchievement = (data: any) => {
- //console.log("成绩", data);
- let dic: any = dataDictionary;
- let type = 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 + ",请下一位准备!" || "");
- }
- };
- /**
- * 状态抛给父组件
- */
- watch(() => examState.value, (newVal, oldVal) => {
- console.log(area, examState.value)
- emit('returnData', { examState: examState.value, area: area });
- }, { deep: true });
- /**
- * 人脸信息抛给父组件
- */
- watch(() => faceCheckStu.value, (newVal, oldVal) => {
- emit('returnData', { faceCheckStu: faceCheckStu.value, area: area });
- }, { deep: true });
- /**
- * 如果总流程结束了个别区仍然在43就重新执行一次,用于没有开的区自动复位
- */
- watch(() => props.examState, (newVal, oldVal) => {
- if (newVal == 3 && examState.value == 43) {
- initProject();
- }
- //父状态已经进入41了就不要等子组件40清空数据了
- if (newVal == 41) {
- cleanData();
- }
- }, { deep: true });
- onMounted(() => {
- let dic: any = dataDictionary;
- unit.value = dic.unit[project];
- })
- //暴露给父组件用
- defineExpose({
- getMessage,
- getOpenOneTestAndStartFace,
- getStopFace,
- getStartOneTest,
- getAgain,
- })
- </script>
- <style scoped lang="scss"></style>
|