@ecoding/components.antd 0.2.28 → 0.2.30

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,20 @@
1
+ import React from "react";
2
+ interface IProps {
3
+ value?: string;
4
+ type?: "secondary" | "success" | "warning" | "danger";
5
+ empty?: React.ReactNode;
6
+ disabled?: boolean;
7
+ mark?: boolean;
8
+ code?: boolean;
9
+ keyboard?: boolean;
10
+ underline?: boolean;
11
+ delete?: boolean;
12
+ strong?: boolean;
13
+ italic?: boolean;
14
+ link?: {
15
+ href?: string;
16
+ target?: "_blank" | "_self";
17
+ };
18
+ }
19
+ declare const C: React.FC<IProps>;
20
+ export default C;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { Typography } from "antd";
3
+ const C = (props) => {
4
+ if (props.link) {
5
+ return React.createElement(Typography.Link, Object.assign({}, props.link), props.value);
6
+ }
7
+ return React.createElement(Typography.Text, { italic: props.italic, strong: props.strong, delete: props.delete, underline: props.underline, disabled: props.disabled, mark: props.mark, code: props.code, keyboard: props.keyboard }, props.empty ? props.empty : props.value);
8
+ };
9
+ export default C;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import type { FormListFieldData } from 'antd';
3
+ interface IC {
4
+ title: string;
5
+ require?: boolean;
6
+ name: string;
7
+ rules?: any;
8
+ width?: number;
9
+ render: (field: FormListFieldData, index: number) => React.ReactNode;
10
+ }
11
+ interface IProps {
12
+ columns: IC[];
13
+ name: string;
14
+ rules?: any;
15
+ i18n?: any;
16
+ hideOperation?: boolean;
17
+ operation?: {
18
+ width?: number;
19
+ component?: React.ReactNode;
20
+ title: string;
21
+ };
22
+ }
23
+ declare const C: React.FC<IProps>;
24
+ export default C;
@@ -0,0 +1,60 @@
1
+ import React, { useMemo } from 'react';
2
+ import { Typography, Form, Button } from 'antd';
3
+ import { PlusCircleOutlined } from '@ant-design/icons';
4
+ const C = ({ columns, rules, name, hideOperation, operation, i18n }) => {
5
+ const tdStyle = {
6
+ verticalAlign: 'top',
7
+ lineHeight: '32px',
8
+ padding: '10px'
9
+ };
10
+ const thStyle = {
11
+ textAlign: 'left',
12
+ backgroundColor: '#fafafa',
13
+ padding: '8px'
14
+ };
15
+ const trStyle = {
16
+ borderBottom: '1px solid #eee'
17
+ };
18
+ const widths = useMemo(() => {
19
+ let w = 60;
20
+ columns.forEach((column) => {
21
+ w += column.width || 200;
22
+ });
23
+ if (operation) {
24
+ w += operation.width || 150;
25
+ }
26
+ else {
27
+ w += 150;
28
+ }
29
+ return w;
30
+ }, []);
31
+ return (React.createElement(Form.List, { name: name, rules: rules || [] }, (fields, { add, remove }, { errors }) => (React.createElement(React.Fragment, null,
32
+ React.createElement("div", { className: "m-form-list", style: { overflowX: 'auto', marginBottom: '4px', paddingBottom: '12px', position: 'relative' } },
33
+ React.createElement("table", { style: { width: widths } },
34
+ React.createElement("thead", null,
35
+ React.createElement("tr", null,
36
+ React.createElement("th", { style: Object.assign({}, thStyle, { width: '60px' }) }, i18n ? i18n.$t("global.num") : "序号"),
37
+ columns.map((column, i) => {
38
+ if (column.require) {
39
+ return (React.createElement("th", { style: Object.assign({}, thStyle, { width: column.width || 200 }) },
40
+ React.createElement("span", { style: { color: '#ff4d4f' } }, "*"),
41
+ " ",
42
+ column.title));
43
+ }
44
+ return React.createElement("th", { style: Object.assign({}, thStyle, { width: 150 }) }, column.title);
45
+ }),
46
+ hideOperation ? null : operation ? (React.createElement("th", { style: Object.assign({}, thStyle, { width: operation.width || 150, right: 0, position: "sticky" }) }, operation.title)) : (React.createElement("th", { style: Object.assign({}, thStyle, { width: 150, right: 0, position: "sticky" }) }, i18n ? i18n.$t("global.operation") : "操作")))),
47
+ React.createElement("tbody", null, fields.map((field, index) => {
48
+ return (React.createElement("tr", { style: trStyle },
49
+ React.createElement("td", { style: tdStyle }, index + 1),
50
+ columns.map((column, i) => {
51
+ return (React.createElement("td", { style: tdStyle },
52
+ React.createElement(Form.Item, { name: [field.name, column.name], rules: column.rules || [] }, column.render(field, index))));
53
+ }),
54
+ hideOperation ? null : operation ? (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) }, operation.component)) : (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
55
+ React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => remove(field.name) }, i18n ? i18n.$t("global.del") : '删除')))));
56
+ })))),
57
+ React.createElement("div", null,
58
+ React.createElement(Button, { icon: React.createElement(PlusCircleOutlined, null), type: "dashed", onClick: () => add() }, i18n ? i18n.$t("global.add") : "添加"))))));
59
+ };
60
+ export default C;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { UploadFile } from 'antd/lib/upload/interface';
3
+ interface IRes {
4
+ name: string;
5
+ url: string;
6
+ }
7
+ interface IProps {
8
+ action: string | (() => string);
9
+ actionParams?: any;
10
+ buttonText?: string;
11
+ type?: string;
12
+ maxCount?: number;
13
+ name?: string;
14
+ data?: any;
15
+ value?: IRes[];
16
+ headers?: any;
17
+ uploadRef?: any;
18
+ onChange?: (infos: IRes[]) => void;
19
+ onDone?: (file: UploadFile, res: any) => void;
20
+ onRemove?: (file: UploadFile) => void;
21
+ onError?: (file: UploadFile) => void;
22
+ disabled?: boolean;
23
+ icon?: boolean;
24
+ openFileDialogOnClick?: boolean;
25
+ style?: React.CSSProperties;
26
+ }
27
+ declare const SingleFileUpload: React.FC<IProps>;
28
+ export default SingleFileUpload;
@@ -0,0 +1,137 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useCallback, useMemo, useState, useEffect, useRef } from 'react';
11
+ import { Upload, message, Button, Popover, Typography, Space, Empty } from 'antd';
12
+ import { UploadOutlined, LinkOutlined, DeleteOutlined, EllipsisOutlined } from '@ant-design/icons';
13
+ import { buildURL } from '@ecoding/helper.url';
14
+ import Toast from "../../core/toast";
15
+ import Loading from "../../core/loading";
16
+ import http from "../../helpers/http";
17
+ const InfosRender = ({ infos, setInfos }) => {
18
+ const remove = (i) => {
19
+ const temp = infos.concat([]);
20
+ temp.splice(i, 1);
21
+ setInfos(temp);
22
+ };
23
+ if (infos && infos.length > 0) {
24
+ return (React.createElement("ul", null, infos.map((info, i) => {
25
+ return (React.createElement("li", { style: {
26
+ display: "flex",
27
+ justifyContent: "space-between",
28
+ maxWidth: 250
29
+ } },
30
+ React.createElement(Typography.Link, { ellipsis: true, title: info.name, href: info.url, target: "_blank" },
31
+ React.createElement(LinkOutlined, null),
32
+ " ",
33
+ info.name),
34
+ React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => remove(i) },
35
+ React.createElement(DeleteOutlined, null))));
36
+ })));
37
+ }
38
+ return React.createElement(Empty, { imageStyle: { height: 30 }, image: Empty.PRESENTED_IMAGE_SIMPLE });
39
+ };
40
+ const SingleFileUpload = (props) => {
41
+ const [infos, setInfos] = useState([]);
42
+ const [open, setOpen] = useState(undefined);
43
+ const timeout = useRef();
44
+ const r = http.getRequest();
45
+ const action = useMemo(() => {
46
+ if (typeof props.action === "string") {
47
+ return /^http|^\/\//i.test(props.action)
48
+ ? buildURL(props.action, props.actionParams)
49
+ : buildURL(`${r.domain}${props.action}`, props.actionParams);
50
+ }
51
+ return props.action();
52
+ }, [props.actionParams]);
53
+ const handleChange = (info, type) => {
54
+ switch (info.file.status) {
55
+ case 'uploading':
56
+ Loading.show();
57
+ break;
58
+ case 'done':
59
+ Loading.hide();
60
+ const response = info.file.response;
61
+ const file = info.file;
62
+ if ((response && response.code === 200) || response.success) {
63
+ const tempObj = Object.assign({ name: file.name, url: response.data.url }, props.data);
64
+ const tempRes = infos.concat([]);
65
+ tempRes.push(tempObj);
66
+ setInfos(tempRes);
67
+ setOpen(true);
68
+ clearTimeout(timeout.current);
69
+ timeout.current = setTimeout(() => {
70
+ setOpen(undefined);
71
+ }, 3000);
72
+ props.onChange && props.onChange(tempRes);
73
+ }
74
+ else {
75
+ Toast.error({
76
+ mask: true,
77
+ title: response
78
+ ? `${file.name}-${response.msg}` || `${file.name}-${response.message}`
79
+ : `${file.name}-服务出错,文件上传失败`
80
+ });
81
+ }
82
+ break;
83
+ case 'error':
84
+ Toast.error({
85
+ mask: true,
86
+ title: info.file.response
87
+ ? `${info.file.name}-${info.file.response.msg}` || `${info.file.name}-${info.file.response.message}`
88
+ : `${info.file.name}-服务出错,文件上传失败`
89
+ });
90
+ props.onError && props.onError(info.file);
91
+ break;
92
+ default:
93
+ break;
94
+ }
95
+ };
96
+ const beforeUpload = useCallback((file) => {
97
+ return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
98
+ // const ary = ["jpg", "jpeg", "png", "gif"];
99
+ // if (ary.indexOf(file.type.toLowerCase().replace(/image\//g, "")) !== -1) {
100
+ // message.error("上传图片请使用 SingleImgUpload 组件");
101
+ // reject(new Error("上传图片请使用 SingleImgUpload 组件"));
102
+ // return;
103
+ // }
104
+ const fileExtension = file.name && file.name.split('.').pop().toLowerCase();
105
+ if (fileExtension && props.type.indexOf(fileExtension) === -1) {
106
+ message.error(`请上传 ${props.type} 格式的文件!`);
107
+ reject();
108
+ return;
109
+ }
110
+ resolve();
111
+ }));
112
+ }, []);
113
+ useEffect(() => {
114
+ if (props.value) {
115
+ setInfos(props.value);
116
+ }
117
+ }, [props.value]);
118
+ return (React.createElement(Space.Compact, { block: true },
119
+ React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, multiple: true, data: props.data, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, headers: props.headers, action: action, onChange: handleChange, showUploadList: false, onRemove: (e) => {
120
+ props.onRemove && props.onRemove(e);
121
+ }, maxCount: props.maxCount },
122
+ React.createElement(Button, { icon: props.icon ? React.createElement(UploadOutlined, null) : null }, props.buttonText)),
123
+ React.createElement(Popover, { destroyTooltipOnHide: true, open: open, placement: "right", trigger: "hover", title: "Uploaded", content: React.createElement(InfosRender, { infos: infos, setInfos: setInfos }) },
124
+ React.createElement(Button, { icon: React.createElement(EllipsisOutlined, null) }))));
125
+ };
126
+ SingleFileUpload.defaultProps = {
127
+ name: 'file',
128
+ openFileDialogOnClick: true,
129
+ icon: true,
130
+ data: {},
131
+ maxCount: 10,
132
+ headers: undefined,
133
+ buttonText: '点击上传',
134
+ 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',
135
+ style: {}
136
+ };
137
+ export default SingleFileUpload;
@@ -1,11 +1,15 @@
1
1
  import React from "react";
