Browse Source

feat: 修改 入口页 和 Index 页面的加载逻辑。
*

YuJing 1 month ago
parent
commit
dee7e4f27c

+ 1 - 6
commons/basic/src/main/ets/constants/index.ets

@@ -55,14 +55,9 @@ export enum AppStorageKeyCollect {
   PUSH_TOKEN = 'pushToken',
   /**
    * @type boolean
-   * @description 是否首次进入APP
+   * @description 是否显示入口页
    */
   FIRST_ENTER_APP = 'firstEnterApp',
-  /**
-   * @type boolean
-   * @description 是否为单机状态下的app
-   */
-  IS_STAND_ALONE_APP = 'IsStandAloneApp'
 }
 
 export enum EmitterKeyCollection {

+ 3 - 12
commons/basic/src/main/ets/utils/arkts/utils/ContextHelper.ets

@@ -89,19 +89,10 @@ export class ContextHelper {
   static init(context: UIContext, oldContext: Context, isOnline: boolean = true) {
     ContextHelper.UIContext = context
     ContextHelper._oldContext = oldContext
-    PersistentStorage.persistProp(AppStorageKeyCollect.IS_STAND_ALONE_APP, isOnline)
-    if (isOnline) {
-      PersistentStorage.persistProp(AppStorageKeyCollect.TOKEN, '')
-      YTUserRequest.refreshUserInfo()
-      tkAdHelper.init()
-    } else {
-      PersistentStorage.persistProp(AppStorageKeyCollect.FIRST_ENTER_APP, false)
-      let isFirst = AppStorage.get(AppStorageKeyCollect.FIRST_ENTER_APP)! as boolean
-      if (!isFirst) {
-        yTRouter.pushPathByName('EntryPage', null)
-      }
-    }
 
+    PersistentStorage.persistProp(AppStorageKeyCollect.TOKEN, '')
+    // YTUserRequest.refreshUserInfo()
+    tkAdHelper.init()
 
     permissionController.init(ContextHelper.context)
       .then(() => {

+ 9 - 1
products/entry/src/main/ets/entryability/EntryAbility.ets

@@ -24,7 +24,15 @@ export default class EntryAbility extends UIAbility {
   }
 
   onWindowStageCreate(windowStage: window.WindowStage): void {
-    windowStage.loadContent('/pages/Index'.slice(1), (err) => {
+    windowStage.loadContent('/pages/EntryPage'.slice(1), (err) => {
+    // windowStage.loadContent('/pages/Index'.slice(1), (err) => {
+      // 不需要入口页,注释这段代码
+      PersistentStorage.persistProp(AppStorageKeyCollect.FIRST_ENTER_APP, false)
+      let isFirst = AppStorage.get<boolean>(AppStorageKeyCollect.FIRST_ENTER_APP)
+      if (isFirst) {
+        windowStage.loadContent('/pages/Index'.slice(1))
+      }
+
       if (err.code) {
         hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
         return;

+ 32 - 48
products/entry/src/main/ets/pages/EntryPage.ets

@@ -1,9 +1,7 @@
-import { common } from '@kit.AbilityKit'
-import { RouterPage, yTRouter } from 'basic'
 
 // app 入口页面
+@Entry
 @Component
-@RouterPage
 struct EntryPage {
   // 渐变色
   linear: LinearGradientOptions = {
@@ -12,58 +10,44 @@ struct EntryPage {
 
   // 点击立刻体验按钮
   _onClick() {
-    yTRouter.pushPathByName('PrivacyPage', null)
+    this.getUIContext().getRouter().pushUrl({ url: 'pages/PrivacyPage' })
   }
 
-  // 重写返回事件
-  _onBack() {
-    // 点击返回直接关闭 app
-    (this.getUIContext().getHostContext() as common.UIAbilityContext).terminateSelf()
-    return true
-  }
 
   build() {
-    NavDestination() {
-      Column() {
-        Column(){
-          Column({space: 13}){
-            Image($r('app.media.app_icon'))
-              .width(100)
-              .aspectRatio(1)
-              .borderRadius(20)
-
-            Text($r('app.string.app_name'))
-              .fontSize(18)
-              .fontWeight(500)
-              .fontColor(Color.Black)
-          }
-          .backgroundColor(Color.Transparent)
-
-          Blank()
-            .height(197)
+    Column() {
+      Column(){
+        Column({space: 13}){
+          Image($r('app.media.app_icon'))
+            .width(100)
+            .aspectRatio(1)
+            .borderRadius(20)
 
-          Text("立刻体验")
-            .fontSize(22)
+          Text($r('app.string.app_name'))
+            .fontSize(18)
             .fontWeight(500)
-            .borderRadius(20)
-            .fontColor('#FAFAFA')
-            .backgroundColor('#7186F9')
-            .padding({left: 25, top: 7, right: 25, bottom: 7})
-            .onClick(() => { this._onClick() })
+            .fontColor(Color.Black)
         }
-        .justifyContent(FlexAlign.SpaceBetween)
+        .backgroundColor(Color.Transparent)
+
+        Blank()
+          .height(197)
+
+        Text("立刻体验")
+          .fontSize(22)
+          .fontWeight(500)
+          .borderRadius(20)
+          .fontColor('#FAFAFA')
+          .backgroundColor('#7186F9')
+          .padding({left: 25, top: 7, right: 25, bottom: 7})
+          .onClick(() => { this._onClick() })
       }
-      .width('100%')
-      .height('100%')
-      .alignItems(HorizontalAlign.Center)
-      .justifyContent(FlexAlign.Center)
-      .linearGradient(this.linear)
+      .justifyContent(FlexAlign.SpaceBetween)
     }
-    .hideTitleBar(true)
-    .onBackPressed(() => { return this._onBack() })
+    .width('100%')
+    .height('100%')
+    .alignItems(HorizontalAlign.Center)
+    .justifyContent(FlexAlign.Center)
+    .linearGradient(this.linear)
   }
-}
-@Builder
-function EntryBuilder() {
-  EntryPage()
-}
+}

+ 1 - 1
products/entry/src/main/ets/pages/Index.ets

@@ -36,7 +36,7 @@ struct Index {
 
   aboutToAppear(): void {
     ContextHelper.init(this.getUIContext(), getContext())
-
+    this.getUIContext().getRouter().clear()
 
   }
 

+ 67 - 75
products/entry/src/main/ets/pages/PrivacyPage.ets

@@ -1,10 +1,10 @@
-import { AppStorageKeyCollect, BasicType, YTAvoid, yTRouter, RouterPage } from 'basic'
+import { AppStorageKeyCollect, BasicType, YTAvoid } from 'basic'
 import { webview } from '@kit.ArkWeb'
 
 
 // 隐私协议 说明页面
+@Entry
 @Component
-@RouterPage
 struct PrivacyPage {
   @StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
   // 倒计时
@@ -22,14 +22,15 @@ struct PrivacyPage {
   ]
 
   _onBack(){
-    yTRouter.pop()
-    return true
+    this.getUIContext().getRouter().back()
   }
 
   // 同意
   _onConfirm(){
     AppStorage.set(AppStorageKeyCollect.FIRST_ENTER_APP, true)
-    yTRouter.clear()
+    this.getUIContext().getRouter().pushUrl({
+      url: 'pages/Index'
+    })
   }
 
   aboutToAppear(): void {
@@ -39,88 +40,79 @@ struct PrivacyPage {
     }, 1000)
   }
 
-
   build() {
-    NavDestination() {
-      Column({space: 40}) {
-        Text('隐私政策及用户协议')
-          .fontSize(18)
-          .fontWeight(500)
-          .fontColor(Color.Black)
-
-        // Main
-        Column({space: 10}){
-          ForEach(this.forEach, (item: BasicType) => {
-              Column({ space: 8 }) {
-                Text(item.text)
-                  .fontColor(Color.Black)
-                Row() {
-                  Web({
-                    src: item.message,
-                    controller: this.webviewController,
-                    renderMode: RenderMode.ASYNC_RENDER // 设置渲染模式
-                  })
-                }
-                .height(225)
-                .width('100%')
-                .padding(8)
-                .border({ width: 1 })
-              }
-              .alignItems(HorizontalAlign.Start)
-          })
+    Column({space: 40}) {
+      Text('隐私政策及用户协议')
+        .fontSize(18)
+        .fontWeight(500)
+        .fontColor(Color.Black)
 
-          Blank().height(10)
+      // Main
+      Column({space: 10}){
+        ForEach(this.forEach, (item: BasicType) => {
+          Column({ space: 8 }) {
+            Text(item.text)
+              .fontColor(Color.Black)
+            Row() {
+              Web({
+                src: item.message,
+                controller: this.webviewController,
+                renderMode: RenderMode.ASYNC_RENDER // 设置渲染模式
+              })
+            }
+            .height(225)
+            .width('100%')
+            .padding(8)
+            .border({ width: 1 })
+          }
+          .alignItems(HorizontalAlign.Start)
+        })
 
-          Row(){
-            Text('我不同意并返回')
-              .fontSize(16)
-              .fontWeight(400)
-              .fontColor('#676767')
-              .onClick(() => { this._onBack() })
+        Blank().height(10)
 
-            Text(`我已全部了解${this.time != 0 ? ' ('+this.time+')' : '' }`)
-              .fontSize(18)
-              .fontWeight(500)
-              .borderRadius(20)
-              .fontColor('#FAFAFA')
-              .enabled(this.time == 0)
-              .backgroundColor(this.time == 0 ?'#7186F9' : '#ffacbaf3')
-              .padding({ left: 20, top: 8, right: 20, bottom: 8 })
-              .onClick(() => { this._onConfirm() })
-          }
-          .width('100%')
-          .padding({top: 5, bottom: 5})
-          .alignItems(VerticalAlign.Center)
-          .justifyContent(FlexAlign.SpaceBetween )
+        Row(){
+          Text('我不同意并返回')
+            .fontSize(16)
+            .fontWeight(400)
+            .fontColor('#676767')
+            .onClick(() => { this._onBack() })
 
-          Row(){
-            Text('*请仔细阅读以上协议内容,点击同意表示您已充分理解并接受协议条款')
-              .fontSize(10)
-              .fontWeight(400)
-              .fontColor('#F50000')
-          }
-          .padding({top: 5})
-          .width("100%")
-          .justifyContent(FlexAlign.Center)
+          Text(`我已全部了解${this.time != 0 ? ' ('+this.time+')' : '' }`)
+            .fontSize(18)
+            .fontWeight(500)
+            .borderRadius(20)
+            .fontColor('#FAFAFA')
+            .enabled(this.time == 0)
+            .backgroundColor(this.time == 0 ?'#7186F9' : '#ffacbaf3')
+            .padding({ left: 20, top: 8, right: 20, bottom: 8 })
+            .onClick(() => { this._onConfirm() })
         }
         .width('100%')
-        .layoutWeight(1)
-        .alignItems(HorizontalAlign.Start)
-        .justifyContent(FlexAlign.Start)
+        .padding({top: 5, bottom: 5})
+        .alignItems(VerticalAlign.Center)
+        .justifyContent(FlexAlign.SpaceBetween )
+
+        Row(){
+          Text('*请仔细阅读以上协议内容,点击同意表示您已充分理解并接受协议条款')
+            .fontSize(10)
+            .fontWeight(400)
+            .fontColor('#F50000')
+        }
+        .padding({top: 5})
+        .width("100%")
+        .justifyContent(FlexAlign.Center)
       }
       .width('100%')
-      .height('100%')
+      .layoutWeight(1)
       .padding({left: 16, right: 16})
-      .alignItems(HorizontalAlign.Center)
-      .justifyContent(FlexAlign.Center)
+      .alignItems(HorizontalAlign.Start)
+      .justifyContent(FlexAlign.Start)
     }
+    .width('100%')
+    .height('100%')
+    .alignItems(HorizontalAlign.Center)
+    .justifyContent(FlexAlign.Center)
     .backgroundColor(Color.White)
-    .hideTitleBar(true)
     .padding({ top: this.safeTop })
-    .onBackPressed(() => { return this._onBack() })
   }
 }
-@Builder
-function PrivacyBuilder() {
-  PrivacyPage()
-}

+ 0 - 1
products/entry/src/main/module.json5

@@ -2,7 +2,6 @@
   "module": {
     "name": "entry",
     "type": "entry",
-    "routerMap": "$profile:router_map",
     "description": "$string:module_desc",
     "mainElement": "EntryAbility",
     "deviceTypes": [

+ 3 - 1
products/entry/src/main/resources/base/profile/main_pages.json

@@ -1,5 +1,7 @@
 {
   "src": [
-    "pages/Index"
+    "pages/Index",
+    "pages/EntryPage",
+    "pages/PrivacyPage"
   ]
 }

+ 0 - 14
products/entry/src/main/resources/base/profile/router_map.json

@@ -1,14 +0,0 @@
-{
-  "routerMap": [
-    {
-      "name": "EntryPage",
-      "pageSourceFile": "src/main/ets/pages/EntryPage.ets",
-      "buildFunction": "EntryBuilder"
-    },
-    {
-      "name": "PrivacyPage",
-      "pageSourceFile": "src/main/ets/pages/PrivacyPage.ets",
-      "buildFunction": "PrivacyBuilder"
-    }
-  ]
-}