332 lines
10 KiB
Plaintext
Raw Normal View History

2025-04-10 10:27:28 +08:00
import common from '@ohos.app.ability.common';
import router from '@ohos.router';
2025-04-11 14:08:48 +08:00
import { JudgeConfig } from "../config";
2025-04-10 10:27:28 +08:00
import promptAction from '@ohos.promptAction';
import errorMsgDialog from './compontents/errorMsgDialog';
import imageBtn from './compontents/imageBtn';
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
import { BaseInfoType, centerCallBackMsgType } from '../model/Common';
import {
CarInfoType,
InitializeTheCentralTableType,
MASYSSETTableType,
TimeSynchronizationRspBody
} from '../model';
2025-04-11 15:48:18 +08:00
import { GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils';
2025-04-10 10:27:28 +08:00
import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation';
import { BusinessError } from '@ohos.base';
import { delPic } from '../utils/Video';
import { FileHelper } from '../utils/FileHelp';
import { GetCurrentTime } from '../utils/Common';
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
2025-04-10 15:10:31 +08:00
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
2025-04-10 10:27:28 +08:00
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness';
import { JudgeEmitterInstance } from '../utils/business/UdpEvent';
2025-04-11 10:13:29 +08:00
import { LoadingDialog } from './Index/Loading';
2025-04-11 15:48:18 +08:00
import { ExitDialog } from './Index/ExitDialog'
2025-04-10 10:27:28 +08:00
2025-04-10 09:30:47 +08:00
@Entry
@Component
struct Index {
2025-04-10 10:27:28 +08:00
@State url: string = ''
@State hasAuth: boolean = false;
@State dialogVisible: boolean = false;
@State singlePlay: boolean = false;
@State baseInfo: BaseInfoType = {};
@State deviceId: string = '';
@State angle: number = 0
@State dialogRatio: number = 0.8
@State ratio: number = 1700 / 960
@State delLoading: boolean = false
@State initParamFlag: boolean = false
@State fd: number = -1;
@State carInfo: CarInfoType = {};
@State num: number = 0;
2025-04-10 15:10:31 +08:00
private context = getContext(this) as common.UIAbilityContext;
2025-04-11 10:13:29 +08:00
private fileHelper: FileHelper = new FileHelper(this.context)
private avPlayer: VoiceAnnounce = new VoiceAnnounce(this.context)
private timeInfo: TimeSynchronizationRspBody = {}
private loadingDialog: CustomDialogController = new CustomDialogController({
builder: LoadingDialog(),
customStyle: true,
alignment: DialogAlignment.Center,
autoCancel: false
})
2025-04-11 15:48:18 +08:00
private delDialog: CustomDialogController = new CustomDialogController({
builder: LoadingDialog({
text: "正在清理本地数据,请稍候……"
}),
customStyle: true,
alignment: DialogAlignment.Center,
autoCancel: false
})
private exitDialog: CustomDialogController = new CustomDialogController({
builder: ExitDialog(),
customStyle: true,
alignment: DialogAlignment.Center,
autoCancel: false
})
2025-04-11 10:13:29 +08:00
private errorDialog: CustomDialogController = new CustomDialogController({
2025-04-10 10:27:28 +08:00
builder: errorMsgDialog({
title: AppStorage.get('title'),
type: AppStorage.get('type'),
cancel: () => {
},
confirm: () => {
}
}),
customStyle: true,
alignment: DialogAlignment.Center,
2025-04-11 10:13:29 +08:00
})
@Styles
commStyle(){
.width(220 * this.ratio * this.dialogRatio)
.height(69 * this.ratio * this.dialogRatio)
.backgroundImage($r('app.media.button_nor'))
.backgroundImageSize({ width: '100%', height: '100%' })
}
2025-04-10 10:27:28 +08:00
async aboutToAppear() {
2025-04-11 15:48:18 +08:00
await UseAuth(this.context)
2025-04-10 10:27:28 +08:00
this.ratio = AppStorage.get<BaseInfoType>('baseInfo')?.ratio || 1.4
this.angle = 0
AppStorage.set('lsh', '1111111111111')
JudgeEmitterInstance.init()
GetSyncData<MASYSSETTableType>("MA_SYSSET").then((res: MASYSSETTableType[]) => {
res.forEach((element) => {
if (element.v_no === "305") {
delPic(Number(element.v_value), 1, this.context)
delPic(Number(element.v_value), 2, this.context)
}
});
});
}
async onPageShow(): Promise<void> {
this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')!
2025-04-11 10:13:29 +08:00
await UseAuth(this.context)
this.initParams()
AppStorage.setOrCreate('singlePlay', false)
this.context.resourceManager.getRawFileContent("welcome.wav")
.then(() => {
this.avPlayer.playAudio(['welcome.wav'])
})
.catch((error: BusinessError) => {
console.log("getRawFileContent promise error is " + error);
});
2025-04-10 10:27:28 +08:00
this.num = 0
AppStorage.setOrCreate('lsh', '1111111111111')
}
2025-04-11 15:48:18 +08:00
exam() {
this.loadingDialog.open()
if (!this.timeInfo) {
AppStorage.setOrCreate('type', 1)
AppStorage.setOrCreate('title', '时间同步接口连接失败')
this.errorDialog.open()
promptAction.showToast({
message: `时间同步接口连接失败`,
duration: 3000
});
this.loadingDialog.close()
return
}
if (!this.carInfo) {
promptAction.showToast({
message: `车辆信息接口获取失败`,
duration: 3000
});
AppStorage.setOrCreate('type', 1)
AppStorage.setOrCreate('title', '车辆信息接口获取失败')
this.errorDialog.open()
this.loadingDialog.close()
return
}
this.testXMLToJSONInWorker()
}
practice() {
if (JudgeConfig.isTrajectoryOpen) {
router.pushUrl({
url: 'pages/UserInfo',
}, router.RouterMode.Single)
return
}
//判断数据库是否有表数据,有则直接跳转,没有则读取本地数据
GetSyncData<MASYSSETTableType>('MA_SYSSET').then((data: Array<MASYSSETTableType>) => {
if (data?.[0]) {
router.pushUrl({
url: 'pages/UserInfo',
}, router.RouterMode.Single)
} else {
this.testXMLToJSONInWorker()
}
});
}
2025-04-10 10:27:28 +08:00
async testXMLToJSONInWorker() {
const param: InitializeTheCentralTableType = {
carId: this.carInfo?.carId,
examinationRoomId: this.carInfo?.examinationRoomId,
judgeVersion: this.baseInfo?.judgeVersion,
2025-04-10 15:10:31 +08:00
shellVersion: this.baseInfo?.version || "",
2025-04-10 10:27:28 +08:00
paraKdid: this.timeInfo?.paraKdid || this.timeInfo?.kdid,
kdid: this.timeInfo?.kdid || this.timeInfo?.paraKdid,
mode: this.timeInfo?.mode,
context: this.context,
host: AppStorage.get<string>('host'),
centerHost: this.timeInfo?.url,
singlePlay: this.singlePlay
}
InitializeTheCentralTable(param).then((ret) => {
2025-04-11 10:13:29 +08:00
this.loadingDialog.close()
2025-04-10 10:27:28 +08:00
if (ret) {
GetSyncData<MASYSSETTableType>("MA_SYSSET").then(data => {
data.forEach(sys => {
//判断是否能点开始考试
if (sys.v_no === '854') {
AppStorage.setOrCreate('param854Str', sys.v_value)
}
if (sys.v_no === '824' && decodeURIComponent(sys.v_value || '') == '0') {
router.pushUrl({
url: 'pages/CarCheck',
params: {
'fromIndex': true
}
}, router.RouterMode.Single)
} else {
router.pushUrl({
url: 'pages/ExaminerLogin',
}, router.RouterMode.Single)
}
})
});
}
})
}
async createAlbum() {
const time = GetCurrentTime()
const date = time.split(' ')[0]
this.fileHelper.createAlbum('jt')
this.fileHelper.createAlbum('pz');
this.fileHelper.createAlbum(date);
}
async initParams() {
2025-04-11 10:13:29 +08:00
console.log("test1111")
2025-04-10 10:27:28 +08:00
ObtainUdpBusinessInstance.init();
2025-04-10 15:10:31 +08:00
CenterUDPBusinessInstance.init();
CenterUDPBusinessInstance.onMsg((data: centerCallBackMsgType) => {
2025-04-10 10:27:28 +08:00
if (data.id == 32) {
AppStorage.setOrCreate('signNum', data.body[1])
}
},)
await GetDeviceInfo(this.context)
await GetCarInfo()
// getTCP()
this.carInfo = AppStorage.get<CarInfoType>('carInfo')!
this.deviceId = this.carInfo.carNo || ""
await SetCurrentTime()
this.timeInfo = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')!
DrivingDataStorage.init(this.context)
DrivingDataStorage.initializeTheDrivingDataFolder()
JudgeUdpBusinessInstance.init()
// TODO 摄像头遮挡
// takePhotoFn(this.context)
2025-04-11 15:48:18 +08:00
// TODO
// CenterUDPBusinessInstance.startHeartBeat()
2025-04-10 10:27:28 +08:00
this.createAlbum()
}
2025-04-10 09:30:47 +08:00
build() {
2025-04-10 10:27:28 +08:00
Column() {
2025-04-11 15:48:18 +08:00
Row() {
Image($r('app.media.logo')).width('30%').margin({ left: 24 })
2025-04-10 10:27:28 +08:00
Row() {
2025-04-11 15:48:18 +08:00
Image($r('app.media.btn_setting')).width('16.7%')
.onClick(async () => {
2025-04-10 10:27:28 +08:00
router.pushUrl({
2025-04-11 15:48:18 +08:00
url: 'pages/Settings',
2025-04-10 10:27:28 +08:00
}, router.RouterMode.Single);
})
2025-04-11 15:48:18 +08:00
Image($r('app.media.btn_back')).width('14.4%')
.onClick(() => {
this.exitDialog.open()
})
2025-04-10 10:27:28 +08:00
}
}
2025-04-11 15:48:18 +08:00
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
2025-04-10 10:27:28 +08:00
2025-04-11 15:48:18 +08:00
Row() {
imageBtn({ btnWidth: '28%', imgSrc: this.singlePlay ? $r('app.media.index_dj') : $r('app.media.index_lw') })
.margin({ left: 80 * this.ratio })
.onClick(() => {
if (this.singlePlay) {
this.practice()
} else {
this.exam()
2025-04-10 10:27:28 +08:00
}
2025-04-11 15:48:18 +08:00
})
imageBtn({ btnWidth: '28%', imgSrc: $r('app.media.index_zj') })
.margin({ right: 80 * this.ratio })
.onClick(() => {
router.pushUrl({
url: 'pages/CarCheck'
}, router.RouterMode.Single);
})
2025-04-10 10:27:28 +08:00
}
2025-04-11 15:48:18 +08:00
.padding({ top: 30, bottom: 30 })
.layoutWeight(1)
.width('100%')
.justifyContent(FlexAlign.SpaceAround)
Row() {
2025-04-10 10:27:28 +08:00
Column() {
2025-04-11 15:48:18 +08:00
Text('V外壳' + this.baseInfo?.version)
.fontColor('#CCAE7A')
.fontSize(28)
.width('30%')
.margin({ bottom: 10 })
Text('V评判' + this.baseInfo.judgeVersion)
.fontColor('#CCAE7A')
.fontSize(28)
.width('30%')
.margin({ bottom: 10 })
2025-04-10 10:27:28 +08:00
2025-04-11 15:48:18 +08:00
Text('授权信息:' + (this.baseInfo.hasAuth ? '已授权' : '未授权'))
.fontColor('#CCAE7A')
.fontSize(28)
.width('30%')
2025-04-10 10:27:28 +08:00
}
2025-04-11 15:48:18 +08:00
.margin({ left: 24 })
.gesture(
GestureGroup(GestureMode.Exclusive,
TapGesture({ count: 2 })
.onAction(() => {
this.singlePlay = !this.singlePlay
AppStorage.setOrCreate('singlePlay', this.singlePlay)
})
)
)
Text('考车号:' + this.deviceId)
.fontColor('#CCAE7A')
.fontSize(36)
.margin({ right: 24 })
2025-04-10 10:27:28 +08:00
}
2025-04-11 15:48:18 +08:00
.padding({ top: 10, bottom: 10 })
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
2025-04-10 09:30:47 +08:00
}
2025-04-10 10:27:28 +08:00
.width('100%')
2025-04-10 09:30:47 +08:00
.height('100%')
2025-04-10 10:27:28 +08:00
.justifyContent(FlexAlign.SpaceBetween)
.backgroundImage($r('app.media.index_bg'))
2025-04-10 09:30:47 +08:00
}
}