refactor: 更新类型定义,优化代码可读性

This commit is contained in:
wangzhongjie 2025-04-11 11:01:48 +08:00
commit a75bba1761
5 changed files with 76 additions and 65 deletions

View File

@ -112,7 +112,7 @@ export interface CarInfoType {
examinationRoomId?: string;
plateNo?: string;
carNo?: string;
examSubject: string;
examSubject?: string;
isNeedCheck?: string;
udpAddress?: string
messagePort?: string

View File

@ -120,7 +120,6 @@ struct Index {
@State isDeductedPopShow: boolean = false
@State isAmplifyPopShow: boolean = false
@State amplifiedImgIndex: number = 0
judge: Judge
//行驶距离
@State jl: number = 0
//应考里程
@ -162,6 +161,7 @@ struct Index {
@State isErrorMsgEnd: boolean = false
@State disConnectErrorOpen: boolean = false
public context = getContext(this) as common.UIAbilityContext;
private judge: Judge = new Judge(this)
async aboutToDisappear() {
clearInterval(this.mileageTimer)
@ -185,8 +185,7 @@ struct Index {
//断点续考
await this.goDdxkItems()
//初始化评判
const judge = await this.initJudge();
this.judge = judge
await this.initJudge();
}
//初始化相关数据库表
@ -522,16 +521,12 @@ struct Index {
// 评判相关初始化
async initJudge() {
const JUDGEUI: JudgeUI = this;
const judge = new Judge(JUDGEUI);
// await judge.init<typeof Index>()
await judge.onJudgeFn(async (judgeData: JudgeCallBacData) => {
// const { xmmcStr, carztStr, kfArr } = judgeData;
;
await this.judge.onJudgeFn(async (judgeData: JudgeCallBacData) => {
this.xmmcStr = judgeData.xmmcStr || "";
this.carztStr = judgeData.carztStr || "";
this.kfArr = judgeData.kfArr || [];
});
return judge
}
// 断点续考判断

View File

@ -339,7 +339,7 @@ export default struct DeductedPopup {
}
if (mark.itemno == 1 && Number(mark.markserial) > 100 && Number(mark.markserial) < 200) {
this.markRuleListObj[`${mark.itemno}_${mark.markserial}`] = {
Reflect.set(this.markRuleListObj, `${mark.itemno}_${mark.markserial}`, {
itemno: tempObj.itemno,
markcatalog: tempObj.markcatalog,
markshow: tempObj.markshow,
@ -350,11 +350,9 @@ export default struct DeductedPopup {
OnlyOneKind: tempObj.OnlyOneKind,
NoCancelId: tempObj.NoCancelId,
GPS_SID: tempObj.GPS_SID,
};
})
this.universalMarkRules.push(tempObj)
}
})
}

View File

@ -41,6 +41,7 @@ import {
BaseInfoType,
CarInfoType,
CDSBInfo,
CDSBInfos,
DrvexamType,
ExaminerInfoType,
ItemInfo,
@ -83,7 +84,7 @@ type GetDqxmStr = (xmdm: number) => string
type TJudgeBeginObj = JudgeBeginObj
export default class Judge {
public plcStr!: string
public plcStr: string = ""
public judgeUI: JudgeUI
//获取科目三的评判初始化配置
getKm3JudgeInitConfig: GetKm3JudgeInitConfig = async () => {
@ -92,8 +93,8 @@ export default class Judge {
map_point_item: this.judgeUI.mapPointItemArr,
//科目三暂时为空
iteminfo: [],
roads: this.getModelData('km3/Roads.txt'),
sharps: this.getModelData('km3/Sharps.txt')
roads: this.getModelData('km3/Roads.txt') || "",
sharps: this.getModelData('km3/Sharps.txt') || ""
}
}
private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
@ -785,7 +786,7 @@ export default class Judge {
const kssycs = judgeUI.kssycs
const isDdxk = judgeUI.isDdxk
const ddxkTime = judgeUI.ddxkTime
const projectsCenterObj = judgeUI.projectsCenterObj
const projectsCenterObj: object = judgeUI.projectsCenterObj
const ddxkKsxmArr = judgeUI.ddxkKsxmArr
const ddxkKfArr = judgeUI.ddxkKfArr
const passingScore = judgeUI.passingScore
@ -893,9 +894,9 @@ export default class Judge {
this.rmndg = 1
}
this.judgeUI.currentXmdm = xmdm;
const xmmcStr = project?.name || "";
const xmmcCode = project?.projectCodeCenter || "";
const xmmcSingleCode = project?.projectCode || "";
const xmmcStr = project.name || "";
const xmmcCode = project.projectCodeCenter || "";
const xmmcSingleCode = project.projectCode || "";
const kmItem: KmItem = Reflect.get(this.kmItems, xmmcCode)
kmItem.status = 2;
this.xmmcStr = xmmcStr;
@ -1018,9 +1019,9 @@ export default class Judge {
const xmxh = precast.xmxh
const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, xmdm)
const projectCode = project.projectCode
const xmmcCode = judgeUI.projectsObj[xmdm].projectCodeCenter;
const xmmcSingleCode = judgeUI.projectsObj[xmdm].projectCode;
// const projectCode = project.projectCode
const xmmcCode: string = judgeUI.projectsObj[xmdm].projectCodeCenter;
const xmmcSingleCode: string = judgeUI.projectsObj[xmdm].projectCode;
const kmItem: KmItem = Reflect.get(this.kmItems, xmmcCode)
const xmmcStr = project?.name || "";
kmItem.status = 2;
@ -1050,7 +1051,7 @@ export default class Judge {
this.goVoiceAnnounce(event, xmdm, this.kfArr || [], xmjs, ksjs, xmxh)
//更新UI
if (event == 1 || event == 2 || event == 3 || event == 6) {
const copyProjectsObj = this.judgeUI.projectsObj;
const copyProjectsObj: object = this.judgeUI.projectsObj;
judgeUI.projectsObj = deepClone(copyProjectsObj);
}
}
@ -1071,8 +1072,8 @@ export default class Judge {
const lane = this.lane
const closeAllFiles = this.closeAllFiles
const projectsObj = judgeUI.projectsObj
const judgeConfigObj = judgeUI.judgeConfigObj
const projectsObj: object = judgeUI.projectsObj
const judgeConfigObj: object = judgeUI.judgeConfigObj
const examSubject = judgeUI.examSubject
const jl = judgeUI.jl
const isAllProjectsEnd = judgeUI.isAllProjectsEnd
@ -1163,7 +1164,8 @@ export default class Judge {
const currentKf = kf[kfLen -1];
if (JudgeConfig.kfVoiceOpen || (examSubject == '2' && judgeConfigObj['618'] == '1') ||
(examSubject == '3' && judgeConfigObj['418'] == '1')) {
avPlayer?.playAudio([`voice/${currentKf.markcatalog}.mp3`, `voice/mark_${Math.abs(currentKf?.score||0)}.mp3`])
avPlayer?.playAudio([`voice/${currentKf.markcatalog}.mp3`,
`voice/mark_${Math.abs(currentKf?.score || 0)}.mp3`])
}
const isStart = await checkProjectIsStart(Number(currentKf.xmdm), 2, currentKf);
if (isStart) {
@ -1228,10 +1230,10 @@ export default class Judge {
const idCard = judgeUI.idCard
const serialNumber = judgeUI.serialNumber
const ksdd = judgeUI.ksdd
const projectsObj = judgeUI.projectsObj
const projectsObj: object = judgeUI.projectsObj
const time = GetCurrentTime();
const project = this.getProjectInfo(ksxm);
const project: ProjectInfo = this.getProjectInfo(ksxm);
//科目三夜间行驶.模拟灯光、上车准备出现通用评判ksxm为当前进行的项目
const checkProjects = ['17', '41', '1'];
//获取正在进行的项目
@ -1247,11 +1249,25 @@ export default class Judge {
}
})
const ksxmD: string = project == undefined
? (commonKsxm
? (project?.projectCodeCenter||"")
: (examSubject == '3' ? '30000' : (xmmcEndCode == undefined ? '10000' : xmmcEndCode)))
: project.projectCodeCenter
// const ksxmD: string = !project
// ? (commonKsxm
// ? (project?.projectCodeCenter!)
// : (examSubject == '3' ? '30000' : (xmmcEndCode == undefined ? '10000' : xmmcEndCode)))
// : project.projectCodeCenter
let ksxmD: string;
if (!project) {
if (commonKsxm) {
ksxmD = Reflect.get(projectsObj, commonKsxm).projectCodeCenter;
} else {
if (examSubject == '3') {
ksxmD = '30000';
} else {
ksxmD = (xmmcEndCode == undefined ? '10000' : xmmcEndCode);
}
}
} else {
ksxmD = project?.projectCodeCenter || "";
}
const drvexam: DrvexamType = {
lsh,
kskm: examSubject,
@ -1682,8 +1698,8 @@ export default class Judge {
//获取场地序号
getSbxh: GetgSbbm = (ksxm, xmxh) => {
const judgeUI = this.judgeUI;
const projectsObj = judgeUI.projectsObj;
const cdsbInfoObj = judgeUI.cdsbInfoObj;
const projectsObj: object = judgeUI.projectsObj;
const cdsbInfoObj: CDSBInfos = judgeUI.cdsbInfoObj!;
const project: ProjectInfo = Reflect.get(projectsObj, ksxm);
if (judgeUI.examSubject == '3') {
return '0000000000'
@ -1693,24 +1709,24 @@ export default class Judge {
}
const projectKey = `${ksxm}_${xmxh}`;
// const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj, projectKey) || {}
const currentCdsb: CDSBInfo = (Reflect.get(cdsbInfoObj, projectKey) ?? {}) as CDSBInfo;
const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj, projectKey) ?? {} as CDSBInfo;
const sbxh: string = currentCdsb.sbbh || '0000000000'
return sbxh
}
getSbbm: GetgSbbm = (ksxm, xmxh) => {
const judgeUI = this.judgeUI;
const cdsbInfoObj = judgeUI.cdsbInfoObj;
const projectsObj = judgeUI.projectsObj;
const projectsObj: object = judgeUI.projectsObj;
const project: ProjectInfo = Reflect.get(projectsObj, ksxm);
//科目三不需要
if (judgeUI.examSubject == '3') {
return undefined
return ""
}
if (project === undefined) {
return '00000000'
}
const projectKey = `${ksxm}_${xmxh}`;
const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj, projectKey) || {}
const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj!, projectKey) || {}
const sbxh: string = currentCdsb.sbbm || '00000000'
return sbxh
}
@ -1757,7 +1773,7 @@ export default class Judge {
}
// 统计必考项目、所有项目、已考数量
setCountItems = async () => {
const projectsObj = this.judgeUI.projectsObj;
const projectsObj: object = this.judgeUI.projectsObj;
//必考项目数量 必考项目已考数量
let projectNum = 0, endProjectsNum = 0;
// 所有考试项目数量 项目已考项目数量
@ -1898,12 +1914,14 @@ export default class Judge {
// 3.开始考试
if (isTrajectoryOpen) {
beginExamInfo = JSON.parse(strArr[1])
beginExamInfo.replay = 1
beginExamInfo && (beginExamInfo.replay = 1)
} else {
beginExamInfo = await getJudgeBeginData()
}
await fileLog?.setExamJudgeData(JSON.stringify(beginExamInfo))
if (beginExamInfo) {
await examJudgeBeginExam(beginExamInfo);
}
console.info(judgeTag, '6.开始考试注册完成')
avPlayer?.playAudio([judgeUI.singlePlay ? 'voice/ksks.wav' : 'voice/监管成功.mp3'])

View File

@ -16,7 +16,7 @@ export function chunkArr<T>(arr: T[], size: number): T[][] {
}
//对象深拷贝
export function deepClone<T>(target: T): T {
export function deepClone<T extends Object>(target: T): T {
// 如果是对象且不是原始值null
if (typeof target === 'object' && target !== null) {
// 创建容器