entry.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React, {
  2. useMemo,
  3. useState,
  4. forwardRef,
  5. useImperativeHandle,
  6. useRef,
  7. } from "react";
  8. import styles from "./entry.module.scss";
  9. import "./style/global.less";
  10. import Easy from "./pages/Alarm/components/easy";
  11. import Complex from "./pages/Alarm/components/complex";
  12. import { getAntdToken } from "./utils/theme";
  13. import ThemeWrapper from "./utils/theme/ThemeWrapper";
  14. import { ConfigProvider, App } from "antd";
  15. import zhCN from "antd/es/locale/zh_CN";
  16. import "./utils/theme/customStyle.less";
  17. import "dayjs/locale/zh-cn";
  18. import dayjs from "dayjs";
  19. dayjs.locale("zh-cn");
  20. const EasyConfig = forwardRef((props, ref) => {
  21. const { editId = -1, onConfirm } = props;
  22. const compRef = useRef(null);
  23. const [themeName, setThemeName] = useState();
  24. const antdToken = useMemo(() => {
  25. if (themeName) {
  26. return getAntdToken(themeName);
  27. }
  28. }, [themeName]);
  29. useImperativeHandle(ref, () => {
  30. return {
  31. ok: compRef?.current?.ok,
  32. };
  33. });
  34. return (
  35. <ThemeWrapper setThemeName={setThemeName}>
  36. {themeName && (
  37. <ConfigProvider
  38. locale={zhCN}
  39. theme={antdToken}
  40. autoInsertSpaceInButton={false}
  41. >
  42. <App className={styles.App}>
  43. <Easy ref={compRef} alarmId={editId} onConfirm={onConfirm} />
  44. </App>
  45. </ConfigProvider>
  46. )}
  47. </ThemeWrapper>
  48. );
  49. });
  50. const ComplexConfig = forwardRef((props, ref) => {
  51. const { editId = -1, onConfirm } = props;
  52. const compRef = useRef(null);
  53. const [themeName, setThemeName] = useState();
  54. const antdToken = useMemo(() => {
  55. if (themeName) {
  56. return getAntdToken(themeName);
  57. }
  58. }, [themeName]);
  59. useImperativeHandle(ref, () => {
  60. return {
  61. ok: compRef?.current?.ok,
  62. };
  63. });
  64. console.log(compRef);
  65. return (
  66. <ThemeWrapper setThemeName={setThemeName}>
  67. {themeName && (
  68. <ConfigProvider
  69. locale={zhCN}
  70. theme={antdToken}
  71. autoInsertSpaceInButton={false}
  72. >
  73. <App className={styles.App}>
  74. <Complex ref={compRef} alarmId={editId} onConfirm={onConfirm} />
  75. </App>
  76. </ConfigProvider>
  77. )}
  78. </ThemeWrapper>
  79. );
  80. });
  81. export default {
  82. EasyConfig,
  83. ComplexConfig,
  84. };