routes.js 4.76 KB
import layoutHeaderAside from '@/layout/header-aside'
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)

/**
 * 在主框架内显示(children 由后台返回资源点集合 从 resources 中动态过滤加载)
 */
const frameIn = [{
  path: '/',
  redirect: {
    name: 'index'
  },
  component: layoutHeaderAside,
  children: []
}]
/**
 * 首页
 * icon:element-ui
 */
export const home = {
  path: '/index',
  name: 'index',
  icon: 's-home',
  meta: {
    title: '总览',
    authId: '101',
    parentId: '0',
    cache: true
  },
  component: _import('index')
}
export const sys = [
  // 系统 前端日志
  // {
  //   path: '/log',
  //   name: 'log',
  //   meta: {
  //     title: '前端日志',
  //   },
  //   component: _import('system/log')
  // },
  // 刷新页面 必须保留
  {
    path: '/refresh',
    name: 'refresh',
    hidden: true,
    component: _import('system/function/refresh')
  },
  // 页面重定向 必须保留
  {
    path: 'redirect/:route*',
    name: 'redirect',
    hidden: true,
    component: _import('system/function/redirect')
  }
]

/**
 * 所有需动态过滤的资源点
 */
export const resources = {
  '102': {
    path: '/customer',
    icon: 'user-solid',
    name: 'customer',
    meta: {
      title: '客户管理',
      authId: '102',
      parentId: '0',
      cache: true
    },
    auth: [
      {
        authId: '10201',
        parentId: '102',
        label: '重置密码',
        handle: 'handleResetPassword',
        ruleObj: {
          attr: 'status',
          rule: { 0: '重置密码', 1: '重置密码', 2: '' }
        }
      }, {
        authId: '10202',
        parentId: '102',
        label: '启用',
        handle: 'handleUpOrDown',
        ruleObj: {
          attr: 'status',
          rule: { 0: '启用', 1: '停用', 2: '' }
        }
      }, {
        authId: '10203',
        parentId: '102',
        label: '审核通过',
        handle: 'handleExamine',
        ruleObj: {
          attr: 'status',
          rule: { 0: '', 1: '', 2: '审核通过' }
        }
      }
    ],
    component: _import('customer/customer')
  },
  '103': {
    path: '/device',
    icon: 'document-copy',
    name: 'device',
    meta: {
      title: '设备管理',
      authId: '103',
      parentId: '0',
      cache: true
    },
    component: _import('device/device')
  },
  '104': {
    path: '/user',
    icon: 'document-copy',
    name: 'user',
    meta: {
      title: '用户管理',
      authId: '104',
      parentId: '0',
      cache: true
    },
    component: _import('user/user')
  },
  '105': {
    path: '/apiManage',
    icon: 'document-copy',
    name: 'apiManage',
    meta: {
      title: 'API管理',
      authId: '105',
      parentId: '0',
      cache: true
    }
  },
  '10501': {
    path: '/apiList',
    icon: 'document-copy',
    name: 'apiList',
    meta: {
      title: 'API列表',
      authId: '10501',
      parentId: '105',
      cache: true
    },
    auth: [{
      authId: '1050101',
      parentId: '10501',
      label: '启用',
      handle: 'handleUpOrDown',
      ruleObj: {
        attr: 'status',
        rule: { 0: '启用', 1: '停用' }
      }
    }
    ],
    component: _import('apiManage/apiList')
  },
  '10502': {
    path: '/apiRecord',
    icon: 'document-copy',
    name: 'apiRecord',
    meta: {
      title: 'API调用记录',
      authId: '10502',
      parentId: '105',
      cache: true
    },
    component: _import('apiManage/apiRecord')
  },
  '106': {
    path: '/appMarket',
    icon: 'document-copy',
    name: 'appMarket',
    meta: {
      title: 'APP营销管理',
      authId: '106',
      parentId: '0',
      cache: true
    },
    auth: [{
      authId: '10601',
      parentId: '106',
      label: '新增',
      category: 'Button',
      type: 'primary',
      handle: 'handleAdd'
    }, {
      authId: '10602',
      parentId: '106',
      label: '编辑',
      handle: 'handleEdit'
    }, {
      authId: '10603',
      parentId: '106',
      label: '下架',
      handle: 'handleUpOrDown',
      ruleObj: {
        attr: 'status',
        rule: { 0: '上架', 1: '下架' }
      }
    }],
    component: _import('appMarket/appMarket')
  }
}

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

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

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

export const localRoutes = {
  ...resources,
  [home.meta.authId]: home
}

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