diff --git a/src/main.scss b/src/main.scss index b2f03c4..e71e598 100644 --- a/src/main.scss +++ b/src/main.scss @@ -32,6 +32,13 @@ code { float: left; height: auto; } + +.float-left { + width: 100%; + height: auto; + float: left; +} + .main-header { position: relative; width: 100%; diff --git a/src/pages/index/index.module.scss b/src/pages/index/index.module.scss index 8ab7721..f66752b 100644 --- a/src/pages/index/index.module.scss +++ b/src/pages/index/index.module.scss @@ -107,7 +107,7 @@ width: 100%; height: auto; box-sizing: border-box; - padding: 96px 20px 55px 20px; + padding: 0px 20px 55px 20px; text-align: left; overflow-x: hidden; overflow-y: auto; diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 83d66c9..eec950d 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,5 +1,6 @@ import { useEffect, useRef, useState } from "react"; -import { Dropdown, Skeleton, Tabs } from "antd-mobile"; +import { Dropdown, PullToRefresh, Skeleton, Tabs } from "antd-mobile"; +import { sleep } from "antd-mobile/es/utils/sleep"; import { DropdownRef } from "antd-mobile/es/components/dropdown"; import { user } from "../../api/index"; import styles from "./index.module.scss"; @@ -71,14 +72,15 @@ const IndexPage = () => { }, []); useEffect(() => { + setLoading(true); if (currentDepId === 0) { + setLoading(false); return; } getData(); }, [currentDepId, categoryId]); const getData = () => { - setLoading(true); user.courses(currentDepId, categoryId).then((res: any) => { const records = res.data.learn_course_records; setLearnCourseRecords(records); @@ -265,61 +267,74 @@ const IndexPage = () => { -
- {loading && - Array.from({ length: 2 }).map((_, i) => ( -
- -
- - -
-
- ))} - {!loading && coursesList.length === 0 && } - {!loading && coursesList.length > 0 && ( - <> - {coursesList.map((item: any) => ( -
- -
- ))} - - - )} +
+ { + setLoading(true); + await sleep(700); + getData(); + }} + > +
+ {loading && + Array.from({ length: 2 }).map((_, i) => ( +
+ +
+ + +
+
+ ))} + {!loading && coursesList.length === 0 && } + {!loading && coursesList.length > 0 && ( + <> + {coursesList.map((item: any) => ( +
+ +
+ ))} + + + )} +
{" "} +
); diff --git a/src/pages/study/index.tsx b/src/pages/study/index.tsx index 1b87bb1..9326999 100644 --- a/src/pages/study/index.tsx +++ b/src/pages/study/index.tsx @@ -1,5 +1,6 @@ import { useState, useEffect } from "react"; -import { Skeleton } from "antd-mobile"; +import { PullToRefresh, Skeleton } from "antd-mobile"; +import { sleep } from "antd-mobile/es/utils/sleep"; import styles from "./index.module.scss"; import { course } from "../../api/index"; import { Empty } from "../../components"; @@ -17,14 +18,11 @@ const StudyPage = () => { }, []); useEffect(() => { + setLoading(true); getCourses(); }, []); const getCourses = () => { - if (loading) { - return; - } - setLoading(true); course .latestLearn() .then((res: any) => { @@ -61,87 +59,97 @@ const StudyPage = () => { return (
最近学习
-
- {loading && - Array.from({ length: 2 }).map((_, i) => ( -
- -
- - -
-
- ))} - {!loading && - courses.length === 0 && - todayCourses.length === 0 && - yesterdayCourses.length === 0 && } - {!loading && ( - <> - {todayCourses.length > 0 && ( - <> -
今日
- {todayCourses.map((item: any, index: number) => ( -
- {item.course && ( - - )} +
+ { + setLoading(true); + await sleep(700); + getCourses(); + }} + > +
+ {loading && + Array.from({ length: 2 }).map((_, i) => ( +
+ +
+ +
- ))} +
+ ))} + {!loading && + courses.length === 0 && + todayCourses.length === 0 && + yesterdayCourses.length === 0 && } + {!loading && ( + <> + {todayCourses.length > 0 && ( + <> +
今日
+ {todayCourses.map((item: any, index: number) => ( +
+ {item.course && ( + + )} +
+ ))} + + )} + {yesterdayCourses.length > 0 && ( + <> +
昨日
+ {yesterdayCourses.map((item: any, index: number) => ( +
+ {item.course && ( + + )} +
+ ))} + + )} + {courses.length > 0 && ( + <> +
更早
+ {courses.map((item: any, index: number) => ( +
+ {item.course && ( + + )} +
+ ))} + + )} )} - {yesterdayCourses.length > 0 && ( - <> -
昨日
- {yesterdayCourses.map((item: any, index: number) => ( -
- {item.course && ( - - )} -
- ))} - - )} - {courses.length > 0 && ( - <> -
更早
- {courses.map((item: any, index: number) => ( -
- {item.course && ( - - )} -
- ))} - - )} - - )} +
+
);