<template>
  <div class="site-bar" v-show="1">
    <div class="btn wechat">
      <svg-icon icon-class="wechat"  />
      <img class="show-img z-50" :src="imagePathBabel(platform.wx_qrc)" alt="">
    </div>
    <div class="btn top" @click="toTop" >
      <svg-icon icon-class="top" />
    </div>
  </div>
</template>

<script>
// 网页侧边栏小工具
import {imagePathBabel} from "@/tools/imagePath";

export default {
  name: "siteBar",
  props:{
    lang: {
      type: String,
      default: 'cn'
    },
  },
  data() {
    return {
      platform: this.$store.getters.platform
    }
  },
  // 指令
  directives:{
    // 滚动超过一屏时显示元素,否则隐藏
    show:{
      inserted(el){
        const elHeight = el.offsetHeight;
        const winHeight = window.innerHeight;
        const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        if (elHeight + scrollTop > winHeight){
          el.style.display = 'block';
        }else{
          el.style.display = 'none';
        }
        window.addEventListener('scroll',()=>{
          const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
          if (elHeight + scrollTop > winHeight){
            el.style.display = 'block';
          }else{
            el.style.display = 'none';
          }
        })
      }
    }

  },
  methods: {
    toTop() {
      // 缓慢移动到顶部
      window.scrollTo({
        top: 0,
        behavior: "smooth"
      });
    },
    imagePathBabel
  }
}
</script>

<style scoped>
.site-bar{
  width: 50px;
  height: auto;
  position: fixed;
  right: 30px;
  bottom: 30px;
  /*transform: translateY(-50%);*/
}
@media screen and (min-width: 1024px) {
  .site-bar{
    right: 180px;
    bottom: 26%;
  }
}
.site-bar .btn{
  width: 50px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  cursor: pointer;
  background-color: #f5f5f5;
  border-radius: 50%;
  box-shadow: 0 0 5px #dedede;
  color: #999999;
  margin-bottom: 10px;
}
.site-bar .btn:hover{
  background-color: #dedede;
  color: #af4141;
}
.wechat{
  position: relative;
}
.wechat .show-img{
  position: absolute;
  bottom: 50px;
  right: 50px;
  display: block;
  width: 0;
  height: 0;
  max-width: none;
  border-radius: 5px;
  box-shadow: 1px 1px 7px 5px #dedede;
  opacity: 0;
  transition: all 0.5s;
}
.wechat:hover .show-img{
  opacity: 1;
  width: 180px;
  height: 180px;
}
</style>
