新增路由管理
Change-Id: I8139fd09f135c42944f60ca473ee208e69549dc2
diff --git a/Merge/front/src/components/CreatePost.jsx b/Merge/front/src/components/CreatePost.jsx
index 9817ac0..1d2f306 100644
--- a/Merge/front/src/components/CreatePost.jsx
+++ b/Merge/front/src/components/CreatePost.jsx
@@ -1,5 +1,3 @@
-// src/components/CreatePost.jsx
-
import React, { useState, useEffect } from 'react'
import { useNavigate, useParams } from 'react-router-dom'
import UploadPage from './UploadPage'
@@ -8,6 +6,7 @@
updatePost,
fetchPost as fetchPostDetail
} from '../api/posts_wzy'
+import { getUserInfo } from '../utils/auth'
import '../style/CreatePost.css'
export default function CreatePost() {
@@ -36,6 +35,10 @@
{ id: 3, name: '我染上了拼豆' },
]
+ // 获取当前登录用户id
+ const user = getUserInfo()
+ const currentUserId = user?.id
+
// 编辑模式:拉取原帖数据填入
useEffect(() => {
if (!isEdit) return
@@ -68,6 +71,10 @@
setError('标题和正文必填')
return
}
+ if (!currentUserId) {
+ setError('未获取到用户ID,请重新登录')
+ return
+ }
setError(null)
try {
if (isEdit) {
@@ -81,7 +88,7 @@
alert('更新成功!')
} else {
await createPost({
- user_id: 1,
+ user_id: currentUserId,
topic_id: topicId || undefined,
title: title.trim(),
content: content.trim(),