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