@teamias/pro-layout 0.0.11 → 0.0.12

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.
@@ -17,7 +17,7 @@ export declare class KeepAliveClass {
17
17
  updateAllComponent(type?: 'all' | 'pagesHook' | 'context'): Promise<void>;
18
18
  /** 获取页面数据 */
19
19
  getPages(): (import("react-router-dom").Location & {
20
- pageStatus: 200 | 403 | 404;
20
+ pageStatus: 200 | 404 | 403;
21
21
  pageTitle: string;
22
22
  })[];
23
23
  /** 关闭页面 */
@@ -32,7 +32,7 @@ export declare class KeepAliveClass {
32
32
  useLifeCycle: (callback: IPageLifeCycleCallback) => void;
33
33
  /** 获取缓存页面数组 */
34
34
  useKeepAlivePages: () => (import("react-router-dom").Location & {
35
- pageStatus: 200 | 403 | 404;
35
+ pageStatus: 200 | 404 | 403;
36
36
  pageTitle: string;
37
37
  })[];
38
38
  /** 更新当前路由页面 */
@@ -6,7 +6,7 @@ export declare const keepAliveControl: KeepAliveClass;
6
6
  export declare const useLifeCycle: (callback: import("./types").IPageLifeCycleCallback) => void;
7
7
  /** 获取页面数组 */
8
8
  export declare const useKeepAlivePages: () => (import("react-router-dom").Location & {
9
- pageStatus: 200 | 403 | 404;
9
+ pageStatus: 200 | 404 | 403;
10
10
  pageTitle: string;
11
11
  })[];
12
12
  /** 根 */
@@ -1,11 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  /** 这里初始化获取后,除了initialState 变化,会发生更新,其余的 pathname 不会变化 */
3
- export declare const useApiRouter: () => import("..").TMenuData | undefined;
3
+ export declare const useApiRouter: () => import("../types").TMenuData | undefined;
4
4
  /** 权限router */
5
5
  export declare const useAccessRouter: () => {
6
6
  page: {
7
7
  element?: import("react").ReactNode;
8
8
  access?: string | undefined;
9
+ path?: string | undefined;
10
+ name?: string | undefined;
9
11
  };
10
12
  location: import("react-router-dom").Location & {
11
13
  pageStatus: 200 | 404 | 403;
@@ -1,10 +1,25 @@
1
+ import { useIntl } from 'react-intl';
1
2
  import { matchPath, useLocation } from 'react-router-dom';
2
3
  import { NoFoundPage } from "../components/NoFoundPage";
3
4
  import { useLayoutContext } from "../context";
4
-
5
- /** 这里初始化获取后,除了initialState 变化,会发生更新,其余的 pathname 不会变化 */
6
5
  import { Fragment as _Fragment } from "react/jsx-runtime";
7
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
+ var getMenuFormattedTitle = function getMenuFormattedTitle(pageComponentMap, menuKey, defaultName) {
8
+ // 先通过原生的路由配置,找到初始的配置路径
9
+ // 主要针对动态参数的那种 (/product/list/:code)
10
+
11
+ /** 本地配置的页面路由 */
12
+ var localConfigPath = Object.keys(pageComponentMap || {}).find(function (p) {
13
+ return matchPath(p, menuKey);
14
+ }) || menuKey;
15
+ return {
16
+ id: "menu".concat(localConfigPath.replaceAll('/', '.')),
17
+ defaultMessage: defaultName || '',
18
+ localConfigPath: localConfigPath
19
+ };
20
+ };
21
+
22
+ /** 这里初始化获取后,除了initialState 变化,会发生更新,其余的 pathname 不会变化 */
8
23
  export var useApiRouter = function useApiRouter() {
9
24
  var _layoutContext$routeM;
10
25
  var location = useLocation();
@@ -16,11 +31,13 @@ export var useApiRouter = function useApiRouter() {
16
31
 
17
32
  /** 权限router */
18
33
  export var useAccessRouter = function useAccessRouter() {
19
- var _layoutContext$routeM2, _fullPathDataMap$loca;
34
+ var _layoutContext$routeM2, _fullPathDataMap, _currentPage;
20
35
  var layoutContext = useLayoutContext();
21
36
  var location = useLocation();
22
37
  var fullPathDataMap = ((_layoutContext$routeM2 = layoutContext.routeMenu) === null || _layoutContext$routeM2 === void 0 ? void 0 : _layoutContext$routeM2.fullPathDataMap) || {};
23
38
  var pageComponentMap = layoutContext.pageComponentMap || {};
39
+ var _useIntl = useIntl(),
40
+ formatMessage = _useIntl.formatMessage;
24
41
  var access = layoutContext.access;
25
42
 
26
43
  /** 匹配路径对应组件 */
@@ -30,7 +47,7 @@ export var useAccessRouter = function useAccessRouter() {
30
47
 
31
48
  // 补充数据
32
49
  location.pageStatus = 200;
33
- 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) || '';
50
+ location.pageTitle = ((_fullPathDataMap = fullPathDataMap[((_currentPage = currentPage) === null || _currentPage === void 0 ? void 0 : _currentPage.path) || location.pathname]) === null || _fullPathDataMap === void 0 || (_fullPathDataMap = _fullPathDataMap.raw) === null || _fullPathDataMap === void 0 ? void 0 : _fullPathDataMap.title) || formatMessage(getMenuFormattedTitle(pageComponentMap, location.pathname, '未知页面'));
34
51
 
35
52
  // 路由不存在, 但有菜单, 使用默认页面
36
53
  if (!currentPage && fullPathDataMap[location.pathname]) {
@@ -40,7 +57,6 @@ export var useAccessRouter = function useAccessRouter() {
40
57
  children: "\u8BF7\u521B\u5EFA\u8DEF\u7531\u5BF9\u5E94\u7684\u7EC4\u4EF6"
41
58
  })
42
59
  };
43
- // currentPage = { element: <>低代码页面</> };
44
60
  }
45
61
 
46
62
  // 判断页面是否需要权限判断
@@ -108,6 +108,8 @@ export type TLayoutContext = {
108
108
  pageComponentMap?: Record<string, {
109
109
  element?: ReactNode;
110
110
  access?: string;
111
+ path?: string;
112
+ name?: string;
111
113
  }>;
112
114
  /** 权限相关 */
113
115
  access?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/pro-layout",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",