46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /**
 | ||
|  * 系统业务模块
 | ||
|  * @param Vue 外部接入Vue
 | ||
|  * @param params showList:打印加载的应用;apps:加载的应用文件名数组
 | ||
|  */
 | ||
| 
 | ||
| const install = function (Vue, params) {
 | ||
|   if (install.installed) return Promise.resolve()
 | ||
|   else {
 | ||
|     // 遍历工作控件内的应用
 | ||
|     let apps = []
 | ||
|     let contexts = require.context('.', true, /\.(\/.+)\/App[^\/]+\.vue$/)
 | ||
|     if (contexts) {
 | ||
|       contexts.keys().map(e => {
 | ||
|         if (contexts(e).default) {
 | ||
|           if (params?.apps) {
 | ||
|             if (params?.apps.includes(contexts(e).default.name)) {
 | ||
|               apps.push(contexts(e).default)
 | ||
|               Vue.component(contexts(e).default.name, contexts(e).default)
 | ||
|             }
 | ||
|           } else {
 | ||
|             apps.push(contexts(e).default)
 | ||
|             Vue.component(contexts(e).default.name, contexts(e).default)
 | ||
|           }
 | ||
|         }
 | ||
|       })
 | ||
|       // apps.map(e=>{
 | ||
|       //   console.log(e.name,e.label)
 | ||
|       // })
 | ||
|       !!params?.showList && console.log(apps.map(e => e.name))
 | ||
|     }
 | ||
|     return Promise.resolve(apps)
 | ||
|   }
 | ||
| 
 | ||
| }
 | ||
| 
 | ||
| // 判断是否是直接引入文件
 | ||
| if (typeof window !== 'undefined' && window.Vue) {
 | ||
|   install(window.Vue)
 | ||
| }
 | ||
| 
 | ||
| export default {
 | ||
|   // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
 | ||
|   install
 | ||
| }
 |