<template>
  <div id="app">
    <div class="view-container">
      <AppHeader :visible="visible"></AppHeader>
      <transition :name="transitionName">
        <router-view />
      </transition>
      <AppBackTop></AppBackTop>
    </div>
    <el-dialog  width="50%" title="系统规则" :visible.sync="dialogVisible">
      <!-- <div>座机：010-82783688转122</div>
      <div>邮箱：guowl@dgtis.com</div> -->
      <div v-html="htmlData"></div>
    </el-dialog>
  </div>
</template>
<script>
import AppHeader from '@/components/AppHeader.vue';
import AppBackTop from '@/components/AppBackTop.vue';
import { lockStatus } from "@/api/allApi";
export default {
  name: 'app',
  components: {
    AppHeader,
    AppBackTop
  },
  data() {
    return {
      htmlData:'',
      dialogVisible: false,
      transitionName: "",
      isGray: false,
      visible:true,
    };
  },
  created(){
    this.$store.dispatch('GetUserInfo');
    this.$nextTick(() => {
      // 1.禁用右键菜单
      document.oncontextmenu = new Function("event.returnValue=false");
      // 2.禁用鼠标选中
      document.onselectstart = new Function("event.returnValue=false");
      // 3.禁止键盘F12键
      document.addEventListener("keydown", function (e) {
        // 禁止 F12
        if (e.key === "F12") {
          e.preventDefault();
        }
        // 禁止 Ctrl + Shift + I 打开开发者工具
        if (e.ctrlKey && e.shiftKey && e.key === 'I') {
          e.preventDefault();
        }
        // 禁止 Ctrl + Shift + C 打开检查元素
        if (e.ctrlKey && e.shiftKey && e.key === 'C') {
          e.preventDefault();
        }
      });
    });
  },
  methods:{
    fatherMethod() {
      lockStatus().then(response=>{
        this.htmlData = response.data.errmsg; 
        this.dialogVisible = true;
      })
    },
    // 保存滚动值，这是兼容的写法
    handleScroll () {
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
          //变量scrollTop是滚动条滚动时，距离顶部的距离
      // var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    //   //变量windowHeight是可视区的高度
    //   var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
    //   //变量windowHeight是可视区的高度
    //   var scrollHeight =document.documentElement.scrollHeight || document.body.scrollHeight;
    //       //滚动条到底部的条件
    //    if(scrollTop + windowHeight == scrollHeight){
    //         //你要触发的方法
    //     }
        if(scrollTop >= 80){
            this.visible = false;
        }else{
          this.visible = true;
        }
    },
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },

  destroyed () {
    // 离开该页面需要移除这个监听的事件，不然会报错
    window.removeEventListener('scroll', this.handleScroll)
  },
  watch: {
    //使用watch 监听$router的变化
    $route(to, from) {
      //如果to索引大于from索引,判断为前进状态,反之则为后退状态
      console.log(to, "to");
      console.log(from, "from");
      if (to.meta.index > from.meta.index) {
        //设置动画名称
        this.transitionName = "slide-left";
      } else {
        this.transitionName = "slide-right";
      }
    },
  },
}
</script>
<style>
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 0;
}

::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 5px;
  height: 6px;
}

::-webkit-scrollbar-thumb {
  cursor: pointer;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.15);
  transition: color 0.2s ease;
}
.el-card__body{
    padding: 0 10px !important;
}
.el-dialog__body{
  padding-top: 0px !important;
}
.view-container{
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 1200px;
}


.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 80ms;
  position: fixed;
}
​
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
​
.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
​
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
​
.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
</style>

<style scoped>
::v-deep .el-dialog {
  left: 50%;
  top: 5%;
  transform: translate(-50%, -5%);
  margin: 0px !important;
  border-radius: 8px;
}
::v-deep .el-dialog__title,::v-deep .el-dialog__headerbtn{
  font-size: 24px;
}
::v-deep .el-dialog__header {
    -webkit-box-shadow: 0 1px 4px 0 rgba(31, 45, 61, .12);
    box-shadow: 0 1px 4px 0 rgba(31, 45, 61, .12);
}
::v-deep .el-dialog__body{
    overflow: auto;
    overflow-x: hidden;
    max-height: 70vh!important;
}
::v-deep .el-dialog__footer {
    border-top: 1px solid #d7d9dc;
}
</style>
