@pointcloud/pcloud-components 1.0.1 → 1.0.3

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,6 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
- import React, { useRef, useEffect, useCallback, useContext } from 'react';
3
+ import React, { useRef, useEffect, useCallback, useContext, useMemo } from 'react';
4
4
  import classNames from 'classnames';
5
5
  import { ConfigContext } from "../ConfigProvider";
6
6
  import "./styles/index.less";
@@ -286,19 +286,23 @@ function AnimatedScrollList(props) {
286
286
  }, [data, renderItem, getItemKey]);
287
287
 
288
288
  // 容器样式
289
- var containerStyle = _objectSpread({
290
- height: containerHeight,
291
- width: containerWidth,
292
- overflow: showScrollbar ? 'auto' : 'hidden',
293
- position: 'relative'
294
- }, style);
289
+ var containerStyle = useMemo(function () {
290
+ return _objectSpread({
291
+ height: containerHeight,
292
+ width: containerWidth,
293
+ overflow: showScrollbar ? 'auto' : 'hidden',
294
+ position: 'relative'
295
+ }, style);
296
+ }, [containerHeight, containerWidth, showScrollbar, style]);
295
297
 
296
298
  // 内容容器样式
297
- var contentStyle = {
298
- display: 'flex',
299
- flexDirection: isVertical ? 'column' : 'row',
300
- willChange: 'transform'
301
- };
299
+ var contentStyle = useMemo(function () {
300
+ return {
301
+ display: 'flex',
302
+ flexDirection: isVertical ? 'column' : 'row',
303
+ willChange: 'transform'
304
+ };
305
+ }, [isVertical]);
302
306
  return /*#__PURE__*/_jsxs("div", {
303
307
  className: wrapperClass,
304
308
  children: [header && /*#__PURE__*/_jsx("div", {
@@ -125,14 +125,10 @@ var forwardCRUD = /*#__PURE__*/forwardRef(function (props, ref) {
125
125
  _useState12 = _slicedToArray(_useState11, 2),
126
126
  conditionVisible = _useState12[0],
127
127
  setConditionVisible = _useState12[1];
128
- var _useState13 = useState(0),
128
+ var _useState13 = useState(props.tableProps || {}),
129
129
  _useState14 = _slicedToArray(_useState13, 2),
130
- refreshKey = _useState14[0],
131
- setRefreshKey = _useState14[1];
132
- var _useState15 = useState(props.tableProps || {}),
133
- _useState16 = _slicedToArray(_useState15, 2),
134
- tablePropsState = _useState16[0],
135
- setTablePropsState = _useState16[1];
130
+ tablePropsState = _useState14[0],
131
+ setTablePropsState = _useState14[1];
136
132
  var originalColumnsRef = useRef(((_props$tableProps = props.tableProps) === null || _props$tableProps === void 0 ? void 0 : _props$tableProps.columns) || []);
137
133
  var _DForm$useForm = DForm.useForm(),
138
134
  _DForm$useForm2 = _slicedToArray(_DForm$useForm, 1),
@@ -141,7 +137,7 @@ var forwardCRUD = /*#__PURE__*/forwardRef(function (props, ref) {
141
137
  return classNames(_defineProperty({
142
138
  fullscreen: fullScreen
143
139
  }, "".concat(prefixCls, "-crud"), !!prefixCls), classname, className);
144
- }, [fullScreen]);
140
+ }, [fullScreen, prefixCls, classname, className]);
145
141
  var visible = useMemo(function () {
146
142
  return conditionVisible ? 'visible' : 'hidden';
147
143
  }, [conditionVisible]);
@@ -307,12 +303,11 @@ var forwardCRUD = /*#__PURE__*/forwardRef(function (props, ref) {
307
303
  var _tableRef$current2, _tableRef$current2$re;
308
304
  (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 || (_tableRef$current2$re = _tableRef$current2.refreshToPage) === null || _tableRef$current2$re === void 0 || _tableRef$current2$re.call(_tableRef$current2, refreshOptions.targetPage);
309
305
  } else if (!finalStrategy.keepPage) {
310
- setRefreshKey(function (prev) {
311
- return prev + 1;
312
- });
313
- } else {
314
306
  var _tableRef$current3;
315
- (_tableRef$current3 = tableRef.current) === null || _tableRef$current3 === void 0 || _tableRef$current3.refresh();
307
+ (_tableRef$current3 = tableRef.current) === null || _tableRef$current3 === void 0 || _tableRef$current3.refreshToPage(1);
308
+ } else {
309
+ var _tableRef$current4;
310
+ (_tableRef$current4 = tableRef.current) === null || _tableRef$current4 === void 0 || _tableRef$current4.refresh();
316
311
  }
317
312
  onRefresh === null || onRefresh === void 0 || onRefresh();
318
313
  }, [memoizedRefreshStrategy, onRefresh, form]);
@@ -590,6 +585,14 @@ var forwardCRUD = /*#__PURE__*/forwardRef(function (props, ref) {
590
585
  }, modalFormProps === null || modalFormProps === void 0 ? void 0 : modalFormProps.formProps)
591
586
  };
592
587
  }, [modalConfig, detailData, handleCancel, handleModalOk, modalFormProps, classname]);
588
+ var onActions = useMemo(function () {
589
+ return {
590
+ setFullScreen: setFullScreen,
591
+ handleRefresh: handleRefresh,
592
+ onColumnSettingChanged: onColumnSettingChanged,
593
+ setConditionVisible: setConditionVisible
594
+ };
595
+ }, [setFullScreen, handleRefresh, onColumnSettingChanged, setConditionVisible]);
593
596
  useImperativeHandle(ref, function () {
594
597
  return {
595
598
  refresh: function refresh(strategy, refreshOptions) {
@@ -662,18 +665,13 @@ var forwardCRUD = /*#__PURE__*/forwardRef(function (props, ref) {
662
665
  fullScreen: fullScreen,
663
666
  conditionVisible: conditionVisible,
664
667
  columns: originalColumnsRef.current,
665
- onActions: {
666
- setFullScreen: setFullScreen,
667
- handleRefresh: handleRefresh,
668
- onColumnSettingChanged: onColumnSettingChanged,
669
- setConditionVisible: setConditionVisible
670
- }
668
+ onActions: onActions
671
669
  })]
672
670
  }), /*#__PURE__*/_jsx(DTable, _objectSpread(_objectSpread({
673
671
  ref: tableRef
674
672
  }, tablePropsWithSearch), {}, {
675
673
  className: "".concat(classname, "-table")
676
- }), refreshKey), mergedModalFormProps && /*#__PURE__*/_jsx(ModalForm, _objectSpread({}, mergedModalFormProps))]
674
+ })), mergedModalFormProps && /*#__PURE__*/_jsx(ModalForm, _objectSpread({}, mergedModalFormProps))]
677
675
  });
