TRM-coding | 78aa966 | 2025-06-17 23:40:10 +0800 | [diff] [blame] | 1 | const BASE = 'http://10.126.59.25:5713' // 后端地址 |
| 2 | |
| 3 | /** |
| 4 | * 获取待审核的帖子列表 |
| 5 | * POST /apostlist |
| 6 | * @param {number|string} userId 平台管理员的用户 ID |
| 7 | * @returns Promise<[ {id, title, status}, … ]> |
| 8 | */ |
| 9 | export async function fetchPosts(userId) { |
| 10 | const res = await fetch(`${BASE}/apostlist`, { |
| 11 | method: 'POST', |
| 12 | headers: { 'Content-Type': 'application/json' }, |
| 13 | body: JSON.stringify({ userid: userId }) |
| 14 | }) |
| 15 | if (!res.ok) throw new Error(`fetchPosts: ${res.status}`) |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame^] | 16 | |
| 17 | const json = await res.json() |
| 18 | console.log('fetchPosts response:', json) // debug: inspect shape |
| 19 | |
| 20 | // normalize: if it's already an array use it; else pull array out of known keys |
| 21 | const list = Array.isArray(json) |
| 22 | ? json |
| 23 | : json.data || json.posts || [] |
| 24 | |
| 25 | return list |
TRM-coding | 78aa966 | 2025-06-17 23:40:10 +0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | /** |
| 29 | * 审核通过 |
| 30 | * POST /areview |
| 31 | */ |
| 32 | export async function approvePost(postId, userId) { |
| 33 | const res = await fetch(`${BASE}/areview`, { |
| 34 | method: 'POST', |
| 35 | headers: { 'Content-Type': 'application/json' }, |
| 36 | body: JSON.stringify({ userid: userId, postid: postId, status: 'published' }) |
| 37 | }) |
| 38 | if (!res.ok) throw new Error(`approvePost: ${res.status}`) |
| 39 | return res.json() |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * 驳回 |
| 44 | * POST /areview |
| 45 | */ |
| 46 | export async function rejectPost(postId, userId) { |
| 47 | const res = await fetch(`${BASE}/areview`, { |
| 48 | method: 'POST', |
| 49 | headers: { 'Content-Type': 'application/json' }, |
| 50 | body: JSON.stringify({ userid: userId, postid: postId, status: 'rejected' }) |
| 51 | }) |
| 52 | if (!res.ok) throw new Error(`rejectPost: ${res.status}`) |
| 53 | return res.json() |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * 获取单个帖子详情 |
| 58 | * POST /agetpost |
| 59 | * @param {number|string} postId 帖子 ID |
| 60 | * @param {number|string} userId 平台管理员的用户 ID |
| 61 | * @returns Promise<{id, title, content, status}> |
| 62 | */ |
| 63 | export async function fetchPost(postId, userId) { |
| 64 | const res = await fetch(`${BASE}/agetpost`, { |
| 65 | method: 'POST', |
| 66 | headers: { 'Content-Type': 'application/json' }, |
| 67 | body: JSON.stringify({ userid: userId, postid: postId }) |
| 68 | }) |
| 69 | if (!res.ok) throw new Error(`fetchPost: ${res.status}`) |
| 70 | return res.json() |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame^] | 71 | } |
| 72 | |
| 73 | /** |
| 74 | * 获取超级管理员用户列表 |
| 75 | * POST /sgetuserlist |
| 76 | * @param {number|string} userId 平台管理员的用户 ID |
| 77 | * @returns Promise<[ {id, name, role}, … ]> |
| 78 | */ |
| 79 | export async function fetchUserList(userId) { |
| 80 | const res = await fetch(`${BASE}/sgetuserlist`, { |
| 81 | method: 'POST', |
| 82 | headers: { 'Content-Type': 'application/json' }, |
| 83 | body: JSON.stringify({ userid: userId }) |
| 84 | }) |
| 85 | if (!res.ok) throw new Error(`fetchUserList: ${res.status}`) |
| 86 | return res.json() |
| 87 | } |
| 88 | |
| 89 | export async function giveAdmin(userId, targetId) { |
| 90 | const res = await fetch(`${BASE}/sgiveadmin`, { |
| 91 | method: 'POST', |
| 92 | headers: { 'Content-Type': 'application/json' }, |
| 93 | body: JSON.stringify({ userid: userId, targetid: targetId }) |
| 94 | }) |
| 95 | if (!res.ok) throw new Error(`giveAdmin: ${res.status}`) |
| 96 | return res.json() |
| 97 | } |
| 98 | |
| 99 | export async function giveSuperAdmin(userId, targetId) { |
| 100 | const res = await fetch(`${BASE}/sgivesuperadmin`, { |
| 101 | method: 'POST', |
| 102 | headers: { 'Content-Type': 'application/json' }, |
| 103 | body: JSON.stringify({ userid: userId, targetid: targetId }) |
| 104 | }) |
| 105 | if (!res.ok) throw new Error(`giveSuperAdmin: ${res.status}`) |
| 106 | return res.json() |
| 107 | } |
| 108 | |
| 109 | export async function giveUser(userId, targetId) { |
| 110 | const res = await fetch(`${BASE}/sgiveuser`, { |
| 111 | method: 'POST', |
| 112 | headers: { 'Content-Type': 'application/json' }, |
| 113 | body: JSON.stringify({ userid: userId, targetid: targetId }) |
| 114 | }) |
| 115 | if (!res.ok) throw new Error(`giveUser: ${res.status}`) |
| 116 | return res.json() |
TRM-coding | 78aa966 | 2025-06-17 23:40:10 +0800 | [diff] [blame] | 117 | } |