2024-06-04 15:56:50 +08:00

290 lines
9.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { VideoConfig } from './interfaces';
import common from '@ohos.app.ability.common';
import router from '@ohos.router';
import { getCarInfo, getDeviceInfo } from '../common/service/terminalService';
import { setCurrentTime } from '../common/service/timeService';
import { string2Bytes } from '../common/utils/tools';
import { FileHelper } from '../common/service/FileHelper';
import { getUDP, getUDP2 } from '../common/utils/GlobalUdp';
import { initJudgeUdp } from '../common/utils/UdpJudge';
import { getTCP } from '../common/utils/GlobalTcp';
import testNapi from '@ohos.hiserialsdk';
import {
getEsCarModel,
} from '../common/service/initable'
import {
getDoubleCeneterTable,
getliushuiNum,
getSingleCenterTable,
setliushuiNum,
takePhotoFn
} from '../common/service/indexService';
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
import promptAction from '@ohos.promptAction';
@Entry
@Component
struct Index {
@State carNum: string = ''
@State version: string = ''
@State url: string = ''
@State hasAuth: boolean = false;
@State isSingle: boolean = false;
@State deviceId: string = '';
@State angle: number = 0
@State ratio: number = 1700 / 960
@State loading: boolean = true
@State fd: number = -1;
private interval=null;
private context = getContext(this) as common.UIAbilityContext;
fileHelper =null;
build() {
Column() {
Column() {
Row() {
Image($r('app.media.logo')).width('30%').height('5.5%').margin({ left: 24 })
Row() {
Image($r('app.media.btn_setting')).width('16.7%').height('12.2%')
.onClick(async () => {
if (this.loading) {
return
}
router.pushUrl({
url: 'pages/Settings',
}, router.RouterMode.Single);
})
Image($r('app.media.btn_back')).width('14.4%').height('12.2%')
.onClick(() => {
if (this.loading) {
return
}
router.back()
})
}
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
}
Column() {
Row() {
if (!this.isSingle) {
Image($r('app.media.index_lw')).width('30.5%').height('74%').onClick(async () => {
if (this.loading) {
return
}
this.loading = true
setTimeout(() => {
this.angle = 360
}, 1000)
this.angle = 0
//mode为3双中心下载表
if (globalThis.timeInfo?.mode == '3') {
await getDoubleCeneterTable()
} else if (globalThis.timeInfo?.mode == '1') {
//单中心
await getSingleCenterTable()
} else {
promptAction.showToast({
message: `网络连接失败`,
duration: 3000
});
this.loading = false
}
this.loading = false
})
}
if (this.isSingle) {
Image($r('app.media.index_dj')).width('30.5%').height('74%').onClick(() => {
if (this.loading) {
return
}
router.pushUrl({
url: 'pages/UserInfo',
params: { judge: true }
}, router.RouterMode.Single);
// router.pushUrl({
// url: 'pages/UserInfo',
// }, router.RouterMode.Single);
})
}
Image($r('app.media.index_zj')).width('30.5%').height('74%').onClick(() => {
if (this.loading) {
return
}
router.pushUrl({
url: 'pages/CarCheck'
}, router.RouterMode.Single);
})
}
.width('100%')
.justifyContent(FlexAlign.SpaceAround)
}
Column() {
Row() {
Column() {
Text('V ' + globalThis.version)
.fontColor('#CCAE7A')
.fontSize(22 * this.ratio)
.width('30%')
.margin({ bottom: 10 })
Text('授权信息:' + (this.hasAuth ? '已授权' : '未授权'))
.fontColor('#CCAE7A')
.fontSize(22 * this.ratio)
.width('30%')
}
.margin({ left: 24 })
.gesture(
GestureGroup(GestureMode.Exclusive,
TapGesture({ count: 2 })
.onAction(() => {
globalThis.singlePlay = !globalThis.singlePlay
this.isSingle = globalThis.singlePlay
})
)
)
Text('考车号:' + globalThis.deviceNo).fontColor('#CCAE7A').fontSize(22 * this.ratio).margin({ right: 24 })
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.margin({ bottom: 10 })
}
//
if (this.loading) {
Column() {
Image($r('app.media.open_loading'))
.width(200 * this.ratio)
.rotate({ angle: this.angle })
.height(200 * this.ratio)
.animation({
duration: 5000, // 动画时长
curve: Curve.EaseOut, // 动画曲线
delay: 500, // 动画延迟
iterations: -1, // 播放次数
playMode: PlayMode.Normal, // 动画模式
})
.margin({ top: 30 * this.ratio })
Image($r('app.media.car'))
.width(80 * this.ratio)
.height(80 * this.ratio)
.position({ x: 288 * this.ratio, y: 89 * this.ratio })
Text('获取考车信息,请稍候……').fontSize(24 * this.ratio).margin({ top: 20 * this.ratio }).fontWeight(400)
}
.width(660 * this.ratio)
.height(360 * this.ratio)
.position({ x: 150 * this.ratio, y: 98 * this.ratio })
.backgroundColor('#E6E3DF')
.borderRadius(19 * this.ratio)
}
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.SpaceBetween)
.backgroundImagePosition({ x: 0, y: 0 })
.backgroundImage($r('app.media.index_bg'))
.backgroundImageSize({ width: '100%', height: '100%' })
}
aboutToAppear() {
this.angle = 0
this.loading = false
}
async heartMsg() {
//心跳指令编号 //考试状态
const arr = [globalThis.signNum || 0, globalThis.statue || 1]
let tmpList = [];
tmpList.push(string2Bytes(arr[0], 1 * 8)[0])
tmpList.push(string2Bytes(arr[1], 1 * 8)[0])
const str =globalThis.lsh|| '0000000000000'
for (let i = 0;i < str.length; i++) {
tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
}
const param= {id: 31,list:tmpList,carNo: globalThis.carInfo.carNo,placeId: globalThis.carInfo.examinationRomId}
globalThis.udpClient2.sendMsg(param, this.context)
}
onPageShow() {
this.loading = false
this.userAuth();
//plc
getUDP()
//中心udp
getUDP2()
clearInterval(this.interval)
this.interval=setInterval(() => {
setliushuiNum(this.context)
getliushuiNum()
this.heartMsg()
}, 1000)
// 3s拍照
takePhotoFn(this.context)
//tcp差分转发如果差分通过udp转发可注释
getTCP()
if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) {
globalThis.singlePlay = false
}
this.isSingle = globalThis.singlePlay
console.info('Index onPageShow');
}
//创建截图文件夹
async createAlbum() {
this.fileHelper = new FileHelper();
// this.fileHelper.createAlbum('jt')
this.fileHelper.createAlbum('pz');
}
userAuth() {
const permissions: Array<Permissions> = ["ohos.permission.READ_IMAGEVIDEO", "ohos.permission.DISTRIBUTED_DATASYNC" ,'ohos.permission.CONNECTIVITY_INTERNAL','ohos.permission.CAMERA','ohos.permission.READ_MEDIA','ohos.permission.WRITE_MEDIA','ohos.permission.FILE_ACCESS_MANAGER'];
let context = this.context;
let atManager = abilityAccessCtrl.createAtManager();
// requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
atManager.requestPermissionsFromUser(context, permissions).then((data) => {
this.initParams()
let grantStatus: Array<number> = data.authResults;
let length: number = grantStatus.length;
for (let i = 0; i < length; i++) {
if (grantStatus[i] === 0) {
// 用户授权,可以继续访问目标操作
} else {
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
return;
}
}
// 授权成功
}).catch((err) => {
console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
})
}
async initParams() {
this.loading=false
//获取设备信息
this.createAlbum()
await getDeviceInfo()
//车辆信息
getCarInfo()
await setCurrentTime();
this.carNum = globalThis.carInfo.plateNo;
this.version = globalThis.version;
this.hasAuth = globalThis.hasAuth;
initJudgeUdp()
//下载模型
// await this.getModel()
// const arr = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00]
// globalThis.udpClientByTopLine.sendMsg(Array2Byte(arr).buffer)
}
async getModel() {
const context = this.context;
//下载模型
await getEsCarModel(context)
}
}