@xingtukeji/micro 1.1.12 → 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/dist/index.js +181 -173
- 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/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
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
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
2
|
+
var T = Object.defineProperty, v = Object.defineProperties;
|
|
3
|
+
var b = Object.getOwnPropertyDescriptors;
|
|
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
|
-
}, c = (
|
|
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",
|
|
@@ -48,45 +48,45 @@ const i = {
|
|
|
48
48
|
// 微应用在 url 参数中的前缀
|
|
49
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
50
50
|
// 微应用版本
|
|
51
|
-
},
|
|
52
|
-
function
|
|
51
|
+
}, h = "1.1.12";
|
|
52
|
+
function f(e, t = window.location.href) {
|
|
53
53
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
54
|
-
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"),
|
|
55
|
-
return
|
|
54
|
+
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), o = n.exec(t);
|
|
55
|
+
return o ? o[2] ? decodeURIComponent(o[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function C(e, t, n) {
|
|
58
58
|
try {
|
|
59
59
|
return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
|
|
60
|
-
} catch (
|
|
60
|
+
} catch (o) {
|
|
61
61
|
return e;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function D(e) {
|
|
65
65
|
const t = window.document.createElement("a");
|
|
66
66
|
return t.href = e, t.href = t.href, t;
|
|
67
67
|
}
|
|
68
68
|
function F(e) {
|
|
69
69
|
const t = e.search || "";
|
|
70
|
-
return [...new URLSearchParams(t).entries()].reduce((n,
|
|
70
|
+
return [...new URLSearchParams(t).entries()].reduce((n, o) => (n[o[0]] = o[1], n), {});
|
|
71
71
|
}
|
|
72
72
|
function K(e, t) {
|
|
73
73
|
let n = null;
|
|
74
|
-
return function(...
|
|
75
|
-
const
|
|
74
|
+
return function(...o) {
|
|
75
|
+
const r = this;
|
|
76
76
|
n && clearTimeout(n), n = setTimeout(() => {
|
|
77
|
-
e.apply(
|
|
77
|
+
e.apply(r, o);
|
|
78
78
|
}, t);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
const [
|
|
83
|
-
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();
|
|
84
84
|
}
|
|
85
|
-
const
|
|
85
|
+
const M = (e) => u(void 0, null, function* () {
|
|
86
86
|
return new Promise((t) => {
|
|
87
87
|
window.addEventListener("message", (n) => {
|
|
88
|
-
console.debug("child ipcSyncAppInfo receive message", n.data), n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !==
|
|
89
|
-
`子应用版本与主应用版本不一致,${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}`
|
|
90
90
|
), t(n.data.data));
|
|
91
91
|
}), console.debug("child ipcSyncAppInfo send message", e), window.parent.postMessage(
|
|
92
92
|
{
|
|
@@ -96,69 +96,69 @@ const S = (e) => g(void 0, null, function* () {
|
|
|
96
96
|
"*"
|
|
97
97
|
);
|
|
98
98
|
});
|
|
99
|
-
}),
|
|
99
|
+
}), ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
100
100
|
__proto__: null,
|
|
101
|
-
addOrReplaceUrlParam:
|
|
102
|
-
anchorElementGenerator:
|
|
101
|
+
addOrReplaceUrlParam: S,
|
|
102
|
+
anchorElementGenerator: D,
|
|
103
103
|
debounce: K,
|
|
104
|
-
getAbsolutePath:
|
|
104
|
+
getAbsolutePath: C,
|
|
105
105
|
getAnchorElementQueryMap: F,
|
|
106
|
-
getQueryParameter:
|
|
107
|
-
ipcSyncAppInfo:
|
|
108
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
109
|
-
Object.defineProperty(window,
|
|
106
|
+
getQueryParameter: f,
|
|
107
|
+
ipcSyncAppInfo: M
|
|
108
|
+
}, Symbol.toStringTag, { value: "Module" })), P = E(!1);
|
|
109
|
+
Object.defineProperty(window, s.IS_MICRO, {
|
|
110
110
|
get: function() {
|
|
111
|
-
return
|
|
111
|
+
return P.value;
|
|
112
112
|
},
|
|
113
113
|
set: function(e) {
|
|
114
|
-
|
|
114
|
+
P.value = e;
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
const I = (e) => `${
|
|
118
|
-
function
|
|
119
|
-
return
|
|
117
|
+
const I = (e) => `${s.DOM_ID_PREFIX}${e}`, A = (e, t = !1) => {
|
|
118
|
+
function n(i) {
|
|
119
|
+
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
120
120
|
}
|
|
121
|
-
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(
|
|
122
122
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
123
|
-
),
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}),
|
|
123
|
+
), c = f(s.URL_PARAM_PREFIX + e.name);
|
|
124
|
+
if (!t && c) {
|
|
125
|
+
const i = C(c, e.url, !0);
|
|
126
|
+
if (i) {
|
|
127
|
+
const p = new URL(i);
|
|
128
|
+
p.searchParams.forEach((U, L) => {
|
|
129
|
+
a.searchParams.set(L, U);
|
|
130
|
+
}), a.hash = p.hash;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
if (
|
|
134
|
-
for (let
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
return
|
|
138
|
-
},
|
|
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;
|
|
138
|
+
}, W = () => {
|
|
139
139
|
const e = document.createElement("div");
|
|
140
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;
|
|
141
|
-
},
|
|
141
|
+
}, Y = (e) => {
|
|
142
142
|
e.style.opacity = "0", setTimeout(() => {
|
|
143
143
|
e.remove();
|
|
144
144
|
}, 500);
|
|
145
145
|
}, q = (e) => {
|
|
146
146
|
const t = document.createElement("iframe");
|
|
147
147
|
t.id = I(e.app.name);
|
|
148
|
-
const n =
|
|
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", (
|
|
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(
|
|
150
150
|
"error",
|
|
151
|
-
(
|
|
151
|
+
(r) => e.onError.call(e, r)
|
|
152
152
|
), t.addEventListener(
|
|
153
153
|
"unload",
|
|
154
|
-
(
|
|
154
|
+
(r) => e.onUnload.call(e, r)
|
|
155
155
|
);
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
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());
|
|
159
159
|
});
|
|
160
160
|
});
|
|
161
|
-
return
|
|
161
|
+
return o.observe(e.panel, { childList: !0 }), t;
|
|
162
162
|
};
|
|
163
163
|
class z {
|
|
164
164
|
constructor(t) {
|
|
@@ -170,15 +170,15 @@ class z {
|
|
|
170
170
|
return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
|
|
171
171
|
}
|
|
172
172
|
mount(t, n = !1) {
|
|
173
|
-
let
|
|
174
|
-
if (t ? (typeof t == "string" ?
|
|
175
|
-
this.panel =
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
const a =
|
|
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");
|
|
178
|
+
const a = W();
|
|
179
179
|
this.loadingTimer = setTimeout(() => {
|
|
180
|
-
this.loading = a,
|
|
181
|
-
}, 1e3),
|
|
180
|
+
this.loading = a, o.appendChild(a);
|
|
181
|
+
}, 1e3), o.appendChild(r);
|
|
182
182
|
} else
|
|
183
183
|
throw new Error("el not found");
|
|
184
184
|
}
|
|
@@ -204,15 +204,17 @@ class z {
|
|
|
204
204
|
preload() {
|
|
205
205
|
this.mount(void 0, !0);
|
|
206
206
|
}
|
|
207
|
-
reload() {
|
|
208
|
-
|
|
209
|
-
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();
|
|
210
212
|
}
|
|
211
213
|
changeOptions(t) {
|
|
212
|
-
this.app =
|
|
214
|
+
this.app = d(d({}, this.app), t);
|
|
213
215
|
}
|
|
214
216
|
onLoad(t) {
|
|
215
|
-
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);
|
|
216
218
|
}
|
|
217
219
|
onUnload(t) {
|
|
218
220
|
console.debug("app onUnload", this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
@@ -237,31 +239,32 @@ const G = (e) => {
|
|
|
237
239
|
"*"
|
|
238
240
|
);
|
|
239
241
|
}, Q = () => {
|
|
240
|
-
window[
|
|
242
|
+
window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
|
|
241
243
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
244
|
+
console.log("父页面接受子应用同步路由信息", e.data);
|
|
242
245
|
const t = [
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
+
s.IS_MICRO,
|
|
247
|
+
s.MICRO_NAME,
|
|
248
|
+
s.MICRO_TOKEN
|
|
246
249
|
], n = new URL(
|
|
247
250
|
window.decodeURIComponent(e.data.data.url),
|
|
248
251
|
e.origin
|
|
249
252
|
);
|
|
250
253
|
for (let a of t)
|
|
251
254
|
n.searchParams.delete(a);
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
c.startsWith(
|
|
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);
|
|
255
258
|
});
|
|
256
|
-
const
|
|
257
|
-
|
|
259
|
+
const r = S(
|
|
260
|
+
o.href,
|
|
258
261
|
e.data.data.name,
|
|
259
262
|
n.href
|
|
260
263
|
);
|
|
261
|
-
window.history.replaceState(null, "",
|
|
264
|
+
window.history.replaceState(null, "", r);
|
|
262
265
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
263
266
|
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
264
|
-
const t =
|
|
267
|
+
const t = y(e.data.data);
|
|
265
268
|
e.source.postMessage(
|
|
266
269
|
{
|
|
267
270
|
cmd: "$xt/micro/info",
|
|
@@ -277,7 +280,7 @@ const G = (e) => {
|
|
|
277
280
|
port: window.location.port,
|
|
278
281
|
protocol: window.location.protocol
|
|
279
282
|
},
|
|
280
|
-
mainMicroVersion:
|
|
283
|
+
mainMicroVersion: h,
|
|
281
284
|
name: t.name,
|
|
282
285
|
url: t.url,
|
|
283
286
|
params: t.params,
|
|
@@ -289,129 +292,134 @@ const G = (e) => {
|
|
|
289
292
|
);
|
|
290
293
|
}
|
|
291
294
|
});
|
|
292
|
-
},
|
|
293
|
-
window[
|
|
294
|
-
const n =
|
|
295
|
-
if (console.debug("child microInit", n,
|
|
296
|
-
window[
|
|
297
|
-
microVersion:
|
|
298
|
-
},
|
|
299
|
-
}), window[
|
|
300
|
-
let
|
|
301
|
-
var
|
|
302
|
-
if (!
|
|
303
|
-
var
|
|
304
|
-
document.head.appendChild(
|
|
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;
|
|
305
308
|
}
|
|
306
|
-
|
|
309
|
+
l.insertRule(c, l.cssRules.length);
|
|
307
310
|
};
|
|
308
|
-
window[
|
|
309
|
-
|
|
310
|
-
}) :
|
|
311
|
+
window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
|
|
312
|
+
r(`${c} { display: none !important; }`);
|
|
313
|
+
}) : r(
|
|
311
314
|
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
312
|
-
)), window.addEventListener("message", (c) => {
|
|
313
|
-
c.data.cmd === `$xt/micro/${
|
|
314
|
-
})
|
|
315
|
-
const a =
|
|
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);
|
|
316
319
|
e.authHandler && a && (yield e.authHandler(a));
|
|
317
320
|
} else
|
|
318
321
|
console.warn("当前环境非微应用环境");
|
|
319
322
|
});
|
|
320
|
-
function J(e) {
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
const
|
|
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), {
|
|
324
327
|
// 添加新数据
|
|
325
328
|
_patchedByParent: !0
|
|
326
329
|
// 可选:标记这是被父窗口修改的状态
|
|
327
330
|
});
|
|
328
|
-
|
|
329
|
-
},
|
|
330
|
-
const
|
|
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), {
|
|
331
334
|
// 添加新数据
|
|
332
335
|
_patchedByParent: !0
|
|
333
336
|
// 可选:标记这是被父窗口修改的状态
|
|
334
337
|
});
|
|
335
|
-
r.call(
|
|
338
|
+
r.call(n, i, c, l), R(e);
|
|
336
339
|
};
|
|
337
340
|
}
|
|
338
|
-
function R() {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
+
});
|
|
352
360
|
}
|
|
353
|
-
let
|
|
361
|
+
let _ = {};
|
|
354
362
|
const Z = {
|
|
355
363
|
url: "",
|
|
356
364
|
name: "",
|
|
357
365
|
sync: !0
|
|
358
|
-
},
|
|
366
|
+
}, le = (e) => {
|
|
359
367
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
360
368
|
console.error("app url is required", e);
|
|
361
369
|
return;
|
|
362
370
|
}
|
|
363
371
|
const t = Object.assign({}, Z, e);
|
|
364
|
-
return
|
|
372
|
+
return _[e.name] = w(d({}, t), {
|
|
365
373
|
instance: new z(e)
|
|
366
|
-
}),
|
|
367
|
-
},
|
|
368
|
-
let
|
|
369
|
-
|
|
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");
|
|
370
378
|
}), ne = (e) => {
|
|
371
|
-
let t =
|
|
379
|
+
let t = y(e);
|
|
372
380
|
t && t.instance.unmount();
|
|
373
|
-
}, de = (e) => {
|
|
374
|
-
let
|
|
375
|
-
|
|
376
|
-
}, oe = /* @__PURE__ */
|
|
381
|
+
}, de = (e, t = !1) => {
|
|
382
|
+
let n = y(e);
|
|
383
|
+
n && n.instance.reload(t);
|
|
384
|
+
}, oe = /* @__PURE__ */ X({
|
|
377
385
|
__name: "XTMicroView",
|
|
378
386
|
props: {
|
|
379
387
|
appId: String
|
|
380
388
|
},
|
|
381
389
|
setup(e) {
|
|
382
|
-
const t = e, n =
|
|
390
|
+
const t = e, n = E(), o = () => {
|
|
383
391
|
t.appId && te(t.appId, {
|
|
384
392
|
el: n.value
|
|
385
|
-
}).then((
|
|
393
|
+
}).then((r) => {
|
|
386
394
|
console.debug("app mounted", t.appId);
|
|
387
395
|
});
|
|
388
396
|
};
|
|
389
|
-
return
|
|
390
|
-
|
|
391
|
-
}), k(() => {
|
|
392
|
-
r();
|
|
397
|
+
return k(() => t.appId, (r, a) => {
|
|
398
|
+
r !== a && a && ne(a), o();
|
|
393
399
|
}), H(() => {
|
|
400
|
+
o();
|
|
401
|
+
}), N(() => {
|
|
394
402
|
console.debug("app unmount", t.appId);
|
|
395
|
-
}), (
|
|
403
|
+
}), (r, a) => (j(), V("div", B({
|
|
396
404
|
ref_key: "refPanel",
|
|
397
405
|
ref: n
|
|
398
|
-
},
|
|
406
|
+
}, r.$attrs, { class: "xt-micro" }), null, 16));
|
|
399
407
|
}
|
|
400
408
|
});
|
|
401
|
-
window[
|
|
402
|
-
const
|
|
409
|
+
window[s.MICRO_VERSION] = h;
|
|
410
|
+
const pe = {
|
|
403
411
|
install: (e, t = {}) => {
|
|
404
412
|
e.component("xt-micro-view", oe), Q();
|
|
405
413
|
}
|
|
406
414
|
};
|
|
407
415
|
export {
|
|
408
416
|
oe as XTMicroView,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
417
|
+
pe as default,
|
|
418
|
+
y as getApp,
|
|
419
|
+
ce as microInit,
|
|
412
420
|
de as reloadApp,
|
|
413
|
-
|
|
421
|
+
le as setupApp,
|
|
414
422
|
te as startApp,
|
|
415
423
|
ne as stopApp,
|
|
416
|
-
|
|
424
|
+
ie as utils
|
|
417
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;
|