zhangbo1_wd

解决图文详情web页面,偶现crash问题【Init error, The Webviewcontroller must be associated with a Web component】

... ... @@ -12,6 +12,8 @@ const TAG = 'WdWebLocalComponent';
@Component
export struct WdWebLocalComponent {
webviewControl: BridgeWebViewControl = new BridgeWebViewControl()
onWebPrepared: () => void = () => {
}
@Prop backVisibility: boolean = false
@Prop webResource: Resource = {} as Resource
@State webHeight: string | number = '100%'
... ... @@ -106,6 +108,7 @@ export struct WdWebLocalComponent {
}
onPageEnd: (url?: string) => void = () => {
Logger.debug(TAG, 'onPageEnd');
this.onWebPrepared()
}
onLoadIntercept: (url?: string) => boolean = () => {
Logger.debug(TAG, 'onLoadIntercept return false');
... ...
... ... @@ -17,6 +17,9 @@ export struct ImageAndTextWebComponent {
@State reload: number = 0;
@Prop @Watch('onDetailDataUpdated') contentDetailData: ContentDetailDTO [] = [] as ContentDetailDTO []
webviewControl: BridgeWebViewControl = new BridgeWebViewControl()
private h5ReceiveAppData: H5ReceiveDetailBean = { dataSource: '2' } as H5ReceiveDetailBean
private webPrepared = false;
private dataPrepared = false;
onDetailDataUpdated() {
if (this.action) {
... ... @@ -50,7 +53,6 @@ export struct ImageAndTextWebComponent {
}
let h5ReceiveAppData: H5ReceiveDetailBean = { dataSource: '2' } as H5ReceiveDetailBean
// TODO 对接user信息、登录情况
let h5ReceiveDataExtraBean: H5ReceiveDataExtraBean = { creatorId: '', isLogin: '0' } as H5ReceiveDataExtraBean
let h5ReceiveDataJsonBean: H5ReceiveDataJsonBean = {
... ... @@ -67,12 +69,10 @@ export struct ImageAndTextWebComponent {
response.code = 200
response.success = true
h5ReceiveDataJsonBean.responseMap = response
h5ReceiveAppData.dataJson = h5ReceiveDataJsonBean
h5ReceiveAppData.dataExt = h5ReceiveDataExtraBean
// TODO 暂延时1s,考虑业务流程再优化
setTimeout(() => {
this.sendContentData2H5(h5ReceiveAppData);
}, 2000)
this.h5ReceiveAppData.dataJson = h5ReceiveDataJsonBean
this.h5ReceiveAppData.dataExt = h5ReceiveDataExtraBean
this.dataPrepared = true
this.trySendData2H5()
}
... ... @@ -84,10 +84,24 @@ export struct ImageAndTextWebComponent {
webviewControl: this.webviewControl,
webResource: $rawfile('apph5/index.html'),
backVisibility: false,
onWebPrepared: this.onWebPrepared.bind(this)
})
}
}
private trySendData2H5() {
if (!this.webPrepared || !this.dataPrepared) {
return
}
// 数据、web组件,都准备好了,开始塞详情数据
this.sendContentData2H5(this.h5ReceiveAppData)
}
private onWebPrepared() {
this.webPrepared = true
this.trySendData2H5()
}
private sendContentData2H5(h5ReceiveAppData: H5ReceiveDetailBean) {
Logger.debug('ImageAndTextWebComponent', 'jsCall_receiveAppData');
this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData,
... ...