合并JWL,WZY,TRM代码

Change-Id: Ifb4fcad3c06733e1e005e7d8d9403e3561010fb4
diff --git a/Merge/front/src/api/posts.js b/Merge/front/src/api/posts.js
new file mode 100644
index 0000000..37acf43
--- /dev/null
+++ b/Merge/front/src/api/posts.js
@@ -0,0 +1,131 @@
+const BASE = 'http://10.126.59.25:5713'  // 后端地址
+
+/**
+ * 获取待审核的帖子列表
+ * POST /apostlist
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<[ {id, title, status}, … ]>
+ */
+export async function fetchPosts(userId) {
+  const res = await fetch(`${BASE}/apostlist`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId })
+  })
+  if (!res.ok) throw new Error(`fetchPosts: ${res.status}`)
+  
+  const json = await res.json()
+  console.log('fetchPosts response:', json)         // debug: inspect shape
+
+  // handle unauthorized
+  if (json.status === 'error' && json.message === 'Unauthorized') {
+    throw new Error('Unauthorized')
+  }
+  
+  // normalize response into an array
+  let list
+  if (Array.isArray(json)) {
+    list = json
+  } else if (Array.isArray(json.data)) {
+    list = json.data
+  } else if (Array.isArray(json.posts)) {
+    list = json.posts
+  } else if (Array.isArray(json.data?.posts)) {
+    list = json.data.posts
+  } else {
+    list = []
+  }
+  console.log('Normalized post list:', list) // debug: check final shape
+  return list
+}
+
+/**
+ * 审核通过
+ * POST /areview
+ */
+export async function approvePost(postId, userId) {
+  const res = await fetch(`${BASE}/areview`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId, postid: postId, status: 'published' })
+  })
+  if (!res.ok) throw new Error(`approvePost: ${res.status}`)
+  return res.json()
+}
+
+/**
+ * 驳回
+ * POST /areview
+ */
+export async function rejectPost(postId, userId) {
+  const res = await fetch(`${BASE}/areview`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId, postid: postId, status: 'rejected' })
+  })
+  if (!res.ok) throw new Error(`rejectPost: ${res.status}`)
+  return res.json()
+}
+
+/**
+ * 获取单个帖子详情
+ * POST /agetpost
+ * @param {number|string} postId 帖子 ID
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<{id, title, content, status}>
+ */
+export async function fetchPost(postId, userId) {
+  const res = await fetch(`${BASE}/agetpost`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId, postid: postId })
+  })
+  if (!res.ok) throw new Error(`fetchPost: ${res.status}`)
+  return res.json()
+}
+
+/**
+ * 获取超级管理员用户列表
+ * POST /sgetuserlist
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<[ {id, name, role}, … ]>
+ */
+export async function fetchUserList(userId) {
+  const res = await fetch(`${BASE}/sgetuserlist`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId })
+  })
+  if (!res.ok) throw new Error(`fetchUserList: ${res.status}`)
+  return res.json()
+}
+
+export async function giveAdmin(userId, targetId) {
+  const res = await fetch(`${BASE}/sgiveadmin`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId, targetid: targetId })
+  })
+  if (!res.ok) throw new Error(`giveAdmin: ${res.status}`)
+  return res.json()
+}
+
+export async function giveSuperAdmin(userId, targetId) {
+  const res = await fetch(`${BASE}/sgivesuperadmin`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId, targetid: targetId })
+  })
+  if (!res.ok) throw new Error(`giveSuperAdmin: ${res.status}`)
+  return res.json()
+}
+
+export async function giveUser(userId, targetId) {
+  const res = await fetch(`${BASE}/sgiveuser`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ userid: userId, targetid: targetId })
+  })
+  if (!res.ok) throw new Error(`giveUser: ${res.status}`)
+  return res.json()
+}
\ No newline at end of file
diff --git a/Merge/front/src/api/posts_wzy.js b/Merge/front/src/api/posts_wzy.js
new file mode 100644
index 0000000..ae65756
--- /dev/null
+++ b/Merge/front/src/api/posts_wzy.js
@@ -0,0 +1,130 @@
+// src/api/posts.js
+const BASE = 'http://127.0.0.1:5714/'  // 如果有代理可以留空,否则填完整域名,如 'http://localhost:3000'
+
+/**
+ * 获取所有已发布的帖子列表
+ * GET /posts
+ */
+export async function fetchPosts() {
+  const res = await fetch(`${BASE}/posts`)
+  if (!res.ok) throw new Error(`fetchPosts: ${res.status}`)
+  console.log('fetchPosts response:', res)  // debug: inspect response
+  return res.json()  // 返回 [ { id, title, heat, created_at }, … ]
+}
+
+/**
+ * 查看单个帖子详情
+ * GET /posts/{postId}
+ */
+export async function fetchPost(postId) {
+  const res = await fetch(`${BASE}/posts/${postId}`)
+  if (!res.ok) throw new Error(`fetchPost(${postId}): ${res.status}`)
+  return res.json()  // 返回完整的帖子对象
+}
+
+/**
+ * 发布新帖
+ * POST /posts
+ */
+export async function createPost(payload) {
+  const res = await fetch(`${BASE}/posts`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify(payload)
+  })
+  if (!res.ok) {
+    const err = await res.json().catch(() => null)
+    throw new Error(err?.error || `createPost: ${res.status}`)
+  }
+  return res.json()  // { id }
+}
+
+/**
+ * 修改帖子
+ * PUT /posts/{postId}
+ */
+export async function updatePost(postId, payload) {
+  const res = await fetch(`${BASE}/posts/${postId}`, {
+    method: 'PUT',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify(payload)
+  })
+  if (!res.ok) throw new Error(`updatePost(${postId}): ${res.status}`)
+  // 204 No Content
+}
+
+/**
+ * 删除帖子
+ * DELETE /posts/{postId}
+ */
+export async function deletePost(postId) {
+  const res = await fetch(`${BASE}/posts/${postId}`, {
+    method: 'DELETE'
+  })
+  if (!res.ok) throw new Error(`deletePost(${postId}): ${res.status}`)
+}
+
+/**
+ * 点赞
+ * POST /posts/{postId}/like
+ */
+export async function likePost(postId, userId) {
+  const res = await fetch(`${BASE}/posts/${postId}/like`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ user_id: userId })
+  })
+  if (!res.ok) {
+    const err = await res.json().catch(() => null)
+    throw new Error(err?.error || `likePost: ${res.status}`)
+  }
+}
+
+/**
+ * 取消点赞
+ * DELETE /posts/{postId}/like
+ */
+export async function unlikePost(postId, userId) {
+  const res = await fetch(`${BASE}/posts/${postId}/like`, {
+    method: 'DELETE',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ user_id: userId })
+  })
+  if (!res.ok) {
+    const err = await res.json().catch(() => null)
+    throw new Error(err?.error || `unlikePost: ${res.status}`)
+  }
+}
+
+/**
+ * 收藏、取消收藏、浏览、分享 等接口:
+ * POST   /posts/{postId}/favorite
+ * DELETE /posts/{postId}/favorite
+ * POST   /posts/{postId}/view
+ * POST   /posts/{postId}/share
+ * 用法同上,替换路径即可
+ */
+
+/**
+ * 添加评论
+ * POST /posts/{postId}/comments
+ */
+export async function addComment(postId, payload) {
+  const res = await fetch(`${BASE}/posts/${postId}/comments`, {
+    method: 'POST',
+    headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify(payload)
+  })
+  if (!res.ok) throw new Error(`addComment: ${res.status}`)
+  return res.json()  // { id }
+}
+
+/**
+ * 获取评论列表
+ * GET /posts/{postId}/comments
+ */
+export async function fetchComments(postId) {
+  const res = await fetch(`${BASE}/posts/${postId}/comments`)
+  if (!res.ok) throw new Error(`fetchComments: ${res.status}`)
+  return res.json()
+}