refactor: 更新类型定义,优化代码可读性
This commit is contained in:
		
						commit
						a75bba1761
					
				| @ -112,7 +112,7 @@ export interface CarInfoType { | |||||||
|   examinationRoomId?: string; |   examinationRoomId?: string; | ||||||
|   plateNo?: string; |   plateNo?: string; | ||||||
|   carNo?: string; |   carNo?: string; | ||||||
|   examSubject: string; |   examSubject?: string; | ||||||
|   isNeedCheck?: string; |   isNeedCheck?: string; | ||||||
|   udpAddress?: string |   udpAddress?: string | ||||||
|   messagePort?: string |   messagePort?: string | ||||||
|  | |||||||
| @ -120,7 +120,6 @@ struct Index { | |||||||
|   @State isDeductedPopShow: boolean = false |   @State isDeductedPopShow: boolean = false | ||||||
|   @State isAmplifyPopShow: boolean = false |   @State isAmplifyPopShow: boolean = false | ||||||
|   @State amplifiedImgIndex: number = 0 |   @State amplifiedImgIndex: number = 0 | ||||||
|   judge: Judge |  | ||||||
|   //行驶距离 |   //行驶距离 | ||||||
|   @State jl: number = 0 |   @State jl: number = 0 | ||||||
|   //应考里程 |   //应考里程 | ||||||
| @ -162,6 +161,7 @@ struct Index { | |||||||
|   @State isErrorMsgEnd: boolean = false |   @State isErrorMsgEnd: boolean = false | ||||||
|   @State disConnectErrorOpen: boolean = false |   @State disConnectErrorOpen: boolean = false | ||||||
|   public context = getContext(this) as common.UIAbilityContext; |   public context = getContext(this) as common.UIAbilityContext; | ||||||
|  |   private judge: Judge = new Judge(this) | ||||||
| 
 | 
 | ||||||
|   async aboutToDisappear() { |   async aboutToDisappear() { | ||||||
|     clearInterval(this.mileageTimer) |     clearInterval(this.mileageTimer) | ||||||
| @ -185,8 +185,7 @@ struct Index { | |||||||
|     //断点续考 |     //断点续考 | ||||||
|     await this.goDdxkItems() |     await this.goDdxkItems() | ||||||
|     //初始化评判 |     //初始化评判 | ||||||
|     const judge = await this.initJudge(); |     await this.initJudge(); | ||||||
|     this.judge = judge |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //初始化相关数据库表 |   //初始化相关数据库表 | ||||||
| @ -522,16 +521,12 @@ struct Index { | |||||||
| 
 | 
 | ||||||
|   // 评判相关初始化 |   // 评判相关初始化 | ||||||
|   async initJudge() { |   async initJudge() { | ||||||
|     const JUDGEUI: JudgeUI = this; |     ; | ||||||
|     const judge = new Judge(JUDGEUI); |     await this.judge.onJudgeFn(async (judgeData: JudgeCallBacData) => { | ||||||
|     // await judge.init<typeof Index>() |  | ||||||
|     await judge.onJudgeFn(async (judgeData: JudgeCallBacData) => { |  | ||||||
|       // const { xmmcStr, carztStr, kfArr } = judgeData; |  | ||||||
|       this.xmmcStr = judgeData.xmmcStr || ""; |       this.xmmcStr = judgeData.xmmcStr || ""; | ||||||
|       this.carztStr = judgeData.carztStr || ""; |       this.carztStr = judgeData.carztStr || ""; | ||||||
|       this.kfArr = judgeData.kfArr || []; |       this.kfArr = judgeData.kfArr || []; | ||||||
|     }); |     }); | ||||||
|     return judge |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 断点续考判断 |   // 断点续考判断 | ||||||
|  | |||||||
| @ -339,7 +339,7 @@ export default struct DeductedPopup { | |||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (mark.itemno == 1 && Number(mark.markserial) > 100 && Number(mark.markserial) < 200) { |       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, |           itemno: tempObj.itemno, | ||||||
|           markcatalog: tempObj.markcatalog, |           markcatalog: tempObj.markcatalog, | ||||||
|           markshow: tempObj.markshow, |           markshow: tempObj.markshow, | ||||||
| @ -350,11 +350,9 @@ export default struct DeductedPopup { | |||||||
|           OnlyOneKind: tempObj.OnlyOneKind, |           OnlyOneKind: tempObj.OnlyOneKind, | ||||||
|           NoCancelId: tempObj.NoCancelId, |           NoCancelId: tempObj.NoCancelId, | ||||||
|           GPS_SID: tempObj.GPS_SID, |           GPS_SID: tempObj.GPS_SID, | ||||||
|         }; |         }) | ||||||
| 
 |  | ||||||
|         this.universalMarkRules.push(tempObj) |         this.universalMarkRules.push(tempObj) | ||||||
|       } |       } | ||||||
| 
 |  | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -41,6 +41,7 @@ import { | |||||||
|   BaseInfoType, |   BaseInfoType, | ||||||
|   CarInfoType, |   CarInfoType, | ||||||
|   CDSBInfo, |   CDSBInfo, | ||||||
|  |   CDSBInfos, | ||||||
|   DrvexamType, |   DrvexamType, | ||||||
|   ExaminerInfoType, |   ExaminerInfoType, | ||||||
|   ItemInfo, |   ItemInfo, | ||||||
| @ -83,7 +84,7 @@ type GetDqxmStr = (xmdm: number) => string | |||||||
| type TJudgeBeginObj = JudgeBeginObj | type TJudgeBeginObj = JudgeBeginObj | ||||||
| 
 | 
 | ||||||
| export default class Judge { | export default class Judge { | ||||||
|   public plcStr!: string |   public plcStr: string = "" | ||||||
|   public judgeUI: JudgeUI |   public judgeUI: JudgeUI | ||||||
|   //获取科目三的评判初始化配置 |   //获取科目三的评判初始化配置 | ||||||
|   getKm3JudgeInitConfig: GetKm3JudgeInitConfig = async () => { |   getKm3JudgeInitConfig: GetKm3JudgeInitConfig = async () => { | ||||||
| @ -92,8 +93,8 @@ export default class Judge { | |||||||
|       map_point_item: this.judgeUI.mapPointItemArr, |       map_point_item: this.judgeUI.mapPointItemArr, | ||||||
|       //科目三暂时为空 |       //科目三暂时为空 | ||||||
|       iteminfo: [], |       iteminfo: [], | ||||||
|       roads: this.getModelData('km3/Roads.txt'), |       roads: this.getModelData('km3/Roads.txt') || "", | ||||||
|       sharps: this.getModelData('km3/Sharps.txt') |       sharps: this.getModelData('km3/Sharps.txt') || "" | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; |   private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; | ||||||
| @ -785,7 +786,7 @@ export default class Judge { | |||||||
|     const kssycs = judgeUI.kssycs |     const kssycs = judgeUI.kssycs | ||||||
|     const isDdxk = judgeUI.isDdxk |     const isDdxk = judgeUI.isDdxk | ||||||
|     const ddxkTime = judgeUI.ddxkTime |     const ddxkTime = judgeUI.ddxkTime | ||||||
|     const projectsCenterObj = judgeUI.projectsCenterObj |     const projectsCenterObj: object = judgeUI.projectsCenterObj | ||||||
|     const ddxkKsxmArr = judgeUI.ddxkKsxmArr |     const ddxkKsxmArr = judgeUI.ddxkKsxmArr | ||||||
|     const ddxkKfArr = judgeUI.ddxkKfArr |     const ddxkKfArr = judgeUI.ddxkKfArr | ||||||
|     const passingScore = judgeUI.passingScore |     const passingScore = judgeUI.passingScore | ||||||
| @ -893,9 +894,9 @@ export default class Judge { | |||||||
|           this.rmndg = 1 |           this.rmndg = 1 | ||||||
|         } |         } | ||||||
|         this.judgeUI.currentXmdm = xmdm; |         this.judgeUI.currentXmdm = xmdm; | ||||||
|         const xmmcStr = project?.name || ""; |         const xmmcStr = project.name || ""; | ||||||
|         const xmmcCode = project?.projectCodeCenter || ""; |         const xmmcCode = project.projectCodeCenter || ""; | ||||||
|         const xmmcSingleCode = project?.projectCode || ""; |         const xmmcSingleCode = project.projectCode || ""; | ||||||
|         const kmItem: KmItem = Reflect.get(this.kmItems, xmmcCode) |         const kmItem: KmItem = Reflect.get(this.kmItems, xmmcCode) | ||||||
|         kmItem.status = 2; |         kmItem.status = 2; | ||||||
|         this.xmmcStr = xmmcStr; |         this.xmmcStr = xmmcStr; | ||||||
| @ -1018,9 +1019,9 @@ export default class Judge { | |||||||
|         const xmxh = precast.xmxh |         const xmxh = precast.xmxh | ||||||
| 
 | 
 | ||||||
|         const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, xmdm) |         const project: ProjectInfo = Reflect.get(judgeUI.projectsObj, xmdm) | ||||||
|         const projectCode = project.projectCode |         // const projectCode = project.projectCode | ||||||
|         const xmmcCode = judgeUI.projectsObj[xmdm].projectCodeCenter; |         const xmmcCode: string = judgeUI.projectsObj[xmdm].projectCodeCenter; | ||||||
|         const xmmcSingleCode = judgeUI.projectsObj[xmdm].projectCode; |         const xmmcSingleCode: string = judgeUI.projectsObj[xmdm].projectCode; | ||||||
|         const kmItem: KmItem = Reflect.get(this.kmItems, xmmcCode) |         const kmItem: KmItem = Reflect.get(this.kmItems, xmmcCode) | ||||||
|         const xmmcStr = project?.name || ""; |         const xmmcStr = project?.name || ""; | ||||||
|         kmItem.status = 2; |         kmItem.status = 2; | ||||||
| @ -1050,7 +1051,7 @@ export default class Judge { | |||||||
|     this.goVoiceAnnounce(event, xmdm, this.kfArr || [], xmjs, ksjs, xmxh) |     this.goVoiceAnnounce(event, xmdm, this.kfArr || [], xmjs, ksjs, xmxh) | ||||||
|     //更新UI |     //更新UI | ||||||
|     if (event == 1 || event == 2 || event == 3 || event == 6) { |     if (event == 1 || event == 2 || event == 3 || event == 6) { | ||||||
|       const copyProjectsObj = this.judgeUI.projectsObj; |       const copyProjectsObj: object = this.judgeUI.projectsObj; | ||||||
|       judgeUI.projectsObj = deepClone(copyProjectsObj); |       judgeUI.projectsObj = deepClone(copyProjectsObj); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @ -1071,8 +1072,8 @@ export default class Judge { | |||||||
|       const lane = this.lane |       const lane = this.lane | ||||||
|       const closeAllFiles = this.closeAllFiles |       const closeAllFiles = this.closeAllFiles | ||||||
| 
 | 
 | ||||||
|       const projectsObj = judgeUI.projectsObj |       const projectsObj: object = judgeUI.projectsObj | ||||||
|       const judgeConfigObj = judgeUI.judgeConfigObj |       const judgeConfigObj: object = judgeUI.judgeConfigObj | ||||||
|       const examSubject = judgeUI.examSubject |       const examSubject = judgeUI.examSubject | ||||||
|       const jl = judgeUI.jl |       const jl = judgeUI.jl | ||||||
|       const isAllProjectsEnd = judgeUI.isAllProjectsEnd |       const isAllProjectsEnd = judgeUI.isAllProjectsEnd | ||||||
| @ -1163,7 +1164,8 @@ export default class Judge { | |||||||
|           const currentKf = kf[kfLen -1]; |           const currentKf = kf[kfLen -1]; | ||||||
|           if (JudgeConfig.kfVoiceOpen || (examSubject == '2' && judgeConfigObj['618'] == '1') || |           if (JudgeConfig.kfVoiceOpen || (examSubject == '2' && judgeConfigObj['618'] == '1') || | ||||||
|             (examSubject == '3' && judgeConfigObj['418'] == '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); |           const isStart = await checkProjectIsStart(Number(currentKf.xmdm), 2, currentKf); | ||||||
|           if (isStart) { |           if (isStart) { | ||||||
| @ -1228,10 +1230,10 @@ export default class Judge { | |||||||
|     const idCard = judgeUI.idCard |     const idCard = judgeUI.idCard | ||||||
|     const serialNumber = judgeUI.serialNumber |     const serialNumber = judgeUI.serialNumber | ||||||
|     const ksdd = judgeUI.ksdd |     const ksdd = judgeUI.ksdd | ||||||
|     const projectsObj = judgeUI.projectsObj |     const projectsObj: object = judgeUI.projectsObj | ||||||
| 
 | 
 | ||||||
|     const time = GetCurrentTime(); |     const time = GetCurrentTime(); | ||||||
|     const project = this.getProjectInfo(ksxm); |     const project: ProjectInfo = this.getProjectInfo(ksxm); | ||||||
|     //科目三夜间行驶.模拟灯光、上车准备出现通用评判,ksxm为当前进行的项目 |     //科目三夜间行驶.模拟灯光、上车准备出现通用评判,ksxm为当前进行的项目 | ||||||
|     const checkProjects = ['17', '41', '1']; |     const checkProjects = ['17', '41', '1']; | ||||||
|     //获取正在进行的项目 |     //获取正在进行的项目 | ||||||
| @ -1247,11 +1249,25 @@ export default class Judge { | |||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     const ksxmD: string = project == undefined |     // const ksxmD: string = !project | ||||||
|       ? (commonKsxm |     //   ? (commonKsxm | ||||||
|         ? (project?.projectCodeCenter||"") |     //     ? (project?.projectCodeCenter!) | ||||||
|         : (examSubject == '3' ? '30000' : (xmmcEndCode == undefined ? '10000' : xmmcEndCode))) |     //     : (examSubject == '3' ? '30000' : (xmmcEndCode == undefined ? '10000' : xmmcEndCode))) | ||||||
|       : project.projectCodeCenter |     //   : 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 = { |     const drvexam: DrvexamType = { | ||||||
|       lsh, |       lsh, | ||||||
|       kskm: examSubject, |       kskm: examSubject, | ||||||
| @ -1682,8 +1698,8 @@ export default class Judge { | |||||||
|   //获取场地序号 |   //获取场地序号 | ||||||
|   getSbxh: GetgSbbm = (ksxm, xmxh) => { |   getSbxh: GetgSbbm = (ksxm, xmxh) => { | ||||||
|     const judgeUI = this.judgeUI; |     const judgeUI = this.judgeUI; | ||||||
|     const projectsObj = judgeUI.projectsObj; |     const projectsObj: object = judgeUI.projectsObj; | ||||||
|     const cdsbInfoObj = judgeUI.cdsbInfoObj; |     const cdsbInfoObj: CDSBInfos = judgeUI.cdsbInfoObj!; | ||||||
|     const project: ProjectInfo = Reflect.get(projectsObj, ksxm); |     const project: ProjectInfo = Reflect.get(projectsObj, ksxm); | ||||||
|     if (judgeUI.examSubject == '3') { |     if (judgeUI.examSubject == '3') { | ||||||
|       return '0000000000' |       return '0000000000' | ||||||
| @ -1693,24 +1709,24 @@ export default class Judge { | |||||||
|     } |     } | ||||||
|     const projectKey = `${ksxm}_${xmxh}`; |     const projectKey = `${ksxm}_${xmxh}`; | ||||||
|     // const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj, projectKey) || {} |     // 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' |     const sbxh: string = currentCdsb.sbbh || '0000000000' | ||||||
|     return sbxh |     return sbxh | ||||||
|   } |   } | ||||||
|   getSbbm: GetgSbbm = (ksxm, xmxh) => { |   getSbbm: GetgSbbm = (ksxm, xmxh) => { | ||||||
|     const judgeUI = this.judgeUI; |     const judgeUI = this.judgeUI; | ||||||
|     const cdsbInfoObj = judgeUI.cdsbInfoObj; |     const cdsbInfoObj = judgeUI.cdsbInfoObj; | ||||||
|     const projectsObj = judgeUI.projectsObj; |     const projectsObj: object = judgeUI.projectsObj; | ||||||
|     const project: ProjectInfo = Reflect.get(projectsObj, ksxm); |     const project: ProjectInfo = Reflect.get(projectsObj, ksxm); | ||||||
|     //科目三不需要 |     //科目三不需要 | ||||||
|     if (judgeUI.examSubject == '3') { |     if (judgeUI.examSubject == '3') { | ||||||
|       return undefined |       return "" | ||||||
|     } |     } | ||||||
|     if (project === undefined) { |     if (project === undefined) { | ||||||
|       return '00000000' |       return '00000000' | ||||||
|     } |     } | ||||||
|     const projectKey = `${ksxm}_${xmxh}`; |     const projectKey = `${ksxm}_${xmxh}`; | ||||||
|     const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj, projectKey) || {} |     const currentCdsb: CDSBInfo = Reflect.get(cdsbInfoObj!, projectKey) || {} | ||||||
|     const sbxh: string = currentCdsb.sbbm || '00000000' |     const sbxh: string = currentCdsb.sbbm || '00000000' | ||||||
|     return sbxh |     return sbxh | ||||||
|   } |   } | ||||||
| @ -1757,7 +1773,7 @@ export default class Judge { | |||||||
|   } |   } | ||||||
|   // 统计必考项目、所有项目、已考数量 |   // 统计必考项目、所有项目、已考数量 | ||||||
|   setCountItems = async () => { |   setCountItems = async () => { | ||||||
|     const projectsObj = this.judgeUI.projectsObj; |     const projectsObj: object = this.judgeUI.projectsObj; | ||||||
|     //必考项目数量       必考项目已考数量 |     //必考项目数量       必考项目已考数量 | ||||||
|     let projectNum = 0, endProjectsNum = 0; |     let projectNum = 0, endProjectsNum = 0; | ||||||
|     // 所有考试项目数量  项目已考项目数量 |     // 所有考试项目数量  项目已考项目数量 | ||||||
| @ -1898,12 +1914,14 @@ export default class Judge { | |||||||
|     // 3.开始考试 |     // 3.开始考试 | ||||||
|     if (isTrajectoryOpen) { |     if (isTrajectoryOpen) { | ||||||
|       beginExamInfo = JSON.parse(strArr[1]) |       beginExamInfo = JSON.parse(strArr[1]) | ||||||
|       beginExamInfo.replay = 1 |       beginExamInfo && (beginExamInfo.replay = 1) | ||||||
|     } else { |     } else { | ||||||
|       beginExamInfo = await getJudgeBeginData() |       beginExamInfo = await getJudgeBeginData() | ||||||
|     } |     } | ||||||
|     await fileLog?.setExamJudgeData(JSON.stringify(beginExamInfo)) |     await fileLog?.setExamJudgeData(JSON.stringify(beginExamInfo)) | ||||||
|  |     if (beginExamInfo) { | ||||||
|       await examJudgeBeginExam(beginExamInfo); |       await examJudgeBeginExam(beginExamInfo); | ||||||
|  |     } | ||||||
|     console.info(judgeTag, '6.开始考试注册完成') |     console.info(judgeTag, '6.开始考试注册完成') | ||||||
|     avPlayer?.playAudio([judgeUI.singlePlay ? 'voice/ksks.wav' : 'voice/监管成功.mp3']) |     avPlayer?.playAudio([judgeUI.singlePlay ? 'voice/ksks.wav' : 'voice/监管成功.mp3']) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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 |   // 如果是对象,且不是原始值null | ||||||
|   if (typeof target === 'object' && target !== null) { |   if (typeof target === 'object' && target !== null) { | ||||||
|     // 创建容器 |     // 创建容器 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user