@litianxiang/portal-core 0.1.24 → 0.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/README.md CHANGED
@@ -16,6 +16,26 @@ pnpm add @litianxiang/portal-core
16
16
  npm i @litianxiang/portal-core
17
17
  ```
18
18
 
19
+ ## 升级说明
20
+
21
+ ### 0.2.0(Breaking Change)
22
+
23
+ - 移除 `createPortalHttpClient`。
24
+ - 统一使用 `createAuthHttpClient`。
25
+ - 业务项目原来通过 `createPortalHttpClient` 传入的 `baseURL: ''`、`timeout: 10000` 可以不再显式传递,`createAuthHttpClient` 内部已提供相同默认值。
26
+
27
+ 迁移示例:
28
+
29
+ ```ts
30
+ import { createAuthHttpClient } from '@litianxiang/portal-core'
31
+
32
+ const { http, logoutToAuth } = createAuthHttpClient({
33
+ getUserStore: () => useUserStore(),
34
+ getLoadingStore: () => useLoadingStore(),
35
+ onShowError: (msg) => console.error(msg)
36
+ })
37
+ ```
38
+
19
39
  ## 快速开始
20
40
 
21
41
  ### 1) 路由接入
@@ -73,6 +93,8 @@ setupPortalApp({
73
93
  ### router
74
94
 
75
95
  - `createAppRouter(options)`:创建统一路由实例,内置登录态校验、菜单动态挂载、首屏跳转逻辑。
96
+ - 菜单类别为 `page` 的动态路由会挂载到 `main` 下。
97
+ - 菜单类别为 `flow-page` 的动态路由会挂载为顶级路由(不进入 `main` 主框架)。
76
98
 
77
99
  最小示例:
78
100
 
@@ -111,13 +133,12 @@ if (shouldRefresh) {
111
133
  ### http
112
134
 
113
135
  - `createAuthHttpClient(options)`:创建带认证拦截器的 HTTP 客户端(Loading、token 注入、401 处理、刷新 token)。
114
- - `createPortalHttpClient(options)`:业务项目 HTTP 初始化便捷封装,减少重复模板代码。
115
136
 
116
137
  最小示例:
117
138
 
118
139
  ```ts
119
140
  import axios from 'axios'
120
- import { createAuthHttpClient, createPortalHttpClient } from '@litianxiang/portal-core'
141
+ import { createAuthHttpClient } from '@litianxiang/portal-core'
121
142
 
