linkmore-design 1.1.8 → 1.1.9

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +1056 -9
  2. package/dist/Form/FormItem/index.d.ts +7 -1
  3. package/dist/Form/demos/ruleTime.d.ts +2 -0
  4. package/dist/LmUpload/UploadList/ItemPictureCard.d.ts +2 -1
  5. package/dist/LmUpload/components/Preview.d.ts +5 -0
  6. package/dist/LmUpload/wrapper/reducer.d.ts +4 -0
  7. package/dist/index.umd.js +245 -120
  8. package/dist/index.umd.min.js +8 -8
  9. package/es/Form/FormItem/index.d.ts +7 -1
  10. package/es/Form/FormItem/index.js +56 -13
  11. package/es/LmEditTable/EditTable.js +24 -21
  12. package/es/LmEditTable/util.js +4 -4
  13. package/es/LmTable/Table.js +8 -6
  14. package/es/LmTable/util.js +9 -5
  15. package/es/LmUpload/LmUpload.js +1 -0
  16. package/es/LmUpload/UploadList/ItemPictureCard.d.ts +2 -1
  17. package/es/LmUpload/UploadList/ItemPictureCard.js +16 -4
  18. package/es/LmUpload/UploadList/index.js +11 -7
  19. package/es/LmUpload/components/Preview.d.ts +5 -0
  20. package/es/LmUpload/components/Preview.js +43 -0
  21. package/es/LmUpload/wrapper/UploadWrapper.js +3 -0
  22. package/es/LmUpload/wrapper/reducer.d.ts +4 -0
  23. package/es/LmUpload/wrapper/reducer.js +12 -3
  24. package/lib/Form/FormItem/index.d.ts +7 -1
  25. package/lib/Form/FormItem/index.js +58 -14
  26. package/lib/LmEditTable/EditTable.js +24 -21
  27. package/lib/LmEditTable/util.js +4 -4
  28. package/lib/LmTable/Table.js +8 -6
  29. package/lib/LmTable/util.js +9 -5
  30. package/lib/LmUpload/LmUpload.js +1 -0
  31. package/lib/LmUpload/UploadList/ItemPictureCard.d.ts +2 -1
  32. package/lib/LmUpload/UploadList/ItemPictureCard.js +16 -4
  33. package/lib/LmUpload/UploadList/index.js +13 -7
  34. package/lib/LmUpload/components/Preview.d.ts +5 -0
  35. package/lib/LmUpload/components/Preview.js +55 -0
  36. package/lib/LmUpload/wrapper/UploadWrapper.js +4 -0
  37. package/lib/LmUpload/wrapper/reducer.d.ts +4 -0
  38. package/lib/LmUpload/wrapper/reducer.js +12 -3
  39. package/package.json +15 -3
@@ -1,5 +1,6 @@
1
1
  import type { FormInstance } from 'rc-field-form';
2
2
  import type { FieldProps } from 'rc-field-form/lib/Field';
3
+ import type { Rule } from 'rc-field-form/lib/interface';
3
4
  import * as React from 'react';
4
5
  import useFormItemStatus from '../hooks/useFormItemStatus';
5
6
  import type { FormItemInputProps } from '../FormItemInput';
@@ -9,7 +10,10 @@ export declare type ValidateStatus = typeof ValidateStatuses[number];
9
10
  declare type RenderChildren<Values = any> = (form: FormInstance<Values>) => React.ReactNode;
10
11
  declare type RcFieldProps<Values = any> = Omit<FieldProps<Values>, 'children'>;
11
12
  declare type ChildrenType<Values = any> = RenderChildren<Values> | React.ReactNode;
