diff --git a/entry/src/main/ets/pages/SceneConfirm.ets b/entry/src/main/ets/pages/SceneConfirm.ets index 640d6407bfcef116934729c75a93c25729967597..f626a1c03ba7d7a93d74e990da67c8195657e74a 100644 --- a/entry/src/main/ets/pages/SceneConfirm.ets +++ b/entry/src/main/ets/pages/SceneConfirm.ets @@ -23,19 +23,18 @@ import { DataConfig } from '../common/store/DataInterface'; @HMRouter({ pageUrl: 'SceneConfirm', dialog: true }) @Component export struct SceneConfirm { - @StorageLink('configSource') configSource: Array | undefined = AppStorage.get('configSource')!; + @StorageLink('configSource') @Watch('configSourceChange') configSource: Array | undefined = AppStorage.get('configSource')!; private title: string | Resource = ''; private content: string | Resource = ''; - private data: Array = AppStorage.get('configSource')!; - aboutToAppear(): void { + initConfigSource() { const sceneIndex: number = AppStore.getInstance().currentSceneIndex; const stepIndex: number = AppStore.getInstance().currentStepIndex; - this.title = this.data[sceneIndex].steps[stepIndex].dialogTitle; - this.content = this.data[sceneIndex].steps[stepIndex].dialogContent; - if (this.data[sceneIndex].steps[stepIndex].service) { - const serviceName: string = this.data[sceneIndex].steps[stepIndex].service; + this.title = this.configSource![sceneIndex].steps[stepIndex].dialogTitle; + this.content = this.configSource![sceneIndex].steps[stepIndex].dialogContent; + if (this.configSource![sceneIndex].steps[stepIndex].service) { + const serviceName: string = this.configSource![sceneIndex].steps[stepIndex].service; if (!serviceName) { return; } @@ -47,6 +46,14 @@ export struct SceneConfirm { } } + aboutToAppear(): void { + this.initConfigSource(); + } + + configSourceChange() { + this.initConfigSource(); + } + build() { Stack() { Column() diff --git a/entry/src/main/ets/pages/SceneHome.ets b/entry/src/main/ets/pages/SceneHome.ets index c7b9f11f1cf8e7113aefcdc8a7663eea59f8f51e..7800f21bb257df9e3bf03411a1d54f9de70b8a96 100644 --- a/entry/src/main/ets/pages/SceneHome.ets +++ b/entry/src/main/ets/pages/SceneHome.ets @@ -47,8 +47,8 @@ export struct SceneHome { @State bestExperience: string[] = []; @State stepTips: string[] = []; @State description: string = ''; + @State private sceneIndex: number = AppStore.getInstance().currentSceneIndex; scroller: Scroller = new Scroller(); - private sceneIndex: number = AppStore.getInstance().currentSceneIndex; initConfigSource() { this.checkPoint = this.configSource![this.sceneIndex].checkPoint; @@ -90,14 +90,14 @@ export struct SceneHome { .layoutWeight(1); Column() { - Text((AppStore.getInstance().currentSceneIndex + 1) + '/13') + Text((this.sceneIndex + 1) + '/13') .margin({ top: 10, bottom: 22 }); Row() { - if (AppStore.getInstance().currentSceneIndex > 0) { + if (this.sceneIndex > 0) { Button($r('app.string.common_previous'), { type: ButtonType.Capsule, stateEffect: false }) .width('48%') .height(40) @@ -105,16 +105,16 @@ export struct SceneHome { .backgroundColor('rgba(0, 0, 0, 0.05)') .onClick(() => { AppStore.getInstance().currentSceneIndex--; + this.sceneIndex--; - const sceneIndex = AppStore.getInstance().currentSceneIndex; - const lastStepLength = AppStore.getInstance().optionRecord[sceneIndex].jumpIndex; + const lastStepLength = AppStore.getInstance().optionRecord[this.sceneIndex].jumpIndex; const stepIndex = AppStore.getInstance().currentStepIndex; let stackLength = (lastStepLength + 1 + stepIndex) * 2; - if (AppStore.getInstance().optionRecord[sceneIndex].isSkiped) { + if (AppStore.getInstance().optionRecord[this.sceneIndex].isSkiped) { stackLength = stackLength - 1; } - AppStore.getInstance().isMultiStep = this.configSource![sceneIndex].steps.length > 1; + AppStore.getInstance().isMultiStep = this.configSource![this.sceneIndex].steps.length > 1; AppStore.getInstance().currentStepIndex = 0; for (let i = 0; i < stackLength; i++) { HMRouterMgr.pop(); @@ -122,7 +122,7 @@ export struct SceneHome { }); } Button($r('app.string.common_skip'), { type: ButtonType.Capsule, stateEffect: false }) - .width(AppStore.getInstance().currentSceneIndex > 0 ? '48%' : '100%') + .width(this.sceneIndex > 0 ? '48%' : '100%') .height(40) .fontColor($r('app.color.primary_button')) .backgroundColor('rgba(0, 0, 0, 0.05)')