import Vue from 'vue'
import App from './App.vue'
import '../public/css/global.css'
import router from './router'
import store from './store'
import { antdFunction } from './antd'
import storage from './utils/storage'
import * as filters from './utils/filters'
import directives from './directives/directives'
Object.keys(filters).forEach(key => {
	Vue.filter(key, filters[key])
})
Vue.use(antdFunction);
Vue.use(directives);
Vue.config.productionTip = false;
Vue.prototype.$storage = storage;
router.beforeEach((to, from, next) => {
	// if (to.meta.title) {
	// 	document.title = to.meta.title;
	// }
	//是否需要登录验证
	if (to.meta.requireAuth) {
		let token = localStorage.getItem("Token")
		if (token && token != 'undefined') {
			let userID = localStorage.getItem("userId") || '';
			if (to.name == 'login' && userID) {
				next({ name: 'qusetionBankManage' });
			} else {
				if (Object.keys(store.state.userInfo.Info).length === 0) {
					store.dispatch('UserGet');
				}
				if (store.state.userInfo.Roles.length == 0) {
					// store.dispatch('RoleGetRoleForEdit');
				}
				next();
			}
		} else {
			next({ name: 'login' })
		}
	} else {
		next();
	}
})
new Vue({
	router,
	store,
	render: h => h(App)
}).$mount('#app')
