import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

import about from "../views/About.vue"
import daichuli from "../views/Daichuli/index.vue"
import yichuli from "../views/Yichuli/index.vue"
import daishenhe from "../views/Daishenhe/index.vue"
import yishenhe from "../views/Yishenhe/index.vue"
import orderUnprocessed from '../views/Daichuli/Feedback/index.vue'
import AuditDsh from '../views/Daishenhe/Audit/index.vue'
import feedbackYcl from '../views/Yichuli/Feedback/index.vue'
import feedbackYsh from '../views/Yishenhe/Feedback/index.vue'
import Inspection from '../views/Daichuli/Feedback/Inspection/index.vue'
import Report from '../views/Daichuli/Feedback/Inspection/Report/index.vue'

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login,
    meta: { title: "首页" }
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: { title: "首页" }
  },
  {
    path: '/about',
    component: about,
    children: [
      {
        path: '/daichuli',
        component: daichuli,
        name: '待处理的检验订单',
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/orderUnprocessed',
        component: orderUnprocessed,
        name: '订单反馈',
        meta: {
          requireAuth: true,
          breadNumber: 2
        }
      },
      {
        path: '/inspection',
        component: Inspection,
        name: '检验处理',
        meta: {
          requireAuth: true,
          breadNumber: 3
        }
      },
      {
        path: '/report',
        component: Report,
        name: '报告生成',
        meta: {
          requireAuth: true,
          breadNumber: 4
        }
      },
      {
        path: '/yichuli',
        component: yichuli,
        name: '已处理检验订单',
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/feedbackycl',
        component: feedbackYcl,
        name: '订单处理信息',
        meta: {
          requireAuth: true,
          breadNumber: 2
        }
      },
      {
        path: '/daishenhe',
        component: daishenhe,
        name: '待审核检验订单',
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/auditdsh',
        component: AuditDsh,
        name: '订单审核',
        meta: {
          requireAuth: true,
          breadNumber: 2
        }
      },
      {
        path: '/yishenhe',
        component: yishenhe,
        name: '已审核检验订单',
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/feedbackysh',
        component: feedbackYsh,
        name: '已审核订单信息',
        meta: {
          requireAuth: true,
          breadNumber: 2
        }
      }
    ]
  }
]
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

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

router.beforeEach((to, from, next) => {
  sessionStorage.setItem('prePage',from.path)
  next()
})

export default router
