import router from '@/router'
import store from '@/store'
import { getCookie, setCookie } from "@/utils/cookie";
import i18n from './lang'
const userToken = getCookie('userToken')
if (userToken) {
  store.commit('SET_LOGIN', true)
}
store.commit("CHANGE_META_INFO", {
  title: i18n.t('html.title'),
  description: i18n.t('html.description'),
  keywords: i18n.t('html.keywords')
})
router.beforeEach(async(to, from, next) => {
  if (to.query.flag) {
    store.commit('setAppFlag')
  }
  if (to.query.token) {
    store.commit('setToken', to.query.token)
    store.commit('SET_LOGIN', true)
    setCookie("userToken", to.query.token)
  }
  if (to.meta.mustLogin && !store.getters.isLogin) {
    next('/login?rejectUrl=' + to.fullPath)
    return
  }
  if (!to.meta.mustLogin && to.meta.loginHidden && store.getters.isLogin) {
    next('/')
    return
  }
  next()
})

router.afterEach(() => {
})

