@ecoding/components.antd 0.3.56 → 0.3.58

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.
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ interface IOpts {
3
+ size?: number;
4
+ w?: number;
5
+ h?: number;
6
+ }
7
+ interface IProps {
8
+ max?: number;
9
+ message?: string;
10
+ showMessage?: boolean;
11
+ action: string | (() => string);
12
+ actionParams?: any;
13
+ name?: string;
14
+ i18n?: any;
15
+ opts?: IOpts;
16
+ value?: string[];
17
+ buttonText?: string;
18
+ headers?: any;
19
+ data?: any;
20
+ onChange?: any;
21
+ gif?: boolean;
22
+ disabled?: boolean;
23
+ isTip?: boolean;
24
+ }
25
+ declare const MultiPileImgUpload: React.FC<IProps>;
26
+ export default MultiPileImgUpload;
@@ -0,0 +1,124 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Space, Alert } from 'antd';
3
+ import { DragOutlined } from '@ant-design/icons';
4
+ import { DndContext, closestCenter, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
5
+ import { arrayMove, SortableContext, horizontalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
6
+ import { CSS } from '@dnd-kit/utilities';
7
+ import ImgUpload from '../single-img-upload';
8
+ const SortableItem = (props) => {
9
+ const { index, items, updateItems } = props;
10
+ const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
11
+ id: props.id
12
+ });
13
+ const style = {
14
+ transform: CSS.Transform.toString(transform),
15
+ transition,
16
+ position: 'relative',
17
+ margin: '0 8px'
18
+ };
19
+ const handleChange = (url) => {
20
+ const newItems = [...items];
21
+ newItems[index].url = url;
22
+ updateItems(newItems);
23
+ };
24
+ return (React.createElement("div", { ref: setNodeRef, style: style },
25
+ React.createElement("div", Object.assign({}, attributes, listeners, { style: {
26
+ position: 'absolute',
27
+ top: '4px',
28
+ left: '4px',
29
+ width: '20px',
30
+ height: '20px',
31
+ background: 'rgba(0,0,0,0.1)',
32
+ borderRadius: '50%',
33
+ cursor: 'grab',
34
+ zIndex: 10,
35
+ display: 'flex',
36
+ alignItems: 'center',
37
+ justifyContent: 'center'
38
+ } }),
39
+ React.createElement(DragOutlined, null)),
40
+ React.createElement(ImgUpload, Object.assign({}, props, { value: props.value, onChange: handleChange }))));
41
+ };
42
+ const MultiPileImgUpload = (props) => {
43
+ const [items, setItems] = useState([]);
44
+ const sensors = useSensors(useSensor(PointerSensor));
45
+ const handleDragEnd = (event) => {
46
+ const { active, over } = event;
47
+ if (active.id !== over.id) {
48
+ const temp = [...items];
49
+ const activeIndex = temp.findIndex((i) => i.id === active.id);
50
+ const overIndex = temp.findIndex((i) => i.id === (over === null || over === void 0 ? void 0 : over.id));
51
+ // 使用arrayMove计算新的排序结果
52
+ const newItems = arrayMove(temp, activeIndex, overIndex);
53
+ updateItems(newItems);
54
+ }
55
+ };
56
+ const updateItems = (newItems) => {
57
+ var _a;
58
+ setItems(newItems);
59
+ let isEmpty = true;
60
+ const urls = newItems.map((item) => item.url);
61
+ urls.forEach((item) => {
62
+ if (item) {
63
+ isEmpty = false;
64
+ return;
65
+ }
66
+ });
67
+ props.onChange && ((_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, !isEmpty ? urls : undefined));
68
+ };
69
+ useEffect(() => {
70
+ const initItems = Array(props.max)
71
+ .fill(undefined)
72
+ .map((item, i) => ({ id: i + 1, url: '' }));
73
+ if (props.value) {
74
+ const sorts = props.value.map((item, i) => ({ id: i + 1, url: item }));
75
+ const len = initItems.length - sorts.length;
76
+ for (let i = 0; i < len; i++) {
77
+ sorts.push({ id: sorts.length + 1 + i, url: '' });
78
+ }
79
+ setItems(sorts);
80
+ }
81
+ else {
82
+ setItems(initItems);
83
+ }
84
+ }, [props.value]);
85
+ return (React.createElement("div", null,
86
+ props.showMessage && (React.createElement(Alert, { className: 'mb20', message: props.message ? props.message : (React.createElement(Space, null,
87
+ React.createElement("div", null,
88
+ props.i18n ? props.i18n.$t("global.size", "大小") : "大小",
89
+ "\uFF1A",
90
+ props.i18n ? props.i18n.$t("global.lt", "小于") : "小于",
91
+ " ",
92
+ props.opts.size || 1,
93
+ "MB;"),
94
+ React.createElement("div", null,
95
+ props.i18n ? props.i18n.$t("global.dimension", "尺寸") : "尺寸",
96
+ "\uFF1A",
97
+ props.opts.w ? `${props.opts.w}px` : "n",
98
+ " * ",
99
+ props.opts.h ? `${props.opts.h}px` : "n",
100
+ ";"),
101
+ React.createElement("div", null,
102
+ props.i18n ? props.i18n.$t("global.support", "支持") : "支持",
103
+ "\uFF1Ajpg\u3001jpeg\u3001png",
104
+ props.gif ? "、gif" : "",
105
+ ";"))), type: "warning", showIcon: true })),
106
+ React.createElement(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd },
107
+ React.createElement(SortableContext, { items: items, strategy: horizontalListSortingStrategy },
108
+ React.createElement(Space, { wrap: true, align: "start" }, items.map((item, index) => (React.createElement(SortableItem, Object.assign({}, props, { index: index, items: items, updateItems: updateItems, value: item.url, key: item.id, id: item.id })))))))));
109
+ };
110
+ MultiPileImgUpload.defaultProps = {
111
+ showMessage: true,
112
+ max: 6,
113
+ action: '/api/upload/img',
114
+ name: 'file',
115
+ gif: false,
116
+ buttonText: '上传图片',
117
+ data: {},
118
+ isTip: false,
119
+ actionParams: {},
120
+ opts: {
121
+ size: 1
122
+ }
123
+ };
124
+ export default MultiPileImgUpload;
@@ -3,6 +3,7 @@ import type { InputProps } from 'antd';
3
3
  interface IItem {
4
4
  key: any;
5
5
  label: string;
6
+ [props: string]: any;
6
7
  }
