diff --git a/entry/src/main/ets/api/typings.d.ts b/entry/src/main/ets/api/typings.d.ts index 2c8ff2b..c965b28 100644 --- a/entry/src/main/ets/api/typings.d.ts +++ b/entry/src/main/ets/api/typings.d.ts @@ -246,6 +246,7 @@ declare namespace API { orderByColumn?: string; pageNum?: number; pageSize?: number; + serialNumber?: string reasonable?: boolean; /** 查验结果 */ results?: string; @@ -688,7 +689,7 @@ declare namespace API { /** 其他移动:轮胎左侧转向、备胎移出等 */ otherMove?: string; /** padId */ - padId?: number; + padId?: string; pageNum?: number; pageSize?: number; /** 铭牌照片 */ diff --git a/entry/src/main/ets/pages/Login.ets b/entry/src/main/ets/pages/Login.ets index 8ecc9b2..43637d7 100644 --- a/entry/src/main/ets/pages/Login.ets +++ b/entry/src/main/ets/pages/Login.ets @@ -80,20 +80,26 @@ struct Index { let deviceId = await getDeviceId() - this.controller.open() - - padLoginUsingPost({ - username: this.account, - password: this.password, - imei: deviceId - }).then((res) => { - AppStorage.setOrCreate("padId", res.data?.padId!) - router.pushUrl({ - url: "pages/home/Index" - }) - }).finally(() => { - this.controller.close() + router.pushUrl({ + // url: "pages/home/Index" + url: "pages/vehicle/Add" }) + + // this.controller.open() + // + // + // padLoginUsingPost({ + // username: this.account, + // password: this.password, + // imei: deviceId + // }).then((res) => { + // AppStorage.setOrCreate("padId", res.data?.padId!) + // router.pushUrl({ + // url: "pages/home/Index" + // }) + // }).finally(() => { + // this.controller.close() + // }) } build() { diff --git a/entry/src/main/ets/pages/vehicle/Add.ets b/entry/src/main/ets/pages/vehicle/Add.ets index 85ee130..069eb42 100644 --- a/entry/src/main/ets/pages/vehicle/Add.ets +++ b/entry/src/main/ets/pages/vehicle/Add.ets @@ -2,6 +2,7 @@ import { promptAction, router } from '@kit.ArkUI' import { saveVinPositionUsingPost } from '../../api/vehicleCollectionController' import { Option } from '../../typings/Common' import { CusButton } from '../components/button/Index' +import { CusInput } from '../components/input/Index' import { Layout } from '../components/layout/Index' import { Title } from '../components/title/Index' import { Card } from './component/Card' @@ -115,9 +116,35 @@ struct Add { @State picture3: string = "" @State picture4: string = "" @State otherInput: string = "" + @State factoryName: string = '' + @State brandName: string = '' + @State model: string = '' + @State year: string = '' + @State month: string = '' aboutToAppear(): void { this.setup() + let data: API.InspectRecordResultRsp = router.getParams() + if (data?.factoryName) { + this.base[0].value = data?.factoryName || "" + this.base[0].init = true + } + if (data?.brandName) { + this.base[1].value = data?.brandName || "" + this.base[1].init = true + } + if (data?.model) { + this.base[2].value = data?.model || "" + this.base[2].init = true + } + if (data?.factoryName) { + this.base[3].value = data?.factoryName || "" + this.base[3].init = true + } + if (data?.factoryName) { + this.base[4].value = data?.factoryName || "" + this.base[4].init = true + } } setup() { @@ -181,7 +208,6 @@ struct Add { return; } - if (!this.vehicleIdentityPosition) { promptAction.showToast({ message: "请选择铭牌位置" @@ -226,11 +252,11 @@ struct Add { const data: API.VehicleCollectionReq = { - brandName: this.base[1].value, - factoryName: this.base[0].value, - model: this.base[2].value, - year: this.base[3].value, - month: this.base[4].value, + factoryName: this.factoryName ?? this.base[0].value, + brandName: this.brandName ?? this.base[1].value, + model: this.model ?? this.base[2].value, + year: this.year ?? this.base[3].value, + month: this.month ?? this.base[4].value, platePhotoUrl: "", platePosition: this.nameplatePosition, @@ -273,21 +299,35 @@ struct Add { Scroll() { Column() { Flex({ justifyContent: FlexAlign.SpaceBetween }) { - ForEach(this.base, (item: Option) => { + ForEach(this.base, (item: Option, index: number) => { Row() { Text(item.label).fontSize(20).fontColor(0x1D2B80).margin({ right: 12 }) - Text(item.value) - .fontSize(20) - .fontColor(0x1D2B80) - .backgroundColor(0xeeeeee) - .border({ width: 1, color: 0xe5e5e5, radius: 5 }) - .padding({ - left: 12, - top: 6, - right: 12, - bottom: 6 - }) - } + if (item.init) { + Text(item.value) + .fontSize(20) + .fontColor(0x1D2B80) + .backgroundColor(0xeeeeee) + .border({ width: 1, color: 0xe5e5e5, radius: 5 }) + .padding({ + left: 12, + top: 6, + right: 12, + bottom: 6 + }) + } else { + if (index === 0) { + CusInput({ value: this.factoryName }).height(32).layoutWeight(1) + } else if (index === 1) { + CusInput({ value: this.brandName }).height(32).layoutWeight(1) + } else if (index === 2) { + CusInput({ value: this.model }).height(32).layoutWeight(1) + } else if (index === 3) { + CusInput({ value: this.year }).height(32).layoutWeight(1) + } else if (index === 4) { + CusInput({ value: this.month }).height(32).layoutWeight(1) + } + } + }.layoutWeight(1).padding({ left: 12 }) }) }.margin({ bottom: 18 }) diff --git a/entry/src/main/ets/pages/vehicle/Index.ets b/entry/src/main/ets/pages/vehicle/Index.ets index 33fd241..fdbf751 100644 --- a/entry/src/main/ets/pages/vehicle/Index.ets +++ b/entry/src/main/ets/pages/vehicle/Index.ets @@ -12,23 +12,25 @@ import { getInspectResultListUsingPost } from '../../api' struct Vehicle { @State columns: Array = [] @State data: Array = [] - @State total: number = 500 + @State total: number = 0 @State loading: boolean = false @State date: string[] = [] @State line: string = "" @State state: string = "" @State step: string = "" @State status: string = "" - @State keyword: string = "" + @State serialNumber: string = "" + @State name: string = "" @State currentPage: number = 1 private pageSize: number = 10 private pageSizes: number[] = [10, 20, 30, 50] @Builder - buildOperate(_row: API.InspectRecordResultRsp) { + buildOperate(row: API.InspectRecordResultRsp) { Image($rawfile("images/detail.png")).objectFit(ImageFit.Contain).width(80).height(30).onClick(() => { router.pushUrl({ - url: "pages/vehicle/Add" + url: "pages/vehicle/Add", + params: row }) }) } @@ -44,12 +46,12 @@ struct Vehicle { { title: "查验日期", prop: "createTime", width: 1, }, { title: "流水号", prop: "serialNumber", width: 1, }, { title: "业务类型", prop: "businessType", width: 1, }, - { title: "号牌种类", prop: "vin", width: 1, }, + // { title: "号牌种类", prop: "vin", width: 1, }, { title: "车辆品牌", prop: "brandName", width: 1, }, { title: "型号", prop: "model", width: 1, }, - // { title: "生产厂家", prop: "factoryName", width: 1.5, }, - // { title: "生产年月", prop: "step", width: 1, }, - // { title: "车主姓名", prop: "step", width: 1, }, + { title: "生产厂家", prop: "factoryName", width: 1.5, }, + { title: "生产年月", prop: "step", width: 1, }, + { title: "车主姓名", prop: "step", width: 1, }, { title: "操作", prop: "", @@ -59,7 +61,6 @@ struct Vehicle { } }, ] - this.total = 500 this.getData() } @@ -70,6 +71,7 @@ struct Vehicle { inspectEndDate: this.date[1], pageNum: this.currentPage, pageSize: this.pageSize, + serialNumber: this.serialNumber, unMatch: "1" }).then(res => { this.data = res.rows || [] @@ -87,7 +89,8 @@ struct Vehicle { this.state = "" this.step = "" this.status = "" - this.keyword = "" + this.serialNumber = "" + this.name = "" } build() { @@ -104,8 +107,8 @@ struct Vehicle { Row() { DateRangePicker({ placeHolder: "日期", value: this.date }).margin({ right: 12 }).layoutWeight(2) - CusInput({ value: this.keyword, placeHolder: "流水号" }).margin({ right: 12 }).layoutWeight(1) - CusInput({ value: this.keyword, placeHolder: "车主姓名" }).margin({ right: 12 }).layoutWeight(1) + CusInput({ value: this.serialNumber, placeHolder: "流水号" }).margin({ right: 12 }).layoutWeight(2) + CusInput({ value: this.name, placeHolder: "车主姓名" }).margin({ right: 12 }).layoutWeight(1) Row().layoutWeight(2) CusButton({ normalImage: $rawfile("images/search.png"), diff --git a/entry/src/main/ets/typings/Common.ets b/entry/src/main/ets/typings/Common.ets index d7e72c9..9a0783e 100644 --- a/entry/src/main/ets/typings/Common.ets +++ b/entry/src/main/ets/typings/Common.ets @@ -1,4 +1,5 @@ export interface Option { label: string value: T + init?: boolean } \ No newline at end of file diff --git a/entry/src/main/ets/utils/CommandService.ets b/entry/src/main/ets/utils/CommandService.ets index de94966..069f16b 100644 --- a/entry/src/main/ets/utils/CommandService.ets +++ b/entry/src/main/ets/utils/CommandService.ets @@ -1,18 +1,52 @@ +import Logger from './Logger'; import { TaskPool } from './TaskPool'; import { WebsocketClient } from './WebsocketUtils'; +import { util } from '@kit.ArkTS'; const Tag = "CommandService" -interface Message { - type: string +interface Message { + type: CommandType reqCode: string - body: object + body: T +} + +interface HandleAlarmBody { + alarmId: string + handleInfo: string +} + +interface CommandBody { + lineId: string + code: string + name: string +} + +interface ResponseMessage { + code: string + msg: string +} + +enum CommandType { + HandleAlarm = "handleAlarm", + PostCmd = "PostCmd" +} + +enum CommandCode { + GetHomePosition = 'getHomePosition', + ToHomePosition = 'toHomePosition', + GetChargePosition = 'getChargePosition', + ToChargePosition = 'toChargePosition', + GetScanPosition = 'getScanPosition', + ToScanPosition = 'toScanPosition', } export class CommandService { private service?: WebsocketClient private taskPool: TaskPool = new TaskPool() private static instance: CommandService + private tick: number = -1 + private commandCallback: Map = new Map() constructor(url: string) { if (!CommandService.instance) { @@ -22,27 +56,41 @@ export class CommandService { return CommandService.instance } - deal(message: string) { - return message + private deal(message: string) { + if (message === "pong") { + Logger.info("心跳回应") + return "" + } else { + try { + let response: Message = JSON.parse(message) + if (response.type === CommandType.PostCmd) { + this.commandCallback.get(response.reqCode)?.(response.body) + this.commandCallback.delete(response.reqCode) + } + return message + } catch (e) { + Logger.error(Tag, "解析报文出错", JSON.stringify(e)) + return "" + } + } } - init() { - return this.service!.connect() - } - - subscribe(cb: Function) { - this.service!.subscribe(cb) - } - - unsubscribe(cb: Function) { - this.service!.unsubscribe(cb) - } - - send(message: Message) { - return new Promise((resolve, reject) => { + private send(message: Message) { + return new Promise((resolve, reject) => { this.taskPool.add({ execute: () => { - return this.service!.send(JSON.stringify(message)) + if (message.type === CommandType.PostCmd) { + return new Promise((_resolve, _reject) => { + this.service!.send(JSON.stringify(message)).then(() => { + this.commandCallback.set(message.reqCode, (res: ResponseMessage) => { + resolve(res) + }) + _resolve(true) + }).catch(_reject) + }) + } else { + return this.service!.send(JSON.stringify(message)) + } }, repair: (): Promise => { return this.service!.reconnect(); @@ -58,9 +106,54 @@ export class CommandService { }) } + init() { + return new Promise((resolve, reject) => { + this.service!.connect().then(() => { + this.tick = setInterval(() => { + this.service?.send("ping") + }, 1000 * 15) + resolve() + }).catch(reject) + }) + } + + subscribe(cb: Function) { + this.service!.subscribe(cb) + } + + unsubscribe(cb: Function) { + this.service!.unsubscribe(cb) + } + close(): Promise { + clearInterval(this.tick) return this.service!.close() } + + submitAlarm(alarmId: string, handleInfo: string): Promise { + let handleBody: HandleAlarmBody = { + alarmId, + handleInfo + } + return this.send({ + type: CommandType.HandleAlarm, + reqCode: util.generateRandomUUID(true), + body: handleBody + }) as Promise + } + + submitCommand(lineId: string, code: CommandCode, name: string): Promise { + let commandBody: CommandBody = { + lineId, + code, + name + } + return this.send({ + type: CommandType.PostCmd, + reqCode: util.generateRandomUUID(true), + body: commandBody + }) as Promise + } } export const commandService = diff --git a/entry/src/main/ets/utils/Logger.ets b/entry/src/main/ets/utils/Logger.ets index 0248045..ff1f2bf 100644 --- a/entry/src/main/ets/utils/Logger.ets +++ b/entry/src/main/ets/utils/Logger.ets @@ -164,5 +164,5 @@ export function readLog(context: common.UIAbilityContext) { export function uploadLog(context: common.UIAbilityContext) { let path = context.filesDir + '/logs/2025_09_25/14_25_31.331.log' - uploadFile(context, "http://192.168.67.190:8088/common/upload", path) + uploadFile(context, path) } \ No newline at end of file diff --git a/entry/src/main/ets/utils/Request.ets b/entry/src/main/ets/utils/Request.ets index 8b6ce0f..bb9771d 100644 --- a/entry/src/main/ets/utils/Request.ets +++ b/entry/src/main/ets/utils/Request.ets @@ -40,6 +40,8 @@ export async function request( ): Promise { const httpRequest = http.createHttp(); return new Promise((resolve, reject) => { + Logger.info(Tag, + `开始请求接口 ${url}, query: ${JSON.stringify(config.params)}, data: ${JSON.stringify(config.data)}`) httpRequest.request(BaseUrl + url, { method: config.method, @@ -48,29 +50,21 @@ export async function request( }, extraData: config.method == "POST" ? config.data : config.params, expectDataType: http.HttpDataType.OBJECT, - connectTimeout: 60000, //超时时间 + connectTimeout: 1000 * 6, //超时时间 }).then(async (data) => { let result = data.result as Response - Logger.info(Tag, `request url ${url} result: `, JSON.stringify(data.result)) + Logger.info(Tag, `请求接口 ${url} 成功, 请求结果: `, JSON.stringify(data.result)) if (result.code === 200) { - if (new RegExp("robotLogin").test(url)) { - try { - token = result.data['token'] - } catch (err) { - let e: BusinessError = err as BusinessError; - Logger.error(Tag, JSON.stringify(e)) - } - } resolve(data.result as T) } else { - Logger.error(Tag, "error message receive: ", url, result.msg) + Logger.error(Tag, `请求接口 ${url} 失败, 失败原因: `, result.msg) promptAction.showToast({ message: result.msg }) reject(result.msg) } }).catch((err: BusinessError) => { - Logger.error(Tag, "error request url: ", BaseUrl + url, err.message) + Logger.error(Tag, `请求接口 ${url} 异常, 异常原因: `, JSON.stringify(err)) promptAction.showToast({ message: '网络异常' }) @@ -82,7 +76,7 @@ export async function request( } -export async function uploadFile(context: common.UIAbilityContext, url: string, path: string) { +export async function uploadFile(context: common.UIAbilityContext, path: string) { if (!fs.accessSync(path)) { Logger.error(Tag, "UPLOAD FILE ERROR: ", "上传文件不存在") return Promise.reject("上传文件不存在") @@ -95,7 +89,7 @@ export async function uploadFile(context: common.UIAbilityContext, url: string, try { return new Promise((resolve, reject) => { sysRequest.uploadFile(context, { - url: BaseUrl + url, + url: BaseUrl + "/car-inspection-rest/device/uploadPhoto.do", header: { 'Accept': '*/*', 'Content-Type': 'multipart/form-data' }, method: http.RequestMethod.POST, files: [