修复异常

This commit is contained in:
aixianling
2022-08-17 10:50:56 +08:00
parent d14371d7dc
commit 70e455b88d
3 changed files with 31 additions and 44 deletions

View File

@@ -14,47 +14,35 @@ export default {
}, },
loadApps() { loadApps() {
//新App的自动化格式 //新App的自动化格式
const apps = require.context('../../', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy') let apps = require.context('../../packages/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy'),
if (process.env.VUE_APP_DEV_MODE == 'fast') { projects = require.context('../../project/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy')
waiting.init({innerHTML: '应用加载中..'}) const promise = (mods, base) => Promise.all(mods.keys().map(path => mods(path).then(file => {
axios.post("/node/wechatapps/list", null, { if (file.default) {
params: {type: 'web', size: 999}, baseURL: "/ns" let {name, label} = file.default,
}).then(res => { addApp = {
if (res?.data) { name: path.replace(/\.\/?(vue)?/g, '')?.split("/").join("_"), label: label || name,
return res.data.records.map(({label, name, libPath: path, id}) => { path: `/${base}${path.replace(/\.(\/.+\/App.+)\.vue$/, '$1')}`,
waiting.setContent(`加载${name}...`) component: appEntry,
const module = () => apps(`.${path}.vue`) module: file.default
const addApp = {label, name: id, path, component: appEntry, module} }
router.addRoute(addApp) waiting.setContent(`加载${name}...`)
store.commit("addApp", addApp) router.addRoute(addApp)
}) //命名规范入口文件必须以App开头
} return store.commit("addApp", addApp)
}).finally(() => waiting.close()) } else return 0
} else { })))
waiting.init({innerHTML: '应用加载中..'}) waiting.init({innerHTML: '应用加载中..'})
Promise.all(apps.keys().map(path => apps(path).then(file => { Promise.all([
if (file.default) { promise(apps, "packages"),
let {name, label} = file.default, promise(projects, "project")
addApp = { ]).then(() => {
name: path.replace(/\.\/?(vue)?/g, '')?.split("/").join("_"), label: label || name, axios.post("/node/wechatapps/addOrUpdate", {
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'), type: "web",
component: appEntry, list: this.routes().map(({path: libPath, label, module: {name}, name: id}) => ({
module: file.default id, type: 'web', libPath, label, name
} }))
waiting.setContent(`加载${name}...`) }, {baseURL: "/ns"}).catch(() => 0)
router.addRoute(addApp) waiting.close()
//命名规范入口文件必须以App开头 })
return store.commit("addApp", addApp)
} else return 0
}))).then(() => {
axios.post("/node/wechatapps/addOrUpdate", {
type: "web",
list: this.routes().map(({path: libPath, label, module: {name}, name: id}) => ({
id, type: 'web', libPath, label, name
}))
}, {baseURL: "/ns"}).catch(() => 0)
waiting.close()
})
}
} }
} }

View File

@@ -6,7 +6,6 @@
"main": "lib/cw-webapps.common.js", "main": "lib/cw-webapps.common.js",
"scripts": { "scripts": {
"dev": "vue-cli-service serve", "dev": "vue-cli-service serve",
"fast": "npx cross-env VUE_APP_DEV_MODE=fast vue-cli-service serve",
"lib": "vue-cli-service build --no-clean --target lib --dest lib packages/index.js&&npm unpublish --force&&npm publish", "lib": "vue-cli-service build --no-clean --target lib --dest lib packages/index.js&&npm unpublish --force&&npm publish",
"lib:core": "vue-cli-service build --target lib --dest core/dist core/index.js --name dvcp-core&&npm unpublish dvcp-core --force&&npm publish core/", "lib:core": "vue-cli-service build --target lib --dest core/dist core/index.js --name dvcp-core&&npm unpublish dvcp-core --force&&npm publish core/",
"lib:project": "node project/build.js", "lib:project": "node project/build.js",

View File

@@ -17,7 +17,7 @@ module.exports = {
filename: 'index.html' filename: 'index.html'
} }
}, },
transpileDependencies: [/node_modules[/\\]dvcp-ui(.+)utils.js/, /node_modules[/\\]dvcp-ui(.+)modules.js/,/node_modules[/\\]dvcp-ui(.+)request.js/], transpileDependencies: [/node_modules[/\\]dvcp-ui[\\\/]lib[\\\/]js/],
chainWebpack: (config) => { chainWebpack: (config) => {
config.module config.module
.rule('js') .rule('js')