app.vue 2.12 KB
<template>
  <div id="app">
    <transition
      :name="`route-view-${yoho.direction}`">
      <router-view></router-view>
    </transition>
    <div class="fps" v-if="showFps">
      {{fps}}
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex';

export default {
  name: 'App',
  data() {
    return {
      showFps: false,
      fpsTick: 0,
      fps: 0
    };
  },
  computed: {
    ...mapState(['yoho'])
  },
  mounted() {
    if (process.env.NODE_ENV === 'development') {
      this.showFps = true;
      this.frameCallback();
    }
    if (this.yoho.context.needLogin) {
      this.$yoho.ready(() => {
        this.$sdk.goLogin();
      });
    }
  },
  methods: {
    frameCallback() {
      window.requestAnimationFrame(() => {
        const now = Date.now();

        if (!this.time) {
          this.time = now;
        }
        if (now - this.time >= 1000) {
          this.time = now;
          this.fps = this.fpsTick;
          this.fpsTick = 0;
        }
        this.fpsTick++;
        this.frameCallback();
      });
    }
  },
  watch: {
    'yoho.context.needLogin': function(newVal) {
      if (newVal) {
        this.$sdk.goLogin();
      }
    },
  }
};
</script>

<style lang="scss">
.route-view-forword-enter-active,
.route-view-forword-leave-active,
.route-view-back-enter-active,
.route-view-back-leave-active {
  will-change: true;
  width: 100%;
  height: 100%;
  position: absolute;
  backface-visibility: hidden;
  perspective: 1000;
}

.route-view-forword-leave-active,
.route-view-back-leave-active {
  transition: all 200ms;
}

.route-view-forword-enter-active,
.route-view-back-enter-active {
  transition: all 200ms cubic-bezier(0.165, 0.84, 0.44, 1);
}

.route-view-forword-enter {
  transform: translate3d(100%, 0, 0);
}

.route-view-forword-leave-active {
  transform: translate3d(-30%, 0, 0);
}

.route-view-back-enter {
  z-index: 1;
  transform: translate3d(-30%, 0, 0);
}

.route-view-back-leave-active {
  transform: translate3d(100%, 0, 0);
  z-index: 2;
}

.fps {
  position: absolute;
  z-index: 99;
  left: 0;
  top: 0;
  width: 20PX;
  height: 20PX;
  background-color: white;
  color: black;
}
</style>