
4 changed files with 9287 additions and 200 deletions
-
2src/tis_app_template_kt/package.json
-
190src/tis_app_template_kt/src/tis/bus.js
-
210src/tis_app_template_kt/src/tis/index.js
-
9085src/tis_app_template_kt/yarn.lock
@ -0,0 +1,190 @@ |
|||||
|
import Vue from "vue"; |
||||
|
import {registerApps} from './scriptsLoader/index' |
||||
|
|
||||
|
// 挂载vue的示例
|
||||
|
let vueInstance = null |
||||
|
// 数据机制,考虑vuex来实现
|
||||
|
const bus = new Vue({ |
||||
|
data: { |
||||
|
components: [], // components
|
||||
|
asserts: {}, |
||||
|
deviceType: "pc", |
||||
|
actives: [],//从菜单中激活的组件,
|
||||
|
layouts: [],//由自定义组件和第三方组件组成的布局组件集合
|
||||
|
widgets: [],//在应用模板内部需要加载的widgets
|
||||
|
}, |
||||
|
methods: { |
||||
|
setVueInstance(instance) { |
||||
|
vueInstance = instance |
||||
|
}, |
||||
|
|
||||
|
getDeviceType() { |
||||
|
return this.deviceType |
||||
|
}, |
||||
|
getTemplateLayouts(){ |
||||
|
return this.layouts; |
||||
|
}, |
||||
|
|
||||
|
// 传递当前所处组件的上下文环境
|
||||
|
menuStatusUpdate(){ |
||||
|
const onActives = this.getTemplateLayouts().filter(l => !l.lazy).map(c=>c.component.name || c.component); |
||||
|
console.log('============>', vueInstance.appId) |
||||
|
// TODO 这里通过event-bus来实现吧,Vue实例获取不到
|
||||
|
this.$emit('TIS_TEMPLATE_MENU_ACTIVE', {appId: vueInstance.appId, onActives: onActives,system:true}) |
||||
|
}, |
||||
|
async loadComponent(component) { |
||||
|
|
||||
|
const comp = this.components.find(arg => arg.component === component) || {}; |
||||
|
console.log('所有组件...', this.components,); |
||||
|
console.log('所有资源...', this.asserts); |
||||
|
console.log('当前加载组件...', component,); |
||||
|
console.log('匹配到的组件...', comp); |
||||
|
let assets = null; |
||||
|
let dependencies = []; |
||||
|
let isLib = false; |
||||
|
try { |
||||
|
const info = comp.segprefix; |
||||
|
assets = this.asserts[info]; |
||||
|
dependencies = comp.dependencies || []; |
||||
|
isLib = comp.lib; |
||||
|
} catch (e) { |
||||
|
console.error(e) |
||||
|
} |
||||
|
|
||||
|
//等待依赖下载完毕
|
||||
|
for (const refer of dependencies) { |
||||
|
let reference = this.asserts[refer] || null; |
||||
|
await registerApps(reference, curBaseUrl); |
||||
|
} |
||||
|
return new Promise((resolve, reject) => { |
||||
|
//加载组件资源
|
||||
|
console.log('开始加载组件资源', assets, curBaseUrl) |
||||
|
registerApps(assets, curBaseUrl).then(() => { |
||||
|
if (!isLib) {//正常组件的加载流程,isLib为true代表纯js lib库的加载
|
||||
|
let startTime = new Date().getTime(); |
||||
|
const looper = setInterval(() => { |
||||
|
|
||||
|
if (Vue.component(`${component}`)) { |
||||
|
resolve(comp) |
||||
|
clearInterval(looper); |
||||
|
} else { |
||||
|
let nowTime = new Date().getTime(); |
||||
|
if (nowTime - startTime > 2000) { |
||||
|
if (!assets) { |
||||
|
reject(`[loading error:${component}]:组件资源加载失败`) |
||||
|
} else { |
||||
|
reject(`[loading error:${component}]:loading component timed out`) |
||||
|
} |
||||
|
clearInterval(looper) |
||||
|
} |
||||
|
} |
||||
|
}, 300) |
||||
|
} else { |
||||
|
resolve(comp); |
||||
|
} |
||||
|
}).catch(err => { |
||||
|
if (!assets) { |
||||
|
reject(`[loading error:${component}]:组件资源加载失败`) |
||||
|
} else { |
||||
|
reject(`[loading error:${component}]:${err}`) |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
}) |
||||
|
|
||||
|
}, |
||||
|
//自定义函数,支持开发者按需增加接口
|
||||
|
|
||||
|
openComponentByMenu(components) { |
||||
|
//长度变化才会触发computed?
|
||||
|
this.components.filter(c => { |
||||
|
const component = c.component.name || c.component; |
||||
|
//激活组件命中此组件,更改状态
|
||||
|
const hit = components.includes(component); |
||||
|
if (hit) { |
||||
|
c.lazy = !hit; |
||||
|
return c; |
||||
|
} |
||||
|
}).forEach(c => { |
||||
|
if (!this.layouts.some(l => (l.component.name || l.component) === c.component)) { |
||||
|
this.layouts.push(c); |
||||
|
}else{ |
||||
|
//改变状态
|
||||
|
this.layouts.forEach(l => { |
||||
|
if((l.component.name || l.component) === c.component ){ |
||||
|
l.lazy = false; |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
if (!this.actives.some(l => l.component === c.component)) { |
||||
|
//弹窗暂定为同一时间只能打开一个
|
||||
|
if (c.type === 'dialog') { |
||||
|
this.actives = [c]; |
||||
|
} else { |
||||
|
this.actives.push(c); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
}); |
||||
|
//有 加入 无 删除?
|
||||
|
|
||||
|
console.log('layouts变化状态', this.layouts); |
||||
|
console.log('actives变化状态', this.actives); |
||||
|
this.menuStatusUpdate(); |
||||
|
}, |
||||
|
// 关闭组件
|
||||
|
closeComponent(components) { |
||||
|
//修改layout中的状态
|
||||
|
this.layouts.forEach(c => { |
||||
|
const component = c.component.name || c.component; |
||||
|
//激活组件命中此组件,更改状态
|
||||
|
const hit = components.includes(component); |
||||
|
if (hit) { |
||||
|
c.lazy = hit; |
||||
|
} |
||||
|
}) |
||||
|
//active中删除该组件
|
||||
|
console.log('待删除组件', components) |
||||
|
components.forEach(c => { |
||||
|
const index = this.actives.findIndex(b => b.component === c); |
||||
|
console.log('aaaaaa', index); |
||||
|
if (index >= 0) { |
||||
|
this.actives.splice(index, 1); |
||||
|
} |
||||
|
|
||||
|
}) |
||||
|
console.log('layouts变化状态', this.layouts) |
||||
|
console.log('actives变化状态', this.actives) |
||||
|
this.menuStatusUpdate(); |
||||
|
}, |
||||
|
//initLayouts //layouts 初始化,外部组件
|
||||
|
initLayouts(layouts = []) { |
||||
|
this.layouts.push(...layouts.filter(l => !l.lazy)) |
||||
|
}, |
||||
|
|
||||
|
//获取组件
|
||||
|
getWidgetsByType(type) { |
||||
|
//以type 或 position 命中widget,背景板默认lazy=false
|
||||
|
return this.layouts.filter(f => (f.type === type || f.position === type) && !f.lazy).map(f => { |
||||
|
//string类型,来自配置文件,需要下载资源才能使用,懒加载组件不加载但是需要加入到数组中、、
|
||||
|
|
||||
|
if (typeof f.component === "string") { |
||||
|
console.log('下载component资源', f.component); |
||||
|
return this.loadComponent(f.component); |
||||
|
} else { |
||||
|
return f |
||||
|
} |
||||
|
|
||||
|
}); |
||||
|
}, |
||||
|
|
||||
|
//获取含有当前类型的激活组件
|
||||
|
getActivesByType(type) { |
||||
|
return this.actives.filter(a => a.type === type); |
||||
|
}, |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
export default bus |
9085
src/tis_app_template_kt/yarn.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue