|
@@ -1,4 +1,5 @@
|
|
|
import io from 'socket.io-client';
|
|
|
+import PubSub from 'pubsub-js';
|
|
|
import { ref, onMounted, onUnmounted, onBeforeUnmount } from 'vue';
|
|
|
|
|
|
export function useWs() {
|
|
@@ -119,6 +120,9 @@ export function useWs() {
|
|
|
|
|
|
socket.on('msg2frontend', (e: any) => {
|
|
|
callback(e);
|
|
|
+ if (['init_result', 'set_exam_state', 'disconnect_request'].includes(e.cmd)) {
|
|
|
+ console.log(`【接收:${e.cmd}】`, JSON.stringify(e));
|
|
|
+ }
|
|
|
//实时状态
|
|
|
if (e.cmd === 'exam_status') {
|
|
|
let index = examStateList.findIndex((item: any) => {
|
|
@@ -180,6 +184,7 @@ export function useWs() {
|
|
|
}
|
|
|
//状态变更
|
|
|
if (e.cmd === 'set_exam_state') {
|
|
|
+
|
|
|
// getClearExamStateTimer();
|
|
|
let index = examStateList.findIndex((item: any) => {
|
|
|
return item.examId == e.exam_id;
|
|
@@ -187,6 +192,7 @@ export function useWs() {
|
|
|
if (index != -1) {
|
|
|
examStateList[index].examState = e.data;
|
|
|
examStateList[index].wsStatus = e.status;
|
|
|
+ PubSub.publish(e.exam_id, e);
|
|
|
}
|
|
|
if (e.data == 3) {
|
|
|
//关闭遮罩层
|
|
@@ -311,14 +317,18 @@ export function useWs() {
|
|
|
exam_id: examId
|
|
|
}
|
|
|
});
|
|
|
- examStateList[index].timer1 = setInterval(() => {
|
|
|
- console.log(`【${examId}】1111111111111`)
|
|
|
- if (examStateList[index].examState != 3) {
|
|
|
- clearInterval(examStateList[index].timer1);
|
|
|
- // clearTimeout(timer2);
|
|
|
+ PubSub.subscribe(examId, (eventName:any,res:any)=>{
|
|
|
+ PubSub.unsubscribe(examId);
|
|
|
resolve({ data: examStateList[index].examState });
|
|
|
- }
|
|
|
- }, 250);
|
|
|
+ });
|
|
|
+ // examStateList[index].timer1 = setInterval(() => {
|
|
|
+ // console.log(`【${examId}】1111111111111`)
|
|
|
+ // if (examStateList[index].examState != 3) {
|
|
|
+ // clearInterval(examStateList[index].timer1);
|
|
|
+ // // clearTimeout(timer2);
|
|
|
+ // resolve({ data: examStateList[index].examState });
|
|
|
+ // }
|
|
|
+ // }, 250);
|
|
|
// let timer2 = setTimeout(() => {
|
|
|
// if (examStateList[index].examState == 3) {
|
|
|
// clearInterval(timer1);
|
|
@@ -344,14 +354,18 @@ export function useWs() {
|
|
|
exam_id: examId
|
|
|
}
|
|
|
});
|
|
|
- examStateList[index].timer2 = setInterval(() => {
|
|
|
- console.log(`【${examId}】2222222222222`)
|
|
|
- if (examStateList[index].examState != 40) {
|
|
|
- clearInterval(examStateList[index].timer2);
|
|
|
- // clearTimeout(timer2);
|
|
|
- resolve({ data: examStateList[index].examState });
|
|
|
- }
|
|
|
- }, 250);
|
|
|
+ PubSub.subscribe(examId, (eventName:any,res:any)=>{
|
|
|
+ PubSub.unsubscribe(examId);
|
|
|
+ resolve({ data: examStateList[index].examState });
|
|
|
+ });
|
|
|
+ // examStateList[index].timer2 = setInterval(() => {
|
|
|
+ // console.log(`【${examId}】2222222222222`)
|
|
|
+ // if (examStateList[index].examState != 40) {
|
|
|
+ // clearInterval(examStateList[index].timer2);
|
|
|
+ // // clearTimeout(timer2);
|
|
|
+ // resolve({ data: examStateList[index].examState });
|
|
|
+ // }
|
|
|
+ // }, 250);
|
|
|
// let timer2 = setTimeout(() => {
|
|
|
// if (examStateList[index].examState == 40) {
|
|
|
// clearInterval(timer1);
|
|
@@ -377,14 +391,18 @@ export function useWs() {
|
|
|
exam_id: examId
|
|
|
}
|
|
|
});
|
|
|
- examStateList[index].timer3 = setInterval(() => {
|
|
|
- console.log(`【${examId}】3333333333333`)
|
|
|
- if (examStateList[index].examState != 41) {
|
|
|
- clearInterval(examStateList[index].timer3);
|
|
|
- // clearTimeout(timer2);
|
|
|
- resolve({ data: examStateList[index].examState });
|
|
|
- }
|
|
|
- }, 250);
|
|
|
+ PubSub.subscribe(examId, (eventName:any,res:any)=>{
|
|
|
+ PubSub.unsubscribe(examId);
|
|
|
+ resolve({ data: examStateList[index].examState });
|
|
|
+ });
|
|
|
+ // examStateList[index].timer3 = setInterval(() => {
|
|
|
+ // console.log(`【${examId}】3333333333333`)
|
|
|
+ // if (examStateList[index].examState != 41) {
|
|
|
+ // clearInterval(examStateList[index].timer3);
|
|
|
+ // // clearTimeout(timer2);
|
|
|
+ // resolve({ data: examStateList[index].examState });
|
|
|
+ // }
|
|
|
+ // }, 250);
|
|
|
// let timer2 = setTimeout(() => {
|
|
|
// if (examStateList[index].examState == 41) {
|
|
|
// clearInterval(timer1);
|
|
@@ -462,14 +480,18 @@ export function useWs() {
|
|
|
exam_id: examId
|
|
|
}
|
|
|
});
|
|
|
- examStateList[index].timer4 = setInterval(() => {
|
|
|
- console.log(`【${examId}】4444444444444`)
|
|
|
- if (examStateList[index].examState != 42) {
|
|
|
- clearInterval(examStateList[index].timer4);
|
|
|
- // clearTimeout(timer2);
|
|
|
- resolve({ data: examStateList[index].examState });
|
|
|
- }
|
|
|
- }, 250);
|
|
|
+ PubSub.subscribe(examId, (eventName:any,res:any)=>{
|
|
|
+ PubSub.unsubscribe(examId);
|
|
|
+ resolve({ data: examStateList[index].examState });
|
|
|
+ });
|
|
|
+ // examStateList[index].timer4 = setInterval(() => {
|
|
|
+ // console.log(`【${examId}】4444444444444`)
|
|
|
+ // if (examStateList[index].examState != 42) {
|
|
|
+ // clearInterval(examStateList[index].timer4);
|
|
|
+ // // clearTimeout(timer2);
|
|
|
+ // resolve({ data: examStateList[index].examState });
|
|
|
+ // }
|
|
|
+ // }, 250);
|
|
|
// let timer2 = setTimeout(() => {
|
|
|
// if (examStateList[index].examState == 42) {
|
|
|
// clearInterval(timer1);
|
|
@@ -495,14 +517,18 @@ export function useWs() {
|
|
|
exam_id: examId
|
|
|
}
|
|
|
});
|
|
|
- examStateList[index].timer5 = setInterval(() => {
|
|
|
- console.log(`【${examId}】5555555555555`)
|
|
|
- if (examStateList[index].examState >= 3) {
|
|
|
- clearInterval(examStateList[index].timer5);
|
|
|
- // clearTimeout(timer2);
|
|
|
- resolve({ data: examStateList[index].examState });
|
|
|
- }
|
|
|
- }, 250);
|
|
|
+ PubSub.subscribe(examId, (eventName:any,res:any)=>{
|
|
|
+ PubSub.unsubscribe(examId);
|
|
|
+ resolve({ data: examStateList[index].examState });
|
|
|
+ });
|
|
|
+ // examStateList[index].timer5 = setInterval(() => {
|
|
|
+ // console.log(`【${examId}】5555555555555`)
|
|
|
+ // if (examStateList[index].examState >= 3) {
|
|
|
+ // clearInterval(examStateList[index].timer5);
|
|
|
+ // // clearTimeout(timer2);
|
|
|
+ // resolve({ data: examStateList[index].examState });
|
|
|
+ // }
|
|
|
+ // }, 250);
|
|
|
// let timer2 = setTimeout(() => {
|
|
|
// if (examStateList[index].examState != 3) {
|
|
|
// clearInterval(timer1);
|
|
@@ -598,6 +624,8 @@ export function useWs() {
|
|
|
loading?.close();
|
|
|
//清除计时器
|
|
|
getClearTimer();
|
|
|
+ //取消订阅
|
|
|
+ // PubSub.unsubscribe('setExamState');
|
|
|
//通知工作站关闭
|
|
|
if (testList.length > 1) {
|
|
|
//单WS多区
|