@ecoding/components.antd 0.4.32 → 0.5.1

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.
@@ -22,12 +22,13 @@ interface IProps {
22
22
  data?: any;
23
23
  gif?: boolean;
24
24
  disabled?: boolean;
25
+ objectInValue?: boolean;
25
26
  type?: string;
26
27
  name?: string;
27
28
  action: string | (() => string);
28
29
  buttonText?: string;
29
30
  maxCount?: number;
30
- onChange?: (infos: string[]) => void;
31
+ onChange?: (infos: any[] | undefined) => void;
31
32
  }
32
33
  /**
33
34
  * @returns 返回地址的string
@@ -15,14 +15,14 @@ import { DndContext, PointerSensor, useSensor } from '@dnd-kit/core';
15
15
  import { arrayMove, SortableContext, useSortable, rectSortingStrategy, } from '@dnd-kit/sortable';
16
16
  import { CSS } from '@dnd-kit/utilities';
17
17
  import Toast from "../../core/toast";
18
- const DraggableUploadListItem = ({ originNode, file }) => {
18
+ const DraggableUploadListItem = ({ originNode, file, disabled }) => {
19
19
  const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
20
20
  id: file.uid,
21
21
  });
22
22
  const style = {
23
23
  transform: CSS.Translate.toString(transform),
24
24
  transition,
25
- cursor: 'move',
25
+ cursor: disabled ? 'not-allowed' : 'move',
26
26
  height: '102px',
27
27
  width: '102px',
28
28
  };
@@ -35,33 +35,53 @@ const DraggableUploadListItem = ({ originNode, file }) => {
35
35
  */
36
36
  const MultipleImgUpload = (props) => {
37
37
  var _a, _b, _c, _d;
38
- const { i18n, name, buttonText, maxCount, disabled, value, onChange } = props;
38
+ const { i18n, name, buttonText, maxCount, disabled, value, onChange, objectInValue } = props;
39
39
  const [previewOpen, setPreviewOpen] = useState(false);
40
40
  const [previewImage, setPreviewImage] = useState('');
41
- const [imgList, setImgList] = useState((value === null || value === void 0 ? void 0 : value.map((url, index) => {
42
- if (typeof url === "string") {
43
- return {
44
- uid: String(index),
45
- status: 'done',
46
- url,
47
- name: url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.'))
48
- };
49
- }
50
- else {
51
- return url;
41
+ const [imgList, setImgList] = useState(() => {
42
+ if (value && value.length > 0) {
43
+ const temp = [];
44
+ value.forEach((item, index) => {
45
+ if (typeof item === "string" && item) {
46
+ temp.push({
47
+ uid: String(index),
48
+ status: 'done',
49
+ url: item,
50
+ name: item.substring(item.lastIndexOf('/') + 1, item.lastIndexOf('.'))
51
+ });
52
+ }
53
+ else {
54
+ if (item.url) {
55
+ temp.push(item);
56
+ }
57
+ }
58
+ });
59
+ return temp;
52
60
  }
53
- })) || []);
61
+ return [];
62
+ });
54
63
  const updateItems = (newItems) => {
55
64
  setImgList(newItems);
56
65
  let isEmpty = true;
57
- const urls = newItems.map((item) => item.url);
58
- urls.forEach((item) => {
66
+ const temp = [];
67
+ newItems && newItems.forEach((item) => {
68
+ if (item.url) {
69
+ temp.push(item);
70
+ }
71
+ });
72
+ temp.forEach((item) => {
59
73
  if (item) {
60
74
  isEmpty = false;
61
75
  return;
62
76
  }
63
77
  });
64
- onChange && (onChange === null || onChange === void 0 ? void 0 : onChange(!isEmpty ? urls : undefined));
78
+ if (objectInValue) {
79
+ onChange && onChange(!isEmpty ? temp : undefined);
80
+ }
81
+ else {
82
+ const urls = temp.map((item) => item.url);
83
+ onChange && onChange(!isEmpty ? urls : undefined);
84
+ }
65
85
  };
66
86
  const handleChange = ({ fileList }) => {
67
87
  fileList && fileList.forEach((file) => {
@@ -230,9 +250,9 @@ const MultipleImgUpload = (props) => {
230
250
  !((_b = props.opts) === null || _b === void 0 ? void 0 : _b.maxW) ? null : (React.createElement("span", null, i18n ? `${i18n.$t("global.maxW", "最大宽")}:${props.opts.maxW}` : `最大宽:${props.opts.maxW}`)),
231
251
  !((_c = props.opts) === null || _c === void 0 ? void 0 : _c.minH) ? null : (React.createElement("span", null, i18n ? `${i18n.$t("global.minH", "最小高")}:${props.opts.minH}` : `最小高:${props.opts.minH}`)),
232
252
  !((_d = props.opts) === null || _d === void 0 ? void 0 : _d.maxH) ? null : (React.createElement("span", null, i18n ? `${i18n.$t("global.maxH", "最大高")}:${props.opts.maxH}` : `最大高:${props.opts.maxH}`))))) : null)), type: "warning", showIcon: true })),
