@skyfox2000/microbase 1.0.15 → 1.2.1

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/.cursorignore ADDED
@@ -0,0 +1,8 @@
1
+ # Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
2
+ target/
3
+ dist/
4
+ lib/
5
+ demo/
6
+ mock
7
+ node_modules/
8
+ .vscode/
package/lib/index.d.ts CHANGED
@@ -111,6 +111,13 @@ export declare enum AppSource {
111
111
  */
112
112
  export declare const combineParams: (...args: (ReqParams | undefined)[]) => ReqParams;
113
113
 
114
+ /**
115
+ * 统一环境变量配置
116
+ */
117
+ export declare const EnvConfig: {
118
+ [key: string]: string;
119
+ };
120
+
114
121
  /**
115
122
  * 启动配置信息
116
123
  * - 网站配置信息
@@ -168,6 +175,11 @@ export declare interface HostInfo {
168
175
  [key: string]: any;
169
176
  }
170
177
 
178
+ /**
179
+ * 初始化环境变量
180
+ */
181
+ export declare const initEnv: (metaEnv: ImportMetaEnv) => void;
182
+
171
183
  /**
172
184
  * 从页面加载处获取接口
173
185
  */
@@ -258,7 +270,7 @@ export declare interface MainOpenApis {
258
270
  /**
259
271
  * 获取当前应用AppInfo
260
272
  */
261
- getAppInfo: () => AppInfo;
273
+ getAppInfo?: () => AppInfo;
262
274
  /**
263
275
  * 用户注册接口
264
276
  */
@@ -275,11 +287,11 @@ export declare interface MainOpenApis {
275
287
  * 获取授权码
276
288
  * @returns 授权码
277
289
  */
278
- getToken: () => string;
290
+ getToken?: () => string;
279
291
  /**
280
292
  * 获取当前用户信息
281
293
  */
282
- getUserInfo: () => UserInfo;
294
+ getUserInfo?: () => UserInfo;
283
295
  /**
284
296
  * 获取前端设置信息
285
297
  */
@@ -1,47 +1,50 @@
1
1
  import { deepClone as l } from "@skyfox2000/fapi";
2
2
  import { ref as o, markRaw as p, h as a } from "vue";
3
- import { createRouter as m, createWebHashHistory as d } from "vue-router";
3
+ import { createRouter as d, createWebHashHistory as m } from "vue-router";
4
4
  var v = /* @__PURE__ */ ((e) => (e.Market = "Market", e.Manual = "Manual", e))(v || {}), y = /* @__PURE__ */ ((e) => (e.App = "App", e.MenuApp = "MenuApp", e.Link = "Link", e.Iframe = "Iframe", e))(y || {});
5
- const r = (e, n) => {
6
- if (!(!n || !e))
7
- for (const t in n)
8
- t in e && typeof e[t] == "object" && typeof n[t] == "object" && !Array.isArray(n[t]) ? r(e[t], n[t]) : e[t] = l(n[t]);
9
- }, P = (...e) => {
10
- const n = {};
11
- for (const t of e)
12
- t != null && t.Option && !n.Option && (n.Option = {}), r(n.Option, t == null ? void 0 : t.Option);
13
- for (const t of e)
14
- t != null && t.Query && !n.Query && (n.Query = {}), r(n.Query, t == null ? void 0 : t.Query);
15
- for (const t of e)
16
- n.Data = t != null && t.Data ? l(t.Data) : {};
17
- return n;
18
- }, I = () => !!window.__MICRO_APP_ENVIRONMENT__, k = () => !!window.__MICRO_APP_BASE_APPLICATION__, i = o(), A = o(), M = o(), R = () => {
5
+ const r = (e, t) => {
6
+ if (!(!t || !e))
7
+ for (const n in t)
8
+ n in e && typeof e[n] == "object" && typeof t[n] == "object" && !Array.isArray(t[n]) ? r(e[n], t[n]) : e[n] = l(t[n]);
9
+ }, k = (...e) => {
10
+ const t = {};
11
+ for (const n of e)
12
+ n != null && n.Option && !t.Option && (t.Option = {}), r(t.Option, n == null ? void 0 : n.Option);
13
+ for (const n of e)
14
+ n != null && n.Query && !t.Query && (t.Query = {}), r(t.Query, n == null ? void 0 : n.Query);
15
+ for (const n of e)
16
+ t.Data = n != null && n.Data ? l(n.Data) : {};
17
+ return t;
18
+ }, I = () => !!window.__MICRO_APP_ENVIRONMENT__, C = () => !!window.__MICRO_APP_BASE_APPLICATION__, i = o(), A = o(), M = o(), E = () => {
19
19
  const e = window.microApp.getData(
20
20
  !0
21
21
  );
22
22
  e && (i.value = e.MainApis, A.value = e.MainEvents, M.value = e.pageUrl);
23
- }, w = [
23
+ }, w = {}, R = (e) => {
24
+ for (const t in e)
25
+ w[t] = e[t];
26
+ }, _ = [
24
27
  {
25
28
  path: "/:page(.*)",
26
29
  name: "默认页面",
27
30
  component: () => import("./assets/modules/index-DQ8DfP_z.js")
28
31
  }
29
- ], u = m({
30
- history: d(void 0),
31
- routes: w
32
+ ], u = d({
33
+ history: m(void 0),
34
+ routes: _
32
35
  });
33
36
  u.afterEach((e) => {
34
37
  if (i.value) {
35
- const { mainAppPush: n } = i.value;
36
- n && n(e.hash);
38
+ const { mainAppPush: t } = i.value;
39
+ t && t(e.hash);
37
40
  }
38
41
  });
39
- const C = o({}), c = o(""), f = o({}), s = o(null), _ = async (e) => {
42
+ const L = o({}), c = o(""), f = o({}), s = o(null), h = async (e) => {
40
43
  c.value = e, e.startsWith("/") && (e = e.substring(1));
41
- const n = f.value[`./views/${e}.vue`];
42
- if (n) {
43
- const t = await n();
44
- s.value = p(t.default), u.replace("/" + e);
44
+ const t = f.value[`./views/${e}.vue`];
45
+ if (t) {
46
+ const n = await t();
47
+ s.value = p(n.default), u.replace("/" + e);
45
48
  } else
46
49
  console.error("加载微模块" + e + "失败"), s.value = a(
47
50
  "div",
@@ -58,27 +61,29 @@ const C = o({}), c = o(""), f = o({}), s = o(null), _ = async (e) => {
58
61
  },
59
62
  [a("div", "404 NOT FOUND")]
60
63
  );
61
- }, E = (e) => {
62
- f.value = e, window.microApp && window.microApp.addDataListener(async (n) => {
63
- if (n.pageUrl === c.value) return;
64
- let t = n.pageUrl;
65
- t ? _(t) : console.error("微模块地址为空");
64
+ }, N = (e) => {
65
+ f.value = e, window.microApp && window.microApp.addDataListener(async (t) => {
66
+ if (t.pageUrl === c.value) return;
67
+ let n = t.pageUrl;
68
+ n ? h(n) : console.error("微模块地址为空");
66
69
  }, !0);
67
70
  };
68
71
  export {
69
72
  y as AppAction,
70
73
  v as AppSource,
74
+ w as EnvConfig,
71
75
  u as LoaderRouter,
72
- P as combineParams,
73
- R as initMainAppData,
74
- E as initModuleLoader,
75
- k as isBaseMicroApp,
76
+ k as combineParams,
77
+ R as initEnv,
78
+ E as initMainAppData,
79
+ N as initModuleLoader,
80
+ C as isBaseMicroApp,
76
81
  I as isMicroApp,
77
- _ as loadModule,
82
+ h as loadModule,
78
83
  i as mainAppApis,
79
84
  A as mainAppEvents,
80
85
  M as mainPageUrl,
81
- C as moduleAttrs,
86
+ L as moduleAttrs,
82
87
  s as moduleCom,
83
88
  f as moduleRecords,
84
89
  c as moduleUrl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyfox2000/microbase",
3
- "version": "1.0.15",
3
+ "version": "1.2.1",
4
4
  "description": "微前端通用功能与数据类型定义",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -22,8 +22,9 @@
22
22
  "build": "vue-tsc -b && vite build",
23
23
  "preview": "vite preview"
24
24
  },
25
- "dependencies": {
26
- "@micro-zoe/micro-app": "1.0.0-rc.18",
25
+ "peerDependencies": {
26
+ "@skyfox2000/fapi": "^1.1.19",
27
+ "@micro-zoe/micro-app": "^1.0.0-rc.18",
27
28
  "vue": "^3.5.13",
28
29
  "vue-router": "^4.5.0"
29
30
  },
package/src/index.ts CHANGED
@@ -6,14 +6,17 @@ import type { LoginInfo, UserInfo } from "@/stores/userInfo.d";
6
6
 
7
7
  import { combineParams } from "@/utils/data";
8
8
 
9
- import {
10
- isMicroApp,
11
- isBaseMicroApp,
12
- mainAppApis,
13
- mainAppEvents,
14
- mainPageUrl,
15
- initMainAppData
9
+ import {
10
+ isMicroApp,
11
+ isBaseMicroApp,
12
+ mainAppApis,
13
+ mainAppEvents,
14
+ mainPageUrl,
15
+ initMainAppData,
16
+ EnvConfig,
17
+ initEnv,
16
18
  } from "@/utils/micro-app";
19
+
17
20
  import type {
18
21
  MainAppData,
19
22
  MainOpenApis,
@@ -44,13 +47,15 @@ export type { LoginInfo, UserInfo };
44
47
 
45
48
  export { combineParams };
46
49
 
47
- export {
48
- isMicroApp,
49
- isBaseMicroApp,
50
- mainAppApis,
51
- mainAppEvents,
52
- mainPageUrl,
53
- initMainAppData
50
+ export {
51
+ isMicroApp,
52
+ isBaseMicroApp,
53
+ mainAppApis,
54
+ mainAppEvents,
55
+ mainPageUrl,
56
+ initMainAppData,
57
+ EnvConfig,
58
+ initEnv,
54
59
  };
55
60
  export type {
56
61
  MainAppData,
@@ -57,7 +57,7 @@ export interface MainOpenApis {
57
57
  /**
58
58
  * 获取当前应用AppInfo
59
59
  */
60
- getAppInfo: () => AppInfo;
60
+ getAppInfo?: () => AppInfo;
61
61
  /**
62
62
  * 用户注册接口
63
63
  */
@@ -74,11 +74,11 @@ export interface MainOpenApis {
74
74
  * 获取授权码
75
75
  * @returns 授权码
76
76
  */
77
- getToken: () => string;
77
+ getToken?: () => string;
78
78
  /**
79
79
  * 获取当前用户信息
80
80
  */
81
- getUserInfo: () => UserInfo;
81
+ getUserInfo?: () => UserInfo;
82
82
  /**
83
83
  * 获取前端设置信息
84
84
  */
@@ -115,3 +115,19 @@ export const initMainAppData = () => {
115
115
  mainPageUrl.value = mainAppData.pageUrl;
116
116
  }
117
117
  };
118
+
119
+ /**
120
+ * 统一环境变量配置
121
+ */
122
+ export const EnvConfig: {
123
+ [key: string]: string;
124
+ } = {};
125
+
126
+ /**
127
+ * 初始化环境变量
128
+ */
129
+ export const initEnv = (metaEnv: ImportMetaEnv) => {
130
+ for (const key in metaEnv) {
131
+ EnvConfig[key] = metaEnv[key];
132
+ }
133
+ };
package/vite.config.ts CHANGED
@@ -8,7 +8,7 @@ import dts from "vite-plugin-dts";
8
8
  export default defineConfig(({ mode }: ConfigEnv) => {
9
9
  const root = process.cwd();
10
10
  const env = loadEnv(mode, root);
11
- console.log(env);
11
+ console.log(new Date().toLocaleTimeString(), " ", env);
12
12
 
13
13
  return {
14
14
  plugins: [