shensuming commited on
Commit
3242671
·
verified ·
1 Parent(s): 812ca9b

Update admin.html

Browse files
Files changed (1) hide show
  1. admin.html +70 -96
admin.html CHANGED
@@ -9,6 +9,8 @@
9
  .modal.active { display: flex; align-items: center; justify-content: center; }
10
  th.sortable { cursor: pointer; transition: background-color 0.2s; }
11
  th.sortable:hover { background-color: #e2e8f0; }
 
 
12
  </style>
13
  </head>
14
  <body class="bg-slate-50 text-slate-800 p-8">
@@ -18,29 +20,8 @@
18
  <h1 class="text-3xl font-bold text-slate-900">CerebrateX 作战指挥室</h1>
19
  <div class="flex gap-4">
20
  <input type="password" id="adminToken" placeholder="输入 Admin Token" class="px-4 py-2 border rounded shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
21
-
22
- <select id="langFilter" onchange="loadUsers()" class="px-4 py-2 border rounded shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white font-semibold text-slate-700 cursor-pointer">
23
- <option value="">🌍 全球所有市场</option>
24
- <option value="zh">🇨🇳 zh (简中)</option>
25
- <option value="zh-TW">🇹🇼 zh-TW (繁中)</option>
26
- <option value="en">🇺🇸 en (英语)</option>
27
- <option value="es">🇪🇸 es (西语)</option>
28
- <option value="fr">🇫🇷 fr (法语)</option>
29
- <option value="de">🇩🇪 de (德语)</option>
30
- <option value="ja">🇯🇵 ja (日语)</option>
31
- <option value="ko">🇰🇷 ko (韩语)</option>
32
- <option value="ru">🇷🇺 ru (俄语)</option>
33
- <option value="ar">🇸🇦 ar (阿拉伯语)</option>
34
- <option value="pt">🇵🇹 pt (葡语)</option>
35
- <option value="hi">🇮🇳 hi (印地语)</option>
36
- <option value="it">🇮🇹 it (意语)</option>
37
- <option value="tr">🇹🇷 tr (土耳其)</option>
38
- <option value="vi">🇻🇳 vi (越南语)</option>
39
- <option value="th">🇹🇭 th (泰语)</option>
40
- </select>
41
-
42
- <button onclick="loadUsers()" class="bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 shadow font-semibold transition">刷新大盘</button>
43
- <button onclick="exportCSV()" class="bg-emerald-600 text-white px-6 py-2 rounded hover:bg-emerald-700 shadow font-semibold transition">导出报表</button>
44
  </div>
45
  </div>
46
 
@@ -50,7 +31,43 @@
50
  <tr class="bg-slate-100 border-b">
51
  <th class="p-4 font-semibold text-sm">邮箱 / ID</th>
52
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('status')">状态 <span id="sort-status" class="text-slate-400"></span></th>
53
- <th class="p-4 font-semibold text-sm">套餐 (来源)</th>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('points_balance')">剩余积分 <span id="sort-points_balance" class="text-slate-400"></span></th>
55
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('monthly_attachment_mb_used')">附件已用 / 记忆长度 <span id="sort-monthly_attachment_mb_used" class="text-slate-400"></span></th>
56
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('create_time')">注册时间 <span id="sort-create_time" class="text-slate-600">↓</span></th>
@@ -68,7 +85,6 @@
68
  <div class="bg-white p-6 rounded-lg shadow-xl w-96">
69
  <h2 class="text-xl font-bold mb-4">调整用户资产</h2>
70
  <input type="hidden" id="targetUserId">
71
-
72
  <label class="block mb-2 text-sm font-semibold">调整项</label>
73
  <select id="targetField" class="w-full p-2 border rounded mb-4">
74
  <option value="points_balance">剩余积分 (整数)</option>
@@ -76,13 +92,10 @@
76
  <option value="max_context_length">记忆长度 (整数)</option>
77
  <option value="monthly_attachment_mb_used">附件已用量 (数字)</option>
78
  </select>
79
-
80
  <label class="block mb-2 text-sm font-semibold">新数值</label>
81
  <input type="text" id="newValue" class="w-full p-2 border rounded mb-4" placeholder="填入新的绝对值">
82
-
83
- <label class="block mb-2 text-sm font-semibold">操作原因 (必填,计入审计)</label>
84
- <input type="text" id="adjustReason" class="w-full p-2 border rounded mb-6" placeholder="例如:客诉补偿、封禁测试">
85
-
86
  <div class="flex justify-end gap-2">
87
  <button onclick="closeModal()" class="px-4 py-2 bg-slate-200 rounded hover:bg-slate-300 transition">取消</button>
88
  <button onclick="submitAdjust()" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition">确认执行</button>
@@ -97,30 +110,19 @@
97
 
98
  async function apiCall(url, method = 'GET', body = null) {
99
  const token = document.getElementById('adminToken').value;
100
- if (!token) {
101
- alert('必须输入 Admin Token');
102
- throw new Error('No token');
103
- }
104
  const headers = { 'X-Admin-Token': token, 'Content-Type': 'application/json' };
105
  const options = { method, headers };
106
  if (body) options.body = JSON.stringify(body);
107
-
108
  const res = await fetch(url, options);
109
- if (!res.ok) {
110
- const err = await res.text();
111
- alert(`API 拒绝: ${err}`);
112
- throw new Error(err);
113
- }
114
  return res;
115
  }
116
 
117
  async function loadUsers() {
118
  try {
119
- // [新增] 抓取当前选中的市场语种
120
- const selectedLang = document.getElementById('langFilter').value;
121
- const langParam = selectedLang ? `&lang=${selectedLang}` : '';
122
-
123
- // 拼接排序参数 + 市场语种过滤,交由后端 PG 数据库处理
124
  const res = await apiCall(`/api/admin/users?limit=100&sort_by=${currentSortBy}&order=${currentOrder}${langParam}`);
125
  const data = await res.json();
126
  currentUsers = data.users;
@@ -130,59 +132,16 @@
130
  }
131
 
132
  function handleSort(column) {
133
- if (currentSortBy === column) {
134
- currentOrder = currentOrder === 'asc' ? 'desc' : 'asc';
135
- } else {
136
- currentSortBy = column;
137
- currentOrder = 'desc'; // 切换新列时默认倒序
138
- }
139
  loadUsers();
140
  }
141
 
142
  function updateSortUI() {
143
- // 清理所有排序箭头
144
  ['status', 'points_balance', 'monthly_attachment_mb_used', 'create_time'].forEach(col => {
145
  const el = document.getElementById(`sort-${col}`);
146
- if (el) {
147
- el.textContent = '';
148
- el.className = 'text-slate-400';
149
- }
150
  });
151
- // 设置当前排序列的箭头
152
- const currentEl = document.getElementById(`sort-${currentSortBy}`);
153
- if (currentEl) {
154
- currentEl.textContent = currentOrder === 'asc' ? '↑' : '↓';
155
- currentEl.className = 'text-slate-800 font-bold';
156
- }
157
- }
158
-
159
- async function exportCSV() {
160
- const token = document.getElementById('adminToken').value;
161
- if (!token) {
162
- alert('必须先输入 Admin Token 以验证权限');
163
- return;
164
- }
165
- try {
166
- // 请求直接返回二进制流
167
- const res = await fetch('/api/admin/users/export', {
168
- headers: { 'X-Admin-Token': token }
169
- });
170
- if (!res.ok) throw new Error('导出被拒绝或失败');
171
-
172
- const blob = await res.blob();
173
- const url = window.URL.createObjectURL(blob);
174
- const a = document.createElement('a');
175
- a.style.display = 'none';
176
- a.href = url;
177
- a.download = `cerebratex_users_${new Date().getTime()}.csv`;
178
- document.body.appendChild(a);
179
- a.click();
180
-
181
- window.URL.revokeObjectURL(url);
182
- a.remove();
183
- } catch (e) {
184
- alert(e.message);
185
- }
186
  }
187
 
188
  function renderTable() {
@@ -200,7 +159,7 @@
200
  </td>
201
  <td class="p-4">
202
  <div class="font-medium text-slate-800">${u.tier || 'free'}</div>
203
- <div class="text-xs font-bold ${u.lang ? 'text-blue-600' : 'text-slate-400'}">市场: ${u.lang || '未知'}</div>
204
  </td>
205
  <td class="p-4 font-mono font-bold text-blue-600 text-lg">${u.points_balance || 0}</td>
206
  <td class="p-4 text-sm text-slate-600">
@@ -233,10 +192,7 @@
233
  const newValue = document.getElementById('newValue').value;
234
  const reason = document.getElementById('adjustReason').value;
235
 
236
- if (!newValue || !reason) {
237
- alert("新数值和原因不能为空");
238
- return;
239
- }
240
 
241
  try {
242
  await apiCall(`/api/admin/users/${userId}/adjust`, 'POST', {
@@ -261,6 +217,24 @@
261
  loadUsers();
262
  } catch (e) {}
263
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  </script>
265
  </body>
266
  </html>
 
9
  .modal.active { display: flex; align-items: center; justify-content: center; }
10
  th.sortable { cursor: pointer; transition: background-color 0.2s; }
11
  th.sortable:hover { background-color: #e2e8f0; }
12
+ /* 隐藏原生下拉箭头,保持表头整洁 */
13
+ select { -webkit-appearance: none; -moz-appearance: none; appearance: none; }
14
  </style>
15
  </head>
16
  <body class="bg-slate-50 text-slate-800 p-8">
 
20
  <h1 class="text-3xl font-bold text-slate-900">CerebrateX 作战指挥室</h1>
21
  <div class="flex gap-4">
22
  <input type="password" id="adminToken" placeholder="输入 Admin Token" class="px-4 py-2 border rounded shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
23
+ <button onclick="loadUsers()" class="bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 shadow font-semibold transition">进入指挥室</button>
24
+ <button onclick="exportCSV()" class="bg-emerald-600 text-white px-6 py-2 rounded hover:bg-emerald-700 shadow font-semibold transition">一键导出 CSV</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  </div>
26
  </div>
27
 
 
31
  <tr class="bg-slate-100 border-b">
32
  <th class="p-4 font-semibold text-sm">邮箱 / ID</th>
33
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('status')">状态 <span id="sort-status" class="text-slate-400"></span></th>
34
+ <th class="p-4 font-semibold text-sm">
35
+ 套餐 (
36
+ <select id="langFilter" onchange="loadUsers()" class="bg-transparent font-bold text-blue-600 outline-none cursor-pointer border-none p-0">
37
+ <option value="">🌍 全部市场</option>
38
+ <option value="zh">🇨🇳 简中 (zh)</option>
39
+ <option value="zh-TW">繁中 (zh-TW)</option>
40
+ <option value="en">🇺🇸 英语 (en)</option>
41
+ <option value="ja">🇯🇵 日语 (ja)</option>
42
+ <option value="ko">🇰🇷 韩语 (ko)</option>
43
+ <option value="fr">🇫🇷 法语 (fr)</option>
44
+ <option value="de">🇩🇪 德语 (de)</option>
45
+ <option value="es">🇪🇸 西语 (es)</option>
46
+ <option value="ru">🇷🇺 俄语 (ru)</option>
47
+ <option value="it">🇮🇹 意语 (it)</option>
48
+ <option value="pt">🇵🇹 葡语 (pt)</option>
49
+ <option value="hi">🇮🇳 印地语 (hi)</option>
50
+ <option value="ar">🇸🇦 阿语 (ar)</option>
51
+ <option value="bn">🇧🇩 孟加拉 (bn)</option>
52
+ <option value="pa">🇵🇰 旁遮普 (pa)</option>
53
+ <option value="jv">🇮🇩 爪哇语 (jv)</option>
54
+ <option value="te">🇮🇳 泰卢固 (te)</option>
55
+ <option value="vi">🇻🇳 越南语 (vi)</option>
56
+ <option value="mr">🇮🇳 马拉地 (mr)</option>
57
+ <option value="ta">🇮🇳 泰米尔 (ta)</option>
58
+ <option value="tr">🇹🇷 土耳其 (tr)</option>
59
+ <option value="th">🇹🇭 泰语 (th)</option>
60
+ <option value="pl">🇵🇱 波兰语 (pl)</option>
61
+ <option value="uk">🇺🇦 乌克兰 (uk)</option>
62
+ <option value="nl">🇳🇱 荷兰语 (nl)</option>
63
+ <option value="sv">🇸🇪 瑞典语 (sv)</option>
64
+ <option value="cs">🇨🇿 捷克语 (cs)</option>
65
+ <option value="el">🇬🇷 希腊语 (el)</option>
66
+ <option value="he">🇮🇱 以色列 (he)</option>
67
+ <option value="fa">🇮🇷 波斯语 (fa)</option>
68
+ </select>
69
+ )
70
+ </th>
71
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('points_balance')">剩余积分 <span id="sort-points_balance" class="text-slate-400"></span></th>
72
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('monthly_attachment_mb_used')">附件已用 / 记忆长度 <span id="sort-monthly_attachment_mb_used" class="text-slate-400"></span></th>
73
  <th class="p-4 font-semibold text-sm sortable select-none" onclick="handleSort('create_time')">注册时间 <span id="sort-create_time" class="text-slate-600">↓</span></th>
 
85
  <div class="bg-white p-6 rounded-lg shadow-xl w-96">
86
  <h2 class="text-xl font-bold mb-4">调整用户资产</h2>
87
  <input type="hidden" id="targetUserId">
 
88
  <label class="block mb-2 text-sm font-semibold">调整项</label>
89
  <select id="targetField" class="w-full p-2 border rounded mb-4">
90
  <option value="points_balance">剩余积分 (整数)</option>
 
92
  <option value="max_context_length">记忆长度 (整数)</option>
93
  <option value="monthly_attachment_mb_used">附件已用量 (数字)</option>
94
  </select>
 
95
  <label class="block mb-2 text-sm font-semibold">新数值</label>
96
  <input type="text" id="newValue" class="w-full p-2 border rounded mb-4" placeholder="填入新的绝对值">
97
+ <label class="block mb-2 text-sm font-semibold">操作原因 (必填)</label>
98
+ <input type="text" id="adjustReason" class="w-full p-2 border rounded mb-6" placeholder="例如:客诉补偿">
 
 
99
  <div class="flex justify-end gap-2">
100
  <button onclick="closeModal()" class="px-4 py-2 bg-slate-200 rounded hover:bg-slate-300 transition">取消</button>
101
  <button onclick="submitAdjust()" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition">确认执行</button>
 
110
 
111
  async function apiCall(url, method = 'GET', body = null) {
112
  const token = document.getElementById('adminToken').value;
113
+ if (!token) { alert('必须输入 Admin Token'); throw new Error('No token'); }
 
 
 
114
  const headers = { 'X-Admin-Token': token, 'Content-Type': 'application/json' };
115
  const options = { method, headers };
116
  if (body) options.body = JSON.stringify(body);
 
117
  const res = await fetch(url, options);
118
+ if (!res.ok) { alert(`API 拒绝: ${await res.text()}`); throw new Error('API Error'); }
 
 
 
 
119
  return res;
120
  }
121
 
122
  async function loadUsers() {
123
  try {
124
+ const lang = document.getElementById('langFilter').value;
125
+ const langParam = lang ? `&lang=${lang}` : '';
 
 
 
126
  const res = await apiCall(`/api/admin/users?limit=100&sort_by=${currentSortBy}&order=${currentOrder}${langParam}`);
127
  const data = await res.json();
128
  currentUsers = data.users;
 
132
  }
133
 
134
  function handleSort(column) {
135
+ currentOrder = (currentSortBy === column && currentOrder === 'desc') ? 'asc' : 'desc';
136
+ currentSortBy = column;
 
 
 
 
137
  loadUsers();
138
  }
139
 
140
  function updateSortUI() {
 
141
  ['status', 'points_balance', 'monthly_attachment_mb_used', 'create_time'].forEach(col => {
142
  const el = document.getElementById(`sort-${col}`);
143
+ if (el) el.textContent = currentSortBy === col ? (currentOrder === 'asc' ? '↑' : '↓') : '';
 
 
 
144
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  }
146
 
147
  function renderTable() {
 
159
  </td>
160
  <td class="p-4">
161
  <div class="font-medium text-slate-800">${u.tier || 'free'}</div>
162
+ <div class="text-xs text-blue-500 font-bold">来源: ${u.lang || 'zh'}</div>
163
  </td>
164
  <td class="p-4 font-mono font-bold text-blue-600 text-lg">${u.points_balance || 0}</td>
165
  <td class="p-4 text-sm text-slate-600">
 
192
  const newValue = document.getElementById('newValue').value;
193
  const reason = document.getElementById('adjustReason').value;
194
 
195
+ if (!newValue || !reason) { alert("新数值和原因不能为空"); return; }
 
 
 
196
 
197
  try {
198
  await apiCall(`/api/admin/users/${userId}/adjust`, 'POST', {
 
217
  loadUsers();
218
  } catch (e) {}
219
  }
220
+
221
+ async function exportCSV() {
222
+ const token = document.getElementById('adminToken').value;
223
+ if (!token) { alert('必须先输入 Admin Token'); return; }
224
+ try {
225
+ const res = await fetch('/api/admin/users/export', { headers: { 'X-Admin-Token': token } });
226
+ if (!res.ok) throw new Error('导出失败');
227
+ const blob = await res.blob();
228
+ const url = window.URL.createObjectURL(blob);
229
+ const a = document.createElement('a');
230
+ a.href = url;
231
+ a.download = `cerebratex_users_${new Date().getTime()}.csv`;
232
+ document.body.appendChild(a);
233
+ a.click();
234
+ window.URL.revokeObjectURL(url);
235
+ a.remove();
236
+ } catch (e) { alert(e.message); }
237
+ }
238
  </script>
239
  </body>
240
  </html>