<template>
    <web-view :src="url" @message="handleGetMessage"></web-view>
</template>

<script>
import {h5BaseUrl} from '@/utils/config'
export default {
    data () {
        return {
            url:'',
            msgObj:{}

        }
    },
    onShareAppMessage() {
        let paramsStr=''
        for(const key in this.msgObj.params){
            if(!paramsStr){
                paramsStr=`${key}=${this.msgObj.params[key]}`
            }else{
                paramsStr=`${paramsStr}&${key}=${this.msgObj.params[key]}`
            }
        }
        return {
            title:this.msgObj.title||'持仓分析详情',
            path:`/pages/positionAnalysis/detail?${paramsStr}&from=share`,
            imageUrl:this.msgObj.shareImg||''
        }
    },
    onLoad(options){
        const queryObj={
            classify_name:options.classify_name,
            classify_type:options.classify_type,
            exchange:options.exchange,
            token:this.$store.state.user.token||uni.getStorageSync("token"),
            timestamp:new Date().getTime(),//防止缓存
        }
        let queryObjStr=''
        for (const key in queryObj) {
            if(!queryObjStr){
                    queryObjStr=`${key}=${queryObj[key]}`
            }else{
                queryObjStr=`${queryObjStr}&${key}=${queryObj[key]}`
            }
        }
        console.log('拼接字符串：',queryObjStr);
        this.url=`${h5BaseUrl}/hzyb/chart/positionanalysis?${queryObjStr}#wechat_redirect`
    },
    methods: {
        // 获取到用户点击转发时从h5页面传来的参数
        handleGetMessage(e){
            const data=e.detail.data[e.detail.data.length-1]
            console.log('h5传来的数据',data);
            this.msgObj=data
        }
    },
}
</script>

<style>
page{
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
}
</style>