<!-- 首页 -->
<template>
    <div class="home">
      <videoBroadcastHk v-if="pageType == 'videoBroadcastHk'"></videoBroadcastHk>
      <videoBroadcastHls v-if="pageType == 'videoBroadcastHls'"></videoBroadcastHls>
      <miniProgramPlayback v-if="pageType == 'miniProgramPlayback'"></miniProgramPlayback>
      <miniProgramVideo v-if="pageType == 'miniProgramVideo'"></miniProgramVideo>
      <!--<miniProgramVideoMpegts v-if="pageType == 'miniProgramVideoMpegts'"></miniProgramVideoMpegts>-->
      <!--<miniProgramVideoMpegtsHorn v-if="pageType == 'miniProgramVideoMpegts'"></miniProgramVideoMpegtsHorn>-->
      <miniProgramVideoHls v-if="pageType == 'miniProgramVideoHls'"></miniProgramVideoHls>
      <chemicalsInstructionsVideo v-if="pageType == 'chemicalsInstructionsVideo'"></chemicalsInstructionsVideo>
      <alarmPage v-if="pageType == 'alarm'"></alarmPage>
    </div>
</template>
<script>
    import videoBroadcastHk from '@/views/videoBroadcast/videoBroadcastHk.vue';
    import videoBroadcastHls from '@/views/videoBroadcast/videoBroadcastHls.vue';
    import miniProgramPlayback from '@/views/miniProgramPlayback/index.vue';
    import miniProgramVideo from '@/views/miniProgramVideo/index.vue';
    import miniProgramVideoMpegts from '@/views/miniProgramVideoMpegts/index.vue';
    import miniProgramVideoMpegtsHorn from '@/views/miniProgramVideoMpegts/mpegtsHorn.vue';
    import miniProgramVideoHls from '@/views/miniProgramVideoHls/index.vue';
    import chemicalsInstructionsVideo from '@/views/chemicalsInstructionsVideo/index.vue';
    import alarmPage from '@/views/alarmPage/index.vue';
    import {
      getConfigByType,
    } from '@/api/index.js'
    import { Encrypt,Decrypt} from '@/utils/secret'
    export default {
        name: 'home',
        components: {
          videoBroadcastHk,
          videoBroadcastHls,
          miniProgramPlayback,
          miniProgramVideo,
          miniProgramVideoMpegts,
          miniProgramVideoMpegtsHorn,
          miniProgramVideoHls,
          chemicalsInstructionsVideo,
          alarmPage,
        },
        data() {
            return {
              pageType:null,
              appName:null,
            }
        },
        created() {

        },
        mounted() {
          let text = decodeURIComponent(window.location.href);
          text = text.split("?")[1]
          console.log('text',text)
          if(text.indexOf('touken') != -1){
            Promise.all([
              //获取开发配置
              this.getConfigByType(),
            ]).then((result) => {
              //页面展示
              if (text.indexOf('videoBroadcastHk') != -1){
                this.$set(this,'pageType','videoBroadcastHk');
              }else if(text.indexOf('videoBroadcastHls') != -1){
                this.$set(this,'pageType','videoBroadcastHls');
              }else if(text.indexOf('mpegts') != -1){
                this.$set(this,'pageType','miniProgramVideoHls');
              }else{
                this.$set(this,'pageType','miniProgramVideo');
              }
            }).catch((error) => {})
          }else if(text.indexOf('alarmHK') != -1){
            localStorage.setItem('alarmUrl',window.location.href);
            this.$set(this,'pageType','alarm');
          }else if(text.indexOf('cameraIndexCode') != -1){
            this.$set(this,'pageType','miniProgramPlayback');
          }else if(text.indexOf('chemicalsInstructionsVideo') != -1){
            this.$set(this,'pageType','chemicalsInstructionsVideo');
          }
        },
        methods: {
          //获取开发配置
          getConfigByType() {
            let text = decodeURIComponent(window.location.href);
            let urlList = text.split("?")[1].split("&");
            let urlData = {};
            urlList.forEach((item) => {
              urlData[item.split("=")[0]] = item.split("=")[1];
            });
            localStorage.setItem('touken',urlData.touken)
            getConfigByType({category: 2, configType: 5}).then(response => {
              let obj = JSON.parse(response.data.configValue)
              //文件预览地址
              localStorage.setItem('filePreviewUrl', 'https://' + obj.fileExtranetUrl)
              //小程序视频地址
              localStorage.setItem('cameraExtranetAgent', 'https://' + obj.cameraExtranetAgent)
              //MQTT地址
              localStorage.setItem('mqttUrl', Decrypt(obj.mqttExtranetUrl))
              //MQTT地址-内网
              localStorage.setItem('mqttIntranetUrl', Decrypt(obj.mqttIntranetUrl))
              //MQTT账号
              localStorage.setItem('mqttUser', Decrypt(obj.mqttExtranetUser))
              //MQTT密码
              localStorage.setItem('mqttPassword', Decrypt(obj.mqttExtranetPassword))
              //文件浏览环境
              localStorage.setItem('fileBrowseEnvironment', 'http://' + Decrypt(obj.fileBrowseEnvironment))
              localStorage.setItem('fileBrowseEnvironmentExtranet', 'http://' + Decrypt(obj.fileBrowseEnvironmentExtranet))

            })
          },
        },
    }
</script>
<style scoped lang="scss">
    .home{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
</style>
