
<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"/>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"/>
    <viewer :images="images" :options='imageOptions' @inited="inited" class="viewer" ref="viewer">
      <img v-for="src in images" :src="src" :key="src">
    </viewer>
    <chosen-open-mode v-if="haveOpenMode" :settingSys="settingSys"></chosen-open-mode>
    <!--  -->
    
  </div>
</template>


<script>
var sUserAgent = navigator.userAgent;
  if (sUserAgent.indexOf('Android') > -1 || sUserAgent.indexOf('iPhone') > -1 || sUserAgent.indexOf('iPad') > -1 || sUserAgent.indexOf('iPod') > -1 || sUserAgent.indexOf('Symbian') > -1) {
      // document.body.style.minWidth = '100%'
      // document.body.style.maxWidth = '100%'
      // document.body.style.overflow = 'hidden'
      // document.html.style.minWidth = '100%'
  } else {
      document.body.style.minWidth = '1366px'
      // document.html.style.minWidth = '1366px'
  }
import chosenOpenMode from './components/commonPage/chosenOpenMode'
export default {
  name: 'App',
  components: {
    chosenOpenMode
  },
  created() {
    //注册禁止后退，并且不做卸载
    // history.go(-1)
    // history.forward(-1)
    if(localStorage.openMode && localStorage.openMode==1){
      try{
        history.pushState(null, null, document.URL);
        window.addEventListener('popstate', function () {
            history.pushState(null, null, document.URL);
        })
      } catch(err) {

      }
    }

  },
  data () {
    return {
      images:[],
      imageOptions:{
        navbar:false,
        title:false
      },
      dataShow:false,
      haveOpenMode:false,
      settingSys: false,
      
      // sessionStorage.getItem("mazip") ? sessionStorage.getItem("mazip") : true
    }
  },
  methods: {
   
    inited (viewer){
      this.$viewer = viewer
    },
    show (data) {
      this.$set(this.images,data)
      this.$viewer.show()
    }
  },
  mounted() {
    if (!this.getLocalStorage()) {
      this.$router.push({
        path: '/login'
      })
    }
    this.haveOpenMode=!localStorage.openMode
    this.MsgBus.$on('imgpreviewoverflow',content=>{
      this.show(content)
    })
    this.MsgBus.$on('imgpreviewshow',content=>{
      this.$viewer.show()
    })
    this.MsgBus.$on('imgpreviewshowindex',content=>{
      this.$viewer.view(this.images.indexOf(content))
      this.$viewer.show()
    })
    this.MsgBus.$on('settingOpen',content=>{
      this.haveOpenMode = true;
      this.settingSys = true;
    })
    this.MsgBus.$on('settingClose',content=>{
      this.haveOpenMode = false;
      this.settingSys = false;
    })
    this.MsgBus.$on('imgprevpush',content=>{
      let isExsit=false
      this.images.forEach(x=>{
        if(x==content)
          isExsit=true
      })
      if(!isExsit)
        this.images.push(content)
    })
    this.MsgBus.$on('imgprevclear',content=>{
      this.images=[]
    })
  }
}
</script>
<style>
  @import "//at.alicdn.com/t/font_635492_dxcl6yumgsq.css";
  @import "./assets/css/Semibold.css";
  @import "./assets/css/global/config.css";
  @import "./assets/css/fileIcon.css";
  /* html,body{height: 100%; min-width: 1366px; } */
  html,body{margin: 0; padding: 0; background:#f9f9f9 url(assets/img/img-bg.png) no-repeat bottom left/100% auto;height: 100%;}
  #app{height: 100%;}
  #app>div{display: flex; flex-direction: column; height: 100%;}
  .BMap_cpyCtrl {display: none;}
  .anchorBL {display: none;}
  .viewer{display: none !important;}


</style>
