diff --git a/src/components/InfiniteScroll/index.css b/src/components/InfiniteScroll/index.css index 2a2a57c..6f0dbcb 100644 --- a/src/components/InfiniteScroll/index.css +++ b/src/components/InfiniteScroll/index.css @@ -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; -} \ No newline at end of file +} diff --git a/src/components/InfiniteScroll/index.jsx b/src/components/InfiniteScroll/index.jsx index 96df6ca..f718c1f 100644 --- a/src/components/InfiniteScroll/index.jsx +++ b/src/components/InfiniteScroll/index.jsx @@ -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 (
加载中...
-- 学号: {profile?.studentId} + 学号: {studentInfo?.studentNo || "-"}
学习情况
diff --git a/src/services/global.js b/src/services/global.js index 477a82b..f7e056b 100644 --- a/src/services/global.js +++ b/src/services/global.js @@ -1,6 +1,6 @@ import request from "@/utils/request"; -// 获取学生信息 -export async function getCurrentStudent() { +// 获取当前登录学生信息 +export async function getLoginStudentInfo() { return request.get("/api/students/me"); } diff --git a/src/services/index.js b/src/services/index.js index cbe0419..d40f283 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -5,7 +5,8 @@ import { } from "./dashboard"; import { getProjectsList } from "./projectLibrary"; import { getJobsList, getInterviewsList } from "./companyJobs"; -import { getCurrentStudent } from "./global"; +import { getLoginStudentInfo } from "./global"; +import { getLoginStudentProgress } from "./personalProfile"; export { getDashboardStatistics, @@ -14,5 +15,6 @@ export { getProjectsList, getJobsList, getInterviewsList, - getCurrentStudent, + getLoginStudentInfo, + getLoginStudentProgress, }; diff --git a/src/services/personalProfile.js b/src/services/personalProfile.js new file mode 100644 index 0000000..7fa6bff --- /dev/null +++ b/src/services/personalProfile.js @@ -0,0 +1,6 @@ +import request from "@/utils/request"; + +// 获取当前登录学生学习进度 +export async function getLoginStudentProgress(id) { + return request.get(`/api/students/${id}/progress`); +} diff --git a/src/store/index.js b/src/store/index.js index 564517f..67f54c6 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,10 +1,10 @@ -import { configureStore } from '@reduxjs/toolkit'; -import loadingReducer from './slices/loadingSlice'; -import userReducer from './slices/userSlice'; // 导入新的用户reducer +import { configureStore } from "@reduxjs/toolkit"; +import loadingReducer from "./slices/loadingSlice"; +import studentReducer from "./slices/studentSlice"; export default configureStore({ reducer: { loading: loadingReducer, - user: userReducer // 添加用户reducer到store - } + student: studentReducer, + }, }); diff --git a/src/store/slices/studentSlice.js b/src/store/slices/studentSlice.js new file mode 100644 index 0000000..66a1db0 --- /dev/null +++ b/src/store/slices/studentSlice.js @@ -0,0 +1,39 @@ +import { createSlice } from "@reduxjs/toolkit"; + +// 定义初始状态 +const initialState = { + studentInfo: null, // 用户信息初始为null + isLoggedIn: false, // 登录状态初始为false +}; + +const studentSlice = createSlice({ + name: "student", + initialState, + reducers: { + // 设置用户信息 + setStudentInfo: (state, action) => { + state.studentInfo = action.payload; + state.isLoggedIn = true; + }, + // 清除用户信息 + clearStudentInfo: (state) => { + state.studentInfo = null; + state.isLoggedIn = false; + }, + // 更新用户信息的部分字段 + updateStudentInfo: (state, action) => { + if (state.studentInfo) { + state.studentInfo = { + ...state.studentInfo, + ...action.payload, + }; + } + }, + }, +}); + +// 导出actions +export const { setStudentInfo, clearStudentInfo, updateStudentInfo } = + studentSlice.actions; + +export default studentSlice.reducer; diff --git a/src/store/slices/userSlice.js b/src/store/slices/userSlice.js deleted file mode 100644 index 82f258a..0000000 --- a/src/store/slices/userSlice.js +++ /dev/null @@ -1,38 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; - -// 定义初始状态 -const initialState = { - userInfo: null, // 用户信息初始为null - isLoggedIn: false // 登录状态初始为false -}; - -const userSlice = createSlice({ - name: 'user', - initialState, - reducers: { - // 设置用户信息 - setUserInfo: (state, action) => { - state.userInfo = action.payload; - state.isLoggedIn = true; - }, - // 清除用户信息 - clearUserInfo: (state) => { - state.userInfo = null; - state.isLoggedIn = false; - }, - // 更新用户信息的部分字段 - updateUserInfo: (state, action) => { - if (state.userInfo) { - state.userInfo = { - ...state.userInfo, - ...action.payload - }; - } - } - } -}); - -// 导出actions -export const { setUserInfo, clearUserInfo, updateUserInfo } = userSlice.actions; - -export default userSlice.reducer; \ No newline at end of file