优化调整web端内存溢出的问题
This commit is contained in:
@@ -2,6 +2,8 @@ import store from "../store";
|
||||
import {waiting} from "../utils";
|
||||
import appEntry from "../views/appEntry";
|
||||
import router from "./router";
|
||||
import mods from "../modules"
|
||||
import Vue from "vue";
|
||||
|
||||
export default {
|
||||
routes: () => store.state.apps,
|
||||
@@ -9,32 +11,47 @@ export default {
|
||||
//约束正则式
|
||||
store.commit("cleanApps")
|
||||
// 自动化本工程应用
|
||||
this.loadApps()
|
||||
waiting.init({innerHTML: '应用加载中..'})
|
||||
this.esm = {
|
||||
packages: require.context('../../packages/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy'),
|
||||
project: require.context('../../project/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy')
|
||||
}
|
||||
const startTime = new Date().getTime()
|
||||
this.loadApps().finally(() => {
|
||||
console.log('模块加载用了%s秒', (new Date().getTime() - startTime) / 1000)
|
||||
waiting.close()
|
||||
})
|
||||
},
|
||||
loadMods() {
|
||||
return Promise.all(mods.apps.map(e => {
|
||||
Vue.component(e.name, this.esm[e.workspace](e.esm))
|
||||
const addApp = {...e, component: appEntry}
|
||||
waiting.setContent(`加载${e.name}...`)
|
||||
//命名规范入口文件必须以App开头
|
||||
return store.commit("addApp", addApp)
|
||||
}))
|
||||
},
|
||||
loadApps() {
|
||||
//新App的自动化格式
|
||||
let apps = require.context('../../packages/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy-once'),
|
||||
projects = require.context('../../project/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy-once')
|
||||
const promise = (mods, base) => Promise.all(mods.keys().map(path => mods(path).then(file => {
|
||||
if (file.default) {
|
||||
let {name, label} = file.default,
|
||||
addApp = {
|
||||
name: [base, path.replace(/\.\/?(vue)?/g, '')?.split("/")].flat().join("_"),
|
||||
label: label || name,
|
||||
path: `/${base}${path.replace(/\.(\/.+\/App.+)\.vue$/, '$1')}`,
|
||||
component: appEntry,
|
||||
module: file.default
|
||||
}
|
||||
const {name, label} = file.default
|
||||
const addApp = {
|
||||
name: [base, path.replace(/\.\/?(vue)?/g, '')?.split("/")].flat().join("_"),
|
||||
label: label || name,
|
||||
path: `/${base}${path.replace(/\.(\/.+\/App.+)\.vue$/, '$1')}`,
|
||||
component: appEntry,
|
||||
esm: file.default
|
||||
}
|
||||
waiting.setContent(`加载${name}...`)
|
||||
router.addRoute(addApp)
|
||||
//命名规范入口文件必须以App开头
|
||||
return store.commit("addApp", addApp)
|
||||
} else return 0
|
||||
})))
|
||||
waiting.init({innerHTML: '应用加载中..'})
|
||||
Promise.all([
|
||||
promise(apps, "packages"),
|
||||
promise(projects, "project")
|
||||
]).finally(() => waiting.close())
|
||||
}).catch(err => console.log(err))))
|
||||
return Promise.all([
|
||||
promise(this.esm.packages, "packages"),
|
||||
promise(this.esm.project, "project")
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ instance.interceptors.request.use(config => {
|
||||
config.baseURL = "/qxn"
|
||||
} else if (/\/xiushan/.test(location.pathname)) {
|
||||
config.baseURL = "/xsjr"
|
||||
} else if (/project\/oms/.test(location.pathname)) {
|
||||
config.baseURL = "/omsapi"
|
||||
// } else if (/project\/oms/.test(location.pathname)) {
|
||||
// config.baseURL = "/omsapi"
|
||||
} else if (/#url-/.test(location.hash)) {
|
||||
config.baseURL = location.hash.replace(/#url-/, '/')
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<script>
|
||||
|
||||
import {mapState} from "vuex";
|
||||
import Vue from "vue";
|
||||
|
||||
export default {
|
||||
name: "appEntry",
|
||||
@@ -15,8 +16,8 @@ export default {
|
||||
computed: {
|
||||
...mapState(['apps']),
|
||||
app() {
|
||||
let app = this.apps.find(e => e.name == this.$route.name)
|
||||
return app ? app.module : ""
|
||||
const app = this.apps.find(e => e.name == this.$route.name)
|
||||
return app.esm ?? ""
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
||||
Reference in New Issue
Block a user