// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import {
	VueJsonp
} from 'vue-jsonp'
Vue.use(VueJsonp)
import App from './App'
import router from './router'
import store from './store/store' // 引入store
import resource from 'vue-resource' // 引入vue-resource
import tabbar from './components/tabbar.vue'
import banner from './components/banner.vue'
import back from './components/back.vue'
import backIndex from './components/backindex.vue'
import Vant from 'vant'
import 'vant/lib/index.less'
import request from "@/utils/request"
import VConsole from 'vconsole';

const vconsole = new VConsole()
Vue.prototype.$axios = request
// Vue.use(request)
Vue.component('tabbar', tabbar)
Vue.component('banner', banner)
Vue.component('back', back)
Vue.component('backindex', backIndex)
Vue.config.productionTip = false
Vue.use(Vant)
Vue.use(resource)
import common from './script/common.js'
Vue.use(common)
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
import Swiper from "swiper"
import 'swiper/swiper.min.css' //样式文件
//import wx from "weixin-jsapi"; 
// 在man.js中注册 weixin-jsapi
//Vue.prototype.wx = wx
import wx from 'weixin-js-sdk'
Vue.prototype.$wx = wx

// import { getWxOpenId } from './script/wxGetOpenId.js'
import { getWxOpenId } from './script/wxGetOpenId.js'
const whiteList = ['/Login']
router.beforeEach((to, from, next) => {
	// if (to.matched.some(record => record.meta.needLogin)) { // 判断该路由是否需要登录权限
	if (!whiteList.includes(to.path)) {
		console.log('有登录权限',to,to.path,from)
		if (!localStorage.getItem('courierUserId')) { // 判断当前用户的登录信息userId是否存在
			console.log('无userId')
			next('/Login')
		} else if (!localStorage.getItem('courierOpenid')) {
			console.log('无openId')
			getWxOpenId().then(() => {
				if(to.path == '/') {
					console.log('window.location.reload()')
					// window.location.reload()
					next()
				}else {
					next()
				}
			})
			console.log('overallExample.getOpenid()走完了')
		} else {
			console.log('什么都有')
			if(to.path == '/') {
				console.log('window.location.reload()')
				// window.location.reload()
				next()
			}else {
				next()
			}
		}
	} else {
		console.log('无登录权限')
		next();
	}
})


new Vue({
	el: '#app',
	router,
	store: store,
	components: { App },
	template: '<App/>',

})
