<template>
  <Nuxt v-if="ready" />
</template>
<script>
export default {
  data() {
    return {
      ready: false,
      tasks: [],
      timerTask: undefined
    }
  },
  head() {
    return {title: 'Cloud'}
  },
  async created() {
    let connlist = this.$readyapi(['moneyunit', 'datatype', 'filterchoice', 'colorchoice', 'textalign', 'placement', 'sex', 'legaltype',
    'colorscheme', 'filtertype', 'sorttype', 'tablesetting', 'settingchoice', 'menuchoice', 'settingtype', 'settingclass', 'runtype', 
    'usertype', 'dbtype'])
    let filter = connlist.filter(v=>!v.ready)
    if(filter.length>0) {
      let rs = await this.$getapi(filter)
      this.ready = true
      if(!this.$store.state.login) this.$router.push('/signin')
    } else {
      this.ready = true
      if(!this.$store.state.login) this.$router.push('/signin')
    }
  },
  mounted() {
    var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
    if(this.$empty(this.viewport)) {
      if(width<=768) this.viewport = 1 //'mobile'
      else if(width>=769 && width<=1023) this.viewport = 2  //'tablet'
      else if(width>=1024 && width<=1215) this.viewport = 3 //'desktop'
      else if(width>=1216 && width<=1407) this.viewport = 4 //'widescreen'
      else if(width>=1408) this.viewport = 5 //'fullhd'
    }
  },
  computed: {
    login: {
      get: function() {return this.$store.state.login},
      set: function(val) {this.$store.commit("updateLogin", {login: val})}
    },
    language: {
      get: function() {return this.$store.state.language},
      set: function(val) {this.$store.commit("updateLanguage", {language: val})}
    },
    common: {
      get: function() {return this.$store.state.common},
      set: function(val) {this.$store.commit("updateCommon", {common: val})}
    },
    tablesetting: {
      get: function() {return this.$store.state.tablesetting},
      set: function(val) {this.$store.commit("updateTable", {tablesetting: val})}
    },
    dialog: {
      get: function() {return this.$store.state['dialog']},
      set: function(val) {this.$store.commit('updateStore', {name: 'dialog', data: val})}
    },
    sshlist: {
      get: function() {return this.$store.state.sshlist},
      set: function(val) {this.$store.commit("updateSshlist", {sshlist: val})}
    },
    viewport: {
      get: function() {return this.$store.state.viewport},
      set: function(val) {this.$store.commit("updateViewPort", {viewport: val})}
    },
    taskstoday: {
      get: function() {return this.$store.state['taskstoday']},
      set: function(val) {this.$store.commit('updateStore', {name: 'taskstoday', data: val})}
    },
    datatask: {
      get: function() {return this.$store.state['datatask']},
      set: function(val) {this.$store.commit('updateStore', {name: 'datatask', data: val})}
    },
    showmodal: {
      get: function() {return this.$store.state['showmodal']},
      set: function(val) {this.$store.commit('updateStore', {name: 'showmodal', data: val})}
    }
  }
}
</script>