|
|
@ -5,14 +5,18 @@ import '../styles/app.scss' |
|
|
|
import { useRouter } from "../hooks/useRouter"; |
|
|
|
import Slider from "../components/layout/Slider"; |
|
|
|
import Header from "../components/layout/Header"; |
|
|
|
import { useEffect, useRef } from "react"; |
|
|
|
import { useEffect, useRef, useState } from "react"; |
|
|
|
import { unLoginPath } from "./routes"; |
|
|
|
import { Divider, Modal } from "antd"; |
|
|
|
import { NotifyStatus_Type } from "../types"; |
|
|
|
import { http_notify } from "../http/api"; |
|
|
|
|
|
|
|
const LayoutRouter = () => { |
|
|
|
|
|
|
|
const { push, location } = useRouter() |
|
|
|
|
|
|
|
const [visible, setVisible] = useState(false) |
|
|
|
const { token, screenWidth } = store.state |
|
|
|
const [notifys, setNotifys] = useState([] as any) |
|
|
|
//
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
@ -36,28 +40,40 @@ const LayoutRouter = () => { |
|
|
|
} |
|
|
|
}, [location.pathname, token]) |
|
|
|
|
|
|
|
const isShowNotifyModal = async () => { |
|
|
|
|
|
|
|
try { |
|
|
|
const res: any = await http_notify() |
|
|
|
if (res.code === 0) { |
|
|
|
console.log(res); |
|
|
|
|
|
|
|
setNotifys(res.data) |
|
|
|
const type = window.localStorage.getItem('NotifyStatus') || NotifyStatus_Type.show |
|
|
|
if (type === NotifyStatus_Type.show && res.data && res.data.length > 0) { |
|
|
|
setVisible(true) |
|
|
|
window.localStorage.setItem('NotifyStatus', NotifyStatus_Type.hidden) |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
token && store.getUserInfo() |
|
|
|
token && store.getReceiveAccount() |
|
|
|
!token && store.resetUserInfo() |
|
|
|
!token && store.resetReceiveAccount() |
|
|
|
}, [token]) |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
window.addEventListener('message', (res) => { |
|
|
|
if (res.origin === process.env.REACT_APP_ORIGIN) { |
|
|
|
if (res && res.data && res.data.token) { |
|
|
|
store.setToken(res.data.token) |
|
|
|
if (!window.sessionStorage.getItem('first_render')) { |
|
|
|
window.location.reload() |
|
|
|
if (token) { |
|
|
|
isShowNotifyModal() |
|
|
|
} |
|
|
|
window.sessionStorage.setItem('first_render', 'true') |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, []) |
|
|
|
}, [token]) |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
{ |
|
|
|
!token ? ( |
|
|
|
<RenderRouter /> |
|
|
|
) : ( |
|
|
@ -75,6 +91,27 @@ const LayoutRouter = () => { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
} |
|
|
|
<Modal |
|
|
|
open={visible} |
|
|
|
onCancel={() => setVisible(false)} |
|
|
|
footer={() => null} |
|
|
|
width={screenWidth > 1000 ? '60%' : '90%'} |
|
|
|
title="平台公告" |
|
|
|
> |
|
|
|
<div style={{ minHeight: 300 }}> |
|
|
|
{ |
|
|
|
notifys.map((item: any) => ( |
|
|
|
<div key={item.id} className="mt-2"> |
|
|
|
<div className="fz-wb-550">{item.title}</div> |
|
|
|
<div dangerouslySetInnerHTML={{ __html: item.content }} className="mt-1"></div> |
|
|
|
<Divider /> |
|
|
|
</div> |
|
|
|
)) |
|
|
|
} |
|
|
|
</div> |
|
|
|
</Modal> |
|
|
|
</> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|