@teamias/pro-layout 0.0.14 → 0.0.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.
@@ -3,6 +3,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
5
  import { ProLayoutMemo } from "../../..";
6
+ import { RexProConfigProvider } from '@teamias/rex-design';
6
7
  import { sleep } from 'radash';
7
8
  import { useEffect } from 'react';
8
9
  import ReactDom from 'react-dom';
@@ -11,66 +12,69 @@ import { menuData, pageComponentMap } from "./testData";
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  var BasicProLayout = function BasicProLayout() {
13
14
  return /*#__PURE__*/_jsx(MemoryRouter, {
14
- children: /*#__PURE__*/_jsx(ProLayoutMemo, {
15
- basename: "/",
16
- projectId: "demo-project",
17
- pageComponentMap: pageComponentMap,
18
- placeholderElement: /*#__PURE__*/_jsx("div", {
19
- children: "\u5360\u4F4D\u5143\u7D20: \u9875\u9762\u6B63\u5728\u5F00\u53D1\u4E2D..."
20
- }),
21
- requestUserInfoMenuData: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
22
- return _regeneratorRuntime().wrap(function _callee$(_context) {
23
- while (1) switch (_context.prev = _context.next) {
24
- case 0:
25
- _context.next = 2;
26
- return sleep(100);
27
- case 2:
28
- return _context.abrupt("return", {
29
- userInfo: {
30
- id: '1',
31
- username: 'demo-user'
32
- },
33
- menuData: menuData
34
- });
35
- case 3:
36
- case "end":
37
- return _context.stop();
38
- }
39
- }, _callee);
40
- })),
41
- onLogin: ( /*#__PURE__*/function () {
42
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
43
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
44
- while (1) switch (_context2.prev = _context2.next) {
15
+ children: /*#__PURE__*/_jsx(RexProConfigProvider, {
16
+ value: {},
17
+ children: /*#__PURE__*/_jsx(ProLayoutMemo, {
18
+ basename: "/",
19
+ projectId: "demo-project",
20
+ pageComponentMap: pageComponentMap,
21
+ placeholderElement: /*#__PURE__*/_jsx("div", {
22
+ children: "\u5360\u4F4D\u5143\u7D20: \u9875\u9762\u6B63\u5728\u5F00\u53D1\u4E2D..."
23
+ }),
24
+ requestUserInfoMenuData: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
25
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
26
+ while (1) switch (_context.prev = _context.next) {
45
27
  case 0:
46
- return _context2.abrupt("return", {
47
- token: 'demo-token',
28
+ _context.next = 2;
29
+ return sleep(100);
30
+ case 2:
31
+ return _context.abrupt("return", {
48
32
  userInfo: {
49
33
  id: '1',
50
34
  username: 'demo-user'
51
- }
35
+ },
36
+ menuData: menuData
52
37
  });
38
+ case 3:
39
+ case "end":
40
+ return _context.stop();
41
+ }
42
+ }, _callee);
43
+ })),
44
+ onLogin: ( /*#__PURE__*/function () {
45
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
46
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
47
+ while (1) switch (_context2.prev = _context2.next) {
48
+ case 0:
49
+ return _context2.abrupt("return", {
50
+ token: 'demo-token',
51
+ userInfo: {
52
+ id: '1',
53
+ username: 'demo-user'
54
+ }
55
+ });
56
+ case 1:
57
+ case "end":
58
+ return _context2.stop();
59
+ }
60
+ }, _callee2);
61
+ }));
62
+ return function (_x) {
63
+ return _ref2.apply(this, arguments);
64
+ };
65
+ }()),
66
+ onLogout: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
67
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
68
+ while (1) switch (_context3.prev = _context3.next) {
69
+ case 0:
70
+ console.log('退出');
53
71
  case 1:
54
72
  case "end":
55
- return _context2.stop();
73
+ return _context3.stop();
56
74
  }
57
- }, _callee2);
58
- }));
59
- return function (_x) {
60
- return _ref2.apply(this, arguments);
61
- };
62
- }()),
63
- onLogout: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
64
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
65
- while (1) switch (_context3.prev = _context3.next) {
66
- case 0:
67
- console.log('退出');
68
- case 1:
69
- case "end":
70
- return _context3.stop();
71
- }
72
- }, _callee3);
73
- }))
75
+ }, _callee3);
76
+ }))
77
+ })
74
78
  })
75
79
  });
76
80
  };
@@ -23,7 +23,12 @@ export var Home = function Home() {
23
23
  onClick: function onClick() {
24
24
  return navigate('/some-path');
25
25
  },
26
- children: "\u8DF3\u8F6C"
26
+ children: "\u8DF3\u8F6C404"
27
+ }), /*#__PURE__*/_jsx(Button, {
28
+ onClick: function onClick() {
29
+ return navigate('/menu/page2');
30
+ },
31
+ children: "\u8DF3\u8F6C \u83DC\u5355-\u4E8C\u7EA7"
27
32
  })]
