<template>
	<view v-if="params.url">
		<web-view :src="`${params.url}`"></web-view>
		<u-loading-page :loading="loading"></u-loading-page>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: true,
				params: {}
			}
		},
		props: {
			src: {
				type: [String],
				default: null
			}
		},
		onReady() {
			// #ifdef APP-PLUS
			var currentWebview = this.$scope.$getAppWebview() //获取当前页面的webview对象
			// console.log("currentWebview",currentWebview)
			setTimeout(function() {
				const wv = currentWebview.children()[0] //取出当前webview实例
				wv.setStyle({
					scalable: true //添加样式，启动缩放
				})
				wv.evalJS(`
					var metaEl = document.createElement('meta')
					metaEl.setAttribute('name','viewport')
					metaEl.setAttribute('content', 'width=device-width, initial-scale=1,user-scalable=yes')
					document.head.appendChild(metaEl)
				`);
			}, 1000); //如果是页面初始化调用时，需要延时一下
			// #endif
		},
		onLoad(event) {
			const { url, ...res } = event;
			this.params = {
				url: decodeURIComponent(url),
				res
			};
			if (event.title) {
				uni.setNavigationBarTitle({
					title: event.title
				})
			};
			setTimeout(() => {
				this.loading = false;
			}, 1000);
		},
	}
</script>