2025-04-10 09:30:47 +08:00
|
|
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
2025-04-10 10:27:28 +08:00
|
|
|
import hilog from '@ohos.hilog';
|
2025-04-10 09:30:47 +08:00
|
|
|
import window from '@ohos.window';
|
2025-04-10 10:27:28 +08:00
|
|
|
import { GlobalConfig } from '../config/global';
|
|
|
|
|
import Want from '@ohos.app.ability.Want';
|
|
|
|
|
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
|
|
|
|
import { BaseInfoType, CarInfoType, EnvironmentConfigurationType, ExaminerInfoType } from '../model';
|
|
|
|
|
import DB from '../utils/DbSql';
|
|
|
|
|
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
|
|
|
|
|
import { InitTable } from '../utils/table/Operation';
|
|
|
|
|
import FileUtils from '../utils/FileUtils';
|
2025-04-10 09:30:47 +08:00
|
|
|
|
|
|
|
|
export default class EntryAbility extends UIAbility {
|
2025-04-10 10:27:28 +08:00
|
|
|
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
|
|
|
|
try {
|
|
|
|
|
console.log("sql first")
|
|
|
|
|
await DB.init(this.context)
|
|
|
|
|
await InitTable()
|
|
|
|
|
console.log("sql first success")
|
|
|
|
|
let fileUtil = new FileUtils(this.context)
|
|
|
|
|
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
|
|
|
|
if (data !== '' && data !== undefined) {
|
|
|
|
|
const result: EnvironmentConfigurationType = JSON.parse(data)
|
|
|
|
|
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result)
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('sql first error', e)
|
|
|
|
|
}
|
2025-04-10 09:30:47 +08:00
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 10:27:28 +08:00
|
|
|
onDestroy() {
|
|
|
|
|
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
|
|
|
|
|
// TODO UDP缺失
|
|
|
|
|
// lightUDPClient.sendMsg(new Uint8Array(arrClose).buffer)
|
|
|
|
|
DrivingDataStorage.close()
|
2025-04-10 09:30:47 +08:00
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 10:27:28 +08:00
|
|
|
async onWindowStageCreate(windowStage: window.WindowStage) {
|
2025-04-10 09:30:47 +08:00
|
|
|
// Main window is created, set main page for this ability
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
2025-04-10 15:10:31 +08:00
|
|
|
const windowClass = await windowStage.getMainWindow();
|
|
|
|
|
let rect = windowClass.getWindowProperties().windowRect
|
|
|
|
|
let width = rect.width
|
|
|
|
|
let height = rect.height
|
|
|
|
|
console.log("log", width, height)
|
2025-04-10 10:27:28 +08:00
|
|
|
AppStorage.setOrCreate<CarInfoType>('carInfo', {})
|
|
|
|
|
AppStorage.setOrCreate<ExaminerInfoType>('examinerInfo', {})
|
|
|
|
|
AppStorage.setOrCreate<string>('lsh', '0000000000000')
|
|
|
|
|
AppStorage.setOrCreate<string>('statue', "1") //考试状态
|
|
|
|
|
AppStorage.setOrCreate<number>('signNum', 0) //心跳指令编号
|
|
|
|
|
AppStorage.setOrCreate<string>('deviceNo', "") //设备号
|
|
|
|
|
AppStorage.setOrCreate<BaseInfoType>('baseInfo', {
|
|
|
|
|
hasAuth: false,
|
|
|
|
|
version: GlobalConfig.version.jn.km3[0] || "",
|
|
|
|
|
judgeVersion: GlobalConfig.version.jn.km3[1] || "",
|
|
|
|
|
tcpSendNum: 0,
|
|
|
|
|
videoVersion: '1.0',
|
2025-04-10 15:10:31 +08:00
|
|
|
ratio: width / height, //适配比例
|
2025-04-10 10:27:28 +08:00
|
|
|
pathDir: this.context.filesDir,
|
|
|
|
|
context: this.context,
|
|
|
|
|
isJudgeInitBool: false,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AppStorage.setOrCreate('windowClass', windowClass)
|
|
|
|
|
await windowClass.setWindowSystemBarEnable([]) //全屏
|
|
|
|
|
windowStage.loadContent('pages/Index', (err, data) => {
|
2025-04-10 09:30:47 +08:00
|
|
|
if (err.code) {
|
|
|
|
|
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-04-10 10:27:28 +08:00
|
|
|
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
2025-04-10 09:30:47 +08:00
|
|
|
});
|
2025-04-10 10:27:28 +08:00
|
|
|
|
|
|
|
|
this.creatFiles();
|
2025-04-10 09:30:47 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-10 10:27:28 +08:00
|
|
|
onWindowStageDestroy() {
|
2025-04-10 09:30:47 +08:00
|
|
|
// Main window is destroyed, release UI related resources
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 10:27:28 +08:00
|
|
|
onForeground() {
|
2025-04-10 09:30:47 +08:00
|
|
|
// Ability has brought to foreground
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 10:27:28 +08:00
|
|
|
onBackground() {
|
2025-04-10 09:30:47 +08:00
|
|
|
// Ability has back to background
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
|
|
|
|
}
|
2025-04-10 10:27:28 +08:00
|
|
|
|
|
|
|
|
creatFiles() {
|
|
|
|
|
}
|
|
|
|
|
}
|