28
33
  });
29
34
  };
@@ -16,7 +16,8 @@ export var DocumentTitle = function DocumentTitle(_ref) {
16
16
  pageStatus = _useAccessRouter$loca.pageStatus,
17
17
  pathname = _useAccessRouter$loca.pathname,
18
18
  pageTitle = _useAccessRouter$loca.pageTitle,
19
- intlMenuConfig = _useAccessRouter$loca.intlMenuConfig;
19
+ intlMenuConfig = _useAccessRouter$loca.intlMenuConfig,
20
+ localLangKey = _useAccessRouter$loca.localLangKey;
20
21
  var _useIntl = useIntl(),
21
22
  formatMessage = _useIntl.formatMessage;
22
23
  useEffect(function () {
@@ -28,9 +29,9 @@ export var DocumentTitle = function DocumentTitle(_ref) {
28
29
  // document.title = pageStatus + '';
29
30
  // return;
30
31
  // }
31
- document.title = pageTitle || formatMessage(_objectSpread(_objectSpread({}, intlMenuConfig), {}, {
32
- id: (intlMenuConfig === null || intlMenuConfig === void 0 ? void 0 : intlMenuConfig.id) || 'menu.unknown'
32
+ document.title = pageTitle || formatMessage(_objectSpread(_objectSpread({}, intlMenuConfig || localLangKey), {}, {
33
+ id: (intlMenuConfig === null || intlMenuConfig === void 0 ? void 0 : intlMenuConfig.id) || (localLangKey === null || localLangKey === void 0 ? void 0 : localLangKey.id) || 'menu.unknown'
33
34
  }));
34
- }, [pathname, pageStatus, pageTitle, intlMenuConfig, title]);
35
+ }, [pathname, pageStatus, pageTitle, intlMenuConfig, localLangKey, title]);
35
36
  return /*#__PURE__*/_jsx(_Fragment, {});
36
37
  };
@@ -17,13 +17,18 @@ 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 | 404 | 403;
20
+ pageStatus: 404 | 403 | 200;
21
21
  pageTitle: string;
22
22
  intlMenuConfig?: {
23
23
  id: string;
24
24
  defaultMessage: string;
25
25
  localConfigPath: string;
26
26
  } | undefined;
27
+ localLangKey?: {
28
+ id: string;
29
+ defaultMessage: string;
30
+ localConfigPath: string;
31
+ } | undefined;
27
32
  })[];
28
33
  /** 关闭页面 */
29
34
  closePage(assignKey: string): number;
@@ -33,22 +38,37 @@ export declare class KeepAliveClass {
33
38
  closeOtherPage(isRetainCurrentKey?: boolean, retainKeys?: string[]): void;
34
39
  /** 刷新页面 */
35
40
  refreshPage(assignKey: string): Promise<void>;
36
- /** hooks 回调页面 初次加载 或 再次加载,以及参数的变化 */
41
+ /**
42
+ * @desc hooks 回调页面 初次加载 或 再次加载,以及参数的变化
43
+ * TODO: 使用时候需要注意闭包问题
44
+ */
37
45
  useLifeCycle: (callback: IPageLifeCycleCallback) => void;
38
46
  /** 获取缓存页面数组 */
39
47
  useKeepAlivePages: () => (import("react-router-dom").Location & {
40
- pageStatus: 200 | 404 | 403;
48
+ pageStatus: 404 | 403 | 200;
41
49
  pageTitle: string;
42
50
  intlMenuConfig?: {
43
51
  id: string;
44
52
  defaultMessage: string;
45
53
  localConfigPath: string;
46
54
  } | undefined;
55
+ localLangKey?: {
56
+ id: string;
57
+ defaultMessage: string;
58
+ localConfigPath: string;
59
+ } | undefined;
47
60
  })[];
48
61
  /** 更新当前路由页面 */
49
62
  updateCurrentPage(index?: number): void;
50
63
  /** 根渲染容器组件 */
51
64
  Content: () => import("react/jsx-runtime").JSX.Element;
65
+ /** 自动刷新 KeepAliveItem 组件(只在再次激活时候有效)
66
+ * 注意:此组件被定义为类属性而不是独立函数组件,是为了能够直接访问
67
+ * KeepAliveClass 实例上的方法和状态(例如 this.useLifeCycle、this.refreshPage)。
68
+ * 如需修改为独立组件,需要通过 props 显式传入这些依赖,这里为了简化内部实现,
69
+ * 保留为类属性组件的实现方式是有意为之。
70
+ */
71
+ private AutoRefreshKeepAliveItem;
52
72
  /** 页面挂载组件 */
53
73
  private KeepAliveItem;
54
74
  }
