WordCount.tsx 891 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Descriptions, Modal } from "antd";
  2. import { LoadingOutlined } from "@ant-design/icons";
  3. import { useArticle } from "./hooks/useArticle";
  4. interface IWidget {
  5. open?: boolean;
  6. articleId?: string;
  7. onClose?: () => void;
  8. }
  9. const WordCount = ({ open = false, articleId, onClose }: IWidget) => {
  10. const { data, loading } = useArticle(articleId, {
  11. format: "text",
  12. origin: true,
  13. });
  14. const wordAll = data?.html?.length ?? 0;
  15. return (
  16. <Modal
  17. destroyOnHidden={true}
  18. width={700}
  19. title="字数统计"
  20. open={open}
  21. footer={false}
  22. onOk={onClose}
  23. onCancel={onClose}
  24. >
  25. {loading ? (
  26. <LoadingOutlined />
  27. ) : (
  28. <Descriptions title="字数">
  29. <Descriptions.Item label="全部字符">{wordAll}</Descriptions.Item>
  30. </Descriptions>
  31. )}
  32. </Modal>
  33. );
  34. };
  35. export default WordCount;