Browse Source

kt下bus改为vuex用法

feature/vuex
yonghang 4 years ago
parent
commit
ff7d7cda10
  1. 2
      src/tis_app_template_kt/src/App.vue
  2. 2
      src/tis_app_template_kt/src/components/BottomView.vue
  3. 10
      src/tis_app_template_kt/src/components/Dialog/DialogPc.vue
  4. 11
      src/tis_app_template_kt/src/components/Dialog/Pc.vue
  5. 2
      src/tis_app_template_kt/src/components/EventBusExample.vue
  6. 8
      src/tis_app_template_kt/src/components/LeftView.vue
  7. 2
      src/tis_app_template_kt/src/components/RightCardComponent.vue
  8. 2
      src/tis_app_template_kt/src/components/RightView.vue
  9. 80
      src/tis_app_template_kt/src/components/controlMixins.js
  10. 50
      src/tis_app_template_kt/src/main.js
  11. 16
      src/tis_app_template_kt/src/pc.vue
  12. 153
      src/tis_app_template_kt/src/tis/index.js
  13. 2
      src/tis_app_template_kt/src/tis/layouts/BackContainer.vue
  14. 3
      src/tis_app_template_kt/src/tis/layouts/DialogContainer.vue
  15. 7
      src/tis_app_template_kt/src/tis/store/index.js
  16. 294
      src/tis_app_template_kt/src/tis/store/modules/tisbus.js

2
src/tis_app_template_kt/src/App.vue

@ -20,7 +20,7 @@
computed: { computed: {
deviceType() { deviceType() {
// return "mobile" // return "mobile"
return this.$tis.getDeviceType() || "pc";
return this.$store.getters['tisbus/getDeviceType'] || "pc";
} }
} }
}; };

2
src/tis_app_template_kt/src/components/BottomView.vue

@ -1,5 +1,5 @@
<template> <template>
<div class="app-cards" v-if="list.length > 0">
<div class="app-cards" v-if="list && list.length > 0">
<div class="side-menu"> <div class="side-menu">
<div class="inner"> <div class="inner">
<div <div

10
src/tis_app_template_kt/src/components/Dialog/DialogPc.vue

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<Pc v-for="(dialog, index) in list" :key="dialog.component" :dialog="dialog" />
<Pc v-for="dialog in list" :key="dialog.component" :dialog="dialog" ></Pc>
</div> </div>
</template> </template>
@ -16,11 +16,12 @@ export default {
asyncComputed: { asyncComputed: {
list: { list: {
async get() { async get() {
const list = this.$tis.getActivesByType('PopupWidget')
// const list = this.$tis.getActivesByType('PopupWidget')
const list = this.$store.getters['tisbus/getActivesByType']('PopupWidget')
for (let component of list) { for (let component of list) {
if (!component.lazy) continue; if (!component.lazy) continue;
if (typeof component.component === 'string') { if (typeof component.component === 'string') {
await this.$tis.loadComponent(component.component)
await this.$store.dispatch('tisbus/loadComponent', component.component)
} }
} }
@ -33,7 +34,6 @@ export default {
} }
} }
}, },
methods: {
}
methods: {}
} }
</script> </script>

11
src/tis_app_template_kt/src/components/Dialog/Pc.vue

@ -33,6 +33,8 @@ import VueDragResize from 'vue-drag-resize'
//import {dialogMixins} from './dialogMixins' //import {dialogMixins} from './dialogMixins'
export default { export default {
name: 'Pc',
components: { VueDragResize },
props: { props: {
dialog: { dialog: {
type: Object, type: Object,
@ -42,9 +44,6 @@ import VueDragResize from 'vue-drag-resize'
} }
}, },
//mixins: [dialogMixins], //mixins: [dialogMixins],
components: {
VueDragResize,
},
computed: { computed: {
parentW() { parentW() {
return window.outerWidth; return window.outerWidth;
@ -122,11 +121,11 @@ import VueDragResize from 'vue-drag-resize'
}, },
minisize() { minisize() {
console.log(this.dialog) console.log(this.dialog)
this.$tis.minimizeComponent(this.dialog.component)
this.$store.commit('tisbus/minimizeComponent', this.dialog.component)
}, },
onClose() { onClose() {
this.centerDialogVisible = false; this.centerDialogVisible = false;
this.$tis.closeComponent([this.dialog.component]);
this.$store.commit('tisbus/closeComponent', this.dialog.component)
}, },
toggle() { toggle() {
this.showSizeChoice = !this.showSizeChoice; this.showSizeChoice = !this.showSizeChoice;
@ -142,7 +141,7 @@ import VueDragResize from 'vue-drag-resize'
onShow() { onShow() {
}, },
activeComponent() { activeComponent() {
this.$tis.activeComponent(this.dialog.component)
this.$store.commit('tisbus/activeComponent', this.dialog.component)
} }
} }
} }

2
src/tis_app_template_kt/src/components/EventBusExample.vue

@ -23,6 +23,8 @@ export default {
computed: {}, computed: {},
created() { created() {
console.log('gggg',this.$tis) console.log('gggg',this.$tis)
// TODO
return
this._off = this.$tis.$on( this._off = this.$tis.$on(
"COUNT", // "COUNT", //
{ appIds: [this.$tis.appId] }, // { appIds: [this.$tis.appId] }, //

8
src/tis_app_template_kt/src/components/LeftView.vue

@ -1,5 +1,5 @@
<template> <template>
<div class="app-cards" v-if="list.length > 0">
<div class="app-cards" v-if="list && list.length > 0">
<div class="side-menu"> <div class="side-menu">
<div class="top-bar"> <div class="top-bar">
<transition name="slide-fade"> <transition name="slide-fade">
@ -56,11 +56,11 @@
actives(){ actives(){
//setTimeout //setTimeout
setTimeout(()=>{ setTimeout(()=>{
const count = this.$tis.getActivesByType(this.type).length;
const count = this.$store.getters['tisbus/getActivesByType'](this.type).length
if (this.activeCache > -1 && this.activeCache < count) { if (this.activeCache > -1 && this.activeCache < count) {
// //
let index = -1; let index = -1;
this.$tis.getActivesByType("left").forEach(a => {
this.$store.getters['tisbus/getActivesByType']('left').forEach(a => {
index = this.list.findIndex(item => { index = this.list.findIndex(item => {
return (item.component.name || item.component) === (a.component.name || a.component) return (item.component.name || item.component) === (a.component.name || a.component)
}); });
@ -71,7 +71,7 @@
}); });
} }
this.activeCache = this.$tis.getActivesByType(this.type).length;
this.activeCache = this.$store.getters['tisbus/getActivesByType'](this.type).length
},800) },800)
} }

2
src/tis_app_template_kt/src/components/RightCardComponent.vue

@ -46,7 +46,7 @@ export default {
return this.conf.type; return this.conf.type;
}, },
deviceType(){ deviceType(){
return this.$tis.getDeviceType()
return this.$store.getters['tisbus/getDeviceType']
} }
}, },
destroyed(){ destroyed(){

2
src/tis_app_template_kt/src/components/RightView.vue

@ -1,5 +1,5 @@
<template> <template>
<div class="app-cards" v-if="list.length > 0">
<div class="app-cards" v-if="list && list.length > 0">
<div class="content"> <div class="content">
<div class="item" v-for="(v, index) in list" :key="index" v-show="!v.lazy" ref="appCards"> <div class="item" v-for="(v, index) in list" :key="index" v-show="!v.lazy" ref="appCards">
<div v-show="active===index && showRightContent"> <div v-show="active===index && showRightContent">

80
src/tis_app_template_kt/src/components/controlMixins.js

@ -7,66 +7,71 @@ export const controlMixins = {
activeCache: -1, activeCache: -1,
show: true, show: true,
showRightContent: true, showRightContent: true,
type1: ''
};
type1: '',
}
}, },
asyncComputed: { asyncComputed: {
list: { list: {
lazy: false, lazy: false,
async get() { async get() {
let list = [];
const lefts = this.$tis.getWidgetsByType(this.type);
if (lefts) {
const lfs = lefts.filter(l => l && !l.lazy);
let list = []
// const lefts = this.$tis.getWidgetsByType(this.type)
return this.$store
.dispatch('tisbus/getWidgetsByType', this.type)
.then(lefts => {
if (lefts.length > 0) {
const lfs = lefts.filter(l => l && !l.lazy)
for (let i = 0; i < lfs.length; i++) { for (let i = 0; i < lfs.length; i++) {
let l = lfs[i];
let l = lfs[i]
if (l instanceof Promise) { if (l instanceof Promise) {
const r = await l.then(r => r)
list.push(r);
console.log('tetetetete4t')
l.then(s => list.push(rl))
} else { } else {
list.push(l);
list.push(l)
} }
} }
} }
console.log(this.type, list);
///记录激活数量 ///记录激活数量
return list;
return list
})
.catch(err => {
console.log(err)
})
}, },
watch: ['$tis.layouts'],
watch: ['$store.state.tisbus.layouts'],
default() { default() {
return [];
return []
}, },
}, },
}, },
computed: { computed: {
actives() { actives() {
return this.$tis.getActivesByType(this.type);
// return this.$tis.getActivesByType(this.type);
return this.$store.getters['tisbus/getActivesByType'](this.type)
}, },
allHiddened() { allHiddened() {
if (this.hidden.length === 0) return false;
if (this.hidden.length === 0) return false
return this.list.every((i, index) => { return this.list.every((i, index) => {
return this.hidden[index] === true;
});
return this.hidden[index] === true
})
}, },
}, },
methods: { methods: {
onClose(index) { onClose(index) {
console.log("删除", index);
console.log('删除', index)
// //最小化后 // //最小化后
this.list[index].lazy = true;
this.$tis.closeComponent([this.list[index].component]);
this.activeCache > 0 ? this.activeCache-- : "";
this.list[index].lazy = true
this.$tis.closeComponent([this.list[index].component])
this.activeCache > 0 ? this.activeCache-- : ''
}, },
onMinize(index) { onMinize(index) {
this.$set(this.hidden, index, true);
this.$set(this.hidden, index, true)
if (this.active === index) { if (this.active === index) {
this.active = -1;
this.active = -1
for (let i = index + 1; i < this.list.length; i++) { for (let i = index + 1; i < this.list.length; i++) {
if (!this.hidden[i]) { if (!this.hidden[i]) {
this.active = i;
return;
this.active = i
return
} }
} }
} }
@ -79,8 +84,8 @@ export const controlMixins = {
this.showRightContent = true this.showRightContent = true
this.type1 = 'ohter' this.type1 = 'ohter'
} }
this.active = index;
this.$set(this.hidden, index, false);
this.active = index
this.$set(this.hidden, index, false)
// const appCard = this.$refs.appCards[index]; // const appCard = this.$refs.appCards[index];
// // console.log('99999999',index,this.$refs.appCards,this.$refs.appCards[index]); // // console.log('99999999',index,this.$refs.appCards,this.$refs.appCards[index]);
// appCard.scrollIntoView({ // appCard.scrollIntoView({
@ -88,20 +93,19 @@ export const controlMixins = {
// block: "start", // block: "start",
// inline: "start", // inline: "start",
// }); // });
this.$forceUpdate();
this.$forceUpdate()
}, },
onHideAll() { onHideAll() {
this.list.forEach((item, index) => { this.list.forEach((item, index) => {
this.$set(this.hidden, index, true);
});
this.active = -1;
this.$set(this.hidden, index, true)
})
this.active = -1
}, },
onOpenAll() { onOpenAll() {
this.list.forEach((item, index) => { this.list.forEach((item, index) => {
this.$set(this.hidden, index, false);
});
this.active = 0;
this.$set(this.hidden, index, false)
})
this.active = 0
}, },
}, },
} }

50
src/tis_app_template_kt/src/main.js

@ -1,6 +1,7 @@
import tis, {setup} from "./tis";
import App from "./App.vue";
// import tis, { setup } from "./tis";
import {setup} from './tis'
import App from './App.vue'
import store from './tis/store'
import EventBusExample from './components/EventBusExample' import EventBusExample from './components/EventBusExample'
import GlobalStateExample from './components/GlobalStateExample.vue' import GlobalStateExample from './components/GlobalStateExample.vue'
import SlideExample from './components/SlideExample.vue' import SlideExample from './components/SlideExample.vue'
@ -9,33 +10,38 @@ import SlideExample from './components/SlideExample.vue'
// import {registerApps} from './scriptsLoader/index' // import {registerApps} from './scriptsLoader/index'
// 生命周期函数 // 生命周期函数
function bootstrap(params) { function bootstrap(params) {
console.log(`[SubApp: ${tis.appId}] boostrap`, params);
console.log(`[SubApp: ${tis.appId}] boostrap`, params)
} }
function mount(params) { function mount(params) {
// window.esapp = tis; // window.esapp = tis;
// console.log('app_demo.....',window.tisApp.Vue) // console.log('app_demo.....',window.tisApp.Vue)
// registerApps(); // registerApps();
console.log(`[SubApp: ${tis.appId}] mount`, params.tis);
// console.log(`[SubApp: ${tis.appId}] mount`, params.tis);
console.log(`[SubApp: mount`, params.tis)
} }
function show(params) { function show(params) {
console.log(`[Template App--->: ${tis.appId}] show`, params);
tis.menuStatusUpdate();
// console.log(`[Template App--->: ${tis.appId}] show`, params);
console.log(`[Template App--->: show`, params)
// tis.menuStatusUpdate();
store.dispatch('tisbus/menuStatusUpdate')
} }
function hide(params) { function hide(params) {
console.log(`[SubApp: ${tis.appId}] hide`, params);
// console.log(`[SubApp: ${tis.appId}] hide`, params);
console.log(`[SubApp: hide`, params)
} }
function unmount(params) { function unmount(params) {
console.log(`[SubApp: ${tis.appId}] unmount`, params);
// console.log(`[SubApp: ${tis.appId}] unmount`, params);
console.log(`[SubApp: unmount`, params)
} }
// 收到消息 // 收到消息
function onMessage(params, message) { function onMessage(params, message) {
console.log(`我是子应用[SubApp: ${tis.appId}] onMessage`, params, message);
// console.log(`我是子应用[SubApp: ${tis.appId}] onMessage`, params, message);
console.log(`我是子应用[SubApp: onMessage`, params, message)
} }
//初始化全局组件 //初始化全局组件
@ -45,9 +51,10 @@ function install() {
// 点击菜单 // 点击菜单
function onMenu(menu) { function onMenu(menu) {
const {component} = menu;
console.log("当前被点击菜单", menu, component)
tis.openComponentByMenu(component);
const {component} = menu
console.log('当前被点击菜单', menu, component)
// tis.openComponentByMenu(component);
store.dispatch('tisbus/openComponentByMenu', component)
} }
//api初始化 //api初始化
@ -55,25 +62,23 @@ function onMenu(menu) {
//layouts 初始化,内部组件 //layouts 初始化,内部组件
const layout = [ const layout = [
{ {
title: "右1",
title: '右1',
component: EventBusExample, component: EventBusExample,
lazy: false, lazy: false,
type: 'RightWidget', type: 'RightWidget',
}, },
{ {
title: "底1",
title: '底1',
component: GlobalStateExample, component: GlobalStateExample,
lazy: false, lazy: false,
type: 'BottomWidget', type: 'BottomWidget',
}, },
{ {
title: "底2",
title: '底2',
component: SlideExample, component: SlideExample,
lazy: false, lazy: false,
type: 'BottomWidget', type: 'BottomWidget',
}, },
] ]
// 启动 // 启动
@ -86,8 +91,9 @@ setup(App, {
show, show,
unmount, unmount,
onMessage, onMessage,
onMenu
});
onMenu,
})
// for qiankun framework // for qiankun framework
export * from "./tis";
// export * from "./tis";
export * from './tis'

16
src/tis_app_template_kt/src/pc.vue

@ -43,14 +43,14 @@
}, },
}, },
created() { created() {
this.off = this.$tis.$on(
"visibleAppCards",
{system: true},
(payload, source) => {
this.visibleAppCards = !!payload;
console.log(payload, source);
}
);
// this.off = this.$tis.$on(
// "visibleAppCards",
// {system: true},
// (payload, source) => {
// this.visibleAppCards = !!payload;
// console.log(payload, source);
// }
// );
}, },
beforeDestroy() { beforeDestroy() {
this.off(); this.off();

153
src/tis_app_template_kt/src/tis/index.js

@ -1,21 +1,21 @@
const devLib = process.env.VUE_APP_DEVLIB === "dev";
const devLib = process.env.VUE_APP_DEVLIB === 'dev'
console.log('当前版本======> for', process.env.VUE_APP_DEVLIB) console.log('当前版本======> for', process.env.VUE_APP_DEVLIB)
if (window.__POWERED_BY_QIANKUN__) { if (window.__POWERED_BY_QIANKUN__) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ + (devLib ? "/TIS_APP_TEMPLATE_KT/" : '');
__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ + (devLib ? '/TIS_APP_TEMPLATE_KT/' : '')
} }
import Vue from "vue";
import Vue from 'vue'
import store from './store' import store from './store'
import AsyncComputed from 'vue-async-computed' import AsyncComputed from 'vue-async-computed'
import axios from 'axios' import axios from 'axios'
import Vuex from 'vuex' import Vuex from 'vuex'
import EventBusExample from '../components/EventBusExample' import EventBusExample from '../components/EventBusExample'
import bus, { onSetup, onMount } from './bus'
// import bus, { onSetup, onMount } from './bus'
Vue.component('EventBusExample', EventBusExample) Vue.component('EventBusExample', EventBusExample)
Vue.config.productionTip = false;
Vue.use(AsyncComputed);
const dev = process.env.NODE_ENV === 'development';
Vue.config.productionTip = false
Vue.use(AsyncComputed)
const dev = process.env.NODE_ENV === 'development'
// const sdk = process.env.VUE_APP_SDK === 'sdk'; // const sdk = process.env.VUE_APP_SDK === 'sdk';
//作为sdk向组件提供能力时,确保加载的资源是当前组件域下的资源, //作为sdk向组件提供能力时,确保加载的资源是当前组件域下的资源,
// http://localhost:7001是一个写死的路径。。如何能正确的获取到组件的域 // http://localhost:7001是一个写死的路径。。如何能正确的获取到组件的域
@ -24,21 +24,22 @@ let _App,
_options = {}, _options = {},
// _layout,//由自定义组件和第三方组件组成的布局组件集合 // _layout,//由自定义组件和第三方组件组成的布局组件集合
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
_props = {};
_props = {}
export function setup(App, options = {}) { export function setup(App, options = {}) {
_App = App;
_options = options;
onSetup(options)
_App = App
_options = options
// onSetup(options)
store.commit('tisbus/onSetup', options)
if (typeof _options.install === "function") {
_options.install(Vue);
if (typeof _options.install === 'function') {
_options.install(Vue)
} }
// 独立运行时 // 独立运行时
if (!window.__POWERED_BY_QIANKUN__) { if (!window.__POWERED_BY_QIANKUN__) {
Vue.prototype.$tis = bus;
// Vue.prototype.$tis = bus
// console.log('----------','独立运行') // console.log('----------','独立运行')
mount();
mount()
} }
} }
@ -51,25 +52,24 @@ export async function bootstrap(props) {
// bus.initAppBusById(bus,props.tis.appId) // bus.initAppBusById(bus,props.tis.appId)
// props.tis.privateBus.asserts = bus. // props.tis.privateBus.asserts = bus.
//主题初始化 //主题初始化
const theme = localStorage.getItem("TIS_DESIGN_THEME") || 'default';
swithTheme(theme);
_props = props;
Vue.prototype.$tis = bus;
Vue.prototype.$EsDataMsg = function (params = {}) {
if (typeof params.callback === "function") {
bus.$on('message', {system: true}, async (payload) => {
params.callback(payload.message)
})
}
}
Vue.prototype.$EsOpenComponent = function () {
}
const theme = localStorage.getItem('TIS_DESIGN_THEME') || 'default'
swithTheme(theme)
_props = props
// Vue.prototype.$tis = bus
// TODO 暂无使用的地方,先注释掉
// Vue.prototype.$EsDataMsg = function(params = {}) {
// if (typeof params.callback === 'function') {
// bus.$on('message', {system: true}, async payload => {
// params.callback(payload.message)
// })
// }
// }
Vue.prototype.$EsOpenComponent = function() {}
props.onMessage.ref = _options.onMessage // 暴露onMessage回调给宿主 props.onMessage.ref = _options.onMessage // 暴露onMessage回调给宿主
props.onMenu && (props.onMenu.ref = _options.onMenu) // 暴露onMessage回调给宿主 props.onMenu && (props.onMenu.ref = _options.onMenu) // 暴露onMessage回调给宿主
if (typeof _options.bootstrap === "function") {
_options.bootstrap(props);
if (typeof _options.bootstrap === 'function') {
_options.bootstrap(props)
} }
;
} }
/** /**
@ -78,48 +78,51 @@ export async function bootstrap(props) {
export async function mount(props = {}) { export async function mount(props = {}) {
//兼容kt接口 //兼容kt接口
Vue.prototype.$ajaxGet = axios.get;
Vue.prototype.$ajaxPost = axios.post;
Vue.prototype.$ajaxPut = axios.put;
Vue.prototype.$ajaxGet = axios.get
Vue.prototype.$ajaxPost = axios.post
Vue.prototype.$ajaxPut = axios.put
Vue.prototype.$ajaxDelete = axios.delete Vue.prototype.$ajaxDelete = axios.delete
Vue.prototype.$axios = axios;
Vue.prototype.$axios = axios
// 等待bus执行mount生命周期 // 等待bus执行mount生命周期
await onMount(props)
await store.dispatch('tisbus/onMount', props)
const {container} = props;
document.documentElement.setAttribute('data-device', "pc");
window.esapp = Object.assign({}, {
const {container} = props
document.documentElement.setAttribute('data-device', 'pc')
window.esapp = Object.assign(
{},
{
Vue: Vue, Vue: Vue,
vue: _instance = new Vue({
vue: (_instance = new Vue({
store, store,
render: h => h(_App), render: h => h(_App),
}).$mount(container ? container.querySelector("#app") : "#app"),
}).$mount(container ? container.querySelector('#app') : '#app')),
add_path: function(route, name, obj) { add_path: function(route, name, obj) {
store.registerModule(name, obj);
store.registerModule(name, obj)
}, },
add_store: function(module, data) { add_store: function(module, data) {
store.commit(module, data);
store.commit(module, data)
}, },
Vuex: Vuex, Vuex: Vuex,
VueRouter: {}, VueRouter: {},
registerAppAsync: function(source) { registerAppAsync: function(source) {
return source return source
}, },
tis: props.tis || bus, //新框架核心对象,
flag: "",
// tis: props.tis || bus, //新框架核心对象,
tis: props.tis || new Vue(), //新框架核心对象,
flag: '',
ShareMap: window.esapp ? window.esapp.ShareMap : {}, ShareMap: window.esapp ? window.esapp.ShareMap : {},
});
}
)
console.log('应用 mounted,检视esapp对象', window.esapp) console.log('应用 mounted,检视esapp对象', window.esapp)
if (typeof _options.mount === "function") {
_options.mount(props);
if (typeof _options.mount === 'function') {
_options.mount(props)
} }
// console.log("---", window.esapp) // console.log("---", window.esapp)
bus.openComponentByMenu(['kt_zzgl_datapackaging'])
bus.openComponentByMenu(['GlobalStateExample'])
setTimeout(() => {
store.dispatch('tisbus/openComponentByMenu', ['kt_zzgl_datapackaging'])
store.dispatch('tisbus/openComponentByMenu', ['GlobalStateExample'])
}, 100)
} }
/** /**
@ -127,12 +130,12 @@ export async function mount(props = {}) {
*/ */
export async function unmount(props = {}) { export async function unmount(props = {}) {
if (_instance) { if (_instance) {
_instance.$destroy();
_instance.$el.innerHTML = "";
_instance = null;
_instance.$destroy()
_instance.$el.innerHTML = ''
_instance = null
} }
if (typeof _options.unmount === "function") {
_options.unmount(props);
if (typeof _options.unmount === 'function') {
_options.unmount(props)
} }
} }
@ -142,20 +145,20 @@ export async function unmount(props = {}) {
export async function update(props = {}) { export async function update(props = {}) {
if (props.show === true && typeof _options.show === 'function') { if (props.show === true && typeof _options.show === 'function') {
//如果当前运行应用和本应用相同,则不执行此函数(待开发。。) //如果当前运行应用和本应用相同,则不执行此函数(待开发。。)
swithTheme(props.theme);
_options.show(props.params);
swithTheme(props.theme)
_options.show(props.params)
} }
if (props.show === false && typeof _options.hide === 'function') { if (props.show === false && typeof _options.hide === 'function') {
_options.hide(props.params);
_options.hide(props.params)
} }
if (props.theme) { if (props.theme) {
swithTheme(props.theme) swithTheme(props.theme)
} }
if (typeof _options.update === "function") {
_options.update(props);
if (typeof _options.update === 'function') {
_options.update(props)
} }
} }
@ -163,21 +166,23 @@ export async function update(props = {}) {
* 主题切换功能 * 主题切换功能
*/ */
function swithTheme(param) { function swithTheme(param) {
console.log('<------当前主题-------->', param);
const container = document.querySelector('body');
const _themeStyle = document.getElementById("tis_app_theme_style");
if (_themeStyle) container.removeChild(_themeStyle);
console.log('<------当前主题-------->', param)
const container = document.querySelector('body')
const _themeStyle = document.getElementById('tis_app_theme_style')
if (_themeStyle) container.removeChild(_themeStyle)
const themeStyle = document.createElement('style') const themeStyle = document.createElement('style')
themeStyle.setAttribute('id', 'tis_app_theme_style');
themeStyle.setAttribute('id', 'tis_app_theme_style')
themeStyle.setAttribute('type', 'text/css') themeStyle.setAttribute('type', 'text/css')
const dir = param === "default" ? "chalk" : param;
const baseURL = dev ? "http://localhost:9902/tis-ui/" : "/TIS_LIB/tis-ui/";
const dir = param === 'default' ? 'chalk' : param
const baseURL = dev ? 'http://localhost:9902/tis-ui/' : '/TIS_LIB/tis-ui/'
// theme-chalk/index${dir}.css // theme-chalk/index${dir}.css
axios.get(`${baseURL}/theme-${dir}/index.css`).then(r => themeStyle.innerHTML = r.data).catch(r => console.log(r));
container.appendChild(themeStyle);
axios
.get(`${baseURL}/theme-${dir}/index.css`)
.then(r => (themeStyle.innerHTML = r.data))
.catch(r => console.log(r))
container.appendChild(themeStyle)
} }
export default bus;
// export default bus

2
src/tis_app_template_kt/src/tis/layouts/BackContainer.vue

@ -17,7 +17,7 @@
BackWidget: { BackWidget: {
lazy: true, lazy: true,
get() { get() {
const p = this.$tis.getWidgetsByType('BackWidget')[0];
const p = this.$store.dispatch('tisbus/getWidgetsByType', 'BackWidget')?.[0]
return p && p.then(r => r.component) return p && p.then(r => r.component)
} }
}, },

3
src/tis_app_template_kt/src/tis/layouts/DialogContainer.vue

@ -14,10 +14,9 @@
components:{DialogPc,DialogPad}, components:{DialogPc,DialogPad},
computed:{ computed:{
deviceType(){ deviceType(){
return this.$tis.getDeviceType();
return this.$store.getters['tisbus/getDeviceType']
} }
} }
} }
</script> </script>

7
src/tis_app_template_kt/src/tis/store/index.js

@ -6,14 +6,15 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger' import createLogger from 'vuex/dist/logger'
import tisbus from './modules/tisbus'
const debug = process.env.NODE_ENV !== 'production' const debug = process.env.NODE_ENV !== 'production'
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
modules: { modules: {
tisbus,
}, },
strict: debug,
plugin: debug ? [createLogger()] : []// debug add logger module
strict: false,
plugin: debug ? [createLogger()] : [], // debug add logger module
}) })

294
src/tis_app_template_kt/src/tis/store/modules/tisbus.js

@ -0,0 +1,294 @@
import Vue from 'vue'
import {registerApps} from '../.././scriptsLoader/index'
export default {
namespaced: true,
state: {
dialogZIndex: 400,
curBaseUrl: '',
baseUrl: process.env.NODE_ENV === 'development' ? process.env.BASE_URL : '',
components: [], // components
asserts: {}, // 所有资源
deviceType: 'pc',
actives: [], // 从菜单中激活的组件,
layouts: [], // 由自定义组件和第三方组件组成的布局组件集合
widgets: [], // 在应用模板内部需要加载的widgets
},
getters: {
// 获取设备型号
getDeviceType(state) {
return state.deviceType
},
// 获取布局组件集合
getTemplateLayouts(state) {
return state.layouts
},
// 计算弹窗的z-index
getNextDialogZIndex(state) {
let zIndex = 0
for (let item of state.actives) {
if (item.zIndex && item.zIndex > zIndex) {
zIndex = item.zIndex
}
}
return zIndex > 0 ? zIndex + 1 : state.dialogZIndex
},
// 获取含有当前类型的激活组件
getActivesByType(state) {
return type => {
console.log(
'获取含有当前类型的激活组件',
state.actives.filter(a => a.type === type)
)
return state.actives.filter(a => a.type === type)
}
// return type => state.actives.filter(a => a.type === type)
},
},
mutations: {
// 传递当前所处组件的上下文环境
menuStatusUpdate(state) {
const onActives = state.layouts
.filter(l => !l.lazy)
.map(c => ({
component: c.component.name || c.component,
status: c.status,
}))
const appId = ''
console.log('============>', appId, onActives)
// TODO 这里通过event-bus来实现吧,Vue实例获取不到
// window.esapp.tis.$emit('TIS_TEMPLATE_MENU_ACTIVE', {
// appId,
// onActives: onActives,
// system: true,
// })
},
// 初始化配置信息
async initData(state, props) {
const dev = process.env.NODE_ENV === 'development'
state.curBaseUrl = props.tis ? props.tis.entry : state.baseUrl
const esData = await Vue.prototype.$axios.get(`${state.curBaseUrl}/esplug.json`).catch(err => console.error(err))
console.log('初始化配置信息', esData)
const asserts = await Vue.prototype.$axios
.get(`${state.curBaseUrl}/tisplatform.json`)
.catch(err => console.error(err))
try {
// 运行模式才取用框架返回的数据
if (props.tis && !dev) {
console.log('框架传入的components:', props.tis.components)
state.components = props.tis.components
? [...props.tis.components, ...esData.data.components]
: esData.data.components
state.asserts = Object.keys(props.tis.asserts).length !== 0 ? props.tis.asserts : asserts.data
state.widgets = props.tis.widgets ? props.tis.widgets : esData.data.widgets
} else {
// state.actives = esData.data.components
state.components = esData.data.components
state.asserts = asserts.data
state.widgets = esData.data.widgets
}
// 避免不填此属性,默认懒加载
state.components = state.components.map(c => {
if (!Object.prototype.hasOwnProperty.call(c, 'lazy') && c.type !== 'background') {
c.lazy = true
}
return c
})
console.log('初始化配置信息components', state.components)
} catch (e) {
console.error(e)
}
},
// 激活窗口
activeComponent(state, component) {
const curComponent = state.actives.find(v => (v.component.name || v.component) === component)
const maxZIndex = Math.max.apply(
Math,
state.actives.map(function(o) {
return o.zIndex
})
)
const maxComponent = state.actives.find(v => v.zIndex === maxZIndex)
if (curComponent === maxComponent) return
maxComponent.zIndex = curComponent.zIndex
curComponent.zIndex = maxZIndex
state.actives = [...state.actives]
},
// 最小化激活的弹窗
minimizeComponent(state, component) {
state.actives.forEach(c => {
const comp = c.component.name || c.component
console.log(comp, component, c)
if (comp === component) {
c.status = 'minimize'
c.zIndex = 0
}
})
state.actives = [...state.actives]
console.log('after minimize', state.actives)
this.commit('menuStatusUpdate')
},
// 关闭组件
closeComponent(state, components) {
// 修改layout中的状态
state.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 = state.actives.findIndex(b => b.component === c)
console.log('aaaaaa', index)
if (index >= 0) {
state.actives.splice(index, 1)
}
})
console.log('layouts变化状态', state.layouts)
console.log('actives变化状态', state.actives)
this.commit('menuStatusUpdate')
},
// initLayouts state.layouts 初始化,外部组件
initLayouts(state, layouts = []) {
state.layouts.push(...layouts.filter(l => !l.lazy))
},
onSetup(state, options = {}) {
state.layouts = options.layout
},
},
actions: {
// 加载组件资源
async loadComponent({state}, component) {
const comp = state.components.find(arg => arg.component === component) || {}
console.log('所有组件...', state.components)
console.log('所有资源...', state.asserts)
console.log('当前加载组件...', component)
console.log('匹配到的组件...', comp)
let assets = null,
dependencies = [],
isLib = false
try {
const info = comp.segprefix
assets = state.asserts[info]
dependencies = comp.dependencies || []
isLib = comp.lib
} catch (e) {
console.error(e)
}
// 等待依赖下载完毕
for (const refer of dependencies) {
let reference = state.asserts[refer] || null
await registerApps(reference, state.curBaseUrl)
}
return new Promise((resolve, reject) => {
// 加载组件资源
console.log('开始加载组件资源', assets, state.curBaseUrl)
registerApps(assets, state.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({commit, state, getters}, components) {
// 长度变化才会触发computed?
state.components
.filter(c => {
const component = c.component.name || c.component
// 激活组件命中此组件,更改状态
const hit = components.includes(component)
if (hit) {
c.lazy = !hit
c.status = c.status === 'minimize' ? 'normal' : c.status
return c
}
})
.forEach(c => {
if (!state.layouts.some(l => (l.component.name || l.component) === c.component)) {
state.layouts.push(c)
} else {
// 改变状态
state.layouts.forEach(l => {
if ((l.component.name || l.component) === c.component) {
l.lazy = false
}
})
}
if (!state.actives.some(l => l.component === c.component)) {
// 弹窗暂定为同一时间只能打开一个 "PopupWidget" 非dialog
// 计算z-index
if (!c.zIndex) {
// c.zIndex = commit('getNextDialogZIndex')
c.zIndex = getters.getNextDialogZIndex
}
if (c.type === 'dialog') {
state.actives = [c]
} else {
state.actives.push(c)
}
}
})
// 有 加入 无 删除?
// 强制触发更新
state.actives = [...state.actives]
console.log('layouts变化状态', state.layouts)
console.log('actives变化状态', state.actives)
commit('menuStatusUpdate')
},
// 获取组件
getWidgetsByType({dispatch, state}, type) {
//以type 或 position 命中widget,背景板默认lazy=false
return state.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 dispatch('loadComponent', f.component)
} else {
return f
}
})
},
async onMount({commit, state}, props) {
await commit('initData', props)
commit('initLayouts', state.components)
commit('initLayouts', state.widgets)
},
},
}
Loading…
Cancel
Save