@ccs-ui/rc-pro 2.3.6-beta-14 → 2.3.6-beta-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.
@@ -55,8 +55,6 @@ type FnContextType<T = Store> = {
55
55
  type CcsFieldNamesType = {
56
56
  dataSource?: string[];
57
57
  total?: string[];
58
- current?: string[];
59
- pageSize?: string[];
60
58
  };
61
59
  type CcsDialogFieldNames = {
62
60
  /** 成功标识字段 */
@@ -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 () {
@@ -6,8 +6,6 @@ declare const useAppConfig: () => import("../context").CssAppConfigType;
6
6
  export declare const useProTableFields: () => {
7
7
  dataSource: string[];
8
8
  total: string[];
9
- current: string[];
10
- pageSize: string[];
11
9
  };
12
10
  export declare const useProTableTreeFields: () => {
13
11
  dataSource: string[];
@@ -23,8 +23,8 @@ export var useProTableFields = function useProTableFields() {
23
23
  var context = useContext(AppConfigContext) || {};
24
24
  return _objectSpread({
25
25
  dataSource: ['data', 'result'],
26
- current: ['data', 'pageNo'],
27
- pageSize: ['data', 'pageSize'],
26
+ // current: ['data', 'pageNo'],
27
+ // pageSize: ['data', 'pageSize'],
28
28
  total: ['data', 'totalNum']
29
29
  }, context === null || context === void 0 || (_context$fieldNames = context.fieldNames) === null || _context$fieldNames === void 0 ? void 0 : _context$fieldNames.proTable);
30
30
  };
@@ -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 */
@@ -24,6 +24,7 @@ type TableTitleType<T> = {
24
24
  data: T[];
25
25
  onClear: () => void;
26
26
  };
27
+ /** 请求参数类型 */
27
28
  export type CcsRequestProps = {
28
29
  pageNo?: number;
29
30
  pageSize?: number;
@@ -39,7 +40,7 @@ export type CcsTableProps<T> = Omit<TableProps<T>, 'columns' | 'title'> & {
39
40
  data?: CCS.TableData<T>;
40
41
  /** request 方法 */
41
42
  request?: (params: CcsRequestProps) => Promise<any>;
42
- /** request 额外参数 dataSource: ['data', 'result']; current: ['data', 'pageNo']; pageSize: ['data', 'pageSize']; total: ['data', 'totalNum'] */
43
+ /** request 额外参数 */
43
44
  requestParam?: ParamType;
44
45
  /** 接口字段指定,默认: */
45
46
  fieldNames?: CcsFieldNamesType;
@@ -31,6 +31,8 @@ import HeadComponent from "./head";
31
31
  import "./index.less";
32
32
  import TableOperation from "./operation";
33
33
  import TableTree from "./tree";
34
+
35
+ /** 请求参数类型 */
34
36
  import { jsx as _jsx } from "react/jsx-runtime";
35
37
  import { Fragment as _Fragment } from "react/jsx-runtime";
36
38
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -176,11 +178,12 @@ var InternalProTable = function InternalProTable(props) {
176
178
  var formValues,
177
179
  pageValue,
178
180
  params,
181
+ _filtersRef$current,
182
+ filters,
183
+ orderProps,
179
184
  _treeRef$current,
180
185
  requestResult,
181
186
  dataSource,
182
- _pageSize,
183
- current,
184
187
  total,
185
188
  _args = arguments;
186
189
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -198,75 +201,91 @@ var InternalProTable = function InternalProTable(props) {
198
201
  }
199
202
  });
200
203
  }
204
+
205
+ // 构建请求参数
201
206
  pageValue = pagination === false ? {} : {
202
207
  pageNo: pageNo,
203
208
  pageSize: pageSize
204
209
  };
205
- params = _objectSpread(_objectSpread(_objectSpread({
210
+ params = _objectSpread(_objectSpread({
206
211
  query: _objectSpread(_objectSpread({}, requestParam), formValues)
207
- }, pageValue), filtersRef.current), {}, {
212
+ }, pageValue), {}, {
208
213
  eventType: eventType
209
- }); // 异步树
214
+ }); // 列过滤或排序参数
215
+ _filtersRef$current = filtersRef.current, filters = _filtersRef$current.filters, orderProps = _filtersRef$current.orderProps;
216
+ if (Object.keys(filters).length > 0) {
217
+ params.filters = filters;
218
+ }
219
+ if (orderProps.length > 0) {
220
+ params.orderProps = orderProps;
221
+ }
222
+
223
+ // 异步树
210
224
  if (!parentFieldName) {
211
- _context.next = 7;
225
+ _context.next = 10;
212
226
  break;
213
227
  }
214
228
  (_treeRef$current = treeRef.current) === null || _treeRef$current === void 0 || _treeRef$current.onRequestTree(params.query, record);
215
229
  return _context.abrupt("return");
216
- case 7:
230
+ case 10:
217
231
  // 发起请求
218
232
  setData(function (d) {
219
233
  return _objectSpread(_objectSpread({}, d), {}, {
220
234
  loading: true
221
235
  });
222
236
  });
223
- _context.next = 10;
237
+ _context.next = 13;
224
238
  return httpRequest(params);
225
- case 10:
239
+ case 13:
226
240
  requestResult = _context.sent;
227
241
  if (!requestResult) {
228
- _context.next = 22;
242
+ _context.next = 23;
229
243
  break;
230
244
  }
231
245
  // 获取table数据
232
- dataSource = getDataFromFields(requestResult, fieldNames.dataSource);
233
- _pageSize = getDataFromFields(requestResult, fieldNames.pageSize);
234
- current = getDataFromFields(requestResult, fieldNames.current);
246
+ dataSource = getDataFromFields(requestResult, fieldNames.dataSource); // const pageSize = getDataFromFields(
247
+ // requestResult,
248
+ // fieldNames.pageSize,
249
+ // );
250
+ // const current = getDataFromFields(requestResult, fieldNames.current);
235
251
  total = getDataFromFields(requestResult, fieldNames.total);
236
- if (!(total === undefined || _pageSize === undefined || current === undefined || dataSource === undefined)) {
237
- _context.next = 19;
252
+ if (!(total === undefined ||
253
+ // pageSize === undefined ||
254
+ // current === undefined ||
255
+ dataSource === undefined)) {
256
+ _context.next = 20;
238
257
  break;
239
258
  }
240
259
  setData({
241
260
  dataSource: dataSource,
242
- pageSize: _pageSize,
243
- current: current,
261
+ pageSize: pageSize,
262
+ current: pageNo,
244
263
  total: total,
245
264
  loading: false
246
265
  });
247
266
  return _context.abrupt("return");
248
- case 19:
267
+ case 20:
249
268
  // 当前页无数据,返回上一页
250
- if (!dataSource.length && current !== 1 && current !== undefined) {
251
- onRequest('reload', current - 1);
269
+ if (!dataSource.length && pageNo !== 1) {
270
+ onRequest('reload', pageNo - 1);
252
271
  } else {
253
272
  setData({
254
- current: current,
255
- pageSize: _pageSize,
273
+ current: pageNo,
274
+ pageSize: pageSize,
256
275
  loading: false,
257
276
  dataSource: dataSource,
258
277
  total: total || 0
259
278
  });
260
279
  }
261
- _context.next = 23;
280
+ _context.next = 24;
262
281
  break;
263
- case 22:
282
+ case 23:
264
283
  setData(function (d) {
265
284
  return _objectSpread(_objectSpread({}, d), {}, {
266
285
  loading: false
267
286
  });
268
287
  });
269
- case 23:
288
+ case 24:
270
289
  case "end":
271
290
  return _context.stop();
272
291
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccs-ui/rc-pro",
3
- "version": "2.3.6-beta-14",
3
+ "version": "2.3.6-beta-16",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": {