@@ -54,23 +54,11 @@ export var KeepAliveClass = /*#__PURE__*/function () {
54
54
  /** 最后打开页面的Location */
55
55
  lastLocation: undefined
56
56
  });
57
- /** hooks 回调页面 初次加载 或 再次加载,以及参数的变化 */
57
+ /**
58
+ * @desc hooks 回调页面 初次加载 或 再次加载,以及参数的变化
59
+ * TODO: 使用时候需要注意闭包问题
60
+ */
58
61
  _defineProperty(this, "useLifeCycle", function (callback) {
59
- // const local = useLocation();
60
- // const lock = useRef(false);
61
- // const fn = useCallback(() => {
62
- // const map = this.keepAliveData.pageLifeCycle;
63
- // const key = this.keepAliveData.currentPathname;
64
- // const oldMap = map[key];
65
-
66
- // if (!oldMap || !oldMap.callback) {
67
- // map[key] = {...oldMap, callback};
68
- // map[key]?.notification?.();
69
- // }
70
- // }, []);
71
-
72
- // !lock.current && fn();
73
-
74
62
  var _useRef = useRef({
75
63
  /** 初次执行锁 */
76
64
  lock: false,
@@ -172,12 +160,40 @@ export var KeepAliveClass = /*#__PURE__*/function () {
172
160
  })]
173
161
  });
174
162
  });
163
+ /** 自动刷新 KeepAliveItem 组件(只在再次激活时候有效)
164
+ * 注意:此组件被定义为类属性而不是独立函数组件,是为了能够直接访问
165
+ * KeepAliveClass 实例上的方法和状态(例如 this.useLifeCycle、this.refreshPage)。
166
+ * 如需修改为独立组件,需要通过 props 显式传入这些依赖,这里为了简化内部实现,
167
+ * 保留为类属性组件的实现方式是有意为之。
168
+ */
169
+ _defineProperty(this, "AutoRefreshKeepAliveItem", function () {
170
+ var _useAccessRouter2 = useAccessRouter(),
171
+ location = _useAccessRouter2.location;
172
+ var ref = useRef(location);
173
+ var count = useRef(0);
174
+ // 计数器大于该阈值才生效,避免初次加载时触发自动刷新
175
+ var ACTIVATION_COUNT_THRESHOLD = 2;
176
+ ref.current = location;
177
+ _this.useLifeCycle(function (type) {
178
+ // 计数器大于2次才生效,避免初次加载时候触发
179
+ if (type === ELifeCycleType.ACTIVATED && count.current > ACTIVATION_COUNT_THRESHOLD) {
180
+ var _ref$current$state;
181
+ // console.log('ACTIVATED', ref.current);
182
+ if (!((_ref$current$state = ref.current.state) !== null && _ref$current$state !== void 0 && _ref$current$state.disabledReload)) {
183
+ // debugger;
184
+ _this.refreshPage(ref.current.pathname);
185
+ }
186
+ }
187
+ count.current += 1;
188
+ });
189
+ return /*#__PURE__*/_jsx(_Fragment, {});
190
+ });
175
191
  /** 页面挂载组件 */
