ChannelPicker.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React, { useEffect, useState } from "react";
  2. import { Modal } from "antd";
  3. import ChannelPickerTable from "./ChannelPickerTable";
  4. import { IChannel } from "./Channel";
  5. import { ArticleType } from "../article/Article";
  6. interface IWidget {
  7. trigger?: React.ReactNode;
  8. type?: ArticleType | "editable";
  9. articleId?: string;
  10. multiSelect?: boolean;
  11. open?: boolean;
  12. defaultOwner?: string;
  13. onClose?: Function;
  14. onSelect?: Function;
  15. }
  16. const ChannelPickerWidget = ({
  17. trigger,
  18. type,
  19. articleId,
  20. multiSelect = true,
  21. open = false,
  22. defaultOwner,
  23. onClose,
  24. onSelect,
  25. }: IWidget) => {
  26. const [isModalOpen, setIsModalOpen] = useState(open);
  27. useEffect(() => {
  28. setIsModalOpen(open);
  29. }, [open]);
  30. const showModal = () => {
  31. setIsModalOpen(true);
  32. };
  33. const handleOk = () => {
  34. setIsModalOpen(false);
  35. if (typeof onClose !== "undefined") {
  36. onClose();
  37. }
  38. };
  39. const handleCancel = () => {
  40. setIsModalOpen(false);
  41. if (typeof onClose !== "undefined") {
  42. onClose();
  43. }
  44. };
  45. return (
  46. <>
  47. <span onClick={showModal}>{trigger}</span>
  48. <Modal
  49. width={"80%"}
  50. title="选择版本风格"
  51. footer={false}
  52. open={isModalOpen}
  53. onOk={handleOk}
  54. onCancel={handleCancel}
  55. >
  56. <ChannelPickerTable
  57. type={type}
  58. articleId={articleId}
  59. multiSelect={multiSelect}
  60. defaultOwner={defaultOwner}
  61. onSelect={(channels: IChannel[]) => {
  62. console.log(channels);
  63. handleCancel();
  64. if (typeof onClose !== "undefined") {
  65. onClose();
  66. }
  67. if (typeof onSelect !== "undefined") {
  68. onSelect(channels);
  69. }
  70. }}
  71. />
  72. </Modal>
  73. </>
  74. );
  75. };
  76. export default ChannelPickerWidget;