import webview from '@ohos.web.webview';
import { HdNav } from '@itcast/basic';
import router from '@ohos.router';

@Entry
@Component
struct WebPage {
  private controller: webview.WebviewController = new webview.WebviewController();
  @State params:RouteParams = router.getParams() as RouteParams;

  @State url: string = this.params.url;
  @State title: string = this.params.title;
  customUserAgent: string = 'gdxz-expert';

  build() {
    Column() {
      HdNav({ title: this.title, showRightIcon: false, hasBorder: true })
      Web({
        src: this.url,
        controller: this.controller
      })
        .mixedMode(MixedMode.All)
        .domStorageAccess(true)
        .onControllerAttached(() => {
          let userAgent = this.controller.getUserAgent() + this.customUserAgent;
          this.controller.setCustomUserAgent(userAgent);
        })
        .width('100%')
        .layoutWeight(1)// 占据剩余空间
        .height('100%')
    }
    .height('100%')// 关键：约束父容器高度
  }
}

interface  RouteParams {
  url:string;
  title:string;
}