From 39a907e852246c462763c24bc64d6f527f28f090 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Thu, 30 Dec 2021 14:22:29 +0800 Subject: [PATCH] feat(App-vue): webview support updateTitle --- .../src/view/components/web-view/index.tsx | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/uni-app-plus/src/view/components/web-view/index.tsx b/packages/uni-app-plus/src/view/components/web-view/index.tsx index d99299621..ae526a21b 100644 --- a/packages/uni-app-plus/src/view/components/web-view/index.tsx +++ b/packages/uni-app-plus/src/view/components/web-view/index.tsx @@ -1,4 +1,11 @@ -import { ref, watch, onBeforeUnmount, Ref, computed } from 'vue' +import { + ref, + watch, + onBeforeUnmount, + Ref, + computed, + ExtractPropTypes, +} from 'vue' import { extend } from '@vue/shared' import { defineBuiltInComponent } from '@dcloudio/uni-components' import { getCurrentPageId } from '@dcloudio/uni-core' @@ -17,6 +24,10 @@ const props = { type: String, default: '', }, + updateTitle: { + type: Boolean, + default: true, + }, webviewStyles: { type: Object, default() { @@ -24,18 +35,22 @@ const props = { }, }, } +type Props = ExtractPropTypes let webview: PlusWebviewWebviewObject | null +interface insertHTMLWebView { + htmlId: string + src: string + webviewStyles: PlusWebviewWebviewStyles + props: Props +} const insertHTMLWebView = ({ htmlId, src, webviewStyles, -}: { - htmlId: string - src: string - webviewStyles: PlusWebviewWebviewStyles -}) => { + props, +}: insertHTMLWebView) => { const parentWebview = plus.webview.currentWebview() // fixed by hxy web-view 组件所在的 webview 不注入 uni-app 框架 const styles: PlusWebviewWebviewStyles & { @@ -57,6 +72,7 @@ const insertHTMLWebView = ({ webview = plus.webview.create(src, htmlId, styles) if (parentTitleNView) { webview.addEventListener('titleUpdate', function () { + if (!props.updateTitle) return const title = webview?.getTitle() parentWebview.setStyle({ titleNView: { @@ -91,6 +107,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({ htmlId: htmlId.value, src: getRealPath(props.src), webviewStyles: webviewStyles.value, + props, }) UniViewJSBridge.publishHandler(WEBVIEW_INSERTED, {}, pageId) if (hidden.value) webview?.hide() -- GitLab