@@ -127,47 +127,46 @@ const KnowledgeBaseForm = ({
{/* 仅当不是私有知识库时才显示部门选项 */}
- {formData.type === 'member' ||
- (formData.type === 'leader' && (
-
-
- {isAdmin ? (
- <>
-
- {formErrors.department && (
-
{formErrors.department}
- )}
- >
- ) : (
- <>
-
- >
- )}
-
- ))}
+ {(formData.type === 'member' || formData.type === 'leader') && (
+
+
+ {isAdmin ? (
+ <>
+
+ {formErrors.department && (
+
{formErrors.department}
+ )}
+ >
+ ) : (
+ <>
+
+ >
+ )}
+
+ )}
{/* 仅当不是私有知识库时才显示组别选项 */}
{formData.type === 'member' && (
diff --git a/src/services/websocket.js b/src/services/websocket.js
index 9c8e6e4..9902e19 100644
--- a/src/services/websocket.js
+++ b/src/services/websocket.js
@@ -2,7 +2,7 @@ import { addNotification, markNotificationAsRead } from '../store/notificationCe
import store from '../store/store'; // 修改为默认导出
// 从环境变量获取 API URL
-const API_URL = import.meta.env.VITE_API_URL || '';
+const API_URL = import.meta.env.VITE_API_URL || 'http://81.69.223.133:8008';
// 将 HTTP URL 转换为 WebSocket URL
const WS_BASE_URL = API_URL.replace(/^http/, 'ws').replace(/\/api\/?$/, '');
diff --git a/src/store/auth/auth.slice.js b/src/store/auth/auth.slice.js
index e5f2bb4..2dc029b 100644
--- a/src/store/auth/auth.slice.js
+++ b/src/store/auth/auth.slice.js
@@ -1,10 +1,9 @@
import { createSlice } from '@reduxjs/toolkit';
-import { checkAuthThunk, loginThunk, logoutThunk, signupThunk } from './auth.thunk';
+import { checkAuthThunk, loginThunk, logoutThunk, signupThunk, updateProfileThunk } from './auth.thunk';
const setPending = (state) => {
state.loading = true;
state.error = null;
- state.user = null;
};
const setFulfilled = (state, action) => {
@@ -49,6 +48,16 @@ const authSlice = createSlice({
.addCase(signupThunk.fulfilled, setFulfilled)
.addCase(signupThunk.rejected, setRejected)
+ .addCase(updateProfileThunk.pending, setPending)
+ .addCase(updateProfileThunk.fulfilled, (state, action) => {
+ state.user = {
+ ...state.user,
+ ...action.payload,
+ };
+ state.loading = false;
+ })
+ .addCase(updateProfileThunk.rejected, setRejected)
+
.addCase(logoutThunk.pending, (state) => {
state.loading = true;
state.error = null;
diff --git a/src/store/auth/auth.thunk.js b/src/store/auth/auth.thunk.js
index e816d44..7f8091f 100644
--- a/src/store/auth/auth.thunk.js
+++ b/src/store/auth/auth.thunk.js
@@ -1,5 +1,5 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
-import { get, post } from '../../services/api';
+import { get, post, put } from '../../services/api';
import { showNotification } from '../notification.slice';
import { logout } from './auth.slice';
import CryptoJS from 'crypto-js';
@@ -40,29 +40,29 @@ export const loginThunk = createAsyncThunk(
export const signupThunk = createAsyncThunk('auth/signup', async (userData, { rejectWithValue, dispatch }) => {
try {
// 使用新的注册 API
- const response = await post('/auth/register/', userData);
- console.log('注册返回数据:', response);
+ const { data, message, code } = await post('/auth/register/', userData);
+ console.log('注册返回数据:', data);
- // 处理新的返回格式
- if (response && response.code === 200) {
- // // 将 token 加密存储到 sessionStorage
- // const { token } = response.data;
- // if (token) {
- // const encryptedToken = CryptoJS.AES.encrypt(token, secretKey).toString();
- // sessionStorage.setItem('token', encryptedToken);
- // }
+ if (code !== 200) {
+ throw new Error(message);
+ }
+ // 将 token 加密存储到 sessionStorage
+ const { token } = data;
- // 显示注册成功通知
- dispatch(
- showNotification({
- message: '注册成功',
- type: 'success',
- })
- );
- return response.data;
+ if (token) {
+ const encryptedToken = CryptoJS.AES.encrypt(token, secretKey).toString();
+ sessionStorage.setItem('token', encryptedToken);
}
- return rejectWithValue(response.message || '注册失败');
+ // 显示注册成功通知
+ dispatch(
+ showNotification({
+ message: '注册成功',
+ type: 'success',
+ })
+ );
+
+ return data;
} catch (error) {
const errorMessage = error.response?.data?.message || '注册失败,请稍后重试';
dispatch(
@@ -107,3 +107,33 @@ export const logoutThunk = createAsyncThunk('auth/logout', async (_, { rejectWit
return rejectWithValue(errorMessage);
}
});
+
+// 更新个人资料
+export const updateProfileThunk = createAsyncThunk('auth/updateProfile', async (userData, { rejectWithValue, dispatch }) => {
+ try {
+ const { data, message, code } = await put('/users/profile/', userData);
+
+ if (code !== 200) {
+ throw new Error(message);
+ }
+
+ // 显示更新成功通知
+ dispatch(
+ showNotification({
+ message: '个人信息更新成功',
+ type: 'success',
+ })
+ );
+
+ return data;
+ } catch (error) {
+ const errorMessage = error.response?.data?.message || '更新失败,请稍后重试';
+ dispatch(
+ showNotification({
+ message: errorMessage,
+ type: 'danger',
+ })
+ );
+ return rejectWithValue(errorMessage);
+ }
+});
\ No newline at end of file
diff --git a/src/styles/style.scss b/src/styles/style.scss
index b815aa5..7cd7833 100644
--- a/src/styles/style.scss
+++ b/src/styles/style.scss
@@ -9,6 +9,7 @@
.snackbar {
top: 6.5rem;
+ z-index: 9999;
}
/* Markdown styling in chat messages */