form-driver 0.3.0 → 0.3.2

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.
package/es/m3.js CHANGED
@@ -20518,10 +20518,12 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20518
20518
  fileListStatus = _this$state.fileListStatus,
20519
20519
  resList = _this$state.resList;
20520
20520
  return _this._client.multipartUpload(name, file, config).then(function (res) {
20521
- console.log('this._client.multipartUpload: result:', res); // 单个上传成功, 记录了到结果
20521
+ console.log('this._client.multipartUpload: result:', res);
20522
+ console.log('this._client.multipartUpload: file:', file); // 单个上传成功, 记录了到结果
20522
20523
 
20523
20524
  _this.changeFileList([].concat(resList, [{
20524
20525
  uid: file.uid,
20526
+ size: file.size,
20525
20527
  name: file.name,
20526
20528
  keyPath: res.name
20527
20529
  }]));
@@ -20607,6 +20609,9 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20607
20609
  srcFormat: function srcFormat(src) {
20608
20610
  return src;
20609
20611
  },
20612
+ maxAmount: 50,
20613
+ maxSize: 1000,
20614
+ checkSame: false,
20610
20615
  multipartUploadConf: {
20611
20616
  parallel: 3,
20612
20617
  partSize: 1024 * 1024 * 2,
@@ -20666,6 +20671,8 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20666
20671
  multipartUploadConf = _this$options.multipartUploadConf,
20667
20672
  maxSize = _this$options.maxSize,
20668
20673
  maxAmount = _this$options.maxAmount;
20674
+ _this$options.showSize;
20675
+ var checkSame = _this$options.checkSame;
20669
20676
  var _this$state2 = this.state,
20670
20677
  loading = _this$state2.loading,
20671
20678
  fileListStatus = _this$state2.fileListStatus,
@@ -20710,8 +20717,14 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20710
20717
  return false;
20711
20718
  }
20712
20719
 
20720
+ if (checkSame && resList.findIndex(function (e) {
20721
+ return e.name == file.name;
20722
+ }) >= 0) {
20723
+ message.error("\u5B58\u5728\u540C\u540D\u6587\u4EF6\uFF0C\u65E0\u6CD5\u4E0A\u4F20\u8BE5\u6587\u4EF6");
20724
+ return false;
20725
+ }
20726
+
20713
20727
  _this3.setState({
20714
- fileList: fileList,
20715
20728
  fileListStatus: fileList.map(function (item) {
20716
20729
  return {
20717
20730
  file: item,
@@ -20752,7 +20765,6 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20752
20765
  _this3.cancleUpload();
20753
20766
 
20754
20767
  _this3.setState({
20755
- fileList: [],
20756
20768
  fileListStatus: [],
20757
20769
  attachmentVisible: false
20758
20770
  });
@@ -20760,7 +20772,6 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20760
20772
  });
20761
20773
  } else {
20762
20774
  _this3.setState({
20763
- fileList: [],
20764
20775
  fileListStatus: [],
20765
20776
  attachmentVisible: false
20766
20777
  });
@@ -20849,6 +20860,21 @@ var OssUploadType = _.assign({}, EmtpyType, {
20849
20860
  }
20850
20861
  });
20851
20862
 
20863
+ function bytesToSize(bytes, fixNum) {
20864
+ if (fixNum === void 0) {
20865
+ fixNum = 1;
20866
+ }
20867
+
20868
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
20869
+ var i = Math.floor(Math.log(bytes) / Math.log(1024));
20870
+
20871
+ if (sizes[i]) {
20872
+ return (bytes / Math.pow(1024, i)).toFixed(fixNum) + ' ' + sizes[i];
20873
+ } else {
20874
+ return '';
20875
+ }
20876
+ }
20877
+
20852
20878
  var OssUploadViewer = /*#__PURE__*/function (_BaseViewer) {
20853
20879
  _inheritsLoose(OssUploadViewer, _BaseViewer);
20854
20880
 
@@ -20866,7 +20892,7 @@ var OssUploadViewer = /*#__PURE__*/function (_BaseViewer) {
20866
20892
  }, /*#__PURE__*/React.createElement("a", {
20867
20893
  target: '_blank',
20868
20894
  href: i.url
20869
- }, i.name));
20895
+ }, i.name), " ", i.size ? /*#__PURE__*/React.createElement("span", null, " ", bytesToSize(i.size)) : "", " ");
20870
20896
  }));
20871
20897
  };
20872
20898
 
