<template>
	<!--pages/web/web.wxml-->
	<view>
		<web-view :src="webUrl" v-if="webUrl!==''"></web-view>
	</view>
</template>

<script>
	// pages/web/web.js
	const req = require("../../utils/request");
	const app = getApp();

	export default {
		data() {
			return {
				webUrl: '',
				back: false,
				options:{}
			};
		},

		components: {},
		props: {},
		onLoad:async function(options) {
			this.options = options
			if (options.appId) req.setStorage('appId', options.appId);
			if (options.x_code_id){
				options = await this.loadCodeParams(options.x_code_id)
			}
			
			this.webUrl = this.options.url
			await req.silenceLogin(this.options.userId);
		},

		onShow() {
			if (this.back) {
				uni.navigateBack();
			}
		},

		methods: {
			loadCodeParams(scene) {
				let _ts = this;
			
				return new Promise((resolve, reject) => {
					let form = {
						scene: scene
					};
					if (!scene) {
						resolve();
						return false;
					}
			
			
					req.getRequest('/api/code/params', form, data => {
						let res = JSON.parse(data.scene)
						for(let key in res){
							this.options[key] = res[key]
						}
						resolve(res);
					});
				});
			},
		}
	};
</script>
<style>
	@import "./index.css";
</style>
