@teamias/pro-layout 0.0.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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/markdowns/example1/BasicRexProLayout/index.d.ts +3 -0
  6. package/dist/markdowns/example1/BasicRexProLayout/index.js +83 -0
  7. package/dist/markdowns/example1/BasicRexProLayout/pages/Home.d.ts +1 -0
  8. package/dist/markdowns/example1/BasicRexProLayout/pages/Home.js +21 -0
  9. package/dist/markdowns/example1/BasicRexProLayout/pages/Level1.d.ts +1 -0
  10. package/dist/markdowns/example1/BasicRexProLayout/pages/Level1.js +21 -0
  11. package/dist/markdowns/example1/BasicRexProLayout/pages/Level2.d.ts +1 -0
  12. package/dist/markdowns/example1/BasicRexProLayout/pages/Level2.js +21 -0
  13. package/dist/markdowns/example1/BasicRexProLayout/testData.d.ts +53 -0
  14. package/dist/markdowns/example1/BasicRexProLayout/testData.js +82 -0
  15. package/dist/pro-layout/assets/login-bg.png +0 -0
  16. package/dist/pro-layout/assets/logo.png +0 -0
  17. package/dist/pro-layout/components/AvatarItem.d.ts +3 -0
  18. package/dist/pro-layout/components/AvatarItem.js +93 -0
  19. package/dist/pro-layout/components/Collapsed.d.ts +5 -0
  20. package/dist/pro-layout/components/Collapsed.js +23 -0
  21. package/dist/pro-layout/components/DocumentTitle.d.ts +4 -0
  22. package/dist/pro-layout/components/DocumentTitle.js +24 -0
  23. package/dist/pro-layout/components/KeepAlive/KeepAliveClass.d.ts +44 -0
  24. package/dist/pro-layout/components/KeepAlive/KeepAliveClass.js +448 -0
  25. package/dist/pro-layout/components/KeepAlive/index.d.ts +13 -0
  26. package/dist/pro-layout/components/KeepAlive/index.js +17 -0
  27. package/dist/pro-layout/components/KeepAlive/modules/useCacheTabsLayout.d.ts +26 -0
  28. package/dist/pro-layout/components/KeepAlive/modules/useCacheTabsLayout.js +75 -0
  29. package/dist/pro-layout/components/KeepAlive/types.d.ts +25 -0
  30. package/dist/pro-layout/components/KeepAlive/types.js +9 -0
  31. package/dist/pro-layout/components/Login/Account.d.ts +1 -0
  32. package/dist/pro-layout/components/Login/Account.js +41 -0
  33. package/dist/pro-layout/components/Login/index.d.ts +3 -0
  34. package/dist/pro-layout/components/Login/index.js +127 -0
  35. package/dist/pro-layout/components/Login/style.d.ts +2 -0
  36. package/dist/pro-layout/components/Login/style.js +5 -0
  37. package/dist/pro-layout/components/Menu/index.d.ts +8 -0
  38. package/dist/pro-layout/components/Menu/index.js +142 -0
  39. package/dist/pro-layout/components/Menu/style.d.ts +7 -0
  40. package/dist/pro-layout/components/Menu/style.js +19 -0
  41. package/dist/pro-layout/components/NoFoundPage/index.d.ts +4 -0
  42. package/dist/pro-layout/components/NoFoundPage/index.js +45 -0
  43. package/dist/pro-layout/components/PageLoading.d.ts +2 -0
  44. package/dist/pro-layout/components/PageLoading.js +14 -0
  45. package/dist/pro-layout/components/SystemId.d.ts +3 -0
  46. package/dist/pro-layout/components/SystemId.js +17 -0
  47. package/dist/pro-layout/components/TabsLayout/index.d.ts +2 -0
  48. package/dist/pro-layout/components/TabsLayout/index.js +193 -0
  49. package/dist/pro-layout/constant/index.d.ts +20 -0
  50. package/dist/pro-layout/constant/index.js +19 -0
  51. package/dist/pro-layout/context/index.d.ts +6 -0
  52. package/dist/pro-layout/context/index.js +84 -0
  53. package/dist/pro-layout/core/index.d.ts +4 -0
  54. package/dist/pro-layout/core/index.js +222 -0
  55. package/dist/pro-layout/hooks/index.d.ts +14 -0
  56. package/dist/pro-layout/hooks/index.js +65 -0
  57. package/dist/pro-layout/index.d.ts +4 -0
  58. package/dist/pro-layout/index.js +4 -0
  59. package/dist/pro-layout/style/index.d.ts +27 -0
  60. package/dist/pro-layout/style/index.js +57 -0
  61. package/dist/pro-layout/types/index.d.ts +154 -0
  62. package/dist/pro-layout/types/index.js +1 -0
  63. package/dist/pro-layout/utils/index.d.ts +25 -0
  64. package/dist/pro-layout/utils/index.js +63 -0
  65. package/dist/pro-layout/utils/menu.d.ts +15 -0
  66. package/dist/pro-layout/utils/menu.js +122 -0
  67. package/dist/types/svg.d.ts +24 -0
  68. package/package.json +108 -0
