@xingtukeji/micro 1.1.8 → 1.1.10
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 +30 -21
- package/dist/index.js +182 -138
- package/dist/types/index.d.ts +1 -1
- package/dist/types/utils.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,41 +1,50 @@
|
|
|
1
1
|
主应用初始化:
|
|
2
|
+
|
|
2
3
|
```javascript
|
|
3
4
|
//主微应用加载插件,注意一定要在 pinia 初始化之后
|
|
4
|
-
import xtMicro, { setupApp } from
|
|
5
|
-
app.use(xtMicro)
|
|
5
|
+
import xtMicro, { setupApp } from "@xingtukeji/micro";
|
|
6
|
+
app.use(xtMicro);
|
|
6
7
|
// 遍历菜单函数
|
|
7
8
|
function traverseMenu(menu) {
|
|
8
9
|
// 遍历菜单项
|
|
9
10
|
menu.forEach((item) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
// 对微应用的菜单做处理
|
|
12
|
+
if (item.type === "micro") {
|
|
13
|
+
// 设置应用
|
|
14
|
+
setupApp({
|
|
15
|
+
...item.microOptions,
|
|
16
|
+
token: () => useUserStore().token,
|
|
17
|
+
params: item.microOptions?.params || {},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// 如果当前菜单项有子菜单,则递归遍历子菜单
|
|
21
|
+
if (item.children) {
|
|
22
|
+
traverseMenu(item.children);
|
|
23
|
+
}
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
traverseMenu(window.$config.menus)
|
|
26
|
+
traverseMenu(window.$config.menus);
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
子应用初始化:
|
|
30
|
+
|
|
29
31
|
```javascript
|
|
30
32
|
//子应用初始化
|
|
31
|
-
import {microInit} from
|
|
33
|
+
import { microInit } from "@xingtukeji/micro";
|
|
32
34
|
microInit({
|
|
33
35
|
// 处理 token,该方法建议同步执行完成,如果有异步处理(比如 http 请求)请后续页面初始化时,判断 token 是否准备完毕。
|
|
34
|
-
authHandler: (token: string)=>{
|
|
35
|
-
window.localStorage.setItem(
|
|
36
|
+
authHandler: (token: string) => {
|
|
37
|
+
window.localStorage.setItem("token", token);
|
|
36
38
|
//or pinia store set token
|
|
37
39
|
},
|
|
38
40
|
//简易处理微应用环境下,隐藏 header
|
|
39
|
-
hideHeaderCssSelector:
|
|
40
|
-
})
|
|
41
|
+
hideHeaderCssSelector: "#app ._hedaui-header",
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
当需要新标签打开子项目时,还想保留父项目加载的方式(不直接访问子项目),可以在父项目的 url 中添加参数 `__XT_MICRO_${子项目名称}=${子项目 url}`
|
|
46
|
+
但要注意,子项目的 url 需要用 encodeURIComponent 编码,否则会导致参数解析错误
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
http://192.168.100.127:8000/console/?__XT_MICRO_microtest2=http://localhost:5173/?test=123#/page2#/micro/microtest2
|
|
41
50
|
```
|
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
|
|
2
|
+
var L = Object.defineProperty, v = Object.defineProperties;
|
|
3
|
+
var b = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var M = Object.getOwnPropertySymbols;
|
|
5
|
+
var T = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var _ = (e, t, n) => t in e ? L(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, l = (e, t) => {
|
|
7
7
|
for (var n in t || (t = {}))
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
for (var n of
|
|
11
|
-
|
|
8
|
+
T.call(t, n) && _(e, n, t[n]);
|
|
9
|
+
if (M)
|
|
10
|
+
for (var n of M(t))
|
|
11
|
+
x.call(t, n) && _(e, n, t[n]);
|
|
12
12
|
return e;
|
|
13
|
-
},
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
13
|
+
}, f = (e, t) => v(e, b(t));
|
|
14
|
+
var m = (e, t, n) => (_(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
15
|
+
var R = (e, t, n) => new Promise((r, o) => {
|
|
16
|
+
var a = (d) => {
|
|
17
17
|
try {
|
|
18
|
-
i(n.next(
|
|
18
|
+
i(n.next(d));
|
|
19
19
|
} catch (h) {
|
|
20
20
|
o(h);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
22
|
+
}, s = (d) => {
|
|
23
23
|
try {
|
|
24
|
-
i(n.throw(
|
|
24
|
+
i(n.throw(d));
|
|
25
25
|
} catch (h) {
|
|
26
26
|
o(h);
|
|
27
27
|
}
|
|
28
|
-
}, i = (
|
|
28
|
+
}, i = (d) => d.done ? r(d.value) : Promise.resolve(d.value).then(a, s);
|
|
29
29
|
i((n = n.apply(e, t)).next());
|
|
30
30
|
});
|
|
31
|
-
import { ref as P, defineComponent as
|
|
31
|
+
import { ref as P, defineComponent as $, watch as X, onMounted as k, onUnmounted as H, openBlock as N, createElementBlock as B, mergeProps as j } from "vue";
|
|
32
32
|
const c = {
|
|
33
33
|
KEY: "$xtm",
|
|
34
34
|
// 父应用注入子应用实例的key
|
|
@@ -42,30 +42,32 @@ const c = {
|
|
|
42
42
|
// 微应用实例
|
|
43
43
|
DOM_ID_PREFIX: "xt-micro-ifr-",
|
|
44
44
|
// dom id前缀
|
|
45
|
-
URL_PARAM_PREFIX: "__XT_MICRO_"
|
|
45
|
+
URL_PARAM_PREFIX: "__XT_MICRO_",
|
|
46
46
|
// 微应用在 url 参数中的前缀
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
MICRO_VERSION: "__XT_MICRO_VERSION"
|
|
48
|
+
// 微应用版本
|
|
49
|
+
}, p = "1.1.10";
|
|
50
|
+
function u(e, t = window.location.href) {
|
|
49
51
|
e = e.replace(/[\[\]]/g, "\\$&");
|
|
50
52
|
var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
|
|
51
53
|
return r ? r[2] ? decodeURIComponent(r[2].replace(/\+/g, " ")).trim() : "" : null;
|
|
52
54
|
}
|
|
53
|
-
function
|
|
55
|
+
function E(e, t, n) {
|
|
54
56
|
try {
|
|
55
57
|
return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
|
|
56
58
|
} catch (r) {
|
|
57
59
|
return e;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
|
-
function
|
|
62
|
+
function V(e) {
|
|
61
63
|
const t = window.document.createElement("a");
|
|
62
64
|
return t.href = e, t.href = t.href, t;
|
|
63
65
|
}
|
|
64
|
-
function
|
|
66
|
+
function F(e) {
|
|
65
67
|
const t = e.search || "";
|
|
66
68
|
return [...new URLSearchParams(t).entries()].reduce((n, r) => (n[r[0]] = r[1], n), {});
|
|
67
69
|
}
|
|
68
|
-
function
|
|
70
|
+
function K(e, t) {
|
|
69
71
|
let n = null;
|
|
70
72
|
return function(...r) {
|
|
71
73
|
const o = this;
|
|
@@ -74,60 +76,75 @@ function F(e, t) {
|
|
|
74
76
|
}, t);
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
|
-
function
|
|
78
|
-
const [r, o] = e.split("#"),
|
|
79
|
-
return t = c.URL_PARAM_PREFIX + t,
|
|
79
|
+
function C(e, t, n) {
|
|
80
|
+
const [r, o] = e.split("#"), a = new URL(r), s = a.searchParams;
|
|
81
|
+
return t = c.URL_PARAM_PREFIX + t, s.has(t) ? s.set(t, n) : s.append(t, n), o && (a.hash = o), a.search = s.toString(), a.toString();
|
|
80
82
|
}
|
|
81
|
-
const
|
|
83
|
+
const S = (e) => R(void 0, null, function* () {
|
|
84
|
+
return new Promise((t) => {
|
|
85
|
+
window.addEventListener("message", (n) => {
|
|
86
|
+
n.data.cmd === "$xt/micro/info" && (n.data.data.mainMicroVersion !== p && console.warn(
|
|
87
|
+
`子应用版本与主应用版本不一致,${e}子应用版本:${p},主应用版本:${n.data.data.mainMicroVersion}`
|
|
88
|
+
), t(n.data.data));
|
|
89
|
+
}), window.parent.postMessage(
|
|
90
|
+
{
|
|
91
|
+
cmd: "$xt/micro/info",
|
|
92
|
+
data: e
|
|
93
|
+
},
|
|
94
|
+
"*"
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
}), se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
82
98
|
__proto__: null,
|
|
83
|
-
addOrReplaceUrlParam:
|
|
84
|
-
anchorElementGenerator:
|
|
85
|
-
debounce:
|
|
86
|
-
getAbsolutePath:
|
|
87
|
-
getAnchorElementQueryMap:
|
|
88
|
-
getQueryParameter:
|
|
89
|
-
|
|
99
|
+
addOrReplaceUrlParam: C,
|
|
100
|
+
anchorElementGenerator: V,
|
|
101
|
+
debounce: K,
|
|
102
|
+
getAbsolutePath: E,
|
|
103
|
+
getAnchorElementQueryMap: F,
|
|
104
|
+
getQueryParameter: u,
|
|
105
|
+
ipcSyncAppInfo: S
|
|
106
|
+
}, Symbol.toStringTag, { value: "Module" })), O = P(!1);
|
|
90
107
|
Object.defineProperty(window, c.IS_MICRO, {
|
|
91
108
|
get: function() {
|
|
92
|
-
return
|
|
109
|
+
return O.value;
|
|
93
110
|
},
|
|
94
111
|
set: function(e) {
|
|
95
|
-
|
|
112
|
+
O.value = e;
|
|
96
113
|
}
|
|
97
114
|
});
|
|
98
|
-
const
|
|
115
|
+
const g = (e) => `${c.DOM_ID_PREFIX}${e}`, D = (e) => {
|
|
99
116
|
function t(i) {
|
|
100
117
|
return i !== null && typeof i == "object" && !Array.isArray(i);
|
|
101
118
|
}
|
|
102
119
|
const n = typeof e.params == "function" ? e.params() : t(e.params) ? e.params : {}, r = typeof e.token == "function" ? e.token() : t(e.token) ? e.token : "", o = new URL(
|
|
103
120
|
e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
|
|
104
|
-
),
|
|
105
|
-
if (
|
|
106
|
-
const i =
|
|
121
|
+
), a = u(c.URL_PARAM_PREFIX + e.name);
|
|
122
|
+
if (a) {
|
|
123
|
+
const i = E(a, e.url, !0);
|
|
107
124
|
if (i) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
o.searchParams.set(
|
|
111
|
-
}), o.hash =
|
|
125
|
+
const d = new URL(i);
|
|
126
|
+
d.searchParams.forEach((U, A) => {
|
|
127
|
+
o.searchParams.set(A, U);
|
|
128
|
+
}), o.hash = d.hash;
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
131
|
if (o.searchParams.set(c.IS_MICRO, !0 + ""), o.searchParams.set(c.MICRO_NAME, e.name), r && o.searchParams.set(c.MICRO_TOKEN, r), n)
|
|
115
132
|
for (let i of Object.keys(n))
|
|
116
133
|
o.searchParams.set(i, n[i]);
|
|
117
|
-
const
|
|
118
|
-
return
|
|
119
|
-
},
|
|
134
|
+
const s = new URL(window.location.href);
|
|
135
|
+
return s.searchParams.delete(e.name), window.history.replaceState({}, "", s.href), o.href;
|
|
136
|
+
}, W = () => {
|
|
120
137
|
const e = document.createElement("div");
|
|
121
138
|
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;
|
|
122
|
-
},
|
|
139
|
+
}, q = (e) => {
|
|
123
140
|
e.style.opacity = "0", setTimeout(() => {
|
|
124
141
|
e.remove();
|
|
125
142
|
}, 500);
|
|
126
|
-
},
|
|
143
|
+
}, z = (e) => {
|
|
127
144
|
const t = document.createElement("iframe");
|
|
128
|
-
t.id =
|
|
129
|
-
const n =
|
|
130
|
-
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.visibility = "hidden", t.addEventListener("load", (o) => (t.style.visibility = "visible", e.onLoad.call(e, o))), t.addEventListener(
|
|
145
|
+
t.id = g(e.app.name);
|
|
146
|
+
const n = D(e.app);
|
|
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"] = "none", t.style.visibility = "hidden", t.addEventListener("load", (o) => (t.style.visibility = "visible", e.onLoad.call(e, o))), t.addEventListener(
|
|
131
148
|
"error",
|
|
132
149
|
(o) => e.onError.call(e, o)
|
|
133
150
|
), t.addEventListener(
|
|
@@ -135,37 +152,37 @@ const w = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
|
|
|
135
152
|
(o) => e.onUnload.call(e, o)
|
|
136
153
|
);
|
|
137
154
|
const r = new MutationObserver((o) => {
|
|
138
|
-
o.forEach((
|
|
139
|
-
Array.from(
|
|
155
|
+
o.forEach((a) => {
|
|
156
|
+
Array.from(a.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
|
|
140
157
|
});
|
|
141
158
|
});
|
|
142
159
|
return r.observe(e.panel, { childList: !0 }), t;
|
|
143
160
|
};
|
|
144
|
-
class
|
|
161
|
+
class G {
|
|
145
162
|
constructor(t) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
163
|
+
m(this, "app");
|
|
164
|
+
m(this, "dom");
|
|
165
|
+
m(this, "panel");
|
|
166
|
+
m(this, "loading");
|
|
167
|
+
m(this, "loadingTimer");
|
|
151
168
|
return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
|
|
152
169
|
}
|
|
153
170
|
mount(t, n = !1) {
|
|
154
171
|
let r;
|
|
155
172
|
if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
|
|
156
173
|
this.panel = r;
|
|
157
|
-
let o = document.getElementById(
|
|
158
|
-
o || (o =
|
|
159
|
-
const
|
|
174
|
+
let o = document.getElementById(g(this.app.name));
|
|
175
|
+
o || (o = z(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
|
|
176
|
+
const a = W();
|
|
160
177
|
this.loadingTimer = setTimeout(() => {
|
|
161
|
-
this.loading =
|
|
178
|
+
this.loading = a, r.appendChild(a);
|
|
162
179
|
}, 1e3), r.appendChild(o);
|
|
163
180
|
} else
|
|
164
181
|
throw new Error("el not found");
|
|
165
182
|
}
|
|
166
183
|
unmount() {
|
|
167
184
|
var n;
|
|
168
|
-
const t = document.getElementById(
|
|
185
|
+
const t = document.getElementById(g(this.app.name));
|
|
169
186
|
if (t)
|
|
170
187
|
this.app.preload ? (t.style.display = "none", document.body.appendChild(t)) : (n = this.panel) == null || n.removeChild(t);
|
|
171
188
|
else
|
|
@@ -190,19 +207,19 @@ class z {
|
|
|
190
207
|
this.dom.src = t;
|
|
191
208
|
}
|
|
192
209
|
changeOptions(t) {
|
|
193
|
-
this.app =
|
|
210
|
+
this.app = l(l({}, this.app), t);
|
|
194
211
|
}
|
|
195
212
|
onLoad(t) {
|
|
196
|
-
console.debug("app onLoad", this.app.name
|
|
213
|
+
console.debug("app onLoad", this.app.name), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && q(this.loading), Q(this), this.app.onLoad && this.app.onLoad(t, this);
|
|
197
214
|
}
|
|
198
215
|
onUnload(t) {
|
|
199
|
-
console.debug("app onUnload", this.app.name
|
|
216
|
+
console.debug("app onUnload", this.app.name), this.app.onUnload && this.app.onUnload(t, this);
|
|
200
217
|
}
|
|
201
218
|
onError(t) {
|
|
202
|
-
console.error("app onError", this.app.name
|
|
219
|
+
console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
|
|
203
220
|
}
|
|
204
221
|
}
|
|
205
|
-
const
|
|
222
|
+
const Q = (e) => {
|
|
206
223
|
var t, n;
|
|
207
224
|
(n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
|
|
208
225
|
{
|
|
@@ -217,7 +234,7 @@ const G = (e) => {
|
|
|
217
234
|
},
|
|
218
235
|
"*"
|
|
219
236
|
);
|
|
220
|
-
},
|
|
237
|
+
}, Y = () => {
|
|
221
238
|
window.addEventListener("message", (e) => {
|
|
222
239
|
if (e.data.cmd === "$xt/micro/sync") {
|
|
223
240
|
const t = [
|
|
@@ -228,130 +245,157 @@ const G = (e) => {
|
|
|
228
245
|
window.decodeURIComponent(e.data.data.url),
|
|
229
246
|
e.origin
|
|
230
247
|
);
|
|
231
|
-
for (let
|
|
232
|
-
n.searchParams.delete(
|
|
248
|
+
for (let a of t)
|
|
249
|
+
n.searchParams.delete(a);
|
|
233
250
|
const r = new URL(window.location.href);
|
|
234
|
-
r.searchParams.forEach((
|
|
235
|
-
|
|
251
|
+
r.searchParams.forEach((a, s) => {
|
|
252
|
+
s.startsWith(c.URL_PARAM_PREFIX) && r.searchParams.delete(s);
|
|
236
253
|
});
|
|
237
|
-
const o =
|
|
254
|
+
const o = C(
|
|
238
255
|
r.href,
|
|
239
256
|
e.data.data.name,
|
|
240
257
|
n.href
|
|
241
258
|
);
|
|
242
259
|
window.history.replaceState(null, "", o);
|
|
260
|
+
} else if (e.data.cmd === "$xt/micro/info") {
|
|
261
|
+
const t = y(e.data.data);
|
|
262
|
+
e.source.postMessage(
|
|
263
|
+
{
|
|
264
|
+
cmd: "$xt/micro/info",
|
|
265
|
+
data: {
|
|
266
|
+
mainBaseURL: window.location.origin,
|
|
267
|
+
mainMicroVersion: p,
|
|
268
|
+
name: t.name,
|
|
269
|
+
url: t.url,
|
|
270
|
+
params: t.params,
|
|
271
|
+
sync: t.sync,
|
|
272
|
+
preload: t.preload
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{ targetOrigin: e.origin }
|
|
276
|
+
);
|
|
243
277
|
}
|
|
244
278
|
});
|
|
245
|
-
},
|
|
246
|
-
const n =
|
|
247
|
-
n && (window[c.IS_MICRO] = !0)
|
|
248
|
-
|
|
279
|
+
}, ie = (...t) => R(void 0, [...t], function* (e = {}) {
|
|
280
|
+
const n = u(c.IS_MICRO), r = u(c.MICRO_NAME);
|
|
281
|
+
n && (window[c.IS_MICRO] = !0), r && S(r).then((s) => {
|
|
282
|
+
window[c.MICRO_APP] = l({
|
|
283
|
+
microVersion: p
|
|
284
|
+
}, s);
|
|
285
|
+
});
|
|
286
|
+
function o(s) {
|
|
249
287
|
var i = document.styleSheets[0];
|
|
250
288
|
if (!i) {
|
|
251
|
-
var
|
|
252
|
-
document.head.appendChild(
|
|
289
|
+
var d = document.createElement("style");
|
|
290
|
+
document.head.appendChild(d), i = d.sheet;
|
|
253
291
|
}
|
|
254
|
-
i.insertRule(
|
|
292
|
+
i.insertRule(s, i.cssRules.length);
|
|
255
293
|
}
|
|
256
|
-
window[c.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((
|
|
257
|
-
o(`${
|
|
258
|
-
}) : o(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
294
|
+
window[c.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((s) => {
|
|
295
|
+
o(`${s} { display: none !important; }`);
|
|
296
|
+
}) : o(
|
|
297
|
+
`${e.hideHeaderCssSelector} { display: none !important; }`
|
|
298
|
+
)), window.addEventListener("message", (s) => {
|
|
299
|
+
s.data.cmd === `$xt/micro/${r}` && I();
|
|
300
|
+
}), J(window);
|
|
301
|
+
const a = u(c.MICRO_TOKEN);
|
|
302
|
+
e.authHandler && a && (yield e.authHandler(a));
|
|
263
303
|
});
|
|
264
|
-
function
|
|
304
|
+
function J(e) {
|
|
265
305
|
const t = e.history, n = t.pushState, r = t.replaceState;
|
|
266
|
-
t.pushState = function(o,
|
|
267
|
-
const i =
|
|
306
|
+
t.pushState = function(o, a, s) {
|
|
307
|
+
const i = f(l(l({}, t.state || {}), o), {
|
|
268
308
|
// 添加新数据
|
|
269
309
|
_patchedByParent: !0
|
|
270
310
|
// 可选:标记这是被父窗口修改的状态
|
|
271
311
|
});
|
|
272
|
-
n.call(t, i,
|
|
273
|
-
}, t.replaceState = function(o,
|
|
274
|
-
const i =
|
|
312
|
+
n.call(t, i, a, s), I();
|
|
313
|
+
}, t.replaceState = function(o, a, s) {
|
|
314
|
+
const i = f(l(l({}, t.state || {}), o), {
|
|
275
315
|
// 添加新数据
|
|
276
316
|
_patchedByParent: !0
|
|
277
317
|
// 可选:标记这是被父窗口修改的状态
|
|
278
318
|
});
|
|
279
|
-
r.call(t, i,
|
|
319
|
+
r.call(t, i, a, s), I();
|
|
280
320
|
};
|
|
281
321
|
}
|
|
282
|
-
function
|
|
322
|
+
function I() {
|
|
283
323
|
if (!window[c.MICRO_APP])
|
|
284
324
|
return;
|
|
285
325
|
const { name: e, sync: t, mainBaseURL: n } = window[c.MICRO_APP], r = window.location.pathname + window.location.search + window.location.hash;
|
|
286
|
-
window.parent.postMessage(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
326
|
+
window.parent.postMessage(
|
|
327
|
+
{
|
|
328
|
+
cmd: "$xt/micro/sync",
|
|
329
|
+
data: {
|
|
330
|
+
name: e,
|
|
331
|
+
url: window.encodeURIComponent(r)
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
n
|
|
335
|
+
);
|
|
293
336
|
}
|
|
294
|
-
let
|
|
295
|
-
const
|
|
337
|
+
let w = {};
|
|
338
|
+
const Z = {
|
|
296
339
|
url: "",
|
|
297
340
|
name: "",
|
|
298
341
|
sync: !0
|
|
299
|
-
},
|
|
342
|
+
}, ce = (e) => {
|
|
300
343
|
if (!e.url || e.url === "" || e.url === "undefined") {
|
|
301
344
|
console.error("app url is required", e);
|
|
302
345
|
return;
|
|
303
346
|
}
|
|
304
|
-
const t = Object.assign({},
|
|
305
|
-
return
|
|
306
|
-
instance: new
|
|
307
|
-
}),
|
|
308
|
-
},
|
|
309
|
-
let o =
|
|
310
|
-
o ? (t && (o.instance.changeOptions(t), o =
|
|
311
|
-
}),
|
|
312
|
-
let t =
|
|
347
|
+
const t = Object.assign({}, Z, e);
|
|
348
|
+
return w[e.name] = f(l({}, t), {
|
|
349
|
+
instance: new G(e)
|
|
350
|
+
}), w[e.name];
|
|
351
|
+
}, y = (e) => w[e], ee = (e, t) => w[e.name] = l(l({}, e), t), te = (e, t) => new Promise((n, r) => {
|
|
352
|
+
let o = y(e);
|
|
353
|
+
o ? (t && (o.instance.changeOptions(t), o = ee(o, t)), o.preload ? o.instance.preloadRender(o.el) : o.instance.mount(o.el), n(o)) : r("app not found");
|
|
354
|
+
}), ne = (e) => {
|
|
355
|
+
let t = y(e);
|
|
313
356
|
t && t.instance.unmount();
|
|
314
|
-
},
|
|
315
|
-
let t =
|
|
357
|
+
}, de = (e) => {
|
|
358
|
+
let t = y(e);
|
|
316
359
|
t && t.instance.reload();
|
|
317
|
-
},
|
|
360
|
+
}, oe = /* @__PURE__ */ $({
|
|
318
361
|
__name: "XTMicroView",
|
|
319
362
|
props: {
|
|
320
363
|
appId: String
|
|
321
364
|
},
|
|
322
365
|
setup(e) {
|
|
323
366
|
const t = e, n = P(), r = () => {
|
|
324
|
-
t.appId &&
|
|
367
|
+
t.appId && te(t.appId, {
|
|
325
368
|
el: n.value
|
|
326
369
|
}).then((o) => {
|
|
327
370
|
console.debug("app mounted", t.appId);
|
|
328
371
|
});
|
|
329
372
|
};
|
|
330
|
-
return
|
|
331
|
-
o !==
|
|
373
|
+
return X(() => t.appId, (o, a) => {
|
|
374
|
+
o !== a && a && ne(a), r();
|
|
332
375
|
}), k(() => {
|
|
333
376
|
r();
|
|
334
|
-
}),
|
|
377
|
+
}), H(() => {
|
|
335
378
|
console.debug("app unmount", t.appId);
|
|
336
|
-
}), (o,
|
|
379
|
+
}), (o, a) => (N(), B("div", j({
|
|
337
380
|
ref_key: "refPanel",
|
|
338
381
|
ref: n
|
|
339
382
|
}, o.$attrs, { class: "xt-micro" }), null, 16));
|
|
340
383
|
}
|
|
341
384
|
});
|
|
342
|
-
|
|
385
|
+
window[c.MICRO_VERSION] = p;
|
|
386
|
+
const le = {
|
|
343
387
|
install: (e, t = {}) => {
|
|
344
|
-
e.component("xt-micro-view",
|
|
388
|
+
e.component("xt-micro-view", oe), Y();
|
|
345
389
|
}
|
|
346
390
|
};
|
|
347
391
|
export {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
392
|
+
oe as XTMicroView,
|
|
393
|
+
le as default,
|
|
394
|
+
y as getApp,
|
|
395
|
+
ie as microInit,
|
|
396
|
+
de as reloadApp,
|
|
397
|
+
ce as setupApp,
|
|
398
|
+
te as startApp,
|
|
399
|
+
ne as stopApp,
|
|
400
|
+
se as utils
|
|
357
401
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
import { default as XTMicroView } from './components/XTMicroView.vue';
|
|
3
3
|
export * from './api';
|
|
4
|
-
import * as utils from
|
|
4
|
+
import * as utils from "./utils";
|
|
5
5
|
export { XTMicroView, utils };
|
|
6
6
|
declare const _default: {
|
|
7
7
|
install: (app: App, _options?: any) => void;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -5,4 +5,12 @@ export declare function getAnchorElementQueryMap(anchorElement: HTMLAnchorElemen
|
|
|
5
5
|
[key: string]: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 向URL中添加或替换指定参数
|
|
10
|
+
* @param url - 原始URL字符串,可能包含查询参数和哈希部分
|
|
11
|
+
* @param paramName - 要添加或替换的参数名称
|
|
12
|
+
* @param paramValue - 参数对应的新值
|
|
13
|
+
* @returns 处理后的完整URL字符串
|
|
14
|
+
*/
|
|
8
15
|
export declare function addOrReplaceUrlParam(url: string, paramName: string, paramValue: string): string;
|
|
16
|
+
export declare const ipcSyncAppInfo: (microName: string) => Promise<unknown>;
|