From 43a673fa4f5d523ff6d55a07a973696c4bbea437 Mon Sep 17 00:00:00 2001 From: lvyuankang <1344032923@qq.com> Date: Wed, 17 Jul 2024 10:19:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=B3=A8=E5=86=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/common/service/terminalService.ts | 71 ++++++++++--------- entry/src/main/ets/config/global.ts | 2 +- entry/src/main/ets/pages/Index.ets | 8 +-- entry/src/main/ets/pages/Register.ets | 11 ++- 4 files changed, 51 insertions(+), 41 deletions(-) diff --git a/entry/src/main/ets/common/service/terminalService.ts b/entry/src/main/ets/common/service/terminalService.ts index 037fe061..2511aa70 100644 --- a/entry/src/main/ets/common/service/terminalService.ts +++ b/entry/src/main/ets/common/service/terminalService.ts @@ -1,44 +1,47 @@ // @ts-nocheck -import { obtainCarExamInfo} from '../../api/index' -import { dateFormat} from '../utils/tools' +import { obtainCarExamInfo } from '../../api/index' +import { dateFormat } from '../utils/tools' import router from '@ohos.router' import { getSyncData } from '../../common/service/initable' +import { GlobalConfig } from '../../config/index' +import FileUtil from '../../common/utils/File' //获取设备信息 -export async function getDeviceInfo() { - // globalThis.deviceNo = '153216400880'; //科目三设备 - globalThis.deviceNo = '150667400235'; //科目三设备 - - return new Promise((resolve, reject) => { - getSyncData('DeviceInfoTable').then((result: Array) => { - if (result.length) { - globalThis.deviceNo = result[0].deviceId - getCarInfo() - resolve(result[0].deviceId) - } else { - // router.pushUrl({ - // url: 'pages/Register', - // }, router.RouterMode.Single); - resolve('') - } - }) - }) +export async function getDeviceInfo(context) { + // globalThis.deviceNo = '153216400880'; //科目三设备 + globalThis.deviceNo = '150667400235'; //科目三设备 + return + return new Promise(async (resolve, reject) => { + const fileUtil = new FileUtil(context) + const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/deviceNo.txt'); + if (data === '' || data === undefined) { + router.pushUrl({ + url: 'pages/Register', + }, router.RouterMode.Single); + resolve('') + } else { + const fileData=JSON.parse(data) + globalThis.deviceNo = fileData.deviceName + getCarInfo() + resolve(fileData.deviceName) + } + }) } //获取考车信息 export async function getCarInfo() { - let date = new Date(); - let params = { time: dateFormat(date), deviceNo: globalThis.deviceNo }; - let res:any = await obtainCarExamInfo(params) - if(!res?.obtainCarExamInfoRsp?.body){ - // router.pushUrl({ - // url: 'pages/Register', - // }, router.RouterMode.Single); - }else { - globalThis.carInfo=res.obtainCarExamInfoRsp.body - console.log('globalThis.carInfo',JSON.stringify(globalThis.carInfo)); - // globalThis.carInfo.carId=res.obtainCarExamInfoRsp.body.carId - globalThis.carInfo.plateNo = decodeURIComponent(globalThis.carInfo.plateNo) - } - return res + let date = new Date(); + let params = { time: dateFormat(date), deviceNo: globalThis.deviceNo }; + let res: any = await obtainCarExamInfo(params) + if (!res?.obtainCarExamInfoRsp?.body) { + // router.pushUrl({ + // url: 'pages/Register', + // }, router.RouterMode.Single); + } else { + globalThis.carInfo = res.obtainCarExamInfoRsp.body + console.log('globalThis.carInfo', JSON.stringify(globalThis.carInfo)); + // globalThis.carInfo.carId=res.obtainCarExamInfoRsp.body.carId + globalThis.carInfo.plateNo = decodeURIComponent(globalThis.carInfo.plateNo) + } + return res } \ No newline at end of file diff --git a/entry/src/main/ets/config/global.ts b/entry/src/main/ets/config/global.ts index 4e939ecc..398a2bd8 100644 --- a/entry/src/main/ets/config/global.ts +++ b/entry/src/main/ets/config/global.ts @@ -10,5 +10,5 @@ export const GlobalConfig={ comoonfileWriteAddress:'/mnt/hmdfs/100/account/device_view/local/files', picSavePath:'/storage/cloud/100/files/Photo/', videoSavePath:'/storage/cloud/100/files/Videos/', - host:'http://172.37.55.191:8082' + host:'http://172.37.55.1912:8082' } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index ee0a64cb..70ade659 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -161,7 +161,7 @@ struct Index { ) ) - Text('考车号:' + globalThis.deviceNo) + Text('考车号:' + this.deviceId) .fontColor('#CCAE7A') .fontSize(22 * globalThis.ratio) .margin({ right: 24 }) @@ -212,7 +212,6 @@ struct Index { } aboutToAppear() { - globalThis.ratio = 1700 / 960 this.angle = 0 this.loading = false this.vocObj = new voiceService(async (status, val, next) => { @@ -338,13 +337,14 @@ struct Index { async initParams() { this.loading = false - await getDeviceInfo() - getCarInfo() + this.deviceId=await getDeviceInfo(this.context) || '' + await getCarInfo() await setCurrentTime(); this.carNum = globalThis.carInfo.plateNo; this.version = globalThis.version; this.hasAuth = globalThis.hasAuth; initJudgeUdp() + console.log('deviceIddeviceId',globalThis.deviceNo,this.deviceNo) //下载模型 // await this.getModel() // const arr = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00] diff --git a/entry/src/main/ets/pages/Register.ets b/entry/src/main/ets/pages/Register.ets index 4619b448..151948aa 100644 --- a/entry/src/main/ets/pages/Register.ets +++ b/entry/src/main/ets/pages/Register.ets @@ -4,6 +4,8 @@ import { dateFormat } from '../common/utils/tools' import deviceManager from '@ohos.distributedHardware.deviceManager' import { upDateTableByArray } from '../common/service/initable' import promptAction from '@ohos.promptAction' +import FileUtil from '../common/utils/File' +import common from '@ohos.app.ability.common'; @Entry @Component @@ -17,6 +19,7 @@ export default struct Index { @State plateNo: string = '' @State @Watch('outClick') outFlag: boolean = false; @State subType: string = '2'; + private context = getContext(this) as common.UIAbilityContext; onPageShow() { // this.plateNo=globalThis.carInfo.plateNo @@ -111,15 +114,19 @@ export default struct Index { outClick() { } - registrationDeviceNoFn() { + async registrationDeviceNoFn() { const date = new Date() const param = { time: dateFormat(date), deviceName: this.ip, type: '1' } + const fileUtil = new FileUtil(this.context) + const folderPath = await fileUtil.initFolder(`/config`); + fileUtil.addFile(`${folderPath}/deviceNo.txt`, JSON.stringify(param)) globalThis.deviceNo = this.ip - upDateTableByArray('DeviceInfoTable', [{ deviceId: this.ip }]) + console.log('globalThis.deviceNo',globalThis.deviceNo) + // upDateTableByArray('DeviceInfoTable', [{ deviceId: this.ip }]) registrationDeviceNo(param).then(res => { if (res.registrationDeviceNoRsp.head.resultCode == '0') { promptAction.showToast({