9251004f
王强
添加 通用组件-上传附件 Feew...
|
1
2
3
|
/*
* @Date: 2021-01-05 14:24:23
* @LastEditors: wangqiang@feewee.cn
|
2c26ad30
王强
fix;
|
4
|
* @LastEditTime: 2023-02-11 16:54:22
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
5
6
7
8
9
10
11
12
|
*/
import React, { useEffect, useRef, useState } from "react";
import { message, Popover, Spin, Upload } from "antd";
import {
LinkOutlined,
EyeOutlined,
DeleteOutlined,
FileTwoTone,
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
13
|
LoadingOutlined,
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
} from "@ant-design/icons";
import { UploadProps } from "antd/lib/upload";
import {
RcFile,
UploadChangeParam,
UploadFile,
} from "antd/lib/upload/interface";
import getFidFile, { FeeweeFileAccept } from "@/utils/getFidFile";
import COS from "@/utils/COS";
import {
getFileListDetailApi,
confirmThirdFileApi,
deleteFileApi,
} from "./api";
import "./index.less";
import { IMGURL } from "@/utils";
// @ts-ignore
interface Props extends UploadProps {
/**
* @description: 附件fid列表。
* @description: 如果在表单中使用,则需要再Form.Item 中声明valuePropName="fidList"
*/
fidList?: string[];
onChange?: (fidList: string[]) => void;
/** 使用腾讯云对象存储 */
useCos?: boolean;
/** 上传腾讯云-前缀文件夹名称 */
catalog?: string;
/** 不允许修改文件项列表 fid 数组[] */
freezeItems?: string[];
limitSize?: number; // 限制文件大小
limitUnit?: "kb" | "mb" | "KB" | "MB"; // 限制大小单位, 默认MB
children?: React.ReactNode;
}
/**
* @description: 自定义封装的 FeeweeUploadAttachment 上传附件组件
* @description: 使用方式:
* 1. 仅需要 传入 fidList 和 onChange 参数就可以使用基本用法;
* 2. 其他的参数同 Upload 组件的参数
* 3. useCos catalog freezeItems 同 APP 组件作用一样;
* 4. limitSize 和 limitUnit 是为了限制上传附件的大小
* @param {Props} props
*/
export default function FeeweeUploadAttachment({
useCos,
catalog = "",
limitSize = undefined,
limitUnit = "MB",
children,
freezeItems = [],
|
fbbd610d
王强
优化 附件上传组件,初始化判断逻辑;
|
66
|
fidList,
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
67
68
69
70
71
72
73
74
|
onChange,
...props
}: Props) {
const [loading, setLoading] = useState(false);
const [fileList, setFileList] = useState<UploadFile[]>([]);
const removingFileFidList = useRef<string[]>([]);
useEffect(() => {
|
fbbd610d
王强
优化 附件上传组件,初始化判断逻辑;
|
75
|
if (fidList?.length) {
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
76
|
setLoading(true);
|
2c26ad30
王强
fix;
|
77
|
// const hide = message.loading("", 0);
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
getFileListDetailApi(fidList)
.then((res) => {
setFileList(
(res.data || []).map((item) => ({
name: item.aliasName || item.fileName || "",
uid: item.fid || "",
url: item.fileUri,
status: "done",
size: item.length,
type: item.contentType,
response: { data: item.fileUri, fid: item.fid },
}))
);
})
|
7193dcdf
莫红玲
车辆加装配置编辑
|
92
|
.catch((error: any) => { })
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
93
|
.finally(() => {
|
2c26ad30
王强
fix;
|
94
|
// hide();
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
95
96
97
|
setLoading(false);
});
}
|
e8ba57d2
王强
优化 通用组件-附件上传,交互;
|
98
|
}, [fidList]);
|
fbbd610d
王强
优化 附件上传组件,初始化判断逻辑;
|
99
|
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
if (!props.listType) {
props.listType = "text";
}
if (useCos) {
props.customRequest = (data) => COS.cosUpload({ ...data, uploadPath: "fw_fds_file/" + catalog });
} else {
props.action = "api/file/upload";
}
const onPreview = (file: UploadFile) => {
if (props.onPreview) {
props.onPreview(file);
return;
}
getFidFile(file?.response.data);
};
const beforeUpload = (file: RcFile, filelist: RcFile[]) => {
if (limitSize !== undefined && typeof limitSize === "number") {
const limit = isExceededSize(file, limitSize, limitUnit);
if (limit.success) {
return true;
} else {
message.error(limit.msg);
// @ts-ignore
file.status = "size_limit";
// @ts-ignore
file.errMsg = limit.msg;
return false;
}
}
return props.beforeUpload ? props.beforeUpload(file, filelist) : true;
};
|
ec4af811
王强
优化 通用组件-附件上传,当多个文...
|
134
135
|
const allFileDone = (fileList: UploadFile<any>[]) => (fileList || []).every((file) => file?.status !== "uploading");
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
const onUploadChange = async ({
file,
fileList,
}: UploadChangeParam<UploadFile>) => {
setFileList(
fileList.map((_file) => ({
..._file,
// @ts-ignore
status: _file?.status === "size_limit" ? "error" : _file?.status,
}))
);
if (file?.status === "done") {
if (useCos) {
try {
const ext_array = file?.name.split(".");
const { data } = await confirmThirdFileApi({
fileName: file?.name,
ext: "." + ext_array[ext_array.length - 1],
contentType: file?.type,
fileUri: file?.response.data,
length: file?.size,
});
file.response.fid = data;
|
ec4af811
王强
优化 通用组件-附件上传,当多个文...
|
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
if (allFileDone(fileList)) {
onChange &&
onChange(
fileList
.filter(
(file) => file?.status === "done" && file?.response.fid
)
.map((file) => file?.response.fid)
);
}
} catch (error: any) {
message.error(error.message || "确认文件失败", 2);
}
} else {
file.response.fid = file?.response.data;
if (allFileDone(fileList)) {
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
175
176
177
178
179
180
|
onChange &&
onChange(
fileList
.filter((file) => file?.status === "done" && file?.response.fid)
.map((file) => file?.response.fid)
);
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
181
|
}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
182
183
184
185
186
187
188
|
}
}
};
const onFileRemove = async (file: UploadFile) => {
if (removingFileFidList.current.includes(file?.response?.fid)) return false;
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
189
|
if (file.status === "error" || file?.status === "uploading") {
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
190
191
192
193
194
195
196
197
|
setFileList(fileList.filter((_file) => _file.uid !== file.uid));
return true;
}
const hide = message.loading("删除中...", 0);
try {
removingFileFidList.current.push(file?.response.fid);
setLoading(true);
|
0a763d83
王强
修复 通用上传附件组件,删除附件仅...
|
198
199
200
201
|
// await deleteFileApi(file?.response.fid);
// if (useCos) {
// await deleteCOSFile(file?.response.data);
// }
|
ec4af811
王强
优化 通用组件-附件上传,当多个文...
|
202
203
|
onChange &&
onChange((fidList || []).filter((fid) => fid !== file?.response.fid));
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
return Promise.resolve();
} catch (error: any) {
message.error(error.message || "删除文件失败", 2);
return Promise.reject();
} finally {
removingFileFidList.current = removingFileFidList.current.filter(
(fid) => fid !== file?.response.fid
);
setLoading(false);
hide();
}
};
return (
<Spin spinning={loading}>
<Upload
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
220
221
|
accept={FeeweeFileAccept}
beforeUpload={beforeUpload}
|
7193dcdf
莫红玲
车辆加装配置编辑
|
222
|
{...props}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
223
224
225
226
227
228
229
230
231
|
onPreview={onPreview}
fileList={fileList}
onChange={onUploadChange}
onRemove={onFileRemove}
itemRender={(originalNode, file, fileList, { remove }) => {
const DOM =
props.listType === "picture-card"
? ListTypeOfPictureCard
: props.listType === "picture"
|
7193dcdf
莫红玲
车辆加装配置编辑
|
232
233
|
? ListTypeOfPicture
: ListTypeOfText;
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
234
235
236
237
238
239
240
241
|
return (
<DOM
file={file}
freezeItems={freezeItems}
remove={remove}
disabled={props.disabled}
/>
);
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
// return (
// <div
// id="FeeweeUploadAttachment"
// className={
// freezeItems.includes(file?.response?.fid)
// ? "FeeweeUploadAttachment_hidden_delete_icon"
// : ""
// }
// >
// {/* @ts-ignore */}
// {originalNode}
// </div>
// );
}}
>
|
e8ba57d2
王强
优化 通用组件-附件上传,交互;
|
257
258
259
260
261
262
263
|
{props.disabled ? (
fileList.length ? null : (
<span style={{ color: "#999" }}>暂无附件</span>
)
) : (
children
)}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
264
265
266
267
268
|
</Upload>
</Spin>
);
}
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
269
270
271
272
273
274
275
|
interface ItemRenderProps {
file: UploadFile;
freezeItems?: string[];
remove: () => void;
disabled?: boolean;
}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
276
277
278
279
|
const ListTypeOfText = ({
file,
freezeItems = [],
remove,
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
280
281
|
disabled,
}: ItemRenderProps) => (
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
282
283
284
285
286
287
288
289
290
|
<div
id="FeeweeUploadAttachment"
className={
freezeItems.includes(file?.response?.fid)
? "FeeweeUploadAttachment_hidden_delete_icon"
: ""
}
>
<div
|
7193dcdf
莫红玲
车辆加装配置编辑
|
291
292
|
className={`ant-upload-list-item ant-upload-list-item-done ${file?.status === "error" ? "ant-upload-list-item-error" : ""
} ant-upload-list-item-list-type-text`}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
293
294
|
>
<div className="ant-upload-list-item-info">
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
295
296
297
298
299
300
301
|
{file?.status === "uploading" ? (
<span className="ant-upload-span">
<div className="ant-upload-text-icon">
<LoadingOutlined />
</div>
<span
className="ant-upload-list-item-name"
|
7193dcdf
莫红玲
车辆加装配置编辑
|
302
303
|
title={`${file?.name}(${file?.size ? getFileSize(file?.size) : ""
})`}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
304
|
>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
305
306
307
308
309
310
311
312
313
314
315
316
|
{file?.name}({file?.size ? getFileSize(file?.size) : ""})
</span>
<span className="ant-upload-list-item-card-actions">
<button
title="删除文件"
type="button"
onClick={() => remove()}
className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
>
<DeleteOutlined />
</button>
</span>
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
317
|
</span>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
) : (
<span className="ant-upload-span">
<div className="ant-upload-text-icon">
<LinkOutlined />
</div>
<a
target="_blank"
rel="noopener noreferrer"
className="ant-upload-list-item-name"
title={file?.name}
href={
file?.status === "error"
? undefined
: IMGURL.showImage(file?.response?.data)
}
>
{file?.name}({file?.size ? getFileSize(file?.size) : ""})
</a>
{/* @ts-ignore */}
{file?.status === "error" && file?.errMsg ? (
// @ts-ignore
<span>{file?.errMsg}</span>
) : null}
<span className="ant-upload-list-item-card-actions">
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
342
343
344
345
346
347
348
349
350
351
|
{!disabled ? (
<button
title="删除文件"
type="button"
onClick={() => remove()}
className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
>
<DeleteOutlined />
</button>
) : null}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
352
353
354
|
</span>
</span>
)}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
355
|
</div>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
{file?.status === "uploading" ? (
<div className="ant-upload-list-item-progress">
<div className="ant-progress ant-progress-line ant-progress-status-normal ant-progress-default">
<div className="ant-progress-outer">
<div className="ant-progress-inner">
<div
className="ant-progress-bg"
style={{ width: `${file?.percent || 0}%`, height: 2 }}
/>
</div>
</div>
</div>
</div>
) : null}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
370
371
372
373
374
375
376
377
|
</div>
</div>
);
const ListTypeOfPictureCard = ({
file,
freezeItems = [],
remove,
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
378
379
|
disabled,
}: ItemRenderProps) => (
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
<div
id="FeeweeUploadAttachment"
className={
freezeItems.includes(file?.response?.fid)
? "FeeweeUploadAttachment_hidden_delete_icon"
: ""
}
>
<Popover
placement="topLeft"
content={
<div>
<p>
文件信息:{file?.name}({file?.size ? getFileSize(file?.size) : ""})
</p>
{/* @ts-ignore */}
{file?.errMsg ? (
<p>
{/* @ts-ignore */}
错误原因:<span style={{ color: "#ff4d4f" }}>{file?.errMsg}</span>
</p>
) : null}
</div>
}
>
<div
|
7193dcdf
莫红玲
车辆加装配置编辑
|
406
407
|
className={`ant-upload-list-item ant-upload-list-item-done ${file?.status === "error" ? "ant-upload-list-item-error" : ""
} ant-upload-list-item-list-type-picture-card`}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
408
409
|
>
<div className="ant-upload-list-item-info">
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
{file?.status === "uploading" ? (
<span className="ant-upload-span">
<div className="ant-upload-list-item-thumbnail">文件上传中</div>
<span className="ant-upload-list-item-name" title={file?.name}>
{file?.name}
</span>
</span>
) : (
<span className="ant-upload-span">
<a
className="ant-upload-list-item-thumbnail ant-upload-list-item-file"
href={
file?.status === "error"
? undefined
: IMGURL.showImage(file?.response?.data)
}
target="_blank"
rel="noopener noreferrer"
>
{file?.type?.includes("image") ? (
<img
src={IMGURL.showImage(
file?.thumbUrl || file?.response?.data
)}
|
7193dcdf
莫红玲
车辆加装配置编辑
|
434
435
|
alt={`${file?.name}(${file?.size ? getFileSize(file?.size) : ""
})`}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
436
437
438
439
440
441
442
443
444
445
446
|
className="ant-upload-list-item-image"
/>
) : (
<FileTwoTone style={{ fontSize: 26 }} />
)}
</a>
<span
className="ant-upload-list-item-name"
style={{
display: file?.type?.includes("image") ? "none" : undefined,
}}
|
7193dcdf
莫红玲
车辆加装配置编辑
|
447
448
|
title={`${file?.name}(${file?.size ? getFileSize(file?.size) : ""
})`}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
|
>
{file?.name}({file?.size ? getFileSize(file?.size) : ""})
</span>
</span>
)}
</div>
{file?.status === "uploading" ? (
<div className="ant-upload-list-item-progress">
<div className="ant-progress ant-progress-line ant-progress-status-normal ant-progress-default">
<div className="ant-progress-outer">
<div className="ant-progress-inner">
<div
className="ant-progress-bg"
style={{ width: `${file?.percent || 0}%`, height: 2 }}
/>
</div>
</div>
</div>
</div>
) : (
<span className="ant-upload-list-item-actions">
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
470
|
<a
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
471
472
473
|
target="_blank"
rel="noopener noreferrer"
title="预览文件"
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
474
475
476
477
478
|
href={
file?.status === "error"
? undefined
: IMGURL.showImage(file?.response?.data)
}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
479
|
style={{ display: file?.status === "error" ? "none" : undefined }}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
480
|
>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
481
|
<EyeOutlined />
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
482
|
</a>
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
483
484
485
486
487
488
489
490
491
492
|
{!disabled ? (
<button
title="删除文件"
type="button"
onClick={() => remove()}
className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
>
<DeleteOutlined />
</button>
) : null}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
493
|
</span>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
494
|
)}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
495
496
497
498
499
500
501
502
503
|
</div>
</Popover>
</div>
);
const ListTypeOfPicture = ({
file,
freezeItems = [],
remove,
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
504
505
|
disabled,
}: ItemRenderProps) => (
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
506
507
508
509
510
511
512
513
514
|
<div
id="FeeweeUploadAttachment"
className={
freezeItems.includes(file?.response?.fid)
? "FeeweeUploadAttachment_hidden_delete_icon"
: ""
}
>
<div
|
7193dcdf
莫红玲
车辆加装配置编辑
|
515
516
517
|
className={`ant-upload-list-item ant-upload-list-item-done ${file?.status === "error" ? "ant-upload-list-item-error" : ""
} ${file?.status === "uploading" ? "ant-upload-list-item-uploading" : ""
} ant-upload-list-item-list-type-picture`}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
518
519
|
>
<div className="ant-upload-list-item-info">
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
520
521
522
523
524
525
526
|
{file?.status === "uploading" ? (
<span className="ant-upload-span">
<div className="ant-upload-list-item-thumbnail">
<LoadingOutlined />
</div>
<span
className="ant-upload-list-item-name"
|
7193dcdf
莫红玲
车辆加装配置编辑
|
527
528
|
title={`${file?.name}(${file?.size ? getFileSize(file?.size) : ""
})`}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
529
|
>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
{file?.name}({file?.size ? getFileSize(file?.size) : ""})
</span>
<span className="ant-upload-list-item-card-actions picture">
<button
title="删除文件"
type="button"
onClick={() => remove()}
className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
>
<DeleteOutlined />
</button>
</span>
</span>
) : (
<span className="ant-upload-span">
<a
className="ant-upload-list-item-thumbnail"
href={
file?.status === "error"
? undefined
: IMGURL.showImage(file?.response?.data)
}
target="_blank"
rel="noopener noreferrer"
>
{file?.type?.includes("image") ? (
<img
src={IMGURL.showImage(file?.thumbUrl || file?.response?.data)}
|
7193dcdf
莫红玲
车辆加装配置编辑
|
558
559
|
alt={`${file?.name}(${file?.size ? getFileSize(file?.size) : ""
})`}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
560
561
562
563
564
565
566
567
568
569
|
className="ant-upload-list-item-image"
/>
) : (
<FileTwoTone style={{ fontSize: 26 }} />
)}
</a>
<a
target="_blank"
rel="noopener noreferrer"
className="ant-upload-list-item-name"
|
7193dcdf
莫红玲
车辆加装配置编辑
|
570
571
|
title={`${file?.name}(${file?.size ? getFileSize(file?.size) : ""
})`}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
href={
file?.status === "error"
? undefined
: IMGURL.showImage(file?.response?.data)
}
>
{file?.name}({file?.size ? getFileSize(file?.size) : ""})
</a>
{/* @ts-ignore */}
{file?.status === "error" && file?.errMsg ? (
// @ts-ignore
<span>{file?.errMsg}</span>
) : null}
<span className="ant-upload-list-item-card-actions picture">
|
ca760b7f
王强
优化 通用组件-FeeweeUpl...
|
586
587
588
589
590
591
592
593
594
595
|
{!disabled ? (
<button
title="删除文件"
type="button"
onClick={() => remove()}
className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
>
<DeleteOutlined />
</button>
) : null}
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
596
|
</span>
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
597
|
</span>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
598
|
)}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
599
|
</div>
|
2add803f
王强
修改 通用组件-FeeweeUpl...
|
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
{file?.status === "uploading" ? (
<div className="ant-upload-list-item-progress">
<div className="ant-progress ant-progress-line ant-progress-status-normal ant-progress-default">
<div className="ant-progress-outer">
<div className="ant-progress-inner">
<div
className="ant-progress-bg"
style={{ width: `${file?.percent || 0}%`, height: 2 }}
/>
</div>
</div>
</div>
</div>
) : null}
|
9251004f
王强
添加 通用组件-上传附件 Feew...
|
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
</div>
</div>
);
const deleteCOSFile = (filePath: string) => {
return new Promise((resolve, reject) => {
COS.cosDelete({ filePath }, resolve, reject);
});
};
/**
* @description: 计算限制大小,统一返回限制大小转换为KB
* @param {number} limitSize
* @param {'kb' | 'mb' | 'KB' | 'MB'} limitUnit
* @return {number}
*/
function getLimitSize(
limitSize: number,
limitUnit: "kb" | "mb" | "KB" | "MB"
): number {
if (limitUnit === "kb" || limitUnit === "KB") {
return limitSize;
}
if (limitUnit === "mb" || limitUnit === "MB") {
return limitSize * 1024;
}
return 0;
}
/**
* @description: 判断是否没超过限制大小
* @param {RcFile} file
* @param {number} limitSize
* @param {*} limitUnit
* @return {{ success: boolean, msg?: string }}
*/
function isExceededSize(
file: RcFile,
limitSize: number,
limitUnit: "kb" | "mb" | "KB" | "MB"
): { success: boolean; msg?: string } {
const _limitSize = getLimitSize(limitSize, limitUnit);
const fileSizeToKB = file?.size / 1024;
if (fileSizeToKB <= _limitSize) {
return { success: true };
} else {
return {
success: false,
msg: `文件【${file?.name}】大小不能超过${limitSize}${limitUnit}`,
};
}
}
export function getFileSize(length: number): string {
let fileSize: string;
fileSize = (length / 1024).toFixed(2);
if (+fileSize > 1024) {
fileSize = (+fileSize / 1024).toFixed(2) + "MB";
} else {
fileSize += "KB";
}
return fileSize;
}
|