@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/dist/index.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  import * as vue_router from 'vue-router';
2
2
  import { RouteRecordRaw } from 'vue-router';
3
3
  import { Dayjs } from 'dayjs';
4
+ import { App, Plugin } from 'vue';
5
+ import * as vue_i18n from 'vue-i18n';
4
6
 
5
7
  interface AppRouterOptions {
6
8
  staticRoutes: RouteRecordRaw[];
7
9
  getUserStore: () => any;
8
- getTabStore: () => any;
9
- getFirstPage: (allMenu: any[]) => string | null | undefined;
10
+ getFirstPage?: (allMenu: any[]) => string | null | undefined;
10
11
  authLoginUrl?: string;
12
+ /** 是否开启从 URL 参数恢复 token,默认关闭 */
13
+ enableUrlTokenRecovery?: boolean;
11
14
  }
12
15
  /**
13
16
  * 创建带统一登录、动态菜单和 Tab 管理的 Router
@@ -24,11 +27,13 @@ interface LogoutToAuthOptions {
24
27
  };
25
28
  authLoginUrl?: string;
26
29
  ssoStorageKey?: string;
30
+ legacySsoStorageKey?: string;
31
+ fallbackAccessTokenKey?: string;
27
32
  }
28
33
  /**
29
34
  * 创建统一退出方法:
30
35
  * - 清除当前子系统的用户信息
31
- * - 清除统一登录站点的本地缓存(默认 key: user-store)
36
+ * - 清除统一登录站点的本地缓存(默认 key: auth-user-store)
32
37
  * - 跳转到统一登录地址,携带 redirect
33
38
  */
34
39
  declare function createLogoutToAuth(options: LogoutToAuthOptions): () => void;
@@ -89,6 +94,9 @@ interface PermissionHelper {
89
94
  */
90
95
  hasAnyPermission: (codesOrPaths: string[]) => boolean;
91
96
  }
97
+ /**
98
+ * 创建统一权限判断工具,提供页面权限、按钮权限和任意权限判断。
99
+ */
92
100
  declare function createPermissionHelper(options: PermissionHelperOptions): PermissionHelper;
93
101
 
