import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import {dynamicRoutes} from "./module/dynamicRoutes";
import {globalRoutes} from "./module/globalRoutes";

import { useStore } from 'vuex'

const routes: Array<RouteRecordRaw> = [
  ...dynamicRoutes,
  ...globalRoutes
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

/**
 * 设置标题
 */
router.afterEach((to, from) => {
  document.title = '复诊系统 - ' + to.meta.title;
})


router.beforeEach((to,from,next)=>{
	const store = useStore()
  const token = 1
	if(token){
		next()
	}else{
		//如果是登录页面路径，就直接next()
		if (to.path === '/') {
			next();
		} else {
			next('/');
		}
	}
	// if(to.name=='login'){//直接进入了登录,清除token
	// 	let obj = store.state.userinfo
	// 	obj.token = ''
	// 	obj.UserId = ''
	// 	store.commit('setInfo',obj) 
	// }
})

export default router
