Files
dvcp_v2_webapp/packages/index.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-12-14 18:36:19 +08:00
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
/**
*
* @param Vue 外部接入Vue
* @param params showList:打印加载的应用;apps:加载的应用文件名数组
*/
import core from './core.import'
2022-06-28 09:15:10 +08:00
import dvui from '../project/dvui/entries'
2021-12-14 18:36:19 +08:00
const install = function (Vue, params) {
if (install.installed) return
// 遍历注册全局组件
let apps = []
2022-05-10 15:11:52 +08:00
let contexts = import.meta.glob('./**/App*.vue')
2021-12-14 18:36:19 +08:00
if (contexts) {
2022-05-10 15:11:52 +08:00
Object.keys(contexts).map(path => {
if (/App[A-Z]\w+\.vue/.test(path)) {
return contexts?.[path]()?.then(file => {
apps.push(file.default)
return Vue.component(file.default.name, file.default)
})
2021-12-14 18:36:19 +08:00
}
})
}
core?.map(app => {
apps.push(app.component)
Vue.component(app.name, app.component)
})
2022-06-28 09:15:10 +08:00
Vue.use(dvui)
2021-12-14 18:36:19 +08:00
return Promise.resolve(apps)
}
// 判断是否是直接引入文件
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue)
}
export default {
// 导出的对象必须具有 install才能被 Vue.use() 方法安装
install
}