94
102
  interface MenuHelperOptions {
@@ -121,6 +129,9 @@ interface MenuHelper {
121
129
  */
122
130
  getBreadcrumb: (path: string) => BreadcrumbItem[];
123
131
  }
132
+ /**
133
+ * 创建菜单辅助工具,统一提供查找、标题、链路、父级与面包屑能力。
134
+ */
124
135
  declare function createMenuHelper(options: MenuHelperOptions): MenuHelper;
125
136
  /**
126
137
  * 标准化后的菜单节点结构,供各前端站点复用
@@ -207,6 +218,9 @@ declare function getPresetRange(key: PresetRangeKey, now?: TimeInput): TimeRange
207
218
  * 判断某个时间是否在区间内(含边界)
208
219
  */
209
220
  declare function isInRange(value: TimeInput, range: TimeRange<TimeInput>): boolean;
221
+ /**
222
+ * 组合导出时间工具方法,便于在业务中按对象方式使用。
223
+ */
210
224
  declare function useTime(): {
211
225
  formatTime: typeof formatTime;
212
226
  humanizeTime: typeof humanizeTime;
@@ -257,23 +271,132 @@ interface TabItem {
257
271
  keepAlive: boolean;
258
272
  }
259
273
  declare const DEFAULT_HOME_PATH = "/main/home";
274
+ /**
275
+ * 向标签页列表追加新标签;若路径已存在则保持原列表。
276
+ */
260
277
  declare function addTab(tabs: TabItem[], tab: TabItem): TabItem[];
278
+ /**
279
+ * 根据路径移除指定标签页。
280
+ */
261
281
  declare function removeTab(tabs: TabItem[], path: string): TabItem[];
282
+ /**
283
+ * 关闭除当前与首页外的其他标签页。
284
+ */
262
285
  declare function closeOthers(tabs: TabItem[], path: string, homePath?: string): TabItem[];
286
+ /**
287
+ * 关闭当前标签左侧的标签页(首页始终保留)。
288
+ */
263
289
  declare function closeLeft(tabs: TabItem[], path: string, homePath?: string): TabItem[];
290
+ /**
291
+ * 关闭当前标签右侧的标签页(首页始终保留)。
292
+ */
264
293
  declare function closeRight(tabs: TabItem[], path: string, homePath?: string): TabItem[];
294
+ /**
295
+ * 关闭所有可关闭标签,仅保留不可关闭项。
296
+ */
265
297
  declare function closeAll(tabs: TabItem[]): TabItem[];
298
+ /**
299
+ * 为 Pinia 创建通用的 Tab Store 配置
300
+ * @param homePath 首页路径,默认 /main/home
301
+ */
302
+ declare function createTabStoreOptions(homePath?: string): {
303
+ state: () => {
304
+ tabs: TabItem[];
305
+ };
306
+ actions: {
307
+ addTab(this: {
308
+ tabs: TabItem[];
309
+ }, tab: TabItem): void;
310
+ removeTab(this: {
311
+ tabs: TabItem[];
312
+ }, path: string): void;
313
+ closeOthers(this: {
314
+ tabs: TabItem[];
315
+ }, path: string): void;
316
+ closeLeft(this: {
317
+ tabs: TabItem[];
318
+ }, path: string): void;
319
+ closeRight(this: {
320
+ tabs: TabItem[];
321
+ }, path: string): void;
322
+ closeAll(this: {
323
+ tabs: TabItem[];
324
+ }): void;
325
+ };
326
+ };
266
327
 
267
- interface CoreUserStoreLike {
328
+ interface BaseUserStoreLike {
268
329
  userno: string;
269
330
  username: string;
270
331
  access_token: string;
271
332
  refresh_token: string;
272
333
  lastActiveTime: number | null;
334
+ }
335
+ /**
336
+ * 创建基础用户状态(不含菜单)。
337
+ * 适用于 portal.web、portal.auth.web 等轻量站点。
338
+ */
339
+ declare function createBaseUserState(): BaseUserStoreLike;
340
+ /**
341
+ * 创建基础用户 getters(不含菜单)。
342
+ */
343
+ declare function createBaseUserGetters(): {
344
+ getUserInfo: (state: any) => {
345
+ userno: any;
346
+ username: any;
347
+ access_token: any;
348
+ refresh_token: any;
349
+ lastActiveTime: any;
350
+ };
351
+ getUserNo: (state: any) => any;
352
+ getUserName: (state: any) => any;
353
+ getUserAccessToken: (state: any) => any;
354
+ getUserRefreshToken: (state: any) => any;
355
+ getUserLastActiveTime: (state: any) => any;
356
+ };
357
+ interface CreateBaseUserActionsOptions {
358
+ /** SSO 缓存 key,默认读取 AUTH_CONFIG.ssoStorageKey */
359
+ ssoStorageKey?: string;
360
+ }
361
+ /**
362
+ * 创建基础用户 actions(不含菜单)。
363
+ */
364
+ declare function createBaseUserActions(options?: CreateBaseUserActionsOptions): {
365
+ setUserInfo(this: BaseUserStoreLike, userInfo: any): void;
366
+ setUserAccessToken(this: BaseUserStoreLike, access_token: string): void;
367
+ setUserRefreshToken(this: BaseUserStoreLike, refresh_token: string): void;
368
+ setUserLastActiveTime(this: BaseUserStoreLike, lastActiveTime: number): void;
369
+ syncFromAuthStore(this: BaseUserStoreLike): boolean;
370
+ clearUserInfo(this: BaseUserStoreLike): void;
371
+ };
372
+ interface CoreUserStoreLike extends BaseUserStoreLike {
273
373
  all_menu: any[];
274
374
  sidebar_menu: any[];
275
375
  menuLoaded: boolean;
276
376
  }
377
+ interface CoreMenuUserState<TMenu = any> extends CoreUserStoreLike {
378
+ all_menu: TMenu[];
379
+ sidebar_menu: TMenu[];
380
+ }
381
+ /**
382
+ * 创建管理站点用户状态(含菜单)。
383
+ * 适用于带动态菜单的后台系统。
384
+ */
385
+ declare function createMenuUserState<TMenu = any>(): CoreMenuUserState<TMenu>;
386
+ /**
387
+ * 创建管理站点用户 getters(含菜单)。
388
+ */
389
+ declare function createMenuUserGetters<TUserInfo = any>(): {
390
+ getUserInfo: (state: any) => TUserInfo;
391
+ getUserNo: (state: any) => any;
392
+ getUserName: (state: any) => any;
393
+ getUserAccessToken: (state: any) => any;
394
+ getUserRefreshToken: (state: any) => any;
395
+ getUserLastActiveTime: (state: any) => any;
396
+ getUserALLMenu: (state: any) => any;
397
+ getUserSidebarMenu: (state: any) => any;
398
+ isMenuLoaded: (state: any) => any;
399
+ };
277
400
  interface SidebarMenuFilterOptions {
278
401
  /** 需要排除的菜单类别 */
279
402
  excludeCategories?: string[];
@@ -283,8 +406,12 @@ interface SidebarMenuFilterOptions {
283
406
  */
284
407
  declare function filterSidebarMenu(menus: any[], options?: SidebarMenuFilterOptions): any[];
285
408
  interface SyncFromAuthStoreOptions {
286
- /** 统一登录站点在 localStorage 中使用的 key,默认 user-store */
409
+ /** 统一登录站点在 localStorage 中使用的 key,默认 auth-user-store */
287
410
  storageKey?: string;
411
+ /** 历史兼容 key,默认 user-store */
412
+ legacyStorageKey?: string;
413
+ /** 仅 access_token 的兜底 key,默认 portal_access_token */
414
+ fallbackAccessTokenKey?: string;
288
415
  }
289
416
  /**
290
417
  * 从统一登录站点的本地缓存中恢复用户基础信息
@@ -297,6 +424,28 @@ interface FetchUserMenuForStoreOptions {
297
424
  getALLMenu: (menuTree: any[]) => any[];
298
425
  filterOptions?: SidebarMenuFilterOptions;
299
426
  }
427
+ interface CreateMenuUserActionsOptions {
428
+ http: any;
429
+ site: string;
430
+ transformMenuData: (data: any[]) => any[];
431
+ getALLMenu: (menuTree: any[]) => any[];
432
+ filterOptions?: SidebarMenuFilterOptions;
433
+ ssoStorageKey?: string;
434
+ }
435
+ /**
436
+ * 创建管理站点用户 actions(含菜单请求、菜单状态维护、SSO 恢复)。
437
+ */
438
+ declare function createMenuUserActions(options: CreateMenuUserActionsOptions): {
439
+ setUserInfo(this: CoreUserStoreLike, userInfo: any): void;
440
+ setUserAccessToken(this: CoreUserStoreLike, access_token: string): void;
441
+ setUserRefreshToken(this: CoreUserStoreLike, refresh_token: string): void;
442
+ setUserLastActiveTime(this: CoreUserStoreLike, lastActiveTime: number): void;
443
+ syncFromAuthStore(this: CoreUserStoreLike): boolean;
444
+ setLoadUserMenulist(this: CoreUserStoreLike): void;
445
+ fetchUserMenu(this: CoreUserStoreLike): Promise<boolean>;
446
+ resetMenuLoaded(this: CoreUserStoreLike): void;
447
+ clearUserInfo(this: CoreUserStoreLike): void;
448
+ };
300
449
  /**
301
450
  * 为指定站点拉取并设置用户菜单(包含完整菜单树和侧边栏菜单)
302
451
  */
@@ -325,7 +474,7 @@ declare function createLoadingStoreOptions(): {
325
474
  * - DEFAULT_AUTH_LOGIN_ENV_KEY: 前端项目中约定的统一登录地址环境变量名
326
475
  * - DEFAULT_AUTH_LOGIN_PATH: 统一登录站点在当前域下的默认路径
327
476
  */
328
- declare const DEFAULT_SSO_STORAGE_KEY = "user-store";
477
+ declare const DEFAULT_SSO_STORAGE_KEY = "auth-user-store";
329
478
  declare const DEFAULT_AUTH_LOGIN_ENV_KEY = "VITE_AUTH_LOGIN_URL";
330
479
  declare const DEFAULT_AUTH_LOGIN_PATH = "/auth/#/login";
331
480
  /**
@@ -335,7 +484,7 @@ declare const DEFAULT_AUTH_LOGIN_PATH = "/auth/#/login";
335
484
  */
336
485
  declare function getDefaultAuthLoginUrl(): string;
337
486
  interface AuthConfig {
338
- /** 统一登录站点在 localStorage 中使用的 key,默认 user-store */
487
+ /** 统一登录站点在 localStorage 中使用的 key,默认 auth-user-store */
339
488
  ssoStorageKey: string;
340
489
  /** 前端项目中约定的统一登录地址环境变量名,默认 VITE_AUTH_LOGIN_URL */
341
490
  authLoginEnvKey: string;
@@ -344,4 +493,38 @@ interface AuthConfig {
344
493
  }
345
494
  declare const AUTH_CONFIG: AuthConfig;
346
495
 
347
- export { AUTH_CONFIG, type AppRouterOptions, type AuthConfig, type BreadcrumbItem, type CoreMenuItem, type CoreUserStoreLike, type CreateAuthHttpClientOptions, 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 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, createLoadingStoreOptions, createLogoutToAuth, createMenuHelper, createPermissionHelper, createRange, fetchUserMenuForStore, filterSidebarMenu, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getDefaultAuthLoginUrl, getPresetRange, humanizeTime, initTheme, isInRange, removeTab, syncFromAuthStoreToStore, timeDiff, transformMenuTree, useThemeWatcher, useTime };
496
+ type PluginTuple = [Plugin, ...unknown[]];
497
+ type UsePluginItem = Plugin | PluginTuple;
498
+ interface SetupPortalAppOptions {
499
+ app: App;
500
+ plugins?: UsePluginItem[];
501
+ elementIcons?: Record<string, unknown>;
502
+ beforeMount?: () => void;
503
+ mountSelector?: string;
504
+ }
505
+ /**
506
+ * 按 Portal 约定完成应用启动编排:
507
+ * 1. 注册插件
508
+ * 2. 注册 Element Plus 图标
509
+ * 3. 执行挂载前回调
510
+ * 4. 挂载应用
511
+ */
512
+ declare function setupPortalApp(options: SetupPortalAppOptions): void;
513
+
514
+ interface CreateI18nOptions {
515
+ /** 翻译消息,key 为 locale(如 'zh-CN'),value 为翻译对象 */
516
+ messages: Record<string, any>;
517
+ /** localStorage 中存储语言偏好的 key,默认 'locale' */
518
+ storageKey?: string;
519
+ /** 默认语言,默认 'zh-CN' */
520
+ defaultLocale?: string;
521
+ /** 回退语言,默认 'zh-CN' */
522
+ fallbackLocale?: string;
523
+ }
524
+ /**
525
+ * 创建统一配置的 vue-i18n 实例
526
+ * 四个站点的初始化逻辑完全相同,只有翻译内容不同
527
+ */
528
+ declare function createPortalI18n(options: CreateI18nOptions): vue_i18n.I18n<Record<string, any>, {}, {}, string, false>;
529
+
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 };