Reference.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Typography } from "antd";
  2. import { useIntl } from "react-intl";
  3. const { Text, Paragraph } = Typography;
  4. const ucFirst = (input: string) => {
  5. if (typeof input !== "string" || input.length === 0) {
  6. return input; // 如果输入不是字符串或者字符串为空,则直接返回原值
  7. }
  8. return input.charAt(0).toUpperCase() + input.slice(1);
  9. };
  10. interface IReference {
  11. sn: number;
  12. title: string;
  13. copyright: string;
  14. }
  15. interface IReferenceCtl {
  16. pali?: IReference[];
  17. }
  18. const ReferenceCtl = ({ pali }: IReferenceCtl) => {
  19. const intl = useIntl();
  20. const Reference = (ref: IReference) => {
  21. return (
  22. <Paragraph>{`[${ref.sn}] ${ucFirst(ref.title)} ${
  23. ref.copyright
  24. }`}</Paragraph>
  25. );
  26. };
  27. return (
  28. <>
  29. {pali?.map((item, id) => {
  30. return Reference(item);
  31. })}
  32. </>
  33. );
  34. };
  35. interface IWidget {
  36. props: string;
  37. }
  38. const Widget = ({ props }: IWidget) => {
  39. const prop = JSON.parse(atob(props)) as IReferenceCtl;
  40. console.log(prop);
  41. return (
  42. <>
  43. <ReferenceCtl {...prop} />
  44. </>
  45. );
  46. };
  47. export default Widget;