import layoutHeaderAside from '@/layout/header-aside'
import system from './modules/system'
import permission from './modules/permission'
import equipment from './modules/equipment'
import card from './modules/card'
import attendance from './modules/attendance'
import parking from './modules/parking'
import cost from './modules/cost'
import accessControl from './modules/accessControl'
import face from './modules/face'
import electric from "./modules/electric";
import Visitor from "./modules/Visitor";
import dormitory from "./modules/dormitory";
import water from "./modules/water";
// 由于懒加载页面太多的话会造成webpack热更新太慢，所以开发环境不使用懒加载，只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
const meta = { requiresAuth: true }

/**
 * 在主框架内显示
 */
const frameIn = [
  {
    path: '/',
    redirect: { name: 'index' },
    component: layoutHeaderAside,
    children: [
      // 首页
      {
        path: 'index',
        name: 'index',
        meta,
        component: () => import('@/views/system/index')
      },
      // 系统 前端日志
      {
        path: 'log',
        name: 'log',
        meta:{
					title: '前端日志',
					requiresAuth: true
				},
				component: () => import('@/views/system/log')
      },
      // 刷新页面 必须保留
      {
        path: 'refresh',
        name: 'refresh',
        hidden: true,
        component: {
          beforeRouteEnter (to, from, next) {
            next(vm => vm.$router.replace(from.fullPath))
          },
          render: h => h()
        }
      },
      // 页面重定向 必须保留
      {
        path: 'redirect/:route*',
        name: 'redirect',
        hidden: true,
        component: {
          beforeRouteEnter (to, from, next) {
            next(vm => vm.$router.replace(JSON.parse(from.params.route)))
          },
          render: h => h()
        }
      }
    ]
  },
	system,
	permission,
	equipment,
  card,
	attendance,
  parking,
	cost,
  accessControl,
	face,
    electric,
    Visitor,
  dormitory,
  water
]

/**
 * 在主框架之外显示
 */
const frameOut = [
  // 登录
  {
    path: '/login',
    name: 'login',
    component: _import('system/login')
  }
]

/**
 * 错误页面
 */
const errorPage = [
  {
    path: '*',
    name: '404',
    component: _import('system/error/404')
  }
]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

// 重新组织后导出
export default [
  ...frameIn,
  ...frameOut,
  ...errorPage
]
