From 80dd24fd644b54d5ee2b09c63ffccfd97716aa0c Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Thu, 11 Sep 2025 18:27:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=9D=E7=A6=BB=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/config/LogEnum.ets | 2 +- entry/src/main/ets/config/judge.ets | 2 +- .../main/ets/entryability/EntryAbility.ets | 1 + entry/src/main/ets/model/Judge.ets | 1 + entry/src/main/ets/pages/Index.ets | 19 ++++-- entry/src/main/ets/pages/Index/utils.ets | 61 ++++++++++++++++--- entry/src/main/ets/pages/Judge.ets | 1 + .../ets/workers/DifferentialCorrection.ets | 1 + 8 files changed, 71 insertions(+), 17 deletions(-) diff --git a/entry/src/main/ets/config/LogEnum.ets b/entry/src/main/ets/config/LogEnum.ets index da2fbe4..5c29dee 100644 --- a/entry/src/main/ets/config/LogEnum.ets +++ b/entry/src/main/ets/config/LogEnum.ets @@ -72,4 +72,4 @@ export const StartExamTag = '[StartExam]' //人脸对比 export const FaceCompareTag = '[FaceCompare]'; //过程数据处理 -export const ProcessDataTag = '[ProcessData]'; \ No newline at end of file +export const ProcessDataTag = '[ProcessData]'; diff --git a/entry/src/main/ets/config/judge.ets b/entry/src/main/ets/config/judge.ets index bbf2a18..c022cf8 100644 --- a/entry/src/main/ets/config/judge.ets +++ b/entry/src/main/ets/config/judge.ets @@ -16,7 +16,7 @@ export const JudgeConfig: JudgeConfigType = { //是否开启拍照 isPhotoOpen: true, //扣分语音是否强制开启 - kfVoiceOpen: false, + kfVoiceOpen: true, //忽略的考试项目 ignoreProjects: [], // 是否忽略考试前熄火、车门检查 diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 61a6792..7e1eb7d 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -96,6 +96,7 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); + this.createFiles(); } diff --git a/entry/src/main/ets/model/Judge.ets b/entry/src/main/ets/model/Judge.ets index 1753dc9..879b5c1 100644 --- a/entry/src/main/ets/model/Judge.ets +++ b/entry/src/main/ets/model/Judge.ets @@ -550,6 +550,7 @@ export interface CARINFO { FLAG: string, BK1: string, BK2: string + X_MCH: string, } export interface KmItem { diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 2969691..97c60ec 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -4,8 +4,14 @@ import router from '@ohos.router'; import { HomeTag, InitTableTag, JudgeConfig } from '../config'; import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; import { BaseInfoType } from '../model/Common'; -import { CarInfoType, InitializeTheCentralTableType, MASYSSETTableType, TimeSynchronizationRspBody } from '../model'; -import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime } from './Index/utils'; +import { + CarInfoType, + ES_CARINFOType, + InitializeTheCentralTableType, + MASYSSETTableType, + TimeSynchronizationRspBody +} from '../model'; +import { CheckNetUntilConnected, CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime } from './Index/utils'; import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation'; import { BusinessError } from '@ohos.base'; import { delPic } from '../utils/Video'; @@ -19,7 +25,6 @@ import Prompt from '@system.prompt'; import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignalWorker'; import { dConsole } from '../utils/LogWorker'; import CarLoadingComponent from './Index/Loading'; -import { ObtainNetworkCameraImages } from '../api/networkCamera'; @Entry @Component @@ -64,7 +69,8 @@ struct Index { async aboutToAppear() { dConsole.log("权限首页 aboutToAppear") - this.base64Img = await ObtainNetworkCameraImages() || "" + const result = await GetSyncData("ES_CARINFO") + dConsole.log(HomeTag, "读取carinfo", result) this.ratio = AppStorage.get('baseInfo')?.ratio || 1.4 this.angle = 0 AppStorage.set('lsh', '1111111111111') @@ -78,9 +84,10 @@ struct Index { }); }); } - + async onPageShow(): Promise { - dConsole.log("权限首页 onPageShow2") + dConsole.log("权限首页 onPageShow") + await CheckNetUntilConnected() if (!this.isPlay) { this.avPlayer.playAudio(['welcome.wav']) this.isPlay = true diff --git a/entry/src/main/ets/pages/Index/utils.ets b/entry/src/main/ets/pages/Index/utils.ets index f313f91..9ae9984 100644 --- a/entry/src/main/ets/pages/Index/utils.ets +++ b/entry/src/main/ets/pages/Index/utils.ets @@ -1,5 +1,5 @@ import common from '@ohos.app.ability.common'; -import { GlobalConfig } from '../../config'; +import { GlobalConfig, HomeTag } from '../../config'; import Prompt from '@system.prompt'; import { ApiResponseType, @@ -19,6 +19,8 @@ import { VideoConfigData } from '../../mock'; import FileUtils from '../../utils/FileUtils'; import { FileHelper } from '../../utils/FileHelp'; import { dConsole } from '../../utils/LogWorker'; +import connection from '@ohos.net.connection'; + //获取设备信息 export async function GetDeviceInfo(context: common.UIAbilityContext): Promise { @@ -42,19 +44,28 @@ export async function GetDeviceInfo(context: common.UIAbilityContext): Promise { + let date = new Date(); let params: ObtainCarExamInfoParams = { time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"), deviceNo: AppStorage.get('deviceNo') || "" }; - let res: ApiResponseType = await obtainCarExamInfo(params) - dConsole.log("90", res) - if (res.obtainCarExamInfoRsp && res.obtainCarExamInfoRsp.body) { - const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body! - carInfo.plateNo = decodeURIComponent(carInfo.plateNo) - dConsole.log("Worker received message car", JSON.stringify(carInfo)) - AppStorage.setOrCreate('carInfo', carInfo) - return carInfo + try { + let res: ApiResponseType = await obtainCarExamInfo(params) + dConsole.log("90", res) + if (res.obtainCarExamInfoRsp && res.obtainCarExamInfoRsp.body) { + const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body! + carInfo.plateNo = decodeURIComponent(carInfo.plateNo) + dConsole.log("Worker received message car", JSON.stringify(carInfo)) + AppStorage.setOrCreate('carInfo', carInfo) + return carInfo + } + } catch (e) { + dConsole.error(HomeTag, "获取考车信息错误", JSON.stringify(e)) + setTimeout(() => { + dConsole.log(HomeTag, "延迟获取考车信息") + GetCarInfo() + }, 1000) } return {} } @@ -141,3 +152,35 @@ export function CreateAlbum(fileHelper: FileHelper) { fileHelper.createAlbum(date); } +const RETRY_INTERVAL_MS = 3000; + +export async function CheckNetUntilConnected(): Promise { + return new Promise(async (resolve, reject) => { + const doCheck = async () => { + try { + let netHandle: connection.NetHandle = await connection.getDefaultNet(); + // getDefaultNet().netId 在网络连接正常时会大于0 + // 在没有默认网络时,getDefaultNet()可能会抛出异常或者返回netId为0的NetHandle + // 最新的OpenHarmony API中,推荐使用connection.getNetCapabilities(netHandle) + // 或 connection.hasDefaultNet() 来更准确判断网络状态 + + let hasDefaultNet: boolean = await connection.hasDefaultNet(); + + if (hasDefaultNet && netHandle && netHandle.netId > 0) { + dConsole.log(HomeTag, "网络通畅"); + resolve(); // 网络通畅,解决Promise + } else { + dConsole.log(HomeTag, "网络不通畅,等待 " + RETRY_INTERVAL_MS / 1000 + " 秒后重试..."); + setTimeout(doCheck, RETRY_INTERVAL_MS); // 网络不通畅,继续重试 + } + } catch (error) { + dConsole.log(HomeTag, "网络不通畅,等待 " + RETRY_INTERVAL_MS / 1000 + " 秒后重试..."); + setTimeout(doCheck, RETRY_INTERVAL_MS); // 即使出错,也继续重试 + } + }; + + // 首次执行检查 + doCheck(); + }); +} + diff --git a/entry/src/main/ets/pages/Judge.ets b/entry/src/main/ets/pages/Judge.ets index 1184498..2517f45 100644 --- a/entry/src/main/ets/pages/Judge.ets +++ b/entry/src/main/ets/pages/Judge.ets @@ -282,6 +282,7 @@ struct JudgePage { FLAG: carInfo.flag!, BK1: carInfo.bk1!, BK2: carInfo.bk2!, + X_MCH: carInfo.x_mch!, }) dConsole.info(JudgeTag, 'surenjun =>carinfoArrr', JSON.stringify(this.carinfoArr)) } diff --git a/entry/src/main/ets/workers/DifferentialCorrection.ets b/entry/src/main/ets/workers/DifferentialCorrection.ets index 3d8954b..27e8feb 100644 --- a/entry/src/main/ets/workers/DifferentialCorrection.ets +++ b/entry/src/main/ets/workers/DifferentialCorrection.ets @@ -75,6 +75,7 @@ function getDataFn(config: EnvironmentConfigurationType) { // 替换data的第28位 dataArray[28] = res[9].toString(); data = dataArray.join(","); + console.log(SerialPortTag, "档位", res[9].toString()) } console.log(SerialPortTag, "处理完的档位信号", data) workerPort.postMessage(