241 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			241 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| import common from '@ohos.app.ability.common';
 | |
| import router from '@ohos.router';
 | |
| 
 | |
| import { JudgeConfig } from '../config';
 | |
| import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
 | |
| import { BaseInfoType, centerCallBackMsgType } from '../model/Common';
 | |
| import { CarInfoType, InitializeTheCentralTableType, MASYSSETTableType, TimeSynchronizationRspBody } from '../model';
 | |
| import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils';
 | |
| import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation';
 | |
| import { BusinessError } from '@ohos.base';
 | |
| import { delPic } from '../utils/Video';
 | |
| import { FileHelper } from '../utils/FileHelp';
 | |
| import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
 | |
| import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
 | |
| import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
 | |
| import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness';
 | |
| import { JudgeEmitterInstance } from '../utils/business/UdpEvent';
 | |
| import HeaderComponent from './compontents/Header';
 | |
| import CardComponent from './Index/Card';
 | |
| import BottomMessageComponent from './Index/BottomMessage';
 | |
| import LoadingComponent from './Index/Loading';
 | |
| import Prompt from '@system.prompt';
 | |
| 
 | |
| 
 | |
| @Entry
 | |
| @Component
 | |
| struct Index {
 | |
|   @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;
 | |
|   // 请求网络表等待弹窗
 | |
|   customDialogController: CustomDialogController = new CustomDialogController({
 | |
|     builder: LoadingComponent(),
 | |
|     customStyle: true,
 | |
|     alignment: DialogAlignment.Center,
 | |
|     autoCancel: true
 | |
|   });
 | |
|   private context = getContext(this) as common.UIAbilityContext;
 | |
|   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%' })
 | |
|   }
 | |
| 
 | |
|   async aboutToAppear() {
 | |
|     await UseAuth(this.context)
 | |
|     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> {
 | |
|     this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')!
 | |
|     await UseAuth(this.context)
 | |
|     this.initParams()
 | |
|     AppStorage.setOrCreate('singlePlay', false)
 | |
|     this.context.resourceManager.getRawFileContent("welcome.wav")
 | |
|       .then(() => {
 | |
|         this.avPlayer.playAudio(['welcome.wav'])
 | |
|       })
 | |
|       .catch((error: BusinessError) => {
 | |
|         console.log("getRawFileContent promise error is " + error);
 | |
|       });
 | |
|     this.num = 0
 | |
|     AppStorage.setOrCreate('lsh', '1111111111111')
 | |
|   }
 | |
| 
 | |
|   // 联网考试逻辑处理
 | |
|   onlineExam() {
 | |
|     this.customDialogController.open()
 | |
|     if (!this.timeInfo) {
 | |
|       Prompt.showToast({
 | |
|         message: `时间同步接口连接失败`,
 | |
|         duration: 3000
 | |
|       });
 | |
|       this.customDialogController.close()
 | |
|       return
 | |
|     }
 | |
|     if (!this.carInfo) {
 | |
|       Prompt.showToast({
 | |
|         message: `车辆信息接口获取失败`,
 | |
|         duration: 3000
 | |
|       });
 | |
|       this.customDialogController.close()
 | |
|       return
 | |
|     }
 | |
|     this.initializationTableRelated()
 | |
|   }
 | |
| 
 | |
|   // 单机训练逻辑处理
 | |
|   singlePlayerTraining() {
 | |
|     AppStorage.setOrCreate('singlePlay', true)
 | |
|     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 {
 | |
|         this.initializationTableRelated()
 | |
|       }
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   async initializationTableRelated() {
 | |
|     const param: InitializeTheCentralTableType = {
 | |
|       carId: this.carInfo?.carId,
 | |
|       examinationRoomId: this.carInfo?.examinationRoomId,
 | |
|       judgeVersion: this.baseInfo?.judgeVersion,
 | |
|       shellVersion: this.baseInfo?.version || "",
 | |
|       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)
 | |
|             }
 | |
|           })
 | |
|         });
 | |
|       } else {
 | |
|         this.customDialogController.close()
 | |
|       }
 | |
|     })
 | |
|   }
 | |
| 
 | |
|   async initParams() {
 | |
|     console.log("test1111")
 | |
|     ObtainUdpBusinessInstance.init();
 | |
|     await GetDeviceInfo(this.context)
 | |
|     this.carInfo = await GetCarInfo()
 | |
|     CenterUDPBusinessInstance.init();
 | |
|     CenterUDPBusinessInstance.onMsg((data: centerCallBackMsgType) => {
 | |
|       if (data.id == 32) {
 | |
|         AppStorage.setOrCreate('signNum', data.body[1])
 | |
|       }
 | |
|     },)
 | |
|     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)
 | |
|     // TODO
 | |
|     // CenterUDPBusinessInstance.startHeartBeat()
 | |
|     CreateAlbum(this.fileHelper)
 | |
|   }
 | |
| 
 | |
|   build() {
 | |
|     Flex({
 | |
|       justifyContent: FlexAlign.SpaceBetween,
 | |
|       direction: FlexDirection.Column
 | |
|     }) {
 | |
|       HeaderComponent({
 | |
|         shortLogo: false
 | |
|       })
 | |
|       CardComponent({
 | |
|         isSingle: this.singlePlay,
 | |
|         singleClick: () => {
 | |
|           this.singlePlayerTraining()
 | |
|         },
 | |
|         networkingClick: () => {
 | |
|           this.onlineExam()
 | |
|         }
 | |
|       })
 | |
| 
 | |
|       BottomMessageComponent({
 | |
|         version: this.baseInfo.version,
 | |
|         judgeVersion: this.baseInfo.judgeVersion,
 | |
|         hasAuth: this.baseInfo.hasAuth,
 | |
|         examCarNumber: this.deviceId,
 | |
|         versionClick: () => {
 | |
|           this.singlePlay = !this.singlePlay
 | |
|           AppStorage.setOrCreate('singlePlay', this.singlePlay)
 | |
|         }
 | |
|       })
 | |
|     }
 | |
|     .width("100%")
 | |
|     .height("100%")
 | |
|     .backgroundImage($r('app.media.index_bg'))
 | |
|     .backgroundImageSize({
 | |
|       width: "100%",
 | |
|       height: "100%"
 | |
|     })
 | |
|   }
 | |
| } |