import Vue from 'vue'
import Router from 'vue-router'

import routerBefore from '@/config/routerBefore.js'

// 主要
import main from '@/components/main.vue'
// 系统配置管理
const processDdesign = () => import( '../components/processDdesign.vue')
const processDdesign2 = () => import( '../components/processDdesign2.vue')
const processManagement = () => import( '../components/processManagement.vue')
const workFlow2 = () => import( '../components/workFlow2.vue')
const processDialog = () => import( '../components/processDialog.vue')
const processDdesign3 = () => import( '../components/processDdesign3.vue')
const coverTask = () => import( '../components/coverTask.vue')
const approvelDetails = () => import( '../components/approvelDetails.vue')
const initiateTransactions = () => import( '../components/initiateTransactions.vue')
const userApplyStart = () => import( '../components/userApplyStart.vue')
const processActiveAndHang = () => import( '../components/processActiveAndHang.vue')
const finishedTask = () => import( '../components/finishedTask.vue')
const personalInitiatedTask = () => import( '../components/personalInitiatedTask.vue')
const countTaskApply = () => import( '../components/countTaskApply.vue')
const drawerAssembly = () => import( '../components/drawerAssembly.vue')

Vue.use(Router)

const constantRouterMap = [
  {
    path: '/',
    name: 'main',
    meta: {title: '流程引擎', code: 'xtpzgl'},
    component: main,
    redirect: {name: 'processManagement'},
    children: [
      {path: 'processDdesign', name: 'processDdesign', component: processDdesign},
      {path: 'processDdesign2', name: 'processDdesign2', component: processDdesign2},
      {path: 'processManagement', name: 'processManagement', component: processManagement, meta: {keepAlive: true}},
      {path: 'workFlow2', name: 'workFlow2', component: workFlow2},
      {path: 'processDialog', name: 'processDialog', component: processDialog},
      {path: 'processDdesign3', name: 'processDdesign3', component: processDdesign3},
      {path: 'coverTask', name: 'coverTask', component: coverTask, meta: {keepAlive: true}},
      {path: 'approvelDetails', name: 'approvelDetails', component: approvelDetails},
      {path: 'initiateTransactions', name: 'initiateTransactions', component: initiateTransactions, meta: {keepAlive: true}},
      {path: 'userApplyStart', name: 'userApplyStart', component: userApplyStart},
      {path: 'processActiveAndHang', name: 'processActiveAndHang', component: processActiveAndHang},
      {path: 'finishedTask', name: 'finishedTask', component: finishedTask,  meta: {keepAlive: true}},
      {path: 'personalInitiatedTask', name: 'personalInitiatedTask', component: personalInitiatedTask, meta: {keepAlive: true}},
      {path: 'countTaskApply', name: 'countTaskApply', component: countTaskApply},
      {path: 'drawerAssembly', name: 'drawerAssembly', component: drawerAssembly}
    ]
  }
];

const router = new Router({
  // 滚动条
  // mode: 'history', // 需要框架支持history模式
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  routes: constantRouterMap
})
//  before
routerBefore(router, constantRouterMap);

export default router;
//  constantRouterMap
export const routes = constantRouterMap;
