<template>
  <view>
    <block v-if="access_token">
      <web-view :src="url + urlPath + '?queryList=' + queryList + '&token=' + access_token" @message="handleGetMessage"></web-view>
    </block>
  </view>
</template>

<script>
import { User } from "@/config/api.js";
export default {
  data() {
    return {
      //url:"http://192.168.2.22:3000/cygx_pc/",//开发
      url: "https://cygxpctest.hzinsights.com/cygx_pc", //测试
      //url: 'https://cygxpc.hzinsights.com/cygx_pc', //生产
      urlPath: "/index",
      queryList: "",
      urlShare: "",
      titleShare: "",
      access_token: "",
    };
  },
  methods: {
    getToken() {
      uni.login({
        success: (result) => {
          User.wechatLog({
            Code: result.code,
          }).then((res) => {
            try {
              let token = res.Data.Authorization;
              this.$db.set("access_token", token);
              this.access_token = token;
            } catch (e) {}
          });
        },
      });
    },
    handleGetMessage(e) {
      const data = e.detail.data[e.detail.data.length - 1];
      this.urlShare = data.url;
      this.titleShare = data.title;
    },
    initLoad(optios) {
      let urlType = [
        "index",
        "reportForm",
        "activity",
        "themeActivity",
        "activityDetail",
        "reportDetail",
        "IndustryReport",
        "reportSecretDetail",
        "roadEssence",
        "chartPage",
        "specialDetail",
        "specialResearchPage",
      ];
      if (JSON.stringify(optios) !== "{}" && optios.path) {
        let pathUrl = optios.path.split("/")[2];
        this.urlPath = urlType.includes(pathUrl) ? "/" + pathUrl : "/index";
        this.queryList = optios.query || "";
      }
    },
  },
  onLoad(optios) {
    this.getToken();
    this.initLoad(optios);
  },
  onShareAppMessage() {
    return {
      title: this.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费月卡！" : this.titleShare,
      path: this.urlShare,
    };
  },
};
</script>

<style></style>
