@ecoding/components.antd 0.2.10 → 0.2.12

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.
@@ -3,7 +3,7 @@ import type { SelectProps } from "antd/lib/select";
3
3
  interface IFace {
4
4
  url: string;
5
5
  paramKey?: string;
6
- paramValue?: string;
6
+ paramValue?: string | number;
7
7
  params?: any;
8
8
  cache?: boolean;
9
9
  method?: string;
@@ -5,6 +5,7 @@ interface IProps {
5
5
  buttonText?: string;
6
6
  type?: string;
7
7
  name?: string;
8
+ value?: any;
8
9
  uploadRef?: any;
9
10
  onChange?: (file: UploadFile) => void;
10
11
  onDone?: (file: UploadFile, res: any) => void;
@@ -7,8 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import React, { useCallback, useMemo, useState } from "react";
11
- import { Upload, message, Button } from "antd";
10
+ import React, { useCallback, useMemo, useState, useEffect } from "react";
11
+ import { Upload, message, Button, Input, Space } from "antd";
12
12
  import { UploadOutlined } from "@ant-design/icons";
13
13
  import { buildURL } from "@ecoding/helper.url";
14
14
  import Toast from "../../core/toast";
@@ -16,10 +16,12 @@ import http from "../../helpers/http";
16
16
  const SingleFileUpload = (props) => {
17
17
  const r = http.getRequest();
18
18
  const [urlParams, setUrlParams] = useState({});
19
+ const [fileUrl, setFileUrl] = useState('');
19
20
  const action = useMemo(() => {
20
21
  return /^http|^\/\//i.test(props.action) ? buildURL(props.action, urlParams) : buildURL(`${r.domain}${props.action}`, urlParams);
21
22
  }, [urlParams]);
22
23
  const handleChange = (info) => {
24
+ var _a, _b;
23
25
  props.onChange && props.onChange(info.file);
24
26
  switch (info.file.status) {
25
27
  case "uploading":
@@ -27,6 +29,7 @@ const SingleFileUpload = (props) => {
27
29
  case "done":
28
30
  const response = info.file.response;
29
31
  if ((response && response.code === 200) || response.success) {
32
+ setFileUrl(((_b = (_a = info.file.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.url) || "");
30
33
  props.onDone && props.onDone(info.file, info.file.response.data);
31
34
  }
32
35
  else {
@@ -64,18 +67,25 @@ const SingleFileUpload = (props) => {
64
67
  resolve();
65
68
  }));
66
69
  }, []);
67
- return (React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, action: action, onChange: handleChange, onRemove: (e) => {
68
- console.log(e);
69
- props.onRemove && props.onRemove(e);
70
- }, maxCount: 1 },
71
- React.createElement(Button, { icon: props.icon ? React.createElement(UploadOutlined, null) : null }, props.buttonText)));
70
+ useEffect(() => {
71
+ if (typeof props.value === "string") {
72
+ setFileUrl(props.value);
73
+ }
74
+ }, [props.value]);
75
+ return (React.createElement(Space.Compact, { block: true },
76
+ React.createElement(Input, { value: fileUrl }),
77
+ 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) => {
78
+ console.log(e);
79
+ props.onRemove && props.onRemove(e);
80
+ }, maxCount: 1 },
81
+ React.createElement(Button, { icon: props.icon ? React.createElement(UploadOutlined, null) : null }, props.buttonText))));
72
82
  };
73
83
  SingleFileUpload.defaultProps = {
74
84
  name: "file",
75
85
  openFileDialogOnClick: true,
76
86
  icon: true,
77
87
  buttonText: "点击上传",
78
- type: "xls, xlsx, txt",
88
+ 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",
79
89
  style: {}
80
90
  };
81
91
  export default SingleFileUpload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
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": "88e2b7a76faaa0b2552e667609cf9a20636eccac"
47
+ "gitHead": "40c7fd1769a29e3a3998f7c4dcb4db553aced298"
48
48
  }