7
8
  interface IProps extends InputProps {
8
9
  placeholder?: string;
@@ -21,6 +21,7 @@ interface IProps {
21
21
  onChange?: any;
22
22
  gif?: boolean;
23
23
  disabled?: boolean;
24
+ isTip?: boolean;
24
25
  }
25
26
  declare const ImgUpload: React.FC<IProps>;
26
27
  export default ImgUpload;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import React, { useCallback, useEffect, useMemo, useState } from "react";
11
- import { Upload, message, Space } from "antd";
11
+ import { Upload, message, Space, Image as Img } from "antd";
12
12
  import { LoadingOutlined, PlusOutlined, DeleteOutlined } from "@ant-design/icons";
13
13
  import { buildURL } from "@ecoding/helper.url";
14
14
  import Toast from "../../core/toast";
@@ -119,27 +119,28 @@ const ImgUpload = (props) => {
119
119
  loading ? React.createElement(LoadingOutlined, null) : React.createElement(PlusOutlined, null),
120
120
  React.createElement("div", { style: { marginTop: 8 } }, props.buttonText))), [loading]);
121
121
  useEffect(() => {
122
- if (props.value) {
122
+ if (props.value || props.value == "") {
123
123
  setImageUrl(props.value);
124
124
  }
125
125
  }, [props.value]);
126
126
  return (React.createElement(Space, null,
127
- React.createElement(Upload, { withCredentials: true, beforeUpload: beforeUpload, name: props.name, data: props.data, headers: props.headers, disabled: props.disabled, listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }, imageUrl ? (React.createElement("div", { style: { position: "relative" } },
127
+ imageUrl ? (React.createElement("div", { style: { position: "relative" } },
128
128
  React.createElement("span", { style: {
129
129
  position: "absolute",
130
- background: "#fff",
131
130
  bottom: "6px",
132
131
  right: "2px",
133
132
  width: "18px",
134
133
  height: "18px",
135
- opacity: ".9"
134
+ opacity: ".9",
135
+ cursor: "pointer",
136
+ zIndex: 10
136
137
  }, onClick: (e) => {
137
138
  e.stopPropagation();
138
139
  clear();
139
140
  } },
140
141
  React.createElement(DeleteOutlined, null)),
141
- React.createElement("img", { style: { width: "102px", height: "102px", objectFit: "contain" }, src: imageUrl }))) : (uploadButton)),
142
- React.createElement("div", null,
142
+ React.createElement(Img, { style: { width: "102px", height: "102px", objectFit: "contain", cursor: "pointer" }, src: imageUrl }))) : (React.createElement(Upload, { withCredentials: true, beforeUpload: beforeUpload, name: props.name, data: props.data, headers: props.headers, disabled: props.disabled, listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }, uploadButton)),
143
+ props.isTip ? (React.createElement("div", null,
143
144
  React.createElement("p", null,
144
145
  props.i18n ? props.i18n.$t("global.size", "大小") : "大小",
145
146
  "\uFF1A",
@@ -156,7 +157,7 @@ const ImgUpload = (props) => {
156
157
  React.createElement("p", null,
157
158
  props.i18n ? props.i18n.$t("global.support", "支持") : "支持",
158
159
  "\uFF1Ajpg\u3001jpeg\u3001png",
159
- props.gif ? "、gif" : ""))));
160
+ props.gif ? "、gif" : ""))) : null));
160
161
  };
