<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
  import axios from 'axios'
  import {
    reqBigScreen,
    reqConfigBigScreen,
    reqConfigDevice,
    reqDevice,
    reqPreviewSourceList
  } from "./api"
  import {getStaticFile} from "../utils/tools"

  export default {
    async mounted() {
      // 单独上传配置文件
      axios.get('static/Data/EnityBigScreen.Data').then(async res => {
        if (res.status === 200) {
          const result = await reqConfigBigScreen(res.data)
          if(result[0].ID){
            console.log('上传大屏配置文件成功!')
          }
        }
      })

      axios.get('static/Data/EnityDevice.Data').then(async res => {
        if (res.status === 200) {
          const result = await reqConfigDevice(res.data)
          if(result[0].ID){
            console.log('上传设备配置文件成功!')

            const windowJson = await getStaticFile('EnityWindow.Data')
            const arr = windowJson.filter(item => item.IsVisibility === true)
            const homeJson = arr[0]
            this.$store.dispatch('updateHomeJson',homeJson)


            // 获取大屏,信号源，设备数据，label数据并保存到vuex中
            const bigScreenJson = await reqBigScreen()
            const signalListJson = await reqPreviewSourceList()
            const deviceJson = await reqDevice()
            const labelJson = await getStaticFile('EnityLable.Data')
            this.$store.dispatch('updateLabelJson',labelJson)
            this.$store.dispatch('saveBigscreen',bigScreenJson.filter(item => item.IsVisibility === true))
            this.$store.dispatch('saveSignalList',signalListJson)
            this.$store.dispatch('saveDevice',deviceJson)
          }
        }
      })

      // 更新vuex中的缩放比例
      // axios.get('static/Data/EnityWindow.Data').then(async res => {
      //   if (res.status === 200) {
      //         const bigScale = window.screen.height/res.data[0].Height
      //         this.$store.dispatch('updateScale',bigScale)
      //     }
      // })
    }
  }
</script>