233
- React.createElement(DndContext, { sensors: [sensor], onDragEnd: onDragEnd },
253
+ React.createElement(DndContext, { sensors: disabled ? [] : [sensor], onDragEnd: disabled ? undefined : onDragEnd },
234
254
  React.createElement(SortableContext, { items: imgList === null || imgList === void 0 ? void 0 : imgList.map((i) => i.uid), strategy: rectSortingStrategy },
235
- React.createElement(Upload, { listType: "picture-card", fileList: imgList, action: action, beforeUpload: beforeUpload, onPreview: handlePreview, onChange: handleChange, onRemove: handleRemove, name: name, data: props.data, multiple: true, disabled: disabled, withCredentials: true, itemRender: (originNode, file) => (React.createElement(DraggableUploadListItem, { originNode: originNode, file: file })) }, maxCount == 0 ? uploadButton : maxCount && imgList.length >= maxCount ? null : uploadButton),
255
+ React.createElement(Upload, { listType: "picture-card", fileList: imgList, action: action, beforeUpload: beforeUpload, onPreview: handlePreview, onChange: handleChange, onRemove: handleRemove, name: name, data: props.data, multiple: true, disabled: disabled, withCredentials: true, itemRender: (originNode, file) => (React.createElement(DraggableUploadListItem, { originNode: originNode, file: file, disabled: disabled })) }, maxCount == 0 ? uploadButton : maxCount && imgList.length >= maxCount ? null : uploadButton),
236
256
  previewImage && (React.createElement(Img, { wrapperStyle: { display: 'none' }, preview: {
237
257
  visible: previewOpen,
238
258
  onVisibleChange: (visible) => setPreviewOpen(visible),
@@ -242,6 +262,7 @@ const MultipleImgUpload = (props) => {
242
262
  MultipleImgUpload.defaultProps = {
243
263
  maxCount: 6,
244
264
  showMessage: true,
265
+ objectInValue: false,
245
266
  action: "/api/upload/img",
246
267
  name: "file",
247
268
  gif: false,
@@ -100,7 +100,7 @@ const TablePro = ({ className, header, buttonArea, filterArea, filters, searchIn
100
100
  useEffect(() => {
101
101
  if (tableRef.current && innerColumns.length > 0 && scrollY == '100%') {
102
102
  const thead = tableRef.current.querySelector('thead');
103
- setTimeout(() => {
103
+ const runCalcHeight = () => {
104
104
  if (offsetY && offsetY > 0) {
105
105
  if (tableRef.current) {
106
106
  setY(tableRef.current.clientHeight - offsetY);
@@ -111,9 +111,17 @@ const TablePro = ({ className, header, buttonArea, filterArea, filters, searchIn
111
111
  setY(tableRef.current.clientHeight - (thead.clientHeight && thead.clientHeight + (pagination ? 64 : 20)));
112
112
  }
113
113
  }
114
- }, 100);
114
+ };
115
+ if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {
116
+ window.requestAnimationFrame(() => {
117
+ setTimeout(runCalcHeight, 100);
118
+ });
119
+ }
120
+ else {
121
+ setTimeout(runCalcHeight, 300);
122
+ }
115
123
  }
116
- }, [header, loading, innerColumns]);
124
+ }, [header, loading, innerColumns, offsetY]);
117
125
  useEffect(() => {
118
126
  if (selectKeys && selectKeys.length > 0 && !isEqual(selectedRowKeys, selectKeys)) {
119
127
  setSelectedRowKeys(selectKeys);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.4.32",
3
+ "version": "0.5.1",
4
4
  "author": "cxc",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -47,5 +47,5 @@
47
47
  "antd": "^6.0.0",
48
48
  "axios": "^1.1.2"
49
49
  },
50
- "gitHead": "cf8c284162bf81352e97c8ebc6e2d00741939543"
50
+ "gitHead": "84c695854492c49bcdf11c73cb5908a7b87f16b5"
51
51
  }