125 lines
2.8 KiB
Plaintext
Raw Normal View History

import emitter from '@ohos.events.emitter';
2025-04-09 10:46:50 +08:00
import { JudgeUdpBusinessInstance } from './JudgeUdpBusiness';
2025-04-07 14:05:15 +08:00
enum EventId {
//远程扣分处理
2025-04-07 14:05:15 +08:00
kfEventId = 35,
//远程扣分查询
2025-04-07 14:05:15 +08:00
kfAskEventId = 36,
//远程扣分确认
2025-04-07 14:05:15 +08:00
kfConfirmEventId = 37,
//远程开始考试
2025-04-07 14:05:15 +08:00
beginExamEventId = 11,
//远程结束考试
2025-04-07 14:05:15 +08:00
endExamEventId = 12
}
2025-04-09 09:28:18 +08:00
class JudgeEmitter {
2025-04-07 14:05:15 +08:00
private beginExamCallBack: Function = () => {
}
private endExamCallBack: Function = () => {
}
private kfContent: Function = () => {
}
private directives: string
//监听开始考试
2025-04-07 14:05:15 +08:00
public onBeginExam(callBack?: Function) {
console.info('surenjun', '注册远程开始考试事件')
this.beginExamCallBack = callBack
}
2025-04-07 14:05:15 +08:00
//监听结束考试
2025-04-07 14:05:15 +08:00
public onEndExam(callBack?: Function) {
console.info('surenjun', '注册远程结束考试事件')
this.endExamCallBack = callBack
}
2025-04-07 14:05:15 +08:00
//监听扣分处理
2025-04-07 14:05:15 +08:00
public onKfExam(callBack?: Function) {
console.info('surenjun', '注册远程扣分考试事件')
this.kfContent = callBack
}
2025-04-07 14:05:15 +08:00
//开始考试
2025-04-07 14:05:15 +08:00
public sendBeginExam(content: string) {
emitter.emit({
2025-04-07 14:05:15 +08:00
eventId: EventId.beginExamEventId
}, {
data: {
directives: content
}
});
}
2025-04-07 14:05:15 +08:00
//结束考试
2025-04-07 14:05:15 +08:00
public sendEndExam(content: string) {
emitter.emit({
2025-04-07 14:05:15 +08:00
eventId: EventId.endExamEventId
}, {
data: {
directives: content
}
});
}
2025-04-07 14:05:15 +08:00
//扣分
2025-04-07 14:05:15 +08:00
public sendKfContent(kfxh: string) {
const directives = this.directives
console.info('surenjun', `udpEvent收到扣分事件。kfxh=>${kfxh};directives=>${directives}`)
emitter.emit({
2025-04-07 14:05:15 +08:00
eventId: EventId.kfEventId
}, {
data: {
directives,
kfxh
}
});
}
2025-04-07 14:05:15 +08:00
//监听扣分指令
2025-04-07 14:05:15 +08:00
public sendOnKf(directives: string) {
this.directives = directives
2025-04-09 10:46:50 +08:00
JudgeUdpBusinessInstance.askKf(Number(directives))
}
2025-04-07 14:05:15 +08:00
// 获取扣分项目编号
2025-04-07 14:05:15 +08:00
public onConfirmKf(kfxh: string) {
const directives = this.directives;
emitter.emit({
2025-04-07 14:05:15 +08:00
eventId: EventId.kfConfirmEventId
}, {
data: {
kfxh, directives
}
});
}
2025-04-07 14:05:15 +08:00
public init() {
console.info('surenjun', '开始注册udp事件')
2025-04-07 14:05:15 +08:00
emitter.off(EventId.beginExamEventId)
emitter.off(EventId.endExamEventId)
emitter.off(EventId.kfConfirmEventId)
emitter.off(EventId.kfEventId)
emitter.on({
2025-04-07 14:05:15 +08:00
eventId: EventId.beginExamEventId
}, () => {
this?.beginExamCallBack()
});
emitter.on({
2025-04-07 14:05:15 +08:00
eventId: EventId.endExamEventId
}, () => {
this?.endExamCallBack()
});
emitter.on({
2025-04-07 14:05:15 +08:00
eventId: EventId.kfEventId
}, (data) => {
2025-04-07 14:05:15 +08:00
console.info('surenjun EventId.kfEvent' + JSON.stringify(data))
this?.kfContent(data)
});
}
}
2025-04-09 09:28:18 +08:00
export const JudgeEmitterInstance = new JudgeEmitter()