import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = () => import('@/views/Home.vue')
const register = ()=>import('@/views/register.vue')
const login = ()=>import('@/views/Login.vue')
const userinfo = ()=>import('@/views/userinfo.vue')
const edit = ()=>import('@/views/Edit.vue')
const article = ()=>import('@/views/Article.vue')
const editcategory = ()=>import('@/views/EditCategory.vue')
const workbench = ()=>import('@/views/workbench.vue')
const cwAttendanceDec = ()=>import('@/views/cwAttendanceDec.vue')
const user = ()=>import('@/views/user.vue')
const leave = ()=>import('@/views/leave.vue')
const approval = ()=>import('@/views/approval.vue')
const details = ()=>import('@/views/details.vue')
const record = ()=>import('@/views/record.vue')
const ecord = ()=>import('@/views/ecord.vue')
const ubmit = ()=>import('@/views/ubmit.vue')
const lock = ()=>import('@/views/lock.vue')
const ttendance = ()=>import('@/views/ttendance.vue')
const set = ()=>import('@/views/set.vue')
const number = ()=>import('@/views/number.vue')
const assword = ()=>import('@/views/assword.vue')
const nformation = ()=>import('@/views/nformation.vue')
const ord = ()=>import('@/views/ord.vue')
const proval = ()=>import('@/views/proval.vue')

Vue.use(VueRouter)
  const routes = [
     {
       path:'/',
       component:Home,
       meta:{
         keepalive:true
       }
     },
     {
      path:'/home',
      component:Home,
      meta:{
        keepalive:true
      }
    },
     {
       path:'/register',
       component:register
     },
     {
       path:'/login',
       component:login
     },
     {
       path:'/userinfo',
       component:userinfo,
       meta:{
         istoken:true
       }
     },
     {
      path:'/user',
      component:user
      
    },
     {
       path:'/edit',
       component:edit,
       meta:{
        istoken:true
      }
     },
     {
       path:'/article/:id',
       component:article
     }, 
    {
      path:'/editcategory',
      component:editcategory
    },
    {
      path:'/workbench',
      component:workbench
    },
    {
      path:'/cwAttendanceDec',
      component:cwAttendanceDec
    },{
      path:'/leave',
      component:leave
    },
    {
      path:'/approval',
      component:approval
    },
    {
      path:'/details',
      component:details
    },
    {
      path:'/record',
      component:record
    },
    {
      path:'/ecord',
      component:ecord
    },
    {
      path:'/ubmit',
      component:ubmit
    },
    {
      path:'/lock',
      component:lock
    },
    {
      path:'/ttendance',
      component:ttendance
    },
    {
      path:'/set',
      component:set
    }, 
    {
      path:'/number',
      component:number
    },
    {
      path:'/assword',
      component:assword
    },
    {
      path:'/nformation',
      component:nformation
    },
    {
      path:'/ord',
      component:ord
    },
    {
      path:'/proval',
      component:proval
    }
  ]

const router = new VueRouter({
  routes,
  mode:'history'
})

router.beforeEach((to,from,next) => {
  if((!localStorage.getItem('token') || !localStorage.getItem('id'))&&to.meta.istoken == true){
    router.push('/login')
    Vue.prototype.$msg.fail('请重新登录')
    return
  }
  next()
})

export default router