package/lib/m3.js CHANGED
@@ -20540,10 +20540,12 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20540
20540
  fileListStatus = _this$state.fileListStatus,
20541
20541
  resList = _this$state.resList;
20542
20542
  return _this._client.multipartUpload(name, file, config).then(function (res) {
20543
- console.log('this._client.multipartUpload: result:', res); // 单个上传成功, 记录了到结果
20543
+ console.log('this._client.multipartUpload: result:', res);
20544
+ console.log('this._client.multipartUpload: file:', file); // 单个上传成功, 记录了到结果
20544
20545
 
20545
20546
  _this.changeFileList([].concat(resList, [{
20546
20547
  uid: file.uid,
20548
+ size: file.size,
20547
20549
  name: file.name,
20548
20550
  keyPath: res.name
20549
20551
  }]));
@@ -20629,6 +20631,9 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20629
20631
  srcFormat: function srcFormat(src) {
20630
20632
  return src;
20631
20633
  },
20634
+ maxAmount: 50,
20635
+ maxSize: 1000,
20636
+ checkSame: false,
20632
20637
  multipartUploadConf: {
20633
20638
  parallel: 3,
20634
20639
  partSize: 1024 * 1024 * 2,
@@ -20688,6 +20693,8 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20688
20693
  multipartUploadConf = _this$options.multipartUploadConf,
20689
20694
  maxSize = _this$options.maxSize,
20690
20695
  maxAmount = _this$options.maxAmount;
20696
+ _this$options.showSize;
20697
+ var checkSame = _this$options.checkSame;
20691
20698
  var _this$state2 = this.state,
20692
20699
  loading = _this$state2.loading,
20693
20700
  fileListStatus = _this$state2.fileListStatus,
@@ -20732,8 +20739,14 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20732
20739
  return false;
20733
20740
  }
20734
20741
 
20742
+ if (checkSame && resList.findIndex(function (e) {
20743
+ return e.name == file.name;
20744
+ }) >= 0) {
20745
+ antd.message.error("\u5B58\u5728\u540C\u540D\u6587\u4EF6\uFF0C\u65E0\u6CD5\u4E0A\u4F20\u8BE5\u6587\u4EF6");
20746
+ return false;
20747
+ }
20748
+
20735
20749
  _this3.setState({
20736
- fileList: fileList,
20737
20750
  fileListStatus: fileList.map(function (item) {
20738
20751
  return {
20739
20752
  file: item,
@@ -20774,7 +20787,6 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20774
20787
  _this3.cancleUpload();
20775
20788
 
20776
20789
  _this3.setState({
20777
- fileList: [],
20778
20790
  fileListStatus: [],
20779
20791
  attachmentVisible: false
20780
20792
  });
@@ -20782,7 +20794,6 @@ var OssUpload$1 = /*#__PURE__*/function (_Viewer) {
20782
20794
  });
20783
20795
  } else {
20784
20796
  _this3.setState({
20785
- fileList: [],
20786
20797
  fileListStatus: [],
20787
20798
  attachmentVisible: false
20788
20799
  });
@@ -20871,6 +20882,21 @@ var OssUploadType = ___default["default"].assign({}, EmtpyType, {
20871
20882
  }
20872
20883
  });
20873
20884
 
20885
+ function bytesToSize(bytes, fixNum) {
20886
+ if (fixNum === void 0) {
20887
+ fixNum = 1;
20888
+ }
20889
+
20890
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
20891
+ var i = Math.floor(Math.log(bytes) / Math.log(1024));
20892
+
20893
+ if (sizes[i]) {
20894
+ return (bytes / Math.pow(1024, i)).toFixed(fixNum) + ' ' + sizes[i];
20895
+ } else {
20896
+ return '';
20897
+ }
20898
+ }
20899
+
20874
20900
  var OssUploadViewer = /*#__PURE__*/function (_BaseViewer) {
20875
20901
  _inheritsLoose__default["default"](OssUploadViewer, _BaseViewer);
20876
20902
 
@@ -20888,7 +20914,7 @@ var OssUploadViewer = /*#__PURE__*/function (_BaseViewer) {
20888
20914
  }, /*#__PURE__*/React__default["default"].createElement("a", {
20889
20915
  target: '_blank',
20890
20916
  href: i.url
20891
- }, i.name));
20917
+ }, i.name), " ", i.size ? /*#__PURE__*/React__default["default"].createElement("span", null, " ", bytesToSize(i.size)) : "", " ");
20892
20918
  }));
20893
20919
  };
