@xingtukeji/micro 1.1.16 → 1.1.18
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 +187 -160
- package/dist/types/api.d.ts +10 -1
- package/package.json +2 -2
- package/src/index.ts +21 -0
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
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 R = (e, t, n) => t in e ?
|
|
2
|
+
var x = Object.defineProperty, X = Object.defineProperties;
|
|
3
|
+
var k = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var M = Object.getOwnPropertySymbols;
|
|
5
|
+
var H = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var R = (e, t, n) => t in e ? x(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
|
+
H.call(t, n) && R(e, n, t[n]);
|
|
9
|
+
if (M)
|
|
10
|
+
for (var n of M(t))
|
|
11
|
+
j.call(t, n) && R(e, n, t[n]);
|
|
12
12
|
return e;
|
|
13
|
-
}, y = (e, t) =>
|
|
13
|
+
}, y = (e, t) => X(e, k(t));
|
|
14
14
|
var p = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
-
var h = (e, t, n) => new Promise((
|
|
15
|
+
var h = (e, t, n) => new Promise((o, r) => {
|
|
16
16
|
var a = (l) => {
|
|
17
17
|
try {
|
|
18
18
|
i(n.next(l));
|
|
19
|
-
} catch (
|
|
20
|
-
|
|
19
|
+
} catch (g) {
|
|
20
|
+
r(g);
|
|
21
21
|
}
|
|
22
22
|
}, c = (l) => {
|
|
23
23
|
try {
|
|
24
24
|
i(n.throw(l));
|
|
25
|
-
} catch (
|
|
26
|
-
|
|
25
|
+
} catch (g) {
|
|
26
|
+
r(g);
|
|
27
27
|
}
|
|
28
|
-
}, i = (l) => l.done ?
|
|
28
|
+
}, i = (l) => l.done ? o(l.value) : Promise.resolve(l.value).then(a, c);
|
|
29
29
|
i((n = n.apply(e, t)).next());
|
|
30
30
|
});
|
|
31
|
-
import { ref as
|
|
31
|
+
import { ref as O, defineComponent as N, watch as F, onMounted as B, onUnmounted as V, openBlock as D, createElementBlock as K, mergeProps as Y } from "vue";
|
|
32
32
|
const s = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
@@ -48,45 +48,45 @@ const s = {
|
|
|
48
48
|
// 微应用在 url 参数中的前缀
|
|
49
49
|
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
50
50
|
// 微应用版本
|
|
51
|
-
},
|
|
51
|
+
}, w = "1.1.17";
|
|
52
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 E(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 W(e) {
|
|
65
65
|
const t = window.document.createElement("a");
|
|
66
66
|
return t.href = e, t.href = t.href, t;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function z(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
|
-
function
|
|
72
|
+
function q(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 = s.URL_PARAM_PREFIX + t, c.has(t) ? c.set(t, n) : c.append(t, n),
|
|
81
|
+
function C(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(), console.trace("urlObj", a), a.origin + a.pathname + a.search + a.hash;
|
|
84
84
|
}
|
|
85
|
-
const
|
|
85
|
+
const S = (e) => h(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 !== w && console.warn(
|
|
89
|
+
`子应用版本与主应用版本不一致,${e}子应用版本:${w},主应用版本:${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,73 +96,74 @@ const P = (e) => h(void 0, null, function* () {
|
|
|
96
96
|
"*"
|
|
97
97
|
);
|
|
98
98
|
});
|
|
99
|
-
}),
|
|
99
|
+
}), he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
100
100
|
__proto__: null,
|
|
101
|
-
addOrReplaceUrlParam:
|
|
102
|
-
anchorElementGenerator:
|
|
103
|
-
debounce:
|
|
104
|
-
getAbsolutePath:
|
|
105
|
-
getAnchorElementQueryMap:
|
|
101
|
+
addOrReplaceUrlParam: C,
|
|
102
|
+
anchorElementGenerator: W,
|
|
103
|
+
debounce: q,
|
|
104
|
+
getAbsolutePath: E,
|
|
105
|
+
getAnchorElementQueryMap: z,
|
|
106
106
|
getQueryParameter: f,
|
|
107
|
-
ipcSyncAppInfo:
|
|
108
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
107
|
+
ipcSyncAppInfo: S
|
|
108
|
+
}, Symbol.toStringTag, { value: "Module" })), P = O(!1);
|
|
109
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) => `${s.DOM_ID_PREFIX}${e}`,
|
|
117
|
+
const I = (e) => `${s.DOM_ID_PREFIX}${e}`, U = (e, t = !1) => {
|
|
118
118
|
function n(i) {
|
|
119
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
123
|
), c = f(s.URL_PARAM_PREFIX + e.name);
|
|
124
124
|
if (!t && c) {
|
|
125
|
-
const i =
|
|
125
|
+
const i = E(c, e.url, !0);
|
|
126
126
|
if (i) {
|
|
127
|
-
const l = new URL(i);
|
|
128
|
-
l.searchParams.forEach((
|
|
129
|
-
a.searchParams.set(
|
|
127
|
+
const l = new URL(i, e.url);
|
|
128
|
+
l.searchParams.forEach((A, $) => {
|
|
129
|
+
a.searchParams.set($, A);
|
|
130
130
|
}), a.hash = l.hash;
|
|
131
131
|
}
|
|
132
|
+
m(e.name);
|
|
132
133
|
}
|
|
133
|
-
if (a.searchParams.set(s.IS_MICRO, !0 + ""), a.searchParams.set(s.MICRO_NAME, e.name),
|
|
134
|
-
for (let i of Object.keys(
|
|
135
|
-
a.searchParams.set(i,
|
|
136
|
-
return
|
|
137
|
-
},
|
|
134
|
+
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)
|
|
135
|
+
for (let i of Object.keys(o))
|
|
136
|
+
a.searchParams.set(i, o[i]);
|
|
137
|
+
return m(e.name), a.href;
|
|
138
|
+
}, G = () => {
|
|
138
139
|
const e = document.createElement("div");
|
|
139
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;
|
|
140
|
-
},
|
|
141
|
+
}, Q = (e) => {
|
|
141
142
|
e.style.opacity = "0", setTimeout(() => {
|
|
142
143
|
e.remove();
|
|
143
144
|
}, 500);
|
|
144
|
-
},
|
|
145
|
+
}, J = (e) => {
|
|
145
146
|
const t = document.createElement("iframe");
|
|
146
147
|
t.id = I(e.app.name);
|
|
147
|
-
const n =
|
|
148
|
-
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 = U(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(
|
|
149
150
|
"error",
|
|
150
|
-
(
|
|
151
|
+
(r) => e.onError.call(e, r)
|
|
151
152
|
), t.addEventListener(
|
|
152
153
|
"unload",
|
|
153
|
-
(
|
|
154
|
+
(r) => e.onUnload.call(e, r)
|
|
154
155
|
);
|
|
155
|
-
const
|
|
156
|
-
console.log("监听 body 中子节点的变化2", e.panel),
|
|
157
|
-
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")),
|
|
156
|
+
const o = new MutationObserver((r) => {
|
|
157
|
+
console.log("监听 body 中子节点的变化2", e.panel), r.forEach((a) => {
|
|
158
|
+
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), o.disconnect());
|
|
158
159
|
});
|
|
159
160
|
});
|
|
160
|
-
return
|
|
161
|
+
return o.observe(e.panel.parentNode, {
|
|
161
162
|
childList: !0,
|
|
162
163
|
subtree: !1
|
|
163
164
|
}), t;
|
|
164
165
|
};
|
|
165
|
-
class
|
|
166
|
+
class Z {
|
|
166
167
|
constructor(t) {
|
|
167
168
|
p(this, "app");
|
|
168
169
|
p(this, "dom");
|
|
@@ -172,15 +173,15 @@ class G {
|
|
|
172
173
|
return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
|
|
173
174
|
}
|
|
174
175
|
mount(t, n = !1) {
|
|
175
|
-
let
|
|
176
|
-
if (t ? (typeof t == "string" ?
|
|
177
|
-
this.panel =
|
|
178
|
-
let
|
|
179
|
-
|
|
180
|
-
const a =
|
|
176
|
+
let o;
|
|
177
|
+
if (t ? (typeof t == "string" ? o = document.querySelector(t) : o = t, o.innerHTML = "") : o = document.body, o) {
|
|
178
|
+
this.panel = o;
|
|
179
|
+
let r = document.getElementById(I(this.app.name));
|
|
180
|
+
r || (r = J(this), this.dom = r), n ? r.style.display = "none" : r.style.removeProperty("display");
|
|
181
|
+
const a = G();
|
|
181
182
|
this.loadingTimer = setTimeout(() => {
|
|
182
|
-
this.loading = a,
|
|
183
|
-
}, 1e3),
|
|
183
|
+
this.loading = a, o.appendChild(a);
|
|
184
|
+
}, 1e3), o.appendChild(r);
|
|
184
185
|
} else
|
|
185
186
|
throw new Error("el not found");
|
|
186
187
|
}
|
|
@@ -209,24 +210,24 @@ class G {
|
|
|
209
210
|
}
|
|
210
211
|
reload(t = !1) {
|
|
211
212
|
let n = this.dom.src;
|
|
212
|
-
t && (n =
|
|
213
|
-
const
|
|
214
|
-
|
|
213
|
+
t && (n = U(this.app, !0), console.log("go home", n)), console.log("reload app", this.app, n);
|
|
214
|
+
const o = new URL(n);
|
|
215
|
+
o.searchParams.set("__t", Date.now().toString()), this.dom.style.visibility = "hidden", this.dom.src = o.toString();
|
|
215
216
|
}
|
|
216
217
|
changeOptions(t) {
|
|
217
218
|
console.log("changeOptions", this.app, t), this.app = d(d({}, this.app), t);
|
|
218
219
|
}
|
|
219
220
|
onLoad(t) {
|
|
220
|
-
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading &&
|
|
221
|
+
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && Q(this.loading), ee(this), console.log("this.app.onLoad", this.app.onLoad), this.app.onLoad && this.app.onLoad(t, this);
|
|
221
222
|
}
|
|
222
223
|
onUnload(t) {
|
|
223
|
-
console.debug("app onUnload", this.app.name),
|
|
224
|
+
console.debug("app onUnload", this.app.name), m(this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
224
225
|
}
|
|
225
226
|
onError(t) {
|
|
226
227
|
console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
|
-
const
|
|
230
|
+
const ee = (e) => {
|
|
230
231
|
var t, n;
|
|
231
232
|
(n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
|
|
232
233
|
{
|
|
@@ -241,7 +242,7 @@ const Q = (e) => {
|
|
|
241
242
|
},
|
|
242
243
|
"*"
|
|
243
244
|
);
|
|
244
|
-
},
|
|
245
|
+
}, te = () => {
|
|
245
246
|
window[s.MICRO_TYPE] = "parent", window.addEventListener("message", (e) => {
|
|
246
247
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
247
248
|
console.log("父页面接受子应用同步路由信息", e.data);
|
|
@@ -253,17 +254,23 @@ const Q = (e) => {
|
|
|
253
254
|
window.decodeURIComponent(e.data.data.url),
|
|
254
255
|
e.origin
|
|
255
256
|
);
|
|
256
|
-
for (let
|
|
257
|
-
n.searchParams.delete(
|
|
258
|
-
|
|
257
|
+
for (let c of t)
|
|
258
|
+
n.searchParams.delete(c);
|
|
259
|
+
console.log("tempUrl", n);
|
|
260
|
+
const o = m(e.data.data.name), r = new URL(o);
|
|
261
|
+
r.searchParams.forEach((c, i) => {
|
|
262
|
+
i.startsWith(s.URL_PARAM_PREFIX) && r.searchParams.delete(i);
|
|
263
|
+
}), console.log("mainURL.href", r.href);
|
|
264
|
+
const a = C(
|
|
259
265
|
r.href,
|
|
260
266
|
e.data.data.name,
|
|
261
267
|
n.href
|
|
268
|
+
// tempUrl.pathname + tempUrl.search + tempUrl.hash
|
|
262
269
|
);
|
|
263
|
-
window.history.replaceState(null, "",
|
|
270
|
+
console.log("curUrl", a), window.history.replaceState(null, "", a);
|
|
264
271
|
} else if (e.data.cmd === "$xt/micro/info") {
|
|
265
272
|
console.debug("parent 「$xt/micro/info」 receive message", e.data);
|
|
266
|
-
const t =
|
|
273
|
+
const t = _(e.data.data);
|
|
267
274
|
e.source.postMessage(
|
|
268
275
|
{
|
|
269
276
|
cmd: "$xt/micro/info",
|
|
@@ -279,7 +286,7 @@ const Q = (e) => {
|
|
|
279
286
|
port: window.location.port,
|
|
280
287
|
protocol: window.location.protocol
|
|
281
288
|
},
|
|
282
|
-
mainMicroVersion:
|
|
289
|
+
mainMicroVersion: w,
|
|
283
290
|
name: t.name,
|
|
284
291
|
url: t.url,
|
|
285
292
|
params: t.params,
|
|
@@ -291,15 +298,15 @@ const Q = (e) => {
|
|
|
291
298
|
);
|
|
292
299
|
}
|
|
293
300
|
});
|
|
294
|
-
},
|
|
301
|
+
}, ne = (...t) => h(void 0, [...t], function* (e = {}) {
|
|
295
302
|
window[s.MICRO_TYPE] = "child";
|
|
296
|
-
const n = f(s.IS_MICRO),
|
|
297
|
-
if (console.debug("child microInit", n,
|
|
303
|
+
const n = f(s.IS_MICRO), o = f(s.MICRO_NAME);
|
|
304
|
+
if (console.debug("child microInit", n, o), n && (window[s.IS_MICRO] = n === "true"), o && S(o).then((r) => {
|
|
298
305
|
window[s.MICRO_APP] = d({
|
|
299
|
-
microVersion:
|
|
300
|
-
},
|
|
306
|
+
microVersion: w
|
|
307
|
+
}, r);
|
|
301
308
|
}), window[s.IS_MICRO]) {
|
|
302
|
-
let
|
|
309
|
+
let r = function(c) {
|
|
303
310
|
var i = document.styleSheets[0];
|
|
304
311
|
if (!i) {
|
|
305
312
|
var l = document.createElement("style");
|
|
@@ -308,131 +315,151 @@ const Q = (e) => {
|
|
|
308
315
|
i.insertRule(c, i.cssRules.length);
|
|
309
316
|
};
|
|
310
317
|
window[s.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((c) => {
|
|
311
|
-
|
|
312
|
-
}) :
|
|
318
|
+
r(`${c} { display: none !important; }`);
|
|
319
|
+
}) : r(
|
|
313
320
|
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
314
|
-
)), yield
|
|
315
|
-
c.data.cmd === `$xt/micro/${
|
|
321
|
+
)), yield oe(o, window), window.addEventListener("message", (c) => h(void 0, null, function* () {
|
|
322
|
+
c.data.cmd === `$xt/micro/${o}` && L(o);
|
|
316
323
|
}));
|
|
317
324
|
const a = f(s.MICRO_TOKEN);
|
|
318
325
|
e.authHandler && a && (yield e.authHandler(a));
|
|
319
326
|
} else
|
|
320
327
|
console.warn("当前环境非微应用环境");
|
|
321
328
|
});
|
|
322
|
-
function
|
|
323
|
-
const n = t.history,
|
|
329
|
+
function oe(e, t) {
|
|
330
|
+
const n = t.history, o = n.pushState, r = n.replaceState;
|
|
324
331
|
n.pushState = function(a, c, i) {
|
|
325
332
|
const l = y(d(d({}, n.state || {}), a), {
|
|
326
333
|
// 添加新数据
|
|
327
334
|
_patchedByParent: !0
|
|
328
335
|
// 可选:标记这是被父窗口修改的状态
|
|
329
336
|
});
|
|
330
|
-
|
|
337
|
+
o.call(n, l, c, i), L(e);
|
|
331
338
|
}, n.replaceState = function(a, c, i) {
|
|
332
339
|
const l = y(d(d({}, n.state || {}), a), {
|
|
333
340
|
// 添加新数据
|
|
334
341
|
_patchedByParent: !0
|
|
335
342
|
// 可选:标记这是被父窗口修改的状态
|
|
336
343
|
});
|
|
337
|
-
|
|
344
|
+
r.call(n, l, c, i);
|
|
338
345
|
};
|
|
339
346
|
}
|
|
340
|
-
function
|
|
347
|
+
function L(e) {
|
|
341
348
|
return h(this, null, function* () {
|
|
342
|
-
console.log("syncUrlToWindow", e, window[s.MICRO_APP]), window[s.MICRO_APP]
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}));
|
|
347
|
-
const { name: t, sync: n, mainLocation: r } = window[s.MICRO_APP], o = window.location.pathname + window.location.search + window.location.hash;
|
|
348
|
-
window.parent.postMessage(
|
|
349
|
+
if (console.log("syncUrlToWindow", e, window[s.MICRO_APP]), !window[s.MICRO_APP])
|
|
350
|
+
return;
|
|
351
|
+
const { name: t, sync: n, mainLocation: o } = window[s.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
|
|
352
|
+
console.log("curUrl", r), window.parent.postMessage(
|
|
349
353
|
{
|
|
350
354
|
cmd: "$xt/micro/sync",
|
|
351
355
|
data: {
|
|
352
356
|
name: t,
|
|
353
|
-
url: window.encodeURIComponent(
|
|
357
|
+
url: window.encodeURIComponent(r)
|
|
354
358
|
}
|
|
355
359
|
},
|
|
356
|
-
|
|
360
|
+
o.origin
|
|
357
361
|
);
|
|
358
362
|
});
|
|
359
363
|
}
|
|
360
|
-
let
|
|
361
|
-
const
|
|
364
|
+
let u = {};
|
|
365
|
+
const re = {
|
|
362
366
|
url: "",
|
|
363
367
|
name: "",
|
|
364
368
|
sync: !0
|
|
365
|
-
},
|
|
369
|
+
}, ae = (e) => {
|
|
366
370
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
367
371
|
console.error("app url is required", e);
|
|
368
372
|
return;
|
|
369
373
|
}
|
|
370
|
-
const t = Object.assign({},
|
|
371
|
-
return n ?
|
|
372
|
-
instance: new
|
|
373
|
-
}),
|
|
374
|
-
},
|
|
375
|
-
let
|
|
376
|
-
|
|
377
|
-
}),
|
|
378
|
-
let t =
|
|
374
|
+
const t = Object.assign({}, re, e), n = u[e.name];
|
|
375
|
+
return n ? u[e.name] = d(d({}, n), t) : u[e.name] = y(d({}, t), {
|
|
376
|
+
instance: new Z(e)
|
|
377
|
+
}), u[e.name];
|
|
378
|
+
}, _ = (e) => u[e], se = (e, t) => u[e.name] = d(d({}, e), t), b = (e, t) => new Promise((n, o) => {
|
|
379
|
+
let r = _(e);
|
|
380
|
+
r ? (t && (r.instance.changeOptions(t), r = se(r, t)), r.preload ? r.instance.preloadRender(r.el) : r.instance.mount(r.el), n(r)) : o("app not found, please setup app first");
|
|
381
|
+
}), T = (e) => {
|
|
382
|
+
let t = _(e);
|
|
379
383
|
t && t.instance.unmount();
|
|
380
|
-
},
|
|
381
|
-
let n =
|
|
384
|
+
}, ie = (e, t = !1) => {
|
|
385
|
+
let n = _(e);
|
|
382
386
|
n && n.instance.reload(t);
|
|
383
|
-
},
|
|
387
|
+
}, m = (e) => {
|
|
384
388
|
console.log("clearParentUrl", e, s.URL_PARAM_PREFIX + e);
|
|
385
389
|
const t = window.location.href.split("#");
|
|
386
390
|
console.log("url", t);
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
let n = new URL(t[0]);
|
|
392
|
+
n.searchParams.delete(s.URL_PARAM_PREFIX + e);
|
|
393
|
+
const o = t.length > 1 ? n.href + "#" + t[1] : n.href;
|
|
394
|
+
return window.history.replaceState({}, "", o), o;
|
|
395
|
+
}, v = () => window[s.IS_MICRO] === !0, ce = () => window[s.MICRO_TYPE] === "parent", le = (e, t = ((n) => (n = window.__XT_MICRO_APP) == null ? void 0 : n.name)()) => {
|
|
396
|
+
let o = window.location;
|
|
397
|
+
if (v())
|
|
398
|
+
o = window.__XT_MICRO_APP.mainLocation;
|
|
399
|
+
else if (!t) {
|
|
400
|
+
console.error("在主应用中需要传入应用名称");
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
return `${o.origin}${o.pathname}?__XT_MICRO_${t}=${encodeURIComponent(e)}${o.hash}`;
|
|
404
|
+
}, de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
405
|
+
__proto__: null,
|
|
406
|
+
clearParentUrl: m,
|
|
407
|
+
createAppUrl: le,
|
|
408
|
+
getApp: _,
|
|
409
|
+
isMicro: v,
|
|
410
|
+
isParent: ce,
|
|
411
|
+
microInit: ne,
|
|
412
|
+
reloadApp: ie,
|
|
413
|
+
setupApp: ae,
|
|
414
|
+
startApp: b,
|
|
415
|
+
stopApp: T
|
|
416
|
+
}, Symbol.toStringTag, { value: "Module" })), me = /* @__PURE__ */ N({
|
|
394
417
|
__name: "XTMicroView",
|
|
395
418
|
props: {
|
|
396
419
|
appId: String
|
|
397
420
|
},
|
|
398
421
|
setup(e) {
|
|
399
|
-
const t = e, n =
|
|
400
|
-
t.appId &&
|
|
422
|
+
const t = e, n = O(), o = () => {
|
|
423
|
+
t.appId && b(t.appId, {
|
|
401
424
|
el: n.value,
|
|
402
|
-
onUnload(
|
|
403
|
-
console.log("on unload", a.app.name),
|
|
425
|
+
onUnload(r, a) {
|
|
426
|
+
console.log("on unload", a.app.name), m(a.app.name);
|
|
404
427
|
}
|
|
405
|
-
}).then((
|
|
428
|
+
}).then((r) => {
|
|
406
429
|
console.debug("app mounted", t.appId);
|
|
407
430
|
});
|
|
408
431
|
};
|
|
409
|
-
return
|
|
410
|
-
|
|
411
|
-
}),
|
|
412
|
-
|
|
413
|
-
}),
|
|
414
|
-
console.debug("「micro」", "app unmount", t.appId),
|
|
415
|
-
}), (
|
|
432
|
+
return F(() => t.appId, (r, a) => {
|
|
433
|
+
r !== a && a && T(a), o();
|
|
434
|
+
}), B(() => {
|
|
435
|
+
o();
|
|
436
|
+
}), V(() => {
|
|
437
|
+
console.debug("「micro」", "app unmount", t.appId), m(t.appId);
|
|
438
|
+
}), (r, a) => (D(), K("div", Y({
|
|
416
439
|
ref_key: "refPanel",
|
|
417
440
|
ref: n
|
|
418
|
-
},
|
|
441
|
+
}, r.$attrs, { class: "xt-micro" }), null, 16));
|
|
419
442
|
}
|
|
420
443
|
});
|
|
421
|
-
window[s.MICRO_VERSION] =
|
|
422
|
-
|
|
444
|
+
window[s.MICRO_VERSION] = w;
|
|
445
|
+
window.api = de;
|
|
446
|
+
const fe = {
|
|
423
447
|
install: (e, t = {}) => {
|
|
424
|
-
e.component("xt-micro-view",
|
|
448
|
+
e.component("xt-micro-view", me), te();
|
|
425
449
|
}
|
|
426
450
|
};
|
|
427
451
|
export {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
ne as
|
|
436
|
-
|
|
437
|
-
|
|
452
|
+
me as XTMicroView,
|
|
453
|
+
m as clearParentUrl,
|
|
454
|
+
le as createAppUrl,
|
|
455
|
+
fe as default,
|
|
456
|
+
_ as getApp,
|
|
457
|
+
v as isMicro,
|
|
458
|
+
ce as isParent,
|
|
459
|
+
ne as microInit,
|
|
460
|
+
ie as reloadApp,
|
|
461
|
+
ae as setupApp,
|
|
462
|
+
b as startApp,
|
|
463
|
+
T as stopApp,
|
|
464
|
+
he as utils
|
|
438
465
|
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -19,5 +19,14 @@ export declare const startApp: (name: string, options?: Partial<AppOption>) => P
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const stopApp: (name: string) => void;
|
|
21
21
|
export declare const reloadApp: (name: string, isGoHome?: boolean) => void;
|
|
22
|
-
export declare const clearParentUrl: (appName: string) =>
|
|
22
|
+
export declare const clearParentUrl: (appName: string) => string;
|
|
23
|
+
export declare const isMicro: () => boolean;
|
|
24
|
+
export declare const isParent: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 创建基于主应用路由的某个子应用的 url
|
|
27
|
+
* @param appName 应用名称
|
|
28
|
+
* @param targetUrlHash 应用地址
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const createAppUrl: (targetUrlHash: string, appName?: string) => string;
|
|
23
32
|
export { microInit };
|
package/package.json
CHANGED
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { App } from "vue";
|
|
2
|
+
import XTMicroView from "./components/XTMicroView.vue";
|
|
3
|
+
|
|
4
|
+
import { mainMicroInit } from "./parent";
|
|
5
|
+
export * from "./api";
|
|
6
|
+
import * as utils from "./utils";
|
|
7
|
+
|
|
8
|
+
export { XTMicroView, utils };
|
|
9
|
+
import { version } from "../package.json";
|
|
10
|
+
import { CONSTANT } from "./types";
|
|
11
|
+
window[CONSTANT.MICRO_VERSION] = version;
|
|
12
|
+
//temp test
|
|
13
|
+
import * as api from "./api";
|
|
14
|
+
window["api"] = api;
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
install: (app: App, _options: any = {}) => {
|
|
18
|
+
app.component("xt-micro-view", XTMicroView);
|
|
19
|
+
mainMicroInit();
|
|
20
|
+
},
|
|
21
|
+
};
|