refactor: 优化BoardPrePareSetPopup组件,重构照片获取逻辑和数据初始化流程

This commit is contained in:
wangzhongjie 2025-03-25 11:48:51 +08:00
parent a8bf95df5f
commit d461cca1c4

View File

@ -64,21 +64,20 @@ export default struct DeductedPopup {
fontColor: '#FFF', fontColor: '#FFF',
bgColor: '#B36E00' bgColor: '#B36E00'
} }
private context = getContext(this) as common.UIAbilityContext;
private judgeTask: JudgeTask
private filePhoto: FilePhoto
// 过程照片拍照 // 过程照片拍照
getPhoto = async (empty?: boolean) => { getPhoto = async (empty?: boolean) => {
//单机模式返回空照片 //单机模式返回空照片
if (this.singlePlay) { if (this.singlePlay) {
return '' return ''
} else { } else {
const { filePhoto } = this; const photoBase64: string = await this.filePhoto.getPhoto();
const photoBase64 = await filePhoto.getPhoto();
return photoBase64 return photoBase64
} }
} }
private context = getContext(this) as common.UIAbilityContext; private avPlayer: VoiceAnnounce
private judgeTask: JudgeTask
private filePhoto: FilePhoto
private avPlayer
async aboutToAppear() { async aboutToAppear() {
this.carInfo = AppStorage.get('carInfo') this.carInfo = AppStorage.get('carInfo')
@ -89,8 +88,8 @@ export default struct DeductedPopup {
this.filePhoto = mediaTest this.filePhoto = mediaTest
//上车准备 //上车准备
// this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+'')) // this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+''))
const { isTrajectoryOpen } = judgeConfig; // const { isTrajectoryOpen } = judgeConfig;
if (isTrajectoryOpen) { if (judgeConfig.isTrajectoryOpen) {
await this.initDb() await this.initDb()
} else { } else {
await this.initSysset() await this.initSysset()
@ -109,16 +108,19 @@ export default struct DeductedPopup {
//本地数据初始化 //本地数据初始化
async initDb() { async initDb() {
const { isTrajectoryOpen, trajectoryPath } = judgeConfig // const { isTrajectoryOpen, trajectoryPath } = judgeConfig
const examSubject = this.carInfo.examSubject; const examSubject = this.carInfo.examSubject;
//轨迹回放读取 systemparam表、markrule表 //轨迹回放读取 systemparam表、markrule表
const fileUtil = new FileUtil(this.context); const fileUtil = new FileUtil(this.context);
const folderPath = await fileUtil.initFolder(trajectoryPath); const folderPath = await fileUtil.initFolder(judgeConfig.trajectoryPath);
const str = await fileUtil.readFile(folderPath); const str = await fileUtil.readFile(folderPath);
const strArr = str.split('\n'); const strArr = str.split('\n');
const [initData, beginData] = [strArr[0], strArr[1]]; // const [initData, beginData] = [strArr[0], strArr[1]];
const initDataObj = JSON.parse(initData); const initData = strArr[0];
this.examSubject = isTrajectoryOpen ? (initDataObj.kskm * 1) : examSubject; const beginData = strArr[1];
// TODO 补全类型
const initDataObj: ESObject = JSON.parse(initData);
this.examSubject = Number(judgeConfig.isTrajectoryOpen ? (initDataObj.kskm * 1) : examSubject);
await this.initMarkRules(initDataObj.mark); await this.initMarkRules(initDataObj.mark);
await this.initSysset(initDataObj.sysset); await this.initSysset(initDataObj.sysset);
await this.initStudent() await this.initStudent()