Commit ca760b7f3a7b5dac93055ed851ff1631d6f472fb
1 parent
2add803f
优化 通用组件-FeeweeUploadAttachment;
Showing
1 changed file
with
52 additions
and
41 deletions
src/components/FeeweeUploadAttachment/index.tsx
1 | /* | 1 | /* |
2 | * @Date: 2021-01-05 14:24:23 | 2 | * @Date: 2021-01-05 14:24:23 |
3 | * @LastEditors: wangqiang@feewee.cn | 3 | * @LastEditors: wangqiang@feewee.cn |
4 | - * @LastEditTime: 2022-10-10 17:54:30 | 4 | + * @LastEditTime: 2022-10-11 09:14:38 |
5 | */ | 5 | */ |
6 | import React, { useEffect, useRef, useState } from "react"; | 6 | import React, { useEffect, useRef, useState } from "react"; |
7 | import { message, Popover, Spin, Upload } from "antd"; | 7 | import { message, Popover, Spin, Upload } from "antd"; |
@@ -221,7 +221,14 @@ export default function FeeweeUploadAttachment({ | @@ -221,7 +221,14 @@ export default function FeeweeUploadAttachment({ | ||
221 | : props.listType === "picture" | 221 | : props.listType === "picture" |
222 | ? ListTypeOfPicture | 222 | ? ListTypeOfPicture |
223 | : ListTypeOfText; | 223 | : ListTypeOfText; |
224 | - return <DOM file={file} freezeItems={freezeItems} remove={remove} />; | 224 | + return ( |
225 | + <DOM | ||
226 | + file={file} | ||
227 | + freezeItems={freezeItems} | ||
228 | + remove={remove} | ||
229 | + disabled={props.disabled} | ||
230 | + /> | ||
231 | + ); | ||
225 | // return ( | 232 | // return ( |
226 | // <div | 233 | // <div |
227 | // id="FeeweeUploadAttachment" | 234 | // id="FeeweeUploadAttachment" |
@@ -243,15 +250,19 @@ export default function FeeweeUploadAttachment({ | @@ -243,15 +250,19 @@ export default function FeeweeUploadAttachment({ | ||
243 | ); | 250 | ); |
244 | } | 251 | } |
245 | 252 | ||
253 | +interface ItemRenderProps { | ||
254 | + file: UploadFile; | ||
255 | + freezeItems?: string[]; | ||
256 | + remove: () => void; | ||
257 | + disabled?: boolean; | ||
258 | +} | ||
259 | + | ||
246 | const ListTypeOfText = ({ | 260 | const ListTypeOfText = ({ |
247 | file, | 261 | file, |
248 | freezeItems = [], | 262 | freezeItems = [], |
249 | remove, | 263 | remove, |
250 | -}: { | ||
251 | - file: UploadFile; | ||
252 | - freezeItems?: string[]; | ||
253 | - remove: () => void; | ||
254 | -}) => ( | 264 | + disabled, |
265 | +}: ItemRenderProps) => ( | ||
255 | <div | 266 | <div |
256 | id="FeeweeUploadAttachment" | 267 | id="FeeweeUploadAttachment" |
257 | className={ | 268 | className={ |
@@ -314,14 +325,16 @@ const ListTypeOfText = ({ | @@ -314,14 +325,16 @@ const ListTypeOfText = ({ | ||
314 | <span>{file?.errMsg}</span> | 325 | <span>{file?.errMsg}</span> |
315 | ) : null} | 326 | ) : null} |
316 | <span className="ant-upload-list-item-card-actions"> | 327 | <span className="ant-upload-list-item-card-actions"> |
317 | - <button | ||
318 | - title="删除文件" | ||
319 | - type="button" | ||
320 | - onClick={() => remove()} | ||
321 | - className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn" | ||
322 | - > | ||
323 | - <DeleteOutlined /> | ||
324 | - </button> | 328 | + {!disabled ? ( |
329 | + <button | ||
330 | + title="删除文件" | ||
331 | + type="button" | ||
332 | + onClick={() => remove()} | ||
333 | + className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn" | ||
334 | + > | ||
335 | + <DeleteOutlined /> | ||
336 | + </button> | ||
337 | + ) : null} | ||
325 | </span> | 338 | </span> |
326 | </span> | 339 | </span> |
327 | )} | 340 | )} |
@@ -348,11 +361,8 @@ const ListTypeOfPictureCard = ({ | @@ -348,11 +361,8 @@ const ListTypeOfPictureCard = ({ | ||
348 | file, | 361 | file, |
349 | freezeItems = [], | 362 | freezeItems = [], |
350 | remove, | 363 | remove, |
351 | -}: { | ||
352 | - file: UploadFile; | ||
353 | - freezeItems?: string[]; | ||
354 | - remove: () => void; | ||
355 | -}) => ( | 364 | + disabled, |
365 | +}: ItemRenderProps) => ( | ||
356 | <div | 366 | <div |
357 | id="FeeweeUploadAttachment" | 367 | id="FeeweeUploadAttachment" |
358 | className={ | 368 | className={ |
@@ -459,14 +469,16 @@ const ListTypeOfPictureCard = ({ | @@ -459,14 +469,16 @@ const ListTypeOfPictureCard = ({ | ||
459 | > | 469 | > |
460 | <EyeOutlined /> | 470 | <EyeOutlined /> |
461 | </a> | 471 | </a> |
462 | - <button | ||
463 | - title="删除文件" | ||
464 | - type="button" | ||
465 | - onClick={() => remove()} | ||
466 | - className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn" | ||
467 | - > | ||
468 | - <DeleteOutlined /> | ||
469 | - </button> | 472 | + {!disabled ? ( |
473 | + <button | ||
474 | + title="删除文件" | ||
475 | + type="button" | ||
476 | + onClick={() => remove()} | ||
477 | + className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn" | ||
478 | + > | ||
479 | + <DeleteOutlined /> | ||
480 | + </button> | ||
481 | + ) : null} | ||
470 | </span> | 482 | </span> |
471 | )} | 483 | )} |
472 | </div> | 484 | </div> |
@@ -478,11 +490,8 @@ const ListTypeOfPicture = ({ | @@ -478,11 +490,8 @@ const ListTypeOfPicture = ({ | ||
478 | file, | 490 | file, |
479 | freezeItems = [], | 491 | freezeItems = [], |
480 | remove, | 492 | remove, |
481 | -}: { | ||
482 | - file: UploadFile; | ||
483 | - freezeItems?: string[]; | ||
484 | - remove: () => void; | ||
485 | -}) => ( | 493 | + disabled, |
494 | +}: ItemRenderProps) => ( | ||
486 | <div | 495 | <div |
487 | id="FeeweeUploadAttachment" | 496 | id="FeeweeUploadAttachment" |
488 | className={ | 497 | className={ |
@@ -568,14 +577,16 @@ const ListTypeOfPicture = ({ | @@ -568,14 +577,16 @@ const ListTypeOfPicture = ({ | ||
568 | <span>{file?.errMsg}</span> | 577 | <span>{file?.errMsg}</span> |
569 | ) : null} | 578 | ) : null} |
570 | <span className="ant-upload-list-item-card-actions picture"> | 579 | <span className="ant-upload-list-item-card-actions picture"> |
571 | - <button | ||
572 | - title="删除文件" | ||
573 | - type="button" | ||
574 | - onClick={() => remove()} | ||
575 | - className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn" | ||
576 | - > | ||
577 | - <DeleteOutlined /> | ||
578 | - </button> | 580 | + {!disabled ? ( |
581 | + <button | ||
582 | + title="删除文件" | ||
583 | + type="button" | ||
584 | + onClick={() => remove()} | ||
585 | + className="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn" | ||
586 | + > | ||
587 | + <DeleteOutlined /> | ||
588 | + </button> | ||
589 | + ) : null} | ||
579 | </span> | 590 | </span> |
580 | </span> | 591 | </span> |
581 | )} | 592 | )} |