完成性能日志和事务日志功能
Change-Id: Iec30043bc5b954a29fa0d8d18a84c1feed2a1696
diff --git a/Merge/front/src/api/posts.js b/Merge/front/src/api/posts_trm.js
similarity index 68%
rename from Merge/front/src/api/posts.js
rename to Merge/front/src/api/posts_trm.js
index 37acf43..f28ec19 100644
--- a/Merge/front/src/api/posts.js
+++ b/Merge/front/src/api/posts_trm.js
@@ -128,4 +128,64 @@
})
if (!res.ok) throw new Error(`giveUser: ${res.status}`)
return res.json()
+}
+
+/**
+ * 获取事务日志
+ * POST /getrecordlog
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<[ {id, user_id, type, content, ip, created_at}, … ]>
+ */
+export async function fetchRecordLog(userId) {
+ const res = await fetch(`${BASE}/getrecordlog`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId })
+ })
+ if (!res.ok) throw new Error(`fetchRecordLog: ${res.status}`)
+ const json = await res.json()
+ console.log('fetchRecordLog response:', json)
+ if (json.status === 'error' && json.message === 'Unauthorized') {
+ throw new Error('Unauthorized')
+ }
+ let list
+ if (Array.isArray(json)) {
+ list = json
+ } else if (Array.isArray(json.data)) {
+ list = json.data
+ } else {
+ list = []
+ }
+ console.log('Normalized record log list:', list)
+ return list
+}
+
+/**
+ * 获取系统性能消耗数据
+ * POST /getsyscost
+ * @param {number|string} userId 平台管理员的用户 ID
+ * @returns Promise<[ {id, record_time, endpoint, elapsed_time, cpu_user, cpu_system, memory_rss}, … ]>
+ */
+export async function fetchSysCost(userId) {
+ const res = await fetch(`${BASE}/getsyscost`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userid: userId })
+ })
+ if (!res.ok) throw new Error(`fetchSysCost: ${res.status}`)
+ const json = await res.json()
+ console.log('fetchSysCost response:', json)
+ if (json.status === 'error' && json.message === 'Unauthorized') {
+ throw new Error('Unauthorized')
+ }
+ let list
+ if (Array.isArray(json)) {
+ list = json
+ } else if (Array.isArray(json.data)) {
+ list = json.data
+ } else {
+ list = []
+ }
+ console.log('Normalized sys cost list:', list)
+ return list
}
\ No newline at end of file