SpacialTopicPageComponent.ets 3.18 KB
import { Action, H5ReceiveDetailBean } from 'wdBean';
import { WdWebComponent } from 'wdWebComponent';
import router from '@ohos.router';
import { CommonConstants } from 'wdConstant'
import { BridgeWebViewControl } from 'wdJsBridge/Index';
import { detailedSkeleton } from './skeleton/detailSkeleton'
import { NativeCallH5Type } from 'wdWebComponent/src/main/ets/pages/NativeCallH5Type';
const TAG = 'SpacialTopicPageComponent'

@Component
export struct SpacialTopicPageComponent {
  webviewControl: BridgeWebViewControl = new BridgeWebViewControl()
  scroller: Scroller = new Scroller();
  action: Action = {} as Action
  @State webUrl: string = '';
  @State isPageEnd: boolean = false
  private h5ReceiveAppData: H5ReceiveDetailBean = { dataSource: '2' } as H5ReceiveDetailBean
  private webPrepared = false;
  private dataPrepared = false;

  private trySendData2H5() {
    if (!this.webPrepared || !this.dataPrepared) {
      return
    }
    // 数据、web组件,都准备好了,开始塞详情数据
    this.sendContentData2H5(this.h5ReceiveAppData)
  }

  private onWebPrepared() {
    this.webPrepared = true
    this.trySendData2H5()
  }

  private sendContentData2H5(h5ReceiveAppData: H5ReceiveDetailBean) {
    this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData,
      JSON.stringify(h5ReceiveAppData), (data: string) => {
      })
  }

  build() {
    Column() {
      if (!this.isPageEnd) {
        detailedSkeleton()
      }
      Stack({ alignContent: Alignment.Bottom }) {
        Column() {
          WdWebComponent({
            webviewControl: this.webviewControl,
            webUrl: this.webUrl,
            backVisibility: false,
            onWebPrepared: this.onWebPrepared.bind(this),
            isPageEnd: $isPageEnd
          })
        }
        .padding({ bottom: 56 })
        .width(CommonConstants.FULL_WIDTH)
        .height(CommonConstants.FULL_HEIGHT)

        //底部交互区
        Row() {
          Image($r('app.media.icon_arrow_left'))
            .width(24)
            .height(24)
            .onClick((event: ClickEvent) => {
              router.back()
            })

          Row() {
            Image($r('app.media.icon_comment'))
              .width(24)
              .height(24)
              .margin({ right: 24 })
              .id('comment')

            Image($r('app.media.icon_star'))
              .width(24)
              .height(24)
              .margin({ right: 24 })

            Image($r('app.media.icon_listen'))
              .width(24)
              .height(24)
              .margin({ right: 24 })

            Image($r('app.media.icon_forward'))
              .width(24)
              .height(24)

          }
        }
        .width(CommonConstants.FULL_WIDTH)
        .height(56)
        .padding({ left: 15, right: 15, bottom: 20, top: 20 })
        .justifyContent(FlexAlign.SpaceBetween)
        .backgroundColor(Color.White)

      }
    }.width(CommonConstants.FULL_WIDTH).height(CommonConstants.FULL_HEIGHT)
    .backgroundColor(Color.White)
  }

  aboutToAppear() {
    let action: Action = router.getParams() as Action
    if (action) {
      this.webUrl = action.params?.url || ''
    }
    this.trySendData2H5()
  }

  aboutToDisappear() {

  }
}