diff --git a/examples/router/autoRoutes.js b/examples/router/autoRoutes.js index b0af13c8..58930cfc 100644 --- a/examples/router/autoRoutes.js +++ b/examples/router/autoRoutes.js @@ -1,4 +1,5 @@ import store from "../store"; +import {waiting} from "../utils"; export default { routes: () => store.state.apps.map(e => { @@ -15,47 +16,63 @@ export default { }, loadApps() { //新App的自动化格式 - let files = require.context('../../packages', true, /\.(\/.+)\/App[A-Z][^\/]+\.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$/, '/packages$1'), - entry: 'appEntry', - module: files(path).default - } - //命名规范入口文件必须以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$/, '/core$1'), - entry: 'appEntry', - module: cores(path).default - } - //命名规范入口文件必须以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, + waiting.init({innerHTML: '应用加载中..'}) + let apps = require.context('../../', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, "lazy") + Promise.all(apps.keys().map(path => apps(path).then(file => { + if (file.default) { + let {name, label} = file.default, addApp = { name: [path.replace(/\.\/([^\/]+)\/.*/, '$1'), name].join("_"), label: label || name, - path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/project$1'), + path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/$1'), entry: 'appEntry', - module: project(path).default + module: file.default } + waiting.setContent(`加载${name}...`) //命名规范入口文件必须以App开头 - store.commit("addApp", addApp) - } - }) + return store.commit("addApp", addApp) + } else return 0 + }))).then(() => waiting.close()) + // let files = require.context('../../packages', true, /\.(\/.+)\/App[A-Z][^\/]+\.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$/, '/packages$1'), + // entry: 'appEntry', + // module: files(path).default + // } + // //命名规范入口文件必须以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$/, '/core$1'), + // entry: 'appEntry', + // module: cores(path).default + // } + // //命名规范入口文件必须以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: [path.replace(/\.\/([^\/]+)\/.*/, '$1'), name].join("_"), label: label || name, + // path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/project$1'), + // entry: 'appEntry', + // module: project(path).default + // } + // //命名规范入口文件必须以App开头 + // store.commit("addApp", addApp) + // } + // }) } } diff --git a/examples/utils/index.js b/examples/utils/index.js index 1e52eaeb..e47b46b5 100644 --- a/examples/utils/index.js +++ b/examples/utils/index.js @@ -58,22 +58,42 @@ const $decimalCalc = (...arr) => { //返回计算值 return intArr.reduce((t, a) => t + a) / precision } -/** - * @param { function } func - - * @param { number } wait 延迟执行毫秒数 - - * @param { boolean } immediate true 表立即执行,false 表非立即执行 - */ - - +export const waiting = { + init(ops, count) { + if (document.body) { + let div = document.createElement('div') + div.id = "ai-waiting" + div.className = "el-loading-mask is-fullscreen" + div.style.zIndex = '202204271710' + div.style.textAlign = 'center' + div.style.lineHeight = '100vh' + div.style.color = '#26f' + div.style.background = 'rgba(0,0,0,.8)' + document.body.appendChild(div) + } else if (count < 10) { + setTimeout(() => this.init(ops, ++count), 500) + } + }, + getDom() { + return document.querySelector('#ai-waiting') + }, + setContent(html) { + let div = this.getDom() + div.innerHTML = html + }, + close() { + let div = this.getDom() + div.parentElement.removeChild(div) + } +} export default { ...tools, addChildParty, $confirm, $permissions, - $decimalCalc + $decimalCalc, + $waiting: waiting } diff --git a/package.json b/package.json index 3ebb719c..f18a6edc 100644 --- a/package.json +++ b/package.json @@ -46,10 +46,12 @@ "@vue/cli-service": "^3.6.0", "axios": "^0.19.2", "babel-eslint": "^10.1.0", + "chalk": "^5.0.1", "core-js": "^2.6.11", "element-ui": "^2.13.2", "eslint": "^5.16.0", "eslint-plugin-vue": "^5.0.0", + "fs-extra": "^10.1.0", "image-webpack-loader": "^6.0.0", "inquirer": "^6.5.2", "node-sass": "npm:sass@^1.43.4",