初始化
This commit is contained in:
71
examples/router/autoRoutes.js
Normal file
71
examples/router/autoRoutes.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import store from "../store";
|
||||
|
||||
export default {
|
||||
routes: () => store.state.apps.map(e => {
|
||||
return {
|
||||
...e,
|
||||
component: () => import(`../views/apps/${e.entry}`)
|
||||
}
|
||||
}),
|
||||
init() {
|
||||
//约束正则式
|
||||
store.commit("cleanApps")
|
||||
// 自动化本工程应用
|
||||
this.loadApps()
|
||||
},
|
||||
loadApps() {
|
||||
//新App的自动化格式
|
||||
let files = require.context('../../packages', true, /\.(\/.+)\/App[^\/]+\.vue$/)
|
||||
files.keys().map(path => {
|
||||
if (files(path).default) {
|
||||
let {name, label} = files(path).default,
|
||||
addApp = {
|
||||
name, label: label || name,
|
||||
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
|
||||
entry: 'appEntry'
|
||||
}
|
||||
//命名规范入口文件必须以App开头
|
||||
store.commit("addApp", addApp)
|
||||
}
|
||||
})
|
||||
let cores = require.context('../../core', true, /\.(\/.+)\/App[^\/]+\.vue$/)
|
||||
cores.keys().map(path => {
|
||||
if (cores(path).default) {
|
||||
let {name, label} = cores(path).default,
|
||||
addApp = {
|
||||
name, label: label || name,
|
||||
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
|
||||
entry: 'appEntry'
|
||||
}
|
||||
//命名规范入口文件必须以App开头
|
||||
store.commit("addApp", addApp)
|
||||
}
|
||||
})
|
||||
let oms = require.context('../../oms', true, /\.(\/.+)\/App[^\/]+\.vue$/)
|
||||
oms.keys().map(path => {
|
||||
if (oms(path).default) {
|
||||
let {name, label} = oms(path).default,
|
||||
addApp = {
|
||||
name, label: label || name,
|
||||
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
|
||||
entry: 'appEntry'
|
||||
}
|
||||
//命名规范入口文件必须以App开头
|
||||
store.commit("addApp", addApp)
|
||||
}
|
||||
})
|
||||
let project = require.context('../../project', true, /\.(\/.+)\/App[^\/]+\.vue$/)
|
||||
project.keys().map(path => {
|
||||
if (project(path).default) {
|
||||
let {name, label} = project(path).default,
|
||||
addApp = {
|
||||
name, label: label || name,
|
||||
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
|
||||
entry: 'appEntry'
|
||||
}
|
||||
//命名规范入口文件必须以App开头
|
||||
store.commit("addApp", addApp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user