Просмотр исходного кода

feat: 新增在去除登录后新的入口页面和隐私协议确认页面。 新增 oaid 工具类。

YuJing 1 месяц назад
Родитель
Сommit
3cbe1b1d83

+ 2 - 0
commons/basic/Index.ets

@@ -90,6 +90,8 @@ export { YTAddressSelectorDialog, DateOption } from './src/main/ets//datepicker/
 
 export { YTDateUtil, DateFormat } from './src/main/ets/utils/YTDateUtil'
 
+export { ytOaidUtils } from './src/main/ets/utils/YtOaidUtils'
+
 export * from '@mumu/crop'
 
 export * from './src/main/ets/models'

+ 14 - 1
commons/basic/src/main/ets/apis/YTRequest.ets

@@ -25,10 +25,23 @@ export const instance = axios.create({
 // 添加请求拦截器
 instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
 
-  // 对请求数据做点什么
+  // 对请求数据做点什么 - 为请求参数添加 token
   if (AppStorage.get<string>(AppStorageKeyCollect.TOKEN)) {
     config.headers.Authorization = AppStorage.get<string>(AppStorageKeyCollect.TOKEN)
   }
+
+  // 为请求参数添加 oaid
+  if ((config.method == 'get' || config.method == 'delete') && config.url) {
+    // if(config?.params) {
+    //   config.params.oaid = await ytOaidUtils.getOaid()
+    // }
+  } else {
+    // if(config?.data) {
+    //   config.data.oaid = await ytOaidUtils.getOaid()
+    // }
+  }
+
+
   YTLog.info(config.data, '请求参数')
 
   return config;

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

@@ -52,7 +52,17 @@ export enum AppStorageKeyCollect {
    * @type string
    * @description 推送token
    */
-  PUSH_TOKEN = 'pushToken'
+  PUSH_TOKEN = 'pushToken',
+  /**
+   * @type boolean
+   * @description 是否首次进入APP
+   */
+  FIRST_ENTER_APP = 'firstEnterApp',
+  /**
+   * @type boolean
+   * @description 是否为单机状态下的app
+   */
+  IS_STAND_ALONE_APP = 'IsStandAloneApp'
 }
 
 export enum EmitterKeyCollection {

+ 22 - 5
commons/basic/src/main/ets/utils/ContextHelper.ets

@@ -8,7 +8,9 @@ import {
   registerFontUtil,
   yTBindSheet,
   YTLog,
+  ytOaidUtils,
   yTPreferences,
+  yTRouter,
   YTToast,
   YTUserRequest
 } from '../../../../Index'
@@ -65,11 +67,26 @@ export class ContextHelper {
   }
 
 
-  //依赖上下文的工具类初始化 需要在第一个页面中设置UIContext后调用
-  static init(context: UIContext) {
+  /**
+   * 依赖上下文的工具类初始化 需要在第一个页面中设置UIContext后调用
+   * @param context 上下文对象
+   * @param isOnline 是否为在线app
+   */
+  static init(context: UIContext, isOnline: boolean = true) {
     ContextHelper.UIContext = context
-    PersistentStorage.persistProp(AppStorageKeyCollect.TOKEN, '')
-    YTUserRequest.refreshUserInfo()
+    PersistentStorage.persistProp(AppStorageKeyCollect.IS_STAND_ALONE_APP, isOnline)
+    if(isOnline) {
+      PersistentStorage.persistProp(AppStorageKeyCollect.TOKEN, '')
+      YTUserRequest.refreshUserInfo()
+    } else {
+      PersistentStorage.persistProp(AppStorageKeyCollect.FIRST_ENTER_APP, false)
+      let isFirst = AppStorage.get(AppStorageKeyCollect.FIRST_ENTER_APP)! as boolean
+      if(!isFirst) {
+        yTRouter.pushPathByName('EntryPage', null)
+      }
+    }
+
+
     permissionController.init(ContextHelper.context)
       .then(() => {
         permissionController
@@ -85,7 +102,7 @@ export class ContextHelper {
                   } else {
                     const oaid: string = data;
                     jHStartAd.init(ContextHelper.UIAbilityContext, oaid)
-                    AppStorage.setOrCreate('OAID', oaid)
+                    ytOaidUtils.setOaid(oaid)
                     YTLog.info(`succeeded in getting oaid by callback , oaid: ${oaid}`);
                   }
                 });

+ 28 - 0
commons/basic/src/main/ets/utils/YtOaidUtils.ets

@@ -0,0 +1,28 @@
+/**
+ * @description oaid 管理类
+ */
+class YtOaidUtils{
+  private messageQueue: ESObject[] =[]
+
+  getOaid(){
+    let oaid = AppStorage.get<string>('OAID')
+    if(!oaid) {
+      let p = new Promise<string>((resolve, reject) => {
+        this.messageQueue.push({resolve, reject})
+      })
+      return p
+    } else {
+      return Promise.resolve(oaid)
+    }
+  }
+
+  setOaid(oaid: string) {
+    AppStorage.setOrCreate('OAID', oaid)
+    this.messageQueue.forEach((item: ESObject) => {
+      item.resolve(oaid)
+    })
+    this.messageQueue = []
+  }
+}
+
+export const ytOaidUtils = new YtOaidUtils()

+ 69 - 0
products/entry/src/main/ets/pages/EntryPage.ets

@@ -0,0 +1,69 @@
+import { common } from '@kit.AbilityKit'
+import { RouterPage, yTRouter } from 'basic'
+
+// app 入口页面
+@Component
+@RouterPage
+struct EntryPage {
+  // 渐变色
+  linear: LinearGradientOptions = {
+    colors: [ ['#EBF7FF', 0.3], ['#A9A8FF', 1] ],
+  }
+
+  // 点击立刻体验按钮
+  _onClick() {
+    yTRouter.pushPathByName('PrivacyPage', null)
+  }
+
+  // 重写返回事件
+  _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)
+
+          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(this.linear)
+    }
+    .hideTitleBar(true)
+    .onBackPressed(() => { return this._onBack() })
+  }
+}
+@Builder
+function EntryBuilder() {
+  EntryPage()
+}

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

@@ -33,7 +33,8 @@ struct Index {
   tabsController: TabsController = new TabsController()
 
   aboutToAppear(): void {
-    ContextHelper.init(this.getUIContext())
+    // 设置为 false 表示为单机 app
+    ContextHelper.init(this.getUIContext(), false)
   }
 
   build() {

+ 126 - 0
products/entry/src/main/ets/pages/PrivacyPage.ets

@@ -0,0 +1,126 @@
+import { AppStorageKeyCollect, BasicType, YTAvoid, yTRouter, RouterPage } from 'basic'
+import { webview } from '@kit.ArkWeb'
+
+
+// 隐私协议 说明页面
+@Component
+@RouterPage
+struct PrivacyPage {
+  @StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
+  // 倒计时
+  @State time: number = 5
+
+  private webviewController: WebviewController = new webview.WebviewController()
+  private forEach: Array<BasicType> = [
+    {
+      text: '隐私政策',
+      message: 'https://hm-test.ytpm.net/classAffairsPrivacy'
+    }, {
+      text: '用户协议',
+      message: 'https://hm-test.ytpm.net/classAffairsUserAgreement'
+    }
+  ]
+
+  _onBack(){
+    yTRouter.pop()
+    return true
+  }
+
+  // 同意
+  _onConfirm(){
+    AppStorage.set(AppStorageKeyCollect.FIRST_ENTER_APP, true)
+    yTRouter.clear()
+  }
+
+  aboutToAppear(): void {
+    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() })
+  }
+}
+@Builder
+function PrivacyBuilder() {
+  PrivacyPage()
+}