修复令牌验证逻辑,修改管理员dashboard,增加退出登录功能
Change-Id: I6a832763126dffd28733269044a1b1956c5b1106
diff --git a/Merge/front/src/api/posts_trm.js b/Merge/front/src/api/posts_trm.js
index f28ec19..43d7105 100644
--- a/Merge/front/src/api/posts_trm.js
+++ b/Merge/front/src/api/posts_trm.js
@@ -1,16 +1,20 @@
+import { getAuthToken } from '../utils/auth'
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) {
+export async function fetchPosts() {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/apostlist`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId })
+ body: JSON.stringify({ userid })
})
if (!res.ok) throw new Error(`fetchPosts: ${res.status}`)
@@ -43,11 +47,12 @@
* 审核通过
* POST /areview
*/
-export async function approvePost(postId, userId) {
+export async function approvePost(postId) {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/areview`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId, postid: postId, status: 'published' })
+ body: JSON.stringify({ userid, postid: postId, status: 'published' })
})
if (!res.ok) throw new Error(`approvePost: ${res.status}`)
return res.json()
@@ -57,11 +62,12 @@
* 驳回
* POST /areview
*/
-export async function rejectPost(postId, userId) {
+export async function rejectPost(postId) {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/areview`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId, postid: postId, status: 'rejected' })
+ body: JSON.stringify({ userid, postid: postId, status: 'rejected' })
})
if (!res.ok) throw new Error(`rejectPost: ${res.status}`)
return res.json()
@@ -74,11 +80,12 @@
* @param {number|string} userId 平台管理员的用户 ID
* @returns Promise<{id, title, content, status}>
*/
-export async function fetchPost(postId, userId) {
+export async function fetchPost(postId) {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/agetpost`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId, postid: postId })
+ body: JSON.stringify({ userid, postid: postId })
})
if (!res.ok) throw new Error(`fetchPost: ${res.status}`)
return res.json()
@@ -90,41 +97,45 @@
* @param {number|string} userId 平台管理员的用户 ID
* @returns Promise<[ {id, name, role}, … ]>
*/
-export async function fetchUserList(userId) {
+export async function fetchUserList() {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/sgetuserlist`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId })
+ body: JSON.stringify({ userid })
})
if (!res.ok) throw new Error(`fetchUserList: ${res.status}`)
return res.json()
}
-export async function giveAdmin(userId, targetId) {
+export async function giveAdmin(targetId) {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/sgiveadmin`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId, targetid: targetId })
+ body: JSON.stringify({ userid, targetid: targetId })
})
if (!res.ok) throw new Error(`giveAdmin: ${res.status}`)
return res.json()
}
-export async function giveSuperAdmin(userId, targetId) {
+export async function giveSuperAdmin(targetId) {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/sgivesuperadmin`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId, targetid: targetId })
+ body: JSON.stringify({ userid, targetid: targetId })
})
if (!res.ok) throw new Error(`giveSuperAdmin: ${res.status}`)
return res.json()
}
-export async function giveUser(userId, targetId) {
+export async function giveUser(targetId) {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/sgiveuser`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId, targetid: targetId })
+ body: JSON.stringify({ userid, targetid: targetId })
})
if (!res.ok) throw new Error(`giveUser: ${res.status}`)
return res.json()
@@ -133,14 +144,14 @@
/**
* 获取事务日志
* POST /getrecordlog
- * @param {number|string} userId 平台管理员的用户 ID
* @returns Promise<[ {id, user_id, type, content, ip, created_at}, … ]>
*/
-export async function fetchRecordLog(userId) {
+export async function fetchRecordLog() {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/getrecordlog`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId })
+ body: JSON.stringify({ userid })
})
if (!res.ok) throw new Error(`fetchRecordLog: ${res.status}`)
const json = await res.json()
@@ -166,11 +177,12 @@
* @param {number|string} userId 平台管理员的用户 ID
* @returns Promise<[ {id, record_time, endpoint, elapsed_time, cpu_user, cpu_system, memory_rss}, … ]>
*/
-export async function fetchSysCost(userId) {
+export async function fetchSysCost() {
+ const userid = getAuthToken()
const res = await fetch(`${BASE}/getsyscost`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ userid: userId })
+ body: JSON.stringify({ userid })
})
if (!res.ok) throw new Error(`fetchSysCost: ${res.status}`)
const json = await res.json()