2025-03-26 13:43:47 +08:00
|
|
|
import common from '@ohos.app.ability.common';
|
|
|
|
|
import { GlobalConfig } from '../../config';
|
|
|
|
|
import Prompt from '@system.prompt';
|
2025-03-24 10:45:28 +08:00
|
|
|
import {
|
|
|
|
|
ApiResponseType,
|
|
|
|
|
BaseInfoType,
|
|
|
|
|
CarConfigurationParamsType,
|
|
|
|
|
ObtainCarExamInfoParams,
|
|
|
|
|
ObtainCarExamInfoRspBody,
|
2025-03-26 10:18:14 +08:00
|
|
|
TimeSynchronizationParams,
|
2025-04-07 14:05:15 +08:00
|
|
|
TimeSynchronizationRspBody,
|
2025-03-26 10:18:14 +08:00
|
|
|
VideoConfig
|
2025-03-26 13:43:47 +08:00
|
|
|
} from '../../model';
|
|
|
|
|
import dayTs from '../../utils/Date';
|
|
|
|
|
import { obtainCarExamInfo, timeSynchronization } from '../../api';
|
2025-03-17 17:55:40 +08:00
|
|
|
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
2025-03-26 13:43:47 +08:00
|
|
|
import { BusinessError } from '@ohos.base';
|
|
|
|
|
import systemTime from '@ohos.systemTime';
|
|
|
|
|
import { VideoConfigData } from '../../mock';
|
2025-03-26 14:48:56 +08:00
|
|
|
import FileUtils from '../../utils/FileUtils';
|
|
|
|
|
|
|
|
|
|
//获取设备信息
|
|
|
|
|
export async function GetDeviceInfo(context: common.UIAbilityContext): Promise<string> {
|
2025-03-17 15:23:25 +08:00
|
|
|
return new Promise(async (resolve, reject) => {
|
2025-03-26 13:43:47 +08:00
|
|
|
const fileUtil = new FileUtils(context)
|
2025-03-17 15:23:25 +08:00
|
|
|
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/deviceNo.txt');
|
|
|
|
|
if (data === '' || data === undefined) {
|
|
|
|
|
Prompt.showToast({
|
|
|
|
|
message: "请先进行设备注册!",
|
|
|
|
|
duration: 3000
|
|
|
|
|
})
|
|
|
|
|
AppStorage.setOrCreate('type', 1)
|
|
|
|
|
AppStorage.setOrCreate('title', '请先进行设备注册')
|
|
|
|
|
resolve("")
|
|
|
|
|
} else {
|
|
|
|
|
const fileData: CarConfigurationParamsType = JSON.parse(data)
|
|
|
|
|
AppStorage.setOrCreate('deviceNo', fileData.deviceName)
|
|
|
|
|
resolve(fileData.deviceName)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function GetCarInfo() {
|
|
|
|
|
let date = new Date();
|
|
|
|
|
let params: ObtainCarExamInfoParams = {
|
|
|
|
|
time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"),
|
2025-04-09 11:23:41 +08:00
|
|
|
deviceNo: AppStorage.get<string>('deviceNo') || ""
|
2025-03-17 15:23:25 +08:00
|
|
|
};
|
2025-03-24 10:45:28 +08:00
|
|
|
let res: ApiResponseType = await obtainCarExamInfo(params)
|
2025-04-09 11:23:41 +08:00
|
|
|
if (res.obtainCarExamInfoRsp && res.obtainCarExamInfoRsp.body) {
|
|
|
|
|
const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body!
|
2025-03-17 15:23:25 +08:00
|
|
|
carInfo.plateNo = decodeURIComponent(carInfo.plateNo)
|
|
|
|
|
AppStorage.setOrCreate('carInfo', carInfo)
|
|
|
|
|
}
|
2025-03-17 17:55:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function UseAuth(context: common.UIAbilityContext): Promise<boolean> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const permissions: Array<Permissions> =
|
|
|
|
|
["ohos.permission.SET_TIME", "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'];
|
|
|
|
|
abilityAccessCtrl.createAtManager().requestPermissionsFromUser(context, permissions).then(res => {
|
|
|
|
|
let grantStatus: Array<number> = res.authResults;
|
|
|
|
|
let length: number = grantStatus.length;
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
if (grantStatus[i] === 0) {
|
|
|
|
|
// 用户授权,可以继续访问目标操作
|
|
|
|
|
resolve(true)
|
|
|
|
|
} else {
|
|
|
|
|
reject(false)
|
|
|
|
|
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).catch((err: BusinessError) => {
|
|
|
|
|
console.log("获取权限失败", JSON.stringify(err))
|
|
|
|
|
reject(false)
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-03-24 10:45:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取时间同步
|
|
|
|
|
export async function SetCurrentTime(): Promise<void> {
|
2025-04-09 11:23:41 +08:00
|
|
|
let deviceNo: string = AppStorage.get<string>('deviceNo')!;
|
|
|
|
|
let baseInfo: BaseInfoType = AppStorage.get<BaseInfoType>('baseInfo')!
|
2025-03-24 10:45:28 +08:00
|
|
|
let params: TimeSynchronizationParams = {
|
|
|
|
|
time: dayTs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
|
|
|
|
|
deviceNo,
|
2025-04-09 11:23:41 +08:00
|
|
|
version: baseInfo.version!,
|
|
|
|
|
judgeVersion: baseInfo.judgeVersion!
|
2025-03-24 10:45:28 +08:00
|
|
|
}
|
|
|
|
|
let res: ApiResponseType = await timeSynchronization(params);
|
2025-04-09 11:23:41 +08:00
|
|
|
if (res.timeSynchronizationRsp?.body) {
|
|
|
|
|
AppStorage.setOrCreate<TimeSynchronizationRspBody>('timeInfo', res.timeSynchronizationRsp.body);
|
|
|
|
|
}
|
|
|
|
|
let currentTime = res.timeSynchronizationRsp?.head?.time;
|
|
|
|
|
let times = 0
|
|
|
|
|
if (currentTime) {
|
|
|
|
|
times = new Date(currentTime).getTime();
|
|
|
|
|
} else {
|
|
|
|
|
console.error("currentTime is undefined");
|
|
|
|
|
}
|
2025-03-24 10:45:28 +08:00
|
|
|
try {
|
|
|
|
|
await systemTime.setTime(times)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('时间同步失败', error)
|
|
|
|
|
}
|
2025-03-26 10:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO 摄像头遮挡 indexService takePhotoFn
|
|
|
|
|
export async function TakePhoto(context: common.UIAbilityContext) {
|
|
|
|
|
let interval: number = -1
|
|
|
|
|
let param: VideoConfig = VideoConfigData
|
|
|
|
|
let spzd: VideoConfig = {
|
|
|
|
|
spzd1: false,
|
|
|
|
|
spzd2: false,
|
|
|
|
|
spzd3: false,
|
|
|
|
|
spzd4: false,
|
|
|
|
|
}
|
2025-03-26 13:43:47 +08:00
|
|
|
const fileUtil = new FileUtils(context)
|
2025-03-26 10:18:14 +08:00
|
|
|
const fileData = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
|
|
|
|
|
param = JSON.parse(fileData)
|
|
|
|
|
clearInterval(interval)
|
|
|
|
|
interval = setTimeout(async () => {
|
|
|
|
|
const arr = ['spzd1', 'spzd2', 'spzd3', 'spzd4']
|
|
|
|
|
}, 3000)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function obtainSerialNumber(data: string) {
|
|
|
|
|
let num = data ? Number(data) + 1 : 0;
|
|
|
|
|
let str = num.toString().padStart(6, '0');
|
|
|
|
|
AppStorage.setOrCreate<string>('lshNo', str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置流水号
|
|
|
|
|
export async function SetSerialNumber() {
|
2025-04-09 11:23:41 +08:00
|
|
|
const data = AppStorage.get<string>("liushuiNo") || "";
|
2025-03-26 10:18:14 +08:00
|
|
|
const serialNumberTime = AppStorage.get<string>("liushuiDate");
|
|
|
|
|
obtainSerialNumber(data);
|
|
|
|
|
const date = dayTs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
if (data && serialNumberTime) {
|
|
|
|
|
const diffDays = dayTs().diff(serialNumberTime, 'day');
|
|
|
|
|
if (diffDays === 0) {
|
|
|
|
|
AppStorage.setOrCreate<string>('liushuiDate', date);
|
|
|
|
|
AppStorage.setOrCreate<string>('liushuiNo', '0');
|
|
|
|
|
} else {
|
|
|
|
|
AppStorage.setOrCreate<string>('liushuiNo', (Number(data) + 1).toString());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
AppStorage.setOrCreate('liushuiNo', '0');
|
|
|
|
|
AppStorage.setOrCreate('liushuiDate', date);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|