678
676
  });
679
677
  export default forwardCRUD;
@@ -1,7 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- import { memo, useState, useRef, useEffect, useMemo } from 'react';
4
+ import { memo, useState, useRef, useEffect, useMemo, useCallback } from 'react';
5
5
  import classNames from 'classnames';
6
6
  import { Popover, Checkbox, Button } from 'antd';
7
7
  import { ReloadOutlined, FullscreenOutlined, FullscreenExitOutlined, BarsOutlined, HolderOutlined, SearchOutlined } from '@ant-design/icons';
@@ -67,18 +67,18 @@ function Toolbar(_ref) {
67
67
  setRotating(false);
68
68
  }, 500);
69
69
  };
70
- var handleConfirm = function handleConfirm() {
70
+ var handleConfirm = useCallback(function () {
71
71
  var _onActions$onColumnSe;
72
72
  setColumnSettingVisible(false);
73
73
  onActions === null || onActions === void 0 || (_onActions$onColumnSe = onActions.onColumnSettingChanged) === null || _onActions$onColumnSe === void 0 || _onActions$onColumnSe.call(onActions, columnSetting.checkedList, columnSetting.sortedColumns);
74
- };
75
- var handleReset = function handleReset() {
74
+ }, [columnSetting.checkedList, columnSetting.sortedColumns]);
75
+ var handleReset = useCallback(function () {
76
76
  setColumnSetting({
77
77
  sortedColumns: columns,
78
78
  checkedList: checkedValues
79
79
  });
80
- };
81
- var onCheckAllChange = function onCheckAllChange(e) {
80
+ }, [columns, checkedValues]);
81
+ var onCheckAllChange = useCallback(function (e) {
82
82
  var checked = e.target.checked;
83
83
  if (checked) {
84
84
  // 全选所有列标题
@@ -100,7 +100,7 @@ function Toolbar(_ref) {
100
100
  });
101
101
  });
102
102
  }
