Parcourir la source

自动签相关

徐勤民 il y a 2 mois
Parent
commit
b41b8ac20a

+ 7 - 0
src/main/ets/pages/XWebview.ets

@@ -7,6 +7,8 @@ import { BusinessError } from '@kit.BasicServicesKit';
 import { ToolsHelper } from '../utils/ToolsHelper';
 import { XWebParams } from '../utils/XWebHelper';
 import { WindowHelper } from '../utils/WindowHelper';
+import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper';
+import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys';
 
 @Entry({ routeName: 'XWebview' })
 @Preview
@@ -15,6 +17,7 @@ export struct XWebview {
   // 手机号
   @State url: string = (router.getParams() as XWebParams).url
   @State title?: string = (router.getParams() as XWebParams).title
+  @State closeTag?: string = (router.getParams() as XWebParams).closeTag
   @State showMenu: boolean = (router.getParams() as XWebParams).showMenu ?? false
   @State errorInfo: string | null = null
   @State progress: number = 0
@@ -22,9 +25,13 @@ export struct XWebview {
   dialogController: XDialogController = {} as XDialogController
 
   aboutToAppear(): void {
+    SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, undefined)
   }
 
   aboutToDisappear(): void {
+    if (this.closeTag !== undefined) {
+      SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, this.closeTag)
+    }
   }
 
   onBackPress(): boolean | void {

+ 1 - 0
src/main/ets/utils/SZYXLocalStorageKeys.ts

@@ -2,4 +2,5 @@
 export class SZYXLocalStorageKeys{
   public static HttpHandlerList: string = 'httpHandlerList';
   public static HttpHandlerListLength: string = 'HttpHandlerListLength';
+  public static XWebViewCLose: string = 'SZYX_XWebViewCLose';
 }

+ 1 - 1
src/main/ets/utils/ToolsHelper.ets

@@ -37,7 +37,7 @@ interface ListItem {
 }
 
 @Builder
-function customDialogBuilder<T>(option: ListOptions<T>, dialogTag: string) {
+export function customDialogBuilder<T>(option: ListOptions<T>, dialogTag: string) {
 
   Column() {
     Text(option.title)

+ 14 - 11
src/main/ets/utils/XWebHelper.ets

@@ -9,6 +9,7 @@ export interface XWebParams {
   url: string
   title?: string
   showMenu?: boolean
+  closeTag?:string
 }
 
 export class XWebHelper {
@@ -16,17 +17,19 @@ export class XWebHelper {
    * 打开web页面,加载h5
    * @param params
    */
-  public static openWeb(params: XWebParams) {
-
-    router.pushNamedRoute({
-      name: 'XWebview',
-      params: params
-    }, router.RouterMode.Single).then(() => {
-      console.info('Succeeded in jumping to the XWebview page.')
-
-    }).catch((err: BusinessError) => {
-      console.error(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`)
-      ToolsHelper.showMessage(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`)
+  public static openWeb(params: XWebParams): Promise<boolean> {
+    return new Promise((resolve) => {
+      router.pushNamedRoute({
+        name: 'XWebview',
+        params: params
+      }, router.RouterMode.Single).then(() => {
+        console.info('Succeeded in jumping to the XWebview page.')
+        resolve(true)
+      }).catch((err: BusinessError) => {
+        resolve(false)
+        console.error(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`)
+        ToolsHelper.showMessage(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`)
+      })
     })
   }
 }