161
162
  ImgUpload.defaultProps = {
162
163
  action: "/api/upload/img",
@@ -165,6 +166,7 @@ ImgUpload.defaultProps = {
165
166
  gif: false,
166
167
  buttonText: '上传图片',
167
168
  data: {},
169
+ isTip: true,
168
170
  actionParams: {},
169
171
  opts: {
170
172
  size: 1
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ interface IProps {
3
+ value?: string[];
4
+ onChange?: any;
5
+ className?: string;
6
+ disabled?: boolean;
7
+ fixedFirst?: boolean;
8
+ addTagText?: string;
9
+ }
10
+ declare const C: React.FC<IProps>;
11
+ export default C;
@@ -0,0 +1,97 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { PlusOutlined } from '@ant-design/icons';
3
+ import { isEqual } from "@ecoding/helper.is";
4
+ import { Flex, Input, Tag, theme, Tooltip } from 'antd';
5
+ const tagInputStyle = {
6
+ width: 64,
7
+ height: 22,
8
+ marginInlineEnd: 8,
9
+ verticalAlign: 'top'
10
+ };
11
+ const C = (props) => {
12
+ const { token } = theme.useToken();
13
+ const [tags, setTags] = useState([]);
14
+ const [inputVisible, setInputVisible] = useState(false);
15
+ const [inputValue, setInputValue] = useState('');
16
+ const [editInputIndex, setEditInputIndex] = useState(-1);
17
+ const [editInputValue, setEditInputValue] = useState('');
18
+ const inputRef = useRef(null);
19
+ const editInputRef = useRef(null);
20
+ useEffect(() => {
21
+ var _a;
22
+ if (inputVisible) {
23
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
24
+ }
25
+ }, [inputVisible]);
26
+ useEffect(() => {
27
+ var _a;
28
+ (_a = editInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
29
+ }, [editInputValue]);
30
+ const handleClose = (removedTag) => {
31
+ const newTags = tags.filter((tag) => tag !== removedTag);
32
+ setTags(newTags);
33
+ props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
34
+ };
35
+ const showInput = () => {
36
+ setInputVisible(true);
37
+ };
38
+ const handleInputChange = (e) => {
39
+ setInputValue(e.target.value);
40
+ };
41
+ const handleInputConfirm = () => {
42
+ if (inputValue && !tags.includes(inputValue)) {
43
+ const values = [...tags, inputValue];
44
+ setTags(values);
45
+ props.onChange && props.onChange(values && values.length > 0 ? values : undefined);
46
+ }
47
+ setInputVisible(false);
48
+ setInputValue('');
49
+ };
50
+ const handleEditInputChange = (e) => {
51
+ setEditInputValue(e.target.value);
52
+ };
53
+ const handleEditInputConfirm = () => {
54
+ const newTags = [...(tags || [])];
55
+ newTags[editInputIndex] = editInputValue;
56
+ setTags(newTags);
57
+ props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
58
+ setEditInputIndex(-1);
59
+ setEditInputValue('');
60
+ };
61
+ const tagPlusStyle = {
62
+ height: 22,
63
+ background: token.colorBgContainer,
64
+ borderStyle: 'dashed'
65
+ };
66
+ useEffect(() => {
67
+ if (props.value && !isEqual(props.value, tags)) {
68
+ setTags(props.value);
69
+ }
70
+ }, [props.value]);
71
+ return (React.createElement(Flex, { gap: "4px 0", wrap: "wrap" },
72
+ tags.map((tag, index) => {
73
+ if (editInputIndex === index) {
74
+ return (React.createElement(Input, { ref: editInputRef, key: tag, size: "small", style: tagInputStyle, value: editInputValue, onChange: handleEditInputChange, onBlur: handleEditInputConfirm, onPressEnter: handleEditInputConfirm }));
75
+ }
76
+ const isLongTag = tag.length > 20;
77
+ const tagElem = (React.createElement(Tag, { key: tag, closable: props.fixedFirst ? index !== 0 : true, style: { userSelect: 'none' }, onClose: () => handleClose(tag) },
78
+ React.createElement("span", { onDoubleClick: (e) => {
79
+ if (props.disabled) {
80
+ return;
81
+ }
82
+ if (props.fixedFirst ? index !== 0 : true) {
83
+ setEditInputIndex(index);
84
+ setEditInputValue(tag);
85
+ e.preventDefault();
86
+ }
87
+ } }, isLongTag ? `${tag.slice(0, 20)}...` : tag)));
88
+ return isLongTag ? (React.createElement(Tooltip, { title: tag, key: tag }, tagElem)) : (tagElem);
89
+ }),
90
+ props.disabled ? null : inputVisible ? (React.createElement(Input, { ref: inputRef, type: "text", size: "small", style: tagInputStyle, value: inputValue, onChange: handleInputChange, onBlur: handleInputConfirm, onPressEnter: handleInputConfirm })) : (React.createElement(Tag, { style: tagPlusStyle, icon: React.createElement(PlusOutlined, null), onClick: showInput }, props.addTagText))));
91
+ };
92
+ C.defaultProps = {
93
+ disabled: false,
94
+ fixedFirst: false,
95
+ addTagText: 'New Tag'
96
+ };
97
+ export default C;
package/lib/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { default as PhoneInput } from "./core/phone-input";
11
11
  export { default as RangePicker } from "./core/range-picker";
12
12
  export { default as DatePicker } from "./core/date.picker";
13
13
  export { default as SingleImgUpload } from "./core/single-img-upload";
14
+ export { default as MultipleSingleImgUpload } from "./core/multiple-single-img-upload";
14
15
  export { default as SingleFileUpload } from "./core/single-file-upload";
15
16
  export { default as MultipleUpload } from "./core/multiple-upload";
16
17
  export { default as FormLabel } from "./core/form.label";
@@ -18,5 +19,6 @@ export { default as FormLabelAttachment } from "./core/form.label.attachment";
18
19
  export { default as FormList } from "./core/form.list";
19
20
  export { default as AsyncSelect } from "./core/async-select";
20
21
  export { default as AsyncTransfer } from "./core/async-transfer";
22
+ export { default as TagItems } from "./core/tag.items";
21
23
  export { default as TablePro } from "./core/table-pro";
22
24
  export { default as http } from "./helpers/http";
package/lib/index.js CHANGED
@@ -11,6 +11,7 @@ export { default as PhoneInput } from "./core/phone-input";
11
11
  export { default as RangePicker } from "./core/range-picker";
12
12
  export { default as DatePicker } from "./core/date.picker";
13
13
  export { default as SingleImgUpload } from "./core/single-img-upload";
14
+ export { default as MultipleSingleImgUpload } from "./core/multiple-single-img-upload";
14
15
  export { default as SingleFileUpload } from "./core/single-file-upload";
15
16
  export { default as MultipleUpload } from "./core/multiple-upload";
16
17
  export { default as FormLabel } from "./core/form.label";
@@ -18,5 +19,6 @@ export { default as FormLabelAttachment } from "./core/form.label.attachment";
18
19
  export { default as FormList } from "./core/form.list";
19
20
  export { default as AsyncSelect } from "./core/async-select";
20
21
  export { default as AsyncTransfer } from "./core/async-transfer";
22
+ export { default as TagItems } from "./core/tag.items";
21
23
  export { default as TablePro } from "./core/table-pro";
22
24
  export { default as http } from "./helpers/http";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.3.56",
3
+ "version": "0.3.58",
4
4
  "author": "cxc",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -24,6 +24,8 @@
24
24
  "build": "rm -rf lib && tsc && rollup -c"
25
25
  },
26
26
  "peerDependencies": {
27
+ "@dnd-kit/core": ">=6.3.1",
28
+ "@dnd-kit/sortable": ">=10.0.0",
27
29
  "@ecoding/helper.event": "*",
28
30
  "@ecoding/helper.is": "*",
29
31
  "@ecoding/helper.json": "*",
@@ -34,14 +36,16 @@
34
36
  "axios": ">=1.1.2"
35
37
  },
36
38
  "devDependencies": {
39
+ "@dnd-kit/core": "^6.3.1",
40
+ "@dnd-kit/sortable": "^10.0.0",
37
41
  "@ecoding/helper.event": "*",
38
42
  "@ecoding/helper.is": "*",
39
43
  "@ecoding/helper.json": "*",
40
44
  "@ecoding/helper.request": "*",
41
45
  "@ecoding/helper.request.hook": "*",
42
46
  "@ecoding/helper.url": "*",
43
- "antd": "^5.8.4",
47
+ "antd": "5.27.0",
44
48
  "axios": "^1.1.2"
45
49
  },
46
- "gitHead": "748f27b64bf7cc282367b4167f9439d92e97fb94"
50
+ "gitHead": "d005731c58467d76d54228231819e2489af8ab2c"
47
51
  }