<template>
  <div class="home">
  </div>
</template>

<script>
  import { Encrypt,Decrypt} from '@/utils/secret'
  import { getConfigByType } from "@/api/commonality/permission";
  export default {
    name: "home",
    data() {
      return {
        routeData:JSON.parse(localStorage.getItem("safetyEducationExaminationRouteData")),
      };
    },
    created(){

    },
    mounted(){
      this.getExploitConfig();
    },
    methods: {
      //获取开发配置
      getExploitConfig(){
        getConfigByType({ category: 2, configType: 5 }).then(response => {
          let obj = JSON.parse(response.data.configValue)
          //判定http或者https
          let urlText = window.location.href.split('://')[0]+'://';
          let outerNet = window.location.href.indexOf(obj.ipIdentify) == -1//true外网 false 内网
          if(outerNet){//外网
            //文件预览地址
            localStorage.setItem('filePreviewUrl',urlText+obj.fileExtranetUrl)
            //摄像头代理访问地址
            localStorage.setItem('cameraExtranetAgent',urlText+obj.cameraExtranetAgent)
            //摄像头地址ip段
            localStorage.setItem('ipIdentify',obj.ipIdentify)
            //摄像头访问地址
            localStorage.setItem('cameraUrl','wss://'+obj.cameraExtranetUrl)
            //MQTT地址
            localStorage.setItem('mqttUrl','wss://'+Decrypt(obj.mqttExtranetUrl))
            //MQTT账号
            localStorage.setItem('mqttUser',Decrypt(obj.mqttExtranetUser))
            //MQTT密码
            localStorage.setItem('mqttPassword',Decrypt(obj.mqttExtranetPassword))
            //可视化大屏访问地址
            localStorage.setItem('screenUrl',urlText+obj.screenExtranetUrl)
            //小程序二维码规则
            localStorage.setItem('codeOnlineAdd',obj.codeOnlineAdd)
            //文件浏览环境
            localStorage.setItem('fileBrowseEnvironment',window.location.href.split('://')[0]+'://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
            localStorage.setItem('fileBrowseEnvironmentInterior',window.location.href.split('://')[0]+'://'+Decrypt(obj.fileBrowseEnvironment))
            localStorage.setItem('fileBrowseEnvironmentExtranet','https://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
          }else{
            //文件预览地址
            localStorage.setItem('filePreviewUrl',urlText+obj.fileIntranetUrl)
            //摄像头代理访问地址
            localStorage.setItem('cameraExtranetAgent',urlText+obj.cameraIntranetAgent)
            //摄像头地址ip段
            localStorage.setItem('ipIdentify',obj.ipIdentify)
            //摄像头访问地址
            localStorage.setItem('cameraUrl','wss://'+obj.cameraIntranetUrl)
            //MQTT地址
            localStorage.setItem('mqttUrl','ws://'+Decrypt(obj.mqttIntranetUrl))
            //MQTT账号
            localStorage.setItem('mqttUser',Decrypt(obj.mqttIntranetUser))
            //MQTT密码
            localStorage.setItem('mqttPassword',Decrypt(obj.mqttIntranetPassword))
            //可视化大屏访问地址
            localStorage.setItem('screenUrl',urlText+obj.screenIntranetUrl)
            //小程序二维码规则
            localStorage.setItem('codeOnlineAdd',obj.codeOnlineAdd)
            //文件浏览环境
            localStorage.setItem('fileBrowseEnvironment',window.location.href.split('://')[0]+'://'+Decrypt(obj.fileBrowseEnvironment))
            localStorage.setItem('fileBrowseEnvironmentInterior',window.location.href.split('://')[0]+'://'+Decrypt(obj.fileBrowseEnvironment))
            localStorage.setItem('fileBrowseEnvironmentExtranet','https://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
          }
          this.autoSkip();
        });
      },
      //自动跳转
      autoSkip(){
        let path = this.circularCallSortSkip(this.routeData);
        this.$router.push({ path: path });
      },
      //循环调用 按照排序跳转
      circularCallSortSkip(list){
        let self = this;
        for(let i=0;i<list.length;i++){
          if(list[i].children){
            let text = self.circularCallSortSkip(list[i].children)
            if(text){
              return list[i].path + '/' + text
            }
          }else if(!list[i].alwaysShow && !list[i].hidden && !list[i].isFrame){
            return list[i].path
          }
        }
      },
    },
  };
</script>

<style scoped lang="scss">
  .home {
    height:100%;
    width:100%;
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }
</style>

