@litianxiang/portal-core 0.1.21 → 0.1.23

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/package.json CHANGED
@@ -1,19 +1,32 @@
1
1
  {
2
2
  "name": "@litianxiang/portal-core",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
9
16
  "files": [
10
17
  "dist"
11
18
  ],
12
19
  "scripts": {
13
- "build": "tsup src/index.ts --format esm --dts"
20
+ "clean": "rm -rf dist",
21
+ "build": "pnpm run clean && tsup src/index.ts --format esm --dts",
22
+ "pack:check": "pnpm run build && pnpm pack --pack-destination /tmp"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
14
26
  },
15
27
  "peerDependencies": {
16
28
  "vue": "^3.5.0",
29
+ "vue-i18n": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0-0",
17
30
  "vue-router": "^4.5.0"
18
31
  },
19
32
  "dependencies": {
@@ -22,7 +35,8 @@
22
35
  },
23
36
  "devDependencies": {
24
37
  "tsup": "^8.3.0",
25
- "typescript": "^5.6.3"
38
+ "typescript": "^5.6.3",
39
+ "vue-i18n": "^11.2.8"
26
40
  },
27
41
  "license": "UNLICENSED"
28
42
  }
package/dist/index.cjs DELETED
@@ -1,183 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- createAppRouter: () => createAppRouter
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
-
27
- // src/router.ts
28
- var import_vue_router = require("vue-router");
29
- var import_meta = {};
30
- function createAppRouter(options) {
31
- const { staticRoutes, getUserStore, getTabStore, getFirstPage, authLoginUrl } = options;
32
- const router = (0, import_vue_router.createRouter)({
33
- history: (0, import_vue_router.createWebHashHistory)(),
34
- routes: staticRoutes
35
- });
36
- const AUTH_LOGIN_URL = authLoginUrl || `${window.location.origin}/auth/#/login`;
37
- const modules = import_meta.glob("@/views/**/*.vue");
38
- const registeredPaths = /* @__PURE__ */ new Set();
39
- const resolveRouteAndView = (item) => {
40
- const [rawPath] = (item.path || "").split("?");
41
- const normalizedPath = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
42
- const routePath = normalizedPath.slice(1);
43
- const candidates = [
44
- `/main${normalizedPath}`,
45
- // /views/main/system/user.vue
46
- `${normalizedPath}`
47
- // /views/system/user.vue 或 /views/kq/leave.vue
48
- ];
49
- let viewKey = "";
50
- for (const viewPath of candidates) {
51
- const key = `/src/views${viewPath}.vue`;
52
- if (key in modules) {
53
- viewKey = key;
54
- break;
55
- }
56
- }
57
- if (!viewKey) {
58
- const fallbackPath = `/main${normalizedPath}`;
59
- viewKey = `/src/views${fallbackPath}.vue`;
60
- }
61
- return { routePath, viewKey };
62
- };
63
- const transformRoutes = (menuItems) => {
64
- const routes = [];
65
- for (const item of menuItems) {
66
- if (item.category === "button") continue;
67
- const { routePath, viewKey } = resolveRouteAndView(item);
68
- const isPage = item.category === "page" || item.category === "flow-page";
69
- if (!registeredPaths.has(routePath)) {
70
- registeredPaths.add(routePath);
71
- routes.push({
72
- path: routePath,
73
- name: `menu_${item.id}`,
74
- component: isPage ? modules[viewKey] : void 0,
75
- meta: {
76
- id: item.id,
77
- parent_id: item.parent_id,
78
- icon: item.icon,
79
- category: item.category,
80
- keepAlive: true,
81
- title: item.name,
82
- fullPath: item.path
83
- },
84
- children: item.children ? transformRoutes(item.children) : []
85
- });
86
- } else if (item.children?.length) {
87
- routes.push(...transformRoutes(item.children));
88
- }
89
- }
90
- return routes;
91
- };
92
- const addDynamicRoutes = (menuData) => {
93
- const dynamicRoutes = transformRoutes(menuData);
94
- dynamicRoutes.forEach((route) => {
95
- router.addRoute("main", route);
96
- });
97
- };
98
- const clearDynamicRoutes = () => {
99
- const routes = router.getRoutes();
100
- routes.forEach((route) => {
101
- if (route.name?.toString().startsWith("menu_") && router.hasRoute(route.name)) {
102
- router.removeRoute(route.name);
103
- }
104
- });
105
- registeredPaths.clear();
106
- };
107
- let justLoadedMenu = false;
108
- router.beforeEach(async (to, _from, next) => {
109
- const userStore = getUserStore();
110
- let access_token = userStore.getUserAccessToken;
111
- if (!access_token && typeof window !== "undefined") {
112
- const restored = userStore.syncFromAuthStore();
113
- if (restored) {
114
- access_token = userStore.getUserAccessToken;
115
- }
116
- }
117
- if (!access_token) {
118
- const currentUrl = encodeURIComponent(window.location.href);
119
- window.location.href = `${AUTH_LOGIN_URL}?redirect=${currentUrl}`;
120
- return;
121
- }
122
- if (justLoadedMenu) {
123
- justLoadedMenu = false;
124
- next();
125
- return;
126
- }
127
- if (userStore.isMenuLoaded && (to.path === "/" || to.path === "")) {
128
- const tabStore = getTabStore();
129
- tabStore.clearAll();
130
- const allMenu = userStore.getUserALLMenu;
131
- if (allMenu && allMenu.length > 0) {
132
- const firstPage = getFirstPage(allMenu);
133
- if (firstPage) {
134
- const [basePath, queryString] = firstPage.split("?");
135
- const query = {};
136
- if (queryString) {
137
- queryString.split("&").forEach((param) => {
138
- const [key, value] = param.split("=");
139
- if (key) query[key] = value || "";
140
- });
141
- }
142
- next({ path: basePath, query, replace: true });
143
- return;
144
- }
145
- }
146
- }
147
- if (!userStore.isMenuLoaded) {
148
- clearDynamicRoutes();
149
- const tabStore = getTabStore();
150
- tabStore.clearAll();
151
- userStore.resetMenuLoaded();
152
- const success = await userStore.fetchUserMenu();
153
- if (!success) {
154
- window.location.href = AUTH_LOGIN_URL;
155
- return;
156
- }
157
- const allMenu = userStore.getUserALLMenu;
158
- if (allMenu && allMenu.length > 0) {
159
- addDynamicRoutes(allMenu);
160
- const firstPage = getFirstPage(allMenu);
161
- if (firstPage) {
162
- const [basePath, queryString] = firstPage.split("?");
163
- const query = {};
164
- if (queryString) {
165
- queryString.split("&").forEach((param) => {
166
- const [key, value] = param.split("=");
167
- if (key) query[key] = value || "";
168
- });
169
- }
170
- justLoadedMenu = true;
171
- next({ path: basePath, query, replace: true });
172
- return;
173
- }
174
- }
175
- }
176
- next();
177
- });
178
- return router;
179
- }
180
- // Annotate the CommonJS export names for ESM import in node:
181
- 0 && (module.exports = {
182
- createAppRouter
183
- });