1. 新增623参数控制联网模式实施轨迹显示

2. 新增监管结束考试异常,错误提示弹窗显示
3. 优化文件系统:考试结束关闭文件读写
This commit is contained in:
surenjun 2025-01-09 20:56:36 +08:00
parent cd4affcb6f
commit 4f1a4f894c
7 changed files with 193 additions and 113 deletions

View File

@ -6,8 +6,7 @@ import common from '@ohos.app.ability.common'
import fs from '@ohos.file.fs'
const LOGTAG = 'LOGTAG'
export default class FileUtil {
export default class FileUtil{
private context: common.UIAbilityContext
private wantInfos: Want[]
private fileAccessHelper: fileAccess.FileAccessHelper
@ -15,7 +14,8 @@ export default class FileUtil {
//后续文件路径待替换
private absolutePath = '/mnt/hmdfs/100/account/device_view/local/files'
public destFile: string
public destFile:string
public filePathFdObj:Object = {}
constructor(wantInfos) {
const {requestPermission} = this;
@ -27,88 +27,94 @@ export default class FileUtil {
* @desc
*
*/
public initFolder = async (folderPath: string) => {
public initFolder = async (folderPath:string) => {
const {absolutePath} = this;
const folderList = folderPath.split('/').filter(folderName => folderName !== '');
let path = absolutePath
folderList.forEach((folderName => {
folderList.forEach((folderName=>{
path += `/${folderName}`;
try {
const isExit = fs.accessSync(path);
if (!isExit) {
if(!isExit){
fs.mkdirSync(path)
}
} catch (e) {
console.info('初始化文件夹失败', path)
console.info('初始化文件夹失败',path)
promptAction.showToast({
message: `初始化文件夹失败` + JSON.stringify(e),
duration: 4000,
message:`初始化文件夹失败`+ folderPath + JSON.stringify(e),
duration:4000,
})
}
}));
return path;
}
/*
* @desc
*
*/
public addFile = async (filePath: string, content: string, type?: string, fd?) => {
const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
public addFile = async (filePath:string,content:string,type?:string)=>{
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
const isExit = fs.accessSync(filePath);
//文件存在先删除
if (isExit) {
if(isExit){
fs.unlinkSync(filePath);
}
try {
let file
if (!fd) {
file = fs.openSync(filePath, READ_WRITE | CREATE);
}
let file = fs.openSync(filePath, READ_WRITE | CREATE);
//追加写入文件
fs.writeSync(file.fd, content)
fs.writeSync(file.fd,content)
fs.closeSync(file)
return file.fd
console.error(LOGTAG,'写入文件成功')
return true
} catch (e) {
console.error(LOGTAG, '写入失败', JSON.stringify(e))
}catch (e){
promptAction.showToast({
message:`addFile文件失败`+ filePath +JSON.stringify(e),
duration:4000,
})
console.error(LOGTAG,'写入失败',JSON.stringify(e))
}
}
public openFileSync = async (filePath) => {
const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
let file = fs.openSync(filePath, READ_WRITE | APPEND | CREATE);
return file
}
public editFileWidthOutOpen(file, content) {
const newStr = content + '\n'
fs.writeSync(file.fd, newStr)
fs.closeSync(file)
console.error(LOGTAG, '写入文件成功')
}
/*
* @desc
*
*/
public editFile = async (filePath: string, content: string, fd?: number) => {
const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
try {
public editFile = async (filePath:string,content:string,fd?:number)=>{
const {filePathFdObj} = this;
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
const newStr = content + '\n'
if (fd !== undefined) {
fs.writeSync(fd, newStr)
return fd
} else {
let file = fs.openSync(filePath, READ_WRITE | APPEND | CREATE);
fs.writeSync(file.fd, newStr)
const thisFile = filePathFdObj[filePath];
try {
if(thisFile){
fs.writeSync(fd,newStr)
return fd;
}else{
let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE);
fs.writeSync(file.fd,newStr)
this.filePathFdObj[filePath] = file
return file.fd
}
} catch (e) {
console.error(LOGTAG, JSON.stringify(e))
promptAction.showToast({
message:`editFile文件失败`+ filePath +JSON.stringify(e),
duration:4000,
})
console.error(LOGTAG,JSON.stringify(e))
}
}
/*
* @desc
*
*/
public closeFile = async (filePath:string)=>{
const {filePathFdObj} = this;
const thisFile = filePathFdObj[filePath];
if(thisFile){
fs.closeSync(thisFile);
console.info(LOGTAG,filePath + '文件关闭成功')
}
}
@ -116,12 +122,17 @@ export default class FileUtil {
* @desc
*
**/
public readFile = async (filePath: string) => {
try {
console.log('strrr', filePath)
public readFile = async (filePath:string) => {
try{
console.log('strrr',filePath)
const str = await fs.readText(filePath);
return str
} catch (err) {
}catch (e){
promptAction.showToast({
message:`读取文件失败`+ filePath +JSON.stringify(e),
duration:4000,
})
console.log('readFile文件失败'+ filePath +JSON.stringify(e))
return ''
}
@ -130,9 +141,9 @@ export default class FileUtil {
/*
* @desc获取系统目录里的文件列表
*/
public getDeviceList = async (folderPath?: string) => {
public getDeviceList = async (folderPath?:string)=>{
const {absolutePath,getFilePathList} = this;
return getFilePathList(`${absolutePath}/${folderPath}`, false)
return getFilePathList(`${absolutePath}/${folderPath}`,false)
};
// 删除文件夹或者文件
@ -141,29 +152,29 @@ export default class FileUtil {
* @param{{type}} 1:文件夹 2 3
**/
public deleteF = async (path: string, type: 1 | 2 | 3) => {
public deleteF = async (path:string,type: 1 | 2 | 3) => {
const {getFilePathList,absolutePath} = this
if (type === 1) {
const fileList = await getFilePathList(`${absolutePath}/${path}`, false);
fileList.forEach(filePath => {
if(type === 1){
const fileList = await getFilePathList(`${absolutePath}/${path}`,false);
fileList.forEach(filePath =>{
fs.unlinkSync(`${absolutePath}/${path}/${filePath}`);
})
fs.rmdirSync(`${absolutePath}/${path}`);
return true
}
if (type === 2) {
if(type === 2){
fs.unlinkSync(`${absolutePath}/${path}`);
return true
}
if (type === 3) {
if(type === 3){
fs.unlinkSync(`${path}`);
return true
}
}
// 获取系统文件绝对路径
public getAbsolutePath = () => {
public getAbsolutePath = () =>{
const {absolutePath} = this;
return absolutePath
}
@ -172,7 +183,7 @@ export default class FileUtil {
public getSdCardPathList = async () => {
this.wantInfos = await fileAccess.getFileAccessAbilityInfo();
const {wantInfos,context} = this;
const fileAccessHelper = fileAccess.createFileAccessHelper(this.context, this.wantInfos);
const fileAccessHelper = fileAccess.createFileAccessHelper(this.context,this.wantInfos);
this.fileAccessHelper = fileAccessHelper;
let isDone = false;
@ -188,48 +199,48 @@ export default class FileUtil {
if (!isDone) {
let deviceType = rootInfo.value.deviceType;
let displayName = rootInfo.value.displayName;
let uri: string = rootInfo.value.uri;
let uri:string = rootInfo.value.uri;
let deviceFlags = rootInfo.value.deviceFlags;
console.error(LOGTAG, `设备类型:${deviceType},设备名称:${displayName}设备根目录Uri${uri},设备支持的能力:${deviceFlags}`);
console.error(LOGTAG,`设备类型:${deviceType},设备名称:${displayName}设备根目录Uri${uri},设备支持的能力:${deviceFlags}`);
if (uri.indexOf('/mnt/external/') > 0) {
if(uri.indexOf('/mnt/external/')>0){
// if('vol-8-1' ==displayName){
this.destFile = uri.split('ExternalFileManager')[1] + '/'
console.error(LOGTAG, `外置存储路径:` + this.destFile);
this.getFilePathList(this.destFile, true)
this.destFile = uri.split('ExternalFileManager')[1]+'/'
console.error(LOGTAG,`外置存储路径:`+this.destFile);
this.getFilePathList(this.destFile,true)
}
}
}
} catch (error) {
console.error(LOGTAG, "getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
console.error(LOGTAG,"getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
}
}
public getFileContent = (filePath: string) => {
public getFileContent = (filePath:string) => {
const {absolutePath} = this;
const { READ_WRITE } = fs.OpenMode
const { READ_WRITE }= fs.OpenMode
const path = `${absolutePath}/${filePath}`
const str = fs.readTextSync(path);
return str
}
private getFilePathList = async (filePath: string, isSdcard: boolean) => {
let fileName = [], sdCardFileName = [];
private getFilePathList = async (filePath:string,isSdcard:boolean) => {
let fileName = [],sdCardFileName = [];
try {
const filenames = await fs.listFile(filePath);
for (let i = 0; i < filenames.length; i++) {
console.error(LOGTAG, `目录:${filePath}的子文件:${filenames[i]}`);
if (isSdcard) {
console.error(LOGTAG,`目录:${filePath}的子文件:${filenames[i]}`);
if(isSdcard){
sdCardFileName.push(filenames[i])
} else {
}else{
fileName.push(filenames[i])
}
}
return isSdcard ? sdCardFileName : fileName
} catch (e) {
console.error(LOGTAG, JSON.stringify(e));
}catch (e){
console.error(LOGTAG,JSON.stringify(e));
}
}
@ -243,15 +254,17 @@ export default class FileUtil {
];
this.wantInfos = await fileAccess.getFileAccessAbilityInfo();
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager()
atManager.requestPermissionsFromUser(context, permissions, async (code, result) => {
atManager.requestPermissionsFromUser(context, permissions , async (code, result) => {
const permissionRequest = result.authResults[0]
if (permissionRequest == -1) {
if(permissionRequest == -1){
promptAction.showToast({
message: "请先授权",
duration: 3000,
duration:3000,
})
return
}
})
}
}

View File

@ -10,6 +10,7 @@ import { defaultJudgeConfigObj } from './judgeSDK/utils//judgeCommon';
import {uploadExamMileage} from '../api/judge'
import DwztErrorPopup from './compontents/judge/DwztErrorPopup'
import {debounce} from '../common/utils/tools'
import MsgPopup from './compontents/judge/MsgPopup'
import {
CARINFO,
@ -186,6 +187,12 @@ struct Index {
name: decodeURI(sys.v_name)
})
}
//623 考试中是否可以查看轨迹画面(0-否+1-是)
if(sys.v_no == '623'){
this.syssetParam623 = value == '1'?true:false
}
//科目三应行驶距离参数
if (sys.v_no == '303') {
this.examMileage = this.examMileage == '0'?(sys.v_value + ''): this.examMileage;
@ -930,6 +937,7 @@ struct Index {
showBack: false,
scaleNum: 1.8,
msgStr: this.judge.plcStr || '',
showTrajectory:globalThis.singlePlay ? true : (this.syssetParam623),
}).margin({ top: 100 })
Row() {
@ -977,6 +985,10 @@ struct Index {
this.endPopupVisible = false;
},
confirmFn: async () => {
if(this.isErrorMsgEnd){
router.back()
return
}
if (this.judgeConfigObj['344'] == 1) {
Prompt.showToast({
message: '考试未结束,不允许手动退出!',
@ -991,6 +1003,7 @@ struct Index {
try {
this.judge.checkExamIsEnd(true);
} catch (e) {
this.judge.closeAllFiles()
router.back()
}
@ -1005,6 +1018,16 @@ struct Index {
})
}
if (this.errorMsg){
MsgPopup({
title: this.errorMsg,
confirmFn:()=>{
this.errorMsg = ''
this.isErrorMsgEnd = true;
},
})
}
if(this.dwztErrorVisible){
DwztErrorPopup({
title:'当前差分状态异常,学员将无法正常进行考试评判,请将车辆行驶到开阔地,等待程序自检,差分正常后会自动关闭该对话框',
@ -1324,6 +1347,7 @@ struct Index {
@State xldm: string = ''
//监管接口序列号
@State serialNumber: number = 0
@State syssetParam623: boolean = false;
@State carType: string = ''
@State carName: string = ''
@State isDeductedPopShow: boolean = false
@ -1369,4 +1393,6 @@ struct Index {
@State dwztErrorVisible: boolean = false;
@State popTimer:number =0;
@State carlist:string= ''
@State errorMsg: string = ''
@State isErrorMsgEnd: boolean = false
}

View File

@ -9,6 +9,7 @@ import { GlobalConfig } from '../../config/index'
@Component
export default struct SignDisplayCom {
@State showBack: boolean = false
@Prop showTrajectory:boolean = false
@State scaleNum: number = 1
@State msg: string = ''
@State signArr: Array<any> = []
@ -50,7 +51,7 @@ export default struct SignDisplayCom {
})
if (!this.showBack) {
if (this.showTrajectory) {
Row() {
Text('实时轨迹').fontColor(this.active == 1 ? '#FFAD33' : '#e7cba3').fontSize(20 * this.ratio)
}

View File

@ -0,0 +1,23 @@
@Component
export default struct MsgPopup{
constructor() {
super()
}
private title:string = ''
private confirmFn:(event?: ClickEvent) => void
build(){
Column(){
Column(){
Text(this.title).fontSize(36).margin({bottom:20}).lineHeight(50)
Row(){}.height(100)
Row(){
Text('确定').backgroundImage($rawfile('judge/end-btn.png'),ImageRepeat.NoRepeat).backgroundImageSize({width:'100%',height:'100%'}).width(250).height(95).fontSize(28).fontColor('#FFF').textAlign(TextAlign.Center).onClick(this.confirmFn)
}.margin({top:20})
}.width('65%').height('70%').padding(30).backgroundColor('#E6E3DF').borderRadius(38).position({y:'12%',x:'17.5%'}).justifyContent(FlexAlign.Center)
}.width('100%').height('100%').position({y:0}).backgroundColor('rgba(0,0,0,0.7)')
}
}

View File

@ -95,6 +95,7 @@ export default class Judge {
: ( projectCenterObj.isEnd ? 3 : 1 )
}
})
console.info(judgeTag+'testKmItems',JSON.stringify(this.testKmItems))
this.isExamEnd = false;
}
@ -170,7 +171,7 @@ export default class Judge {
await fileLog.setExamJudgeData(beginExamInfo)
await examJudgeBeginExam(beginExamInfo);
console.info(judgeTag, '6.开始考试注册完成')
avPlayer.playAudio([globalThis.singlePlay ? 'voice/ksks.WAV' : 'voice/监管成功.mp3'])
avPlayer.playAudio([globalThis.singlePlay ? 'voice/ksks.wav' : 'voice/监管成功.mp3'])
if(!globalThis.singlePlay){
this.videoData = await saveStartRecordVideo(`${name}_${kssycs}`)
@ -542,7 +543,8 @@ export default class Judge {
judgeUI,
checkExamIsEnd,
checkProjectIsStart,
lane
lane,
closeAllFiles
} = this;
const {projectsObj,judgeConfigObj,examSubject,examMileage,jl,isAllProjectsEnd} = judgeUI;
@ -640,6 +642,7 @@ export default class Judge {
judgeTask.addTask(async () => {
console.info(judgeTag, '考试结束 start')
globalThis.isJudge = false;
closeAllFiles()
await handEndExam(ksjs)
})
clearInterval(globalThis.judgeTimer)
@ -1062,10 +1065,11 @@ export default class Judge {
if(code != 1){
avPlayer.playAudio(['voice/监管失败.mp3'])
this.judgeUI.errorMsg = decodeURIComponent(message)
this.isUdpEnd = true
router.back();
return
}
console.info(judgeTag, '考试结束 end')
const param302 = judgeConfigObj['302'];
judgeUI.loadingPopupVisible = true;
@ -1566,7 +1570,7 @@ export default class Judge {
const msgStr = strArr[num];
if(msgStr == ''){
console.info(judgeTag, '模拟数据考试结束')
// globalThis.windowClass.setWindowSystemBarEnable(['navigation'])
globalThis.windowClass.setWindowSystemBarEnable(['navigation'])
clearInterval(judgeTimer)
this.checkExamIsEnd(true)
return
@ -1664,6 +1668,11 @@ export default class Judge {
}
}
closeAllFiles = ()=>{
this.fileLog.closeAllFiles()
}
public plcStr: string
private judgeUI
private fileLog

View File

@ -5,17 +5,17 @@ import common from '@ohos.app.ability.common'
import Want from '@ohos.app.ability.Want'
import fs from '@ohos.file.fs'
import FileUtil from '../../../common/utils/File'
import {getCurrentTime} from '../../../common/utils/tools'
import { getCurrentTime } from '../../../common/utils/tools'
interface StuInfo{
name:string
lsh:string
idCard:string
interface StuInfo {
name: string
lsh: string
idCard: string
}
const LOGTAG = 'LOGTAG'
export default class FileLog {
export default class FileLog {
//后续文件路径待替换
private fileUtil: FileUtil
private stuInfo: StuInfo
@ -40,7 +40,7 @@ export default class FileLog {
}
// 设置文件夹
public initFileLogo = async (stuInfo:StuInfo) => {
public initFileLogo = async (stuInfo: StuInfo) => {
const {fileUtil,setExamLineData} = this
const {name,lsh,idCard} = stuInfo;
this.stuInfo = stuInfo;
@ -53,56 +53,64 @@ export default class FileLog {
}
// 过程文件数据
public setExamProgressData = async (str:Object) => {
public setExamProgressData = async (str: Object) => {
const {fileUtil,folderPath,progressDataFd} = this;
this.progressDataFd = await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str),progressDataFd);
this.progressDataFd = await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`, JSON.stringify(str), progressDataFd);
}
// 无锡所接口数据
public setExamJudgeWuxiData = async (str) => {
const {fileUtil,folderPath,examJudgeWuxiDataFd} = this;
this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str,examJudgeWuxiDataFd);
this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`, str, examJudgeWuxiDataFd);
}
// 无锡所过程数据
public setExamJudgeWuxiProgressData = async (str)=>{
public setExamJudgeWuxiProgressData = async (str) => {
const {fileUtil,folderPath,examJudgeWuxiProgressDataFd} = this;
this.examJudgeWuxiProgressDataFd = await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str,examJudgeWuxiProgressDataFd);
this.examJudgeWuxiProgressDataFd = await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`, str, examJudgeWuxiProgressDataFd);
}
// plc文件数据
public setPlcProgressData = async (str:Object) => {
public setPlcProgressData = async (str: Object) => {
const {fileUtil,folderPath,plcDataFd} = this;
this.plcDataFd = await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str),plcDataFd);
this.plcDataFd = await fileUtil.editFile(`${folderPath}/plc_data.txt`, JSON.stringify(str), plcDataFd);
}
// 过程评判json数据
public setExamJudgeData = async (str:Object) => {
public setExamJudgeData = async (str: Object) => {
const {fileUtil,folderPath,examJudgeDataFd} = this;
this.examJudgeDataFd = await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str),examJudgeDataFd);
this.examJudgeDataFd = await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`, JSON.stringify(str), examJudgeDataFd);
}
// 过程评判回调数据
public setExamJudgeCallbackData = async (str:string) => {
public setExamJudgeCallbackData = async (str: string) => {
const {fileUtil,folderPath,examJudgeCallbackDataFd} = this;
this.examJudgeCallbackDataFd = await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str,examJudgeCallbackDataFd);
this.examJudgeCallbackDataFd = await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`, str, examJudgeCallbackDataFd);
}
// 过程评判日志调数据
public setExamJudgeLogData = async (str:string) => {
public setExamJudgeLogData = async (str: string) => {
const {fileUtil,folderPath,examJudgeLogDataFd} = this;
this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str,examJudgeLogDataFd);
this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`, str, examJudgeLogDataFd);
}
// 设置四合一画面数据
public setFourAndOneLogData = async (str:string) => {
public setFourAndOneLogData = async (str: string) => {
const {fileUtil,folderPath,fourAndOneLogDataFd} = this;
this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`,str,fourAndOneLogDataFd);
this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`, str, fourAndOneLogDataFd);
}
public setFourAndOneLogDataBytes = async (str:string) => {
public setFourAndOneLogDataBytes = async (str: string) => {
const {fileUtil,folderPath,fourAndOneLogDataBytesFd} = this;
this.fourAndOneLogDataBytesFd = await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`,str,fourAndOneLogDataBytesFd);
this.fourAndOneLogDataBytesFd = await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`, str, fourAndOneLogDataBytesFd);
}
//关闭所有文件写入
public closeAllFiles = async () => {
const {fileUtil,folderPath,fourAndOneLogDataFd} = this;
['exam_progress_data', 'wuxi_exam_data', 'wuxi_progress_data', 'plc_data', 'judge_exam_data', 'judge_progress_callback_data', 'judge_log_data', 'four_one_log_data', 'four_one_log_byte_data'].forEach(path => {
fileUtil.closeFile(`${folderPath}/${path}.txt`);
})
}
// 无锡所轨迹数据
@ -111,7 +119,7 @@ export default class FileLog {
const plcData = plcStr.split(',');
const time = await getCurrentTime();
const lineData = [
/*帧头*/ time,
/*帧头*/time,
/*卫星时间*/time,
/*经度*/ plcData[95],
/*纬度*/ plcData[95],
@ -130,11 +138,11 @@ export default class FileLog {
/*天向位置坐标*/'',
/*东向速度*/'',
/*北向速度*/'',
/*评判信号1*/[plcData[14],plcData[19],plcData[5],'',plcData[2],plcData[3],plcData[7],plcData[8],plcData[13],plcData[12],plcData[17],'',plcData[4],plcData[11],plcData[20],plcData[9],0].join(','),
/*评判信号2*/['',plcData[28],'','',plcData[10],'','','','','','','','','','','','',''].join(','),
/*评判信号1*/[plcData[14], plcData[19], plcData[5], '', plcData[2], plcData[3], plcData[7], plcData[8], plcData[13], plcData[12], plcData[17], '', plcData[4], plcData[11], plcData[20], plcData[9], 0].join(','),
/*评判信号2*/['', plcData[28], '', '', plcData[10], '', '', '', '', '', '', '', '', '', '', '', '', ''].join(','),
/*发动机转速*/ plcData[25],
/*结束符*/ time,
];
this.examLineDataFd = await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData),examLineDataFd);
this.examLineDataFd = await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`, JSON.stringify(lineData), examLineDataFd);
};
}

Binary file not shown.