feffery_antd_components 0.1.7 → 0.1.8

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.
@@ -30,6 +30,7 @@ const AntdDraggerUpload = (props) => {
30
30
  multiple,
31
31
  directory,
32
32
  failedTooltipInfo,
33
+ listUploadTaskRecord,
33
34
  loading_state,
34
35
  setProps
35
36
  } = props;
@@ -37,7 +38,6 @@ const AntdDraggerUpload = (props) => {
37
38
  uploadId = uploadId || uuid;
38
39
 
39
40
  const [fileList, updateFileList] = useState([]);
40
- const [lastFileError, updateLastFileError] = useState(false);
41
41
 
42
42
  let uploadProps = {
43
43
  name: 'file',
@@ -55,86 +55,159 @@ const AntdDraggerUpload = (props) => {
55
55
  if (fileTypes.indexOf(file.name.split('.')[file.name.split('.').length - 1]) === -1) {
56
56
  message.error(`上传失败,${file.name} 文件格式不符合要求!`);
57
57
  }
58
- updateLastFileError(!sizeCheck || fileTypes.indexOf(file.name.split('.')[file.name.split('.').length - 1]) === -1)
58
+
59
59
  return sizeCheck && fileTypes.indexOf(file.name.split('.')[file.name.split('.').length - 1]) !== -1;
60
60
  }
61
61
 
62
- updateLastFileError(!sizeCheck)
63
62
  return sizeCheck;
64
63
  },
65
64
  onChange(info) {
66
65
 
67
- if (info.file.status === 'done') {
66
+ // 计算最近一次任务的子任务数量
67
+ let lastTaskCount
68
+ if (info.file.status === 'removed') {
69
+ lastTaskCount = 0
70
+ } else {
71
+ lastTaskCount = info.fileList.length - listUploadTaskRecord.length;
72
+ }
68
73
 
69
- // 检查是否为多文件上传模式
70
- if (multiple || directory) {
71
- // 检查上传列表中是否全部文件都已完成上传
72
- if (info.fileList.every(file => file.status === 'done')) {
73
- console.log(info.fileList)
74
- // 更新任务记录
75
- setProps({
76
- lastUploadTaskRecord: info.fileList.map(
77
- (file) => {
78
- return {
79
- fileName: file.name,
80
- fileSize: file.size,
81
- completeTimestamp: new Date().getTime(),
82
- taskStatus: 'success',
83
- taskId: uploadId
84
- }
74
+ // 当上传模式为multiple或directory时
75
+ if (multiple || directory) {
76
+ // 若当前事件为removed
77
+ if (info.file.status === 'removed') {
78
+
79
+ // 更新任务记录
80
+ setProps({
81
+ listUploadTaskRecord: info.fileList.map(
82
+ (file) => {
83
+ return {
84
+ fileName: file.name,
85
+ fileSize: file.size,
86
+ completeTimestamp: new Date().getTime(),
87
+ taskStatus: file.status === 'done' ? 'success' : 'failed',
88
+ taskId: uploadId
85
89
  }
86
- )
87
- })
88
- }
90
+ }
91
+ )
92
+ })
89
93
  } else {
94
+ // 其他常规事件
95
+ // 判断此次任务所有文件是否已上传结束(done或error)
96
+ if (info.fileList.slice(-lastTaskCount).every(file => file.status !== 'uploading')) {
97
+
98
+ if (info.fileList.slice(-lastTaskCount).every(file => !file.status)) {
99
+
100
+ } else {
101
+ if (lastTaskCount > 0) {
102
+
103
+ // 更新任务记录
104
+ setProps({
105
+ lastUploadTaskRecord: info.fileList.slice(-lastTaskCount).map(
106
+ (file) => {
107
+ return {
108
+ fileName: file.name,
109
+ fileSize: file.size,
110
+ completeTimestamp: new Date().getTime(),
111
+ taskStatus: file.status === 'done' ? 'success' : 'failed',
112
+ taskId: uploadId
113
+ }
114
+ }
115
+ ),
116
+ listUploadTaskRecord: info.fileList.map(
117
+ (file) => {
118
+ return {
119
+ fileName: file.name,
120
+ fileSize: file.size,
121
+ completeTimestamp: new Date().getTime(),
122
+ taskStatus: file.status === 'done' ? 'success' : 'failed',
123
+ taskId: uploadId
124
+ }
125
+ }
126
+ )
127
+ })
128
+ }
129
+ }
130
+
131
+ }
132
+
133
+ }
134
+
135
+ } else {
136
+ // 单文件上传模式
137
+ // 若当前事件为removed
138
+ if (info.file.status === 'removed') {
139
+
90
140
  // 更新任务记录
141
+ setProps({
142
+ listUploadTaskRecord: info.fileList.map(
143
+ (file) => {
144
+ return {
145
+ fileName: file.name,
146
+ fileSize: file.size,
147
+ completeTimestamp: new Date().getTime(),
148
+ taskStatus: file.status === 'done' ? 'success' : 'failed',
149
+ taskId: uploadId
150
+ }
151
+ }
152
+ )
153
+ })
154
+ } else if (info.file.status === 'done' || info.file.status === 'error' || !info.file.status) {
91
155
  setProps({
92
156
  lastUploadTaskRecord: {
93
157
  fileName: info.file.name,
94
158
  fileSize: info.file.size,
95
159
  completeTimestamp: new Date().getTime(),
96
- taskStatus: 'success',
160
+ taskStatus: info.file.status === 'done' ? 'success' : 'failed',
97
161
  taskId: uploadId
98
- }
162
+ },
163
+ listUploadTaskRecord: info.fileList.map(
164
+ (file) => {
165
+ return {
166
+ fileName: file.name,
167
+ fileSize: file.size,
168
+ completeTimestamp: new Date().getTime(),
169
+ taskStatus: file.status === 'done' ? 'success' : 'failed',
170
+ taskId: uploadId
171
+ }
172
+ }
173
+ )
99
174
  })
100
175
  }
176
+ }
177
+
178
+ if (info.file.status === 'done') {
101
179
  message.success(`${info.file.name} 上传成功!`);
102
180
  } else if (info.file.status === 'error') {
103
-
104
- // 更新任务记录
105
- setProps({
106
- lastUploadTaskRecord: {
107
- fileName: info.file.name,
108
- fileSize: info.file.size,
109
- completeTimestamp: new Date().getTime(),
110
- taskStatus: 'failed'
111
- }
112
- })
113
181
  message.error(`${info.file.name} 上传失败!`);
114
182
  }
115
183
 
116
- if (lastFileError && info.fileList.length !== 0) {
117
- info.fileList[info.fileList.length - 1].status = 'error'
118
184
 
119
- updateLastFileError(false)
185
+ // 获取当前上传文件列表
186
+ let _fileList = [...info.fileList];
187
+
188
+ // 是否限制上传记录列表最大数量
189
+ if (fileListMaxLength) {
190
+ _fileList = _fileList.slice(-fileListMaxLength);
120
191
  }
121
192
 
122
- info.fileList = info.fileList.map(
123
- item => {
124
- if (item.status === 'error') {
125
- item.response = failedTooltipInfo ? failedTooltipInfo : '上传失败'
126
- }
127
- return item
128
- }
129
- )
193
+ if (lastTaskCount !== 0) {
194
+ _fileList = _fileList.slice(0, _fileList.length - lastTaskCount)
195
+ .concat(
196
+ _fileList.slice(-lastTaskCount).map(
197
+ item => {
198
+ if (item.status === 'error' || !item.status) {
130
199
 
131
- // 基于fileListMaxLength参数设置,对fileList状态进行更新
132
- if (fileListMaxLength) {
133
- updateFileList(info.fileList.slice(-fileListMaxLength))
134
- } else {
135
- updateFileList(info.fileList)
200
+ item.status = 'error'
201
+ item.response = failedTooltipInfo ? failedTooltipInfo : '上传失败'
202
+ }
203
+ return item
204
+ }
205
+ )
206
+ )
136
207
  }
137
- },
208
+
209
+ updateFileList(_fileList)
210
+ }
138
211
  };
139
212
 
140
213
  // 添加accept参数
@@ -151,6 +224,7 @@ const AntdDraggerUpload = (props) => {
151
224
  style={style}>
152
225
  <Dragger
153
226
  fileList={fileList}
227
+ showUploadList={showUploadList}
154
228
  multiple={multiple}
155
229
  directory={directory}
156
230
  data-dash-is-loading={
@@ -218,23 +292,88 @@ AntdDraggerUpload.propTypes = {
218
292
  showUploadList: PropTypes.bool,
219
293
 
220
294
  // 用于在每次文件上传动作完成后,记录相关的信息
221
- lastUploadTaskRecord: PropTypes.exact({
222
- // 记录文件名称
223
- fileName: PropTypes.string,
295
+ lastUploadTaskRecord: PropTypes.oneOfType([
296
+ // 单文件
297
+ PropTypes.exact({
298
+ // 记录文件名称
299
+ fileName: PropTypes.string,
224
300
 
225
- // 记录文件大小
226
- fileSize: PropTypes.number,
301
+ // 记录文件大小
302
+ fileSize: PropTypes.number,
227
303
 
228
- // 记录完成时间戳信息
229
- completeTimestamp: PropTypes.number,
304
+ // 记录完成时间戳信息
305
+ completeTimestamp: PropTypes.number,
230
306
 
231
- // 记录此次上传任务的状态信息,'success'表示成功,'failed'表示失败
232
- taskStatus: PropTypes.string,
307
+ // 记录此次上传任务的状态信息,'success'表示成功,'failed'表示失败
308
+ taskStatus: PropTypes.string,
233
309
 
234
- // 记录本次任务的id信息,若最近一次任务状态为'failed',则不会携带此信息
235
- taskId: PropTypes.string
310
+ // 记录本次任务的id信息,若最近一次任务状态为'failed',则不会携带此信息
311
+ taskId: PropTypes.string
236
312
 
237
- }),
313
+ }),
314
+ // 文件夹或多文件上传
315
+ PropTypes.arrayOf(
316
+ PropTypes.exact({
317
+ // 记录文件名称
318
+ fileName: PropTypes.string,
319
+
320
+ // 记录文件大小
321
+ fileSize: PropTypes.number,
322
+
323
+ // 记录完成时间戳信息
324
+ completeTimestamp: PropTypes.number,
325
+
326
+ // 记录此次上传任务的状态信息,'success'表示成功,'failed'表示失败
327
+ taskStatus: PropTypes.string,
328
+
329
+ // 记录本次任务的id信息,若最近一次任务状态为'failed',则不会携带此信息
330
+ taskId: PropTypes.string
331
+
332
+ })
333
+ )
334
+ ]),
335
+
336
+ // 用于在每次的上传任务完成后,更新当前文件列表中全部文件的上传信息
337
+ listUploadTaskRecord: PropTypes.oneOfType([
338
+ // 单文件
339
+ PropTypes.exact({
340
+ // 记录文件名称
341
+ fileName: PropTypes.string,
342
+
343
+ // 记录文件大小
344
+ fileSize: PropTypes.number,
345
+
346
+ // 记录完成时间戳信息
347
+ completeTimestamp: PropTypes.number,
348
+
349
+ // 记录此次上传任务的状态信息,'success'表示成功,'failed'表示失败
350
+ taskStatus: PropTypes.string,
351
+
352
+ // 记录本次任务的id信息,若最近一次任务状态为'failed',则不会携带此信息
353
+ taskId: PropTypes.string
354
+
355
+ }),
356
+ // 文件夹或多文件上传
357
+ PropTypes.arrayOf(
358
+ PropTypes.exact({
359
+ // 记录文件名称
360
+ fileName: PropTypes.string,
361
+
362
+ // 记录文件大小
363
+ fileSize: PropTypes.number,
364
+
365
+ // 记录完成时间戳信息
366
+ completeTimestamp: PropTypes.number,
367
+
368
+ // 记录此次上传任务的状态信息,'success'表示成功,'failed'表示失败
369
+ taskStatus: PropTypes.string,
370
+
371
+ // 记录本次任务的id信息,若最近一次任务状态为'failed',则不会携带此信息
372
+ taskId: PropTypes.string
373
+
374
+ })
375
+ )
376
+ ]),
238
377
 
239
378
  loading_state: PropTypes.shape({
240
379
  /**
@@ -262,7 +401,8 @@ AntdDraggerUpload.propTypes = {
262
401
  AntdDraggerUpload.defaultProps = {
263
402
  fileListMaxLength: null,
264
403
  fileMaxSize: 500,
265
- lastUploadTaskRecord: {},
404
+ lastUploadTaskRecord: null,
405
+ listUploadTaskRecord: [],
266
406
  locale: 'zh-cn'
267
407
  }
268
408
 
@@ -319,6 +319,8 @@ export default class AntdTable extends Component {
319
319
  nClicksButton,
320
320
  summaryRowContents,
321
321
  summaryRowFixed,
322
+ customFormatFuncs,
323
+ conditionalStyleFuncs,
322
324
  loading_state
323
325
  } = this.props;
324
326
 
@@ -348,10 +350,11 @@ export default class AntdTable extends Component {
348
350
  for (let i in columns) {
349
351
 
350
352
  columns[i] = {
351
- ...{ align: 'center' },
353
+ align: 'center',
352
354
  ...columns[i],
353
355
  ...{
354
- onCell: columns[i]?.conditionStyle ? eval(columns[i].conditionStyle) : columns[i]?.onCell
356
+ onCell: conditionalStyleFuncs[columns[i].dataIndex] ?
357
+ eval(conditionalStyleFuncs[columns[i].dataIndex]) : undefined
355
358
  }
356
359
  }
357
360
  }
@@ -399,7 +402,9 @@ export default class AntdTable extends Component {
399
402
  ...columns[i],
400
403
  filters: filterOptions[columns[i].dataIndex].filterCustomItems
401
404
  .map(value => ({ text: value.toString(), value: value })),
402
- onFilter: (value, record) => record[columns[i].dataIndex] === value
405
+ onFilter: (value, record) => record[columns[i].dataIndex] === value,
406
+ filterMultiple: filterOptions[columns[i].dataIndex]?.filterMultiple,
407
+ filterSearch: filterOptions[columns[i].dataIndex]?.filterSearch
403
408
  }
404
409
  } else {
405
410
  columns[i] = {
@@ -407,7 +412,9 @@ export default class AntdTable extends Component {
407
412
  filters: Array.from(new Set(data.map(item => item[columns[i].dataIndex]))).map(
408
413
  value => ({ text: value.toString(), value: value })
409
414
  ).sort(compareNumeric),
410
- onFilter: (value, record) => record[columns[i].dataIndex] === value
415
+ onFilter: (value, record) => record[columns[i].dataIndex] === value,
416
+ filterMultiple: filterOptions[columns[i].dataIndex]?.filterMultiple,
417
+ filterSearch: filterOptions[columns[i].dataIndex]?.filterSearch
411
418
  }
412
419
  }
413
420
  }
@@ -496,7 +503,7 @@ export default class AntdTable extends Component {
496
503
  }
497
504
 
498
505
  },
499
- multiple: sortOptions.sortDataIndexes.length - i,
506
+ multiple: sortOptions['multiple'] === 'auto' ? 1 : sortOptions.sortDataIndexes.length - i,
500
507
  }
501
508
  } else { // 若非组合排序模式
502
509
  columns[j]['sorter'] = (a, b) => {
@@ -753,6 +760,24 @@ export default class AntdTable extends Component {
753
760
  }
754
761
  }
755
762
 
763
+ // 配置字段渲染模式为custom-format的相关参数
764
+ for (let i = 0; i < columns.length; i++) {
765
+ // 当前字段具有renderOptions参数时且renderOptions参数是字典时
766
+ if (columns[i]['renderOptions']) {
767
+ if (columns[i]['renderOptions'].hasOwnProperty('renderType')) {
768
+ // 当renderOptions参数的renderType值设置为custom-format时
769
+ if (columns[i]['renderOptions']['renderType'] == 'custom-format') {
770
+ // 若customFormatFuncs对应当前字段的属性值存在
771
+ if (customFormatFuncs[columns[i]['dataIndex']]) {
772
+ columns[i]['render'] = content => (
773
+ eval(customFormatFuncs[columns[i]['dataIndex']])(content)
774
+ )
775
+ }
776
+ }
777
+ }
778
+ }
779
+ }
780
+
756
781
  // 配置字段渲染模式对应迷你图模式的情况
757
782
  for (let i = 0; i < columns.length; i++) {
758
783
  // 当前字段具有renderOptions参数时且renderOptions参数是字典时
@@ -976,7 +1001,7 @@ AntdTable.propTypes = {
976
1001
  renderType: PropTypes.oneOf([
977
1002
  'link', 'ellipsis', 'mini-line', 'mini-bar', 'mini-progress',
978
1003
  'mini-ring-progress', 'mini-area', 'tags', 'button', 'copyable',
979
- 'status-badge', 'image'
1004
+ 'status-badge', 'image', 'custom-format'
980
1005
  ]),
981
1006
 
982
1007
  // 当renderType='link'时,此参数会将传入的字符串作为渲染link的显示文字内容
@@ -1007,9 +1032,6 @@ AntdTable.propTypes = {
1007
1032
  // 自定义列像素宽度
1008
1033
  width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1009
1034
 
1010
- // 用于传入js函数字符串
1011
- conditionStyle: PropTypes.string,
1012
-
1013
1035
  // 防止状态更新报错占位用,无实际意义
1014
1036
  ellipsis: PropTypes.any,
1015
1037
 
@@ -1098,10 +1120,10 @@ AntdTable.propTypes = {
1098
1120
  data: PropTypes.arrayOf(
1099
1121
  PropTypes.objectOf(
1100
1122
  PropTypes.oneOfType([
1101
- // 常规模式、ellipsis模式、copyable模式
1123
+ // 常规模式、ellipsis模式、copyable模式、custom-format模式
1102
1124
  PropTypes.string,
1103
1125
 
1104
- // 常规模式、ellipsis模式、mini-prorgess模式、mini-ring-progress模式、copyable模式
1126
+ // 常规模式、ellipsis模式、mini-prorgess模式、mini-ring-progress模式、copyable模式、custom-format模式
1105
1127
  // 其中mini-prorgess模式、mini-ring-progress模式输入值需在0~1之间
1106
1128
  PropTypes.number,
1107
1129
 
@@ -1205,13 +1227,36 @@ AntdTable.propTypes = {
1205
1227
  // 定义要参与排序的字段对应的dataIndex,多字段组合排序情况下顺序即为优先级,从高往低
1206
1228
  sortDataIndexes: PropTypes.arrayOf(PropTypes.string),
1207
1229
 
1208
- // 设置是否进行多列组合排序
1209
- multiple: PropTypes.bool
1230
+ // 设置是否进行多列组合排序,当设置为'auto'时会开启自动组合排序模式,此时组合排序的字段优先级由用户点击排序的字段顺序所动态决定
1231
+ multiple: PropTypes.oneOfType([
1232
+ PropTypes.bool,
1233
+ PropTypes.oneOf(['auto'])
1234
+ ])
1210
1235
 
1211
1236
  }),
1212
1237
 
1213
1238
  // 定义筛选参数
1214
- filterOptions: PropTypes.object,
1239
+ filterOptions: PropTypes.objectOf(
1240
+ PropTypes.exact({
1241
+ // 设置筛选模式,可选的有'checkbox'、'keyword',默认为'checkbox'
1242
+ filterMode: PropTypes.oneOf(['checkbox', 'keyword']),
1243
+
1244
+ // 'checkbox'模式下可用,用于自定义待筛选项
1245
+ filterCustomItems: PropTypes.oneOfType([
1246
+ PropTypes.arrayOf([
1247
+ PropTypes.string,
1248
+ PropTypes.number
1249
+ ]),
1250
+ PropTypes.any
1251
+ ]),
1252
+
1253
+ // 'checkbox'模式下可用,用于设置是否允许多选,默认为true
1254
+ filterMultiple: PropTypes.bool,
1255
+
1256
+ // 'checkbox'模式下可用,用于设置是否开启搜索框,默认为false
1257
+ filterSearch: PropTypes.bool
1258
+ })
1259
+ ),
1215
1260
 
1216
1261
  // 翻页相关参数,设置为false时不展示和进行分页
1217
1262
  pagination: PropTypes.oneOfType([
@@ -1326,6 +1371,17 @@ AntdTable.propTypes = {
1326
1371
  // 设置总结栏是否启用fixed功能,默认为false
1327
1372
  summaryRowFixed: PropTypes.bool,
1328
1373
 
1374
+ // 针对custom-format自定义格式化对应的字段,设置针对对应列每个值从原始数值到格式化结果的js函数字符串
1375
+ // 键名为对应字段的dataIndex
1376
+ customFormatFuncs: PropTypes.objectOf(
1377
+ PropTypes.string
1378
+ ),
1379
+
1380
+ // 以对应字段的dataIndex为键,传入js函数字符串,用于自定义逻辑改变每个单元格的style样式
1381
+ conditionalStyleFuncs: PropTypes.objectOf(
1382
+ PropTypes.string
1383
+ ),
1384
+
1329
1385
  loading_state: PropTypes.shape({
1330
1386
  /**
1331
1387
  * Determines if the component is loading or not
@@ -1364,5 +1420,6 @@ AntdTable.defaultProps = {
1364
1420
  mode: 'client-side',
1365
1421
  nClicksButton: 0,
1366
1422
  size: 'default',
1367
- locale: 'zh-cn'
1423
+ locale: 'zh-cn',
1424
+ conditionalStyleFuncs: {}
1368
1425
  }