@xingtukeji/micro 1.1.9 → 1.1.11

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 CHANGED
@@ -1,41 +1,50 @@
1
1
  主应用初始化:
2
+
2
3
  ```javascript
3
4
  //主微应用加载插件,注意一定要在 pinia 初始化之后
4
- import xtMicro, { setupApp } from '@xingtukeji/micro'
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
- if(item.type === 'micro'){
12
- // 设置应用
13
- setupApp({
14
- ...item.microOptions,
15
- token: () => useUserStore().token,
16
- params: item.microOptions?.params || {},
17
- })
18
- }
19
- // 如果当前菜单项有子菜单,则递归遍历子菜单
20
- if (item.children) {
21
- traverseMenu(item.children);
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 '@xingtukeji/micro'
33
+ import { microInit } from "@xingtukeji/micro";
32
34
  microInit({
33
35
  // 处理 token,该方法建议同步执行完成,如果有异步处理(比如 http 请求)请后续页面初始化时,判断 token 是否准备完毕。
34
- authHandler: (token: string)=>{
35
- window.localStorage.setItem('token', token)
36
+ authHandler: (token: string) => {
37
+ window.localStorage.setItem("token", token);
36
38
  //or pinia store set token
37
39
  },
38
40
  //简易处理微应用环境下,隐藏 header
39
- hideHeaderCssSelector: '#app ._hedaui-header'
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 U = Object.defineProperty, A = Object.defineProperties;
3
- var L = Object.getOwnPropertyDescriptors;
4
- var g = Object.getOwnPropertySymbols;
5
- var b = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
6
- var y = (e, t, n) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
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, d = (e, t) => {
7
7
  for (var n in t || (t = {}))
8
- b.call(t, n) && y(e, n, t[n]);
9
- if (g)
10
- for (var n of g(t))
11
- T.call(t, n) && y(e, n, t[n]);
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
- }, m = (e, t) => A(e, L(t));
14
- var u = (e, t, n) => (y(e, typeof t != "symbol" ? t + "" : t, n), n);
15
- var I = (e, t, n) => new Promise((r, o) => {
16
- var s = (l) => {
13
+ }, f = (e, t) => v(e, b(t));
14
+ var m = (e, t, n) => (_(e, typeof t != "symbol" ? t + "" : t, n), n);
15
+ var g = (e, t, n) => new Promise((r, o) => {
16
+ var a = (l) => {
17
17
  try {
18
18
  i(n.next(l));
19
19
  } catch (h) {
20
20
  o(h);
21
21
  }
22
- }, a = (l) => {
22
+ }, s = (l) => {
23
23
  try {
24
24
  i(n.throw(l));
25
25
  } catch (h) {
26
26
  o(h);
27
27
  }
28
- }, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(s, a);
28
+ }, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(a, s);
29
29
  i((n = n.apply(e, t)).next());
30
30
  });
31
- import { ref as P, defineComponent as v, watch as x, onMounted as k, onUnmounted as X, openBlock as $, createElementBlock as H, mergeProps as N } from "vue";
31
+ import { ref as P, defineComponent as $, watch as X, onMounted as k, onUnmounted as H, openBlock as N, createElementBlock as j, mergeProps as B } 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
- };
47
+ MICRO_VERSION: "__XT_MICRO_VERSION"
48
+ // 微应用版本
49
+ }, u = "1.1.11";
48
50
  function p(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 O(e, t, n) {
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 B(e) {
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 j(e) {
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 F(e, t) {
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 E(e, t, n) {
78
- const [r, o] = e.split("#"), s = new URL(r), a = s.searchParams;
79
- return t = c.URL_PARAM_PREFIX + t, a.has(t) ? a.set(t, n) : a.append(t, n), o && (s.hash = o), s.search = a.toString(), s.toString();
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 re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
83
+ const S = (e) => g(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 !== u && console.warn(
87
+ `子应用版本与主应用版本不一致,${e}子应用版本:${u},主应用版本:${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: E,
84
- anchorElementGenerator: B,
85
- debounce: F,
86
- getAbsolutePath: O,
87
- getAnchorElementQueryMap: j,
88
- getQueryParameter: p
89
- }, Symbol.toStringTag, { value: "Module" })), M = P(!1);
99
+ addOrReplaceUrlParam: C,
100
+ anchorElementGenerator: V,
101
+ debounce: K,
102
+ getAbsolutePath: E,
103
+ getAnchorElementQueryMap: F,
104
+ getQueryParameter: p,
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 M.value;
109
+ return O.value;
93
110
  },
