feat: 🎸 更新了一部分接口请求信息

This commit is contained in:
2025-08-20 22:39:05 +08:00
parent d4b4bc82f3
commit 9895101fde
13 changed files with 116 additions and 141 deletions

View File

@@ -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,
},
});

View File

@@ -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;

View File

@@ -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;