@@ -0,0 +1,65 @@
1
+ import { matchPath, useLocation } from 'react-router-dom';
2
+ import { NoFoundPage } from "../components/NoFoundPage";
3
+ import { useLayoutContext } from "../context";
4
+
5
+ /** 这里初始化获取后,除了initialState 变化,会发生更新,其余的 pathname 不会变化 */
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ export var useApiRouter = function useApiRouter() {
8
+ var _layoutContext$routeM;
9
+ var location = useLocation();
10
+ var layoutContext = useLayoutContext();
11
+ var fullPathDataMap = (_layoutContext$routeM = layoutContext.routeMenu) === null || _layoutContext$routeM === void 0 ? void 0 : _layoutContext$routeM.fullPathDataMap;
12
+ var localPathname = location.pathname.replace(layoutContext.basename, '/') || '/';
13
+ return fullPathDataMap === null || fullPathDataMap === void 0 ? void 0 : fullPathDataMap[localPathname];
14
+ };
15
+
16
+ /** 权限router */
17
+ export var useAccessRouter = function useAccessRouter() {
18
+ var _layoutContext$routeM2, _fullPathDataMap$loca;
19
+ var layoutContext = useLayoutContext();
20
+ var location = useLocation();
21
+ var fullPathDataMap = ((_layoutContext$routeM2 = layoutContext.routeMenu) === null || _layoutContext$routeM2 === void 0 ? void 0 : _layoutContext$routeM2.fullPathDataMap) || {};
22
+ var pageComponentMap = layoutContext.pageComponentMap || {};
23
+ var access = layoutContext.access;
24
+
25
+ /** 匹配路径对应组件 */
26
+ var currentPage = pageComponentMap[location.pathname] || pageComponentMap[Object.keys(pageComponentMap).find(function (p) {
27
+ return matchPath(p, location.pathname);
28
+ }) || ''];
29
+
30
+ // 补充数据
31
+ location.pageStatus = 200;
32
+ location.pageTitle = ((_fullPathDataMap$loca = fullPathDataMap[location.pathname]) === null || _fullPathDataMap$loca === void 0 || (_fullPathDataMap$loca = _fullPathDataMap$loca.raw) === null || _fullPathDataMap$loca === void 0 ? void 0 : _fullPathDataMap$loca.title) || '';
33
+
34
+ // 路由不存在, 但有菜单, 使用默认页面
35
+ if (!currentPage && fullPathDataMap[location.pathname]) {
36
+ // TODO: 需要注入低代码功能
37
+ // currentPage = { element: <BasicEngineApi /> };
38
+ // currentPage = { element: <>低代码页面</> };
39
+ }
40
+
41
+ // 判断页面是否需要权限判断
42
+ if (currentPage && currentPage.access) {
43
+ var fn = access === null || access === void 0 ? void 0 : access[currentPage.access];
44
+ // 有权限直接返回,否则403
45
+ if (fn && !fn(location.pathname)) {
46
+ currentPage = {
47
+ element: /*#__PURE__*/_jsx(NoFoundPage, {
48
+ type: 403
49
+ })
50
+ };
51
+ location.pageStatus = 403;
52
+ location.pageTitle = '403';
53
+ }
54
+ }
55
+ if (!currentPage) {
56
+ location.pageStatus = 404;
57
+ location.pageTitle = '404';
58
+ }
59
+
60
+ // 直接返回
61
+ return {
62
+ page: currentPage,
63
+ location: location
64
+ };
65
+ };
@@ -0,0 +1,4 @@
1
+ export { useLayoutContext } from './context';
2
+ export * from './core';
3
+ export * from './hooks';
4
+ export * from './types';
@@ -0,0 +1,4 @@
1
+ export { useLayoutContext } from "./context";
2
+ export * from "./core";
3
+ export * from "./hooks";
4
+ export * from "./types";
@@ -0,0 +1,27 @@
1
+ /// <reference types="react" />
2
+ export declare const Layout: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
4
+ }>, never>, never>> & string;
5
+ export declare const Aside: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
6
+ ref?: ((instance: HTMLElement | null) => void) | import("react").RefObject<HTMLElement> | null | undefined;
7
+ }>, never>, never>> & string;
8
+ export declare const Header: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
9
+ ref?: ((instance: HTMLElement | null) => void) | import("react").RefObject<HTMLElement> | null | undefined;
10
+ }>, never>, never>> & string;
11
+ export declare const HeaderLogo: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
12
+ ref?: ((instance: HTMLElement | null) => void) | import("react").RefObject<HTMLElement> | null | undefined;
13
+ }>, {
14
+ 'data-aside-width': string;
15
+ }>, never>> & string;
16
+ export declare const Main: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
17
+ ref?: ((instance: HTMLElement | null) => void) | import("react").RefObject<HTMLElement> | null | undefined;
18
+ }>, never>, never>> & string;
19
+ export declare const TopBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
20
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
21
+ }>, never>, never>> & string;
22
+ export declare const ContentBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
23
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
24
+ }>, never>, never>> & string;
25
+ export declare const TopHoverBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
26
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
27
+ }>, never>, never>> & string;
@@ -0,0 +1,57 @@
1
+ import styled from 'styled-components';
2
+ export var Layout = styled.div.attrs({
3
+ className: 'pro-layout'
4
+ }).withConfig({
5
+ displayName: "Layout",
6
+ componentId: "pro-layout-aaf4__sc-12ppwnu-0"
7
+ })(["overflow:hidden;width:100%;max-width:100%;min-height:100vh;"]);
8
+ export var Aside = styled.aside.attrs({
9
+ className: 'pro-aside'
10
+ }).withConfig({
11
+ displayName: "Aside",
12
+ componentId: "pro-layout-aaf4__sc-12ppwnu-1"
13
+ })([""]);
14
+ export var Header = styled.header.attrs({
15
+ className: 'pro-header'
16
+ }).withConfig({
17
+ displayName: "Header",
18
+ componentId: "pro-layout-aaf4__sc-12ppwnu-2"
19
+ })(["display:flex;background-color:#002140;color:#fff;position:relative;z-index:1;"]);
20
+ export var HeaderLogo = styled.header.attrs({
21
+ className: 'pro-header-logo'
22
+ }).withConfig({
23
+ displayName: "HeaderLogo",
24
+ componentId: "pro-layout-aaf4__sc-12ppwnu-3"
25
+ })(["padding-inline:12px;display:flex;align-items:center;color:rgba(0,0,0,0.65);flex:0 0 ", ";max-width:", ";min-width:", ";width:", ";border-inline-end:1px solid transparent;z-index:3;h1{margin:0;padding-left:10px;font-weight:600;font-size:16px;flex:1;color:#fff;}.anticon{font-size:20px;}"], function (p) {
26
+ return p['data-aside-width'];
27
+ }, function (p) {
28
+ return p['data-aside-width'];
29
+ }, function (p) {
30
+ return p['data-aside-width'];
31
+ }, function (p) {
32
+ return p['data-aside-width'];
33
+ });
34
+ export var Main = styled.main.attrs({
35
+ className: 'pro-main'
36
+ }).withConfig({
37
+ displayName: "Main",
38
+ componentId: "pro-layout-aaf4__sc-12ppwnu-4"
39
+ })(["display:flex;"]);
40
+ export var TopBox = styled.div.attrs({
41
+ className: 'pro-top-box'
42
+ }).withConfig({
43
+ displayName: "TopBox",
44
+ componentId: "pro-layout-aaf4__sc-12ppwnu-5"
45
+ })(["display:flex;align-items:flex-end;overflow:hidden;margin-left:-1px;position:sticky;top:0;z-index:2;width:100%;background:#001529;.ant-tabs{flex:1;width:0;color:#fff;}.ant-tabs-nav{margin:0;}.ant-tabs-nav::before{content:initial;}.ant-tabs-tab-remove{display:none;}.ant-tabs-tab{margin:0 6px !important;border-bottom:none !important;color:#fff;border-color:transparent !important;}.ant-tabs-tab-active{.ant-tabs-tab-remove{display:block;}}.ant-tabs-tab:first-child{margin-left:0 !important;}.ant-tabs-ink-bar,.ant-tabs-content-holder{display:none;}.ant-tabs-nav-more{padding:0 6px !important;color:#fff !important;}"]);
46
+ export var ContentBox = styled.div.attrs({
47
+ className: 'pro-content-box'
48
+ }).withConfig({
49
+ displayName: "ContentBox",
50
+ componentId: "pro-layout-aaf4__sc-12ppwnu-6"
51
+ })(["overflow:auto;height:100%;width:0;max-width:100%;flex:1;transition:0.1s;> div{max-width:100%;}"]);
52
+ export var TopHoverBox = styled.div.attrs({
53
+ className: 'pro-top-hover-box'
54
+ }).withConfig({
55
+ displayName: "TopHoverBox",
56
+ componentId: "pro-layout-aaf4__sc-12ppwnu-7"
57
+ })(["padding-inline:8px;display:flex;align-items:center;gap:8px;border-radius:6px;cursor:pointer;height:40px;overflow:hidden;.ant-dropdown-trigger{display:flex;align-items:center;gap:8px;}&[data-lang]:has(.ant-dropdown-trigger){padding:0;}&[data-lang] .ant-dropdown-trigger{padding-inline:8px !important;height:40px;}&:hover{background:rgba(0,0,0,0.06);}"]);
@@ -0,0 +1,154 @@
1
+ import { ReactNode } from 'react';
2
+ export interface IProLayoutProps extends Pick<TLayoutContext, 'projectId' | 'pageComponentMap' | 'access' | 'basename'> {
3
+ /** title */
4
+ projectTitle?: string;
5
+ /** logo img */
6
+ smallLogoImg?: string;
7
+ /** login background img */
8
+ loginBgImg?: string;
9
+ /**
10
+ * @desc 最大宽度
11
+ * @default '260px'
12
+ */
13
+ defaultMaxAsideWidth?: string;
14
+ /**
15
+ * @desc 最小宽度
16
+ * @default '40px'
17
+ */
18
+ defaultMinAsideWidth?: string;
19
+ /**
20
+ * @desc 折叠状态, 如果已缓存, 则以缓存为准
21
+ * @default false
22
+ */
23
+ defaultCollapsed?: boolean;
24
+ /**
25
+ * @desc 头部高度
26
+ * @default '40px'
27
+ */
28
+ defaultHeaderHeight?: string;
29
+ /** 注意别重复了 */
30
+ childrens?: {
31
+ /** 已登录状态的内容 */
32
+ loggedIn?: ReactNode;
33
+ /** 未登录状态的内容 */
34
+ unLoggedIn?: ReactNode;
35
+ /** 公共内容 */
36
+ common?: ReactNode;
37
+ };
38
+ /** 渲染多语言选择控件 */
39
+ renderSelectLang?: () => ReactNode;
40
+ /** 用户信息+菜单数据 */
41
+ requestUserInfoMenuData: () => Promise<Pick<TLayoutContext, 'userInfo'> & {
42
+ menuData: TApiMenuManagement[];
43
+ }>;
44
+ /** 登录接口 */
45
+ onLogin: (params: {
46
+ username?: string;
47
+ password?: string;
48
+ }) => Promise<Pick<TLayoutContext, 'token' | 'userInfo'>>;
49
+ /** 退出接口 */
50
+ onLogout: () => Promise<void>;
51
+ }
52
+ /** context 数据 */
53
+ export type TLayoutContext = {
54
+ /** 路由基础路径 */
55
+ basename: string;
56
+ /** 项目 id */
57
+ projectId: string | number;
58
+ /** token */
59
+ token?: string;
60
+ /** 用户信息 */
61
+ userInfo?: TApiUserInfo;
62
+ /** 展开/收起菜单 */
63
+ collapsed?: boolean;
64
+ /** 头部高度 */
65
+ headerHeight?: string;
66
+ /** 侧边栏宽度 */
67
+ asideWidth?: string;
68
+ defaultMaxAsideWidth?: string;
69
+ defaultMinAsideWidth?: string;
70
+ /** 隐藏菜单内容 */
71
+ hideMenu?: boolean;
72
+ /** 当前用户权限 */
73
+ permissions?: string[];
74
+ /** 当前用户菜单 */
75
+ routeMenu?: {
76
+ allKeys: Record<string, true>;
77
+ /** 原数据 */
78
+ rawData: TApiMenuManagement[];
79
+ /** 首页 */
80
+ home?: TMenuData;
81
+ /** 菜单 */
82
+ data: TMenuData[];
83
+ /** 根菜单 */
84
+ rootData: Omit<TMenuData, 'children'>[];
85
+ /** 菜单映射 */
86
+ dataMap: Record<string, TMenuData>;
87
+ /** 根菜单映射 */
88
+ rootChildrenMap: Record<string, TMenuData[]>;
89
+ /** 可打开的页面 */
90
+ fullPathData: TMenuData[];
91
+ /** 可打开的页面映射 */
92
+ fullPathDataMap: Record<string, TMenuData>;
93
+ };
94
+ /** 系统路由配置的映射(路径:组件) */
95
+ pageComponentMap?: Record<string, {
96
+ element?: ReactNode;
97
+ access?: string;
98
+ }>;
99
+ /** 权限相关 */
100
+ access?: {
101
+ operationPermission: (code?: string) => boolean;
102
+ adminRouteFilter: (pathname: string) => boolean;
103
+ };
104
+ updateData: (data: Partial<TLayoutContext>, cover?: 'merge' | 'replace') => Promise<void>;
105
+ };
106
+ /** 处理后的菜单数据 */
107
+ export type TMenuData = {
108
+ raw: TApiMenuManagement;
109
+ label: ReactNode;
110
+ key: string;
111
+ paths: string[];
112
+ children?: TMenuData[];
113
+ 'data-menu-id': string;
114
+ 'data-key': string;
115
+ };
116
+ /** 接口原始数据 */
117
+ export type TApiMenuManagement = {
118
+ /** 菜单标识(页面按钮权限控制) */
119
+ permission?: string;
120
+ /** 隐藏路由展示 */
121
+ hidden?: 0 | 1;
122
+ /** 主键ID */
123
+ id: number | string;
124
+ pid: number | string;
125
+ /** 下级列表 */
126
+ children?: TApiMenuManagement[];
127
+ /** 兼容静态路由传入 */
128
+ routes?: TApiMenuManagement[];
129
+ /** 名称 */
130
+ title: string;
131
+ /** 图标 */
132
+ icon: string;
133
+ /**
134
+ * @desc 类型:
135
+ * - 1.菜单(menu)
136
+ * - 2.弹窗(dialog)
137
+ * - 3.外部链接(link)
138
+ * - 4.目录(dir)
139
+ * - 5.按钮(button)
140
+ */
141
+ type: 1 | 2 | 3 | 4 | 5;
142
+ /** 路由地址 */
143
+ routing: string;
144
+ /** 菜单类型 */
145
+ menu_type: 'dir' | 'menu' | 'button';
146
+ };
147
+ type TApiUserInfo = {
148
+ /** 用户名 */
149
+ username?: string;
150
+ /** 用户ID */
151
+ id?: string;
152
+ [key: string]: any;
153
+ };
154
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ export * from './menu';
2
+ /**
3
+ * @description: 获取 localstorage 的值
4
+ */
5
+ export declare const getLocalStorageItem: <T extends unknown = any>(key: string, defaultValue?: T) => T | null;
6
+ /**
7
+ * @description: 存储 localstorage 的值
8
+ */
9
+ export declare const setLocalStorageItem: <T extends unknown = any>(key: string, value: T) => void;
10
+ /**
11
+ * @description: 移除 localstorage 的值
12
+ */
13
+ export declare const removeLocalStorageItem: (key: string) => void;
14
+ /**
15
+ * @description: 获取 sessionStorage 的值
16
+ */
17
+ export declare const getSessionStorageItem: <T extends unknown = any>(key: string) => T | null;
18
+ /**
19
+ * @description: 存储 sessionStorage 的值
20
+ */
21
+ export declare const setSessionStorageItem: <T extends unknown = any>(key: string, value: T) => void;
22
+ /**
23
+ * @description: 移除 sessionStorage 的值
24
+ */
25
+ export declare const removeSessionStorageItem: (key: string) => void;
@@ -0,0 +1,63 @@
1
+ export * from "./menu";
2
+
3
+ /**
4
+ * @description: 获取 localstorage 的值
5
+ */
6
+ export var getLocalStorageItem = function getLocalStorageItem(key, defaultValue) {
7
+ // 获取 值
8
+ var item = localStorage.getItem(key);
9
+ // 判断是否为空或undefined
10
+ if (item === null || item === undefined || item === 'null' || item === 'undefined') {
11
+ return defaultValue || null;
12
+ }
13
+
14
+ // 不为空返回解析后的值
15
+ var result = JSON.parse(item);
16
+ return result;
17
+ };
18
+
19
+ /**
20
+ * @description: 存储 localstorage 的值
21
+ */
22
+ export var setLocalStorageItem = function setLocalStorageItem(key, value) {
23
+ var result = JSON.stringify(value);
24
+ localStorage.setItem(key, result);
25
+ };
26
+
27
+ /**
28
+ * @description: 移除 localstorage 的值
29
+ */
30
+ export var removeLocalStorageItem = function removeLocalStorageItem(key) {
31
+ localStorage.removeItem(key);
32
+ };
33
+
34
+ /**
35
+ * @description: 获取 sessionStorage 的值
36
+ */
37
+ export var getSessionStorageItem = function getSessionStorageItem(key) {
38
+ // 获取 值
39
+ var item = sessionStorage.getItem(key);
40
+ // 判断是否为空或undefined
41
+ if (item === null || item === undefined || item === 'null' || item === 'undefined') {
42
+ return null;
43
+ }
44
+
45
+ // 不为空返回解析后的值
46
+ var result = JSON.parse(item);
47
+ return result;
48
+ };
49
+
50
+ /**
51
+ * @description: 存储 sessionStorage 的值
52
+ */
53
+ export var setSessionStorageItem = function setSessionStorageItem(key, value) {
54
+ var result = JSON.stringify(value);
55
+ sessionStorage.setItem(key, result);
56
+ };
57
+
58
+ /**
59
+ * @description: 移除 sessionStorage 的值
60
+ */
61
+ export var removeSessionStorageItem = function removeSessionStorageItem(key) {
62
+ sessionStorage.removeItem(key);
63
+ };
@@ -0,0 +1,15 @@
1
+ import { TApiMenuManagement, TMenuData } from '../types';
2
+ /**
3
+ * 处理数据菜单数据
4
+ */
5
+ export declare const handleMenuData: (topData?: TApiMenuManagement[]) => {
6
+ allKeys: Record<string, true>;
7
+ rawData: TApiMenuManagement[];
8
+ home: TMenuData;
9
+ data: TMenuData[];
10
+ rootData: Omit<TMenuData, "children">[];
11
+ dataMap: Record<string, TMenuData>;
12
+ rootChildrenMap: Record<string, TMenuData[]>;
13
+ fullPathData: TMenuData[];
14
+ fullPathDataMap: Record<string, TMenuData>;
15
+ };
@@ -0,0 +1,122 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ import { Link } from 'react-router-dom';
8
+ import { Fragment as _Fragment } from "react/jsx-runtime";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ /**
12
+ * 处理数据菜单数据
13
+ */
14
+ export var handleMenuData = function handleMenuData() {
15
+ var topData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
16
+ // const item = {
17
+ // label: data.name,
18
+ // };
19
+ /** 菜单 */
20
+ var data = [];
21
+ /** 根菜单 */
22
+ var rootData = [];
23
+ /** 菜单映射 */
24
+ var dataMap = {};
25
+ /** 根菜单映射 */
26
+ var rootChildrenMap = {};
27
+ /** 可打开的页面 */
28
+ var fullPathData = [];
29
+ /** 可打开的页面映射 */
30
+ var fullPathDataMap = {};
31
+ /** 所有key */
32
+ var allKeys = {};
33
+
34
+ /** 递归遍历 */
35
+ var each = function each(sourceData, source, paths) {
36
+ sourceData.forEach(function (old) {
37
+ /**
38
+ * @desc 移除路径上的层级
39
+ * @example /system/role-management -> role-management
40
+ */
41
+ var nodePath = paths.reduce(function (def, val) {
42
+ var reg = new RegExp("^/".concat(val, "(/)"));
43
+ return def.replace(reg, '$1');
44
+ }, old.routing).replaceAll('/', '') || '/';
45
+ var key = "/".concat([].concat(_toConsumableArray(paths), [nodePath]).join('/')).replaceAll('//', '/');
46
+
47
+ /** 组装新数据 */
48
+ var item = {
49
+ raw: Object.assign(old, {
50
+ // pageStatus: old.pageStatus ?? 0,
51
+ // formattedMessage: {id: '', defaultMessage: ''},
52
+ }),
53
+ label: /*#__PURE__*/_jsx(_Fragment, {
54
+ children: old.title
55
+ }),
56
+ key: key,
57
+ 'data-menu-id': "".concat(old.id),
58
+ 'data-key': key,
59
+ paths: [].concat(_toConsumableArray(paths), [nodePath])
60
+ };
61
+
62
+ // menu类型 或 静态数据 都进行收集
63
+ if (old.menu_type === 'menu') {
64
+ // 菜单页面收集
65
+ item.label = /*#__PURE__*/_jsxs(_Fragment, {
66
+ children: [item.label, /*#__PURE__*/_jsx(Link, {
67
+ to: item.key
68
+ })]
69
+ });
70
+ fullPathDataMap[item.key] = item;
71
+ fullPathData.push(item);
72
+
73
+ // 初始化,设置原型页面,是否绑定页面组件状态
74
+ // if (typeof item.raw.pageStatus === undefined || item.raw.pageStatus === 0) {
75
+ // item.raw.pageStatus = routeComponentMap.pageComponentMap[item['data-key']] ? 2 : 1;
76
+ // }
77
+ }
78
+
79
+ // 递归
80
+ if (Array.isArray(old.routes) && old.routes.length || Array.isArray(old.children) && old.children.length) {
81
+ var arr = Array.isArray(old.routes) && old.routes.length ? old.routes : old.children || [];
82
+ item.children = [];
83
+ each(arr, item.children, _toConsumableArray(item.paths));
84
+ item.children = item.children.filter(function (ii) {
85
+ return !ii.raw.hidden;
86
+ });
87
+ if (!item.children.length) delete item.children;
88
+ }
89
+
90
+ // 只保留有 children 的目录节点(叶子节点不保留)
91
+ if (!item.children && old.menu_type === 'dir' && !item['data-menu-id'].startsWith('custom-')) {
92
+ // 没有 children,不保留
93
+ return;
94
+ }
95
+
96
+ // 收集
97
+ source.push(item);
98
+ allKeys[old.routing] = true;
99
+ dataMap[item.key] = item;
100
+
101
+ // 根节点收集
102
+ if (paths.length === 0) {
103
+ rootData.push(item);
104
+ rootChildrenMap[item.key] = item.children;
105
+ }
106
+ });
107
+ };
108
+ each(topData, data, []);
109
+ // console.log(topData);
110
+
111
+ return {
112
+ allKeys: allKeys,
113
+ rawData: topData,
114
+ home: fullPathData[0],
115
+ data: data,
116
+ rootData: rootData,
117
+ dataMap: dataMap,
118
+ rootChildrenMap: rootChildrenMap,
119
+ fullPathData: fullPathData,
120
+ fullPathDataMap: fullPathDataMap
121
+ };
122
+ };
@@ -0,0 +1,24 @@
1
+ declare module '*.png' {
2
+ const value: string;
3
+ export default value;
4
+ }
5
+
6
+ declare module '*.jpg' {
7
+ const value: string;
8
+ export default value;
9
+ }
10
+
11
+ declare module '*.jpeg' {
12
+ const value: string;
13
+ export default value;
14
+ }
15
+
16
+ declare module '*.svg' {
17
+ const value: string;
18
+ export default value;
19
+ }
20
+
21
+ declare module '*.gif' {
22
+ const value: string;
23
+ export default value;
24
+ }