12
- export interface FormItemProps<Values = any> extends FormItemLabelProps, FormItemInputProps, RcFieldProps<Values> {
13
+ export declare type LmRule = Rule & {
14
+ time?: number;
15
+ };
16
+ export interface FormItemProps<Values = any> extends FormItemLabelProps, FormItemInputProps, Omit<RcFieldProps<Values>, 'rules'> {
13
17
  prefixCls?: string;
14
18
  noStyle?: boolean;
15
19
  style?: React.CSSProperties;
@@ -25,6 +29,8 @@ export interface FormItemProps<Values = any> extends FormItemLabelProps, FormIte
25
29
  tooltip?: LabelTooltipType;
26
30
  /** @deprecated No need anymore */
27
31
  fieldKey?: React.Key | React.Key[];
32
+ /** 变更 */
33
+ rules?: LmRule[];
28
34
  errorPlacement?: string;
29
35
  responsive?: boolean;
30
36
  }
@@ -1,11 +1,12 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
4
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
5
  import { Field, FieldContext, ListContext } from 'rc-field-form';
5
6
  import useState from 'rc-util/lib/hooks/useState';
6
7
  import { supportRef } from 'rc-util/lib/ref';
7
8
  import * as React from 'react';
8
- import { useContext } from 'react';
9
+ import { useContext, useEffect, useRef } from 'react';
9
10
  import useFormItemStatus from '../hooks/useFormItemStatus';
10
11
  import { ConfigContext } from '../../ConfigProvider';
11
12
  import { cloneElement, isValidElement } from '../../_util/reactNode';
@@ -43,6 +44,31 @@ function genEmptyMeta() {
43
44
  };
44
45
  }
45
46
 
