diff --git a/entry/src/main/ets/common/utils/RemotetoolWebsocket.ets b/entry/src/main/ets/common/utils/RemotetoolWebsocket.ets index ebfae574..7713fd45 100644 --- a/entry/src/main/ets/common/utils/RemotetoolWebsocket.ets +++ b/entry/src/main/ets/common/utils/RemotetoolWebsocket.ets @@ -9,7 +9,6 @@ import appRecovery from '@ohos.app.ability.appRecovery'; import power from '@ohos.power'; import preferences from '@ohos.data.preferences'; - export const gpsConfig = [ { label: "差分状态", prop: "cfzt" }, { label: "经纬度收星数", prop: "sxs" }, @@ -71,6 +70,18 @@ enum EventCode { Reply } +enum ButtonEventType { + Single, + Double, + LongPress +} + +interface ToolEvent { + code: EventCode, + data: T + id?: string +} + interface FileInfo { fileName: string lastUpdateTime: string @@ -85,6 +96,13 @@ interface PlatformEvent { data: T } +interface ButtonParams { + type: ButtonEventType + button: number + page: number +} + +export type CommandCallback = (button: number, reply: (result: number) => void) => void const Tag = "[websocket]" const SystemLogDir = "/data/log/hilog" @@ -208,6 +226,10 @@ export class RemoteToolWebsocket { page: number, cb: () => void }> = [] + private onButtonCallback: Array<{ + page: number, + cb: CommandCallback + }> = [] public isStart: boolean = false private isRegister: boolean = false private context: common.UIAbilityContext @@ -374,6 +396,34 @@ export class RemoteToolWebsocket { this.sendReply(this.serialNumber, data.eventType) break case PlatFormEventType.ToolCommand: + let command = JSON.parse(data.data) as ToolEvent + switch (command.code) { + case EventCode.Data: + break + case EventCode.Button: + let button = JSON.parse(command.data) as ButtonParams + this.onButtonCallback.forEach(item => { + const reply = (result: number) => { + this.sendReply(this.serialNumber, PlatFormEventType.SyncData, JSON.stringify({ + code: EventCode.Reply, + data: JSON.stringify(result), + id: command.id + } as ToolEvent)) + } + if (item.page === button.page) { + item.cb(button.button, reply) + } + }) + break + case EventCode.Router: + break + case EventCode.Function: + break + case EventCode.Reply: + break + default: + return + } break default: console.warn("Unknown event type:", data.eventType); @@ -640,6 +690,17 @@ export class RemoteToolWebsocket { } offStart(page: number) { - this.onStartCallback = this.onStartCallback.filter(item => item.page != page) + this.onStartCallback = this.onStartCallback.filter(item => item.page !== page) + } + + onButton(cb: CommandCallback, page: number) { + this.onButtonCallback.push({ + page, + cb + }) + } + + offButton(page: number) { + this.onButtonCallback = this.onButtonCallback.filter(item => item.page !== page) } } \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 4bf1538f..1f31536e 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -38,7 +38,6 @@ export default class EntryAbility extends UIAbility { async onWindowStageCreate(windowStage: window.WindowStage) { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - await tcpUtil.init() globalThis.tcpStep=0 globalThis.carInfo = {} diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index dc85c930..eaf7ebd7 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -19,7 +19,7 @@ import { delPic } from '../common/service/videoService'; import imageBtn from './compontents/imageBtn'; import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; import { updateModelAndCar } from '../common/autoUpdate/index' -import { RemoteToolWebsocket } from '../common/utils/RemotetoolWebsocket'; +import { CommandCallback, RemoteToolWebsocket } from '../common/utils/RemotetoolWebsocket'; import { UsbUtils } from '../common/utils/UsbUtils'; @@ -30,7 +30,7 @@ struct Index { @State version: string = '' @State url: string = '' @State hasAuth: boolean = false; - @State dialogVisiable: boolean = false; + @State dialogVisible: boolean = false; @State isSingle: boolean = false; @State deviceId: string = ''; @State angle: number = 0 @@ -63,6 +63,15 @@ struct Index { private context = getContext(this) as common.UIAbilityContext; private remoteToolWebsocket: RemoteToolWebsocket = new RemoteToolWebsocket() private usbUtils: UsbUtils = new UsbUtils(this.context) + private onButtonCallback: CommandCallback = (button, reply) => { + switch (button) { + case 1: + this.onNetWork(reply) + break + default: + return + } + } @Styles commStyle(){ @@ -91,7 +100,7 @@ struct Index { Image($r('app.media.btn_back')).width('14.4%').height('12.2%') .onClick(() => { - this.dialogVisiable = true + this.dialogVisible = true }) } } @@ -104,40 +113,8 @@ struct Index { if (!this.isSingle) { imageBtn({ btnWidth: '28%', btnHeight: '71%', imgSrc: $r('app.media.index_lw') }) .margin({ left: 80 * globalThis.ratio }) - .onClick(async () => { - - if (this.loading) { - - return - } - setTimeout(() => { - this.angle = 360 - }, 1000) - this.angle = 0 - if (!globalThis.timeInfo) { - globalThis.type = '1' - globalThis.title = '时间同步接口连接失败' - this.errorDialog.open() - promptAction.showToast({ - message: `时间同步接口连接失败`, - duration: 3000 - }); - this.loading = false - return - } - if (!globalThis.carInfo) { - promptAction.showToast({ - message: `车辆信息接口获取失败`, - duration: 3000 - }); - globalThis.type = '1' - globalThis.title = '车辆信息接口获取失败' - this.errorDialog.open() - this.loading = false - return - } - this.testXMLToJSONInWorker() - + .onClick(() => { + this.onNetWork() }) } if (this.isSingle) { @@ -247,8 +224,7 @@ struct Index { .margin({ bottom: 10 }) } - // - if (this.dialogVisiable) { + if (this.dialogVisible) { Flex({ justifyContent: FlexAlign.Center }) { Text('确认是否退出应用') .fontSize(28 * this.ratio * this.dialogRatio) @@ -262,7 +238,7 @@ struct Index { } .commStyle() .onClick(() => { - this.dialogVisiable = false + this.dialogVisible = false }).margin({ right: 10 * this.ratio }) @@ -312,7 +288,6 @@ struct Index { .backgroundColor('#E6E3DF') .borderRadius(19 * globalThis.ratio) } - if (this.loading) { Column() { Image($r('app.media.open_loading')) @@ -353,13 +328,11 @@ struct Index { } async aboutToAppear() { - - console.log('diyidiy') - + this.remoteToolWebsocket.onButton(this.onButtonCallback, 1) this.avPlayer = new VoiceAnnounce(); this.initParamFlag = false this.delLoading = false - this.dialogVisiable = false + this.dialogVisible = false this.angle = 0 this.loading = false globalThis.lsh = '1111111111111' @@ -386,15 +359,46 @@ struct Index { } aboutToDisappear() { - // this.vocObj && this.vocObj.releasePlayer() + this.remoteToolWebsocket.offButton(1) } - async testXMLToJSONInWorker() { + onNetWork(cb?: Function) { if (this.loading) { return } + setTimeout(() => { + this.angle = 360 + }, 1000) + this.angle = 0 + if (!globalThis.timeInfo) { + globalThis.type = '1' + globalThis.title = '时间同步接口连接失败' + this.errorDialog.open() + promptAction.showToast({ + message: `时间同步接口连接失败`, + duration: 3000 + }); + this.loading = false + return + } + if (!globalThis.carInfo) { + promptAction.showToast({ + message: `车辆信息接口获取失败`, + duration: 3000 + }); + globalThis.type = '1' + globalThis.title = '车辆信息接口获取失败' + this.errorDialog.open() + this.loading = false + return + } + this.testXMLToJSONInWorker(cb) + } - + async testXMLToJSONInWorker(cb?: Function) { + if (this.loading) { + return + } const param = { carId: globalThis.carInfo?.carId, examinationRoomId: globalThis.carInfo?.examinationRoomId, @@ -448,12 +452,14 @@ struct Index { } if (sys.v_no === '824' && decodeURIComponent(sys.v_value) == '0') { // this.Param612Str= decodeURIComponent(sys.v_value) + cb(1) router.pushUrl({ url: 'pages/CarCheck', params: { 'fromIndex': true } }, router.RouterMode.Single) + } else { router.pushUrl({ url: 'pages/ExaminerLogin', @@ -463,6 +469,8 @@ struct Index { }); } + }).catch(() => { + cb(0) }) } @@ -482,7 +490,7 @@ struct Index { carNo: globalThis.carInfo.carNo, placeId: globalThis.carInfo.examinationRoomId } - // globalThis.udpClient2.initHeartSendMsg(param,this.context) + if (globalThis.udpClient2.getStatus()) { globalThis.udpClient2.sendMsgExt(param, this.context) }