2
- import { UploadFile } from "antd/lib/upload/interface";
2
+ import type { UploadFile } from "antd/lib/upload/interface";
3
3
  interface IProps {
4
- action: string;
4
+ action: string | (() => string);
5
+ actionParams?: any;
5
6
  buttonText?: string;
6
7
  type?: string;
7
8
  name?: string;
9
+ i18n?: any;
10
+ headers?: any;
8
11
  value?: any;
12
+ data?: any;
9
13
  uploadRef?: any;
10
14
  onChange?: (url: string) => void;
11
15
  onDone?: (file: UploadFile, res: any) => void;
@@ -15,11 +15,15 @@ import Toast from "../../core/toast";
15
15
  import http from "../../helpers/http";
16
16
  const SingleFileUpload = (props) => {
17
17
  const r = http.getRequest();
18
- const [urlParams, setUrlParams] = useState({});
19
18
  const [fileUrl, setFileUrl] = useState('');
20
19
  const action = useMemo(() => {
21
- return /^http|^\/\//i.test(props.action) ? buildURL(props.action, urlParams) : buildURL(`${r.domain}${props.action}`, urlParams);
22
- }, [urlParams]);
20
+ if (typeof props.action === "string") {
21
+ return /^http|^\/\//i.test(props.action)
22
+ ? buildURL(props.action, props.actionParams)
23
+ : buildURL(`${r.domain}${props.action}`, props.actionParams);
24
+ }
25
+ return props.action();
26
+ }, [props.actionParams]);
23
27
  const handleChange = (info) => {
24
28
  // props.onChange && props.onChange(info.file);
25
29
  switch (info.file.status) {
@@ -79,7 +83,7 @@ const SingleFileUpload = (props) => {
79
83
  // setFileUrl(v);
80
84
  props.onChange && props.onChange(v);
81
85
  } }),