94
111
  set: function(e) {
95
- M.value = e;
112
+ O.value = e;
96
113
  }
97
114
  });
98
- const w = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
115
+ const R = (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
- ), s = p(c.URL_PARAM_PREFIX + e.name);
105
- if (s) {
106
- const i = O(s, e.url, !0);
121
+ ), a = p(c.URL_PARAM_PREFIX + e.name);
122
+ if (a) {
123
+ const i = E(a, e.url, !0);
107
124
  if (i) {
108
125
  const l = new URL(i);
109
- l.searchParams.forEach((C, S) => {
110
- o.searchParams.set(S, C);
126
+ l.searchParams.forEach((A, U) => {
127
+ o.searchParams.set(U, A);
111
128
  }), o.hash = l.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 a = new URL(window.location.href);
118
- return a.searchParams.delete(e.name), window.history.replaceState({}, "", a.href), o.href;
119
- }, D = () => {
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
- }, W = (e) => {
139
+ }, q = (e) => {
123
140
  e.style.opacity = "0", setTimeout(() => {
124
141
  e.remove();
125
142
  }, 500);
126
- }, q = (e) => {
143
+ }, z = (e) => {
127
144
  const t = document.createElement("iframe");
128
- t.id = w(e.app.name);
129
- const n = K(e.app);
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["color-scheme"] = "none", t.style.visibility = "hidden", t.addEventListener("load", (o) => (t.style.visibility = "visible", e.onLoad.call(e, o))), t.addEventListener(
145
+ t.id = R(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"] = "unset", 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((s) => {
139
- Array.from(s.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
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 z {
161
+ class G {
145
162
  constructor(t) {
146
- u(this, "app");
147
- u(this, "dom");
148
- u(this, "panel");
149
- u(this, "loading");
150
- u(this, "loadingTimer");
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(w(this.app.name));
158
- o || (o = q(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
159
- const s = D();
174
+ let o = document.getElementById(R(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 = s, r.appendChild(s);
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(w(this.app.name));
185
+ const t = document.getElementById(R(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
@@ -193,16 +210,16 @@ class z {
193
210
  this.app = d(d({}, this.app), t);
194
211
  }
195
212
  onLoad(t) {
196
- console.debug("app onLoad", this.app.name, t, this.loading), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && W(this.loading), G(this), this.app.onLoad && this.app.onLoad(t, this);
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, t), this.app.onUnload && this.app.onUnload(t, this);
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, t), this.app.onError && this.app.onError(t, this);
219
+ console.error("app onError", this.app.name), this.app.onError && this.app.onError(t, this);
203
220
  }
204
221
  }
205
- const G = (e) => {
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
- }, Q = () => {
237
+ }, Y = () => {
221
238
  window.addEventListener("message", (e) => {
222
239
  if (e.data.cmd === "$xt/micro/sync") {
223
240
  const t = [
@@ -228,130 +245,167 @@ const G = (e) => {
228
245
  window.decodeURIComponent(e.data.data.url),
229
246
  e.origin
230
247
  );
231
- for (let s of t)
232
- n.searchParams.delete(s);
248
+ for (let a of t)
249
+ n.searchParams.delete(a);
233
250
  const r = new URL(window.location.href);
234
- r.searchParams.forEach((s, a) => {
235
- a.startsWith(c.URL_PARAM_PREFIX) && r.searchParams.delete(a);
251
+ r.searchParams.forEach((a, s) => {
252
+ s.startsWith(c.URL_PARAM_PREFIX) && r.searchParams.delete(s);
236
253
  });
237
- const o = E(
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
+ mainLocation: {
267
+ origin: window.location.origin,
268
+ href: window.location.href,
269
+ pathname: window.location.pathname,
270
+ search: window.location.search,
271
+ hash: window.location.hash,
272
+ host: window.location.host,
273
+ hostname: window.location.hostname,
274
+ port: window.location.port,
275
+ protocol: window.location.protocol
276
+ },
277
+ mainMicroVersion: u,
278
+ name: t.name,
279
+ url: t.url,
280
+ params: t.params,
281
+ sync: t.sync,
282
+ preload: t.preload
283
+ }
284
+ },
285
+ { targetOrigin: e.origin }
286
+ );
243
287
  }
244
288
  });
245
- }, se = (...t) => I(void 0, [...t], function* (e = {}) {
289
+ }, ie = (...t) => g(void 0, [...t], function* (e = {}) {
246
290
  const n = p(c.IS_MICRO), r = p(c.MICRO_NAME);
247
- n && (window[c.IS_MICRO] = !0);
248
- function o(a) {
291
+ n && (window[c.IS_MICRO] = !0), r && S(r).then((s) => {
292
+ window[c.MICRO_APP] = d({
293
+ microVersion: u
294
+ }, s);
295
+ });
296
+ function o(s) {
249
297
  var i = document.styleSheets[0];
250
298
  if (!i) {
251
299
  var l = document.createElement("style");
252
300
  document.head.appendChild(l), i = l.sheet;
253
301
  }
254
- i.insertRule(a, i.cssRules.length);
302
+ i.insertRule(s, i.cssRules.length);
255
303
  }
256
- window[c.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((a) => {
257
- o(`${a} { display: none !important; }`);
258
- }) : o(`${e.hideHeaderCssSelector} { display: none !important; }`)), window.addEventListener("message", (a) => {
259
- a.data.cmd === `$xt/micro/${r}` && (window[c.MICRO_APP] = m(d({}, a.data.data), { mainBaseURL: a.origin }), _());
260
- }), Y(window);
261
- const s = p(c.MICRO_TOKEN);
262
- e.authHandler && s && (yield e.authHandler(s));
304
+ window[c.IS_MICRO] && e.hideHeaderCssSelector && (Array.isArray(e.hideHeaderCssSelector) ? e.hideHeaderCssSelector.forEach((s) => {
305
+ o(`${s} { display: none !important; }`);
306
+ }) : o(
307
+ `${e.hideHeaderCssSelector} { display: none !important; }`
308
+ )), window.addEventListener("message", (s) => {
309
+ s.data.cmd === `$xt/micro/${r}` && I();
310
+ }), J(window);
311
+ const a = p(c.MICRO_TOKEN);
312
+ e.authHandler && a && (yield e.authHandler(a));
263
313
  });
264
- function Y(e) {
314
+ function J(e) {
265
315
  const t = e.history, n = t.pushState, r = t.replaceState;
266
- t.pushState = function(o, s, a) {
267
- const i = m(d(d({}, t.state || {}), o), {
316
+ t.pushState = function(o, a, s) {
317
+ const i = f(d(d({}, t.state || {}), o), {
268
318
  // 添加新数据
269
319
  _patchedByParent: !0
270
320
  // 可选:标记这是被父窗口修改的状态
271
321
  });
272
- n.call(t, i, s, a), _();
273
- }, t.replaceState = function(o, s, a) {
274
- const i = m(d(d({}, t.state || {}), o), {
322
+ n.call(t, i, a, s), I();
323
+ }, t.replaceState = function(o, a, s) {
324
+ const i = f(d(d({}, t.state || {}), o), {
275
325
  // 添加新数据
276
326
  _patchedByParent: !0
277
327
  // 可选:标记这是被父窗口修改的状态
278
328
  });
279
- r.call(t, i, s, a), _();
329
+ r.call(t, i, a, s), I();
280
330
  };
281
331
  }
282
- function _() {
332
+ function I() {
283
333
  if (!window[c.MICRO_APP])
284
334
  return;
285
335
  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
- cmd: "$xt/micro/sync",
288
- data: {
289
- name: e,
290
- url: window.encodeURIComponent(r)
291
- }
292
- }, n);
336
+ window.parent.postMessage(
337
+ {
338
+ cmd: "$xt/micro/sync",
339
+ data: {
340
+ name: e,
341
+ url: window.encodeURIComponent(r)
342
+ }
343
+ },
344
+ n
345
+ );
293
346
  }
294
- let f = {};
295
- const J = {
347
+ let w = {};
348
+ const Z = {
296
349
  url: "",
297
350
  name: "",
298
351
  sync: !0
299
- }, ae = (e) => {
352
+ }, ce = (e) => {
300
353
  if (!e.url || e.url === "" || e.url === "undefined") {
301
354
  console.error("app url is required", e);
302
355
  return;
303
356
  }
304
- const t = Object.assign({}, J, e);
305
- return f[e.name] = m(d({}, t), {
306
- instance: new z(e)
307
- }), f[e.name];
308
- }, R = (e) => f[e], V = (e, t) => f[e.name] = d(d({}, e), t), Z = (e, t) => new Promise((n, r) => {
309
- let o = R(e);
310
- o ? (t && (o.instance.changeOptions(t), o = V(o, t)), o.preload ? o.instance.preloadRender(o.el) : o.instance.mount(o.el), n(o)) : r("app not found");
311
- }), ee = (e) => {
312
- let t = R(e);
357
+ const t = Object.assign({}, Z, e);
358
+ return w[e.name] = f(d({}, t), {
359
+ instance: new G(e)
360
+ }), w[e.name];
361
+ }, y = (e) => w[e], ee = (e, t) => w[e.name] = d(d({}, e), t), te = (e, t) => new Promise((n, r) => {
362
+ let o = y(e);
363
+ 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");
364
+ }), ne = (e) => {
365
+ let t = y(e);
313
366
  t && t.instance.unmount();
314
- }, ie = (e) => {
315
- let t = R(e);
367
+ }, le = (e) => {
368
+ let t = y(e);
316
369
  t && t.instance.reload();
317
- }, te = /* @__PURE__ */ v({
370
+ }, oe = /* @__PURE__ */ $({
318
371
  __name: "XTMicroView",
319
372
  props: {
320
373
  appId: String
321
374
  },
322
375
  setup(e) {
323
376
  const t = e, n = P(), r = () => {
324
- t.appId && Z(t.appId, {
377
+ t.appId && te(t.appId, {
325
378
  el: n.value
326
379
  }).then((o) => {
327
380
  console.debug("app mounted", t.appId);
328
381
  });
329
382
  };
330
- return x(() => t.appId, (o, s) => {
331
- o !== s && s && ee(s), r();
383
+ return X(() => t.appId, (o, a) => {
384
+ o !== a && a && ne(a), r();
332
385
  }), k(() => {
333
386
  r();
334
- }), X(() => {
387
+ }), H(() => {
335
388
  console.debug("app unmount", t.appId);
336
- }), (o, s) => ($(), H("div", N({
389
+ }), (o, a) => (N(), j("div", B({
337
390
  ref_key: "refPanel",
338
391
  ref: n
339
392
  }, o.$attrs, { class: "xt-micro" }), null, 16));
340
393
  }
341
394
  });
342
- const ce = {
395
+ window[c.MICRO_VERSION] = u;
396
+ const de = {
343
397
  install: (e, t = {}) => {
344
- e.component("xt-micro-view", te), Q();
398
+ e.component("xt-micro-view", oe), Y();
345
399
  }
346
400
  };
347
401
  export {
348
- te as XTMicroView,
349
- ce as default,
350
- R as getApp,
351
- se as microInit,
352
- ie as reloadApp,
353
- ae as setupApp,
354
- Z as startApp,
355
- ee as stopApp,
356
- re as utils
402
+ oe as XTMicroView,
403
+ de as default,
404
+ y as getApp,
405
+ ie as microInit,
406
+ le as reloadApp,
407
+ ce as setupApp,
408
+ te as startApp,
409
+ ne as stopApp,
410
+ se as utils
357
411
  };
@@ -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 './utils';
4
+ import * as utils from "./utils";
5
5
  export { XTMicroView, utils };
6
6
  declare const _default: {
7
7
  install: (app: App, _options?: any) => void;
@@ -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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingtukeji/micro",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "dist/index.js",