From 0ea7eff03d16b9657bfd4dbf74d52abc9b5777e5 Mon Sep 17 00:00:00 2001 From: Dawn1Ocean <1785590531@qq.com> Date: Tue, 16 Apr 2024 19:30:44 +0800 Subject: [PATCH] temp --- mock/requestRecord.mock.js | 14 +++++++++----- mock/user.ts | 3 --- src/pages/Welcome/index.tsx | 21 ++++++++++++++++++++- src/services/api.ts | 10 ++++++++++ src/services/typings.d.ts | 8 ++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/mock/requestRecord.mock.js b/mock/requestRecord.mock.js index b3c0f7d..c7f42cd 100644 --- a/mock/requestRecord.mock.js +++ b/mock/requestRecord.mock.js @@ -1,15 +1,19 @@ +import conclusionlist from './conclusionlist.json'; import loglist from './loglist.json'; +import reportlist from './reportlist.json'; import sheet from './sheet.json'; import sheetlist from './sheetlist.json'; -import reportlist from './reportlist.json'; -import conclusionlist from './conclusionlist.json'; module.exports = { - 'GET /admin/stats': { + 'GET /stats': { success: true, data: { - notInOreo: 114, - total: 514, + todayPT: 114, // 今日预填写工单总数 + totalPT: 514, // 所有预填写工单 + oreo: 93, // 加入 Oreo 工单数 + report: 8, // 今日反馈数 + allSuccess: 1919, // 所有成功工单(包括 Oreo 内) + all: 2024, // 所有工单(包括 Oreo 内) }, }, 'POST /admin/sheet/update': { diff --git a/mock/user.ts b/mock/user.ts index d0596b9..0c9763d 100644 --- a/mock/user.ts +++ b/mock/user.ts @@ -154,9 +154,6 @@ export default { access = ''; res.send({ data: {}, success: true }); }, - 'POST /api/register': (req: Request, res: Response) => { - res.send({ status: 'ok', currentAuthority: 'user', success: true }); - }, 'GET /api/500': (req: Request, res: Response) => { res.status(500).send({ timestamp: 1513932555104, diff --git a/src/pages/Welcome/index.tsx b/src/pages/Welcome/index.tsx index 5d0bb35..6556955 100644 --- a/src/pages/Welcome/index.tsx +++ b/src/pages/Welcome/index.tsx @@ -1,9 +1,10 @@ +import { getStat } from '@/services/api'; import type { TinyRingConfig } from '@ant-design/charts'; import { Tiny } from '@ant-design/charts'; import { PageContainer, ProCard, StatisticCard } from '@ant-design/pro-components'; import { Card, Statistic } from 'antd'; import RcResizeObserver from 'rc-resize-observer'; -import { useState } from 'react'; +import { useLayoutEffect, useState } from 'react'; const percentRing = (percent: number, frontColor: string): React.JSX.Element => { const TinyRing = Tiny.Ring as (props: TinyRingConfig) => JSX.Element; @@ -50,6 +51,24 @@ const indexData: IndexData = { const Logs: React.FC = () => { const [responsive, setResponsive] = useState(false); + const [todayPT, setTodayPT] = useState(0); + const [report, setReport] = useState(0); + const [oreo, setOreo] = useState(0); + const [totalPT, setTotalPT] = useState(0); + const [allSuccess, setAllSuccess] = useState(0); + const [all, setAll] = useState(0); + + useLayoutEffect(() => { + getStat().then((res) => { + const data = res.data; + setTodayPT(data.todayPT); + setReport(data.report); + setOreo(data.oreo); + setTotalPT(data.totalPT); + setAllSuccess(data.allSuccess); + setAll(data.all); + }) + }); return ( diff --git a/src/services/api.ts b/src/services/api.ts index 8fa0224..bcf53cb 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -32,3 +32,13 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an ...(options || {}), }); } + +/** 获取首页信息 GET /admin/stat */ +export async function getStat(options?: { [key: string]: any }) { + return request<{ + data: API.Stat; + }>('/stat', { + method: 'GET', + ...(options || {}), + }); +} diff --git a/src/services/typings.d.ts b/src/services/typings.d.ts index c4df2ba..2c5c6c5 100644 --- a/src/services/typings.d.ts +++ b/src/services/typings.d.ts @@ -54,4 +54,12 @@ declare namespace API { size: number; data: LogsItem[]; }; + type Stat = { + todayPT: number; + totalPT: number; + oreo: number; + report: number; + allSuccess: number; + all: number; + }; }