import { setupLayouts } from 'virtual:meta-layouts'
import { createRouter, createWebHistory } from 'vue-router'
import { routes as fileRoutes } from 'vue-router/auto-routes'
declare module 'vue-router' {}
// 重定向 BASE_URL
fileRoutes.flat(Infinity).forEach((route) => {
	route.path = safeResolve(route.path)
})
export const router = createRouter({
	history: createWebHistory(),
	routes: setupLayouts(fileRoutes),
})
// 路由拦截
router.beforeEach((to, from, next) => {
	// 前台处理逻辑
	if (to.fullPath.includes("/front")){
		if (to.fullPath.includes("/front/info")){
			console.log("公告管理~")
      //判断有没有登录
      if (!userStore().frontIsLogin){
        ElMessage.warning("请先登录~")
        next('/login');
      }
		}
	}
	///////////////////////////////////////////////////////////////////////////////
	// 管理员全部限制
	else if (to.fullPath.includes("/admin")){
		console.log("管理员认证~")
		//判断有没有登录
		if (!userStore().adminIsLogin){
			ElMessage.warning("认证失败~")
			next('/login');
		}
	}
	next();
});

export default router
