<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"/>
      </keep-alive>
    </transition>
    <transition :name="transitionName">
      <router-view v-if="!$route.meta.keepAlive"/>
    </transition>
  </div>
</template>

<script>
export default {
  data () {
    return {
      pathList: [],
      transitionName: 'slide-left',
    }
  },
  watch: { // 监听路由变化
    $route (to, from) {
      if (this.pathList.includes(to.path)) {
        const index = (this.pathList.findIndex(() => {
          return from.path
        }))
        this.pathList.splice(index, 1)
        this.$router.isBack = 1
      } else {
        this.pathList.push(to.path)
        this.$router.isBack = 2
      }
      if (to.path === '/tab/home-page' || to.path === '/tab/my-info' || to.path === '/tab/message-center' || from.path === '/tab/home-page' || from.path === '/tab/my-info' || from.path === '/tab/message-center') {
        this.$router.isBack = 3
        this.transitionName = ''
        this.pathList = []
      }
      // let isBack = this.$router.isBack
      if (to.path !== '/tab/home-page' && to.path !== '/tab/my-info' && to.path !== '/tab/message-center') {
        this.transitionName = 'router-slide-right'
        this.$router.isBack = 2
      }
    },
  },
  methods: {
    onSwipeLeft () {
      this.$router.go(-1)
    },
  },
}
</script>

<style lang="less">
  @import "styles/variables";
  @import "styles/public-style";

  html, body, #app {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    //overflow: auto;
    //-webkit-overflow-scrolling: touch;
    //overflow-scrolling: touch;
  }

  .weui-dialog {
    top: 45vh !important;
  }
</style>
