chenritian hai 2 semanas
pai
achega
fb53d05a34

+ 8 - 1
entry/src/main/ets/entryability/EntryAbility.ets

@@ -3,6 +3,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit';
 import { window } from '@kit.ArkUI';
 import { WindowHelper } from '../utils/WindowHelper';
 import { IBestInit } from '@ibestservices/ibest-ui';
+import { AppStorageKeyCollect } from '../constants';
 
 const DOMAIN = 0x0000;
 
@@ -24,13 +25,19 @@ export default class EntryAbility extends UIAbility {
     // Main window is created, set main page for this ability
     hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
 
-    windowStage.loadContent('pages/Index', (err) => {
+    windowStage.loadContent('/pages/EntryPage'.slice(1), (err) => {
       if (err.code) {
         hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
         return;
       }
       WindowHelper.init(windowStage)
       IBestInit(windowStage, this.context)
+
+      PersistentStorage.persistProp(AppStorageKeyCollect.FIRST_ENTER_APP, false)
+      let isFirst = AppStorage.get<boolean>(AppStorageKeyCollect.FIRST_ENTER_APP)
+      if (isFirst) {
+        windowStage.loadContent('/pages/Index'.slice(1))
+      }
       hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
     });
   }

+ 77 - 0
entry/src/main/ets/pages/EntryPage.ets

@@ -0,0 +1,77 @@
+import { common } from '@kit.AbilityKit'
+import { router } from '@kit.ArkUI'
+
+@Component
+@Entry
+struct EntryPage {
+  // 点击立刻体验按钮
+  _onClick() {
+    router.pushUrl({
+      url: '/pages/PrivacyPage'.slice(1)
+    })
+  }
+
+  // 重写返回事件
+  _onBack() {
+    // 点击返回直接关闭 app
+    (this.getUIContext().getHostContext() as common.UIAbilityContext).terminateSelf()
+    return true
+  }
+
+  build() {
+    NavDestination() {
+      Column() {
+        Column() {
+          Column({ space: 13 }) {
+            Image($r('app.media.startIcon'))
+              .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)
+
+          Text("立刻体验")
+            .fontSize(22)
+            .fontWeight(500)
+            .borderRadius(20)
+            .fontColor('#FAFAFA')
+            .backgroundColor('#7186F9')
+            .padding({
+              left: 25,
+              top: 7,
+              right: 25,
+              bottom: 7
+            })
+            .onClick(() => {
+              this._onClick()
+            })
+        }
+        .justifyContent(FlexAlign.SpaceBetween)
+      }
+      .width('100%')
+      .height('100%')
+      .alignItems(HorizontalAlign.Center)
+      .justifyContent(FlexAlign.Center)
+      .linearGradient({
+        colors: [['#EBF7FF', 0.3], ['#A9A8FF', 1]],
+      })
+    }
+    .hideTitleBar(true)
+    .onBackPressed(() => {
+      return this._onBack()
+    })
+  }
+}
+
+@Builder
+function EntryPageBuilder() {
+  EntryPage()
+}

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

@@ -39,6 +39,7 @@ struct Index {
   ]
 
   aboutToAppear(): void {
+
     ContextHelper.init(this.getUIContext(), getContext())
     yTBindSheet.init({
       context: this.getUIContext(),

+ 137 - 0
entry/src/main/ets/pages/PrivacyPage.ets

@@ -0,0 +1,137 @@
+import { webview } from '@kit.ArkWeb'
+import { BasicType } from '../models'
+import { router } from '@kit.ArkUI'
+import { YTAvoid } from '../utils/YTAvoid'
+import { AppStorageKeyCollect } from '../constants'
+
+@Component
+@Entry
+struct PrivacyPage {
+  @State safeTop: number = 30
+  // 倒计时
+  @State time: number = 5
+  private webviewController: WebviewController = new webview.WebviewController()
+  private forEach: Array<BasicType> = [
+    {
+      text: '隐私政策',
+      message: 'https://file.ytmdm.com/小易旅记隐私协议.html'
+    }, {
+    text: '用户协议',
+    message: 'https://file.ytmdm.com/小易旅记用户协议.html'
+  }
+  ]
+
+  _onBack() {
+    router.back()
+    return true
+  }
+
+  // 同意
+  _onConfirm() {
+    AppStorage.set(AppStorageKeyCollect.FIRST_ENTER_APP, true)
+    this.getUIContext().getRouter().pushUrl({
+      url: 'pages/Index'
+    })
+  }
+
+  aboutToAppear(): void {
+    this.safeTop = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
+
+    let _c = setInterval(() => {
+      this.time--
+      if (this.time == 0) {
+        clearInterval(_c)
+      }
+    }, 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)
+          })
+
+          Blank().height(10)
+
+          Row() {
+            Text('我不同意并返回')
+              .fontSize(16)
+              .fontWeight(400)
+              .fontColor('#676767')
+              .onClick(() => {
+                this._onBack()
+              })
+
+            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(10)
+              .fontWeight(400)
+              .fontColor('#F50000')
+          }
+          .padding({ top: 5 })
+          .width("100%")
+          .justifyContent(FlexAlign.Center)
+        }
+        .width('100%')
+        .layoutWeight(1)
+        .alignItems(HorizontalAlign.Start)
+        .justifyContent(FlexAlign.Start)
+      }
+      .width('100%')
+      .height('100%')
+      .padding({ left: 16, right: 16 })
+      .alignItems(HorizontalAlign.Center)
+      .justifyContent(FlexAlign.Center)
+    }
+    .backgroundColor(Color.White)
+    .hideTitleBar(true)
+    .padding({ top: this.safeTop })
+    .onBackPressed(() => {
+      return this._onBack()
+    })
+  }
+}

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

@@ -3,6 +3,8 @@
     "pages/Index",
     "pages/SuggestionPage",
     "pages/Privacy",
-    "pages/UserAgreement"
+    "pages/UserAgreement",
+    "pages/EntryPage",
+    "pages/PrivacyPage"
   ]
 }