176
192
  _defineProperty(this, "KeepAliveItem", function (_ref) {
177
193
  var activate = _ref.activate,
178
194
  idKey = _ref.idKey;
179
- var _useAccessRouter2 = useAccessRouter(),
180
- page = _useAccessRouter2.page;
195
+ var _useAccessRouter3 = useAccessRouter(),
196
+ page = _useAccessRouter3.page;
181
197
  var _useState3 = useState({}),
182
198
  _useState4 = _slicedToArray(_useState3, 2),
183
199
  update = _useState4[1];
@@ -211,7 +227,7 @@ export var KeepAliveClass = /*#__PURE__*/function () {
211
227
 
212
228
  useEffect(function () {
213
229
  if (activate && _this.contentDom) {
214
- cache.portal = cache.portal || /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(ErrorBoundary, {
230
+ cache.portal = cache.portal || /*#__PURE__*/createPortal( /*#__PURE__*/_jsxs(ErrorBoundary, {
215
231
  fallbackRender: function fallbackRender(_ref2) {
216
232
  var error = _ref2.error;
217
233
  return /*#__PURE__*/_jsx(_Fragment, {
@@ -229,7 +245,7 @@ export var KeepAliveClass = /*#__PURE__*/function () {
229
245
  })
230
246
  });
231
247
  },
232
- children: (page === null || page === void 0 ? void 0 : page.element) || /*#__PURE__*/_jsx(NoFoundPage, {})
248
+ children: [(page === null || page === void 0 ? void 0 : page.element) || /*#__PURE__*/_jsx(NoFoundPage, {}), /*#__PURE__*/_jsx(_this.AutoRefreshKeepAliveItem, {})]
233
249
  }), cache.div);
234
250
  _this.contentDom.appendChild(cache.div);
235
251
  cache.mount = true;
@@ -6,13 +6,18 @@ 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 | 404 | 403;
9
+ pageStatus: 404 | 403 | 200;
10
10
  pageTitle: string;
11
11
  intlMenuConfig?: {
12
12
  id: string;
13
13
  defaultMessage: string;
14
14
  localConfigPath: string;
15
15
  } | undefined;
16
+ localLangKey?: {
17
+ id: string;
18
+ defaultMessage: string;
19
+ localConfigPath: string;
20
+ } | undefined;
16
21
  })[];
17
22
  /** 根 */
18
23
  export declare const KeepAliveRoot: () => import("react/jsx-runtime").JSX.Element;
@@ -48,7 +48,11 @@ export var NoFoundPage = function NoFoundPage(_ref) {
48
48
  _context.next = 5;
49
49
  return sleep(0);
50
50
  case 5:
51
- navigate((home === null || home === void 0 ? void 0 : home.key) || '/');
51
+ navigate((home === null || home === void 0 ? void 0 : home.key) || '/', {
52
+ state: {
53
+ disabledReload: true
54
+ }
55
+ });
52
56
  case 6:
53
57
  case "end":
54
58
  return _context.stop();
@@ -41,9 +41,17 @@ export var TabsLayout = function TabsLayout() {
41
41
  var search = (_pathNameList$find = pathNameList.find(function (ii) {
42
42
  return ii.pathname === to;
43
43
  })) === null || _pathNameList$find === void 0 ? void 0 : _pathNameList$find.search;
44
- navigate("".concat(to).concat(search));
44
+ navigate("".concat(to).concat(search), {
45
+ state: {
46
+ disabledReload: true
47
+ }
48
+ });
45
49
  } else {
46
- navigate(to);
50
+ navigate(to, {
51
+ state: {
52
+ disabledReload: true
53
+ }
54
+ });
47
55
  }
48
56
  };
49
57
 
@@ -133,14 +141,14 @@ export var TabsLayout = function TabsLayout() {
133
141
  };
134
142
  }()),
135
143
  items: pathNameList.map(function (item) {
136
- var _item$intlMenuConfig;
144
+ var _item$intlMenuConfig, _item$localLangKey;
137
145
  // 判断是否当前活跃标签
138
146
  var isCurrent = eq(state.activeKey, item.pathname);
139
147
  return {
140
148
  key: item.pathname,
141
149
  label: /*#__PURE__*/_jsx(TabItem, {
142
- pageTitle: item.pageTitle || /*#__PURE__*/_jsx(FormattedMessage, _objectSpread(_objectSpread({}, item.intlMenuConfig), {}, {
143
- id: ((_item$intlMenuConfig = item.intlMenuConfig) === null || _item$intlMenuConfig === void 0 ? void 0 : _item$intlMenuConfig.id) || 'menu.unknown'
150
+ pageTitle: item.pageTitle || /*#__PURE__*/_jsx(FormattedMessage, _objectSpread(_objectSpread({}, item.intlMenuConfig || item.localLangKey), {}, {
151
+ id: ((_item$intlMenuConfig = item.intlMenuConfig) === null || _item$intlMenuConfig === void 0 ? void 0 : _item$intlMenuConfig.id) || ((_item$localLangKey = item.localLangKey) === null || _item$localLangKey === void 0 ? void 0 : _item$localLangKey.id) || 'menu.unknown'
144
152
  })),
145
153
  pathname: item.pathname,
146
154
  isCurrent: isCurrent,
@@ -19,5 +19,11 @@ export declare const useAccessRouter: () => {
19
19
  defaultMessage: string;
20
20
  localConfigPath: string;
21
21
  } | undefined;
22
+ /** 兼容历史数据保留的, 只在使用时候会用到 */
23
+ localLangKey?: {
24
+ id: string;
25
+ defaultMessage: string;
26
+ localConfigPath: string;
27
+ } | undefined;
22
28
  };
23
29
  };
@@ -64,7 +64,10 @@ export var handleMenuData = function handleMenuData() {
64
64
  // 菜单页面收集
65
65
  item.label = /*#__PURE__*/_jsxs(_Fragment, {
66
66
  children: [item.label, /*#__PURE__*/_jsx(Link, {
67
- to: item.key
67
+ to: item.key,
68
+ state: {
69
+ disabledReload: true
70
+ }
68
71
  })]
69
72
  });
70
73
  fullPathDataMap[item.key] = item;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/pro-layout",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",