ChannelPicker.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. onClose?: Function;
  13. onSelect?: Function;
  14. }
  15. const ChannelPickerWidget = ({
  16. trigger,
  17. type,
  18. articleId,
  19. multiSelect,
  20. open = false,
  21. onClose,
  22. onSelect,
  23. }: IWidget) => {
  24. const [isModalOpen, setIsModalOpen] = useState(open);
  25. useEffect(() => {
  26. setIsModalOpen(open);
  27. }, [open]);
  28. const showModal = () => {
  29. setIsModalOpen(true);
  30. };
  31. const handleOk = () => {
  32. setIsModalOpen(false);
  33. if (typeof onClose !== "undefined") {
  34. onClose();
  35. }
  36. };
  37. const handleCancel = () => {
  38. setIsModalOpen(false);
  39. if (typeof onClose !== "undefined") {
  40. onClose();
  41. }
  42. };
  43. return (
  44. <>
  45. <span onClick={showModal}>{trigger}</span>
  46. <Modal
  47. width={"80%"}
  48. title="选择版本风格"
  49. footer={false}
  50. open={isModalOpen}
  51. onOk={handleOk}
  52. onCancel={handleCancel}
  53. >
  54. <ChannelPickerTable
  55. type={type}
  56. articleId={articleId}
  57. multiSelect={true}
  58. onSelect={(channels: IChannel[]) => {
  59. console.log(channels);
  60. handleCancel();
  61. if (typeof onClose !== "undefined") {
  62. onClose();
  63. }
  64. if (typeof onSelect !== "undefined") {
  65. onSelect(channels);
  66. }
  67. }}
  68. />
  69. </Modal>
  70. </>
  71. );
  72. };
  73. export default ChannelPickerWidget;