From 8d6e6e3b6bbcd80dca60f699e64c868bd365a944 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Tue, 28 Oct 2025 16:27:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 10 +-- entry/oh-package-lock.json5 | 8 +- .../main/ets/common/utils/PreferenceUtils.ets | 63 +++++++++++++++ .../src/main/ets/entryability/EntryAbility.ts | 9 ++- entry/src/main/ets/pages/Index.ets | 29 +++++-- entry/src/main/ets/pages/UserInfo.ets | 76 ++++++++++++------- .../main/ets/pages/compontents/CozyDialog.ets | 18 +++++ .../src/main/ets/pages/judgeSDK/api/index.ts | 4 +- entry/src/main/module.json5 | 5 +- oh-package-lock.json5 | 8 +- 10 files changed, 177 insertions(+), 53 deletions(-) create mode 100644 entry/src/main/ets/common/utils/PreferenceUtils.ets create mode 100644 entry/src/main/ets/pages/compontents/CozyDialog.ets diff --git a/build-profile.json5 b/build-profile.json5 index cd352219..61c6b5dc 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -4,13 +4,13 @@ { "name": "default", "material": { - "certpath": "C:\\Users\\13440\\.ohos\\config\\openharmony\\auto_ohos_default_subject-two2_com.oh.dts.cer", - "storePassword": "0000001BE1869C350CC47385898E8BD73BD9A455D1886BA385CD349B7C5ADE3BCFB7A29422CB379DD38D60", + "certpath": "/Users/wangzhongjie/.ohos/config/openharmony/default_subject-two_Kl4t-ZSvZeuUm9s8O-e6FIH2VFR_OaNyhDP8kPjIWgU=.cer", + "storePassword": "0000001BDD909DD8404E8B92703D5184A866B60293C42962B835ADAE4424AB5244CA8CC5F5B6B9F28F51B1", "keyAlias": "debugKey", - "keyPassword": "0000001B9F28F62DC3596874829120C11C241553B9134766FDA5315E81776F4AB7C392D24F996EDE2E3E5A", - "profile": "C:\\Users\\13440\\.ohos\\config\\openharmony\\auto_ohos_default_subject-two2_com.oh.dts.p7b", + "keyPassword": "0000001B385A41E5971B34BE4AE810C6CB23838F88571ADB42DEAE3687C1AD6F3FCE35E98545F32AA4D057", + "profile": "/Users/wangzhongjie/.ohos/config/openharmony/default_subject-two_Kl4t-ZSvZeuUm9s8O-e6FIH2VFR_OaNyhDP8kPjIWgU=.p7b", "signAlg": "SHA256withECDSA", - "storeFile": "C:\\Users\\13440\\.ohos\\config\\openharmony\\auto_ohos_default_subject-two2_com.oh.dts.p12" + "storeFile": "/Users/wangzhongjie/.ohos/config/openharmony/default_subject-two_Kl4t-ZSvZeuUm9s8O-e6FIH2VFR_OaNyhDP8kPjIWgU=.p12" } } ], diff --git a/entry/oh-package-lock.json5 b/entry/oh-package-lock.json5 index bc40219d..1f023b33 100644 --- a/entry/oh-package-lock.json5 +++ b/entry/oh-package-lock.json5 @@ -1,13 +1,15 @@ { - "lockfileVersion": 1, + "lockfileVersion": 2, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6" }, "packages": { "@ohos/hypium@1.0.6": { - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", - "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==" + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", + "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==", + "registryType": "ohpm", + "shasum": "3f5fed65372633233264b3447705b0831dfe7ea1" } } } \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/PreferenceUtils.ets b/entry/src/main/ets/common/utils/PreferenceUtils.ets new file mode 100644 index 00000000..840132c4 --- /dev/null +++ b/entry/src/main/ets/common/utils/PreferenceUtils.ets @@ -0,0 +1,63 @@ +import dataPreferences from '@ohos.data.preferences'; + +let context = getContext(this); +let preference: dataPreferences.Preferences; +const SYSTEM_DB: string = 'system.db' //其他信息 +const USER_DB: string = 'user.db' //用户信息 + +class PreferenceUtils { + // 写入其他缓存数据 + async writeOtherData(value: dataPreferences.ValueType, key: string) { + // if (value === null) { + // return; + // } + if (!preference) { + await this.getPreferencesFromStorage(SYSTEM_DB); + } + try { + await preference.put(key, value); + } catch (err) { + console.info(`Failed to put value, Cause: ${err}`); + } + await preference.flush(); + } + + // 获取其他缓存数据 + async getOtherModel(key: string) { + let value: dataPreferences.ValueType = 1; + if (!preference) { + await this.getPreferencesFromStorage(SYSTEM_DB); + } + + try { + value = (await preference.get(key, '')); + } catch (err) { + console.info(`Failed to get value, Cause: ${err}`); + } + if (value === '') { + return; + } + return value as T; + } + + // 删除登录数据 + async deletePreferences() { + try { + await dataPreferences.deletePreferences(context, USER_DB); + } catch (err) { + console.info(`Failed to delete preferences, Cause: ${err}`); + } + ; + } + + // 创建登录数据preference + async getPreferencesFromStorage(name: string) { + try { + preference = await dataPreferences.getPreferences(context, name); + } catch (err) { + console.info(`Failed to get preferences, Cause: ${err}`); + } + } +} + +export default new PreferenceUtils(); diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ts index ae3360a5..f1f727a3 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ts +++ b/entry/src/main/ets/entryability/EntryAbility.ts @@ -10,9 +10,15 @@ import { GlobalConfig } from '../config/global' import { tcpUtil } from '../common/utils/TcpRequest'; import DB from '../common/database/DbSql'; import { initTable } from '../common/service/initable'; +import appRecovery from '@ohos.app.ability.appRecovery'; export default class EntryAbility extends UIAbility { async onCreate(want, launchParam) { + appRecovery.enableAppRecovery( + appRecovery.RestartFlag.ALWAYS_RESTART, + appRecovery.SaveOccasionFlag.SAVE_WHEN_ERROR, + appRecovery.SaveModeFlag.SAVE_WITH_FILE + ); try { console.log("sql first") await DB.init(this.context) @@ -23,6 +29,7 @@ export default class EntryAbility extends UIAbility { console.error('sql first error', e) } + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); } @@ -38,7 +45,7 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); await tcpUtil.init() - globalThis.tcpStep=0 + globalThis.tcpStep = 0 globalThis.carInfo = {} globalThis.examinerInfo = {} diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 1d4f6d35..ffb6ea24 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -10,7 +10,7 @@ import { getUDP, getUDP2 } from '../common/utils/GlobalUdp'; import { initJudgeUdp } from '../common/utils/UdpJudge'; import { judgeConfig } from './judgeSDK/utils/judgeConfig'; import { getTCP } from '../common/utils/GlobalTcp'; -import { getSingleCenterTable, setliushuiNum, takePhotoFn ,uploadLogFile} from '../common/service/indexService'; +import { getSingleCenterTable, setliushuiNum, takePhotoFn, uploadLogFile } from '../common/service/indexService'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; import promptAction from '@ohos.promptAction'; import errorMsgDialog from './compontents/errorMsgDialog'; @@ -19,8 +19,11 @@ import UdpEvent from '../common/utils/UdpEvent'; import { delPic } from '../common/service/videoService'; import imageBtn from './compontents/imageBtn'; import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; -import {updateModelAndCar} from '../common/autoUpdate/index' +import { updateModelAndCar } from '../common/autoUpdate/index' import { UsbUtils } from '../common/utils/UsbUtils' +import appRecovery from '@ohos.app.ability.appRecovery'; +import PreferenceUtils from '../common/utils/PreferenceUtils'; +import CozyMsgDialog from './compontents/CozyDialog'; @Entry @Component @@ -77,7 +80,7 @@ struct Index { Column() { Column() { Row() { - Image($r('app.media.logo')).width('30%').height('5.5%').margin({ left: 24 }) .gesture( + Image($r('app.media.logo')).width('30%').height('5.5%').margin({ left: 24 }).gesture( GestureGroup(GestureMode.Exclusive, TapGesture({ count: 2 }) .onAction(async () => { @@ -355,7 +358,7 @@ struct Index { .width(80 * globalThis.ratio) .height(80 * globalThis.ratio) .position({ x: 288 * globalThis.ratio, y: 89 * globalThis.ratio }) - Text(this.loadingText ||'获取考车信息,请稍候……') + Text(this.loadingText || '获取考车信息,请稍候……') .fontSize(24 * globalThis.ratio) .margin({ top: 20 * globalThis.ratio }) .fontWeight(400) @@ -377,6 +380,16 @@ struct Index { } async aboutToAppear() { + const isRestart = await PreferenceUtils.getOtherModel("isRestart") + if (isRestart === "1") { + PreferenceUtils.writeOtherData("0","isRestart") + router.pushUrl({ + url: 'pages/UserInfo', + params: { + type: 1 + } + }, router.RouterMode.Single); + } // setInterval(() => { // let date = new Date(); // console.info('jiangsong1:timeSynchronization begin '); @@ -451,9 +464,9 @@ struct Index { this.loading = true console.log("sql 1111") - getSingleCenterTable(param).then(async (ret:any) => { + getSingleCenterTable(param).then(async (ret: any) => { - if(!this.isModelInit){ + if (!this.isModelInit) { this.loading = true this.loadingText = '正在下载考车模型,请稍候……' await updateModelAndCar(false) @@ -462,7 +475,7 @@ struct Index { this.isModelInit = true } - if(typeof ret == 'object' && ret.resultCode == '3'){ + if (typeof ret == 'object' && ret.resultCode == '3') { this.loadingText = '正在下载考车最新版本,请稍候……' this.loading = true await updateModelAndCar(true) @@ -482,7 +495,7 @@ struct Index { if (globalThis.singlePlay) { router.pushUrl({ url: 'pages/userInfo' - },router.RouterMode.Single) + }, router.RouterMode.Single) return } if (globalThis.singlePlay) { diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index 3121eae8..58c418cd 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -24,6 +24,9 @@ import errorMsgDialog from './compontents/errorMsgDialog'; import imageBtn from './compontents/imageBtn'; import FileUtil from '../common/utils/File'; import DB, { ColumnType } from '../common/database/DbSql'; +import CozyMsgDialog from './compontents/CozyDialog'; +import PreferenceUtils from '../common/utils/PreferenceUtils'; +import appRecovery from '@ohos.app.ability.appRecovery'; @Entry @Component @@ -78,6 +81,7 @@ struct UserInfo { @State faceFlag: string = '0'; @State FaceOpenStatue: string = '0'; //是否开启人脸识别 @State faceCatchImg: string = '' + @State examCount: number = 0 @State systemParam: systemParam = { 'Param341': true, //是否按顺序考试 'Param803Str': '0', //开始考试前必须解开安全带或关车门 @@ -185,6 +189,10 @@ struct UserInfo { { label: '考试员名', key: 'ksy2' }, ] private fileUtil: FileUtil + cozyDialog: CustomDialogController = new CustomDialogController({ + builder: CozyMsgDialog(), + autoCancel: false + }) aboutToAppear() { this.fileUtil = new FileUtil(this.context) @@ -192,6 +200,15 @@ struct UserInfo { } async onPageShow() { + if (this.examCount > 2) { + PreferenceUtils.writeOtherData("1", "isRestart") + this.cozyDialog.open() + // 延迟关闭 + setTimeout(() => { + this.cozyDialog.close() + appRecovery.restartApp() + }, 3000) + } this.isExamStart = false this.startExam = false this.updateTimeLimit = false @@ -210,7 +227,7 @@ struct UserInfo { if (!globalThis.singlePlay) { // @ts-ignore if (routerParam.type != 1) { - console.info('surenjun','Judge返回到UserInfo界面') + console.info('surenjun', 'Judge返回到UserInfo界面') // @ts-ignore this.list = await getSyncData('USERLIST') // @ts-ignore @@ -219,7 +236,7 @@ struct UserInfo { console.log('surenjun useruser1=>,', JSON.stringify(data)) const user = data[0] - if(!Number(user.kssycs)){ + if (!Number(user.kssycs)) { this.list = this.list.filter(res => { return res.sfzmhm != user.sfzmhm }) @@ -538,7 +555,7 @@ struct UserInfo { if (sys.v_no === '770') { that.systemParam.Param770Str = sys.v_value; } - if(sys.v_no === '853'){ + if (sys.v_no === '853') { that.systemParam.Param853 = sys.v_value; } if (sys.v_no === '835') { @@ -969,7 +986,7 @@ struct UserInfo { const ygd = msgArr[8]; const ssc = msgArr[13]; const dw = msgArr[28]; - if(Param853Str == '1' && fdjzs * 1 > 0){ + if (Param853Str == '1' && fdjzs * 1 > 0) { this.avPlayer.playAudio(['voice/熄火.mp3']) promptAction.showToast({ message: '请熄火', @@ -1157,12 +1174,12 @@ struct UserInfo { CommText({ ratio: this.ratio, color: item.sfzmhm != this.currentUser.sfzmhm ? '#FFFFFF' : '#000000', - text: this.systemParam.Param850&&Number(this.systemParam.Param850)>0?"*****":item.lsh + text: this.systemParam.Param850 && Number(this.systemParam.Param850) > 0 ? "*****" : item.lsh }) CommText({ ratio: this.ratio, color: item.sfzmhm != this.currentUser.sfzmhm ? '#FFFFFF' : '#000000', - text: this.systemParam.Param850&&Number(this.systemParam.Param850)>0?"*****":decodeURIComponent(item.xm) + text: this.systemParam.Param850 && Number(this.systemParam.Param850) > 0 ? "*****" : decodeURIComponent(item.xm) }) } } @@ -1231,39 +1248,39 @@ struct UserInfo { Column() { ForEach(this.labelBlocks, (item) => { - if(this.systemParam.Param850=='1'){ - LabelBlock({ label: item.label, ratio: this.ratio, value:'*****'}) + if (this.systemParam.Param850 == '1') { + LabelBlock({ label: item.label, ratio: this.ratio, value: '*****' }) } - else if(this.systemParam.Param850=='2'){ - if(item.key=='xm'){ + else if (this.systemParam.Param850 == '2') { + if (item.key == 'xm') { LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser.xh }) - }else if(item.key=='ksxl'){ + } else if (item.key == 'ksxl') { LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser[item.key] }) - }else{ + } else { LabelBlock({ label: item.label, ratio: this.ratio, value: '*****' }) } - }else if(this.systemParam.Param850=='4'){ - if(item.key=='ksxl'){ + } else if (this.systemParam.Param850 == '4') { + if (item.key == 'ksxl') { LabelBlock({ label: item.label, ratio: this.ratio, value: '*****' }) - }else{ + } else { LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser[item.key] }) } - }else if(this.systemParam.Param850=='5'){ - if(item.key=='xm'){ + } else if (this.systemParam.Param850 == '5') { + if (item.key == 'xm') { LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser.xh }) - }else{ + } else { LabelBlock({ label: item.label, ratio: this.ratio, value: '*****' }) } - }else if(this.systemParam.Param850=='6'){ - if(item.key=='ksxl'||item.key=='kssycs'){ - LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser[item.key] }) - }else if(item.key=='sfzmhm'){ + } else if (this.systemParam.Param850 == '6') { + if (item.key == 'ksxl' || item.key == 'kssycs') { + LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser[item.key] }) + } else if (item.key == 'sfzmhm') { LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser.sfzmhm.slice(-6) }) - }else{ + } else { LabelBlock({ label: item.label, ratio: this.ratio, value: '*****' }) } } - else{ + else { LabelBlock({ label: item.label, ratio: this.ratio, value: this.currentUser[item.key] }) } @@ -1281,7 +1298,7 @@ struct UserInfo { // .commStyle() imageBtn({ btnWidth: 220 * this.ratio, btnHeight: 69 * this.ratio, imgSrc: $r('app.media.yydj_btn') }) .margin({ bottom: 12 * this.ratio }) - .onClick(()=>{ + .onClick(() => { globalThis.judgeUdp.askVoice() }) @@ -1332,13 +1349,14 @@ struct UserInfo { if (this.systemParam.Param612Str == '1') { return } - if(!globalThis.singlePlay&&Number(this.systemParam.Param835)&&Number(this.currentUser.yycs)&&Number(this.systemParam.Param835)<=Number(this.currentUser.yycs)){ - this.type='4' - this.title='当前考生预约考试次数为'+this.currentUser.yycs + if (!globalThis.singlePlay && Number(this.systemParam.Param835) && Number(this.currentUser.yycs) && Number(this.systemParam.Param835) <= Number(this.currentUser.yycs)) { + this.type = '4' + this.title = '当前考生预约考试次数为' + this.currentUser.yycs this.errorDialog.open() return } - + this.examCount++ + console.log("已经考了", this.examCount + "个学员") await this.prePareExam() }) } diff --git a/entry/src/main/ets/pages/compontents/CozyDialog.ets b/entry/src/main/ets/pages/compontents/CozyDialog.ets new file mode 100644 index 00000000..d660dc80 --- /dev/null +++ b/entry/src/main/ets/pages/compontents/CozyDialog.ets @@ -0,0 +1,18 @@ +@CustomDialog +export default struct CozyMsgDialog { + private controller?: CustomDialogController + + build() { + Column() { + Column() { + Text("温馨提示").fontSize(50) + Row() { + Text("设备已经进行过6次考试,马上进入内存以及数据优化过,请稍等片刻,请勿对机器进行操作,感谢配合!") + .fontSize(30).lineHeight(40) + }.width("100%").margin({ + top: 20 + }).padding(20) + } + }.width("100%").height(300).padding(20) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/judgeSDK/api/index.ts b/entry/src/main/ets/pages/judgeSDK/api/index.ts index 6ec593da..b444ac28 100644 --- a/entry/src/main/ets/pages/judgeSDK/api/index.ts +++ b/entry/src/main/ets/pages/judgeSDK/api/index.ts @@ -1,6 +1,6 @@ -import libJudgeSdk from 'libJudgeSdk.so' +// import libJudgeSdk from 'libJudgeSdk.so' //@ts-ignore -// import libJudgeSdk from '@ohos.judgesdk' +import libJudgeSdk from '@ohos.judgesdk' /** * 苏仁君 * @date 2023/04/10 diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 79a0205f..422c62eb 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -5,6 +5,7 @@ "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", "deviceTypes": [ "default", "tablet", @@ -15,13 +16,13 @@ "abilities": [ { "name": "EntryAbility", - "srcEntrance": "./ets/entryability/EntryAbility.ts", + "srcEntry": "./ets/entryability/EntryAbility.ts", "description": "$string:EntryAbility_desc", "icon": "$media:logo_app", "label": "$string:EntryAbility_label", "startWindowIcon": "$media:icon", "startWindowBackground": "$color:start_window_background", - "visible": true, + "exported": true, "skills": [ { "entities": [ diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index bc40219d..1f023b33 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -1,13 +1,15 @@ { - "lockfileVersion": 1, + "lockfileVersion": 2, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6" }, "packages": { "@ohos/hypium@1.0.6": { - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", - "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==" + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", + "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==", + "registryType": "ohpm", + "shasum": "3f5fed65372633233264b3447705b0831dfe7ea1" } } } \ No newline at end of file