| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | import common from '@ohos.app.ability.common'; | 
					
						
							|  |  |  | import router from '@ohos.router'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  | import { JudgeConfig } from '../config'; | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  | import { BaseInfoType } from '../model/Common'; | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  | import { CarInfoType, InitializeTheCentralTableType, MASYSSETTableType, TimeSynchronizationRspBody } from '../model'; | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  | import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils'; | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation'; | 
					
						
							|  |  |  | import { BusinessError } from '@ohos.base'; | 
					
						
							|  |  |  | import { delPic } from '../utils/Video'; | 
					
						
							|  |  |  | import { FileHelper } from '../utils/FileHelp'; | 
					
						
							|  |  |  | import { DrivingDataStorage } from '../utils/business/DrivingDataStorage'; | 
					
						
							|  |  |  | import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness'; | 
					
						
							|  |  |  | import { JudgeEmitterInstance } from '../utils/business/UdpEvent'; | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  | import HeaderComponent from './compontents/Header'; | 
					
						
							|  |  |  | import CardComponent from './Index/Card'; | 
					
						
							|  |  |  | import BottomMessageComponent from './Index/BottomMessage'; | 
					
						
							|  |  |  | import LoadingComponent from './Index/Loading'; | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  | import Prompt from '@system.prompt'; | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  | import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignal'; | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  | @Entry | 
					
						
							|  |  |  | @Component | 
					
						
							|  |  |  | struct Index { | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   @State url: string = '' | 
					
						
							|  |  |  |   @State hasAuth: boolean = false; | 
					
						
							|  |  |  |   @State dialogVisible: boolean = false; | 
					
						
							|  |  |  |   @State singlePlay: boolean = false; | 
					
						
							|  |  |  |   @State baseInfo: BaseInfoType = {}; | 
					
						
							|  |  |  |   @State deviceId: string = ''; | 
					
						
							|  |  |  |   @State angle: number = 0 | 
					
						
							|  |  |  |   @State dialogRatio: number = 0.8 | 
					
						
							|  |  |  |   @State ratio: number = 1700 / 960 | 
					
						
							|  |  |  |   @State delLoading: boolean = false | 
					
						
							|  |  |  |   @State initParamFlag: boolean = false | 
					
						
							|  |  |  |   @State fd: number = -1; | 
					
						
							|  |  |  |   @State carInfo: CarInfoType = {}; | 
					
						
							|  |  |  |   @State num: number = 0; | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |   // 请求网络表等待弹窗 | 
					
						
							|  |  |  |   customDialogController: CustomDialogController = new CustomDialogController({ | 
					
						
							|  |  |  |     builder: LoadingComponent(), | 
					
						
							|  |  |  |     customStyle: true, | 
					
						
							|  |  |  |     alignment: DialogAlignment.Center, | 
					
						
							|  |  |  |     autoCancel: true | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2025-04-10 15:10:31 +08:00
										 |  |  |   private context = getContext(this) as common.UIAbilityContext; | 
					
						
							| 
									
										
										
										
											2025-04-11 10:13:29 +08:00
										 |  |  |   private fileHelper: FileHelper = new FileHelper(this.context) | 
					
						
							|  |  |  |   private avPlayer: VoiceAnnounce = new VoiceAnnounce(this.context) | 
					
						
							|  |  |  |   private timeInfo: TimeSynchronizationRspBody = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @Styles | 
					
						
							|  |  |  |   commStyle(){ | 
					
						
							|  |  |  |     .width(220 * this.ratio * this.dialogRatio) | 
					
						
							|  |  |  |     .height(69 * this.ratio * this.dialogRatio) | 
					
						
							|  |  |  |     .backgroundImage($r('app.media.button_nor')) | 
					
						
							|  |  |  |     .backgroundImageSize({ width: '100%', height: '100%' }) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   async aboutToAppear() { | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  |     console.log("首页 aboutToAppear") | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |     await UseAuth(this.context) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     this.ratio = AppStorage.get<BaseInfoType>('baseInfo')?.ratio || 1.4 | 
					
						
							|  |  |  |     this.angle = 0 | 
					
						
							|  |  |  |     AppStorage.set('lsh', '1111111111111') | 
					
						
							|  |  |  |     JudgeEmitterInstance.init() | 
					
						
							|  |  |  |     GetSyncData<MASYSSETTableType>("MA_SYSSET").then((res: MASYSSETTableType[]) => { | 
					
						
							|  |  |  |       res.forEach((element) => { | 
					
						
							|  |  |  |         if (element.v_no === "305") { | 
					
						
							|  |  |  |           delPic(Number(element.v_value), 1, this.context) | 
					
						
							|  |  |  |           delPic(Number(element.v_value), 2, this.context) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async onPageShow(): Promise<void> { | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  |     console.log("首页 onPageShow") | 
					
						
							| 
									
										
										
										
											2025-04-11 10:13:29 +08:00
										 |  |  |     await UseAuth(this.context) | 
					
						
							| 
									
										
										
										
											2025-06-13 10:15:33 +08:00
										 |  |  |     // DifferentialAndSignal.init() | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  |     DifferentialAndSignal.onMsg(() => { | 
					
						
							|  |  |  |       console.log("外层接受") | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2025-06-06 13:37:15 +08:00
										 |  |  |     this.avPlayer.playAudio(['welcome.wav']) | 
					
						
							|  |  |  |     this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')! | 
					
						
							| 
									
										
										
										
											2025-04-11 10:13:29 +08:00
										 |  |  |     this.initParams() | 
					
						
							|  |  |  |     AppStorage.setOrCreate('singlePlay', false) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     this.num = 0 | 
					
						
							|  |  |  |     AppStorage.setOrCreate('lsh', '1111111111111') | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |   // 联网考试逻辑处理 | 
					
						
							|  |  |  |   onlineExam() { | 
					
						
							|  |  |  |     this.customDialogController.open() | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |     if (!this.timeInfo) { | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |       Prompt.showToast({ | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |         message: `时间同步接口连接失败`, | 
					
						
							|  |  |  |         duration: 3000 | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |       this.customDialogController.close() | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!this.carInfo) { | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |       Prompt.showToast({ | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |         message: `车辆信息接口获取失败`, | 
					
						
							|  |  |  |         duration: 3000 | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |       this.customDialogController.close() | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |     this.initializationTableRelated() | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |   // 单机训练逻辑处理 | 
					
						
							|  |  |  |   singlePlayerTraining() { | 
					
						
							| 
									
										
										
										
											2025-04-11 17:09:27 +08:00
										 |  |  |     AppStorage.setOrCreate('singlePlay', true) | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |     if (JudgeConfig.isTrajectoryOpen) { | 
					
						
							|  |  |  |       router.pushUrl({ | 
					
						
							|  |  |  |         url: 'pages/UserInfo', | 
					
						
							|  |  |  |       }, router.RouterMode.Single) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     //判断数据库是否有表数据,有则直接跳转,没有则读取本地数据 | 
					
						
							|  |  |  |     GetSyncData<MASYSSETTableType>('MA_SYSSET').then((data: Array<MASYSSETTableType>) => { | 
					
						
							|  |  |  |       if (data?.[0]) { | 
					
						
							|  |  |  |         router.pushUrl({ | 
					
						
							|  |  |  |           url: 'pages/UserInfo', | 
					
						
							|  |  |  |         }, router.RouterMode.Single) | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |         this.initializationTableRelated() | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |   async initializationTableRelated() { | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     const param: InitializeTheCentralTableType = { | 
					
						
							|  |  |  |       carId: this.carInfo?.carId, | 
					
						
							|  |  |  |       examinationRoomId: this.carInfo?.examinationRoomId, | 
					
						
							|  |  |  |       judgeVersion: this.baseInfo?.judgeVersion, | 
					
						
							| 
									
										
										
										
											2025-04-10 15:10:31 +08:00
										 |  |  |       shellVersion: this.baseInfo?.version || "", | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       paraKdid: this.timeInfo?.paraKdid || this.timeInfo?.kdid, | 
					
						
							|  |  |  |       kdid: this.timeInfo?.kdid || this.timeInfo?.paraKdid, | 
					
						
							|  |  |  |       mode: this.timeInfo?.mode, | 
					
						
							|  |  |  |       context: this.context, | 
					
						
							|  |  |  |       host: AppStorage.get<string>('host'), | 
					
						
							|  |  |  |       centerHost: this.timeInfo?.url, | 
					
						
							|  |  |  |       singlePlay: this.singlePlay | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     InitializeTheCentralTable(param).then((ret) => { | 
					
						
							|  |  |  |       if (ret) { | 
					
						
							|  |  |  |         GetSyncData<MASYSSETTableType>("MA_SYSSET").then(data => { | 
					
						
							|  |  |  |           data.forEach(sys => { | 
					
						
							|  |  |  |             //判断是否能点开始考试 | 
					
						
							|  |  |  |             if (sys.v_no === '854') { | 
					
						
							|  |  |  |               AppStorage.setOrCreate('param854Str', sys.v_value) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (sys.v_no === '824' && decodeURIComponent(sys.v_value || '') == '0') { | 
					
						
							|  |  |  |               router.pushUrl({ | 
					
						
							|  |  |  |                 url: 'pages/CarCheck', | 
					
						
							|  |  |  |                 params: { | 
					
						
							|  |  |  |                   'fromIndex': true | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               }, router.RouterMode.Single) | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               router.pushUrl({ | 
					
						
							|  |  |  |                 url: 'pages/ExaminerLogin', | 
					
						
							|  |  |  |               }, router.RouterMode.Single) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         this.customDialogController.close() | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-04-15 17:36:14 +08:00
										 |  |  |     }).catch((err: BusinessError) => { | 
					
						
							|  |  |  |       console.error("初始化表失败", err) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async initParams() { | 
					
						
							| 
									
										
										
										
											2025-04-11 10:13:29 +08:00
										 |  |  |     console.log("test1111") | 
					
						
							| 
									
										
										
										
											2025-04-15 10:16:33 +08:00
										 |  |  |     await GetDeviceInfo(this.context) | 
					
						
							|  |  |  |     this.carInfo = await GetCarInfo() | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  |     // TODO | 
					
						
							|  |  |  |     // CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => { | 
					
						
							|  |  |  |     //   if (data.id == 32) { | 
					
						
							|  |  |  |     //     AppStorage.setOrCreate('signNum', data.body[1]) | 
					
						
							|  |  |  |     //   } | 
					
						
							|  |  |  |     // },) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     this.carInfo = AppStorage.get<CarInfoType>('carInfo')! | 
					
						
							|  |  |  |     this.deviceId = this.carInfo.carNo || "" | 
					
						
							|  |  |  |     await SetCurrentTime() | 
					
						
							|  |  |  |     this.timeInfo = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')! | 
					
						
							|  |  |  |     DrivingDataStorage.init(this.context) | 
					
						
							|  |  |  |     DrivingDataStorage.initializeTheDrivingDataFolder() | 
					
						
							|  |  |  |     JudgeUdpBusinessInstance.init() | 
					
						
							|  |  |  |     // TODO 摄像头遮挡 | 
					
						
							|  |  |  |     // takePhotoFn(this.context) | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |     // TODO | 
					
						
							|  |  |  |     // CenterUDPBusinessInstance.startHeartBeat() | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  |     CreateAlbum(this.fileHelper) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   build() { | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |     Flex({ | 
					
						
							|  |  |  |       justifyContent: FlexAlign.SpaceBetween, | 
					
						
							|  |  |  |       direction: FlexDirection.Column | 
					
						
							|  |  |  |     }) { | 
					
						
							|  |  |  |       HeaderComponent({ | 
					
						
							|  |  |  |         shortLogo: false | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2025-06-11 17:50:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |       CardComponent({ | 
					
						
							|  |  |  |         isSingle: this.singlePlay, | 
					
						
							|  |  |  |         singleClick: () => { | 
					
						
							|  |  |  |           this.singlePlayerTraining() | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         networkingClick: () => { | 
					
						
							|  |  |  |           this.onlineExam() | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2025-04-15 14:24:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |       BottomMessageComponent({ | 
					
						
							|  |  |  |         version: this.baseInfo.version, | 
					
						
							|  |  |  |         judgeVersion: this.baseInfo.judgeVersion, | 
					
						
							|  |  |  |         hasAuth: this.baseInfo.hasAuth, | 
					
						
							| 
									
										
										
										
											2025-04-15 10:16:33 +08:00
										 |  |  |         examCarNumber: this.deviceId, | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |         versionClick: () => { | 
					
						
							|  |  |  |           this.singlePlay = !this.singlePlay | 
					
						
							|  |  |  |           AppStorage.setOrCreate('singlePlay', this.singlePlay) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |     .width("100%") | 
					
						
							|  |  |  |     .height("100%") | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     .backgroundImage($r('app.media.index_bg')) | 
					
						
							| 
									
										
										
										
											2025-04-14 18:13:34 +08:00
										 |  |  |     .backgroundImageSize({ | 
					
						
							|  |  |  |       width: "100%", | 
					
						
							|  |  |  |       height: "100%" | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |