Parcourir la source

主应用基础通讯封装

asd26269546 il y a 2 ans
Parent
commit
69880f86b6
2 fichiers modifiés avec 52 ajouts et 34 suppressions
  1. 17 8
      src/libs/micros.js
  2. 35 26
      src/main.js

+ 17 - 8
src/libs/micros.js

@@ -1,16 +1,25 @@
 import { initGlobalState, MicroAppStateActions } from 'qiankun';
 const state = {
-    token:null,
+	token: null,
+	theme: null,
 }
 const actions = initGlobalState(state)
 actions.onGlobalStateChange((state, prev) => {
-  // state: 变更后的状态; prev 变更前的状态
-  console.log(state, prev,'123123123');
+	// state: 变更后的状态; prev 变更前的状态
+	console.log(state, prev, '123123123');
 });
-const setToken = (({token})=>{
-    actions.setGlobalState()
+const setToken = ((token) => {
+	actions.setGlobalState({ ...state, token: token })
 })
-const setTheme = ((theme)=>{
-  
+const setTheme = ((theme) => {
+	actions.setGlobalState({ ...state, theme: theme })
 })
-export {actions}
+
+const getAll = () =>{
+	return state
+}
+export {
+	setToken,
+	setTheme,
+	getAll
+}

+ 35 - 26
src/main.js

@@ -19,36 +19,45 @@ Vue.config.productionTip = false
 
 
 new Vue({
-  router,
-  store,
-  render: h => h(App)
+	router,
+	store,
+	render: h => h(App)
 }).$mount("#app");
 
+import { getAll } from '@/libs/micros'
+console.log(getAll())
+
 registerMicroApps([
-  { 
-    name: 'app-vue-hash', 
-    entry: 'http://localhost:8081', 
-    container: '#appContainer', 
-    activeRule: '/main/app-vue-hash', 
-    props: { data : { store, router } }
-  },
-  { 
-    name: 'fjhxCloudVue', 
-    entry: 'http://localhost:1888', 
-    container: '#appContainer', 
-    activeRule: '/main/fjhxCloudVue', 
-    props: { data : { store, router } }
-  },
-  { 
-    name: 'canvas',
-    entry: 'http://localhost:8080', 
-    container: '#appContainer', 
-    activeRule: '/main/canvas',
-    props: { data : store }
-  },
+	{
+		name: 'app-vue-hash',
+		entry: 'http://localhost:8081',
+		container: '#appContainer',
+		activeRule: '/main/app-vue-hash',
+		props: { data: { store, router } }
+	},
+	{
+		name: 'fjhxCloudVue',
+		entry: 'http://localhost:1777',
+		container: '#appContainer',
+		activeRule: '/main/fjhxCloudVue',
+		props: { data: { store, router } }
+	},
+	{
+		name: 'iotPlatformRoom',
+		entry: 'http://localhost:1888',
+		container: '#appContainer',
+		activeRule: '/main/iotPlatformRoom',
+		props: { data: { store, router } }
+	},
+	{
+		name: 'canvas',
+		entry: 'http://localhost:8080',
+		container: '#appContainer',
+		activeRule: '/main/canvas',
+		props: { data: store }
+	},
 ]);
 
 start();
 
-import {actions} from '@/libs/micros'
-actions.setGlobalState({asd:21312312})
+