82
- React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, action: action, onChange: handleChange, showUploadList: false, onRemove: (e) => {
86
+ React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, headers: props.headers, action: action, onChange: handleChange, showUploadList: false, onRemove: (e) => {
83
87
  console.log(e);
84
88
  props.onRemove && props.onRemove(e);
85
89
  }, maxCount: 1 },
@@ -89,6 +93,8 @@ SingleFileUpload.defaultProps = {
89
93
  name: "file",
90
94
  openFileDialogOnClick: true,
91
95
  icon: true,
96
+ data: {},
97
+ actionParams: {},
92
98
  buttonText: "点击上传",
93
99
  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",
94
100
  style: {}
@@ -9,10 +9,15 @@ interface IOpts {
9
9
  h?: number;
10
10
  }
11
11
  interface IProps {
12
- action?: string;
12
+ action: string | (() => string);
13
+ actionParams?: any;
13
14
  name?: string;
15
+ i18n?: any;
14
16
  opts?: IOpts;
15
17
  value?: string;
18
+ buttonText?: string;
19
+ headers?: any;
20
+ data?: any;
16
21
  onChange?: any;
17
22
  gif?: boolean;
18
23
  disabled?: boolean;
@@ -17,12 +17,14 @@ const ImgUpload = (props) => {
17
17
  const r = http.getRequest();
18
18
  const [loading, setLoading] = useState(false);
19
19
  const [imageUrl, setImageUrl] = useState(props.value || "");
20
- const [urlParams, setUrlParams] = useState({});
21
- useEffect(() => {
22
- if (props.value) {
23
- setImageUrl(props.value);
20
+ const action = useMemo(() => {
21
+ if (typeof props.action === "string") {
22
+ return /^http|^\/\//i.test(props.action)
23
+ ? buildURL(props.action, props.actionParams)
24
+ : buildURL(`${r.domain}${props.action}`, props.actionParams);
24
25
  }
25
- }, [props.value]);
26
+ return props.action();
27
+ }, [props.actionParams]);
26
28
  const getBase64 = useCallback((imgFile) => {
27
29
  return new Promise((resolve) => {
28
30
  const reader = new FileReader();
@@ -110,18 +112,19 @@ const ImgUpload = (props) => {
110
112
  reject();
111
113
  return;
112
114
  }
113
- setUrlParams({ height: wh.h });
114
115
  resolve();
115
116
  }));
116
117
  }, []);
117
118
  const uploadButton = useMemo(() => (React.createElement("div", null,
118
119
  loading ? React.createElement(LoadingOutlined, null) : React.createElement(PlusOutlined, null),
119
- React.createElement("div", { style: { marginTop: 8 } }, "\u4E0A\u4F20\u56FE\u7247"))), [loading]);
120
- const action = useMemo(() => {
121
- return /^http|^\/\//i.test(props.action) ? buildURL(props.action, urlParams) : buildURL(`${r.domain}${props.action}`, urlParams);
122
- }, [urlParams]);
120
+ React.createElement("div", { style: { marginTop: 8 } }, props.buttonText))), [loading]);
121
+ useEffect(() => {
122
+ if (props.value) {
123
+ setImageUrl(props.value);
124
+ }
125
+ }, [props.value]);
123
126
  return (React.createElement(Space, null,
124
- React.createElement(Upload, { withCredentials: true, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }, imageUrl ? (React.createElement("div", { style: { position: "relative" } },
127
+ React.createElement(Upload, { withCredentials: true, beforeUpload: beforeUpload, name: props.name, headers: props.headers, disabled: props.disabled, listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }, imageUrl ? (React.createElement("div", { style: { position: "relative" } },
125
128
  React.createElement("span", { style: {
126
129
  position: "absolute",
127
130
  background: "#fff",
@@ -138,16 +141,21 @@ const ImgUpload = (props) => {
138
141
  React.createElement("img", { style: { width: "102px", height: "102px", objectFit: "contain" }, src: imageUrl }))) : (uploadButton)),
139
142
  React.createElement("div", null,
140
143
  React.createElement("p", null,
141
- "\u5927\u5C0F\uFF1A\u5C0F\u4E8E ",
144
+ props.i18n ? props.i18n.$t("global.size") : "大小",
145
+ "\uFF1A",
146
+ props.i18n ? props.i18n.$t("global.lt") : "小于",
147
+ " ",
142
148
  props.opts.size || 1,
143
149
  "MB"),
144
150
  React.createElement("p", null,
145
- "\u5C3A\u5BF8\uFF1A",
151
+ props.i18n ? props.i18n.$t("global.dimension") : "尺寸",
152
+ "\uFF1A",
146
153
  props.opts.w ? `${props.opts.w}px` : "n",
147
154
  " * ",
148
155
  props.opts.h ? `${props.opts.h}px` : "n"),
149
156
  React.createElement("p", null,
150
- "\u652F\u6301\uFF1Ajpg\u3001jpeg\u3001png",
157
+ props.i18n ? props.i18n.$t("global.support") : "支持",
158
+ "\uFF1Ajpg\u3001jpeg\u3001png",
151
159
  props.gif ? "、gif" : ""))));
152
160
  };
153
161
  ImgUpload.defaultProps = {
@@ -155,6 +163,9 @@ ImgUpload.defaultProps = {
155
163
  name: "file",
156
164
  value: "",
157
165
  gif: false,
166
+ buttonText: '上传图片',
167
+ data: {},
168
+ actionParams: {},
158
169
  opts: {
159
170
  size: 1
160
171
  }
package/lib/index.d.ts CHANGED
@@ -10,6 +10,9 @@ export { default as PhoneInput } from "./core/phone-input";
10
10
  export { default as RangePicker } from "./core/range-picker";
11
11
  export { default as SingleImgUpload } from "./core/single-img-upload";
12
12
  export { default as SingleFileUpload } from "./core/single-file-upload";
13
+ export { default as MultipleUpload } from "./core/multiple-upload";
14
+ export { default as FormLabel } from "./core/form.label";
15
+ export { default as FormList } from "./core/form.list";
13
16
  export { default as AsyncSelect } from "./core/async-select";
14
17
  export { default as AsyncTransfer } from "./core/async-transfer";
15
18
  export { default as TablePro } from "./core/table-pro";
package/lib/index.js CHANGED
@@ -10,6 +10,9 @@ export { default as PhoneInput } from "./core/phone-input";
10
10
  export { default as RangePicker } from "./core/range-picker";
11
11
  export { default as SingleImgUpload } from "./core/single-img-upload";
12
12
  export { default as SingleFileUpload } from "./core/single-file-upload";
13
+ export { default as MultipleUpload } from "./core/multiple-upload";
14
+ export { default as FormLabel } from "./core/form.label";
15
+ export { default as FormList } from "./core/form.list";
13
16
  export { default as AsyncSelect } from "./core/async-select";
14
17
  export { default as AsyncTransfer } from "./core/async-transfer";
15
18
  export { default as TablePro } from "./core/table-pro";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.2.28",
3
+ "version": "0.2.30",
4
4
  "author": "cxc",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -44,5 +44,5 @@
44
44
  "dependencies": {
45
45
  "react-quill": "^2.0.0"
46
46
  },
47
- "gitHead": "2a3afebdf083c3afa505959cf0a35093c0383fa2"
47
+ "gitHead": "1f4c0c8bd91160a2625a5db93d9247a7e1fc385e"
48
48
  }