@ccs-ui/rc-pro 2.3.6-beta-13 → 2.3.6-beta-15

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.
@@ -1,7 +1,7 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["onDisabled", "onHidden"],
2
+ var _excluded = ["onDisabled", "onHidden", "auth"],
3
3
  _excluded2 = ["key", "label", "auth", "confirm", "showRowsCount", "onDisabled", "onHidden"],
4
- _excluded3 = ["key", "label", "disabled", "auth", "confirm", "showRowsCount", "onDisabled", "onHidden"];
4
+ _excluded3 = ["key", "label", "disabled", "auth", "confirm", "showRowsCount"];
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -33,35 +33,35 @@ export default function CssButtonGroup(_ref) {
33
33
  var modalRef = useRef(null);
34
34
  var _ref3 = useContext(TableSelectionContext) || {},
35
35
  selectedRows = _ref3.selectedRows;
36
+
37
+ // 有权限的按钮
36
38
  var authButtons = [];
37
39
 
38
- // 过滤隐藏按钮
39
- authButtons = items.filter(function (item) {
40
- return !item.hidden && !(item.onHidden && item.onHidden(selectedRows || []));
41
- });
40
+ // 变量按钮
41
+ items.forEach(function (_ref4) {
42
+ var onDisabled = _ref4.onDisabled,
43
+ onHidden = _ref4.onHidden,
44
+ auth = _ref4.auth,
45
+ item = _objectWithoutProperties(_ref4, _excluded);
46
+ // 权限校验
47
+ if (onAuth && auth && !onAuth(auth)) {
48
+ return;
49
+ }
42
50
 
43
- // link按钮删除无用参数
44
- if (isLink) {
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
- authButtons = authButtons.map(function (_ref4) {
47
- var onDisabled = _ref4.onDisabled,
48
- onHidden = _ref4.onHidden,
49
- b = _objectWithoutProperties(_ref4, _excluded);
50
- return _objectSpread({}, b);
51
- });
52
- }
51
+ // 隐藏按钮
52
+ if (onHidden && onHidden(selectedRows || [])) {
53
+ return;
54
+ }
53
55
 
54
- // 需要判断权限
55
- if (onAuth) {
56
- authButtons = authButtons.filter(function (b) {
57
- if (b.auth) return onAuth(b.auth);
58
- return true;
59
- });
60
- }
61
- if (!items || items.length === 0) return null;
56
+ // 禁用按钮
57
+ if (onDisabled && onDisabled(selectedRows || [])) {
58
+ item.disabled = true;
59
+ }
60
+ authButtons.push(item);
61
+ });
62
+ if (!authButtons || items.length === 0) return null;
62
63
 
63
- // 当前菜单下查找按钮权限
64
- var showBtns = authButtons.splice(0, showCount || items.length);
64
+ // 按钮点击
65
65
  var handleOnClick = function handleOnClick(key) {
66
66
  if (!onClick) return;
67
67
  var item = items.find(function (i) {
@@ -84,6 +84,10 @@ export default function CssButtonGroup(_ref) {
84
84
  }
85
85
  onClick(key, selectedRows);
86
86
  };
87
+
88
+ // 显示的按钮
89
+ var showBtns = authButtons.splice(0, showCount || items.length);
90
+
87
91
  // link类型按钮
88
92
  if (isLink) {
89
93
  return /*#__PURE__*/_jsxs(_Fragment, {
@@ -146,12 +150,7 @@ export default function CssButtonGroup(_ref) {
146
150
  auth = _ref6.auth,
147
151
  confirm = _ref6.confirm,
148
152
  showRowsCount = _ref6.showRowsCount,
149
- onDisabled = _ref6.onDisabled,
150
- onHidden = _ref6.onHidden,
151
153
  restProps = _objectWithoutProperties(_ref6, _excluded3);
152
- // 按钮禁用
153
- var isDisabled = disabled || onDisabled && onDisabled(selectedRows || []);
154
-
155
154
  // 更多按钮
156
155
  if (index === showBtns.length - 1 && authButtons.length > 0) {
157
156
  return /*#__PURE__*/_jsxs(Space.Compact, {
@@ -160,7 +159,7 @@ export default function CssButtonGroup(_ref) {
160
159
  onClick: function onClick() {
161
160
  return handleOnClick(key);
162
161
  },
163
- disabled: isDisabled,
162
+ disabled: disabled,
164
163
  children: [label, showRowsCount && selectedRows !== null && selectedRows !== void 0 && selectedRows.length ? "(".concat(selectedRows === null || selectedRows === void 0 ? void 0 : selectedRows.length, ")") : '']
165
164
  })), /*#__PURE__*/_jsx(Dropdown, {
166
165
  menu: {
@@ -178,7 +177,7 @@ export default function CssButtonGroup(_ref) {
178
177
  }
179
178
  return /*#__PURE__*/_jsxs(Button, _objectSpread(_objectSpread({}, restProps), {}, {
180
179
  size: size,
181
- disabled: isDisabled,
180
+ disabled: disabled,
182
181
  onClick: function onClick() {
183
182
  return handleOnClick(key);
184
183
  },
@@ -16,7 +16,7 @@ export type DialogButtonsProps<T> = Pick<CcsDialogModalProps, 'okText' | 'onClos
16
16
  export type DialogButtonRef = {
17
17
  onSetButtons: (e: React.ReactElement) => void;
18
18
  };
19
- export declare const DialogButtonHolder: <TParams, TData>({ auth, extraBtn, formRef, request, onOk, onClose, buttonRef, requestFieldNames, formInitialValues, preventRequestHandle, }: Pick<CcsDialogModalProps<TParams, TData>, "auth" | "request" | "onClose" | "onOk" | "extraBtn" | "requestFieldNames" | "preventRequestHandle"> & {
19
+ export declare const DialogButtonHolder: <TParams, TData>({ auth, extraBtn, formRef, request, onOk, onClose, buttonRef, requestFieldNames, formInitialValues, preventRequestHandle, }: Pick<CcsDialogModalProps<TParams, TData>, "auth" | "request" | "onOk" | "onClose" | "extraBtn" | "requestFieldNames" | "preventRequestHandle"> & {
20
20
  formRef: React.RefObject<DialogFormRef<TParams>>;
21
21
  formInitialValues: FormProps['initialValues'];
22
22
  buttonRef: RefObject<DialogButtonRef>;
@@ -1,5 +1,7 @@
1
1
  import { useIsomorphicLayoutEffect, useMemoizedFn } from 'ahooks';
2
+ import { useRef } from 'react';
2
3
  export function useResizeEffect(effect, targetRef) {
4
+ var ref = useRef(0);
3
5
  var fn = useMemoizedFn(effect);
4
6
  useIsomorphicLayoutEffect(function () {
5
7
  var target = targetRef.current;
@@ -7,9 +9,12 @@ export function useResizeEffect(effect, targetRef) {
7
9
  if (window.ResizeObserver) {
8
10
  var animationFrame;
9
11
  var observer = new ResizeObserver(function () {
12
+ // 隐藏了,为0不处理
13
+ if (target.clientWidth === 0 || (target === null || target === void 0 ? void 0 : target.clientWidth) === ref.current) return;
10
14
  animationFrame = window.requestAnimationFrame(function () {
11
15
  return fn(target);
12
16
  });
17
+ ref.current = target === null || target === void 0 ? void 0 : target.clientWidth;
13
18
  });
14
19
  observer.observe(target);
15
20
  return function () {
@@ -1,17 +1,18 @@
1
1
  import { BreadcrumbProps } from 'antd';
2
2
  import { JSXElementConstructor, ReactElement } from 'react';
3
+ import { Location } from 'react-router';
3
4
  import CCS from '..';
4
5
  import { MenuType } from '../ccs';
5
6
  import './index.less';
6
- export type CacheComponent = {
7
+ export type CacheRouter = {
7
8
  key: string;
8
9
  label: string;
9
- locationKey: string;
10
10
  urlAuthList: string[];
11
11
  timestamp: number;
12
12
  outlet: ReactElement<any, string | JSXElementConstructor<any>> | null;
13
13
  children?: ReactElement<any, string | JSXElementConstructor<any>> | null;
14
14
  breadcrumb: BreadcrumbProps['items'];
15
+ pageLocation: Location;
15
16
  };
16
17
  type PropsType = {
17
18
  maxLen?: number;
@@ -19,6 +19,7 @@ import CcsUtils from '@ccs-ui/utils';
19
19
  import { useUpdate, useUpdateEffect } from 'ahooks';
20
20
  import { Button, Dropdown, Empty, Tabs } from 'antd';
21
21
  import classnames from 'classnames';
22
+ import updateHelper from 'immutability-helper';
22
23
  import { useMemo, useRef } from 'react';
23
24
  import { useLocation } from 'react-router';
24
25
  import { useOutlet } from 'react-router-dom';
@@ -131,10 +132,9 @@ export default function KeepAliveTabs(_ref) {
131
132
  _ref$menuItems = _ref.menuItems,
132
133
  menuItems = _ref$menuItems === void 0 ? [] : _ref$menuItems,
133
134
  className = _ref.className;
134
- var components = useRef([]);
135
+ var routers = useRef([]);
135
136
  var location = useLocation();
136
- var pathname = location.pathname,
137
- locationKey = location.key;
137
+ var pathname = location.pathname;
138
138
  var outlet = useOutlet();
139
139
  var update = useUpdate();
140
140
  var _useAppConfig = useAppConfig(),
@@ -143,19 +143,19 @@ export default function KeepAliveTabs(_ref) {
143
143
  var isColorful = theme === 'colorful';
144
144
 
145
145
  // 超过缓存数量,删除第一个
146
- if (components.current.length >= maxLen) {
147
- components.current = components.current.slice(1);
146
+ if (routers.current.length >= maxLen) {
147
+ routers.current = routers.current.slice(1);
148
148
  }
149
149
 
150
150
  // 菜单改变,更新用户权限信息
151
151
  useUpdateEffect(function () {
152
- components.current.forEach(function (component) {
152
+ routers.current.forEach(function (router) {
153
153
  var _menu$btnAuth;
154
- var menu = findMenuById(menuItems, component.key);
155
- component.urlAuthList = (menu === null || menu === void 0 || (_menu$btnAuth = menu.btnAuth) === null || _menu$btnAuth === void 0 ? void 0 : _menu$btnAuth.map(function (b) {
154
+ var menu = findMenuById(menuItems, router.key);
155
+ router.urlAuthList = (menu === null || menu === void 0 || (_menu$btnAuth = menu.btnAuth) === null || _menu$btnAuth === void 0 ? void 0 : _menu$btnAuth.map(function (b) {
156
156
  return b.code;
157
157
  })) || [];
158
- component.timestamp = new Date().getTime();
158
+ router.timestamp = new Date().getTime();
159
159
  });
160
160
  update();
161
161
  }, [menuItems]);
@@ -234,68 +234,110 @@ export default function KeepAliveTabs(_ref) {
234
234
  breadcrumb: breadcrumb
235
235
  });
236
236
  }, [pathname]);
237
- var component = components.current.find(function (c) {
238
- return c.key === pathname;
237
+ var activeKey = location.key;
238
+ // 路由数据
239
+ var routerIndex = routers.current.findIndex(function (c) {
240
+ return c.pageLocation.pathname === pathname;
239
241
  });
240
- if (!component) {
242
+ if (routerIndex > -1) {
243
+ // 路由已存在、判断search,state是否改变,如改变则更新路由数据
244
+ var router = routers.current[routerIndex];
245
+ if (router.pageLocation.search !== location.search || CcsUtils.jsonStringify(router.pageLocation.state) !== CcsUtils.jsonStringify(location.state)) {
246
+ // 更新路由数据,变更key,路由将重新加载
247
+ routers.current = updateHelper(routers.current, _defineProperty({}, routerIndex, {
248
+ key: {
249
+ $set: location.key
250
+ },
251
+ pageLocation: {
252
+ $set: location
253
+ }
254
+ }));
255
+ } else {
256
+ activeKey = router.pageLocation.key;
257
+ }
258
+ } else {
259
+ // 路由不存在,保存路由数据
241
260
  var _ref3 = curMenu || {},
242
261
  _ref3$btnAuth = _ref3.btnAuth,
243
262
  btnAuth = _ref3$btnAuth === void 0 ? [] : _ref3$btnAuth,
244
263
  _ref3$breadcrumb = _ref3.breadcrumb,
245
264
  breadcrumb = _ref3$breadcrumb === void 0 ? [] : _ref3$breadcrumb;
246
- components.current = [].concat(_toConsumableArray(components.current), [{
247
- locationKey: locationKey,
248
- key: pathname,
249
- timestamp: new Date().getTime(),
250
- label: (curMenu === null || curMenu === void 0 ? void 0 : curMenu.label) || '未知',
251
- outlet: curMenu ? outlet : /*#__PURE__*/_jsx(Empty, {
252
- description: "\u672A\u77E5\u9875\u9762"
253
- }),
254
- urlAuthList: btnAuth.map(function (b) {
255
- return b.code;
256
- }),
257
- breadcrumb: breadcrumb
258
- }]);
265
+ routers.current = updateHelper(routers.current, {
266
+ $push: [{
267
+ key: location.key,
268
+ timestamp: new Date().getTime(),
269
+ label: (curMenu === null || curMenu === void 0 ? void 0 : curMenu.label) || '未知',
270
+ outlet: curMenu ? outlet : /*#__PURE__*/_jsx(Empty, {
271
+ description: "\u672A\u77E5\u9875\u9762"
272
+ }),
273
+ urlAuthList: btnAuth.map(function (b) {
274
+ return b.code;
275
+ }),
276
+ breadcrumb: breadcrumb,
277
+ pageLocation: location
278
+ }]
279
+ });
259
280
  }
260
281
 
282
+ // tab路由切换,携带search,state参数
283
+ var onHistory = function onHistory(key) {
284
+ var tab = routers.current.find(function (c) {
285
+ return c.key === key;
286
+ });
287
+ if (tab) {
288
+ var _tab$pageLocation = tab.pageLocation,
289
+ _pathname = _tab$pageLocation.pathname,
290
+ state = _tab$pageLocation.state,
291
+ search = _tab$pageLocation.search;
292
+ history.push("".concat(_pathname).concat(search), state);
293
+ }
294
+ };
295
+
261
296
  // 页面主动销毁或关闭tab
262
- var onDestroy = function onDestroy(path) {
263
- var index = components.current.findIndex(function (c) {
264
- return c.key === path;
297
+ var onDestroy = function onDestroy(key) {
298
+ var index = routers.current.findIndex(function (c) {
299
+ return c.key === key;
265
300
  });
301
+ // 删除的路由
302
+ var delRouter = routers.current[index];
266
303
  if (index >= 0) {
267
- components.current.splice(index, 1);
268
- components.current = _toConsumableArray(components.current);
269
- if (path !== pathname) {
304
+ routers.current = updateHelper(routers.current, {
305
+ $splice: [[index, 1]]
306
+ });
307
+
308
+ // 不是删的自己
309
+ if (delRouter.key !== key) {
270
310
  update();
271
311
  return;
272
312
  }
273
313
 
274
314
  // 显示首页
275
- if (components.current.length === 0) {
315
+ if (routers.current.length === 0) {
276
316
  history.push('/');
277
317
  return;
278
318
  }
279
319
 
280
320
  // 显示前一个
281
- if (index === components.current.length) {
282
- history.push(components.current[index - 1].key);
321
+ if (index === routers.current.length) {
322
+ onHistory(routers.current[index - 1].key);
283
323
  return;
284
324
  }
285
325
 
286
326
  // 显示后一个
287
- history.push(components.current[index].key);
327
+ onHistory(routers.current[index].key);
288
328
  }
289
329
  };
330
+
331
+ // 扩展操作
290
332
  var onCloseTab = function onCloseTab(key) {
291
333
  // 关闭其他标签
292
334
  if (key === '1') {
293
- components.current = components.current.filter(function (c) {
335
+ routers.current = routers.current.filter(function (c) {
294
336
  return c.key === pathname;
295
337
  });
296
338
  update();
297
339
  } else {
298
- components.current = [];
340
+ routers.current = [];
299
341
  history.push('/');
300
342
  }
301
343
  };
@@ -318,26 +360,25 @@ export default function KeepAliveTabs(_ref) {
318
360
  id: "keep-alive-tabs",
319
361
  hideAdd: true,
320
362
  size: "small",
321
- onChange: function onChange(e) {
322
- history.push(e);
323
- },
363
+ onChange: onHistory,
324
364
  className: classnames(_defineProperty(_defineProperty(_defineProperty({}, 'ccs-keep-alive-tabs', !isColorful), 'dark', isDark), 'ccs-keep-alive-tabs-colorful', isColorful)),
325
- activeKey: pathname,
365
+ activeKey: activeKey,
326
366
  type: "editable-card",
327
367
  onEdit: function onEdit(e) {
328
368
  return onDestroy(e);
329
369
  },
330
- items: components.current,
331
- tabBarExtraContent: components.current.length > 2 ? tabBarExtraContent : null
332
- }), components.current.map(function (_ref4) {
370
+ items: routers.current,
371
+ tabBarExtraContent: routers.current.length > 2 ? tabBarExtraContent : null
372
+ }), routers.current.map(function (_ref4) {
333
373
  var key = _ref4.key,
334
374
  urlAuthList = _ref4.urlAuthList,
335
375
  timestamp = _ref4.timestamp,
336
376
  outlet = _ref4.outlet,
337
- breadcrumb = _ref4.breadcrumb;
377
+ breadcrumb = _ref4.breadcrumb,
378
+ pageLocation = _ref4.pageLocation;
338
379
  return /*#__PURE__*/_jsx(Page, {
339
- active: key === pathname,
340
- location: location,
380
+ active: pageLocation.pathname === pathname,
381
+ location: pageLocation,
341
382
  onDestroy: onDestroy,
342
383
  urlAuthList: urlAuthList,
343
384
  timestamp: timestamp,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Location } from 'react-router';
3
- import { CacheComponent } from '.';
4
- export type CachePageProps = Pick<CacheComponent, 'breadcrumb' | 'urlAuthList' | 'children' | 'timestamp'> & {
3
+ import { CacheRouter } from '.';
4
+ export type CachePageProps = Pick<CacheRouter, 'breadcrumb' | 'urlAuthList' | 'children' | 'timestamp'> & {
5
5
  /** 选中状态 */
6
6
  active: boolean;
7
7
  /** router location */
@@ -7,20 +7,20 @@ import { DialogElementsHolder } from "../dialog/hook";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
9
  export default /*#__PURE__*/memo(function (props) {
10
- var locationRef = useRef(props.location);
11
10
  var children = props.children,
12
11
  active = props.active,
13
12
  urlAuthList = props.urlAuthList,
14
13
  onDestroy = props.onDestroy,
15
- breadcrumb = props.breadcrumb;
16
- var id = "_tab_content_".concat(locationRef.current.key);
14
+ breadcrumb = props.breadcrumb,
15
+ location = props.location;
16
+ var id = "_tab_content_".concat(location.key);
17
17
  var dialogHolderRef = useRef(null);
18
18
  return /*#__PURE__*/_jsx(PageContext.Provider, {
19
19
  value: {
20
20
  id: id,
21
21
  dialogHolderRef: dialogHolderRef,
22
22
  isActive: active,
23
- location: locationRef.current,
23
+ location: location,
24
24
  onDestroy: onDestroy,
25
25
  onAuth: function onAuth(e) {
26
26
  return urlAuthList.includes(e);
@@ -1,7 +1,7 @@
1
1
  import { JSXElementConstructor, ReactElement } from 'react';
2
2
  import { Location } from 'react-router';
3
- import { CacheComponent } from '../layout-keep-alive';
4
- export type SinglePageProps = Pick<CacheComponent, 'breadcrumb' | 'urlAuthList'> & {
3
+ import { CacheRouter } from '../layout-keep-alive';
4
+ export type SinglePageProps = Pick<CacheRouter, 'breadcrumb' | 'urlAuthList'> & {
5
5
  /** router location */
6
6
  location: Location;
7
7
  /** children */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccs-ui/rc-pro",
3
- "version": "2.3.6-beta-13",
3
+ "version": "2.3.6-beta-15",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": {