// 100普通路由
import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/views/Login.vue'
import Home from '@/views/Home.vue'
import Welcome from '@/views/Welcome.vue'
 
 

import FeedProcess from '@/views/dataStatistics/FeedProcess.vue'
import WeightTrend from '@/views/dataStatistics/WeightTrend.vue'
import FormulaEffect from '@/views/dataStatistics/FormulaEffect.vue'
import GrowthRate from '@/views/dataStatistics/GrowthRate.vue'
import FeedCost from '@/views/dataStatistics/FeedCost.vue'
import DiseaseSituation from '@/views/dataStatistics/DiseaseSituation.vue'
import SurvivalRate from '@/views/dataStatistics/SurvivalRate.vue'


import WeightRecord from '@/views/cowManagement/WeightRecord.vue'
import CowInfo from '@/views/cowManagement/CowInfo.vue'
import EventRecord from '@/views/cowManagement/EventRecord.vue'




import CowCowShed from '@/views/cowShedManagement/CowCowShed.vue'
import CowShedGroup from '@/views/cowShedManagement/CowShedGroup.vue'

import FeedPlan from '@/views/formulaPlan/FeedPlan.vue'
import FormulaTemplate from '@/views/formulaPlan/FormulaTemplate.vue'

import WorkTaskAssign from '@/views/workManagement/WorkTaskAssign.vue'
import WorkTaskImplement from '@/views/workManagement/WorkTaskImplement.vue'


import CalfType from '@/views/basicSettings/CalfType.vue'
import WorkOrderType from '@/views/basicSettings/WorkOrderType.vue'
import FeedCarManagement from '@/views/basicSettings/FeedCarManagement.vue'
import DiseaseManagement from '@/views/basicSettings/DiseaseManagement.vue'
import InfoRemind from '@/views/basicSettings/InfoRemind.vue'
import DiseaseType from '@/views/basicSettings/DiseaseType.vue'
import FeedTemplate from '@/views/basicSettings/FeedTemplate.vue'
import DefaultPara from '@/views/basicSettings/DefaultPara.vue'
import FeedCostSet from '@/views/basicSettings/FeedCostSet.vue'

import User from '@/views/systemManagement/User.vue'
import Role from '@/views/systemManagement/Role.vue'
import MenuManagement from '@/views/systemManagement/MenuManagement.vue'

import messageTemplete from '@/views/messageCenter/messageTemplete.vue'
import MessagesReceive from '@/views/messageCenter/MessagesReceive.vue'
import MessageSend from '@/views/messageCenter/MessageSend.vue'
 


Vue.use(Router)

const router =  new Router({
  mode:'hash',
  routes: [
    // 当路径为/,重定向路径到/login
    { path: '/', redirect: '/login' },
    // 当路径为/login,转到组件Login
    { path: '/login', component: Login },
    { 
      path: '/home', 
      component: Home,
      // 当路径为/home,转到组件welcome
      redirect: '/welcome',
      //children里面放的是home组件下的子组件
      children:[
        { path: '/welcome', component: Welcome },
         
        

        { path: '/FeedProcess', component: FeedProcess },
        { path: '/WeightTrend', component: WeightTrend },
        { path: '/FormulaEffect', component: FormulaEffect },
        { path: '/GrowthRate', component: GrowthRate },
        { path: '/FeedCost', component: FeedCost },
        { path: '/DiseaseSituation', component: DiseaseSituation },
        { path: '/SurvivalRate', component: SurvivalRate },

        { path: '/WeightRecord', component: WeightRecord },
        { path: '/CowInfo', component: CowInfo },
        { path: '/EventRecord', component: EventRecord },
        
        

        { path: '/CowCowShed', component: CowCowShed },
        { path: '/CowShedGroup', component: CowShedGroup },

        { path: '/FeedPlan', component: FeedPlan },
        { path: '/FormulaTemplate', component: FormulaTemplate },

        { path: '/WorkTaskAssign', component: WorkTaskAssign },
        { path: '/WorkTaskImplement', component: WorkTaskImplement },
        

        { path: '/CalfType', component: CalfType },
        { path: '/WorkOrderType', component: WorkOrderType },
        { path: '/FeedCarManagement', component: FeedCarManagement },
        { path: '/DiseaseManagement', component: DiseaseManagement },
        { path: '/InfoRemind', component: InfoRemind },
        { path: '/DiseaseType', component: DiseaseType },
        { path: '/FeedTemplate', component: FeedTemplate },
        { path: '/DefaultPara', component: DefaultPara },
        { path: '/FeedCostSet', component: FeedCostSet },

  
        { path: '/User', component: User },
        { path: '/Role', component: Role },
        { path: '/MenuManagement',  name: 'MenuManagement', component: MenuManagement },
        
        { path: '/messageTemplete', component: messageTemplete },
        { path: '/MessagesReceive', component: MessagesReceive },
        { path: '/MessageSend',component: MessageSend },
        

 
 
        
      ] 
    }
  ]
})



// 添加 beforeEach 导航守卫，如果用户没登录，直接访问其他页面，就跳转到登录页
router.beforeEach((to, form, next) => {
  // to 将要访问的路径
  // form 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  // next() 放行，next('/login')强制跳转
  //如果用户访问登录页，直接放行，
  if(to.path === '/login') return next();
  //从本地存储获取到token信息
  // const tokenStr  = window.sessionStorage.getItem('token')
  //没有token就强制跳转到登录页
   //if (!tokenStr) return next('/login')
  next()
})

export default router

