优化首页逻辑

This commit is contained in:
lixiao 2025-03-13 10:09:12 +08:00
parent e8bd7a00ec
commit 49e62fa685
2 changed files with 23 additions and 99 deletions

View File

@ -1,21 +1,26 @@
import systemTime from '@ohos.systemTime'; import systemTime from '@ohos.systemTime';
import { timeSynchronization } from '../../api/index' import { timeSynchronization } from '../../api/index'
import { dateFormat,dateVersionFormat } from '../utils/tools'; import { dateFormat, dateVersionFormat } from '../utils/tools';
//同步时时间 //同步时时间
export async function timeSynchronize() { export async function timeSynchronize() {
let date = new Date(); let date = new Date();
console.info('jiangsong1:timeSynchronization begin ' ); console.info('jiangsong1:timeSynchronization begin ');
let params = { time: dateFormat(date), deviceNo: globalThis.deviceNo,version:globalThis.version,judgeVersion:globalThis.judgeVersion} let params = {
let res:any = await timeSynchronization(params) time: dateFormat(date),
deviceNo: globalThis.deviceNo,
version: globalThis.version,
judgeVersion: globalThis.judgeVersion
}
let res: any = await timeSynchronization(params)
res = res.timeSynchronizationRsp; res = res.timeSynchronizationRsp;
globalThis.timeInfo=res.body globalThis.timeInfo = res.body
console.log('timeInfo',JSON.stringify(res.body)) console.log('timeInfo', JSON.stringify(res.body))
return res; return res;
} }
export async function setCurrentTime():Promise<void> { export async function setCurrentTime(): Promise<void> {
let res = await timeSynchronize(); let res = await timeSynchronize();
let currentTime = res.head.time; let currentTime = res.head.time;
let times = new Date(currentTime).getTime(); let times = new Date(currentTime).getTime();
@ -27,13 +32,13 @@ export async function setCurrentTime():Promise<void> {
// }).catch((error) => { // }).catch((error) => {
// console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`); // console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`);
// }); // });
} catch(e) { } catch (e) {
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`); console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
} }
} }
//获取当前时间并转化 //获取当前时间并转化
export async function getCurrentTime():Promise<string> { export async function getCurrentTime(): Promise<string> {
const date = await systemTime.getDate(); const date = await systemTime.getDate();
const year = date.getFullYear(); const year = date.getFullYear();
let month = date.getMonth() + 1; let month = date.getMonth() + 1;
@ -55,7 +60,7 @@ export async function getCurrentTime():Promise<string> {
} }
//时间戳转日期 //时间戳转日期
export function formatTime(time:number):string { export function formatTime(time: number): string {
//@ts-ignore //@ts-ignore
const h = parseInt(time / 3600) const h = parseInt(time / 3600)
//@ts-ignore //@ts-ignore

View File

@ -23,8 +23,6 @@ import IdlServiceExtProxy from '../IdlServiceExt/idl_service_ext_proxy';
import Want from '@ohos.app.ability.Want'; import Want from '@ohos.app.ability.Want';
import emitter from '@ohos.events.emitter'; import emitter from '@ohos.events.emitter';
// import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
@Entry @Entry
@Component @Component
struct Index { struct Index {
@ -55,13 +53,9 @@ struct Index {
}), }),
customStyle: true, customStyle: true,
alignment: DialogAlignment.Center, alignment: DialogAlignment.Center,
}, })
)
private fileUtil: FileUtil
private interval = null; private interval = null;
// private vocObj = null;
private avPlayer private avPlayer
private workerInstance = null;
private context = getContext(this) as common.UIAbilityContext; private context = getContext(this) as common.UIAbilityContext;
private serviceExtProxy: IdlServiceExtProxy private serviceExtProxy: IdlServiceExtProxy
@ -114,14 +108,7 @@ struct Index {
imageBtn({ btnWidth: '28%', btnHeight: '71%', imgSrc: $r('app.media.index_lw') }) imageBtn({ btnWidth: '28%', btnHeight: '71%', imgSrc: $r('app.media.index_lw') })
.margin({ left: 80 * globalThis.ratio }) .margin({ left: 80 * globalThis.ratio })
.onClick(async () => { .onClick(async () => {
// this.vocObj.playAudio({
// type: 1,
// name: 'button_media.wav'
// })
// ||!this.initParamFlag
if (this.loading) { if (this.loading) {
// globalThis.title = '正在初始化请等待5s后重试'
// this.errorDialog.open()
return return
} }
setTimeout(() => { setTimeout(() => {
@ -130,29 +117,29 @@ struct Index {
this.angle = 0 this.angle = 0
if (!globalThis.timeInfo) { if (!globalThis.timeInfo) {
globalThis.type = '1' globalThis.type = '1'
globalThis.title = '时间同步接口连接失败' globalThis.title = '时间同步接口连接失败,尝试重新同步,请稍后'
this.errorDialog.open() this.errorDialog.open()
promptAction.showToast({ promptAction.showToast({
message: `时间同步接口连接失败`, message: `时间同步接口连接失败,尝试重新同步,请稍后`,
duration: 3000 duration: 3000
}); });
this.loading = false this.loading = false
await setCurrentTime()
return return
} }
if (!globalThis.carInfo) { if (!globalThis.carInfo) {
promptAction.showToast({ promptAction.showToast({
message: `车辆信息接口获取失败`, message: `车辆信息接口获取失败,尝试重新获取,请稍后`,
duration: 3000 duration: 3000
}); });
globalThis.type = '1' globalThis.type = '1'
globalThis.title = '车辆信息接口获取失败' globalThis.title = '车辆信息接口获取失败,尝试重新获取,请稍后'
this.errorDialog.open()
this.loading = false this.loading = false
this.errorDialog.open()
await getCarInfo()
return return
} }
this.testXMLToJSONInWorker() this.testXMLToJSONInWorker()
}) })
} }
if (this.isSingle) { if (this.isSingle) {
@ -413,20 +400,6 @@ struct Index {
} }
async aboutToAppear() { async aboutToAppear() {
// setInterval(() => {
// let date = new Date();
// console.info('jiangsong1:timeSynchronization begin ');
// uploadProgressData()
// let params = {
// time: dateFormat(date),
// deviceNo: globalThis.deviceNo,
// version: globalThis.version,
// judgeVersion: globalThis.judgeVersion
// }
// timeSynchronizationHTTP(params)
// }, 1000)
console.log('diyidiy')
emitter.on({ emitter.on({
eventId: 1 eventId: 1
}, async () => { }, async () => {
@ -544,47 +517,6 @@ struct Index {
} }
}) })
// workerInstance.postMessage(param);
// workerInstance.onmessage = (e: MessageEvents): void => {
// console.log("baoyihu after postMessage :", JSON.stringify(e.data));
// // @ts-ignore
// let workData: WorkData = e.data;
// this.loading = false
// if (workData.isComplete) {
// if(globalThis.singlePlay){
// router.pushUrl({
// url: 'pages/UserInfo',
// }, router.RouterMode.Single)
// return
// }
// getSyncData('MA_SYSSET').then(data => {
// console.log('datadata', JSON.stringify(data))
// // @ts-ignore
// data.forEach(sys => {
// //判断是否能点开始考试
// if(sys.v_no === '854'){
// globalThis.param854Str=sys.v_value
// }
// if (sys.v_no === '824'&&decodeURIComponent(sys.v_value)=='0') {
// // this.Param612Str= decodeURIComponent(sys.v_value)
// router.pushUrl({
// url:'pages/CarCheck',
// params: {
// 'fromIndex':true
// }
// }, router.RouterMode.Single)
// }else{
// router.pushUrl({
// url: 'pages/ExaminerLogin',
// }, router.RouterMode.Single)
// }
// })
// });
//
// }
// workerInstance.terminate();
//
// }
} }
async heartMsg() { async heartMsg() {
@ -610,7 +542,6 @@ struct Index {
} }
async onPageShow() { async onPageShow() {
console.log('ttttt', 1111)
await this.userAuth(); await this.userAuth();
console.log('globalThis.singlePlay', globalThis.singlePlay) console.log('globalThis.singlePlay', globalThis.singlePlay)
if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) { if (globalThis.singlePlay == undefined || globalThis.singlePlay == null) {
@ -680,12 +611,9 @@ struct Index {
} }
async initParams() { async initParams() {
// deleteAllFIleLog(GlobalConfig.comoonfileWriteAddress + '/PLC/')
//设置plc udp 同步requesthost
await getUDP(this.context, false) await getUDP(this.context, false)
this.loading = false this.loading = false
await getDeviceInfo(this.context) await getDeviceInfo(this.context)
await getCarInfo() await getCarInfo()
await getUDP2(this.context, false) await getUDP2(this.context, false)
getTCP() getTCP()
@ -715,15 +643,6 @@ struct Index {
} }
}, 1000) }, 1000)
this.createAlbum() this.createAlbum()
// clearInterval(globalThis.demo)
// globalThis.demo= setInterval(()=>{
// const str= {"carId":"1062","examinationRoomId":"2","videoVersion":"1.0","judgeVersion":"2023.09.30.1","shellVersion":"2023.12.13.01","host":"http://172.37.55.191:8082"}
// initialization(str)
// },10000)
//下载模型
// await this.getModel()
// const arr = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00]
// globalThis.udpClientByTopLine.sendMsg(Array2Byte(arr).buffer)
} }
async getModel() { async getModel() {