徐勤民 hai 6 meses
pai
achega
bba0b2ed77

+ 1 - 1
BuildProfile.ets

@@ -1,7 +1,7 @@
 /**
  * Use these variables when you tailor your ArkTS code. They must be of the const type.
  */
-export const HAR_VERSION = '1.0.2';
+export const HAR_VERSION = '1.0.3';
 export const BUILD_MODE_NAME = 'debug';
 export const DEBUG = true;
 export const TARGET_NAME = 'default';

+ 7 - 1
README.md

@@ -270,7 +270,13 @@ WindowHelper.setWindowLayoutFullScreen(true)
 WindowHelper.hideStatusBar()
 
 // 显示状态栏
-WindowHelper.showStatusBar
+WindowHelper.showStatusBar()
+
+// 顶部安全区高度
+WindowHelper.topRectHeight()
+
+// 底部安全区高度
+WindowHelper.bottomRectHeight()
 ```
 
 

+ 1 - 1
oh-package.json5

@@ -1,6 +1,6 @@
 {
   "name": "@szyx/sdk_base",
-  "version": "1.0.2",
+  "version": "1.0.3",
   "description": "数字医信公司,鸿蒙app开发基础工具。",
   "main": "Index.ets",
   "author": "szyx",

+ 13 - 3
src/main/ets/pages/XWebview.ets

@@ -6,6 +6,7 @@ import { picker } from '@kit.CoreFileKit';
 import { BusinessError } from '@kit.BasicServicesKit';
 import { ToolsHelper } from '../utils/ToolsHelper';
 import { XWebParams } from '../utils/XWebHelper';
+import { WindowHelper } from '../utils/WindowHelper';
 
 @Entry({ routeName: 'XWebview' })
 @Preview
@@ -14,6 +15,7 @@ export struct XWebview {
   // 手机号
   @State url: string = (router.getParams() as XWebParams).url
   @State title?: string = (router.getParams() as XWebParams).title
+  @State showMenu: boolean = (router.getParams() as XWebParams).showMenu ?? false
   @State errorInfo: string | null = null
   @State progress: number = 0
   controller: web_webview.WebviewController = new web_webview.WebviewController();
@@ -72,7 +74,7 @@ export struct XWebview {
           if (this.dialogController != null) {
             this.dialogController.open()
           }
-        })
+        }).visibility(this.showMenu ? Visibility.Visible : Visibility.Hidden)
       }
       .width('100%')
       .height(45)
@@ -145,7 +147,9 @@ export struct XWebview {
           }
         })
         .onErrorReceive((event) => { // 加载失败
-          if (this.progress > 65) return
+          if (this.progress > 65) {
+            return
+          }
           if (event) {
             this.errorInfo = `错误码:${event.error.getErrorCode()}\n${event.error.getErrorInfo()}`
           } else {
@@ -153,7 +157,9 @@ export struct XWebview {
           }
         })
         .onHttpErrorReceive((event) => { // 加载失败
-          if (this.progress > 65) return
+          if (this.progress > 65) {
+            return
+          }
           if (event) {
             this.errorInfo = `错误码:${event.response.getResponseCode()}\n${event.response.getReasonMessage()}`
           } else {
@@ -228,6 +234,10 @@ export struct XWebview {
       })
 
     }.width('100%').height('100%')
+    .padding({
+      top: WindowHelper.topRectHeight,
+      bottom: WindowHelper.bottomRectHeight
+    })
   }
 }
 

+ 31 - 0
src/main/ets/utils/WindowHelper.ets

@@ -66,6 +66,9 @@ export class WindowHelper {
   }
 
   private static _windowClass: window.Window | undefined = undefined;
+  private static _isFullScreen: boolean = false;
+  private static _topRectHeight: number = 0;
+  private static _bottomRectHeight: number = 0;
 
   /**
    * 设置窗口管理器
@@ -73,12 +76,39 @@ export class WindowHelper {
    */
   public static set windowClass(value: window.Window | undefined) {
     WindowHelper._windowClass = value;
+    if (WindowHelper._windowClass) {
+      let avoidArea = WindowHelper._windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
+      WindowHelper._bottomRectHeight = avoidArea.bottomRect.height
+      let avoidArea2 = WindowHelper._windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_CUTOUT);
+      WindowHelper._topRectHeight = avoidArea2.topRect.height
+      console.log('=====>', WindowHelper._topRectHeight)
+    }
   }
 
+  /**
+   * 获取当前窗口管理器
+   * @returns
+   */
   public static get windowClass(): window.Window | undefined {
     return WindowHelper._windowClass;
   }
 
+  /**
+   * 获取底部安全区高度
+   * @returns
+   */
+  public static get bottomRectHeight(): number {
+    return WindowHelper._bottomRectHeight
+  }
+
+  /**
+   * 获取顶部安全区高度
+   * @returns
+   */
+  public static get topRectHeight(): number {
+    return WindowHelper._isFullScreen?WindowHelper._topRectHeight:0
+  }
+
 
   /**
    * 设置是否全屏
@@ -86,6 +116,7 @@ export class WindowHelper {
    */
   static setWindowLayoutFullScreen(isLayoutFullScreen: boolean) {
     if (WindowHelper._windowClass) {
+      WindowHelper._isFullScreen = isLayoutFullScreen
       WindowHelper._windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
     }
   }

+ 1 - 0
src/main/ets/utils/XWebHelper.ets

@@ -8,6 +8,7 @@ const XWebview = import('../pages/XWebview');
 export interface XWebParams {
   url: string
   title?: string
+  showMenu?: boolean
 }
 
 export class XWebHelper {