ChapterChannelSelect.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Col, List, Modal, Progress, Row, Space, Typography } from "antd";
  2. import ChannelListItem from "../channel/ChannelListItem";
  3. import type { IChapterChannelData } from "./ChapterInChannel"
  4. import { LikeOutlined, EyeOutlined } from "@ant-design/icons";
  5. import { useState } from "react";
  6. import TimeShow from "../general/TimeShow";
  7. const { Text } = Typography;
  8. /**
  9. * 章节中的版本选择对话框
  10. * @returns
  11. */
  12. interface IWidget {
  13. trigger?: JSX.Element | string;
  14. channels?: IChapterChannelData[];
  15. currChannel?: string;
  16. onSelect?: Function;
  17. }
  18. const ChapterChannelSelectWidget = ({
  19. trigger,
  20. channels,
  21. currChannel,
  22. onSelect,
  23. }: IWidget) => {
  24. const [open, setOpen] = useState(false);
  25. const handleCancel = () => {
  26. setOpen(false);
  27. };
  28. return (
  29. <div>
  30. <div
  31. onClick={() => {
  32. setOpen(true);
  33. }}
  34. >
  35. {trigger}
  36. </div>
  37. <Modal
  38. title="版本选择"
  39. open={open}
  40. onCancel={handleCancel}
  41. onOk={handleCancel}
  42. >
  43. <List
  44. style={{ maxWidth: 500 }}
  45. itemLayout="vertical"
  46. size="small"
  47. dataSource={channels}
  48. pagination={
  49. currChannel
  50. ? undefined
  51. : {
  52. showQuickJumper: false,
  53. showSizeChanger: false,
  54. pageSize: 5,
  55. total: channels?.length,
  56. position: "bottom",
  57. showTotal: (total) => {
  58. return `结果: ${total}`;
  59. },
  60. }
  61. }
  62. renderItem={(item, id) => (
  63. <List.Item key={id}>
  64. <Row>
  65. <Col span={12}>
  66. <div
  67. onClick={() => {
  68. if (typeof onSelect !== "undefined") {
  69. onSelect(item.channel.id);
  70. }
  71. }}
  72. >
  73. <ChannelListItem
  74. channel={item.channel}
  75. studio={item.studio}
  76. />
  77. </div>
  78. </Col>
  79. <Col span={12}>
  80. <Progress percent={item.progress} size="small" />
  81. </Col>
  82. </Row>
  83. <Text type="secondary">
  84. <Space style={{ paddingLeft: "2em" }}>
  85. <EyeOutlined />
  86. {item.hit} | <LikeOutlined />
  87. {item.like} |
  88. <TimeShow updatedAt={item.updatedAt} />
  89. </Space>
  90. </Text>
  91. </List.Item>
  92. )}
  93. />
  94. </Modal>
  95. </div>
  96. );
  97. };
  98. export default ChapterChannelSelectWidget;