@das-fed/upf-web 6.4.0-dev.201 → 6.4.0-dev.203

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.
@@ -1,59 +1,137 @@
1
- import { ref as v, createApp as x } from "vue";
2
- import { initTheme as w } from "@das-fed/upf-web/packages/theme/index";
3
- import { DasWebLayout as O } from "@das-fed/upf-web/packages/layout/index";
4
- import { registerMicroI18nData as P } from "@das-fed/upf-web/packages/i18n/register";
5
- import { createPinia as W } from "pinia";
6
- import $ from "pinia-plugin-persistedstate";
7
- import { createRouter as j, createWebHistory as D } from "vue-router";
8
- const k = {
9
- install: (e, a) => {
10
- var l;
11
- const c = (l = a == null ? void 0 : a.plugins) == null ? void 0 : l.glob;
12
- c && Object.values(c).sort((t, u) => (t.index ?? 0) - (u.index ?? 0)).filter((t) => t ? !!(t.default && t.default.install || t.install) : !1).forEach((t) => {
13
- t.default && t.default.install && e.use(t.default, a), t.install && e.use(t, a);
1
+ import { reactive as L, ref as j, createApp as B } from "vue";
2
+ import { initTheme as I } from "@das-fed/upf-web/packages/theme/index";
3
+ import { DasWebLayout as N } from "@das-fed/upf-web/packages/layout/index";
4
+ import { createPinia as D } from "pinia";
5
+ import W from "pinia-plugin-persistedstate";
6
+ import { createRouter as C, createWebHistory as M } from "vue-router";
7
+ import { getUrlParams as O, handleI18nData as S } from "@das-fed/upf-utils/common-tools";
8
+ import { getConfig as z } from "@das-fed/upf-utils/config";
9
+ const H = {
10
+ install: (e, n) => {
11
+ var a;
12
+ const r = (a = n == null ? void 0 : n.plugins) == null ? void 0 : a.glob;
13
+ r && Object.values(r).sort((t, s) => (t.index ?? 0) - (s.index ?? 0)).filter((t) => t ? !!(t.default && t.default.install || t.install) : !1).forEach((t) => {
14
+ t.default && t.default.install && e.use(t.default, n), t.install && e.use(t, n);
14
15
  });
15
16
  }
16
- }, d = W();
17
- d.use($);
18
- const y = (e) => {
19
- var h, b, p, g, A;
20
- const a = ((h = e == null ? void 0 : e.router) == null ? void 0 : h.routerBase) ?? "/", c = ((b = e == null ? void 0 : e.router) == null ? void 0 : b.options) || {};
21
- let l = Object.assign(((p = e == null ? void 0 : e.router) == null ? void 0 : p.glob) || {});
22
- const t = Object.values(l).filter((f) => !!f).flat().sort((f, m) => (f.index ?? 0) - (m.index ?? 0)), u = [];
23
- (g = e == null ? void 0 : e.microApps) == null || g.map((f) => {
24
- var R;
25
- const m = Object.values(((R = f.router) == null ? void 0 : R.glob) || {}).filter((r) => !!r).flat().sort((r, o) => (r.index ?? 0) - (o.index ?? 0));
26
- u.push(
27
- ...m.map((r) => ({ ...r, path: `/${f.microAppName}${r.path}` }))
28
- ), u.push(
29
- ...m.filter((r) => !!r.path).filter((r) => r.path !== "").filter((r) => r.path !== "/").filter((r) => !r.path.startsWith(`/${r.microAppName}`)).map((r) => ({
30
- path: r.path,
31
- redirect: `/${f.microAppName}${r.path}`,
32
- meta: { ...r.meta || {}, isMicroAppRouteRedirect: !0 }
17
+ }, E = D();
18
+ E.use(W);
19
+ const P = "language", A = L({});
20
+ L({});
21
+ L({});
22
+ const K = O(location.href, "uiCulture") || "", F = K || window.localStorage.getItem(P) || window.navigator.language || "zh-CN", $ = j(F), G = () => {
23
+ const e = document.documentElement;
24
+ e && e.setAttribute("lang", $.value);
25
+ }, R = (e = {}, n) => {
26
+ const r = {};
27
+ for (const a in e)
28
+ for (const t in e[a])
29
+ r[t] || (r[t] = {}), r[t][a] = e[a][t] ?? "", A[t] || (A[t] = {}), A[t][a] = r[t][a];
30
+ }, T = (e) => {
31
+ $.value = e, G();
32
+ }, q = {
33
+ loaded: {},
34
+ isLoaded(e) {
35
+ return !!this.loaded[e];
36
+ },
37
+ markLoaded(e) {
38
+ this.loaded[e] = !0;
39
+ },
40
+ markUnloaded(e) {
41
+ delete this.loaded[e];
42
+ }
43
+ }, J = async (e, n) => {
44
+ var d, g, l;
45
+ const r = z() || {}, a = ((d = r.i18n) == null ? void 0 : d.fromOss) ?? !0, t = ((g = r.i18n) == null ? void 0 : g.isPullBack) ?? !1, s = ((l = r.i18n) == null ? void 0 : l.isDasUI) ?? !0;
46
+ let i = "/oss/resource/";
47
+ try {
48
+ const f = await S({
49
+ baseUrl: a ? i : "/",
50
+ currentLang: n,
51
+ appName: e,
52
+ isPullBack: t,
53
+ fallbackBaseUrl: "/",
54
+ isDasUI: s
55
+ });
56
+ if (!f || !(f != null && f.frontEnd))
57
+ throw new Error("Failed to fetch i18n data");
58
+ return f;
59
+ } catch (h) {
60
+ throw new Error(`registerResources error: ${h}`);
61
+ }
62
+ }, Q = async (e = []) => {
63
+ const n = O(location.href, "uiCulture") || window.localStorage.getItem(P) || window.navigator.language || "zh-CN";
64
+ try {
65
+ const r = await J(e, n);
66
+ r != null && r.frontEnd && typeof r.frontEnd == "object" && Object.keys(r.frontEnd).length && e.forEach((a) => {
67
+ r.frontEnd[a] && typeof r.frontEnd[a] == "object" && Object.keys(r.frontEnd[a]).length && R({ [n]: r.frontEnd[a] });
68
+ }), r != null && r.dasUiEnd && typeof r.dasUiEnd == "object" && Object.keys(r.dasUiEnd).length && R({ [n]: r.dasUiEnd }), T(n);
69
+ } catch {
70
+ }
71
+ }, V = (e) => {
72
+ var h, p, f, U, v;
73
+ const n = ((h = e == null ? void 0 : e.router) == null ? void 0 : h.routerBase) ?? "/", r = ((p = e == null ? void 0 : e.router) == null ? void 0 : p.options) || {};
74
+ let a = Object.assign(((f = e == null ? void 0 : e.router) == null ? void 0 : f.glob) || {});
75
+ const t = Object.values(a).filter((u) => !!u).flat().sort((u, o) => (u.index ?? 0) - (o.index ?? 0)), s = [];
76
+ (U = e == null ? void 0 : e.microApps) == null || U.map((u) => {
77
+ var w;
78
+ const o = Object.values(((w = u.router) == null ? void 0 : w.glob) || {}).filter((c) => !!c).flat().sort((c, y) => (c.index ?? 0) - (y.index ?? 0));
79
+ s.push(
80
+ ...o.map((c) => ({ ...c, path: `/${u.microAppName}${c.path}` }))
81
+ ), s.push(
82
+ ...o.filter((c) => !!c.path).filter((c) => c.path !== "").filter((c) => c.path !== "/").filter((c) => !c.path.startsWith(`/${c.microAppName}`)).map((c) => ({
83
+ path: c.path,
84
+ redirect: `/${u.microAppName}${c.path}`,
85
+ meta: { ...c.meta || {}, isMicroAppRouteRedirect: !0 }
33
86
  }))
34
87
  );
35
88
  });
36
- const s = ((A = e == null ? void 0 : e.router) == null ? void 0 : A.routers) || [], n = [
37
- ...i(t, e),
38
- ...i(s, e),
39
- ...i(u, e)
40
- ];
41
- return { router: j({ history: D(a), routes: n, ...c }) };
42
- }, i = (e, a) => e.map((c) => {
43
- const l = c.meta || {};
44
- return l.keepAlive = l.keepAlive ?? (a == null ? void 0 : a.keepAlive) ?? !0, { ...c, meta: l };
45
- }), q = (e) => {
46
- var n;
89
+ const i = ((v = e == null ? void 0 : e.router) == null ? void 0 : v.routers) || [], d = [
90
+ ...k(t, e),
91
+ ...k(i, e),
92
+ ...k(s, e)
93
+ ], g = C({ history: M(n), routes: d, ...r }), l = q;
94
+ if (Array.isArray(e == null ? void 0 : e.microApps) && e.microApps.length && l) {
95
+ const u = /* @__PURE__ */ new Map();
96
+ for (const o of e.microApps)
97
+ o != null && o.microAppName && (o != null && o.i18n) && u.set(o.microAppName, o.i18n);
98
+ g.beforeEach(async (o, w, c) => {
99
+ try {
100
+ const y = o.path || "";
101
+ for (const [b, m] of u.entries()) {
102
+ if (!b || !y.toLowerCase().startsWith(`/${b.toLowerCase()}`)) continue;
103
+ if (typeof l.isLoaded == "function" && l.isLoaded(b) || !m || !(m != null && m.length)) break;
104
+ const x = typeof m == "string" ? [m] : m;
105
+ typeof l.markLoaded == "function" && l.markLoaded(b);
106
+ try {
107
+ await Q(x);
108
+ } catch {
109
+ typeof l.markUnloaded == "function" && l.markUnloaded(b);
110
+ }
111
+ break;
112
+ }
113
+ } catch {
114
+ } finally {
115
+ c();
116
+ }
117
+ });
118
+ }
119
+ return { router: g };
120
+ }, k = (e, n) => e.map((r) => {
121
+ const a = r.meta || {};
122
+ return a.keepAlive = a.keepAlive ?? (n == null ? void 0 : n.keepAlive) ?? !0, { ...r, meta: a };
123
+ }), ce = (e) => {
124
+ var d;
47
125
  e || (e = {});
48
- const a = v(!0);
49
- Promise.all([w(e), P(e)]).then(() => {
50
- a.value = !1;
126
+ const n = j(!0);
127
+ Promise.all([I(e)]).then(() => {
128
+ n.value = !1;
51
129
  });
52
- const { container: c, component: l, props: t } = (e == null ? void 0 : e.root) || {}, u = x(l || O, t);
53
- u.use(k, e), u.use(d);
54
- const { router: s } = y(e);
55
- return u.use(s), u.mount(c || "#app"), (n = window.top) != null && n.vueRouter || window.top && (window.top.vueRouter = s), { app: u, router: s, loading: a, store: d };
130
+ const { container: r, component: a, props: t } = (e == null ? void 0 : e.root) || {}, s = B(a || N, t);
131
+ s.use(H, e), s.use(E);
132
+ const { router: i } = V(e);
133
+ return s.use(i), s.mount(r || "#app"), (d = window.top) != null && d.vueRouter || window.top && (window.top.vueRouter = i), { app: s, router: i, loading: n, store: E };
56
134
  };
57
135
  export {
58
- q as createDasWebApp
136
+ ce as createDasWebApp
59
137
  };
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ import { langType } from './type';
2
+
3
+ /**
4
+ * 内存存储:记录本次页面会话中哪些 micro app 的 i18n 已加载。
5
+ */
6
+ export declare const microI18nStore: {
7
+ loaded: Record<string, boolean>;
8
+ isLoaded(name: string): boolean;
9
+ markLoaded(name: string): void;
10
+ markUnloaded(name: string): void;
11
+ };
12
+ export declare const registerI18nData: (appName: string[], currentLang: langType) => Promise<Record<string, any>>;
13
+ export declare const registerMicroI18nData: (i18nCodes?: string[]) => Promise<void>;
package/types/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './create-das-web-app';
2
2
  export * from './i18n';
3
- export * from './i18n/register';
4
3
  export * from './theme';
5
4
  export * from './layout';
6
5
  export * from './micro-frontend';
Binary file
Binary file
@@ -1,4 +0,0 @@
1
- import { langType } from './type';
2
-
3
- export declare const registerI18nData: (appName: string[], currentLang: langType, cb: any) => Promise<void>;
4
- export declare const registerMicroI18nData: (opt?: any) => void;