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

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

  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('上传设备配置文件成功!')

            // 获取大屏,信号源，设备数据并保存到vuex中
            const bigScreenJson = await reqBigScreen()
            const signalListJson = await reqPreviewSourceList()
            const deviceJson = await reqDevice()
            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>
