import { createRouter, createWebHashHistory } from 'vue-router'



import Login from '../views/Login.vue'
import Index from '../views/Index.vue'
import MenuList from '../views/SystemMngr/Menu/List.vue'
import AdminGroupList from '../views/SystemMngr/Group/List.vue'
import AdminUserList from '../views/SystemMngr/User/List.vue'
import AdminChangPwd from '../views/SystemMngr/User/ChangPwd.vue'
import HealthCalendar from '../views/AppointmentMngr/HealthCalendar.vue'
import AppointmentList from '../views/AppointmentMngr/AppointmentList.vue'
import healthCheckList from '../views/MedicalCenter/HealthCheckList.vue'
import Dashboard from '../views/MedicalCenter/Dashboard.vue'
import AppointmentCount from '../views/Report/AppointmentCount.vue'
import ConflictRecord from '../views/Report/ConflictRecord.vue'
import DeleteOperationLog from '../views/Report/DeleteOperationLog.vue'

const router = createRouter({
	history: createWebHashHistory(import.meta.env.BASE_URL),
	routes: [
		{
			path: '/',
			name: 'Login1',
			component: Login,
			meta: { requiresAuth:false}
		},
		 {
			path: '/login',
			name: 'Login',
			component: Login,
			meta: { requiresAuth:false}
		}, {
			path: '/index',
			name: 'Index',
			component: Index,
			children: [{
				path: '/dashboard',
				name: 'Dashboard',
				component: Dashboard,
				meta: { title: '数据面板' }
			}, {
				path: '/menuList',
				name: 'menuList',
				component: MenuList,
				meta: { title: '菜单管理' }
			}, {
				path: '/groupMngr',
				name: 'AdminGroupList',
				component: AdminGroupList,
				meta: { title: '组管理' }
			}, {
				path: '/adminUserList',
				name: 'AdminUserList',
				component: AdminUserList,
				meta: { title: '系统用户管理' }
			}, {
				path: '/adminChangPwd',
				name: 'AdminChangPwd',
				component: AdminChangPwd,
				meta: { title: '用户中心' }
			}, {
				path: '/systemMngr/systemLog',
				name: 'SystemMngrsystemLog',
				component: () => import('../views/SystemMngr/SystemLog.vue'),
				meta: {
					title: '系统日志'
				}
			} ,{
				path: '/systemMngr/InstitutionMngr',
				name: 'SystemInstitutionMngr',
				component: () => import('../views/SystemMngr/Institution/InstitutionMngr.vue'),
				meta: {
					title: '机构管理'
				}
			},{
				path: '/healthCalendar',
				name: 'HealthCalendar',
				component: HealthCalendar,
				meta: { title: '体检日历' }
			}, {
				path: '/healthCheckList',
				name: 'HealthCheckList',
				component: healthCheckList,
				meta: { title: '体检记录列表' }
			}, {
				path: '/appointmentList',
				name: 'AppointmentList',
				component: AppointmentList,
				meta: { title: '预约记录列表' }
			} ,{
				path: '/report/appointmentList',
				name: 'ReportAppointmentList',
				component: AppointmentCount,
				meta: { title: '预约登记统计' }
			},{
				path: '/report/healthcard',
				name: 'ReportHealthCard',
				component: () => import('../views/Report/HealthCard.vue'),
				meta: { title: '体检统计' }
			},{
				path: '/report/conflictRecord',
				name: 'ReportConflictRecord',
				component: ConflictRecord,
				meta: { title: '冲突记录' }
			},{
				path: '/report/deleteOperationLog',
				name: 'ReportDeleteOperationLog',
				component: DeleteOperationLog,
				meta: { title: '取消操作日志' }
			},{
				path: '/systemMngr/Configs',
				name: 'SystemConfigs',
				component: () => import('../views/SystemMngr/Configs.vue'),
				meta: {
					title: '系统参数设置'
				}
			}, {
				path: '/pushilist',
				name: 'pingTaiPushList',
				component: () => import('../views/PingTai/PushList.vue'),
				meta: { title: '平台推送列表' }
			}]
		},
		
	]
})


import {
	CheckMenuAuth
} from "@/api/api.js";
import {
	ElMessage
} from 'element-plus'


router.beforeEach( (to, from ,next) => {
	console.log(to.meta.requiresAuth)
	const url= to.path
	if(to.meta.requiresAuth ==false){
		next()	
	}else{
		const NewUrl=url.substring(1)
		CheckMenuAuth({url:NewUrl}).then(res=>{
			if(res.status){
				next();
			}else{
				ElMessage.error(res.msg)
				next('/');
			}
		})
	}
})


export default router
