fix: API param localStorge useId
Change-Id: Ifd624462360111f08ca308ea07b6fcaac0747104
diff --git "a/src/app/community/thread-detail/\133threadId\135/page.tsx" "b/src/app/community/thread-detail/\133threadId\135/page.tsx"
index f998f64..0f3e5b2 100644
--- "a/src/app/community/thread-detail/\133threadId\135/page.tsx"
+++ "b/src/app/community/thread-detail/\133threadId\135/page.tsx"
@@ -16,8 +16,12 @@
import { Paginator, type PaginatorPageChangeEvent } from 'primereact/paginator';
// 消息提醒
import { Toast } from 'primereact/toast';
+import { useLocalStorage } from '../../../hook/useLocalStorage';
// 样式
import './thread.scss';
+interface User {
+ Id: number;
+}
// 评论信息
@@ -65,6 +69,9 @@
//帖子详情界面
export default function ThreadDetailPage() {
+ const user = useLocalStorage<User>('user');
+ const userId: number = user?.Id ?? -1;
+
// 获取URL参数,页面跳转
const params = useParams<{ threadId: string }>()
const threadId = decodeURIComponent(params.threadId); // 防止中文路径乱码
@@ -104,7 +111,7 @@
const { data } = await axios.get(process.env.PUBLIC_URL + `/thread`, {
params: {
threadId,
- userId: 22301145
+ userId
}
});
setThreadInfo(data);
@@ -132,7 +139,7 @@
try {
const response = await axios.post(
process.env.PUBLIC_URL + `/thread/like`, {
- params: { threadId, userId: 22301145 }
+ params: { threadId, userId }
}
);
fetchThreadInfo(); // 刷新帖子信息
@@ -148,7 +155,7 @@
try {
const response = await axios.delete(
process.env.PUBLIC_URL + `/thread/like`, {
- params: { threadId, userId: 22301145 }
+ params: { threadId, userId }
}
);
fetchThreadInfo(); // 刷新帖子信息
@@ -216,7 +223,7 @@
console.log('发布评论:', commentId);
try {
const newComment: NewComment = {
- userId: 22301145,
+ userId,
threadId: threadInfo.threadId,
resourceId: 0,
replyId: commentId,
@@ -246,7 +253,7 @@
try {
const newComment: NewComment = {
- userId: 22301145,
+ userId,
threadId: threadInfo.threadId,
resourceId: 0,
replyId: 0, // 直接评论,不是回复
@@ -373,7 +380,7 @@
if (el) ops.current[index] = el;
}}>
<Button label="回复" text size="small" onClick={() => setVisibleReply(true)} />
- {comment.userId === 22301145 &&
+ {comment.userId === userId &&
<Button
label="删除"
text