<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <div v-if="envtips!=''" class="envtipsBox">{{ envtips }}</div>
      <router-view/>
    </div>
  </a-config-provider>
</template>

<script>
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import { AppDeviceEnquire } from '@/utils/mixin'
import { onTextSelected } from '@/utils/util'
import moment from 'moment';//引入moment 
import 'moment/locale/zh-cn';
moment.locale('zh-cn'); //设置语言 或 moment.lang('zh-cn'); 
export default {
  mixins: [AppDeviceEnquire],
  data () {
    return {
      locale:zhCN,
      envtips: '',
      moment
    }
  },
  created () {
    const _this = this
    this.envtips = process.env.VUE_APP_ENVTIPS
    // 在页面加载时读取sessionStorage
    if (sessionStorage.getItem('store')) {
      const data = JSON.parse(sessionStorage.getItem('store'))
      sessionStorage.setItem('Access-Token', data.user.token)
      this.$store.replaceState(Object.assign({}, this.$store.state, data))
    }
    // 在页面刷新时将store保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      this.$store.state.app.isNewTab = true
      this.$store.state.app.updateList = false
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })
    // 按F5 刷新页面
    window.addEventListener('keydown', (e) => {
      if (e.keyCode == '116') {
        window.location.reload()
      }
    })
    // window.addEventListener('visibilitychange',()=>{
    //   this.$store.state.app.visibilityState = document.visibilityState == 'visible'
    // })
    // window.addEventListener('focus',(e)=>{
    //   if(!this.$store.state.app.visibilityState){
    //     this.$store.state.app.visibilityState = true
    //   }
    // })
    // window.addEventListener('blur',(e)=>{
    //   if(this.$store.state.app.visibilityState){
    //     this.$store.state.app.visibilityState = false
    //   }
    // })
    // 选择文本后复制
    window.addEventListener('mouseup', (e) => {
      onTextSelected(this.$copyText,this.$message)
    })
    window.addEventListener('mousedown', (e) => {
      const n = document.getElementsByClassName('copy-rect')
      if(n[0]){
        document.body.removeChild(n[0])
      }
    })

    this.$message.config({
      top: `100px`,
      duration: 3,
      maxCount: 3
    })
  }
}
</script>
<style lang="less">
  #app {
    height: 100%;
  }
  .copy-rect{
      background: #fff;
      border: 1px solid #eee;
      border-radius: 5px;
      font-size: 12px;
      padding: 2px 5px;
      cursor: pointer;
      &:hover{
        color: #0282eb;
      }
    }
  .envtipsBox{
    position: fixed;
    z-index: 100000;
    background: red;
    text-align: center;
    color: #fff;
    font-size: 30px;
    top: 0;
    left: 0;
    width: 30%;
    margin-left: 20%;
  }
</style>