103
- };
103
+ }, [columns]);
104
104
  useEffect(function () {
105
105
  return function () {
106
106
  if (timer.current) clearTimeout(timer.current);
@@ -1,5 +1,6 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { DItemProps } from './itemType';
3
3
  export type { DItemProps };
4
4
  declare function DItem(props: DItemProps): JSX.Element;
5
- export default DItem;
5
+ declare const _default: React.MemoExoticComponent<typeof DItem>;
6
+ export default _default;
@@ -1,6 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  var _excluded = ["formItemProps", "label", "name", "renderType", "render", "children"];
4
+ import React from 'react';
4
5
  import itemsRender from "./itemsRender";
5
6
  import { Fragment as _Fragment } from "react/jsx-runtime";
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -33,4 +34,4 @@ function DItem(props) {
33
34
  return /*#__PURE__*/_jsx(_Fragment, {});
34
35
  }
35
36
  }
36
- export default DItem;
37
+ export default /*#__PURE__*/React.memo(DItem);
@@ -1,4 +1,4 @@
1
- import { HTMLAttributes, ReactNode } from 'react';
1
+ import { ReactNode } from 'react';
2
2
  import { InputProps, InputNumberProps, AutoCompleteProps, CascaderProps, SelectProps, TreeSelectProps, DatePickerProps, TimePickerProps, MentionProps, CheckboxProps, RadioProps, RateProps, SliderSingleProps, SwitchProps, TransferProps, UploadProps, ButtonProps, DividerProps, FormItemProps, RadioGroupProps, ColProps } from 'antd';
3
3
  import { PasswordProps, TextAreaProps } from 'antd/lib/input';
4
4
  import { RangePickerProps } from 'antd/lib/date-picker';
@@ -10,21 +10,12 @@ import { DTreeSelectProps } from '../../DTreeSelect';
10
10
  import { DUploadProps } from '../../DUpload';
11
11
  import { IPAddressProps } from '../../IPAddress';
12
12
  import { DRangePickerProps } from '../../DRangePicker/interface';
13
- export type RenderType = 'custom' | 'dInput' | 'ipAddress' | 'input' | 'textArea' | 'password' | 'inputNumber' | 'autoComplete' | 'dSelect' | 'select' | 'dCascader' | 'cascader' | 'dTreeSelect' | 'treeSelect' | 'datePicker' | 'dRangePicker' | 'timePicker' | 'rangePicker' | 'mentions' | 'checkbox' | 'checkboxGroup' | 'radio' | 'radioGroup' | 'rate' | 'slider' | 'switch' | 'transfer' | 'upload' | 'dUpload' | 'button' | 'divider';
13
+ export type RenderType = 'custom' | 'other' | 'dInput' | 'ipAddress' | 'input' | 'textArea' | 'password' | 'inputNumber' | 'autoComplete' | 'dSelect' | 'select' | 'dCascader' | 'cascader' | 'dTreeSelect' | 'treeSelect' | 'datePicker' | 'dRangePicker' | 'timePicker' | 'rangePicker' | 'mentions' | 'checkbox' | 'checkboxGroup' | 'radio' | 'radioGroup' | 'rate' | 'slider' | 'switch' | 'transfer' | 'upload' | 'dUpload' | 'button' | 'divider';
14
14
  export type DItemBaseProps = Pick<FormItemProps, 'label' | 'name'> & {
15
15
  formItemProps?: FormItemProps & {
16
16
  grid?: Omit<ColProps, 'prefixCls'>;
17
17
  };
18
18
  };
19
- /** 自定义渲染的DItem */
20
- type CustomItemProps = DItemBaseProps & HTMLAttributes<HTMLElement> & {
21
- /** 渲染类型 */
22
- renderType?: 'custom' | 'other';
23
- /** 自定义渲染函数 */
24
- render?: (props: any, formItemProps: FormItemProps, allProps?: DItemProps) => ReactNode;
25
- children?: ReactNode;
26
- [key: string]: any;
27
- };
28
19
  export type DInputItemProps = {
29
20
  renderType?: 'dInput';
30
21
  } & DItemBaseProps & DInputProps;
@@ -115,5 +106,12 @@ export type ButtonItemProps = {
115
106
  export type DividerItemProps = {
116
107
  renderType?: 'divider';
117
108
  } & DItemBaseProps & DividerProps;
118
- export type DItemProps = CustomItemProps | DInputItemProps | DIpAddressProps | InputItemProps | TextAreaItemProps | PasswordItemProps | InputNumberItemProps | AutoCompleteItemProps | DSelectItemProps | SelectItemProps | DCascaderItemProps | CascaderItemProps | DTreeSelectItemProps | TreeSelectItemProps | DatePickerItemProps | TimePickerItemProps | RangePickerItemProps | DRangePickerItemProps | MentionItemProps | CheckboxItemProps | CheckboxGroupProps | DCheckboxGroupProps | RadioItemProps | RadioGroupProps | DRadioGorupProps | RateItemProps | SliderItemProps | SwitchItemProps | TransferItemProps | UploadItemProps | DUploadItemProps | ButtonItemProps | DividerItemProps;
119
- export {};
109
+ export type DItemProps = {
110
+ renderType?: RenderType;
111
+ formItemProps?: FormItemProps & {
112
+ grid?: Omit<ColProps, 'prefixCls'>;
113
+ };
114
+ children?: ReactNode;
115
+ render?: any;
116
+ [key: string]: any;
117
+ };
@@ -10,7 +10,7 @@ var _excluded = ["className", "defaultItemProps", "items", "children", "layout",
10
10
  * @Description : 基于antd的Form组件
11
11
  */
12
12
 
13
- import React, { forwardRef, useContext, useState, useEffect, useImperativeHandle } from 'react';
13
+ import React, { forwardRef, useContext, useState, useMemo, useEffect, useImperativeHandle } from 'react';
14
14
  import { Form, Row, Col } from 'antd';
15
15
  import { ConfigContext } from "../ConfigProvider";
16
16
  import helper from "./helper";
@@ -69,13 +69,16 @@ function InternalForm(props, ref) {
69
69
  getPrefixCls = _useContext.getPrefixCls;
70
70
  var _className = "".concat(getPrefixCls('form'), " ").concat(className, " ").concat(['inlineVertical', 'grid'].includes(layout) ? 'inlineVertical' : '');
71
71
  var _layout = ['inlineVertical', 'grid'].includes(layout) ? 'inline' : layout;
72
- var _useState = useState(getChildren(items, children, defaultItemProps, layout)),
72
+ var propsDerivedChildren = useMemo(function () {
73
+ return getChildren(items, children, defaultItemProps, layout);
74
+ }, [items, children, defaultItemProps, layout]);
75
+ var _useState = useState(propsDerivedChildren),
73
76
  _useState2 = _slicedToArray(_useState, 2),
74
77
  itemChildren = _useState2[0],
75
78
  setItemChildren = _useState2[1];
76
79
  useEffect(function () {
77
- setItemChildren(getChildren(items, children, defaultItemProps, layout));
78
- }, [items, children, defaultItemProps, layout]);
80
+ setItemChildren(propsDerivedChildren);
81
+ }, [propsDerivedChildren]);
79
82
  useImperativeHandle(ref, function () {
80
83
  return {
81
84
  setItems: function setItems(value) {
@@ -93,7 +96,7 @@ function InternalForm(props, ref) {
93
96
  }
94
97
  }
95
98
  };
96
- }, [items, children, defaultItemProps]);
99
+ }, [items, children, defaultItemProps, layout]);
97
100
  return /*#__PURE__*/_jsx(Form, _objectSpread(_objectSpread({}, otherProps), {}, {
98
101
  className: _className,
99
102
  layout: _layout,
@@ -9,7 +9,7 @@ var _excluded = ["className", "onChange", "onCompositionStart", "onCompositionEn
9
9
  * @LastEditTime : 2023-08-16 16:48:52
10
10
  * @Description : 基于antd的Input组件
11
11
  */
12
- import React, { useRef, forwardRef, useState, useEffect, useContext } from 'react';
12
+ import React, { useRef, forwardRef, useState, useEffect, useContext, useCallback } from 'react';
13
13
  import { Input } from 'antd';
14
14
  import { ConfigContext } from "../ConfigProvider";
15
15
 
@@ -53,7 +53,7 @@ function InternalInput(props, ref) {
53
53
 
54
54
  // debounce: 默认800ms,false或0表示不开启
55
55
  var _debounce = getDebounceTime(debounce);
56
- var emitChange = function emitChange(_value, e) {
56
+ var emitChange = useCallback(function (_value, e) {
57
57
  if (_debounce > 0) {
58
58
  clearTimeout(debounceRef.current);
59
59
  debounceRef.current = setTimeout(function () {
@@ -62,7 +62,7 @@ function InternalInput(props, ref) {
62
62
  } else {
63
63
  onChange === null || onChange === void 0 || onChange(_value, e);
64
64
  }
65
- };
65
+ }, [_debounce, onChange]);
66
66
 
67
67
  // 监听用户onChange事件(如果正在进行合成输入,则不响应用户事件)
68
68
  var _onChange = function _onChange(e) {
@@ -88,6 +88,14 @@ function InternalInput(props, ref) {
88
88
  useEffect(function () {
89
89
  return setValue(initValue);
90
90
  }, [initValue]);
91
+ useEffect(function () {
92
+ return function () {
93
+ if (debounceRef.current) {
94
+ clearTimeout(debounceRef.current);
95
+ debounceRef.current = null;
96
+ }
97
+ };
98
+ }, []);
91
99
  return /*#__PURE__*/_jsx(Input, _objectSpread(_objectSpread({}, otherProps), {}, {
92
100
  className: _className,
93
101
  ref: ref,
@@ -14,16 +14,16 @@ function DModal(props) {
14
14
  otherProps = _objectWithoutProperties(props, _excluded);
15
15
  var _useContext = useContext(ConfigContext),
16
16
  getPrefixCls = _useContext.getPrefixCls;
17
- var containerRef = useRef();
17
+ var containerRef = useRef(null);
18
18
  var style = useMemo(function () {
19
19
  var _otherProps$style;
20
20
  return _objectSpread({
21
- getContainer: containerRef.current,
21
+ getContainer: containerRef.current || document.body,
22
22
  width: ((_otherProps$style = otherProps.style) === null || _otherProps$style === void 0 ? void 0 : _otherProps$style.width) || '80%',
23
23
  centered: true,
24
24
  maskClosable: false
25
25
  }, otherProps);
26
- }, [otherProps]);
26
+ }, [otherProps.open, otherProps.title, otherProps.wrapClassName, otherProps.style, otherProps.centered, otherProps.width, otherProps.zIndex]);
27
27
  useEffect(function () {
28
28
  if (otherProps.open) {
29
29
  document.body.style.overflow = 'hidden';
@@ -35,17 +35,24 @@ function DModal(props) {
35
35
  };
36
36
  }, [otherProps.open]);
37
37
  useEffect(function () {
38
- if (containerRef.current) {
39
- if (mode === 'absolute') {
40
- containerRef.current.parentElement.style.position = '';
38
+ var _containerRef$current;
39
+ var parentElement = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.parentElement;
40
+ if (parentElement) {
41
+ if (mode === 'absolute' || mode === 'fixed' || mode === 'panel') {
42
+ parentElement.style.position = '';
41
43
  } else {
42
- containerRef.current.parentElement.style.position = 'relative';
44
+ parentElement.style.position = 'relative';
43
45
  }
44
46
  }
45
- }, [mode, containerRef.current]);
47
+ }, [mode]);
48
+ var getContainerClass = function getContainerClass() {
49
+ if (mode === 'fixed') return 'fixed-modal-container';
50
+ if (mode === 'absolute' || mode === 'panel') return 'absolute-modal-container';
51
+ return 'relative-modal-container';
52
+ };
46
53
  return /*#__PURE__*/_jsx("div", {
47
54
  ref: containerRef,
48
- className: "".concat(getPrefixCls('modal-container'), " ").concat(getPrefixCls(mode === 'absolute' || mode === 'panel' ? 'absolute-modal-container' : 'relative-modal-container')),
55
+ className: "".concat(getPrefixCls('modal-container'), " ").concat(getPrefixCls(getContainerClass())),
49
56
  children: /*#__PURE__*/_jsx(Modal, _objectSpread(_objectSpread({}, style), {}, {
50
57
  children: children
51
58
  }))
@@ -3,6 +3,6 @@ import type { ModalProps } from 'antd';
3
3
  type IModalProps = Omit<ModalProps, 'className'>;
4
4
  export interface DModalProps extends IModalProps {
5
5
  children?: ReactNode | undefined;
6
- mode?: 'absolute' | 'relative' | 'panel';
6
+ mode?: 'absolute' | 'relative' | 'panel' | 'fixed';
7
7
  }
8
8
  export {};
@@ -1,27 +1,33 @@
1
- @import '../../commonStyle/index.less';
2
-
3
- .@{prefix}-modal-container {
4
- .ant-modal-wrap {
5
- .ant-modal {
6
- max-width: unset;
7
- height: 100%;
8
-
9
- .ant-modal-content {
10
- width: 100%;
11
- height: 100%;
12
- }
13
- }
14
- }
15
- }
16
-
17
- .@{prefix}-absolute-modal-container {
18
- .ant-modal-wrap {
19
- position: fixed;
20
- }
21
- }
22
-
23
- .@{prefix}-relative-modal-container {
24
- .ant-modal-wrap {
25
- position: absolute;
26
- }
27
- }
1
+ @import '../../commonStyle/index.less';
2
+
3
+ .@{prefix}-modal-container {
4
+ .ant-modal-wrap {
5
+ .ant-modal {
6
+ max-width: unset;
7
+ height: 100%;
8
+
9
+ .ant-modal-content {
10
+ width: 100%;
11
+ height: 100%;
12
+ }
13
+ }
14
+ }
15
+ }
16
+
17
+ .@{prefix}-absolute-modal-container {
18
+ .ant-modal-wrap {
19
+ position: fixed;
20
+ }
21
+ }
22
+
23
+ .@{prefix}-fixed-modal-container {
24
+ .ant-modal-wrap {
25
+ position: fixed;
26
+ }
27
+ }
28
+
29
+ .@{prefix}-relative-modal-container {
30
+ .ant-modal-wrap {
31
+ position: absolute;
32
+ }
33
+ }
@@ -9,7 +9,7 @@ var _excluded = ["loadMore", "defaultColumnProps", "actionColumn", "showErrorMsg
9
9
  * @LastEditTime : 2023-08-16 16:45:15
10
10
  * @Description : 基于antd的Table组件
11
11
  */
12
- import React, { forwardRef, useEffect, useRef, useState, useContext, useMemo, useImperativeHandle } from 'react';
12
+ import React, { forwardRef, useEffect, useRef, useState, useContext, useMemo, useImperativeHandle, useCallback } from 'react';
13
13
  import { message, Table } from 'antd';
14
14
  import { ConfigContext } from "../ConfigProvider";
15
15
  import "./index.less";
@@ -131,19 +131,19 @@ function InternalTable(props, ref) {
131
131
  // pcf-table 样式中已经包含对_scroll的支持
132
132
  var _className = "".concat(getPrefixCls('table'), " ").concat(className || '', " ").concat(_pagination ? 'height-on-page' : '');
133
133
 
134
- // loading 默认延迟 600ms
134
+ // loading 默认延迟 300ms
135
135
  var _loading = useMemo(function () {
136
136
  return typeof loading === 'boolean' ? {
137
137
  spinning: loading,
138
- delay: 500
138
+ delay: 300
139
139
  } : _objectSpread({
140
- delay: 500,
140
+ delay: 300,
141
141
  spinning: false
142
142
  }, loading);
143
143
  }, [loading]);
144
144
 
145
145
  // 加载数据
146
- var loadData = function loadData(params) {
146
+ var loadData = useCallback(function (params) {
147
147
  if (typeof loadMore === 'function') {
148
148
  setTableSource(_objectSpread(_objectSpread({}, tableSource), {}, {
149
149
  loading: true
@@ -165,9 +165,11 @@ function InternalTable(props, ref) {
165
165
  });
166
166
  }
167
167
  }).catch(function (err) {
168
- setTableSource(_objectSpread(_objectSpread({}, tableSource), {}, {
169
- loading: false
170
- }));
168
+ setTableSource(function (prev) {
169
+ return _objectSpread(_objectSpread({}, prev), {}, {
170
+ loading: false
171
+ });
172
+ });
171
173
  if (showErrorMsg) {
172
174
  var _err$response;
173
175
  var errMsg = (err === null || err === void 0 || (_err$response = err.response) === null || _err$response === void 0 || (_err$response = _err$response.data) === null || _err$response === void 0 ? void 0 : _err$response.msg) || (err === null || err === void 0 ? void 0 : err.msg) || (err === null || err === void 0 ? void 0 : err.message);
@@ -185,16 +187,16 @@ function InternalTable(props, ref) {
185
187
  records: dataSource
186
188
  });
187
189
  }
188
- };
190
+ }, [loadMore, dataSource, _pagination]);
189
191
 
190
192
  // 手动刷新方法
191
- var refresh = function refresh(params) {
193
+ var refresh = useCallback(function (params) {
192
194
  var refreshParams = _objectSpread(_objectSpread({}, tableParams), params);
193
195
  loadData(refreshParams);
194
- };
196
+ }, [tableParams, loadData]);
195
197
 
196
198
  // 监听分页大小变化,如果外部也监听了onChange,则不会触发loadMore,但如果外部onChange返回值为undefined则正常触loadMore
197
- var onChange = function onChange(page, pageSize) {
199
+ var onChange = useCallback(function (page, pageSize) {
198
200
  if (_pagination && typeof (_pagination === null || _pagination === void 0 ? void 0 : _pagination.onChange) === 'function') {
199
201
  var data = _pagination.onChange(page, pageSize);
200
202
  if (data === undefined) loadData(_objectSpread(_objectSpread({}, tableParams), {}, {
@@ -207,7 +209,7 @@ function InternalTable(props, ref) {
207
209
  size: pageSize
208
210
  }));
209
211
  }
210
- };
212
+ }, [tableParams, loadData, _pagination]);
211
213
  var _tablePagination = _pagination ? _objectSpread(_objectSpread({}, _pagination), {}, {
212
214
  total: tableSource.total,
213
215
  current: tableParams.current,
@@ -57,6 +57,10 @@ interface ISLProps<T, P> {
57
57
  * @description 列表底部提示
58
58
  */
59
59
  endMessage?: React.ReactNode;
60
+ /**
61
+ * @description 列表项点击事件
62
+ */
63
+ onItemClick?: (item: P, index: number) => void;
60
64
  }
61
65
  export type InfiniteScrollListProps<T, P> = ISLProps<T, P>;
62
66
  declare const _default: React.MemoExoticComponent<(<T, P>(props: ISLProps<T, P>) => import("react/jsx-runtime").JSX.Element)>;
@@ -32,7 +32,8 @@ var InfiniteScrollList = function InfiniteScrollList(props) {
32
32
  _props$showBackTop = props.showBackTop,
33
33
  showBackTop = _props$showBackTop === void 0 ? true : _props$showBackTop,
34
34
  endMessage = props.endMessage,
35
- _renderItem = props.renderItem;
35
+ _renderItem = props.renderItem,
36
+ onItemClick = props.onItemClick;
36
37
  var _useContext = useContext(ConfigContext),
37
38
  prefixCls = _useContext.prefixCls,
38
39
  getPrefixCls = _useContext.getPrefixCls;
@@ -51,6 +52,7 @@ var InfiniteScrollList = function InfiniteScrollList(props) {
51
52
  _useState2 = _slicedToArray(_useState, 2),
52
53
  listData = _useState2[0],
53
54
  setListData = _useState2[1];
55
+ var listDataRef = useRef(listData);
54
56
  var handleLoadMore = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
55
57
  var _yield$loadMore, data, total, records;
56
58
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -104,12 +106,30 @@ var InfiniteScrollList = function InfiniteScrollList(props) {
104
106
  }
105
107
  }, _callee, null, [[3, 13, 17, 20]]);
106
108
  })), [loadMore]);
109
+ var handleItemClick = useCallback(function (e) {
110
+ var _itemElement$dataset, _listDataRef$current;
111
+ e.stopPropagation();
112
+ e.preventDefault();
113
+ var targetElement = e.target;
114
+ var itemElement = targetElement.closest('[data-key]');
115
+ var key = itemElement === null || itemElement === void 0 || (_itemElement$dataset = itemElement.dataset) === null || _itemElement$dataset === void 0 ? void 0 : _itemElement$dataset.key;
116
+ if (key && ((_listDataRef$current = listDataRef.current) === null || _listDataRef$current === void 0 || (_listDataRef$current = _listDataRef$current.data) === null || _listDataRef$current === void 0 ? void 0 : _listDataRef$current.length) > 0) {
117
+ var _listDataRef$current$;
118
+ var _index = listDataRef.current.data.findIndex(function (item, index) {
119
+ return item[itemKey] === key || index === Number(key);
120
+ });
121
+ if (_index >= 0 && _index < ((_listDataRef$current$ = listDataRef.current.data) === null || _listDataRef$current$ === void 0 ? void 0 : _listDataRef$current$.length)) {
122
+ onItemClick === null || onItemClick === void 0 || onItemClick(listDataRef.current.data[_index], _index);
123
+ }
124
+ }
125
+ }, [itemKey, onItemClick]);
107
126
  useEffect(function () {
108
127
  if (listData.total > 0 && listData.data.length < listData.total) {
109
128
  pageParamsRef.current = _objectSpread(_objectSpread({}, pageParamsRef.current), {}, {
110
129
  current: pageParamsRef.current.current + 1
111
130
  });
112
131
  }
132
+ listDataRef.current = listData;
113
133
  }, [listData]);
114
134
  useEffect(function () {
115
135
  var currentInitialParams = initialParams && _typeof(initialParams) === 'object' ? initialParams : {};
@@ -133,6 +153,7 @@ var InfiniteScrollList = function InfiniteScrollList(props) {
133
153
  style: {
134
154
  height: containerHeight
135
155
  },
156
+ onClick: handleItemClick,
136
157
  children: [/*#__PURE__*/_jsx(InfiniteScroll, {
137
158
  className: "".concat(wrapperClass, " ").concat(className),
138
159
  style: {
@@ -161,8 +182,9 @@ var InfiniteScrollList = function InfiniteScrollList(props) {
161
182
  dataSource: listData.data,
162
183
  renderItem: function renderItem(item, index) {
163
184
  return /*#__PURE__*/_jsx(List.Item, {
185
+ "data-key": item[itemKey] || index,
164
186
  children: _renderItem(item, index)
165
- }, item[itemKey]);
187
+ }, item[itemKey] || index);
166
188
  }
167
189
  })
168
190
  }), showBackTop && /*#__PURE__*/_jsx(BackTop, {