main.js 1.99 KB
import Vue from 'vue'
// import routes from './routes'
import asyncComponents from './asyncCompontents/index'
// const sharePool = (Vue.__share_pool__ = Vue.__share_pool__ || {})
// const routesPool = (sharePool.routes = sharePool.routes || {})
// // 挂载子项目的 route-list
// routesPool[process.env.VUE_APP_NAME] = routes
// const comPathMap = {}
// const serviceFiles = require.context(
//   './services/', // 在当前目录下查找
//   true, // 遍历子文件夹
//   /\.js$/ // 正则匹配 以 .js结尾的文件
// )

// serviceFiles.keys().forEach(path => {
//   const service = serviceFiles(path)
//   service.default.install()
// })
const sharePool = (Vue.__share_pool__ = Vue.__share_pool__ || {})
const store = (sharePool.store = sharePool.store || {})

function loadView(component) {
  return (resolve) => require([`@/views/${component}`], resolve)
}
function formatRoutes(routes) {
  const formatRoutesArr = []
  if (!routes) {
    return []
  }
  routes.forEach(el => {
    const router = {
      meta: {}
    }
    const {
      path,
      route,
      remark,
      serverName,
      name,
      isCached
    } = el
    router['component'] = loadView(path)
    if (name !== null) {
      router['name'] = name
    }
    router['meta']['title'] = remark
    router['meta']['serverName'] = serverName
    router['meta']['keepAlive'] = isCached
    router['path'] = route
    // router['meta']['noCache'] = !keep_alive
    formatRoutesArr.push(router)
  })
  return formatRoutesArr
}
function loadComponent(comName, type) {
  let c
  if (!type) {
    c = resolve => { require([`@/asyncCompontents${comName}`], resolve) }
  } else if (type === 'customComponent') {
    c = resolve => { require([`@/customComponent${comName}`], resolve) }
  }
  return c
}

require('./business-components/tabCom/index.js')
export default {
  name: 'dee-es',
  routes: formatRoutes(store.state.routes.routesObj[process.env.VUE_APP_NAME]),
  asyncComponents,
  loadComponent,
  beforeEach(from, to, next) {
    next()
  },
  init() {}
}