ArticleEditDrawer.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Drawer } from "antd";
  2. import React, { useEffect, useState } from "react";
  3. import type { IArticleDataResponse } from "../../api/Article";
  4. import ArticleEdit from "./ArticleEdit";
  5. interface IWidget {
  6. trigger?: React.ReactNode;
  7. articleId?: string;
  8. anthologyId?: string;
  9. open?: boolean;
  10. onClose?: Function;
  11. onChange?: Function;
  12. }
  13. const ArticleEditDrawerWidget = ({
  14. trigger,
  15. articleId,
  16. anthologyId,
  17. open,
  18. onClose,
  19. onChange,
  20. }: IWidget) => {
  21. const [openDrawer, setOpenDrawer] = useState(open);
  22. const [title, setTitle] = useState("loading");
  23. const [readonly, setReadonly] = useState(false);
  24. const [_studioName, setStudioName] = useState<string>();
  25. useEffect(() => setOpenDrawer(open), [open]);
  26. const showDrawer = () => {
  27. setOpenDrawer(true);
  28. };
  29. const onDrawerClose = () => {
  30. setOpenDrawer(false);
  31. if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
  32. document.getElementsByTagName("body")[0].removeAttribute("style");
  33. }
  34. if (typeof onClose !== "undefined") {
  35. onClose();
  36. }
  37. };
  38. return (
  39. <>
  40. <span onClick={() => showDrawer()}>{trigger}</span>
  41. <Drawer
  42. title={title + (readonly ? "(只读)" : "")}
  43. width={1000}
  44. placement="right"
  45. onClose={onDrawerClose}
  46. open={openDrawer}
  47. destroyOnHidden={true}
  48. >
  49. <ArticleEdit
  50. anthologyId={anthologyId}
  51. articleId={articleId}
  52. onReady={(title: string, readonly: boolean, studio?: string) => {
  53. setTitle(title);
  54. setReadonly(readonly);
  55. setStudioName(studio);
  56. }}
  57. onChange={(data: IArticleDataResponse) => {
  58. if (typeof onChange !== "undefined") {
  59. onChange(data);
  60. }
  61. }}
  62. />
  63. </Drawer>
  64. </>
  65. );
  66. };
  67. export default ArticleEditDrawerWidget;