20894
20920
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-driver",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "An efficient framework for creating forms.",
5
5
  "license": "MIT",
6
6
  "authors": [
@@ -5,7 +5,6 @@ import { CloseOutlined, CaretRightOutlined } from '@ant-design/icons';
5
5
  import { Ajax, Viewer } from "../../index";
6
6
  import './index.less';
7
7
 
8
-
9
8
  class OssUpload extends Viewer {
10
9
  constructor(p) {
11
10
  super(p);
@@ -25,6 +24,9 @@ class OssUpload extends Viewer {
25
24
  changeHandle: () => { },
26
25
  resFormat: res => res,
27
26
  srcFormat: src => src,
27
+ maxAmount: 50,
28
+ maxSize: 1000,
29
+ checkSame: false,
28
30
  multipartUploadConf: {
29
31
  parallel: 3,
30
32
  partSize: 1024 * 1024 * 2,
@@ -87,9 +89,11 @@ class OssUpload extends Viewer {
87
89
  return this._client.multipartUpload(name, file, config)
88
90
  .then(res => {
89
91
  console.log('this._client.multipartUpload: result:', res)
92
+ console.log('this._client.multipartUpload: file:', file)
90
93
  // 单个上传成功, 记录了到结果
91
94
  this.changeFileList([...resList, {
92
95
  uid: file.uid,
96
+ size: file.size,
93
97
  name: file.name,
94
98
  keyPath: res.name
95
99
  }]);
@@ -148,7 +152,7 @@ class OssUpload extends Viewer {
148
152
  }
149
153
 
150
154
  element() {
151
- const { multiple = false, accept = '', multipartUploadConf, maxSize, maxAmount } = this.options
155
+ const { multiple = false, accept = '', multipartUploadConf, maxSize, maxAmount, showSize = false, checkSame } = this.options
152
156
  const { loading, fileListStatus, keyPath, attachmentVisible, resList } = this.state
153
157
 
154
158
  // 上传配置
@@ -177,8 +181,11 @@ class OssUpload extends Viewer {
177
181
  message.error(`文件大小超过${maxSize}MB,请压缩后上传`);
178
182
  return false
179
183
  }
184
+ if (checkSame && resList.findIndex(e => e.name == file.name) >= 0) {
185
+ message.error(`存在同名文件,无法上传该文件`);
186
+ return false
187
+ }
180
188
  this.setState({
181
- fileList,
182
189
  fileListStatus: fileList.map(item => ({ file: item, count: 1, percent: 0 })),
183
190
  attachmentVisible: true,
184
191
  })
@@ -207,7 +214,6 @@ class OssUpload extends Viewer {
207
214
  onOk: () => {
208
215
  this.cancleUpload()
209
216
  this.setState({
210
- fileList: [],
211
217
  fileListStatus: [],
212
218
  attachmentVisible: false
213
219
  })
@@ -215,7 +221,6 @@ class OssUpload extends Viewer {
215
221
  })
216
222
  } else {
217
223
  this.setState({
218
- fileList: [],
219
224
  fileListStatus: [],
220
225
  attachmentVisible: false
221
226
  })
@@ -1,6 +1,17 @@
1
1
  import React from "react";
2
2
  import { BaseViewer } from "../../index";
3
3
 
4
+ // 字节友好展示
5
+ export function bytesToSize(bytes, fixNum = 1) {
6
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
7
+ var i = Math.floor(Math.log(bytes) / Math.log(1024));
8
+ if (sizes[i]) {
9
+ return (bytes / Math.pow(1024, i)).toFixed(fixNum) + ' ' + sizes[i];
10
+ } else {
11
+ return ''
12
+ }
13
+ }
14
+
4
15
  class OssUploadViewer extends BaseViewer {
5
16
  [x: string]: any;
6
17
  element() {
@@ -8,7 +19,7 @@ class OssUploadViewer extends BaseViewer {
8
19
  return <div>
9
20
  {
10
21
  arr.map(i => {
11
- return <div key={i.uid}><a target='_blank' href={i.url}>{i.name}</a></div>
22
+ return <div key={i.uid}><a target='_blank' href={i.url}>{i.name}</a> {i.size ? <span> {bytesToSize(i.size)}</span> : ""} </div>
12
23
  })
13
24
  }
14
25
  </div>
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { BaseViewer } from "../../index";
3
+ export declare function bytesToSize(bytes: any, fixNum?: number): string;
3
4
  declare class OssUploadViewer extends BaseViewer {
4
5
  [x: string]: any;
5
6
  element(): JSX.Element;