import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/styles/main.less' // global css
import '@/plugins/vant'
import '@/filters'
import '@/plugins/vueClipboard'
import '@/plugins/deviceId'

router.beforeEach((to, from, next) => {
  const { uin = 0, id = 0, sessionId = 0 } = to.query

  if (!uin && !['/error'].includes(to.path)) {
    // 处理缺失 uin 的情况
    next('/error')
    return
  }
  store.commit('users/SET_UIN', uin)

  if (['/list', '/index', '/message', '/winners'].includes(to.path) && !id) {
    // 处理缺失 id 的情况
    next('/error')
    return
  }

  if (['/index', '/message'].includes(to.path) && !sessionId) {
    // 处理缺失 sessionId 的情况
    next('/error')
    return
  }

  // 如果一切正常，继续导航
  next()
})


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
