ztxkui 4.2.8 → 4.2.10

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.
@@ -61,6 +61,30 @@ import { EditableContext } from './table-enhance-row';
61
61
  import { Form, Input, InputNumber, Select, message } from '../../index';
62
62
  import { ERROR_TD_CLASSNAME } from './index';
63
63
  import { getInnerIndex } from './hooks/useInnerPagination';
64
+ import { exactRound } from 'ztxkutils/dist/tools';
65
+ /**
66
+ * 数据转换 将粘贴过来的数据格式化处理
67
+ */
68
+ function transformData(data, config) {
69
+ var newData = data;
70
+ if (!config) {
71
+ return newData;
72
+ }
73
+ var editableConfig = config.editableConfig;
74
+ if (!editableConfig) {
75
+ return newData;
76
+ }
77
+ var type = editableConfig.type, precision = editableConfig.precision;
78
+ if (type === 'inputNumber') {
79
+ // 先转换成符合规则的数字
80
+ newData = isNaN(Number(newData))
81
+ ? newData
82
+ : typeof precision === 'number'
83
+ ? Number(exactRound(newData, precision))
84
+ : Number(newData);
85
+ }
86
+ return newData;
87
+ }
64
88
  var TableEnhanceCell = memo(function (_a) {
65
89
  var title = _a.title, index = _a.index, editable = _a.editable, editableConfig = _a.editableConfig, children = _a.children, dataIndex = _a.dataIndex, record = _a.record, handleSave = _a.handleSave, onTableChange = _a.onTableChange, columns = _a.columns, currentpage = _a.currentpage, restProps = __rest(_a, ["title", "index", "editable", "editableConfig", "children", "dataIndex", "record", "handleSave", "onTableChange", "columns", "currentpage"]);
66
90
  var form = useContext(EditableContext);
@@ -164,16 +188,23 @@ var TableEnhanceCell = memo(function (_a) {
164
188
  var result = {};
165
189
  resultItemList.forEach(function (resultItem, index) {
166
190
  var _a;
191
+ var config = null;
192
+ try {
193
+ config = newColumns_1[currentColumnIndex_1 + index];
194
+ }
195
+ catch (err) {
196
+ console.error("table paste error", err);
197
+ }
167
198
  if (resultItem === '' || resultItem == null) {
168
199
  return;
169
200
  }
170
201
  if (index === 0) {
171
- result[dataIndex] = resultItem;
202
+ result[dataIndex] = transformData(resultItem, config);
172
203
  }
173
204
  else {
174
205
  var key = (_a = newColumns_1[currentColumnIndex_1 + index]) === null || _a === void 0 ? void 0 : _a.dataIndex;
175
206
  if (key) {
176
- result[key] = resultItem;
207
+ result[key] = transformData(resultItem, config);
177
208
  }
178
209
  }
179
210
  });
@@ -70,6 +70,7 @@ import { downloadFileCallBack, downloadPublicFile, previewFile, batchPreviewFile
70
70
  import { transformFileSize, dangerouslySetXss } from 'ztxkutils/dist/tools';
71
71
  import { MAX_PREVIEW_FILE_SIZE } from '../utils/constants';
72
72
  import { isImage } from '../utils/upload';
73
+ import { getFileId } from './upload';
73
74
  var UploadTable = function (_a) {
74
75
  var fileList = _a.fileList, action = _a.action, headers = _a.headers, authToken = _a.authToken, method = _a.method, apiBaseUrl = _a.apiBaseUrl, uploadUser = _a.uploadUser, _b = _a.fileBaseUrl, fileBaseUrl = _b === void 0 ? '' : _b, onDelete = _a.onDelete, onUpload = _a.onUpload, showDeleteBtn = _a.showDeleteBtn, isAutoDelete = _a.isAutoDelete, onDownLoadCallbackBefore = _a.onDownLoadCallbackBefore, showDownloadBtn = _a.showDownloadBtn, onDownLoadCallbackAfter = _a.onDownLoadCallbackAfter, onPreviewCallbackBefore = _a.onPreviewCallbackBefore, showPreviewBtn = _a.showPreviewBtn, isPublic = _a.isPublic, data = _a.data, _c = _a.startColumns, startColumns = _c === void 0 ? [] : _c, _d = _a.otherColumns, otherColumns = _d === void 0 ? [] : _d, showUploadBtn = _a.showUploadBtn, rowSelection = _a.rowSelection, uploadTableRef = _a.uploadTableRef, tableRestProps = _a.tableRestProps, privateTableRef = _a.privateTableRef;
75
76
  var _e = useState([]), dataSource = _e[0], setDataSource = _e[1];
@@ -463,8 +464,9 @@ var UploadTable = function (_a) {
463
464
  useEffect(function () {
464
465
  if (Array.isArray(fileList)) {
465
466
  var newDataSource = fileList.map(function (file, index) {
466
- var _a, _b, _c, _d, _e, _f, _g, _h;
467
+ var _a, _b, _c, _d, _e, _f, _g;
467
468
  var name = file.name, fileName = file.fileName, percent = file.percent, size = file.size, fileSize = file.fileSize, status = file.status, response = file.response, originFileObj = file.originFileObj, updateTime = file.updateTime, createUserName = file.createUserName, restItem = __rest(file, ["name", "fileName", "percent", "size", "fileSize", "status", "response", "originFileObj", "updateTime", "createUserName"]);
469
+ var attachId = getFileId(file);
468
470
  // if (response && response.data && !response.data?.createTime) {
469
471
  // response.data.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
470
472
  // }
@@ -486,8 +488,10 @@ var UploadTable = function (_a) {
486
488
  ? response.data.createUserName
487
489
  : createUserName
488
490
  ? createUserName
489
- : uploadUser, fileId: response ? (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.attachId : null, fileUrl: response ? (_f = response === null || response === void 0 ? void 0 : response.data) === null || _f === void 0 ? void 0 : _f.link : null, originFileObj: originFileObj, serverFileName: response
490
- ? ((_g = response.data) === null || _g === void 0 ? void 0 : _g.name) || ((_h = response.data) === null || _h === void 0 ? void 0 : _h.originalName)
491
+ : uploadUser,
492
+ // fileId: response ? response?.data?.attachId : null,
493
+ fileId: attachId, fileUrl: response ? (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.link : null, originFileObj: originFileObj, serverFileName: response
494
+ ? ((_f = response.data) === null || _f === void 0 ? void 0 : _f.name) || ((_g = response.data) === null || _g === void 0 ? void 0 : _g.originalName)
491
495
  : null }, restItem);
492
496
  });
493
497
  if (fileList.every(function (item) { return item.status === 'done' || item.status === 'error'; })) {
@@ -80,5 +80,7 @@ export interface IProps extends UploadProps {
80
80
  /**表格方法 */
81
81
  tableRestProps?: any;
82
82
  }
83
+ export declare function getFileId(item: any): any;
84
+ export declare function getFileSize(item: any): any;
83
85
  declare const Upload: React.FC<IProps>;
84
86
  export default Upload;
@@ -86,6 +86,33 @@ var _accept = [
86
86
  '.ppt',
87
87
  ];
88
88
  var statusArr = ['error', 'success', 'done', 'uploading', 'removed'];
89
+ export function getFileId(item) {
90
+ var _a, _b;
91
+ var _c = item || {}, response = _c.response, attachId = _c.attachId, id = _c.id;
92
+ if (attachId && attachId !== 'null' && attachId !== 'undefined') {
93
+ return attachId;
94
+ }
95
+ if (response && ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.attachId)) {
96
+ return (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.attachId;
97
+ }
98
+ if (id) {
99
+ return id;
100
+ }
101
+ return null;
102
+ }
103
+ export function getFileSize(item) {
104
+ var _a = item || {}, attachSize = _a.attachSize, fileSize = _a.fileSize, size = _a.size;
105
+ if (fileSize) {
106
+ return fileSize;
107
+ }
108
+ if (size) {
109
+ return size;
110
+ }
111
+ if (attachSize) {
112
+ return attachSize;
113
+ }
114
+ return null;
115
+ }
89
116
  var Upload = function (props) {
90
117
  var children = props.children, className = props.className, _a = props.showTip, showTip = _a === void 0 ? true : _a, _b = props.showUploadBtn, showUploadBtn = _b === void 0 ? true : _b, _c = props.showDeleteBtn, showDeleteBtn = _c === void 0 ? true : _c, onDownLoadCallbackBefore = props.onDownLoadCallbackBefore, _d = props.showDownloadBtn, showDownloadBtn = _d === void 0 ? true : _d, onDownLoadCallbackAfter = props.onDownLoadCallbackAfter, _e = props.showPreviewBtn, showPreviewBtn = _e === void 0 ? true : _e, onPreviewCallbackBefore = props.onPreviewCallbackBefore, _f = props.showTable, showTable = _f === void 0 ? true : _f, showUploadList = props.showUploadList, onChange = props.onChange, beforeUpload = props.beforeUpload, multiple = props.multiple, ztAccept = props.ztAccept, ztShowTipText = props.ztShowTipText, maxCount = props.maxCount, maxSize = props.maxSize, maxSizeStr = props.maxSizeStr, action = props.action, headers = props.headers, method = props.method, uploadUser = props.uploadUser, originFileList = props.originFileList, callback = props.callback, onDeleteCallback = props.onDeleteCallback, isAutoDelete = props.isAutoDelete, apiBaseUrl = props.apiBaseUrl, _g = props.fileBaseUrl, fileBaseUrl = _g === void 0 ? '' : _g, fileBtnText = props.fileBtnText, data = props.data, authToken = props.authToken, listType = props.listType, isPublic = props.isPublic, startColumns = props.startColumns, otherColumns = props.otherColumns, _h = props.isDirect, isDirect = _h === void 0 ? false : _h, upload = props.upload, rowSelection = props.rowSelection, uploadTableRef = props.uploadTableRef, tableRestProps = props.tableRestProps, showAllDeleteBtn = props.showAllDeleteBtn, showAllDownloadBtn = props.showAllDownloadBtn, allDeleteCallback = props.allDeleteCallback, allDownloadCallback = props.allDownloadCallback, batchDownloadZipName = props.batchDownloadZipName, restProps = __rest(props, ["children", "className", "showTip", "showUploadBtn", "showDeleteBtn", "onDownLoadCallbackBefore", "showDownloadBtn", "onDownLoadCallbackAfter", "showPreviewBtn", "onPreviewCallbackBefore", "showTable", "showUploadList", "onChange", "beforeUpload", "multiple", "ztAccept", "ztShowTipText", "maxCount", "maxSize", "maxSizeStr", "action", "headers", "method", "uploadUser", "originFileList", "callback", "onDeleteCallback", "isAutoDelete", "apiBaseUrl", "fileBaseUrl", "fileBtnText", "data", "authToken", "listType", "isPublic", "startColumns", "otherColumns", "isDirect", "upload", "rowSelection", "uploadTableRef", "tableRestProps", "showAllDeleteBtn", "showAllDownloadBtn", "allDeleteCallback", "allDownloadCallback", "batchDownloadZipName"]);
91
118
  var _j = useState(originFileList || []), fileList = _j[0], setFileList = _j[1];
@@ -149,15 +176,22 @@ var Upload = function (props) {
149
176
  if (Array.isArray(originFileList)) {
150
177
  if (listType === 'text') {
151
178
  setFileList(originFileList.map(function (item) {
152
- var _a, _b, _c, _d;
153
- var attachId = item.attachId, name = item.name, attachName = item.attachName, fileSize = item.fileSize, size = item.size, response = item.response, percent = item.percent, status = item.status;
154
- return __assign(__assign({}, item), { uid: attachId ? attachId : (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.attachId, size: fileSize ? fileSize : size, name: name
179
+ var _a, _b, _c;
180
+ var
181
+ // attachId,
182
+ name = item.name, attachName = item.attachName,
183
+ // fileSize,
184
+ // size,
185
+ response = item.response, percent = item.percent, status = item.status;
186
+ var attachId = getFileId(item);
187
+ var attachSize = getFileSize(item);
188
+ return __assign(__assign({}, item), { uid: attachId, size: attachSize, name: name
155
189
  ? name
156
190
  : attachName
157
191
  ? attachName
158
- : ((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.attachName)
159
- ? (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.attachName
160
- : (_d = response === null || response === void 0 ? void 0 : response.data) === null || _d === void 0 ? void 0 : _d.originalName, percent: typeof percent === 'number' ? percent : 100, status: statusArr.includes(status) ? status : 'done', response: response
192
+ : ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.attachName)
193
+ ? (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.attachName
194
+ : (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.originalName, percent: typeof percent === 'number' ? percent : 100, status: statusArr.includes(status) ? status : 'done', response: response
161
195
  ? response
162
196
  : {
163
197
  code: 200,
@@ -169,23 +203,32 @@ var Upload = function (props) {
169
203
  }
170
204
  else {
171
205
  setFileList(originFileList.map(function (item) {
172
- var _a, _b, _c, _d, _e;
173
- var attachId = item.attachId, name = item.name, attachName = item.attachName, fileSize = item.fileSize, size = item.size, response = item.response, percent = item.percent, status = item.status;
174
- var fileId = response ? (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.attachId : null;
175
- return __assign(__assign({}, item), { uid: attachId ? attachId : (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.attachId, size: fileSize ? fileSize : size, name: name
206
+ var _a, _b, _c, _d;
207
+ var
208
+ // attachId,
209
+ name = item.name, attachName = item.attachName,
210
+ // fileSize,
211
+ // size,
212
+ response = item.response, percent = item.percent, status = item.status;
213
+ var attachId = getFileId(item);
214
+ var attachSize = getFileSize(item);
215
+ // const fileId = response ? response?.data?.attachId : null;
216
+ return __assign(__assign({}, item), { uid: attachId ? attachId : (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.attachId,
217
+ // size: fileSize ? fileSize : size,
218
+ size: attachSize, name: name
176
219
  ? name
177
220
  : attachName
178
221
  ? attachName
179
- : ((_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.attachName)
180
- ? (_d = response === null || response === void 0 ? void 0 : response.data) === null || _d === void 0 ? void 0 : _d.attachName
181
- : (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.originalName, percent: typeof percent === 'number' ? percent : 100, status: statusArr.includes(status) ? status : 'done', response: response
222
+ : ((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.attachName)
223
+ ? (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.attachName
224
+ : (_d = response === null || response === void 0 ? void 0 : response.data) === null || _d === void 0 ? void 0 : _d.originalName, percent: typeof percent === 'number' ? percent : 100, status: statusArr.includes(status) ? status : 'done', response: response
182
225
  ? response
183
226
  : {
184
227
  code: 200,
185
228
  data: {
186
229
  attachId: attachId,
187
230
  },
188
- }, thumbUrl: createThumbnailUrl(apiBaseUrl, fileId, 1) });
231
+ }, thumbUrl: createThumbnailUrl(apiBaseUrl, attachId, 1) });
189
232
  }));
190
233
  }
191
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "4.2.8",
3
+ "version": "4.2.10",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",