feat: 🎸 更新了一部分接口请求信息
This commit is contained in:
@@ -3,18 +3,10 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.loading-indicator {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.no-more-data {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Empty } from "@arco-design/web-react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setLoadingFalse } from "@/store/slices/loadingSlice";
|
||||
|
||||
const InfiniteScroll = ({
|
||||
loadMore,
|
||||
@@ -11,21 +8,18 @@ const InfiniteScroll = ({
|
||||
threshold = 50,
|
||||
className = "",
|
||||
}) => {
|
||||
const dispatch = useDispatch();
|
||||
const containerRef = useRef(null);
|
||||
const globalLoading = useSelector((state) => state.loading.value);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleScroll = () => {
|
||||
if (loading) return;
|
||||
setLoading(true);
|
||||
if (!containerRef.current || globalLoading || !hasMore) return;
|
||||
if (!containerRef.current || !hasMore) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = containerRef.current;
|
||||
|
||||
if (scrollTop + clientHeight >= scrollHeight - threshold) {
|
||||
loadMore().finally(() => {
|
||||
dispatch(setLoadingFalse());
|
||||
setLoading(false);
|
||||
});
|
||||
}
|
||||
@@ -44,7 +38,7 @@ const InfiniteScroll = ({
|
||||
container.removeEventListener("scroll", handleScroll);
|
||||
}
|
||||
};
|
||||
}, [loadMore, hasMore, threshold, globalLoading]);
|
||||
}, [loadMore, hasMore, threshold]);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -52,7 +46,7 @@ const InfiniteScroll = ({
|
||||
className={`infinite-scroll-container ${className}`}
|
||||
>
|
||||
{children}
|
||||
{!hasMore && !globalLoading && <Empty description="没有更多了" />}
|
||||
{!hasMore && !loading && <Empty description="没有更多了" />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { Spin } from "@arco-design/web-react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { getLoginStudentInfo } from "@/services";
|
||||
import { setStudentInfo } from "@/store/slices/studentSlice";
|
||||
import Sidebar from "../Sidebar";
|
||||
import "./index.css";
|
||||
|
||||
const Layout = ({ children }) => {
|
||||
const loading = useSelector((state) => state.loading.value);
|
||||
const dispatch = useDispatch();
|
||||
const [isCollapsed, setIsCollapsed] = useState(true);
|
||||
const loading = useSelector((state) => state.loading.value);
|
||||
const studentInfo = useSelector((state) => state.student.studentInfo);
|
||||
|
||||
const queryLoginStudentInfo = async () => {
|
||||
const res = await getLoginStudentInfo();
|
||||
dispatch(setStudentInfo(res));
|
||||
};
|
||||
|
||||
// 初始化项目统一获取登录用户信息
|
||||
useEffect(() => {
|
||||
if (!studentInfo) {
|
||||
queryLoginStudentInfo();
|
||||
}
|
||||
}, [studentInfo]);
|
||||
|
||||
return (
|
||||
<div className="app-layout">
|
||||
|
||||
Reference in New Issue
Block a user