WbwDetailUpload.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { DeleteOutlined } from "@ant-design/icons";
  2. import { Button, List } from "antd";
  3. import { currentUser } from "../../../reducers/current-user";
  4. import type { IWbw, IWbwAttachment } from "./WbwWord";
  5. import AttachmentDialog from "../../attachment/AttachmentDialog";
  6. import { useAppSelector } from "../../../hooks";
  7. import type { IAttachmentRequest } from "../../../api/Attachments";
  8. interface IWidget {
  9. data: IWbw;
  10. onUpload?: (value: IAttachmentRequest[]) => void;
  11. onChange?: (output?: IWbwAttachment[]) => void;
  12. onDialogOpen?: (open: boolean) => void;
  13. }
  14. const WbwDetailUploadWidget = ({
  15. data,
  16. onUpload,
  17. onChange,
  18. onDialogOpen,
  19. }: IWidget) => {
  20. const user = useAppSelector(currentUser);
  21. const attachments = data.attachments;
  22. return (
  23. <>
  24. <List
  25. itemLayout="vertical"
  26. size="small"
  27. header={
  28. <AttachmentDialog
  29. trigger={<Button>上传</Button>}
  30. studioName={user?.realName}
  31. onOpenChange={(open: boolean) => {
  32. if (typeof onDialogOpen !== "undefined") {
  33. onDialogOpen(open);
  34. }
  35. }}
  36. onSelect={(value: IAttachmentRequest) => {
  37. onUpload?.([value]);
  38. }}
  39. />
  40. }
  41. dataSource={attachments}
  42. renderItem={(item, id) => (
  43. <List.Item>
  44. <div style={{ display: "flex", justifyContent: "space-between" }}>
  45. <div style={{ maxWidth: 400, overflowX: "hidden" }}>
  46. {item.title}
  47. </div>
  48. <div style={{ marginLeft: 20 }}>
  49. <Button
  50. type="link"
  51. size="small"
  52. icon={<DeleteOutlined />}
  53. onClick={() => {
  54. const output = data.attachments?.filter(
  55. (_value: IWbwAttachment, index: number) => index !== id
  56. );
  57. onChange?.(output);
  58. }}
  59. />
  60. </div>
  61. </div>
  62. </List.Item>
  63. )}
  64. />
  65. </>
  66. );
  67. };
  68. export default WbwDetailUploadWidget;