From ebf22a15d327e45b7c1a93ec7f5616bdad10cd71 Mon Sep 17 00:00:00 2001 From: Poised_flw Date: Sun, 24 Oct 2021 23:45:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BD=E9=87=8F=E6=8A=BD=E7=A6=BBbus?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tis_app_template_kt/src/tis/bus.js | 38 ++++++++++++++++++++++-- src/tis_app_template_kt/src/tis/index.js | 32 +++----------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/tis_app_template_kt/src/tis/bus.js b/src/tis_app_template_kt/src/tis/bus.js index e04baa1..a07b300 100644 --- a/src/tis_app_template_kt/src/tis/bus.js +++ b/src/tis_app_template_kt/src/tis/bus.js @@ -1,6 +1,9 @@ import Vue from "vue"; +import axios from 'axios' import {registerApps} from './scriptsLoader/index' +// temp +let curBaseUrl = '' // 挂载vue的示例 let vueInstance = null // 数据机制,考虑vuex来实现 @@ -28,9 +31,10 @@ const bus = new Vue({ // 传递当前所处组件的上下文环境 menuStatusUpdate(){ const onActives = this.getTemplateLayouts().filter(l => !l.lazy).map(c=>c.component.name || c.component); - console.log('============>', vueInstance.appId) + const appId = '' + console.log('============>', appId) // TODO 这里通过event-bus来实现吧,Vue实例获取不到 - this.$emit('TIS_TEMPLATE_MENU_ACTIVE', {appId: vueInstance.appId, onActives: onActives,system:true}) + this.$emit('TIS_TEMPLATE_MENU_ACTIVE', {appId, onActives: onActives,system:true}) }, async loadComponent(component) { @@ -184,6 +188,36 @@ const bus = new Vue({ getActivesByType(type) { return this.actives.filter(a => a.type === type); }, + + // 初始化配置信息 + async initData(props) { + const dev = process.env.NODE_ENV === 'development'; + curBaseUrl = props.tis ? props.tis.entry : baseUrl; + const esData = await axios.get(`${curBaseUrl}/esplug.json`).catch(err => console.error(err)); + const asserts = await axios.get(`${curBaseUrl}/tisplatform.json`).catch(err => console.error(err)); + try { + //运行模式才取用框架返回的数据 + if (props.tis && !dev) { + console.log('框架传入的components:',props.tis.components) + this.components = props.tis.components ? [...props.tis.components,...esData.data.components] : esData.data.components; + this.asserts = Object.keys(props.tis.asserts).length !== 0 ? props.tis.asserts : asserts.data; + this.widgets = props.tis.widgets ? props.tis.widgets : esData.data.widgets; + } else { + this.components = esData.data.components + this.asserts = asserts.data; + this.widgets = esData.data.widgets; + } + //避免不填此属性,默认懒加载 + this.components = this.components.map(c => { + if (!Object.prototype.hasOwnProperty.call(c, "lazy") && c.type !== "background") { + c.lazy = true + } + return c; + }) + } catch (e) { + console.error(e) + } + }, } }); diff --git a/src/tis_app_template_kt/src/tis/index.js b/src/tis_app_template_kt/src/tis/index.js index 17ef2f2..0cf0a81 100644 --- a/src/tis_app_template_kt/src/tis/index.js +++ b/src/tis_app_template_kt/src/tis/index.js @@ -42,7 +42,7 @@ export function setup(App, options = {}) { // registerApps(_options.components) // 独立运行时 if (!window.__POWERED_BY_QIANKUN__) { - Vue.prototype.$tis = tis; + Vue.prototype.$tis = bus; // console.log('----------','独立运行') mount(); } @@ -95,31 +95,7 @@ export async function mount(props = {}) { // console.log('框架传来的参数', props.tis.components,props.tis.asserts) //取得esplug // console.log('当前运行环境',dev,'baseURL',props.tis.entry); - curBaseUrl = props.tis ? props.tis.entry : baseUrl; - const esData = await axios.get(`${curBaseUrl}/esplug.json`).catch(err => console.error(err)); - const asserts = await axios.get(`${curBaseUrl}/tisplatform.json`).catch(err => console.error(err)); - try { - //运行模式才取用框架返回的数据 - if (props.tis && !dev) { - console.log('框架传入的components:',props.tis.components) - bus.components = props.tis.components ? [...props.tis.components,...esData.data.components] : esData.data.components; - bus.asserts = Object.keys(props.tis.asserts).length !== 0 ? props.tis.asserts : asserts.data; - bus.widgets = props.tis.widgets ? props.tis.widgets : esData.data.widgets; - } else { - bus.components = esData.data.components - bus.asserts = asserts.data; - bus.widgets = esData.data.widgets; - } - //避免不填此属性,默认懒加载 - bus.components = bus.components.map(c => { - if (!Object.prototype.hasOwnProperty.call(c, "lazy") && c.type !== "background") { - c.lazy = true - } - return c; - }) - } catch (e) { - console.error(e) - } + await bus.initData(props) console.log('app frame', bus.components, bus.asserts); //一些内部配置的component需要加入layouts bus.initLayouts(bus.components); @@ -143,7 +119,7 @@ export async function mount(props = {}) { registerAppAsync: function (source) { return source }, - tis: props.tis || tis, //新框架核心对象, + tis: props.tis || bus, //新框架核心对象, flag: "", ShareMap: window.esapp ? window.esapp.ShareMap : {}, }); @@ -215,4 +191,4 @@ function swithTheme(param) { } -export default tis; +export default bus;