You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.6 KiB

11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
  1. import { observer } from "mobx-react";
  2. import RenderRouter from "./renderRouter";
  3. import store from "../store";
  4. import '../styles/app.scss'
  5. import { useRouter } from "../hooks/useRouter";
  6. import Slider from "../components/layout/Slider";
  7. import Header from "../components/layout/Header";
  8. import { useEffect, useRef, useState } from "react";
  9. import { unLoginPath } from "./routes";
  10. import { Divider, Modal } from "antd";
  11. import { NotifyStatus_Type } from "../types";
  12. import { http_notify } from "../http/api";
  13. import { useTranslation } from "react-i18next";
  14. import LanguageMenu from "../components/LanguageMenu";
  15. const LayoutRouter = () => {
  16. const { push, location } = useRouter()
  17. const [visible, setVisible] = useState(false)
  18. const { token, screenWidth } = store.state
  19. const [notifys, setNotifys] = useState([] as any)
  20. const { t } = useTranslation()
  21. //
  22. useEffect(() => {
  23. window.addEventListener("resize", (e) => {
  24. const _width = window.innerWidth;
  25. store.setScreenWidth(_width)
  26. })
  27. window.onload = () => {
  28. const _width = window.innerWidth;
  29. store.setScreenWidth(_width)
  30. }
  31. }, [])
  32. useEffect(() => {
  33. if (!token && !unLoginPath.includes(location.pathname) && location.pathname !== "/submit") {
  34. push('/login', null, true)
  35. }
  36. if (token && unLoginPath.includes(location.pathname) && location.pathname !== "/submit") {
  37. push('/', null, true)
  38. }
  39. }, [location.pathname, token])
  40. const isShowNotifyModal = async () => {
  41. try {
  42. const res: any = await http_notify()
  43. if (res.code === 0) {
  44. setNotifys(res.data)
  45. const type = window.localStorage.getItem('NotifyStatus') || NotifyStatus_Type.show
  46. if (type === NotifyStatus_Type.show && res.data && res.data.length > 0) {
  47. setVisible(true)
  48. window.localStorage.setItem('NotifyStatus', NotifyStatus_Type.hidden)
  49. }
  50. }
  51. } catch (error) {
  52. }
  53. }
  54. useEffect(() => {
  55. token && store.getUserInfo()
  56. token && store.getReceiveAccount()
  57. !token && store.resetUserInfo()
  58. !token && store.resetReceiveAccount()
  59. if (token) {
  60. isShowNotifyModal()
  61. }
  62. }, [token])
  63. if (location.pathname === '/submit') return <></>
  64. return (
  65. <>
  66. {
  67. !token ? (
  68. <>
  69. <div style={{ position: 'absolute', top: 20, right: 20 }}>
  70. <LanguageMenu width={40} />
  71. </div>
  72. <RenderRouter />
  73. </>
  74. ) : (
  75. <div className="layout">
  76. <div className="container-header"></div>
  77. <div className="container-aplication">
  78. {
  79. screenWidth > 1000 && <Slider />
  80. }
  81. <div style={{ paddingLeft: screenWidth > 1000 ? 40 : 0, flex: 1 }}>
  82. <Header />
  83. <div className="divider"></div>
  84. <RenderRouter />
  85. </div>
  86. </div>
  87. </div>
  88. )
  89. }
  90. <Modal
  91. open={visible}
  92. onCancel={() => setVisible(false)}
  93. footer={() => null}
  94. width={screenWidth > 1000 ? '60%' : '90%'}
  95. title={t('Platform announcement')}
  96. >
  97. <div style={{ minHeight: 300 }}>
  98. {
  99. notifys.map((item: any) => (
  100. <div key={item.id} className="mt-2">
  101. <div className="fz-wb-550">{item.title}</div>
  102. <div dangerouslySetInnerHTML={{ __html: item.content }} className="mt-1"></div>
  103. <Divider />
  104. </div>
  105. ))
  106. }
  107. </div>
  108. </Modal>
  109. </>
  110. )
  111. }
  112. export default observer(LayoutRouter);