254 lines
8.1 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-06-25 13:38:13 +08:00
import { HomeTag, InitTableTag, JudgeConfig } from '../config';
2025-04-10 10:27:28 +08:00
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
2025-06-11 17:50:37 +08:00
import { BaseInfoType } from '../model/Common';
2025-04-14 18:13:34 +08:00
import { CarInfoType, InitializeTheCentralTableType, MASYSSETTableType, TimeSynchronizationRspBody } from '../model';
2025-06-25 10:35:33 +08:00
import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime } 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 { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
import { JudgeEmitterInstance } from '../utils/business/UdpEvent';
2025-04-14 18:13:34 +08:00
import HeaderComponent from './compontents/Header';
import CardComponent from './Index/Card';
import BottomMessageComponent from './Index/BottomMessage';
import LoadingComponent from './Index/Loading';
import Prompt from '@system.prompt';
import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignalWorker';
2025-06-23 15:31:58 +08:00
import { dConsole } from '../utils/LogWorker';
2025-04-10 10:27:28 +08:00
2025-06-23 17:08:25 +08:00
@Entry
2025-04-10 09:30:47 +08:00
@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-06-18 14:15:05 +08:00
@State isPlay: boolean = false;
2025-06-19 16:53:49 +08:00
@State initWork: boolean = false
2025-04-14 18:13:34 +08:00
// 请求网络表等待弹窗
customDialogController: CustomDialogController = new CustomDialogController({
builder: LoadingComponent(),
customStyle: true,
alignment: DialogAlignment.Center,
autoCancel: true
});
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 = {}
@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-06-25 10:35:33 +08:00
dConsole.log("权限首页 aboutToAppear")
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> {
2025-06-25 10:35:33 +08:00
dConsole.log("权限首页 onPageShow2")
2025-06-18 14:15:05 +08:00
if (!this.isPlay) {
this.avPlayer.playAudio(['welcome.wav'])
this.isPlay = true
}
2025-06-06 13:37:15 +08:00
this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')!
2025-04-11 10:13:29 +08:00
this.initParams()
2025-06-13 13:23:41 +08:00
2025-04-11 10:13:29 +08:00
AppStorage.setOrCreate('singlePlay', false)
2025-04-10 10:27:28 +08:00
this.num = 0
AppStorage.setOrCreate('lsh', '1111111111111')
}
2025-04-14 18:13:34 +08:00
// 联网考试逻辑处理
onlineExam() {
this.customDialogController.open()
2025-04-11 15:48:18 +08:00
if (!this.timeInfo) {
Prompt.showToast({
2025-04-11 15:48:18 +08:00
message: `时间同步接口连接失败`,
duration: 3000
});
2025-04-14 18:13:34 +08:00
this.customDialogController.close()
2025-04-11 15:48:18 +08:00
return
}
if (!this.carInfo) {
Prompt.showToast({
2025-04-11 15:48:18 +08:00
message: `车辆信息接口获取失败`,
duration: 3000
});
2025-04-14 18:13:34 +08:00
this.customDialogController.close()
2025-04-11 15:48:18 +08:00
return
}
this.initializationTableRelated()
2025-04-11 15:48:18 +08:00
}
2025-04-14 18:13:34 +08:00
// 单机训练逻辑处理
singlePlayerTraining() {
2025-04-11 17:09:27 +08:00
AppStorage.setOrCreate('singlePlay', true)
2025-04-11 15:48:18 +08:00
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.initializationTableRelated()
2025-04-11 15:48:18 +08:00
}
});
}
async initializationTableRelated() {
2025-04-10 10:27:28 +08:00
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-06-25 13:38:13 +08:00
dConsole.log(InitTableTag, "初始化表成功", ret)
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 {
2025-06-19 16:53:49 +08:00
if (this.singlePlay) {
router.pushUrl({
url: 'pages/UserInfo',
}, router.RouterMode.Single)
} else {
router.pushUrl({
url: 'pages/ExaminerLogin',
}, router.RouterMode.Single)
}
2025-04-10 10:27:28 +08:00
}
})
});
} else {
this.customDialogController.close()
2025-04-10 10:27:28 +08:00
}
2025-04-15 17:36:14 +08:00
}).catch((err: BusinessError) => {
2025-06-23 15:31:58 +08:00
dConsole.error("初始化表失败", err)
2025-04-10 10:27:28 +08:00
})
}
async initParams() {
2025-06-23 15:31:58 +08:00
dConsole.log("test1111")
2025-04-15 10:16:33 +08:00
await GetDeviceInfo(this.context)
this.carInfo = await GetCarInfo()
2025-04-10 10:27:28 +08:00
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()
2025-06-17 09:06:18 +08:00
// JudgeUdpBusinessInstance.init()
2025-04-10 10:27:28 +08:00
// TODO 摄像头遮挡
// takePhotoFn(this.context)
2025-04-11 15:48:18 +08:00
// TODO
// CenterUDPBusinessInstance.startHeartBeat()
CreateAlbum(this.fileHelper)
2025-06-13 13:23:41 +08:00
// 启动worker通道
2025-06-19 16:53:49 +08:00
if (!this.initWork) {
DifferentialAndSignal.init()
this.initWork = true
}
2025-06-13 13:23:41 +08:00
DifferentialAndSignal.onMsg(() => {
2025-06-23 15:31:58 +08:00
dConsole.log("外层接受")
2025-06-13 13:23:41 +08:00
})
2025-04-10 10:27:28 +08:00
}
2025-04-10 09:30:47 +08:00
build() {
2025-04-14 18:13:34 +08:00
Flex({
justifyContent: FlexAlign.SpaceBetween,
direction: FlexDirection.Column
}) {
HeaderComponent({
shortLogo: false
})
2025-06-11 17:50:37 +08:00
2025-04-14 18:13:34 +08:00
CardComponent({
isSingle: this.singlePlay,
singleClick: () => {
2025-06-23 15:31:58 +08:00
dConsole.log(HomeTag, "单机模式点击")
2025-04-14 18:13:34 +08:00
this.singlePlayerTraining()
},
networkingClick: () => {
2025-06-23 15:31:58 +08:00
dConsole.log(HomeTag, "联网考试点击")
2025-04-14 18:13:34 +08:00
this.onlineExam()
2025-04-10 10:27:28 +08:00
}
2025-04-14 18:13:34 +08:00
})
2025-04-14 18:13:34 +08:00
BottomMessageComponent({
version: this.baseInfo.version,
judgeVersion: this.baseInfo.judgeVersion,
hasAuth: this.baseInfo.hasAuth,
2025-04-15 10:16:33 +08:00
examCarNumber: this.deviceId,
2025-04-14 18:13:34 +08:00
versionClick: () => {
2025-06-23 15:31:58 +08:00
dConsole.log(HomeTag, "版本号点击事件")
2025-04-14 18:13:34 +08:00
this.singlePlay = !this.singlePlay
AppStorage.setOrCreate('singlePlay', this.singlePlay)
2025-04-10 10:27:28 +08:00
}
2025-04-14 18:13:34 +08:00
})
2025-04-10 09:30:47 +08:00
}
2025-04-14 18:13:34 +08:00
.width("100%")
.height("100%")
2025-04-10 10:27:28 +08:00
.backgroundImage($r('app.media.index_bg'))
2025-04-14 18:13:34 +08:00
.backgroundImageSize({
width: "100%",
height: "100%"
})
2025-04-10 09:30:47 +08:00
}
}