105 lines
4.1 KiB
Plaintext
105 lines
4.1 KiB
Plaintext
import UIAbility from '@ohos.app.ability.UIAbility';
|
|
import hilog from '@ohos.hilog';
|
|
import window from '@ohos.window';
|
|
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';
|
|
import { EntryTag } from '../config';
|
|
import { dConsole } from '../utils/LogWorker';
|
|
import { UseAuth } from '../utils/Common';
|
|
|
|
export default class EntryAbility extends UIAbility {
|
|
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
|
console.log(EntryTag, "多伦鸿蒙车载程序启动")
|
|
await DB.init(this.context)
|
|
try {
|
|
let fileUtil = new FileUtils(this.context)
|
|
// 一些地址配置
|
|
const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt');
|
|
if (data !== '' && data !== undefined) {
|
|
const result: EnvironmentConfigurationType = JSON.parse(data)
|
|
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result)
|
|
if (result.isOpenLog) {
|
|
dConsole.init(result.isOpenLog)
|
|
}
|
|
const host = `http://${result.centerIp}:${result.centerPort}`
|
|
AppStorage.setOrCreate<string>("host", host)
|
|
}
|
|
await InitTable()
|
|
} catch (e) {
|
|
console.error(EntryTag, 'sql first error', e)
|
|
}
|
|
console.log(EntryTag, "onCreate", "加载完成")
|
|
}
|
|
|
|
onDestroy() {
|
|
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
|
|
// TODO UDP缺失
|
|
// lightUDPClient.sendMsg(new Uint8Array(arrClose).buffer)
|
|
DrivingDataStorage.close()
|
|
console.log(EntryTag, "onDestroy", "销毁完成")
|
|
}
|
|
|
|
async onWindowStageCreate(windowStage: window.WindowStage) {
|
|
console.log(EntryTag, "onWindowStageCreate", "窗口创建完成")
|
|
await UseAuth(this.context)
|
|
const windowClass = await windowStage.getMainWindow();
|
|
let rect = windowClass.getWindowProperties().windowRect
|
|
let width = rect.width
|
|
let height = rect.height
|
|
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.sz.km2[0] || "",
|
|
judgeVersion: GlobalConfig.version.sz.km2[1] || "",
|
|
tcpSendNum: 0,
|
|
videoVersion: '1.0',
|
|
ratio: width / height, //适配比例
|
|
pathDir: this.context.filesDir,
|
|
context: this.context,
|
|
isJudgeInitBool: false,
|
|
})
|
|
|
|
AppStorage.setOrCreate('windowClass', windowClass)
|
|
await windowClass.setWindowLayoutFullScreen(true)
|
|
// await windowClass.setWindowSystemBarEnable([]) //全屏
|
|
windowStage.loadContent('pages/Index', (err, data) => {
|
|
if (err.code) {
|
|
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
|
return;
|
|
}
|
|
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
|
});
|
|
|
|
this.createFiles();
|
|
}
|
|
|
|
onWindowStageDestroy() {
|
|
// Main window is destroyed, release UI related resources
|
|
console.log(EntryTag, "onWindowStageDestroy", "窗口销毁完成")
|
|
}
|
|
|
|
onForeground() {
|
|
// Ability has brought to foreground
|
|
console.log(EntryTag, "onForeground", "当应用从后台转到前台时触发")
|
|
}
|
|
|
|
onBackground() {
|
|
// Ability has back to background
|
|
console.log(EntryTag, "onBackground", "当应用从前台转到后台时触发")
|
|
}
|
|
|
|
createFiles() {
|
|
console.log(EntryTag, "createFiles", "创建文件")
|
|
}
|
|
} |