<template>
  <div id="app">

    <component :is="currentComponent" />
  </div>
</template>

<script>

import api from './api.js'
import testRes from './components/baozuo-demo/testbak'
const queryParams = new URLSearchParams(window.location.search);
const dataTypeParam = queryParams.get('q');
export default {
  name: 'app', 
  data() {
    return {
      dataType: '',
      //确保testRes加载好后再加载组件
      currentComponent: null
    }
  },
  components: {
    // 异步注册两个组件
    datav2: () => import('./components/baozuo-demo2/index.vue'),
    datav: () => import('./components/baozuo-demo/index.vue'),
    datav3: () => import('./components/baozuo-demo3/index.vue')
  },
  created() {
    this.dataType = dataTypeParam;

    if (this.dataType == '3') {
      this.init();
    } else {
          window.htd_bidata = testRes;
      if (this.dataType == '4') {
        this.currentComponent = 'datav2';
      } else if (this.dataType == '5') {
        this.currentComponent = 'datav3';
      } else if (this.dataType == '6'){
        this.currentComponent = 'datav2';
      } else {
        this.currentComponent = 'datav';
      }
    }


  },
  computed: {
  },
  methods: {
    init() {
      /**
 * 获取当前地址
 * @returns {string} 当前地址
 */
      function getCurrentAddress() {
        if (typeof window !== 'undefined' && window.location) {
          return window.location.origin;
        } else {
          console.warn('当前环境非浏览器环境，无法使用 window.location 获取地址');
          return null;
        }
      }
      console.log(api.baseURL)
      if (getCurrentAddress().includes('192.168') || api.baseURL.includes('natool')) {
        console.log('当前环境为开发环境');
        api.post2('/api/web/getBiData', ["yx_v_scgdgk", "yx_v_byzcl", "yx_v_wwcscdd", "yx_v_bzcl1w", "yx_v_bzcl6m", "yx_v_pgjd"]).then(res => {

          window.htd_bidata = res;
          console.log(window.htd_bidata);
          this.currentComponent = 'datav';

        }).catch(() => {
          //window.htd_bidata = testRes;
          console.log(window.htd_bidata);

          this.currentComponent = 'datav';
        })
      } else {

        //window.htd_bidata = testRes;


        this.currentComponent = 'datav';
      }
    }
  }
}
</script>

<style lang="less">
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  width: 100%;
  height: 100%;
}
</style>
