@litianxiang/portal-core 0.1.14 → 0.1.16

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
@@ -250,4 +250,56 @@ declare function formatToWanShou(value: number | string | null | undefined, deci
250
250
  */
251
251
  declare function formatWanYuanToYi(value: number | string | null | undefined, decimals?: number): string;
252
252
 
253
- export { type AppRouterOptions, type BreadcrumbItem, type CoreMenuItem, type CreateAuthHttpClientOptions, type FontSize, type InactivityConfig, type InactivityResult, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type PresetRangeKey, type ThemeConfig, type ThemeMode, type TimeInput, type TimeRange, type TransformMenuOptions, applyTheme, buildAllMenuTree, buildPageMenuList, calcInactivityAction, createAppRouter, createAuthHttpClient, createLogoutToAuth, createMenuHelper, createPermissionHelper, createRange, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getPresetRange, humanizeTime, initTheme, isInRange, timeDiff, transformMenuTree, useThemeWatcher, useTime };
253
+ interface TabItem {
254
+ title: string;
255
+ path: string;
256
+ closable: boolean;
257
+ keepAlive: boolean;
258
+ }
259
+ declare const DEFAULT_HOME_PATH = "/main/home";
260
+ declare function addTab(tabs: TabItem[], tab: TabItem): TabItem[];
261
+ declare function removeTab(tabs: TabItem[], path: string): TabItem[];
262
+ declare function closeOthers(tabs: TabItem[], path: string, homePath?: string): TabItem[];
263
+ declare function closeLeft(tabs: TabItem[], path: string, homePath?: string): TabItem[];
264
+ declare function closeRight(tabs: TabItem[], path: string, homePath?: string): TabItem[];
265
+ declare function closeAll(tabs: TabItem[]): TabItem[];
266
+
267
+ interface CoreUserStoreLike {
268
+ userno: string;
269
+ username: string;
270
+ access_token: string;
271
+ refresh_token: string;
272
+ lastActiveTime: number | null;
273
+ all_menu: any[];
274
+ sidebar_menu: any[];
275
+ menuLoaded: boolean;
276
+ }
277
+ interface SidebarMenuFilterOptions {
278
+ /** 需要排除的菜单类别 */
279
+ excludeCategories?: string[];
280
+ }
281
+ /**
282
+ * 过滤侧边栏需要展示的菜单:递归排除指定类别
283
+ */
284
+ declare function filterSidebarMenu(menus: any[], options?: SidebarMenuFilterOptions): any[];
285
+ interface SyncFromAuthStoreOptions {
286
+ /** 统一登录站点在 localStorage 中使用的 key,默认 user-store */
287
+ storageKey?: string;
288
+ }
289
+ /**
290
+ * 从统一登录站点的本地缓存中恢复用户基础信息
291
+ */
292
+ declare function syncFromAuthStoreToStore(store: CoreUserStoreLike, options?: SyncFromAuthStoreOptions): boolean;
293
+ interface FetchUserMenuForStoreOptions {
294
+ http: any;
295
+ site: string;
296
+ transformMenuData: (data: any[]) => any[];
297
+ getALLMenu: (menuTree: any[]) => any[];
298
+ filterOptions?: SidebarMenuFilterOptions;
299
+ }
300
+ /**
301
+ * 为指定站点拉取并设置用户菜单(包含完整菜单树和侧边栏菜单)
302
+ */
303
+ declare function fetchUserMenuForStore(store: CoreUserStoreLike, options: FetchUserMenuForStoreOptions): Promise<boolean>;
304
+
305
+ export { type AppRouterOptions, type BreadcrumbItem, type CoreMenuItem, type CoreUserStoreLike, type CreateAuthHttpClientOptions, DEFAULT_HOME_PATH, type FetchUserMenuForStoreOptions, type FontSize, type InactivityConfig, type InactivityResult, 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, createLogoutToAuth, createMenuHelper, createPermissionHelper, createRange, fetchUserMenuForStore, filterSidebarMenu, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getPresetRange, humanizeTime, initTheme, isInRange, removeTab, syncFromAuthStoreToStore, timeDiff, transformMenuTree, useThemeWatcher, useTime };
package/dist/index.js CHANGED
@@ -745,17 +745,98 @@ function formatWanYuanToYi(value, decimals = 2) {
745
745
  const yi = num / 1e4;
746
746
  return `${yi.toFixed(decimals)} \u4EBF\u5143`;
747
747
  }
748
+
749
+ // src/tab/tab.ts
750
+ var DEFAULT_HOME_PATH = "/main/home";
751
+ function addTab(tabs, tab) {
752
+ if (!tabs.some((item) => item.path === tab.path)) {
753
+ return [...tabs, tab];
754
+ }
755
+ return tabs;
756
+ }
757
+ function removeTab(tabs, path) {
758
+ return tabs.filter((tab) => tab.path !== path);
759
+ }
760
+ function closeOthers(tabs, path, homePath = DEFAULT_HOME_PATH) {
761
+ return tabs.filter((tab) => tab.path === path || tab.path === homePath);
762
+ }
763
+ function closeLeft(tabs, path, homePath = DEFAULT_HOME_PATH) {
764
+ const index = tabs.findIndex((tab) => tab.path === path);
765
+ return tabs.filter((tab, i) => i >= index || tab.path === homePath);
766
+ }
767
+ function closeRight(tabs, path, homePath = DEFAULT_HOME_PATH) {
768
+ const index = tabs.findIndex((tab) => tab.path === path);
769
+ return tabs.filter((tab, i) => i <= index || tab.path === homePath);
770
+ }
771
+ function closeAll(tabs) {
772
+ return tabs.filter((tab) => tab.closable === false);
773
+ }
774
+
775
+ // src/user/user.ts
776
+ function filterSidebarMenu(menus, options) {
777
+ const exclude = options?.excludeCategories ?? ["button", "flow-module", "flow-page"];
778
+ return (menus || []).filter((item) => !exclude.includes(item?.category)).map((item) => ({
779
+ ...item,
780
+ children: item.children && item.children.length > 0 ? filterSidebarMenu(item.children, options) : []
781
+ }));
782
+ }
783
+ function syncFromAuthStoreToStore(store, options) {
784
+ const storageKey = options?.storageKey ?? "user-store";
785
+ if (typeof window === "undefined") return false;
786
+ try {
787
+ const raw = window.localStorage.getItem(storageKey);
788
+ if (!raw) return false;
789
+ const data = JSON.parse(raw);
790
+ if (!data || !data.access_token) return false;
791
+ store.userno = data.userno || "";
792
+ store.username = data.username || "";
793
+ store.access_token = data.access_token || "";
794
+ store.refresh_token = data.refresh_token || "";
795
+ store.lastActiveTime = data.lastActiveTime ?? null;
796
+ return !!store.access_token;
797
+ } catch (error) {
798
+ console.error("\u4ECE\u7EDF\u4E00\u767B\u5F55\u7F13\u5B58\u6062\u590D\u7528\u6237\u4FE1\u606F\u5931\u8D25:", error);
799
+ return false;
800
+ }
801
+ }
802
+ async function fetchUserMenuForStore(store, options) {
803
+ const { http, site, transformMenuData, getALLMenu, filterOptions } = options;
804
+ if (!store.access_token) return false;
805
+ try {
806
+ const response = await http.post("/proxy/auth/api/user_menu_all", { site });
807
+ if (response.code === 200) {
808
+ const menuTree = transformMenuData(response.data);
809
+ const allMenu = getALLMenu(menuTree);
810
+ store.all_menu = allMenu;
811
+ store.sidebar_menu = filterSidebarMenu(allMenu, filterOptions);
812
+ store.menuLoaded = true;
813
+ return true;
814
+ }
815
+ return false;
816
+ } catch (error) {
817
+ console.error("\u83B7\u53D6\u7528\u6237\u83DC\u5355\u5931\u8D25:", error);
818
+ return false;
819
+ }
820
+ }
748
821
  export {
822
+ DEFAULT_HOME_PATH,
823
+ addTab,
749
824
  applyTheme,
750
825
  buildAllMenuTree,
751
826
  buildPageMenuList,
752
827
  calcInactivityAction,
828
+ closeAll,
829
+ closeLeft,
830
+ closeOthers,
831
+ closeRight,
753
832
  createAppRouter,
754
833
  createAuthHttpClient,
755
834
  createLogoutToAuth,
756
835
  createMenuHelper,
757
836
  createPermissionHelper,
758
837
  createRange,
838
+ fetchUserMenuForStore,
839
+ filterSidebarMenu,
759
840
  findFirstPagePath,
760
841
  formatRange,
761
842
  formatTime,
@@ -767,6 +848,8 @@ export {
767
848
  humanizeTime,
768
849
  initTheme,
769
850
  isInRange,
851
+ removeTab,
852
+ syncFromAuthStoreToStore,
770
853
  timeDiff,
771
854
  transformMenuTree,
772
855
  useThemeWatcher,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litianxiang/portal-core",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",