entry.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 Detail from "./pages/Alarm/components/detail";
  13. import { getAntdToken } from "./utils/theme";
  14. import ThemeWrapper from "./utils/theme/ThemeWrapper";
  15. import { ConfigProvider, App } from "antd";
  16. import zhCN from "antd/es/locale/zh_CN";
  17. import "./utils/theme/customStyle.less";
  18. import "dayjs/locale/zh-cn";
  19. import dayjs from "dayjs";
  20. dayjs.locale("zh-cn");
  21. const EasyConfig = forwardRef((props, ref) => {
  22. const { editId = -1, onConfirm, groupList, pointId, readonly, style } = props;
  23. const compRef = useRef(null);
  24. const [themeName, setThemeName] = useState();
  25. const antdToken = useMemo(() => {
  26. if (themeName) {
  27. return getAntdToken(themeName);
  28. }
  29. }, [themeName]);
  30. useImperativeHandle(ref, () => {
  31. return {
  32. ok: compRef?.current?.ok,
  33. };
  34. });
  35. return (
  36. <ThemeWrapper setThemeName={setThemeName}>
  37. {themeName && (
  38. <ConfigProvider
  39. locale={zhCN}
  40. theme={antdToken}
  41. autoInsertSpaceInButton={false}
  42. >
  43. <App className={styles.App}>
  44. <Easy
  45. ref={compRef}
  46. editId={editId}
  47. pointId={pointId}
  48. onConfirm={onConfirm}
  49. groupList={groupList}
  50. readonly={readonly}
  51. style={style}
  52. />
  53. </App>
  54. </ConfigProvider>
  55. )}
  56. </ThemeWrapper>
  57. );
  58. });
  59. const ComplexConfig = forwardRef((props, ref) => {
  60. const { editId = -1, onConfirm, groupList, showList, style, rightStyle } = props;
  61. const compRef = useRef(null);
  62. const [themeName, setThemeName] = useState();
  63. const antdToken = useMemo(() => {
  64. if (themeName) {
  65. return getAntdToken(themeName);
  66. }
  67. }, [themeName]);
  68. useImperativeHandle(ref, () => {
  69. return {
  70. ok: compRef?.current?.ok,
  71. };
  72. });
  73. return (
  74. <ThemeWrapper setThemeName={setThemeName}>
  75. {themeName && (
  76. <ConfigProvider
  77. locale={zhCN}
  78. theme={antdToken}
  79. autoInsertSpaceInButton={false}
  80. >
  81. <App className={styles.App}>
  82. <Complex
  83. ref={compRef}
  84. editId={editId}
  85. onConfirm={onConfirm}
  86. groupList={groupList}
  87. showList={showList}
  88. style={style}
  89. rightStyle={rightStyle}
  90. />
  91. </App>
  92. </ConfigProvider>
  93. )}
  94. </ThemeWrapper>
  95. );
  96. });
  97. const DetailModal = (props) => {
  98. const [themeName, setThemeName] = useState();
  99. const antdToken = useMemo(() => {
  100. if (themeName) {
  101. return getAntdToken(themeName);
  102. }
  103. }, [themeName]);
  104. return (
  105. <ThemeWrapper setThemeName={setThemeName}>
  106. {themeName && (
  107. <ConfigProvider
  108. locale={zhCN}
  109. theme={antdToken}
  110. autoInsertSpaceInButton={false}
  111. >
  112. <App className={styles.App}>
  113. <Detail {...props} />
  114. </App>
  115. </ConfigProvider>
  116. )}
  117. </ThemeWrapper>
  118. );
  119. };
  120. export default {
  121. EasyConfig,
  122. ComplexConfig,
  123. DetailModal,
  124. };