Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
feat(api): support frontend notice ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuanxin committed Jul 30, 2020
1 parent a491e5e commit 0be75a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
18 changes: 15 additions & 3 deletions frontend/components/Navigation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ClockCircleOutlined,
HomeOutlined,
} from "./../../components/Icon/";
import { NoticeReq } from './../../requests/notice'
import Darkmode from "darkmode-js";

const { Header } = Layout;
Expand All @@ -39,6 +40,7 @@ const Navigation = ({ style }) => {
const [searchColWidth, setSearchColWidth] = useState(8);
const [selectedKeys, setSelectedKeys] = useState([router.route]);
const [isLightMode, setIsLightMode] = useState(true);
const [notices, setNotices] = useState([])
const nav = [
{
title: "首页",
Expand Down Expand Up @@ -78,8 +80,18 @@ const Navigation = ({ style }) => {
useEffect(() => {
refDarkmode.current = new Darkmode(darkmodeOptions);
setIsLightMode(localStorage.getItem("darkmode") !== "true");

getNotices()
}, []);

const getNotices = async () => {
const { notices } = await NoticeReq.getNotices({
size: 5,
startTime: Date.now() - 1000 * 60 * 60 * 24 * 100
})
setNotices(notices)
}

return (
<Header style={style}>
<Row
Expand Down Expand Up @@ -108,8 +120,8 @@ const Navigation = ({ style }) => {
{item.title}
</a>
) : (
<span>{item.title}</span>
)}
<span>{item.title}</span>
)}
</Menu.Item>
))}
</Menu>
Expand Down Expand Up @@ -144,7 +156,7 @@ const Navigation = ({ style }) => {
}}
/>
<Button type="text">
<Badge dot={true}>
<Badge count={notices.length} overflowCount={10}>
<BellOutlined
style={{
fontSize: "1.4em",
Expand Down
18 changes: 18 additions & 0 deletions frontend/requests/notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import axios from 'axios'

export class NoticeReq {
static async getNotices(params) {
const { startTime, size } = params

const config = {
headers: {
"Content-Type": "application/json",
},
method: "get",
url: `//localhost/notice?startTime=${startTime}&size=${size}`,
}

const axiosRes = await axios(config)
return axiosRes.data.result
}
}

0 comments on commit 0be75a9

Please sign in to comment.