@xingtukeji/micro 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/index.js +191 -177
- package/dist/types/api.d.ts +1 -1
- package/dist/types/child.d.ts +1 -1
- package/dist/types/parent.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,3 +48,8 @@ microInit({
|
|
|
48
48
|
```javascript
|
|
49
49
|
http://192.168.100.127:8000/console/?__XT_MICRO_microtest2=http://localhost:5173/?test=123#/page2#/micro/microtest2
|
|
50
50
|
```
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
window.__XT_MICRO_VERSION; //获取微前端框架版本
|
|
54
|
+
window.__XT_MICRO_APP; //获取微应用信息,包括主应用的 location 信息
|
|
55
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document!="undefined"){var e=document.createElement("style");e.appendChild(document.createTextNode('.xt-micro{width:100%;height:100%;overflow:hidden;background-color:transparent}.xt-micro:before{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;z-index:-1}.micro-iframe{width:100%;height:100%;border:none;margin:0;padding:0}.micro-iframe:after{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;background:#fff}')),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
2
|
-
var
|
|
2
|
+
var T = Object.defineProperty, v = Object.defineProperties;
|
|
3
3
|
var b = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
4
|
+
var O = Object.getOwnPropertySymbols;
|
|
5
|
+
var x = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var g = (e, t, n) => t in e ? T(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
|
|
7
7
|
for (var n in t || (t = {}))
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
for (var n of
|
|
11
|
-
|
|
8
|
+
x.call(t, n) && g(e, n, t[n]);
|
|
9
|
+
if (O)
|
|
10
|
+
for (var n of O(t))
|
|
11
|
+
$.call(t, n) && g(e, n, t[n]);
|
|
12
12
|
return e;
|
|
13
|
-
},
|
|
14
|
-
var m = (e, t, n) => (
|
|
15
|
-
var
|
|
16
|
-
var a = (
|
|
13
|
+
}, w = (e, t) => v(e, b(t));
|
|
14
|
+
var m = (e, t, n) => (g(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
+
var u = (e, t, n) => new Promise((o, r) => {
|
|
16
|
+
var a = (i) => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
19
|
-
} catch (
|
|
20
|
-
|
|
18
|
+
l(n.next(i));
|
|
19
|
+
} catch (p) {
|
|
20
|
+
r(p);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
22
|
+
}, c = (i) => {
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
} catch (
|
|
26
|
-
|
|
24
|
+
l(n.throw(i));
|
|
25
|
+
} catch (p) {
|
|
26
|
+
r(p);
|
|
27
27
|
}
|
|
28
|
-
},
|
|
29
|
-
|
|
28
|
+
}, l = (i) => i.done ? o(i.value) : Promise.resolve(i.value).then(a, c);
|
|
29
|
+
l((n = n.apply(e, t)).next());
|
|
30
30
|
});
|
|
31
|
-
import { ref as
|
|
32
|
-
const
|
|
31
|
+
import { ref as E, defineComponent as X, watch as k, onMounted as H, onUnmounted as N, openBlock as j, createElementBlock as V, mergeProps as B } from "vue";
|
|
32
|
+
const s = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
35
35
|
IS_MICRO: "__XT_MICRO",
|
|
36
36
|
// 是否在微应用中
|
|
37
37
|
MICRO_NAME: "__XT_MICRO_NAME",
|
|
38
38
|
// 微应用名称
|
|
39
|
+
MICRO_TYPE: "__XT_MICRO_TYPE",
|
|
40
|
+
// 微应用类型 'parent' | 'child'
|
|
39
41
|
MICRO_TOKEN: "__XT_MICRO_TOKEN",
|
|
40
42
|
// 微应用token
|
|
41
43
|
MICRO_APP: "__XT_MICRO_APP",
|
|
@@ -46,47 +48,47 @@ const c = {
|
|
|
46
48
|
// 微应用在 url 参数中的前缀
|
|
47
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
48
50
|
// 微应用版本
|
|
49
|
-
},
|
|
50
|
-
function
|
|
51
|
+
}, h = "1.1.12";
|
|
52
|
+
function f(e, t = window.location.href) {
|
|
51
53
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
52
|
-
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"),
|
|
53
|
-
return
|
|
54
|
+
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), o = n.exec(t);
|
|
55
|
+
return o ? o[2] ? decodeURIComponent(o[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
54
56
|
}
|
|
55
|
-
function
|
|
57
|
+
function C(e, t, n) {
|
|
56
58
|
try {
|
|
57
59
|
return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
|
|
58
|
-
} catch (
|
|
60
|
+
} catch (o) {
|
|
59
61
|
return e;
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
function
|
|
64
|
+
function D(e) {
|
|
63
65
|
const t = window.document.createElement("a");
|
|
64
66
|
return t.href = e, t.href = t.href, t;
|
|
65
67
|
}
|
|
66
68
|
function F(e) {
|
|
67
69
|
const t = e.search || "";
|
|
68
|
-
return [...new URLSearchParams(t).entries()].reduce((n,
|
|
70
|
+
return [...new URLSearchParams(t).entries()].reduce((n, o) => (n[o[0]] = o[1], n), {});
|
|
69
71
|
}
|
|
70
72
|
function K(e, t) {
|
|
71
73
|
let n = null;
|
|
72
|
-
return function(...
|
|
73
|
-
const
|
|
74
|
+
return function(...o) {
|
|
75
|
+
const r = this;
|
|
74
76
|
n && clearTimeout(n), n = setTimeout(() => {
|
|
75
|
-
e.apply(
|
|
77
|
+
e.apply(r, o);
|
|
76
78
|
}, t);
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
|
-
function
|
|
80
|
-
const [
|
|
81
|
-
return t =
|
|
81
|
+
function S(e, t, n) {
|
|
82
|
+
const [o, r] = e.split("#"), a = new URL(o), c = a.searchParams;
|
|
83
|
+
return t = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n), r && (a.hash = r), a.search = c.toString(), a.toString();
|
|
82
84
|
}
|
|
83
|
-
const
|
|
85
|
+
const M = (e) => u(void 0, null, function* () {
|
|
84
86
|
return new Promise((t) => {
|
|
85
87
|
window.addEventListener("message", (n) => {
|
|
86
|
-
n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !==
|
|
87
|
-
`子应用版本与主应用版本不一致,${e}子应用版本:${
|
|
88
|
+
console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== h && console.warn(
|
|
89
|
+
`子应用版本与主应用版本不一致,${e}子应用版本:${h},主应用版本:${n.data.data.mainMicroVersion}`
|
|
88
90
|
), t(n.data.data));
|
|
89
|
-
}), window.parent.postMessage(
|
|
91
|
+
}), console.debug("child ipcSyncAppInfo send message", e), window.parent.postMessage(
|
|
90
92
|
{
|
|
91
93
|
cmd: "$xt/micro/info",
|
|
92
94
|
data: e
|
|
@@ -94,71 +96,71 @@ const S = (e) => g(void 0, null, function* () {
|
|
|
94
96
|
"*"
|
|
95
97
|
);
|
|
96
98
|
});
|
|
97
|
-
}),
|
|
99
|
+
}), ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
98
100
|
__proto__: null,
|
|
99
|
-
addOrReplaceUrlParam:
|
|
100
|
-
anchorElementGenerator:
|
|
101
|
+
addOrReplaceUrlParam: S,
|
|
102
|
+
anchorElementGenerator: D,
|
|
101
103
|
debounce: K,
|
|
102
|
-
getAbsolutePath:
|
|
104
|
+
getAbsolutePath: C,
|
|
103
105
|
getAnchorElementQueryMap: F,
|
|
104
|
-
getQueryParameter:
|
|
105
|
-
ipcSyncAppInfo:
|
|
106
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
107
|
-
Object.defineProperty(window,
|
|
106
|
+
getQueryParameter: f,
|
|
107
|
+
ipcSyncAppInfo: M
|
|
108
|
+
}, Symbol.toStringTag, { value: "Module" })), P = E(!1);
|
|
109
|
+
Object.defineProperty(window, s.IS_MICRO, {
|
|
108
110
|
get: function() {
|
|
109
|
-
return
|
|
111
|
+
return P.value;
|
|
110
112
|
},
|
|
111
113
|
set: function(e) {
|
|
112
|
-
|
|
114
|
+
P.value = e;
|
|
113
115
|
}
|
|
114
116
|
});
|
|
115
|
-
const
|
|
116
|
-
function
|
|
117
|
+
const I = (e) => `${s.DOM_ID_PREFIX}${e}`, A = (e, t = !1) => {
|
|
118
|
+
function n(i) {
|
|
117
119
|
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
118
120
|
}
|
|
119
|
-
const
|
|
121
|
+
const o = typeof e.params == "function" ? e.params() : n(e.params) ? e.params : {}, r = typeof e.token == "function" ? e.token() : n(e.token) ? e.token : "", a = new URL(
|
|
120
122
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
121
|
-
),
|
|
122
|
-
if (
|
|
123
|
-
const i =
|
|
123
|
+
), c = f(s.URL_PARAM_PREFIX + e.name);
|
|
124
|
+
if (!t && c) {
|
|
125
|
+
const i = C(c, e.url, !0);
|
|
124
126
|
if (i) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}),
|
|
127
|
+
const p = new URL(i);
|
|
128
|
+
p.searchParams.forEach((U, L) => {
|
|
129
|
+
a.searchParams.set(L, U);
|
|
130
|
+
}), a.hash = p.hash;
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
|
-
if (
|
|
132
|
-
for (let i of Object.keys(
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
return
|
|
133
|
+
if (a.searchParams.set(s.IS_MICRO, !0 + ""), a.searchParams.set(s.MICRO_NAME, e.name), r && a.searchParams.set(s.MICRO_TOKEN, r), o)
|
|
134
|
+
for (let i of Object.keys(o))
|
|
135
|
+
a.searchParams.set(i, o[i]);
|
|
136
|
+
const l = new URL(window.location.href);
|
|
137
|
+
return l.searchParams.delete(e.name), window.history.replaceState({}, "", l.href), a.href;
|
|
136
138
|
}, W = () => {
|
|
137
139
|
const e = document.createElement("div");
|
|
138
140
|
return e.innerHTML = "应用加载中...", e.style.textAlign = "center", e.style.lineHeight = "100px", e.style.fontSize = "20px", e.style.color = "#999", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.right = "0", e.style.bottom = "0", e.style.zIndex = "999", e.style.background = "transparent", e.style["mix-blend-mode"] = "difference", e;
|
|
139
|
-
},
|
|
141
|
+
}, Y = (e) => {
|
|
140
142
|
e.style.opacity = "0", setTimeout(() => {
|
|
141
143
|
e.remove();
|
|
142
144
|
}, 500);
|
|
143
|
-
},
|
|
145
|
+
}, q = (e) => {
|
|
144
146
|
const t = document.createElement("iframe");
|
|
145
|
-
t.id =
|
|
146
|
-
const n =
|
|
147
|
-
t.src = n, t.style.width = "100%", t.style.height = "100%", t.style.border = "none", t.style.margin = "0", t.style.padding = "0", t.style.backgroundColor = "transparent", t.style["color-scheme"] = "unset", t.style.visibility = "hidden", t.addEventListener("load", (
|
|
147
|
+
t.id = I(e.app.name);
|
|
148
|
+
const n = A(e.app);
|
|
149
|
+
t.src = n, t.style.width = "100%", t.style.height = "100%", t.style.border = "none", t.style.margin = "0", t.style.padding = "0", t.style.backgroundColor = "transparent", t.style["color-scheme"] = "unset", t.style.visibility = "hidden", t.addEventListener("load", (r) => (t.style.visibility = "visible", e.onLoad.call(e, r))), t.addEventListener(
|
|
148
150
|
"error",
|
|
149
|
-
(
|
|
151
|
+
(r) => e.onError.call(e, r)
|
|
150
152
|
), t.addEventListener(
|
|
151
153
|
"unload",
|
|
152
|
-
(
|
|
154
|
+
(r) => e.onUnload.call(e, r)
|
|
153
155
|
);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")),
|
|
156
|
+
const o = new MutationObserver((r) => {
|
|
157
|
+
r.forEach((a) => {
|
|
158
|
+
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), o.disconnect());
|
|
157
159
|
});
|
|
158
160
|
});
|
|
159
|
-
return
|
|
161
|
+
return o.observe(e.panel, { childList: !0 }), t;
|
|
160
162
|
};
|
|
161
|
-
class
|
|
163
|
+
class z {
|
|
162
164
|
constructor(t) {
|
|
163
165
|
m(this, "app");
|
|
164
166
|
m(this, "dom");
|
|
@@ -168,21 +170,21 @@ class G {
|
|
|
168
170
|
return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
|
|
169
171
|
}
|
|
170
172
|
mount(t, n = !1) {
|
|
171
|
-
let
|
|
172
|
-
if (t ? (typeof t == "string" ?
|
|
173
|
-
this.panel =
|
|
174
|
-
let
|
|
175
|
-
|
|
173
|
+
let o;
|
|
174
|
+
if (t ? (typeof t == "string" ? o = document.querySelector(t) : o = t, o.innerHTML = "") : o = document.body, o) {
|
|
175
|
+
this.panel = o;
|
|
176
|
+
let r = document.getElementById(I(this.app.name));
|
|
177
|
+
r || (r = q(this), this.dom = r), n ? r.style.display = "none" : r.style.removeProperty("display");
|
|
176
178
|
const a = W();
|
|
177
179
|
this.loadingTimer = setTimeout(() => {
|
|
178
|
-
this.loading = a,
|
|
179
|
-
}, 1e3),
|
|
180
|
+
this.loading = a, o.appendChild(a);
|
|
181
|
+
}, 1e3), o.appendChild(r);
|
|
180
182
|
} else
|
|
181
183
|
throw new Error("el not found");
|
|
182
184
|
}
|
|
183
185
|
unmount() {
|
|
184
186
|
var n;
|
|
185
|
-
const t = document.getElementById(
|
|
187
|
+
const t = document.getElementById(I(this.app.name));
|
|
186
188
|
if (t)
|
|
187
189
|
this.app.preload ? (t.style.display = "none", document.body.appendChild(t)) : (n = this.panel) == null || n.removeChild(t);
|
|
188
190
|
else
|
|
@@ -202,15 +204,17 @@ class G {
|
|
|
202
204
|
preload() {
|
|
203
205
|
this.mount(void 0, !0);
|
|
204
206
|
}
|
|
205
|
-
reload() {
|
|
206
|
-
|
|
207
|
-
this.
|
|
207
|
+
reload(t = !1) {
|
|
208
|
+
let n = this.dom.src;
|
|
209
|
+
t && (n = A(this.app, !0), console.log("go home", n)), console.log("reload app", this.app, n);
|
|
210
|
+
const o = new URL(n);
|
|
211
|
+
o.searchParams.set("__t", Date.now().toString()), this.dom.src = o.toString();
|
|
208
212
|
}
|
|
209
213
|
changeOptions(t) {
|
|
210
214
|
this.app = d(d({}, this.app), t);
|
|
211
215
|
}
|
|
212
216
|
onLoad(t) {
|
|
213
|
-
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading &&
|
|
217
|
+
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && Y(this.loading), G(this), this.app.onLoad && this.app.onLoad(t, this);
|
|
214
218
|
}
|
|
215
219
|
onUnload(t) {
|
|
216
220
|
console.debug("app onUnload", this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
@@ -219,7 +223,7 @@ class G {
|
|
|
219
223
|
console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
|
|
220
224
|
}
|
|
221
225
|
}
|
|
222
|
-
const
|
|
226
|
+
const G = (e) => {
|
|
223
227
|
var t, n;
|
|
224
228
|
(n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
|
|
225
229
|
{
|
|
@@ -234,30 +238,32 @@ const Q = (e) => {
|
|
|
234
238
|
},
|
|
235
239
|
"*"
|
|
236
240
|
);
|
|
237
|
-
},
|
|
238
|
-
window.addEventListener("message", (e) => {
|
|
241
|
+
}, Q = () => {
|
|
242
|
+
window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
|
|
239
243
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
244
|
+
console.log("父页面接受子应用同步路由信息", e.data);
|
|
240
245
|
const t = [
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
s.IS_MICRO,
|
|
247
|
+
s.MICRO_NAME,
|
|
248
|
+
s.MICRO_TOKEN
|
|
244
249
|
], n = new URL(
|
|
245
250
|
window.decodeURIComponent(e.data.data.url),
|
|
246
251
|
e.origin
|
|
247
252
|
);
|
|
248
253
|
for (let a of t)
|
|
249
254
|
n.searchParams.delete(a);
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
255
|
+
const o = new URL(window.location.href);
|
|
256
|
+
o.searchParams.forEach((a, c) => {
|
|
257
|
+
c.startsWith(s.URL_PARAM_PREFIX) && o.searchParams.delete(c);
|
|
253
258
|
});
|
|
254
|
-
const
|
|
255
|
-
|
|
259
|
+
const r = S(
|
|
260
|
+
o.href,
|
|
256
261
|
e.data.data.name,
|
|
257
262
|
n.href
|
|
258
263
|
);
|
|
259
|
-
window.history.replaceState(null, "",
|
|
264
|
+
window.history.replaceState(null, "", r);
|
|
260
265
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
266
|
+
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
261
267
|
const t = y(e.data.data);
|
|
262
268
|
e.source.postMessage(
|
|
263
269
|
{
|
|
@@ -274,7 +280,7 @@ const Q = (e) => {
|
|
|
274
280
|
port: window.location.port,
|
|
275
281
|
protocol: window.location.protocol
|
|
276
282
|
},
|
|
277
|
-
mainMicroVersion:
|
|
283
|
+
mainMicroVersion: h,
|
|
278
284
|
name: t.name,
|
|
279
285
|
url: t.url,
|
|
280
286
|
params: t.params,
|
|
@@ -286,126 +292,134 @@ const Q = (e) => {
|
|
|
286
292
|
);
|
|
287
293
|
}
|
|
288
294
|
});
|
|
289
|
-
},
|
|
290
|
-
|
|
291
|
-
n
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
295
|
+
}, ce = (...t) => u(void 0, [...t], function* (e = {}) {
|
|
296
|
+
window[s.MICRO_TYPE] = "child";
|
|
297
|
+
const n = f(s.IS_MICRO), o = f(s.MICRO_NAME);
|
|
298
|
+
if (console.debug("child microInit", n, o), n && (window[s.IS_MICRO] = n === "true"), o && M(o).then((r) => {
|
|
299
|
+
window[s.MICRO_APP] = d({
|
|
300
|
+
microVersion: h
|
|
301
|
+
}, r);
|
|
302
|
+
}), window[s.IS_MICRO]) {
|
|
303
|
+
let r = function(c) {
|
|
304
|
+
var l = document.styleSheets[0];
|
|
305
|
+
if (!l) {
|
|
306
|
+
var i = document.createElement("style");
|
|
307
|
+
document.head.appendChild(i), l = i.sheet;
|
|
308
|
+
}
|
|
309
|
+
l.insertRule(c, l.cssRules.length);
|
|
310
|
+
};
|
|
311
|
+
window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
|
|
312
|
+
r(`${c} { display: none !important; }`);
|
|
313
|
+
}) : r(
|
|
314
|
+
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
315
|
+
)), yield J(o, window), window.addEventListener("message", (c) => u(void 0, null, function* () {
|
|
316
|
+
c.data.cmd === `$xt/micro/${o}` && R(o);
|
|
317
|
+
}));
|
|
318
|
+
const a = f(s.MICRO_TOKEN);
|
|
319
|
+
e.authHandler && a && (yield e.authHandler(a));
|
|
320
|
+
} else
|
|
321
|
+
console.warn("当前环境非微应用环境");
|
|
313
322
|
});
|
|
314
|
-
function J(e) {
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
const i =
|
|
323
|
+
function J(e, t) {
|
|
324
|
+
const n = t.history, o = n.pushState, r = n.replaceState;
|
|
325
|
+
n.pushState = function(a, c, l) {
|
|
326
|
+
const i = w(d(d({}, n.state || {}), a), {
|
|
318
327
|
// 添加新数据
|
|
319
328
|
_patchedByParent: !0
|
|
320
329
|
// 可选:标记这是被父窗口修改的状态
|
|
321
330
|
});
|
|
322
|
-
|
|
323
|
-
},
|
|
324
|
-
const i =
|
|
331
|
+
o.call(n, i, c, l), R(e);
|
|
332
|
+
}, n.replaceState = function(a, c, l) {
|
|
333
|
+
const i = w(d(d({}, n.state || {}), a), {
|
|
325
334
|
// 添加新数据
|
|
326
335
|
_patchedByParent: !0
|
|
327
336
|
// 可选:标记这是被父窗口修改的状态
|
|
328
337
|
});
|
|
329
|
-
r.call(
|
|
338
|
+
r.call(n, i, c, l), R(e);
|
|
330
339
|
};
|
|
331
340
|
}
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
341
|
+
function R(e) {
|
|
342
|
+
return u(this, null, function* () {
|
|
343
|
+
console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP] || (yield M(e).then((a) => {
|
|
344
|
+
window[s.MICRO_APP] = d({
|
|
345
|
+
microVersion: h
|
|
346
|
+
}, a);
|
|
347
|
+
}));
|
|
348
|
+
const { name: t, sync: n, mainLocation: o } = window[s.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
|
|
349
|
+
window.parent.postMessage(
|
|
350
|
+
{
|
|
351
|
+
cmd: "$xt/micro/sync",
|
|
352
|
+
data: {
|
|
353
|
+
name: t,
|
|
354
|
+
url: window.encodeURIComponent(r)
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
o.origin
|
|
358
|
+
);
|
|
359
|
+
});
|
|
346
360
|
}
|
|
347
|
-
let
|
|
361
|
+
let _ = {};
|
|
348
362
|
const Z = {
|
|
349
363
|
url: "",
|
|
350
364
|
name: "",
|
|
351
365
|
sync: !0
|
|
352
|
-
},
|
|
366
|
+
}, le = (e) => {
|
|
353
367
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
354
368
|
console.error("app url is required", e);
|
|
355
369
|
return;
|
|
356
370
|
}
|
|
357
371
|
const t = Object.assign({}, Z, e);
|
|
358
|
-
return
|
|
359
|
-
instance: new
|
|
360
|
-
}),
|
|
361
|
-
}, y = (e) =>
|
|
362
|
-
let
|
|
363
|
-
|
|
372
|
+
return _[e.name] = w(d({}, t), {
|
|
373
|
+
instance: new z(e)
|
|
374
|
+
}), _[e.name];
|
|
375
|
+
}, y = (e) => _[e], ee = (e, t) => _[e.name] = d(d({}, e), t), te = (e, t) => new Promise((n, o) => {
|
|
376
|
+
let r = y(e);
|
|
377
|
+
r ? (t && (r.instance.changeOptions(t), r = ee(r, t)), r.preload ? r.instance.preloadRender(r.el) : r.instance.mount(r.el), n(r)) : o("app not found");
|
|
364
378
|
}), ne = (e) => {
|
|
365
379
|
let t = y(e);
|
|
366
380
|
t && t.instance.unmount();
|
|
367
|
-
},
|
|
368
|
-
let
|
|
369
|
-
|
|
370
|
-
}, oe = /* @__PURE__ */
|
|
381
|
+
}, de = (e, t = !1) => {
|
|
382
|
+
let n = y(e);
|
|
383
|
+
n && n.instance.reload(t);
|
|
384
|
+
}, oe = /* @__PURE__ */ X({
|
|
371
385
|
__name: "XTMicroView",
|
|
372
386
|
props: {
|
|
373
387
|
appId: String
|
|
374
388
|
},
|
|
375
389
|
setup(e) {
|
|
376
|
-
const t = e, n =
|
|
390
|
+
const t = e, n = E(), o = () => {
|
|
377
391
|
t.appId && te(t.appId, {
|
|
378
392
|
el: n.value
|
|
379
|
-
}).then((
|
|
393
|
+
}).then((r) => {
|
|
380
394
|
console.debug("app mounted", t.appId);
|
|
381
395
|
});
|
|
382
396
|
};
|
|
383
|
-
return
|
|
384
|
-
|
|
385
|
-
}), k(() => {
|
|
386
|
-
r();
|
|
397
|
+
return k(() => t.appId, (r, a) => {
|
|
398
|
+
r !== a && a && ne(a), o();
|
|
387
399
|
}), H(() => {
|
|
400
|
+
o();
|
|
401
|
+
}), N(() => {
|
|
388
402
|
console.debug("app unmount", t.appId);
|
|
389
|
-
}), (
|
|
403
|
+
}), (r, a) => (j(), V("div", B({
|
|
390
404
|
ref_key: "refPanel",
|
|
391
405
|
ref: n
|
|
392
|
-
},
|
|
406
|
+
}, r.$attrs, { class: "xt-micro" }), null, 16));
|
|
393
407
|
}
|
|
394
408
|
});
|
|
395
|
-
window[
|
|
396
|
-
const
|
|
409
|
+
window[s.MICRO_VERSION] = h;
|
|
410
|
+
const pe = {
|
|
397
411
|
install: (e, t = {}) => {
|
|
398
|
-
e.component("xt-micro-view", oe),
|
|
412
|
+
e.component("xt-micro-view", oe), Q();
|
|
399
413
|
}
|
|
400
414
|
};
|
|
401
415
|
export {
|
|
402
416
|
oe as XTMicroView,
|
|
403
|
-
|
|
417
|
+
pe as default,
|
|
404
418
|
y as getApp,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
419
|
+
ce as microInit,
|
|
420
|
+
de as reloadApp,
|
|
421
|
+
le as setupApp,
|
|
408
422
|
te as startApp,
|
|
409
423
|
ne as stopApp,
|
|
410
|
-
|
|
424
|
+
ie as utils
|
|
411
425
|
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export declare const startApp: (name: string, options?: Partial<AppOption>) => P
|
|
|
18
18
|
* @param {string} name - 应用程序的名称
|
|
19
19
|
*/
|
|
20
20
|
export declare const stopApp: (name: string) => void;
|
|
21
|
-
export declare const reloadApp: (name: string) => void;
|
|
21
|
+
export declare const reloadApp: (name: string, isGoHome?: boolean) => void;
|
|
22
22
|
export { microInit };
|
package/dist/types/child.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const microInit: (options?: MicroInitOptions) => Promise<void>;
|
|
|
9
9
|
/**
|
|
10
10
|
* 同步子应用路由到主应用路由
|
|
11
11
|
*/
|
|
12
|
-
export declare function syncUrlToWindow(): void
|
|
12
|
+
export declare function syncUrlToWindow(microName: string): Promise<void>;
|
|
13
13
|
/**
|
|
14
14
|
* 同步主应用路由到子应用
|
|
15
15
|
*/
|
package/dist/types/parent.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class MicroApp {
|
|
|
19
19
|
* 预加载app,先放到body,待启动时,挪过来
|
|
20
20
|
*/
|
|
21
21
|
preload(): void;
|
|
22
|
-
reload(): void;
|
|
22
|
+
reload(isGoHome?: boolean): void;
|
|
23
23
|
changeOptions(options: Partial<AppOption>): void;
|
|
24
24
|
onLoad(_event: Event): void;
|
|
25
25
|
onUnload(_event: Event): void;
|