From f2e13a9f3535941be37fe83d1ba7f7a66711c0a8 Mon Sep 17 00:00:00 2001 From: lixiao <932184220@qq.com> Date: Mon, 27 Oct 2025 14:14:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=20=E6=9F=A5=E9=AA=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/api/typings.d.ts | 2 + entry/src/main/ets/pages/control/Index.ets | 27 ++++-- .../main/ets/pages/control/utils/Control.ets | 10 +- entry/src/main/ets/pages/process/Index.ets | 67 +++++++------- entry/src/main/ets/pages/result/Detail.ets | 92 +++++++++++++++++-- entry/src/main/ets/utils/CommandService.ets | 15 ++- 6 files changed, 161 insertions(+), 52 deletions(-) diff --git a/entry/src/main/ets/api/typings.d.ts b/entry/src/main/ets/api/typings.d.ts index 06da8c3..d4b9201 100644 --- a/entry/src/main/ets/api/typings.d.ts +++ b/entry/src/main/ets/api/typings.d.ts @@ -762,6 +762,8 @@ declare namespace API { name?: string; params?: Record; remark?: string; + robotId?: string; + robotIp?: string stationId?: number; status?: string; updateBy?: string; diff --git a/entry/src/main/ets/pages/control/Index.ets b/entry/src/main/ets/pages/control/Index.ets index 0f90173..4fe1a47 100644 --- a/entry/src/main/ets/pages/control/Index.ets +++ b/entry/src/main/ets/pages/control/Index.ets @@ -6,6 +6,8 @@ import { RebootControl } from './utils/Control' import { promptAction, router } from '@kit.ArkUI' import { CommandCode, commandService } from '../../utils/CommandService' import Logger from '../../utils/Logger' +import { getPadRecordInfoUsingGet } from '../../api/padController' +import { getDeviceId } from '../../utils/System' function TouchEventWrapper(callback: Function) { let tick: number = -1 @@ -31,7 +33,7 @@ function TouchEventWrapper(callback: Function) { @Entry struct Control { @State select: number = 0 - @State line: API.VcInspectionLine[] = AppStorage.get("line") || [] + @State line: API.VcInspectionLine[] = [] @State mode: number[] = [] private control: RebootControl = new RebootControl("ws://192.168.7.101:10000") private forward: (event: TouchEvent) => void = TouchEventWrapper(() => { @@ -48,11 +50,20 @@ struct Control { }) async aboutToAppear(): Promise { - await this.control.init() - this.mode = this.line.map(() => 0) - this.control.getMode().then(res => { - Logger.info(res) - this.mode[this.select] = res.mode + this.getPadInfo() + } + + async getPadInfo() { + let deviceId = await getDeviceId() + getPadRecordInfoUsingGet({ imei: deviceId }).then(async (res) => { + this.line = res.data?.lines || [] + this.control = new RebootControl(`ws://${this.line[this.select]?.robotIp}:10000`) + await this.control.init() + this.mode = this.line.map(() => 0) + this.control.getMode().then(res => { + Logger.info(res) + this.mode[this.select] = res.mode + }) }) } @@ -123,11 +134,13 @@ struct Control { ForEach(this.line, (menu: API.VcInspectionLine, index: number) => { CusMenuItem({ text: menu.name, active: this.select === index }) .margin({ bottom: 24 }) - .onClick(() => { + .onClick(async () => { if (this.mode[this.select] === 1) { this.control.setMode(0) } this.select = index + this.control = new RebootControl(`ws://${this.line[this.select]?.robotIp}:10000`) + await this.control.init() }) }) }.width("100%").padding({ left: 24, right: 24 }) diff --git a/entry/src/main/ets/pages/control/utils/Control.ets b/entry/src/main/ets/pages/control/utils/Control.ets index 333628c..24612a0 100644 --- a/entry/src/main/ets/pages/control/utils/Control.ets +++ b/entry/src/main/ets/pages/control/utils/Control.ets @@ -3,6 +3,7 @@ import { TaskPool } from '../../../utils/TaskPool' import { EventType, WebsocketClient } from '../../../utils/WebsocketUtils' import { VehicleBean, VehicleInfo } from './Model' import { BusinessError } from '@kit.BasicServicesKit' +import { promptAction } from '@kit.ArkUI' const Tag = "RebootControl" @@ -58,7 +59,14 @@ export class RebootControl { } setMode(mode: number) { - return this.service.send(JSON.stringify({ mode })) + return new Promise((resolve, reject) => { + this.service.send(JSON.stringify({ mode })).then(resolve).catch((err: BusinessError) => { + promptAction.showToast({ + message: JSON.stringify(err) + }) + reject(err) + }) + }) } destroy() { diff --git a/entry/src/main/ets/pages/process/Index.ets b/entry/src/main/ets/pages/process/Index.ets index 0c7a67a..14d2d28 100644 --- a/entry/src/main/ets/pages/process/Index.ets +++ b/entry/src/main/ets/pages/process/Index.ets @@ -4,20 +4,49 @@ import { Title } from '../components/title/Index' import { promptAction, router } from '@kit.ArkUI' import { getStepListUsingGet } from '../../api/padController' import { CusMenuItem } from './components/MenuItem' -import { CommandCode, commandService } from '../../utils/CommandService' +import { + CommandCode, + commandService, + CommandType, + Message, + PostCurrentStepMessage, +} from '../../utils/CommandService' import Logger from '../../utils/Logger' interface RouterParams { lineId: number } +const Tag = "[Process]" + @Component @Entry struct Process { @State process: API.StepVo[] = [] @State select: number = -1 - @State currentStep: number = 6 + // @State currentStep: number = 0 private lineId: number = -1 + private onProcess = (msg: Message) => { + if (msg.type === CommandType.PostCurrentStep) { + Logger.info(Tag, msg) + if (Number(msg.body.lineId) === this.lineId) { + let current = 0 + for (let i = 0; i < this.process.length; i++) { + if (this.process[i].code === msg.body.stepCode) { + this.process[i].status === "2" + current = i + } else if (i < current) { + this.process[i].status === "1" + } else { + this.process[i].status === "0" + } + } + getStepListUsingGet({ lineId: this.lineId }).then(res => { + this.process = res.data || [] + }) + } + } + } aboutToAppear(): void { const params = router.getParams() as RouterParams; @@ -25,32 +54,11 @@ struct Process { getStepListUsingGet({ lineId: this.lineId }).then(res => { this.process = res.data || [] }) - // getStageAndStepInfoUsingGet().then(res => { - // let len = 0 - // this.process = (res.data || []).map((item) => { - // let result: API.StageAndStepRsp = { - // stageCode: item.stageCode, - // stageId: item.stageId, - // stageName: item.stageName, - // stepList: item.stepList?.map((sub, index) => { - // return { - // code: sub.code, - // id: sub.id, - // name: sub.name, - // orderNo: sub.orderNo, - // stageId: sub.stageId, - // index: len + index + 1 - // } as API.StepVo - // }), - // count: len - // } - // len += item.stepList?.length || 0 - // return result - // }) - // if (this.process.length > 0) { - // this.select = this.process[0].stepList?.[0]?.id || -1 - // } - // }) + commandService.subscribe(this.onProcess) + } + + aboutToDisappear(): void { + commandService.unsubscribe(this.onProcess) } build() { @@ -84,9 +92,6 @@ struct Process { CusMenuItem({ step: step, index: index + 1, - // onSelect: (id) => { - // this.select = id - // } }) }) }.width("100%").padding({ left: 24, right: 24 }) diff --git a/entry/src/main/ets/pages/result/Detail.ets b/entry/src/main/ets/pages/result/Detail.ets index d2cff68..0b53726 100644 --- a/entry/src/main/ets/pages/result/Detail.ets +++ b/entry/src/main/ets/pages/result/Detail.ets @@ -192,14 +192,14 @@ struct Detail { Text("左前45度照片").label() }.margin({ right: 6 }).layoutWeight(1).height("100%") - Stack({ alignContent: Alignment.TopStart }) { - Image(this.rightBackward) - .alt($rawfile("images/vehicle/default.png")) - .width("100%") - .height("100%") - .objectFit(ImageFit.Fill) - Text("右后45度照片").label() - }.margin({ left: 6 }).layoutWeight(1).height("100%") + // Stack({ alignContent: Alignment.TopStart }) { + // Image(this.rightBackward) + // .alt($rawfile("images/vehicle/default.png")) + // .width("100%") + // .height("100%") + // .objectFit(ImageFit.Fill) + // Text("右后45度照片").label() + // }.margin({ left: 6 }).layoutWeight(1).height("100%") }.margin({ right: 6 }).layoutWeight(1) Row() { @@ -223,6 +223,81 @@ struct Detail { Text("左前45度视频").label() }.margin({ right: 6 }).layoutWeight(1).height("100%") + // Stack({ alignContent: Alignment.TopStart }) { + // if (this.rightBackward) { + // VideoPlayer({ + // isFullScreen: this.isFullScreen, + // showPreview: true, + // attribute: { + // preview: $rawfile("images/vehicle/default.png"), + // type: "network" + // }, + // url: this.rightBackward + // }) + // } else { + // Image($rawfile("images/vehicle/default.png")) + // .width("100%") + // .height("100%") + // .objectFit(ImageFit.Fill) + // } + // Text("右后45度视频").label() + // }.margin({ left: 6 }).layoutWeight(1).height("100%") + }.margin({ right: 6 }).layoutWeight(1) + } + .width("100%") + .padding({ left: 6, top: 12, bottom: 12 }) + .height(240) + .margin({ bottom: 18 }) + .backgroundColor(0xE7F3FF) + + Row() { + Column() { + Label({ mode: 2, label: "号牌号码", value: this.data.licensePlateNumber }) + Label({ mode: 2, label: "车辆品牌", value: this.data.vehicleBrandName }) + Label({ mode: 2, label: "车身颜色", value: this.data.vehicleColor }) + }.margin({ right: 6 }).layoutWeight(1).justifyContent(FlexAlign.SpaceBetween).height("100%") + + Row() { + // Stack({ alignContent: Alignment.TopStart }) { + // Image(this.leftForward) + // .alt($rawfile("images/vehicle/default.png")) + // .width("100%") + // .height("100%") + // .objectFit(ImageFit.Fill) + // Text("左前45度照片").label() + // }.margin({ right: 6 }).layoutWeight(1).height("100%") + + Stack({ alignContent: Alignment.TopStart }) { + Image(this.rightBackward) + .alt($rawfile("images/vehicle/default.png")) + .width("100%") + .height("100%") + .objectFit(ImageFit.Fill) + Text("右后45度照片").label() + }.margin({ left: 6 }).layoutWeight(1).height("100%") + }.margin({ right: 6 }).layoutWeight(1) + + Row() { + // Stack({ alignContent: Alignment.TopStart }) { + // if (this.leftForward) { + // VideoPlayer({ + // isFullScreen: this.isFullScreen, + // showPreview: true, + // attribute: { + // preview: $rawfile("images/vehicle/default.png"), + // type: "network" + // }, + // url: this.leftForward + // }) + // } else { + // Image($rawfile("images/vehicle/default.png")) + // .width("100%") + // .height("100%") + // .objectFit(ImageFit.Fill) + // } + // Text("左前45度视频").label() + // }.margin({ right: 6 }).layoutWeight(1).height("100%") + Stack({ alignContent: Alignment.TopStart }) { if (this.rightBackward) { VideoPlayer({ @@ -243,7 +318,6 @@ struct Detail { Text("右后45度视频").label() }.margin({ left: 6 }).layoutWeight(1).height("100%") }.margin({ right: 6 }).layoutWeight(1) - } .width("100%") .padding({ left: 6, top: 12, bottom: 12 }) diff --git a/entry/src/main/ets/utils/CommandService.ets b/entry/src/main/ets/utils/CommandService.ets index bd29715..10a4237 100644 --- a/entry/src/main/ets/utils/CommandService.ets +++ b/entry/src/main/ets/utils/CommandService.ets @@ -5,7 +5,7 @@ import { util } from '@kit.ArkTS'; const Tag = "CommandService" -interface Message { +export interface Message { type: CommandType reqCode: string body: T @@ -22,15 +22,22 @@ interface CommandBody { name: string } -interface ResponseMessage { +export interface ResponseMessage { code: string msg: string } -enum CommandType { +export interface PostCurrentStepMessage { + lineId: string + stepCode: string + stepName: string +} + +export enum CommandType { HandleAlarm = "handleAlarm", PostCmd = "postCmd", - PostCmdRsp = "postCmdRsp" + PostCmdRsp = "postCmdRsp", + PostCurrentStep = "postCurrentStep" } export enum CommandCode {