47
+ function getRuleTime(rules) {
48
+ if (!rules) {
49
+ return 0;
50
+ }
51
+
52
+ var _iterator = _createForOfIteratorHelper(rules),
53
+ _step;
54
+
55
+ try {
56
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
+ var rule = _step.value;
58
+
59
+ if (rule && _typeof(rule) === 'object' && rule.time) {
60
+ return rule.time;
61
+ }
62
+ }
63
+ } catch (err) {
64
+ _iterator.e(err);
65
+ } finally {
66
+ _iterator.f();
67
+ }
68
+
69
+ return 0;
70
+ }
71
+
46
72
  function InternalFormItem(props) {
47
73
  var name = props.name,
48
74
  noStyle = props.noStyle,
@@ -58,6 +84,17 @@ function InternalFormItem(props) {
58
84
  trigger = _props$trigger === void 0 ? 'onChange' : _props$trigger,
59
85
  validateTrigger = props.validateTrigger,
60
86
  hidden = props.hidden;
87
+ var timerRef = useRef(null);
88
+
89
+ var _useState = useState([]),
90
+ _useState2 = _slicedToArray(_useState, 2),
91
+ mergedErrors = _useState2[0],
92
+ setMergedErrors = _useState2[1];
93
+
94
+ var _useState3 = useState([]),
95
+ _useState4 = _slicedToArray(_useState3, 2),
96
+ mergedWarnings = _useState4[0],
97
+ setMergedWarnings = _useState4[1];
61
98
 
62
99
  var _useContext = useContext(ConfigContext),
63
100
  getPrefixCls = _useContext.getPrefixCls;
@@ -86,12 +123,12 @@ function InternalFormItem(props) {
86
123
  setSubFieldErrors = _useFrameState2[1]; // >>>>> Current field errors
87
124
 
88
125
 
89
- var _useState = useState(function () {
126
+ var _useState5 = useState(function () {
90
127
  return genEmptyMeta();
91
128
  }),
92
- _useState2 = _slicedToArray(_useState, 2),
93
- meta = _useState2[0],
94
- setMeta = _useState2[1];
129
+ _useState6 = _slicedToArray(_useState5, 2),
130
+ meta = _useState6[0],
131
+ setMeta = _useState6[1];
95
132
 
96
133
  var onMetaChange = function onMetaChange(nextMeta) {
97
134
  // This keyInfo is not correct when field is removed
@@ -144,7 +181,7 @@ function InternalFormItem(props) {
144
181
  }; // >>>>> Get merged errors
145
182
 
146
183
 
147
- var _React$useMemo = React.useMemo(function () {
184
+ useEffect(function () {
148
185
  var errorList = _toConsumableArray(meta.errors);
149
186
 
150
187
  var warningList = _toConsumableArray(meta.warnings);
@@ -153,12 +190,18 @@ function InternalFormItem(props) {
153
190
  errorList.push.apply(errorList, _toConsumableArray(subFieldError.errors || []));
154
191
  warningList.push.apply(warningList, _toConsumableArray(subFieldError.warnings || []));
155
192
  });
156
- return [errorList, warningList];
157
- }, [subFieldErrors, meta.errors, meta.warnings]),
158
- _React$useMemo2 = _slicedToArray(_React$useMemo, 2),
159
- mergedErrors = _React$useMemo2[0],
160
- mergedWarnings = _React$useMemo2[1]; // ===================== Children Ref =====================
161
-
193
+ setMergedErrors(errorList);
194
+ setMergedWarnings(warningList);
195
+ var time = getRuleTime(rules);
196
+
197
+ if (time) {
198
+ clearTimeout(timerRef.current);
199
+ timerRef.current = setTimeout(function () {
200
+ setMergedErrors([]);
201
+ setMergedWarnings([]);
202
+ }, time);
203
+ }
204
+ }, [subFieldErrors, meta.errors, meta.warnings]); // ===================== Children Ref =====================
162
205
 
163
206
  var getItemRef = useItemRef(); // ======================== Render ========================
164
207
 
@@ -735,13 +735,15 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
735
735
  };
736
736
 
737
737
  var onColSortEnd = function onColSortEnd(active, over) {
738
+ var _a;
739
+
738
740
  var oldIndex = columns.findIndex(function (item) {
739
741
  return item.dataIndex === active;
740
742
  });
741
743
  var newIndex = columns.findIndex(function (item) {
742
744
  return item.dataIndex === over;
743
745
  });
744
- filterChange === null || filterChange === void 0 ? void 0 : filterChange(arrayMove(columns, oldIndex, newIndex).map(function (item, index) {
746
+ filterChange === null || filterChange === void 0 ? void 0 : filterChange((_a = arrayMove(columns, oldIndex, newIndex)) === null || _a === void 0 ? void 0 : _a.map(function (item, index) {
745
747
  return Object.assign(Object.assign({}, item), {
746
748
  order: index
747
749
  });
@@ -775,7 +777,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
775
777
  dataSourceRef.current = dataSource;
776
778
 
777
779
  if (sortOpen) {
778
- var dataSourceKeys = dataSource.map(function (item) {
780
+ var dataSourceKeys = dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item) {
779
781
  return item[_rowKey];
780
782
  }).join(',');
781
783
  var setCallBackFalgKeys = ((_a = sortDataSorceRef.current) === null || _a === void 0 ? void 0 : _a.map(function (item) {
@@ -819,12 +821,12 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
819
821
 
820
822
  if ((preKeys === null || preKeys === void 0 ? void 0 : preKeys.length) > 1) {
821
823
  var deeps = function deeps(children) {
822
- children.forEach(function (item) {
824
+ children === null || children === void 0 ? void 0 : children.forEach(function (item) {
823
825
  var _a;
824
826
 
825
827
  if (preKeys.includes(item[_rowKey])) {
826
828
  if (item[_rowKey] === row[_rowKey]) {
827
- children.forEach(function (c) {
829
+ children === null || children === void 0 ? void 0 : children.forEach(function (c) {
828
830
  c[key] = value;
829
831
  });
830
832
  (_a = Object.keys(item)) === null || _a === void 0 ? void 0 : _a.forEach(function (v) {
@@ -839,7 +841,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
839
841
 
840
842
  deeps(draft);
841
843
  } else {
842
- draft.forEach(function (item, index) {
844
+ draft === null || draft === void 0 ? void 0 : draft.forEach(function (item, index) {
843
845
  if (row[_rowKey] === item[_rowKey]) {
844
846
  draft[index] = row;
845
847
  } else {
@@ -850,7 +852,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
850
852
  } else {
851
853
  if ((preKeys === null || preKeys === void 0 ? void 0 : preKeys.length) > 1) {
852
854
  var _deeps = function _deeps(children) {
853
- children.forEach(function (item) {
855
+ children === null || children === void 0 ? void 0 : children.forEach(function (item) {
854
856
  var _a;
855
857
 
856
858
  if (preKeys.includes(item[_rowKey])) {
@@ -887,7 +889,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
887
889
 
888
890
  var reWriteOriginSource = function reWriteOriginSource(rowKey, rowValue, dataIndex, nextValue) {
889
891
  setDataSource(function (prevDataSource) {
890
- return prevDataSource.map(function (item) {
892
+ return prevDataSource === null || prevDataSource === void 0 ? void 0 : prevDataSource.map(function (item) {
891
893
  if (get(item, rowKey) === rowValue) {
892
894
  set(item, dataIndex, nextValue);
893
895
  }
@@ -906,10 +908,10 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
906
908
  if (preKeys.length > 1) {
907
909
  /** 说明删除的是children中的数据 */
908
910
  var filter = function filter(data, key) {
909
- var newData = data.filter(function (x) {
911
+ var newData = data === null || data === void 0 ? void 0 : data.filter(function (x) {
910
912
  return x[_rowKey] !== key;
911
913
  });
912
- newData.forEach(function (x) {
914
+ newData === null || newData === void 0 ? void 0 : newData.forEach(function (x) {
913
915
  if (x.children) {
914
916
  var c = filter(x.children, key);
915
917
  x.children = c;
@@ -957,13 +959,12 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
957
959
  var handleTableRowAdd = function handleTableRowAdd(record) {
958
960
  var _a, _b;
959
961
 
960
- console.log(record, '-rrrrr');
961
962
  var preKeys = (_b = (_a = deepDataSourceRef === null || deepDataSourceRef === void 0 ? void 0 : deepDataSourceRef.current) === null || _a === void 0 ? void 0 : _a[record[_rowKey]]) === null || _b === void 0 ? void 0 : _b.preKeys;
962
963
  var res = produce(dataSourceRef.current, function (draft) {
963
964
  if (preKeys.length > 1) {
964
965
  var deeps = function deeps(children) {
965
- children.forEach(function (item, index) {
966
- if (preKeys.includes(item[_rowKey])) {
966
+ children === null || children === void 0 ? void 0 : children.forEach(function (item, index) {
967
+ if (preKeys === null || preKeys === void 0 ? void 0 : preKeys.includes(item[_rowKey])) {
967
968
  if (item[_rowKey] === record[_rowKey]) {
968
969
  children.splice(index + 1, 0, _defineProperty({}, _rowKey, "".concat(Date.now())));
969
970
  } else if (item.children) {
@@ -994,7 +995,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
994
995
 
995
996
  var handleCopy = function handleCopy(key, value) {
996
997
  var res = produce(dataSourceRef.current, function (draft) {
997
- draft.forEach(function (item) {
998
+ draft === null || draft === void 0 ? void 0 : draft.forEach(function (item) {
998
999
  return item[key] = value;
999
1000
  });
1000
1001
  });
@@ -1016,7 +1017,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1016
1017
  });
1017
1018
 
1018
1019
  if (hasOnlyOptionsDatas.length) {
1019
- return hasOnlyOptionsDatas.map(function (item) {
1020
+ return hasOnlyOptionsDatas === null || hasOnlyOptionsDatas === void 0 ? void 0 : hasOnlyOptionsDatas.map(function (item) {
1020
1021
  return item.dataIndex;
1021
1022
  });
1022
1023
  }
@@ -1033,10 +1034,10 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1033
1034
 
1034
1035
  if (optionOnly && options) {
1035
1036
  var dataIndex = item.dataIndex;
1036
- var dataIndexData = dataSource.map(function (d) {
1037
+ var dataIndexData = dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (d) {
1037
1038
  return d[dataIndex];
1038
1039
  });
1039
- var newOptions = options.map(function (o) {
1040
+ var newOptions = options === null || options === void 0 ? void 0 : options.map(function (o) {
1040
1041
  return Object.assign(Object.assign({}, o), {
1041
1042
  disabled: !!dataIndexData.includes(o === null || o === void 0 ? void 0 : o.value)
1042
1043
  });
@@ -1092,7 +1093,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1092
1093
  var leftColumns = [];
1093
1094
  var mainColumns = [];
1094
1095
  var rightColumns = [];
1095
- localColumns.forEach(function (item) {
1096
+ localColumns === null || localColumns === void 0 ? void 0 : localColumns.forEach(function (item) {
1096
1097
  if ((item === null || item === void 0 ? void 0 : item.fixed) === 'left') {
1097
1098
  leftColumns.push(item);
1098
1099
  } else if ((item === null || item === void 0 ? void 0 : item.fixed) === 'right') {
@@ -1105,7 +1106,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1105
1106
  /** 为了支持colums中的分组之后,进行递归处理 */
1106
1107
 
1107
1108
  var mapColumns = function mapColumns(col, index) {
1108
- var _a;
1109
+ var _a, _b;
1109
1110
 
1110
1111
  if (!col.editable && !((_a = col.children) === null || _a === void 0 ? void 0 : _a.length)) {
1111
1112
  return col;
@@ -1154,7 +1155,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1154
1155
  });
1155
1156
 
1156
1157
  if (col === null || col === void 0 ? void 0 : col.children) {
1157
- newCol.children = col.children.map(mapColumns);
1158
+ newCol.children = (_b = col.children) === null || _b === void 0 ? void 0 : _b.map(mapColumns);
1158
1159
  }
1159
1160
 
1160
1161
  return newCol;
@@ -1179,9 +1180,11 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1179
1180
  }, /*#__PURE__*/React.createElement("tbody", Object.assign({}, props))));
1180
1181
  }, [sortEditTable]);
1181
1182
  var colDraggableContainer = useCallback(function (_a) {
1183
+ var _b;
1184
+
1182
1185
  var props = __rest(_a, []);
1183
1186
 
1184
- return /*#__PURE__*/React.createElement("tr", null, React.Children.map(props.children, function (child) {
1187
+ return /*#__PURE__*/React.createElement("tr", null, (_b = React.Children) === null || _b === void 0 ? void 0 : _b.map(props.children, function (child) {
1185
1188
  var _a, _b;
1186
1189
 
1187
1190
  if ((_b = (_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.column) === null || _b === void 0 ? void 0 : _b.fixed) {
@@ -1322,7 +1325,7 @@ var EditTable = /*#__PURE__*/forwardRef(function (props, ref) {
1322
1325
  fixed: true,
1323
1326
  type: 'checkbox',
1324
1327
  columnWidth: 36,
1325
- selectedRowKeys: localRowSelectList.map(function (v) {
1328
+ selectedRowKeys: localRowSelectList === null || localRowSelectList === void 0 ? void 0 : localRowSelectList.map(function (v) {
1326
1329
  return v[_rowKey];
1327
1330
  }),
1328
1331
  onChange: function onChange(selectedRowKeys, selectedRows) {
@@ -9,13 +9,13 @@ export function deepDataSourcePreKeys(dataSource, rowKey) {
9
9
  var deepDataSource = [];
10
10
 
11
11
  var eachChildren = function eachChildren(children, preKeys) {
12
- children.forEach(function (item) {
12
+ children === null || children === void 0 ? void 0 : children.forEach(function (item) {
13
13
  deepDataSource.push(Object.assign(Object.assign({}, item), {
14
- preKeys: [].concat(_toConsumableArray(preKeys), [item[rowKey]])
14
+ preKeys: [].concat(_toConsumableArray(preKeys), [item === null || item === void 0 ? void 0 : item[rowKey]])
15
15
  }));
16
16
 
17
- if (item.children) {
18
- eachChildren(item.children, [].concat(_toConsumableArray(preKeys), [item[rowKey]])); // deepDataSource.push({ ...item, preKeys: [...preKeys, item[rowKey]] })
17
+ if (item === null || item === void 0 ? void 0 : item.children) {
18
+ eachChildren(item === null || item === void 0 ? void 0 : item.children, [].concat(_toConsumableArray(preKeys), [item === null || item === void 0 ? void 0 : item[rowKey]])); // deepDataSource.push({ ...item, preKeys: [...preKeys, item[rowKey]] })
19
19
  }
20
20
  });
21
21
  };
@@ -310,7 +310,7 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
310
310
  var source = [];
311
311
 
312
312
  var deepChildren = function deepChildren(arr) {
313
- arr.forEach(function (item) {
313
+ arr === null || arr === void 0 ? void 0 : arr.forEach(function (item) {
314
314
  source.push((0, _lodash.omit)(item, 'children')); // 展开
315
315
 
316
316
  if ((item === null || item === void 0 ? void 0 : item.children) && expandedRowKeys.includes(item.key)) {
@@ -327,7 +327,7 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
327
327
  var source = [];
328
328
 
329
329
  var deepChildren = function deepChildren(arr) {
330
- arr.forEach(function (item) {
330
+ arr === null || arr === void 0 ? void 0 : arr.forEach(function (item) {
331
331
  if (item.children && item.children.length) {
332
332
  deepChildren(item.children);
333
333
  } else {
@@ -758,6 +758,8 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
758
758
  var _shellStatusRef$curre11;
759
759
 
760
760
  if (isEmpty((_shellStatusRef$curre11 = shellStatusRef.current) === null || _shellStatusRef$curre11 === void 0 ? void 0 : _shellStatusRef$curre11.editing)) {
761
+ var _pasteData;
762
+
761
763
  var _shellStatusRef$curre12 = shellStatusRef.current,
762
764
  start = _shellStatusRef$curre12.start,
763
765
  end = _shellStatusRef$curre12.end;
@@ -781,8 +783,8 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
781
783
 
782
784
 
783
785
  var resultEnd = [];
784
- pasteData.forEach(function (row, i) {
785
- row.forEach(function (value, j) {
786
+ (_pasteData = pasteData) === null || _pasteData === void 0 ? void 0 : _pasteData.forEach(function (row, i) {
787
+ row === null || row === void 0 ? void 0 : row.forEach(function (value, j) {
786
788
  resultEnd.push({
787
789
  i: start.i + i,
788
790
  j: start.j + j,
@@ -791,7 +793,7 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
791
793
  });
792
794
  });
793
795
  var res = (0, _immer.produce)(dataSourceRef.current, function (draft) {
794
- resultEnd.forEach(function (item) {
796
+ resultEnd === null || resultEnd === void 0 ? void 0 : resultEnd.forEach(function (item) {
795
797
  var _isSelected2;
796
798
 
797
799
  if ((_isSelected2 = isSelected(item.i, item.j)) === null || _isSelected2 === void 0 ? void 0 : _isSelected2.isSelected) {
@@ -994,7 +996,7 @@ var ResetTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
994
996
  var colIndex = 0;
995
997
 
996
998
  var traverseColumns = function traverseColumns(columns) {
997
- columns.forEach(function (col) {
999
+ columns === null || columns === void 0 ? void 0 : columns.forEach(function (col) {
998
1000
  if (col.show === false) {
999
1001
  return;
1000
1002
  }
@@ -50,10 +50,12 @@ exports.range = range;
50
50
 
51
51
  function dataGroup(data, key) {
52
52
  var result = {};
53
- data.forEach(function (item) {
53
+ data === null || data === void 0 ? void 0 : data.forEach(function (item) {
54
54
  if (item.children) {
55
+ var _Object$keys;
56
+
55
57
  var temp = dataGroup(item.children, key);
56
- Object.keys(temp).forEach(function (k) {
58
+ (_Object$keys = Object.keys(temp)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.forEach(function (k) {
57
59
  if (!result[k]) result[k] = [];
58
60
  result[k] = result[k].concat(temp[k]);
59
61
  });
@@ -100,7 +102,7 @@ function transformWithColGroup(columns, dataSource, groupColKeys) {
100
102
  // 表头数据的生成,生成新的 dataIndex 值
101
103
  // dataIndex最后的i:筛选的值相同需要加索引
102
104
  var handledColumns = [];
103
- source.forEach(function (souItem, i) {
105
+ source === null || source === void 0 ? void 0 : source.forEach(function (souItem, i) {
104
106
  handledColumns = handledColumns.concat(columns.filter(function (c) {
105
107
  // 过滤掉(表头操作) 使用列分组作为key的项
106
108
  return groupColKeysCopy.indexOf(c.dataIndex) === -1;
@@ -143,9 +145,11 @@ function transformWithColGroup(columns, dataSource, groupColKeys) {
143
145
 
144
146
  return [].concat((0, _toConsumableArray2.default)(prev), [sItem]);
145
147
  } else {
148
+ var _Object$keys2;
149
+
146
150
  var str = ''; // 根据筛选条件生成对应的前缀key值,比如[name, age] => 'name_xiaoming_age_18'
147
151
 
148
- groupColKeysCopy.forEach(function (dataIndex, i) {
152
+ groupColKeysCopy === null || groupColKeysCopy === void 0 ? void 0 : groupColKeysCopy.forEach(function (dataIndex, i) {
149
153
  if (i !== 0) {
150
154
  str += '_';
151
155
  }
@@ -153,7 +157,7 @@ function transformWithColGroup(columns, dataSource, groupColKeys) {
153
157
  str += "".concat(dataIndex, "_").concat(sItem[dataIndex]);
154
158
  }); // 对dataSource的key值进行更改:例如:'name' => 'name_xiaoming_age_18_address'
155
159
 
156
- Object.keys(sItem).forEach(function (key) {
160
+ (_Object$keys2 = Object.keys(sItem)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2.forEach(function (key) {
157
161
  if (key === '__index') {
158
162
  return;
159
163
  }
@@ -86,6 +86,7 @@ var LmUpload = function LmUpload(_a, ref) {
86
86
  maxCount: null,
87
87
  children: null,
88
88
  itemRender: null,
89
+ enabledPreview: true,
89
90
  enabledCrop: false,
90
91
  enabledOss: false,
91
92
  // oss配置
@@ -1,5 +1,6 @@
1
- declare const PictureItem: ({ file, instance }: {
1
+ declare const PictureItem: ({ file, index, instance }: {
2
2
  file: any;
3
+ index: any;
3
4
  instance: any;
4
5
  }) => JSX.Element;
5
6
  export default PictureItem;
@@ -63,8 +63,10 @@ var renderThumb = function renderThumb(file) {
63
63
 
64
64
  var PictureItem = function PictureItem(_ref) {
65
65
  var file = _ref.file,
66
+ index = _ref.index,
66
67
  instance = _ref.instance;
67
- var readOnly = instance.readOnly,
68
+ var dispatch = instance.dispatch,
69
+ readOnly = instance.readOnly,
68
70
  size = instance.size,
69
71
  remove = instance.remove,
70
72
  preview = instance.preview,
@@ -107,6 +109,18 @@ var PictureItem = function PictureItem(_ref) {
107
109
  fontSize: fontSize
108
110
  };
109
111
  }, [size]);
112
+
113
+ var handlePreview = function handlePreview() {
114
+ preview === null || preview === void 0 ? void 0 : preview(file);
115
+ dispatch({
116
+ type: 'changePreview',
117
+ preview: {
118
+ visible: true,
119
+ index: index
120
+ }
121
+ });
122
+ };
123
+
110
124
  return /*#__PURE__*/React.createElement("div", {
111
125
  className: cn('lm_upload_item', 'lm_upload_item_card', isError && 'lm_upload_item_error'),
112
126
  style: {
@@ -128,9 +142,7 @@ var PictureItem = function PictureItem(_ref) {
128
142
  className: "lm_upload_item_action"
129
143
  }, /*#__PURE__*/React.createElement("div", {
130
144
  className: "action_preview",
131
- onClick: function onClick() {
132
- return preview(file);
133
- }
145
+ onClick: handlePreview
134
146
  }, /*#__PURE__*/React.createElement(IconFont, {
135
147
  type: "lmweb-eye",
136
148
  style: {
@@ -1,25 +1,29 @@
1
- import React from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import { render } from '../utils';
3
3
  import RenderItem from './RenderItem';
4
4
 
5
5
  var LmUploadList = function LmUploadList(_ref) {
6
6
  var instance = _ref.instance;
7
-
8
- var _a, _b;
9
-
10
7
  var getFileHasValue = instance.getFileHasValue,
11
8
  getFileList = instance.getFileList,
12
9
  itemRender = instance.itemRender,
13
10
  listType = instance.listType,
14
11
  showUploadList = instance.showUploadList;
15
12
  if (!showUploadList) return null;
16
- return /*#__PURE__*/React.createElement(React.Fragment, null, (_b = (_a = getFileList()) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) {
17
- return a.seq - b.seq;
18
- })) === null || _b === void 0 ? void 0 : _b.map(function (file, idx) {
13
+ var fileList = useMemo(function () {
14
+ var _a;
15
+
16
+ return (_a = getFileList()) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) {
17
+ return a.seq - b.seq;
18
+ });
19
+ }, [getFileList]);
20
+ return /*#__PURE__*/React.createElement(React.Fragment, null, fileList === null || fileList === void 0 ? void 0 : fileList.map(function (file, idx) {
19
21
  return render(itemRender || RenderItem, {
20
22
  type: listType,
21
23
  key: getFileHasValue(file) || idx,
24
+ index: idx,
22
25
  file: file,
26
+ fileList: fileList,
23
27
  instance: instance
24
28
  });
25
29
  }));
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ declare const _default: React.MemoExoticComponent<({ instance }: {
3
+ instance: any;
4
+ }) => JSX.Element>;
5
+ export default _default;
@@ -0,0 +1,43 @@
1
+ import React, { useMemo } from 'react';
2
+ import { ImageViewer } from 'linkmore-design';
3
+
4
+ var Preview = function Preview(_ref) {
5
+ var instance = _ref.instance;
6
+ var enabledPreview = instance.enabledPreview,
7
+ state = instance.state,
8
+ dispatch = instance.dispatch,
9
+ getFileList = instance.getFileList;
10
+ if (!enabledPreview) return null; // 与展示顺序保持一致
11
+
12
+ var fileList = useMemo(function () {
13
+ var _a;
14
+
15
+ return (_a = getFileList()) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) {
16
+ return a.seq - b.seq;
17
+ });
18
+ }, [getFileList]);
19
+ var config = useMemo(function () {
20
+ var _state$preview = state.preview,
21
+ index = _state$preview.index,
22
+ visible = _state$preview.visible;
23
+ return {
24
+ urlList: fileList === null || fileList === void 0 ? void 0 : fileList.map(function (_ref2) {
25
+ var url = _ref2.url;
26
+ return url;
27
+ }),
28
+ initialIndex: index,
29
+ visible: visible,
30
+ close: function close() {
31
+ dispatch({
32
+ type: 'changePreview',
33
+ preview: {
34
+ visible: false
35
+ }
36
+ });
37
+ }
38
+ };
39
+ }, [fileList, state.preview]);
40
+ return /*#__PURE__*/React.createElement(ImageViewer, Object.assign({}, config));
41
+ };
42
+
43
+ export default /*#__PURE__*/React.memo(Preview);
@@ -3,6 +3,7 @@ import React from 'react';
3
3
  import LmUploadContainer from './UploadContainer';
4
4
  import LmUploadView from '../view';
5
5
  import Crop from '../components/Crop';
6
+ import Preview from '../components/Preview';
6
7
 
7
8
  var LmUploadWrapper = function LmUploadWrapper(_ref) {
8
9
  var instance = _ref.instance;
@@ -14,6 +15,8 @@ var LmUploadWrapper = function LmUploadWrapper(_ref) {
14
15
  instance: instance
15
16
  }), /*#__PURE__*/React.createElement(Crop, {
16
17
  instance: instance
18
+ }), /*#__PURE__*/React.createElement(Preview, {
19
+ instance: instance
17
20
  }));
18
21
  };
19
22
 
@@ -5,5 +5,9 @@ export declare const initialState: (props: any) => {
5
5
  status: string;
6
6
  fileList: any;
7
7
  cropFile: any;
8
+ preview: {
9
+ index: number;
10
+ visible: boolean;
11
+ };
8
12
  };
9
13
  export default reducer;
@@ -2,7 +2,8 @@
2
2
  export var reducer = function reducer(state, action) {
3
3
  var fileList = action.fileList,
4
4
  percent = action.percent,
5
- cropFile = action.cropFile;
5
+ cropFile = action.cropFile,
6
+ preview = action.preview;
6
7
 
7
8
  switch (action.type) {
8
9
  case 'changeFileList':
@@ -20,6 +21,11 @@ export var reducer = function reducer(state, action) {
20
21
  cropFile: cropFile
21
22
  });
22
23
 
24
+ case 'changePreview':
25
+ return Object.assign(Object.assign({}, state), {
26
+ preview: Object.assign(Object.assign({}, state.preview), preview)
27
+ });
28
+
23
29
  default:
24
30
  throw new Error();
25
31
  }
@@ -33,8 +39,11 @@ export var initialState = function initialState(props) {
33
39
  process: 0,
34
40
  status: 'done',
35
41
  fileList: defaultFileList,
36
- cropFile: null // 需要裁剪的图片
37
-
42
+ cropFile: null,
43
+ preview: {
44
+ index: 0,
45
+ visible: false
46
+ }
38
47
  };
39
48
  };
40
49
  export default reducer;