130 lines
2.9 KiB
Plaintext
130 lines
2.9 KiB
Plaintext
|
|
import emitter from '@ohos.events.emitter';
|
||
|
|
|
||
|
|
export const EVENTID = {
|
||
|
|
//远程扣分处理
|
||
|
|
kfEventId: 35,
|
||
|
|
//远程扣分查询
|
||
|
|
kfAskEventId: 36,
|
||
|
|
//远程扣分确认
|
||
|
|
kfConfirmEventId: 37,
|
||
|
|
|
||
|
|
//远程开始考试
|
||
|
|
beginExamEventId: 11,
|
||
|
|
//远程结束考试
|
||
|
|
endExamEventId: 12
|
||
|
|
}
|
||
|
|
|
||
|
|
export default class JudgeEmitter {
|
||
|
|
//监听开始考试
|
||
|
|
public onBeginExam = async (callBack?: Function) => {
|
||
|
|
console.info('surenjun', '注册远程开始考试事件')
|
||
|
|
this.beginExamCallBack = callBack
|
||
|
|
}
|
||
|
|
//监听结束考试
|
||
|
|
public onEndExam = async (callBack?: Function) => {
|
||
|
|
console.info('surenjun', '注册远程结束考试事件')
|
||
|
|
this.endExamCallBack = callBack
|
||
|
|
}
|
||
|
|
//监听扣分处理
|
||
|
|
public onKfExam = async (callBack?: Function) => {
|
||
|
|
console.info('surenjun', '注册远程扣分考试事件')
|
||
|
|
this.kfContent = callBack
|
||
|
|
}
|
||
|
|
//开始考试
|
||
|
|
public sendBeginExam = async (content: string) => {
|
||
|
|
emitter.emit({
|
||
|
|
eventId: EVENTID.beginExamEventId
|
||
|
|
}, {
|
||
|
|
data: {
|
||
|
|
directives: content
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
//结束考试
|
||
|
|
public sendEndExam = async (content: string) => {
|
||
|
|
emitter.emit({
|
||
|
|
eventId: EVENTID.endExamEventId
|
||
|
|
}, {
|
||
|
|
data: {
|
||
|
|
directives: content
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
private directives: string
|
||
|
|
//扣分
|
||
|
|
public sendKfContent = async (kfxh: string) => {
|
||
|
|
const directives = this.directives
|
||
|
|
console.info('surenjun', `udpEvent收到扣分事件。kfxh=>${kfxh};directives=>${directives}`)
|
||
|
|
emitter.emit({
|
||
|
|
eventId: EVENTID.kfEventId
|
||
|
|
}, {
|
||
|
|
data: {
|
||
|
|
directives,
|
||
|
|
kfxh
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
//监听扣分指令
|
||
|
|
public sendOnKf = async (directives: string) => {
|
||
|
|
//TODO 临时存储指令编号
|
||
|
|
this.directives = directives
|
||
|
|
globalThis.judgeUdp.askKf(directives)
|
||
|
|
}
|
||
|
|
// 获取扣分项目编号
|
||
|
|
public onConfirmKf = async (kfxh: string) => {
|
||
|
|
const directives = this.directives;
|
||
|
|
emitter.emit({
|
||
|
|
eventId: EVENTID.kfConfirmEventId
|
||
|
|
}, {
|
||
|
|
data: {
|
||
|
|
kfxh, directives
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
constructor() {
|
||
|
|
this.init()
|
||
|
|
}
|
||
|
|
|
||
|
|
init = async () => {
|
||
|
|
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)
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private beginExamCallBack: Function = () => {
|
||
|
|
}
|
||
|
|
|
||
|
|
private endExamCallBack: Function = () => {
|
||
|
|
}
|
||
|
|
|
||
|
|
private confirmExamCallBack: Function = () => {
|
||
|
|
}
|
||
|
|
|
||
|
|
private kfContent: Function = () => {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|