@ecoding/components.antd 0.3.60 → 0.3.62

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.
@@ -31,5 +31,5 @@ interface IProps extends SelectProps<any> {
31
31
  onChange?: any;
32
32
  onChangeOpts?: any;
33
33
  }
34
- declare const AsyncSlect: React.FC<IProps>;
35
- export default AsyncSlect;
34
+ declare const AsyncSelect: React.FC<IProps>;
35
+ export default AsyncSelect;
@@ -26,7 +26,7 @@ import { isSomething } from "@ecoding/helper.is";
26
26
  import { jsonFormatNewKey, jsonFormatNewKey2 } from "@ecoding/helper.json";
27
27
  const { Option } = Select;
28
28
  let timeout;
29
- const AsyncSlect = memo((props) => {
29
+ const AsyncSelect = memo((props) => {
30
30
  const r = http.getRequest();
31
31
  const [loading, setLoading] = useState(true);
32
32
  const [options, setOptions] = useState([]);
@@ -37,57 +37,57 @@ const AsyncSlect = memo((props) => {
37
37
  const { onChange, searchIface, data, iface } = p, rest = __rest(p, ["onChange", "searchIface", "data", "iface"]);
38
38
  return rest;
39
39
  };
40
- useEffect(() => {
41
- const ex = () => __awaiter(void 0, void 0, void 0, function* () {
42
- const innerEx = () => __awaiter(void 0, void 0, void 0, function* () {
43
- var _a;
44
- // 获得第一个接口信息
45
- if (data) {
46
- const res = data.format2 ? jsonFormatNewKey2(data.datas, data.format2) : data.format ? jsonFormatNewKey(data.datas, data.format) : data.datas;
47
- return Promise.resolve(res);
40
+ const initEx = () => __awaiter(void 0, void 0, void 0, function* () {
41
+ var _a;
42
+ // 获得第一个接口信息
43
+ if (data) {
44
+ const res = data.format2 ? jsonFormatNewKey2(data.datas, data.format2) : data.format ? jsonFormatNewKey(data.datas, data.format) : data.datas;
45
+ return Promise.resolve(res);
46
+ }
47
+ let params = {};
48
+ if (iface) {
49
+ if (iface.paramKey) {
50
+ // 设置接口调用参数
51
+ params[iface.paramKey] = iface.paramValue;
52
+ }
53
+ if (iface.params) {
54
+ params = Object.assign({}, params, iface.params);
55
+ }
56
+ let resOrigin = [];
57
+ // 这里支持了外部直接传入列表结果
58
+ const cache = isSomething(iface.cache) ? iface.cache : false;
59
+ if (((_a = iface.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "post") {
60
+ resOrigin = yield r.post(iface.url, params, { cache });
61
+ }
62
+ else {
63
+ resOrigin = yield r.get(iface.url, params, { cache });
64
+ }
65
+ // 指定数据key
66
+ if (iface && iface.fromKey) {
67
+ if (Array.isArray(iface.fromKey)) {
68
+ iface.fromKey.forEach((key) => {
69
+ resOrigin = resOrigin[key];
70
+ });
48
71
  }
49
- let params = {};
50
- if (iface) {
51
- if (iface.paramKey) {
52
- // 设置接口调用参数
53
- params[iface.paramKey] = iface.paramValue;
54
- }
55
- if (iface.params) {
56
- params = Object.assign({}, params, iface.params);
57
- }
58
- let resOrigin = [];
59
- // 这里支持了外部直接传入列表结果
60
- const cache = isSomething(iface.cache) ? iface.cache : false;
61
- if (((_a = iface.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "post") {
62
- resOrigin = yield r.post(iface.url, params, { cache });
63
- }
64
- else {
65
- resOrigin = yield r.get(iface.url, params, { cache });
66
- }
67
- // 指定数据key
68
- if (iface && iface.fromKey) {
69
- if (Array.isArray(iface.fromKey)) {
70
- iface.fromKey.forEach((key) => {
71
- resOrigin = resOrigin[key];
72
- });
73
- }
74
- else {
75
- resOrigin = resOrigin[iface.fromKey];
76
- }
77
- }
78
- const res = iface.format2 ? jsonFormatNewKey2(resOrigin, iface.format2) : iface.format ? jsonFormatNewKey(resOrigin, iface.format) : resOrigin;
79
- return Promise.resolve(res);
72
+ else {
73
+ resOrigin = resOrigin[iface.fromKey];
80
74
  }
81
- return Promise.reject("没有iface或data");
82
- });
83
- const res = yield innerEx();
75
+ }
76
+ const res = iface.format2 ? jsonFormatNewKey2(resOrigin, iface.format2) : iface.format ? jsonFormatNewKey(resOrigin, iface.format) : resOrigin;
77
+ return Promise.resolve(res);
78
+ }
79
+ return Promise.reject("没有iface或data");
80
+ });
81
+ useEffect(() => {
82
+ const ex = () => __awaiter(void 0, void 0, void 0, function* () {
83
+ const res = yield initEx();
84
84
  setOptions(res);
85
85
  setLoading(false);
86
86
  });
87
87
  ex();
88
88
  }, [data, iface]);
89
89
  const handleSearch = (newValue) => __awaiter(void 0, void 0, void 0, function* () {
90
- if (!newValue || !searchIface) {
90
+ if (!searchIface) {
91
91
  return null;
92
92
  }
93
93
  if (timeout) {
@@ -95,8 +95,13 @@ const AsyncSlect = memo((props) => {
95
95
  timeout = null;
96
96
  }
97
97
  const innerEx = () => __awaiter(void 0, void 0, void 0, function* () {
98
- var _a;
98
+ var _b;
99
99
  let params = {};
100
+ if (!newValue) {
101
+ const res = yield initEx();
102
+ setOptions(res);
103
+ return;
104
+ }
100
105
  if (searchIface) {
101
106
  if (searchIface.paramKey) {
102
107
  // 设置接口调用参数
@@ -108,7 +113,7 @@ const AsyncSlect = memo((props) => {
108
113
  let resOrigin = [];
109
114
  // 这里支持了外部直接传入列表结果
110
115
  const cache = isSomething(searchIface.cache) ? searchIface.cache : false;
111
- if (((_a = searchIface.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === "post") {
116
+ if (((_b = searchIface.method) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === "post") {
112
117
  resOrigin = yield r.post(searchIface.url, params, { cache });
113
118
  }
114
119
  else {
@@ -151,4 +156,4 @@ const AsyncSlect = memo((props) => {
151
156
  return option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0;
152
157
  }, allowClear: true, showSearch: true, onSearch: handleSearch, optionFilterProp: "children" }, getRest(props), { onChange: changeHandler }), children));
153
158
  });
154
- export default AsyncSlect;
159
+ export default AsyncSelect;
@@ -11,8 +11,6 @@ import React, { useState, useCallback, useMemo } from 'react';
11
11
  import { Upload, Image as Img, Alert, Flex, message } from 'antd';
12
12
  import { PlusOutlined } from '@ant-design/icons';
13
13
  import { buildURL } from "@ecoding/helper.url";
14
- import Toast from "../../core/toast";
15
- import Loading from "../../core/loading";
16
14
  import { DndContext, PointerSensor, useSensor } from '@dnd-kit/core';
17
15
  import { arrayMove, SortableContext, useSortable, horizontalListSortingStrategy, } from '@dnd-kit/sortable';
18
16
  import { CSS } from '@dnd-kit/utilities';
@@ -63,39 +61,17 @@ const MultipleImgUpload = (props) => {
63
61
  });
64
62
  onChange && (onChange === null || onChange === void 0 ? void 0 : onChange(!isEmpty ? urls : undefined));
65
63
  };
66
- const handleChange = (info) => {
67
- switch (info.file.status) {
68
- case 'uploading':
69
- Loading.show();
70
- break;
71
- case 'done': {
72
- Loading.hide();
73
- const response = info.file.response;
74
- if (response && response.code === 200) {
75
- const data = response.data || {};
76
- const temp = imgList.concat([Object.assign({}, data)]);
77
- updateItems(temp);
78
- }
79
- else {
80
- Toast.error({
81
- mask: true,
82
- title: response.message || '服务出错,图片上传失败'
83
- });
84
- }
85
- break;
64
+ const handleChange = ({ fileList }) => {
65
+ fileList && fileList.forEach((item) => {
66
+ if (item.status == "done" && item.response.code == 200 && item.response.data) {
67
+ item.url = item.response.data.url;
86
68
  }
87
- case 'error': {
88
- const response = info.file.response;
89
- Toast.error({
90
- mask: true,
91
- title: response.message || '服务出错,图片上传失败'
92
- });
93
- Loading.hide();
94
- break;
95
- }
96
- default:
97
- break;
98
- }
69
+ });
70
+ updateItems(fileList);
71
+ // if (len) {
72
+ // return;
73
+ // }
74
+ // updateItems(fileList)
99
75
  };
100
76
  const handleRemove = (file) => {
101
77
  const lefts = imgList.filter(item => item.uid !== file.uid);
@@ -221,7 +197,7 @@ MultipleImgUpload.defaultProps = {
221
197
  action: "/api/upload/img",
222
198
  name: "file",
223
199
  gif: false,
224
- buttonText: '上传图片',
200
+ buttonText: 'Upload',
225
201
  data: {},
226
202
  actionParams: {},
227
203
  opts: {
@@ -122,7 +122,7 @@ MultiPileImgUpload.defaultProps = {
122
122
  action: '/api/upload/img',
123
123
  name: 'file',
124
124
  gif: false,
125
- buttonText: '上传图片',
125
+ buttonText: 'Upload',
126
126
  data: {},
127
127
  isTip: false,
128
128
  actionParams: {},
@@ -26,5 +26,5 @@ interface IProps {
26
26
  openFileDialogOnClick?: boolean;
27
27
  style?: React.CSSProperties;
28
28
  }
29
- declare const SingleFileUpload: React.FC<IProps>;
30
- export default SingleFileUpload;
29
+ declare const MultipleUpload: React.FC<IProps>;
30
+ export default MultipleUpload;
@@ -37,7 +37,7 @@ const InfosRender = ({ infos, setInfos, onChange }) => {
37
37
  }
38
38
  return React.createElement(Empty, { imageStyle: { height: 30 }, image: Empty.PRESENTED_IMAGE_SIMPLE });
39
39
  };
40
- const SingleFileUpload = (props) => {
40
+ const MultipleUpload = (props) => {
41
41
  const [infos, setInfos] = useState([]);
42
42
  const [open, setOpen] = useState(undefined);
43
43
  const timeout = useRef();
@@ -128,7 +128,7 @@ const SingleFileUpload = (props) => {
128
128
  React.createElement(Popover, { destroyTooltipOnHide: true, open: open, placement: "right", trigger: "hover", title: "Uploaded", content: React.createElement(InfosRender, { onChange: props.onChange, infos: infos, setInfos: setInfos }) },
129
129
  React.createElement(Button, { icon: React.createElement(EllipsisOutlined, null) }))));
130
130
  };
131
- SingleFileUpload.defaultProps = {
131
+ MultipleUpload.defaultProps = {
132
132
  name: 'file',
133
133
  openFileDialogOnClick: true,
134
134
  icon: true,
@@ -136,8 +136,8 @@ SingleFileUpload.defaultProps = {
136
136
  extraData: {},
137
137
  maxCount: 10,
138
138
  headers: undefined,
139
- buttonText: '点击上传',
139
+ buttonText: 'Upload',
140
140
  type: 'jpg, jpeg, png, gif, bmp, wbmp, webp, tif, woff, woff2, ttf, otf, txt, psd, svg, js, jsx, json, css, less, html, htm, xml, pdf, zip, gz, tgz, gzip, mp3, mp4, avi, xlsx, xls, doc, docx, ppt, pptx, rar, 7z',
141
141
  style: {}
142
142
  };
143
- export default SingleFileUpload;
143
+ export default MultipleUpload;
@@ -101,7 +101,7 @@ SingleFileUpload.defaultProps = {
101
101
  icon: true,
102
102
  data: {},
103
103
  actionParams: {},
104
- buttonText: "点击上传",
104
+ buttonText: "Upload",
105
105
  type: "jpg, jpeg, png, gif, bmp, wbmp, webp, tif, woff, woff2, ttf, otf, txt, psd, svg, js, jsx, json, css, less, html, htm, xml, pdf, zip, gz, tgz, gzip, mp3, mp4, avi, xlsx, xls, doc, docx, ppt, pptx, rar, 7z",
106
106
  style: {}
107
107
  };
@@ -133,6 +133,7 @@ const ImgUpload = (props) => {
133
133
  height: "18px",
134
134
  opacity: ".9",
135
135
  cursor: "pointer",
136
+ zIndex: 1
136
137
  }, onClick: (e) => {
137
138
  e.stopPropagation();
138
139
  clear();
@@ -163,7 +164,7 @@ ImgUpload.defaultProps = {
163
164
  name: "file",
164
165
  value: "",
165
166
  gif: false,
166
- buttonText: '上传图片',
167
+ buttonText: 'Upload',
167
168
  data: {},
168
169
  isTip: true,
169
170
  actionParams: {},
@@ -6,6 +6,7 @@ interface IProps {
6
6
  disabled?: boolean;
7
7
  fixedFirst?: boolean;
8
8
  addTagText?: string;
9
+ multipleError?: string;
9
10
  }
10
11
  declare const C: React.FC<IProps>;
11
12
  export default C;
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
2
  import { PlusOutlined } from '@ant-design/icons';
3
3
  import { isEqual } from "@ecoding/helper.is";
4
- import { Flex, Input, Tag, theme, Tooltip } from 'antd';
4
+ import { Flex, Input, message, Tag, theme, Tooltip } from 'antd';
5
5
  const tagInputStyle = {
6
6
  width: 64,
7
7
  height: 22,
@@ -39,10 +39,15 @@ const C = (props) => {
39
39
  setInputValue(e.target.value);
40
40
  };
41
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);
42
+ if (inputValue) {
43
+ if (!tags.includes(inputValue.trim())) {
44
+ const values = [...tags, inputValue.trim()];
45
+ setTags(values);
46
+ props.onChange && props.onChange(values && values.length > 0 ? values : undefined);
47
+ }
48
+ else {
49
+ message.error(props.multipleError || '标签已存在');
50
+ }
46
51
  }
47
52
  setInputVisible(false);
48
53
  setInputValue('');
@@ -52,9 +57,14 @@ const C = (props) => {
52
57
  };
53
58
  const handleEditInputConfirm = () => {
54
59
  const newTags = [...(tags || [])];
55
- newTags[editInputIndex] = editInputValue;
56
- setTags(newTags);
57
- props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
60
+ if (!newTags.includes(editInputValue.trim())) {
61
+ newTags[editInputIndex] = editInputValue.trim();
62
+ setTags(newTags);
63
+ props.onChange && props.onChange(newTags && newTags.length > 0 ? newTags : undefined);
64
+ }
65
+ else {
66
+ message.error(props.multipleError || '标签已存在');
67
+ }
58
68
  setEditInputIndex(-1);
59
69
  setEditInputValue('');
60
70
  };
@@ -63,6 +73,12 @@ const C = (props) => {
63
73
  background: token.colorBgContainer,
64
74
  borderStyle: 'dashed'
65
75
  };
76
+ const tagDisabledPlusStyle = {
77
+ height: 22,
78
+ background: token.colorBgContainerDisabled,
79
+ borderStyle: 'dashed',
80
+ color: token.colorTextDisabled
81
+ };
66
82
  useEffect(() => {
67
83
  if (props.value && !isEqual(props.value, tags)) {
68
84
  setTags(props.value);
@@ -74,7 +90,7 @@ const C = (props) => {
74
90
  return (React.createElement(Input, { ref: editInputRef, key: tag, size: "small", style: tagInputStyle, value: editInputValue, onChange: handleEditInputChange, onBlur: handleEditInputConfirm, onPressEnter: handleEditInputConfirm }));
75
91
  }
76
92
  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) },
93
+ const tagElem = (React.createElement(Tag, { key: tag, closable: props.disabled ? false : props.fixedFirst ? index !== 0 : true, style: { userSelect: 'none' }, onClose: () => handleClose(tag) },
78
94
  React.createElement("span", { onDoubleClick: (e) => {
79
95
  if (props.disabled) {
80
96
  return;
@@ -87,7 +103,7 @@ const C = (props) => {
87
103
  } }, isLongTag ? `${tag.slice(0, 20)}...` : tag)));
88
104
  return isLongTag ? (React.createElement(Tooltip, { title: tag, key: tag }, tagElem)) : (tagElem);
89
105
  }),
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))));
106
+ props.disabled ? (React.createElement(Tag, { style: tagDisabledPlusStyle, icon: React.createElement(PlusOutlined, null) }, props.addTagText)) : 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
107
  };
92
108
  C.defaultProps = {
93
109
  disabled: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.3.60",
3
+ "version": "0.3.62",
4
4
  "author": "cxc",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -47,5 +47,5 @@
47
47
  "antd": "5.27.0",
48
48
  "axios": "^1.1.2"
49
49
  },
50
- "gitHead": "ba3818c41417032a2fb1c71f400cf283940dd54f"
50
+ "gitHead": "08d74aa3e9086a168e7482332a68a209d1dce911"
51
51
  }