From 5ac496e44b2a0f94dcc5cd3e3f6d84adb23de947 Mon Sep 17 00:00:00 2001 From: zywyl Date: Tue, 15 Oct 2024 10:36:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/SceneCheck.ets | 1 - entry/src/main/ets/pages/SceneConfirm.ets | 2 +- entry/src/main/ets/pages/SceneHome.ets | 43 +++++++++-------------- entry/src/main/ets/pages/ScorePage.ets | 9 +++-- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/entry/src/main/ets/pages/SceneCheck.ets b/entry/src/main/ets/pages/SceneCheck.ets index d700e3c..f44c55f 100644 --- a/entry/src/main/ets/pages/SceneCheck.ets +++ b/entry/src/main/ets/pages/SceneCheck.ets @@ -22,7 +22,6 @@ import { AppStore } from '../common/store/AppStore'; import { SceneOption } from '../common/store/Score'; import { IconContent } from '../components/IconContent'; - @HMLifecycle({ lifecycleName: 'SceneCheckLifecycle' }) export class SceneCheckLifecycle implements IHMLifecycle { private data: Array = AppStorage.get('configSource')! diff --git a/entry/src/main/ets/pages/SceneConfirm.ets b/entry/src/main/ets/pages/SceneConfirm.ets index 8e380b8..2cf9445 100644 --- a/entry/src/main/ets/pages/SceneConfirm.ets +++ b/entry/src/main/ets/pages/SceneConfirm.ets @@ -22,10 +22,10 @@ import { confirmServiceMap, DialogText } from '../common/utils/ConfirmService'; @HMRouter({ pageUrl: 'SceneConfirm', dialog: true }) @Component export struct SceneConfirm { + @StorageLink('configSource') configSource: Array | undefined = AppStorage.get('configSource')!; private title: string | Resource = ''; private content: string | Resource = ''; private data: Array = AppStorage.get('configSource')! - @StorageLink('configSource') configSource: Array | undefined = AppStorage.get('configSource')!; aboutToAppear(): void { const sceneIndex: number = AppStore.getInstance().currentSceneIndex; diff --git a/entry/src/main/ets/pages/SceneHome.ets b/entry/src/main/ets/pages/SceneHome.ets index 2172386..1adb5df 100644 --- a/entry/src/main/ets/pages/SceneHome.ets +++ b/entry/src/main/ets/pages/SceneHome.ets @@ -22,24 +22,7 @@ import { AppStore } from '../common/store/AppStore'; @HMLifecycle({ lifecycleName: 'SceneHomeLifecycle' }) @Observed export class SceneHomeLifecycle implements IHMLifecycle { - description: string = ''; - checkPoint: Array = []; - bestExperience: Array = []; - stepTips: Array = []; - data: Array = AppStorage.get('configSource')! - - onPrepare(ctx: HMLifecycleContext): void { - const sceneIndex: number = AppStore.getInstance().currentSceneIndex; - this.description = this.data[sceneIndex].sceneDescription; - this.checkPoint = this.data[sceneIndex].checkPoint; - this.bestExperience = this.data[sceneIndex].bestExperience; - if (this.data[sceneIndex].steps.length > 1) { - this.stepTips = this.data[sceneIndex].steps.map((item: Step) => item.text || ''); - AppStore.getInstance().isMultiStep = true; - } else { - this.stepTips = this.data[sceneIndex].stepTips; - } - } + private data: Array = AppStorage.get('configSource')!; onBackPressed(ctx: HMLifecycleContext): boolean { if (AppStore.getInstance().currentStepIndex > 0) { @@ -54,24 +37,29 @@ export class SceneHomeLifecycle implements IHMLifecycle { } } - @HMRouter({ pageUrl: 'SceneHome', lifecycle: 'SceneHomeLifecycle' }) @Component export struct SceneHome { - scroller: Scroller = new Scroller(); - private sceneIndex: number = AppStore.getInstance().currentSceneIndex; @StorageLink('configSource') @Watch('configSourceChange') configSource: Array | undefined = AppStorage.get('configSource')!; @State checkPoint: string[] = []; @State bestExperience: string[] = []; @State stepTips: string[] = []; @State description: string = ''; + scroller: Scroller = new Scroller(); + private sceneIndex: number = AppStore.getInstance().currentSceneIndex; initConfigSource() { this.checkPoint = this.configSource![this.sceneIndex].checkPoint; this.bestExperience = this.configSource![this.sceneIndex].bestExperience; - this.stepTips = this.configSource![this.sceneIndex].stepTips; this.description = this.configSource![this.sceneIndex].sceneDescription; + + if (this.configSource![this.sceneIndex].steps.length > 1) { + this.stepTips = this.configSource![this.sceneIndex].steps.map((item: Step) => item.text || ''); + AppStore.getInstance().isMultiStep = true; + } else { + this.stepTips = this.configSource![this.sceneIndex].stepTips; + } } aboutToAppear(): void { @@ -87,24 +75,25 @@ export struct SceneHome { Scroll(this.scroller) { Column() { Header({ description: this.description }); + MainContent({ checkPoint: this.checkPoint, bestExperience: this.bestExperience, stepTips: this.stepTips }); } - .constraintSize({ minHeight: "100%" }) + .constraintSize({ minHeight: '100%' }); } .scrollable(ScrollDirection.Vertical) .scrollBar(BarState.Off) - .layoutWeight(1) + .layoutWeight(1); Column() { Text((AppStore.getInstance().currentSceneIndex + 1) + '/13') .margin({ top: 10, bottom: 22 - }) + }); Row() { if (AppStore.getInstance().currentSceneIndex > 0) { @@ -116,7 +105,7 @@ export struct SceneHome { .onClick(() => { AppStore.getInstance().currentSceneIndex--; - const sceneIndex = AppStore.getInstance().currentSceneIndex + const sceneIndex = AppStore.getInstance().currentSceneIndex; const lastStepLength = AppStore.getInstance().optionRecord[sceneIndex].jumpIndex; const stepIndex = AppStore.getInstance().currentStepIndex; @@ -165,6 +154,6 @@ export struct SceneHome { }) .justifyContent(FlexAlign.SpaceBetween) .backgroundColor($r('app.color.page_background')) - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/ScorePage.ets b/entry/src/main/ets/pages/ScorePage.ets index 701aa35..0f7b733 100644 --- a/entry/src/main/ets/pages/ScorePage.ets +++ b/entry/src/main/ets/pages/ScorePage.ets @@ -39,16 +39,15 @@ export class SceneCheckLifecycle implements IHMLifecycle { @HMRouter({ pageUrl: 'ScorePage', singleton: true, lifecycle: 'ScorePageLifecycle' }) @Component export struct ScorePage { - @State requiredSceneInfo: Array = []; - @State recommendSceneInfo: Array = []; @StorageLink('configSource') @Watch('configSourceChange') configSource: Array | undefined = AppStorage.get('configSource')!; - scroller: Scroller = new Scroller(); + @State requiredSceneInfo: Array = []; + @State recommendSceneInfo: Array = []; @State title: string = ''; + scroller: Scroller = new Scroller(); private acquiredScore: number = 0; private totalScore: number = 0; - private tableData: Array> = - []; + private tableData: Array> = []; private csvFileUtil: CsvFileUtil | undefined = undefined; private dialogController: CustomDialogController = new CustomDialogController({ builder: GenerateFile({ -- Gitee