ronds-metadata 1.1.69 → 1.1.71

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.
@@ -1,5 +1,7 @@
1
1
  interface IFileViewProps {
2
- path: string;
2
+ path?: string;
3
+ limit?: number;
4
+ data?: any[];
3
5
  }
4
6
  declare const FileView: (props: IFileViewProps) => JSX.Element;
5
7
  export default FileView;
@@ -1,5 +1,5 @@
1
- import "antd/es/empty/style";
2
- import _Empty from "antd/es/empty";
1
+ import "antd/es/spin/style";
2
+ import _Spin from "antd/es/spin";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
5
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
@@ -9,7 +9,10 @@ import { ReactJexcel } from 'react-jexcel';
9
9
  import * as XLSX from 'xlsx';
10
10
 
11
11
  var FileView = function FileView(props) {
12
- var path = props.path;
12
+ var path = props.path,
13
+ data = props.data,
14
+ _props$limit = props.limit,
15
+ limit = _props$limit === void 0 ? 1000 : _props$limit;
13
16
  var ref = React.useRef(null);
14
17
  var firstLoadRef = React.useRef(true);
15
18
 
@@ -31,7 +34,7 @@ var FileView = function FileView(props) {
31
34
  _title = f.map(function (it) {
32
35
  return {
33
36
  title: it,
34
- width: 150,
37
+ width: 100,
35
38
  align: 'left'
36
39
  };
37
40
  });
@@ -43,10 +46,14 @@ var FileView = function FileView(props) {
43
46
  });
44
47
 
45
48
  _value.push(arr);
49
+
50
+ if (i === limit - 1) return "break";
46
51
  };
47
52
 
48
53
  for (var i = 0; i < data.length; i++) {
49
- _loop(i);
54
+ var _ret = _loop(i);
55
+
56
+ if (_ret === "break") break;
50
57
  }
51
58
 
52
59
  setValue([].concat(_value));
@@ -74,25 +81,41 @@ var FileView = function FileView(props) {
74
81
  case 6:
75
82
  blob = _context.sent;
76
83
  fileReader = new FileReader();
77
- fileReader.readAsBinaryString(blob); //二进制
84
+ // blob.type = 'text/csv;charset=utf-8;';
85
+ // const bl = new Blob([blob], { type: 'text/csv;charset=utf-8;' });
86
+ // console.log('blob2', bl);
87
+ //二进制
88
+ // fileReader.readAsBinaryString(blob);
89
+ fileReader.readAsArrayBuffer(blob);
78
90
 
79
91
  fileReader.onload = function (event) {
80
92
  try {
81
- var data = [];
82
- var result = event.target.result; // 以二进制流方式读取得到整份excel表格对象
93
+ var _data = [];
94
+ var binary = ''; // 以二进制流方式读取得到整份excel表格对象
95
+
96
+ var result = event.target.result;
97
+ var bytes = new Uint8Array(result);
98
+
99
+ for (var i = 0; i < bytes.byteLength; i++) {
100
+ binary += String.fromCharCode(bytes[i]);
101
+ }
83
102
 
84
- var workbook = XLSX.read(result, {
85
- type: 'binary'
86
- }); // 遍历每张工作表进行读取(这里默认只读取第一张表)
103
+ // 遍历每张工作表进行读取(这里默认只读取第一张表)
104
+ var workbook = XLSX.read(binary, {
105
+ type: 'binary',
106
+ codepage: 936
107
+ });
87
108
 
88
109
  for (var sheet in workbook.Sheets) {
89
110
  if (workbook.Sheets.hasOwnProperty(sheet)) {
90
111
  // 利用 sheet_to_json 方法将 excel 转成 json 数据
91
- data = data.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet])); // break; // 如果只取第一张表,就取消注释这行
112
+ _data = _data.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet])); // 如果只取第一张表,就取消注释这行
113
+
114
+ break;
92
115
  }
93
116
  }
94
117
 
95
- processDataToExcel(data);
118
+ processDataToExcel(_data);
96
119
  } catch (e) {
97
120
  return;
98
121
  }
@@ -110,9 +133,14 @@ var FileView = function FileView(props) {
110
133
  getFileData();
111
134
  }
112
135
  }, [getFileData, path]);
136
+ React.useEffect(function () {
137
+ if (data && firstLoadRef.current) {
138
+ processDataToExcel(data);
139
+ }
140
+ }, [getFileData, data]);
113
141
 
114
142
  if (!value) {
115
- return /*#__PURE__*/React.createElement(_Empty, null);
143
+ return /*#__PURE__*/React.createElement(_Spin, null);
116
144
  }
117
145
 
118
146
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ReactJexcel, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.1.69",
4
+ "version": "1.1.71",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",
@@ -44,6 +44,7 @@
44
44
  "babel-plugin-transform-remove-console": "^6.9.4",
45
45
  "bl": "^5.0.0",
46
46
  "codemirror": "^5.63.0",
47
+ "codepage": "^1.15.0",
47
48
  "github-markdown-css": "^5.1.0",
48
49
  "immer": "^9.0.14",
49
50
  "lodash": "^4.17.21",