Reference.tsx 1.0 KB

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