<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { isAppEnv, close } from './util/Bridge'
import {postMessage} from '@/util/PostMessage'
import { PostMsg } from './Interface'

export default Vue.extend({
  name: 'App',
  components: {
    // 'app-icon':()=>import('./components/common/Icon.vue'),
    // 'main-page': () => import('@/layout/main-page.vue')
  },
  data() {
    return {
      timer: 0 as any
    }
  },
  created() {
    if (!isAppEnv()) {
      this.intervalHandler()
      this.timer = setInterval(this.intervalHandler, 60 * 1000)
    }
    if (window.history) {
      window.addEventListener('popstate', this.handler)
    }
  },
  beforeDestroy() {
    if (!isAppEnv()) {
      clearInterval(this.timer)
    }
    window.removeEventListener('popstate', this.handler)
  },
  methods: {
    handler(e:PopStateEvent) {
      if(this.$route.path === '/team/team-frame') {
        close()
      }
      if(['/team/two-code'].indexOf(this.$route.path) > -1) {
        window.history.pushState(null, '', window.origin + '/team/team-frame')
      }
    },
    intervalHandler() {
      postMessage(PostMsg.GET_AUTH).then((data: any) => {
        if (data.method === PostMsg.GET_AUTH) {
          this.$global.sig = data.data
        }
      })
    }
  }
})
</script>

<style lang="less">

</style>
