From e7be30c7006981bf0fdba46fd7d7a013219955c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Thu, 23 Mar 2023 10:49:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=A6=82=E8=A7=88=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/dashboard.ts | 5 + src/api/index.ts | 1 + src/pages/dashboard/index.tsx | 217 +++++++++++++++++++--------------- src/utils/index.ts | 18 +++ 4 files changed, 147 insertions(+), 94 deletions(-) create mode 100644 src/api/dashboard.ts diff --git a/src/api/dashboard.ts b/src/api/dashboard.ts new file mode 100644 index 0000000..27bb381 --- /dev/null +++ b/src/api/dashboard.ts @@ -0,0 +1,5 @@ +import client from "./internal/httpClient"; + +export function dashboardList() { + return client.get("/backend/v1/dashboard/index", {}); +} diff --git a/src/api/index.ts b/src/api/index.ts index 8ff0c83..ad717e8 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -12,3 +12,4 @@ export * as resource from "./resource"; export * as upload from "./upload"; export * as user from "./user"; export * as appConfig from "./app-config"; +export * as dashboard from "./dashboard"; diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx index f808f25..403ef47 100644 --- a/src/pages/dashboard/index.tsx +++ b/src/pages/dashboard/index.tsx @@ -8,19 +8,28 @@ import iconN1 from "../../assets/images/dashboard/icon-n1.png"; import iconN2 from "../../assets/images/dashboard/icon-n2.png"; import iconN3 from "../../assets/images/dashboard/icon-n3.png"; import { Footer } from "../../compenents/footer"; +import { dashboard } from "../../api/index"; +import { timeFormat } from "../../utils/index"; export const Dashboard: React.FC = () => { const navigate = useNavigate(); + const [basicData, setBasicData] = useState([]); useEffect(() => { - renderPieView({ - videos_count: 30, - images_count: 10, - }); - return () => { - window.onresize = null; - }; + getData(); }, []); + const getData = () => { + dashboard.dashboardList().then((res: any) => { + setBasicData(res.data); + renderPieView({ + videos_count: res.data.resource_video_total, + images_count: res.data.resource_image_total, + }); + return () => { + window.onresize = null; + }; + }); + }; const renderPieView = (params: any) => { let num = params.videos_count + params.images_count; @@ -124,6 +133,25 @@ export const Dashboard: React.FC = () => { }; }; + const compareNum = (today: number, yesterday: number) => { + let num = today - yesterday; + if (num < 0) { + return ( + + + {Math.abs(num)} + + ); + } else { + return ( + + + {Math.abs(num)} + + ); + } + }; + return ( <> @@ -133,31 +161,32 @@ export const Dashboard: React.FC = () => {
今日学习学员
-
300
+
+ {basicData.user_learn_today} +
较昨日 - - 100 - + {compareNum( + basicData.user_learn_today, + basicData.user_learn_yesterday + )}
总学员数
-
3000
+
{basicData.user_total}
较昨日 - - 100 - + {compareNum(basicData.user_today, basicData.user_yesterday)}
线上课数
-
20
+
{basicData.course_total}
@@ -215,84 +244,78 @@ export const Dashboard: React.FC = () => { -
+
今日学习排行
-
-
-
-
- -
忻咏
+ {basicData.user_learn_top10 && + basicData.user_learn_top10.length > 0 && ( +
+
+ {basicData.user_learn_top10.map( + (item: any, index: number) => + index <= 4 && ( +
+
+ {index === 0 && ( + + )} + {index === 1 && ( + + )} + {index === 2 && ( + + )} + {index > 2 && ( +
+ {index} +
+ )} +
+ {item.user_id} +
+
+
+ {timeFormat(Number(item.duration) / 1000)} +
+
+ ) + )}
-
1小时24秒
+ {basicData.user_learn_top10.length > 5 && ( +
+ {basicData.user_learn_top10.map( + (item: any, index: number) => + index > 4 && ( +
+
+
+ {index} +
+
+ {item.user_id} +
+
+
+ {timeFormat(Number(item.duration) / 1000)} +
+
+ ) + )} +
+ )}
-
-
- -
蒋建
-
-
1小时24秒
-
-
-
- -
谭茂
-
-
1小时24秒
-
-
-
-
4
-
渠雅眉
-
-
1小时24秒
-
-
-
-
5
-
柴晨
-
-
1小时24秒
-
-
-
-
-
-
6
-
柴晨
-
-
1小时24秒
-
-
-
-
7
-
柴晨
-
-
1小时24秒
-
-
-
-
8
-
柴晨
-
-
1小时24秒
-
-
-
-
9
-
柴晨
-
-
1小时24秒
-
-
-
-
10
-
柴晨
-
-
1小时24秒
-
-
-
+ )}
@@ -301,19 +324,25 @@ export const Dashboard: React.FC = () => {
部门数
-
8
+
+ {basicData.department_total} +
分类数
-
2
+
+ {basicData.resource_category_total} +
管理员
-
8
+
+ {basicData.admin_user_total} +
diff --git a/src/utils/index.ts b/src/utils/index.ts index 8b88130..a468cf1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -18,6 +18,24 @@ export function dateFormat(dateStr: string) { return moment(dateStr).format("YYYY-MM-DD HH:mm"); } +export function timeFormat(dateStr: number) { + var d = moment.duration(dateStr, "seconds"); + let value = + Math.floor(d.asDays()) + + "天" + + d.hours() + + "时" + + d.minutes() + + "分" + + d.seconds() + + "秒"; + + if (Math.floor(d.asDays()) === 0) { + value = d.hours() + "时" + d.minutes() + "分" + d.seconds() + "秒"; + } + return value; +} + export function generateUUID(): string { let guid = ""; for (let i = 1; i <= 32; i++) {