Showing
8 changed files
with
55 additions
and
29 deletions
| 1 | -import { Callback, BridgeWebViewControl } from 'wdJsBridge'; | 1 | +import { Callback } from 'wdJsBridge'; |
| 2 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; | 2 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; |
| 3 | -import { Logger, StringUtils, } from 'wdKit'; | 3 | +import { Logger } from 'wdKit'; |
| 4 | import { H5CallNativeType } from './H5CallNativeType'; | 4 | import { H5CallNativeType } from './H5CallNativeType'; |
| 5 | import { ContentDTO } from 'wdBean'; | 5 | import { ContentDTO } from 'wdBean'; |
| 6 | //TODO 这里引用了 features模块,是否考虑将跳转抽到公共模块 | 6 | //TODO 这里引用了 features模块,是否考虑将跳转抽到公共模块 |
| @@ -27,7 +27,10 @@ export function performJSCallNative(data: Message, call: Callback) { | @@ -27,7 +27,10 @@ export function performJSCallNative(data: Message, call: Callback) { | ||
| 27 | case H5CallNativeType.jsCall_callAppService: | 27 | case H5CallNativeType.jsCall_callAppService: |
| 28 | break; | 28 | break; |
| 29 | case H5CallNativeType.jsCall_receiveH5Data: | 29 | case H5CallNativeType.jsCall_receiveH5Data: |
| 30 | - handleH5Data(JSON.parse(data?.data?.dataJson || '{}')) | 30 | + if(data?.data?.dataSource === 5){ |
| 31 | + handleH5Data(JSON.parse(data?.data?.dataJson || '{}')) | ||
| 32 | + | ||
| 33 | + } | ||
| 31 | break; | 34 | break; |
| 32 | case 'changeNativeMessage': | 35 | case 'changeNativeMessage': |
| 33 | call("this is change Web Message") | 36 | call("this is change Web Message") |
| @@ -59,6 +62,7 @@ function getAppPublicInfo(): string { | @@ -59,6 +62,7 @@ function getAppPublicInfo(): string { | ||
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | function handleH5Data(content:ContentDTO) { | 64 | function handleH5Data(content:ContentDTO) { |
| 65 | + Logger.debug(TAG, 'handleH5Data' + ', content: ' + JSON.stringify(content)) | ||
| 62 | ProcessUtils.processPage(content) | 66 | ProcessUtils.processPage(content) |
| 63 | } | 67 | } |
| 64 | 68 |
| 1 | import router from '@ohos.router'; | 1 | import router from '@ohos.router'; |
| 2 | -import { BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsBridge'; | 2 | +import { BridgeHandler, BridgeUtil, BridgeWebViewControl, Callback } from 'wdJsBridge'; |
| 3 | import { Logger } from 'wdKit/Index'; | 3 | import { Logger } from 'wdKit/Index'; |
| 4 | +import { setDefaultNativeWebSettings } from './WebComponentUtil'; | ||
| 5 | +import { Action } from 'wdBean'; | ||
| 4 | import { performJSCallNative } from './JsBridgeBiz'; | 6 | import { performJSCallNative } from './JsBridgeBiz'; |
| 5 | import { H5CallNativeType } from './H5CallNativeType'; | 7 | import { H5CallNativeType } from './H5CallNativeType'; |
| 6 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; | 8 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; |
| @@ -10,9 +12,9 @@ const TAG = 'WdWebLocalComponent'; | @@ -10,9 +12,9 @@ const TAG = 'WdWebLocalComponent'; | ||
| 10 | @Component | 12 | @Component |
| 11 | export struct WdWebComponent { | 13 | export struct WdWebComponent { |
| 12 | webviewControl: BridgeWebViewControl = new BridgeWebViewControl() | 14 | webviewControl: BridgeWebViewControl = new BridgeWebViewControl() |
| 15 | + onWebPrepared: () => void = () => {} | ||
| 13 | @Prop backVisibility: boolean = false | 16 | @Prop backVisibility: boolean = false |
| 14 | @Prop webUrl: string = '' | 17 | @Prop webUrl: string = '' |
| 15 | - @Prop @Watch('onReloadStateChanged') reload: number = 0 | ||
| 16 | @Link isPageEnd: boolean | 18 | @Link isPageEnd: boolean |
| 17 | 19 | ||
| 18 | build() { | 20 | build() { |
| @@ -34,9 +36,10 @@ export struct WdWebComponent { | @@ -34,9 +36,10 @@ export struct WdWebComponent { | ||
| 34 | .domStorageAccess(true) | 36 | .domStorageAccess(true) |
| 35 | .databaseAccess(true) | 37 | .databaseAccess(true) |
| 36 | .javaScriptAccess(true) | 38 | .javaScriptAccess(true) |
| 37 | - .zoomAccess(false) | ||
| 38 | - .horizontalScrollBarAccess(false) | ||
| 39 | - .verticalScrollBarAccess(false) | 39 | + .imageAccess(true) |
| 40 | + .mixedMode(MixedMode.All) | ||
| 41 | + .onlineImageAccess(true) | ||
| 42 | + .enableNativeEmbedMode(true) | ||
| 40 | .onPageBegin((event) => { | 43 | .onPageBegin((event) => { |
| 41 | this.onPageBegin(event?.url); | 44 | this.onPageBegin(event?.url); |
| 42 | }) | 45 | }) |
| @@ -66,14 +69,13 @@ export struct WdWebComponent { | @@ -66,14 +69,13 @@ export struct WdWebComponent { | ||
| 66 | // 注册h5调用js相关 | 69 | // 注册h5调用js相关 |
| 67 | for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { | 70 | for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { |
| 68 | let handleName = H5CallNativeType.JsCallTypeList[i]; | 71 | let handleName = H5CallNativeType.JsCallTypeList[i]; |
| 69 | - console.log('handleName:', handleName) | ||
| 70 | let handle = (data: Message, f: Callback) => { | 72 | let handle = (data: Message, f: Callback) => { |
| 73 | + Logger.debug('registerHandlers handlerName: ' + JSON.stringify(data)) | ||
| 71 | this.defaultPerformJSCallNative(data, f) | 74 | this.defaultPerformJSCallNative(data, f) |
| 72 | }; | 75 | }; |
| 73 | this.webviewControl.registerHandler(handleName, { handle: handle }); | 76 | this.webviewControl.registerHandler(handleName, { handle: handle }); |
| 74 | } | 77 | } |
| 75 | } | 78 | } |
| 76 | - | ||
| 77 | /** | 79 | /** |
| 78 | * 默认【CallNative】逻辑处理 | 80 | * 默认【CallNative】逻辑处理 |
| 79 | */ | 81 | */ |
| @@ -83,22 +85,18 @@ export struct WdWebComponent { | @@ -83,22 +85,18 @@ export struct WdWebComponent { | ||
| 83 | onPageBegin: (url?: string) => void = () => { | 85 | onPageBegin: (url?: string) => void = () => { |
| 84 | Logger.debug(TAG, 'onPageBegin'); | 86 | Logger.debug(TAG, 'onPageBegin'); |
| 85 | this.registerHandlers(); | 87 | this.registerHandlers(); |
| 88 | + // setTimeout(() => { | ||
| 86 | BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl) | 89 | BridgeUtil.webViewLoadLocalJs(getContext(this), this.webviewControl) |
| 90 | + // }, 100) | ||
| 87 | } | 91 | } |
| 88 | onPageEnd: (url?: string) => void = () => { | 92 | onPageEnd: (url?: string) => void = () => { |
| 89 | - this.isPageEnd = true | ||
| 90 | Logger.debug(TAG, 'onPageEnd'); | 93 | Logger.debug(TAG, 'onPageEnd'); |
| 94 | + this.onWebPrepared() | ||
| 95 | + this.isPageEnd = true | ||
| 91 | } | 96 | } |
| 92 | onLoadIntercept: (url?: string) => boolean = () => { | 97 | onLoadIntercept: (url?: string) => boolean = () => { |
| 93 | Logger.debug(TAG, 'onLoadIntercept return false'); | 98 | Logger.debug(TAG, 'onLoadIntercept return false'); |
| 94 | return false | 99 | return false |
| 95 | } | 100 | } |
| 96 | - | ||
| 97 | - onReloadStateChanged() { | ||
| 98 | - Logger.info(TAG, `onReloadStateChanged:::refresh, this.reload: ${this.reload}`); | ||
| 99 | - if (this.reload > 0) { | ||
| 100 | - this.webviewControl.refresh() | ||
| 101 | - } | ||
| 102 | - } | ||
| 103 | } | 101 | } |
| 104 | 102 |
| @@ -12,8 +12,7 @@ const TAG = 'WdWebLocalComponent'; | @@ -12,8 +12,7 @@ const TAG = 'WdWebLocalComponent'; | ||
| 12 | @Component | 12 | @Component |
| 13 | export struct WdWebLocalComponent { | 13 | export struct WdWebLocalComponent { |
| 14 | webviewControl: BridgeWebViewControl = new BridgeWebViewControl() | 14 | webviewControl: BridgeWebViewControl = new BridgeWebViewControl() |
| 15 | - onWebPrepared: () => void = () => { | ||
| 16 | - } | 15 | + onWebPrepared: () => void = () => {} |
| 17 | @Prop backVisibility: boolean = false | 16 | @Prop backVisibility: boolean = false |
| 18 | @Prop webResource: Resource = {} as Resource | 17 | @Prop webResource: Resource = {} as Resource |
| 19 | @State webHeight: string | number = '100%' | 18 | @State webHeight: string | number = '100%' |
| @@ -73,6 +72,7 @@ export struct WdWebLocalComponent { | @@ -73,6 +72,7 @@ export struct WdWebLocalComponent { | ||
| 73 | for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { | 72 | for (let i = 0; i < H5CallNativeType.JsCallTypeList.length; i++) { |
| 74 | let handleName = H5CallNativeType.JsCallTypeList[i]; | 73 | let handleName = H5CallNativeType.JsCallTypeList[i]; |
| 75 | let handle = (data: Message, f: Callback) => { | 74 | let handle = (data: Message, f: Callback) => { |
| 75 | + Logger.debug('registerHandlers handlerName: ' + JSON.stringify(data.data)) | ||
| 76 | this.setCurrentPageOperate(data) | 76 | this.setCurrentPageOperate(data) |
| 77 | this.defaultPerformJSCallNative(data, f) | 77 | this.defaultPerformJSCallNative(data, f) |
| 78 | }; | 78 | }; |
| @@ -19,7 +19,7 @@ export interface CompDTO { | @@ -19,7 +19,7 @@ export interface CompDTO { | ||
| 19 | name: string; | 19 | name: string; |
| 20 | objectId: string; // 跳转页面id? | 20 | objectId: string; // 跳转页面id? |
| 21 | objectTitle: string; // comp标题 | 21 | objectTitle: string; // comp标题 |
| 22 | - objectType?: string; // 跳转类型,枚举: | 22 | + // objectType?: string; // 跳转类型,枚举: |
| 23 | operDataList: ContentDTO[]; // 运营数据列表【正常运营配置的强运营数据,部分推荐场景的配置(自动源兜底数据)】 | 23 | operDataList: ContentDTO[]; // 运营数据列表【正常运营配置的强运营数据,部分推荐场景的配置(自动源兜底数据)】 |
| 24 | // pageId?: any; | 24 | // pageId?: any; |
| 25 | posterSize: string; | 25 | posterSize: string; |
| @@ -38,7 +38,7 @@ export struct CompParser { | @@ -38,7 +38,7 @@ export struct CompParser { | ||
| 38 | 38 | ||
| 39 | @Builder | 39 | @Builder |
| 40 | componentBuilder(compDTO: CompDTO, compIndex: number) { | 40 | componentBuilder(compDTO: CompDTO, compIndex: number) { |
| 41 | - if (compDTO.objectType !== '3' && compDTO.objectType !== '13') { //暂时屏蔽活动和音频详情入口 | 41 | + if (compDTO.operDataList[0]?.objectType !== '3' && compDTO.operDataList[0]?.objectType !== '13') { //暂时屏蔽活动和音频详情入口 |
| 42 | if (compDTO.compStyle === CompStyle.Label_03) { | 42 | if (compDTO.compStyle === CompStyle.Label_03) { |
| 43 | LabelComponent({ compDTO: compDTO }) | 43 | LabelComponent({ compDTO: compDTO }) |
| 44 | } else if (compDTO.compStyle === CompStyle.Zh_Carousel_Layout_01) { | 44 | } else if (compDTO.compStyle === CompStyle.Zh_Carousel_Layout_01) { |
| 1 | -import { Action, ContentDetailDTO, } from 'wdBean'; | ||
| 2 | -import DetailViewModel from '../viewmodel/DetailViewModel'; | 1 | +import { Action, H5ReceiveDetailBean } from 'wdBean'; |
| 3 | import { WdWebComponent } from 'wdWebComponent'; | 2 | import { WdWebComponent } from 'wdWebComponent'; |
| 4 | import router from '@ohos.router'; | 3 | import router from '@ohos.router'; |
| 5 | import { CommonConstants } from 'wdConstant' | 4 | import { CommonConstants } from 'wdConstant' |
| 6 | import { BridgeWebViewControl } from 'wdJsBridge/Index'; | 5 | import { BridgeWebViewControl } from 'wdJsBridge/Index'; |
| 7 | import { detailedSkeleton } from './skeleton/detailSkeleton' | 6 | import { detailedSkeleton } from './skeleton/detailSkeleton' |
| 8 | - | 7 | +import { NativeCallH5Type } from 'wdWebComponent/src/main/ets/pages/NativeCallH5Type'; |
| 9 | const TAG = 'SpacialTopicPageComponent' | 8 | const TAG = 'SpacialTopicPageComponent' |
| 10 | 9 | ||
| 11 | @Component | 10 | @Component |
| @@ -15,6 +14,28 @@ export struct SpacialTopicPageComponent { | @@ -15,6 +14,28 @@ export struct SpacialTopicPageComponent { | ||
| 15 | action: Action = {} as Action | 14 | action: Action = {} as Action |
| 16 | @State webUrl: string = ''; | 15 | @State webUrl: string = ''; |
| 17 | @State isPageEnd: boolean = false | 16 | @State isPageEnd: boolean = false |
| 17 | + private h5ReceiveAppData: H5ReceiveDetailBean = { dataSource: '2' } as H5ReceiveDetailBean | ||
| 18 | + private webPrepared = false; | ||
| 19 | + private dataPrepared = false; | ||
| 20 | + | ||
| 21 | + private trySendData2H5() { | ||
| 22 | + if (!this.webPrepared || !this.dataPrepared) { | ||
| 23 | + return | ||
| 24 | + } | ||
| 25 | + // 数据、web组件,都准备好了,开始塞详情数据 | ||
| 26 | + this.sendContentData2H5(this.h5ReceiveAppData) | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + private onWebPrepared() { | ||
| 30 | + this.webPrepared = true | ||
| 31 | + this.trySendData2H5() | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + private sendContentData2H5(h5ReceiveAppData: H5ReceiveDetailBean) { | ||
| 35 | + this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData, | ||
| 36 | + JSON.stringify(h5ReceiveAppData), (data: string) => { | ||
| 37 | + }) | ||
| 38 | + } | ||
| 18 | 39 | ||
| 19 | build() { | 40 | build() { |
| 20 | Column() { | 41 | Column() { |
| @@ -27,7 +48,8 @@ export struct SpacialTopicPageComponent { | @@ -27,7 +48,8 @@ export struct SpacialTopicPageComponent { | ||
| 27 | webviewControl: this.webviewControl, | 48 | webviewControl: this.webviewControl, |
| 28 | webUrl: this.webUrl, | 49 | webUrl: this.webUrl, |
| 29 | backVisibility: false, | 50 | backVisibility: false, |
| 30 | - isPageEnd:$isPageEnd | 51 | + onWebPrepared: this.onWebPrepared.bind(this), |
| 52 | + isPageEnd: $isPageEnd | ||
| 31 | }) | 53 | }) |
| 32 | } | 54 | } |
| 33 | .padding({ bottom: 56 }) | 55 | .padding({ bottom: 56 }) |
| @@ -72,7 +94,6 @@ export struct SpacialTopicPageComponent { | @@ -72,7 +94,6 @@ export struct SpacialTopicPageComponent { | ||
| 72 | .justifyContent(FlexAlign.SpaceBetween) | 94 | .justifyContent(FlexAlign.SpaceBetween) |
| 73 | .backgroundColor(Color.White) | 95 | .backgroundColor(Color.White) |
| 74 | 96 | ||
| 75 | - | ||
| 76 | } | 97 | } |
| 77 | }.width(CommonConstants.FULL_WIDTH).height(CommonConstants.FULL_HEIGHT) | 98 | }.width(CommonConstants.FULL_WIDTH).height(CommonConstants.FULL_HEIGHT) |
| 78 | .backgroundColor(Color.White) | 99 | .backgroundColor(Color.White) |
| @@ -83,8 +104,10 @@ export struct SpacialTopicPageComponent { | @@ -83,8 +104,10 @@ export struct SpacialTopicPageComponent { | ||
| 83 | if (action) { | 104 | if (action) { |
| 84 | this.webUrl = action.params?.url || '' | 105 | this.webUrl = action.params?.url || '' |
| 85 | } | 106 | } |
| 107 | + this.trySendData2H5() | ||
| 86 | } | 108 | } |
| 87 | 109 | ||
| 88 | aboutToDisappear() { | 110 | aboutToDisappear() { |
| 111 | + | ||
| 89 | } | 112 | } |
| 90 | } | 113 | } |
| @@ -25,6 +25,7 @@ export class ProcessUtils { | @@ -25,6 +25,7 @@ export class ProcessUtils { | ||
| 25 | return; | 25 | return; |
| 26 | } | 26 | } |
| 27 | let type = content.objectType; | 27 | let type = content.objectType; |
| 28 | + console.log(TAG,'objectType',`${JSON.stringify(content)}`); | ||
| 28 | switch (type) { | 29 | switch (type) { |
| 29 | case ContentConstants.TYPE_NONE: | 30 | case ContentConstants.TYPE_NONE: |
| 30 | Logger.debug(TAG, "processPage, do nothing"); | 31 | Logger.debug(TAG, "processPage, do nothing"); |
| @@ -59,7 +60,7 @@ export class ProcessUtils { | @@ -59,7 +60,7 @@ export class ProcessUtils { | ||
| 59 | break; | 60 | break; |
| 60 | //动态详情页(动态视频) | 61 | //动态详情页(动态视频) |
| 61 | case ContentConstants.TYPE_FIFTEEN: | 62 | case ContentConstants.TYPE_FIFTEEN: |
| 62 | - ProcessUtils.gotoDynamicDetailPage(content); | 63 | + ProcessUtils.gotoWeb(content); |
| 63 | break; | 64 | break; |
| 64 | default: | 65 | default: |
| 65 | break; | 66 | break; |
| @@ -32,7 +32,7 @@ struct DefaultWebPage { | @@ -32,7 +32,7 @@ struct DefaultWebPage { | ||
| 32 | WdWebComponent({ | 32 | WdWebComponent({ |
| 33 | webUrl: this.url, | 33 | webUrl: this.url, |
| 34 | backVisibility: false, | 34 | backVisibility: false, |
| 35 | - reload: this.reload, | 35 | + // reload: this.reload, |
| 36 | isPageEnd:$isPageEnd | 36 | isPageEnd:$isPageEnd |
| 37 | }) | 37 | }) |
| 38 | } | 38 | } |
-
Please register or login to post a comment