提交 39a907e8 编写于 作者: D DCloud_LXH

feat(App-vue): webview support updateTitle

上级 9d75143e
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<typeof props>
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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册