XWebHelper.ets 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { router } from '@kit.ArkUI';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { ToolsHelper } from './ToolsHelper';
  4. const XWebview = import('../pages/XWebview');
  5. export interface XWebParams {
  6. url?: string
  7. content?: string
  8. title?: string
  9. showMenu?: boolean
  10. closeTag?:string
  11. }
  12. export class XWebHelper {
  13. /**
  14. * 打开web页面,加载h5
  15. * @param params
  16. */
  17. public static openWeb(params: XWebParams): Promise<boolean> {
  18. return new Promise((resolve) => {
  19. router.pushNamedRoute({
  20. name: 'XWebview',
  21. params: params
  22. }, router.RouterMode.Single).then(() => {
  23. console.info('Succeeded in jumping to the XWebview page.')
  24. resolve(true)
  25. }).catch((err: BusinessError) => {
  26. resolve(false)
  27. console.error(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`)
  28. ToolsHelper.showMessage(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`)
  29. })
  30. })
  31. }
  32. }