122
143
  const { http } = createAuthHttpClient({
123
144
  axios,
@@ -126,13 +147,6 @@ const { http } = createAuthHttpClient({
126
147
  })
127
148
 
128
149
  await http.post('/api/demo', {})
129
-
130
- // 业务项目推荐直接使用便捷封装
131
- const { http: portalHttp } = createPortalHttpClient({
132
- axios,
133
- getUserStore: () => useUserStore(),
134
- getLoadingStore: () => useLoadingStore()
135
- })
136
150
  ```
137
151
 
138
152
  ### config
package/dist/index.d.ts CHANGED
@@ -69,30 +69,6 @@ interface CreateAuthHttpClientOptions {
69
69
  inactiveBufferMs?: number;
70
70
  onShowError?: (msg: string) => void;
71
71
  }
72
- interface CreatePortalHttpClientOptions {
73
- axios?: any;
74
- baseURL?: string;
75
- timeout?: number;
76
- getUserStore: () => any;
77
- getLoadingStore: () => any;
78
- authLoginUrl?: string;
79
- ssoStorageKey?: string;
80
- refreshUrl?: string;
81
- inactiveExpireMs?: number;
82
- inactiveBufferMs?: number;
83
- onShowError?: (msg: string) => void;
84
- }
85
- /**
86
- * 创建业务项目通用 HTTP 客户端(createAuthHttpClient 的便捷封装)。
87
- *
88
- * 作用:
89
- * - 统一管理端项目中的标准 HTTP 初始化写法
90
- * - 复用 portal-core 认证拦截器能力
91
- */
92
- declare function createPortalHttpClient(options: CreatePortalHttpClientOptions): {
93
- http: any;
94
- logoutToAuth: () => void;
95
- };
96
72
  declare function createAuthHttpClient(options: CreateAuthHttpClientOptions): {
97
73
  http: any;
98
74
  logoutToAuth: () => void;
@@ -551,4 +527,4 @@ interface CreateI18nOptions {
551
527
  */
552
528
  declare function createPortalI18n(options: CreateI18nOptions): vue_i18n.I18n<Record<string, any>, {}, {}, string, false>;
553
529
 
554
- export { AUTH_CONFIG, type AppRouterOptions, type AuthConfig, type BaseUserStoreLike, type BreadcrumbItem, type CoreMenuItem, type CoreMenuUserState, type CoreUserStoreLike, type CreateAuthHttpClientOptions, type CreateBaseUserActionsOptions, type CreateI18nOptions, type CreateMenuUserActionsOptions, type CreatePortalHttpClientOptions, DEFAULT_AUTH_LOGIN_ENV_KEY, DEFAULT_AUTH_LOGIN_PATH, DEFAULT_HOME_PATH, DEFAULT_SSO_STORAGE_KEY, type FetchUserMenuForStoreOptions, type FontSize, type InactivityConfig, type InactivityResult, type LoadingState, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type PresetRangeKey, type SetupPortalAppOptions, type SidebarMenuFilterOptions, type SyncFromAuthStoreOptions, type TabItem, type ThemeConfig, type ThemeMode, type TimeInput, type TimeRange, type TransformMenuOptions, addTab, applyTheme, buildAllMenuTree, buildPageMenuList, calcInactivityAction, closeAll, closeLeft, closeOthers, closeRight, createAppRouter, createAuthHttpClient, createBaseUserActions, createBaseUserGetters, createBaseUserState, createLoadingStoreOptions, createLogoutToAuth, createMenuHelper, createMenuUserActions, createMenuUserGetters, createMenuUserState, createPermissionHelper, createPortalHttpClient, createPortalI18n, createRange, createTabStoreOptions, fetchUserMenuForStore, filterSidebarMenu, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getDefaultAuthLoginUrl, getPresetRange, humanizeTime, initTheme, isInRange, removeTab, setupPortalApp, syncFromAuthStoreToStore, timeDiff, transformMenuTree, useThemeWatcher, useTime };
530
+ export { AUTH_CONFIG, type AppRouterOptions, type AuthConfig, type BaseUserStoreLike, type BreadcrumbItem, type CoreMenuItem, type CoreMenuUserState, type CoreUserStoreLike, type CreateAuthHttpClientOptions, type CreateBaseUserActionsOptions, type CreateI18nOptions, type CreateMenuUserActionsOptions, DEFAULT_AUTH_LOGIN_ENV_KEY, DEFAULT_AUTH_LOGIN_PATH, DEFAULT_HOME_PATH, DEFAULT_SSO_STORAGE_KEY, type FetchUserMenuForStoreOptions, type FontSize, type InactivityConfig, type InactivityResult, type LoadingState, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type PresetRangeKey, type SetupPortalAppOptions, type SidebarMenuFilterOptions, type SyncFromAuthStoreOptions, type TabItem, type ThemeConfig, type ThemeMode, type TimeInput, type TimeRange, type TransformMenuOptions, addTab, applyTheme, buildAllMenuTree, buildPageMenuList, calcInactivityAction, closeAll, closeLeft, closeOthers, closeRight, createAppRouter, createAuthHttpClient, createBaseUserActions, createBaseUserGetters, createBaseUserState, createLoadingStoreOptions, createLogoutToAuth, createMenuHelper, createMenuUserActions, createMenuUserGetters, createMenuUserState, createPermissionHelper, createPortalI18n, createRange, createTabStoreOptions, fetchUserMenuForStore, filterSidebarMenu, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getDefaultAuthLoginUrl, getPresetRange, humanizeTime, initTheme, isInRange, removeTab, setupPortalApp, syncFromAuthStoreToStore, timeDiff, transformMenuTree, useThemeWatcher, useTime };
package/dist/index.js CHANGED
@@ -212,7 +212,8 @@ function createAppRouter(options) {
212
212
  const resolveRouteAndView = (item) => {
213
213
  const [rawPath] = (item.path || "").split("?");
214
214
  const normalizedPath = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
215
- const routePath = normalizedPath.slice(1);
215
+ const childPath = normalizedPath.slice(1);
216
+ const rootPath = normalizedPath;
216
217
  const candidates = [
217
218
  `/main${normalizedPath}`,
218
219
  // /views/main/system/user.vue
@@ -231,40 +232,44 @@ function createAppRouter(options) {
231
232
  const fallbackPath = `/main${normalizedPath}`;
232
233
  viewKey = `/src/views${fallbackPath}.vue`;
233
234
  }
234
- return { routePath, viewKey };
235
+ return { childPath, rootPath, viewKey };
235
236
  };
236
- const transformRoutes = (menuItems) => {
237
+ const collectDynamicRoutes = (menuItems) => {
237
238
  const routes = [];
238
- for (const item of menuItems) {
239
- if (item.category === "button") continue;
240
- const { routePath, viewKey } = resolveRouteAndView(item);
241
- const isPage = item.category === "page" || item.category === "flow-page";
242
- if (!registeredPaths.has(routePath)) {
243
- registeredPaths.add(routePath);
244
- routes.push({
245
- path: routePath,
246
- name: `menu_${item.id}`,
247
- component: isPage ? modules[viewKey] : void 0,
248
- meta: {
249
- id: item.id,
250
- parent_id: item.parent_id,
251
- icon: item.icon,
252
- category: item.category,
253
- keepAlive: true,
254
- title: item.name,
255
- fullPath: item.path
256
- },
257
- children: item.children ? transformRoutes(item.children) : []
258
- });
259
- } else if (item.children?.length) {
260
- routes.push(...transformRoutes(item.children));
239
+ for (const item of menuItems || []) {
240
+ if (item?.children?.length) {
241
+ routes.push(...collectDynamicRoutes(item.children));
261
242
  }
243
+ const isDynamicPage = item?.category === "page" || item?.category === "flow-page";
244
+ if (!isDynamicPage) continue;
245
+ const { childPath, rootPath, viewKey } = resolveRouteAndView(item);
246
+ const routePath = item?.category === "flow-page" ? rootPath : childPath;
247
+ if (registeredPaths.has(routePath)) continue;
248
+ registeredPaths.add(routePath);
249
+ routes.push({
250
+ path: routePath,
251
+ name: `menu_${item.id}`,
252
+ component: modules[viewKey],
253
+ meta: {
254
+ id: item.id,
255
+ parent_id: item.parent_id,
256
+ icon: item.icon,
257
+ category: item.category,
258
+ keepAlive: true,
259
+ title: item.name,
260
+ fullPath: item.path
261
+ }
262
+ });
262
263
  }
263
264
  return routes;
264
265
  };
265
266
  const addDynamicRoutes = (menuData) => {
266
- const dynamicRoutes = transformRoutes(menuData);
267
+ const dynamicRoutes = collectDynamicRoutes(menuData);
267
268
  dynamicRoutes.forEach((route) => {
269
+ if (route.meta?.category === "flow-page") {
270
+ router.addRoute(route);
271
+ return;
272
+ }
268
273
  router.addRoute("main", route);
269
274
  });
270
275
  };
@@ -458,13 +463,6 @@ function calcInactivityAction(lastActiveTime, now, config = {}) {
458
463
 
459
464
  // src/http/http.ts
460
465
  import axiosLib from "axios";
461
- function createPortalHttpClient(options) {
462
- return createAuthHttpClient({
463
- baseURL: "",
464
- timeout: 1e4,
465
- ...options
466
- });
467
- }
468
466
  function createAuthHttpClient(options) {
469
467
  const {
470
468
  axios,
@@ -1207,7 +1205,6 @@ export {
1207
1205
  createMenuUserGetters,
1208
1206
  createMenuUserState,
1209
1207
  createPermissionHelper,
1210
- createPortalHttpClient,
1211
1208
  createPortalI18n,
1212
1209
  createRange,
1213
1210
  createTabStoreOptions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litianxiang/portal-core",
3
- "version": "0.1.24",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",