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.

118 lines
3.2 KiB

11 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
11 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
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. const LayoutRouter = () => {
  14. const { push, location } = useRouter()
  15. const [visible, setVisible] = useState(false)
  16. const { token, screenWidth } = store.state
  17. const [notifys, setNotifys] = useState([] as any)
  18. //
  19. useEffect(() => {
  20. window.addEventListener("resize", (e) => {
  21. const _width = window.innerWidth;
  22. store.setScreenWidth(_width)
  23. })
  24. window.onload = () => {
  25. const _width = window.innerWidth;
  26. store.setScreenWidth(_width)
  27. }
  28. }, [])
  29. useEffect(() => {
  30. if (!token && !unLoginPath.includes(location.pathname) && location.pathname !== "/submit") {
  31. push('/login', null, true)
  32. }
  33. if (token && unLoginPath.includes(location.pathname) && location.pathname !== "/submit") {
  34. push('/', null, true)
  35. }
  36. }, [location.pathname, token])
  37. const isShowNotifyModal = async () => {
  38. try {
  39. const res: any = await http_notify()
  40. if (res.code === 0) {
  41. console.log(res);
  42. setNotifys(res.data)
  43. const type = window.localStorage.getItem('NotifyStatus') || NotifyStatus_Type.show
  44. if (type === NotifyStatus_Type.show && res.data && res.data.length > 0) {
  45. setVisible(true)
  46. window.localStorage.setItem('NotifyStatus', NotifyStatus_Type.hidden)
  47. }
  48. }
  49. } catch (error) {
  50. }
  51. }
  52. useEffect(() => {
  53. token && store.getUserInfo()
  54. token && store.getReceiveAccount()
  55. !token && store.resetUserInfo()
  56. !token && store.resetReceiveAccount()
  57. if (token) {
  58. isShowNotifyModal()
  59. }
  60. }, [token])
  61. return (
  62. <>
  63. {
  64. !token ? (
  65. <RenderRouter />
  66. ) : (
  67. <div className="layout">
  68. <div className="container-header"></div>
  69. <div className="container-aplication">
  70. {
  71. screenWidth > 1000 && <Slider />
  72. }
  73. <div style={{ paddingLeft: screenWidth > 1000 ? 40 : 0, flex: 1 }}>
  74. <Header />
  75. <div className="divider"></div>
  76. <RenderRouter />
  77. </div>
  78. </div>
  79. </div>
  80. )
  81. }
  82. <Modal
  83. open={visible}
  84. onCancel={() => setVisible(false)}
  85. footer={() => null}
  86. width={screenWidth > 1000 ? '60%' : '90%'}
  87. title="平台公告"
  88. >
  89. <div style={{ minHeight: 300 }}>
  90. {
  91. notifys.map((item: any) => (
  92. <div key={item.id} className="mt-2">
  93. <div className="fz-wb-550">{item.title}</div>
  94. <div dangerouslySetInnerHTML={{ __html: item.content }} className="mt-1"></div>
  95. <Divider />
  96. </div>
  97. ))
  98. }
  99. </div>
  100. </Modal>
  101. </>
  102. )
  103. }
  104. export default observer(LayoutRouter);