@@ -164,17 +164,17 @@ function updateWSStatus(connected) {
164164// ========== Dashboard ==========
165165
166166function refreshDashboard ( ) {
167- try {
168- j ( '/api/health ') . then ( function ( ) {
169- document . getElementById ( 'statToday ' ) . textContent = messageCache . length ;
170- document . getElementById ( 'statPlatforms ' ) . textContent = '--' ;
171- document . getElementById ( 'statClients ' ) . textContent = '--' ;
172- document . getElementById ( 'statPending ' ) . textContent = '--' ;
173- renderRecentMessages ( ) ;
174- } ) ;
175- } catch ( e ) {
176- document . getElementById ( 'statToday' ) . textContent = '错误' ;
177- }
167+ j ( '/api/stats' ) . then ( function ( stats ) {
168+ document . getElementById ( 'statPending ') . textContent = stats . pending || 0 ;
169+ document . getElementById ( 'statSending ' ) . textContent = stats . sending || 0 ;
170+ document . getElementById ( 'statSent ' ) . textContent = stats . sent || 0 ;
171+ document . getElementById ( 'statFailed ' ) . textContent = stats . failed || 0 ;
172+ document . getElementById ( 'statCanceled ' ) . textContent = stats . canceled || 0 ;
173+ document . getElementById ( 'statTotal' ) . textContent = stats . total || 0 ;
174+ } ) . catch ( function ( ) {
175+ document . getElementById ( 'statPending' ) . textContent = 'ERR' ;
176+ } ) ;
177+ renderRecentMessages ( ) ;
178178}
179179
180180function renderRecentMessages ( ) {
@@ -188,9 +188,9 @@ function renderRecentMessages() {
188188 var time = new Date ( m . created_at * 1000 ) . toLocaleTimeString ( 'zh-CN' ) ;
189189 return '<tr>' +
190190 '<td><span class="badge info">' + esc ( m . platform ) + '</span></td>' +
191- '<td>' + esc ( m . conversation . substring ( 0 , 20 ) ) + '</td>' +
192- '<td>' + esc ( m . content . substring ( 0 , 50 ) ) + '</td>' +
193- '<td><span class="badge success">已接收</span> </td>' +
191+ '<td>' + esc ( ( m . conversation || '' ) . substring ( 0 , 20 ) ) + '</td>' +
192+ '<td>' + esc ( ( m . content || '' ) . substring ( 0 , 50 ) ) + '</td>' +
193+ '<td>' + statusBadge ( m . status || 'Pending' ) + ' </td>' +
194194 '<td>' + time + '</td>' +
195195 '</tr>' ;
196196 } ) . join ( '' ) ;
@@ -214,11 +214,11 @@ function renderMessages() {
214214 var sender = m . sender ? m . sender . name : '--' ;
215215 return '<tr>' +
216216 '<td><span class="badge info">' + esc ( m . platform ) + '</span></td>' +
217- '<td>' + esc ( m . conversation . substring ( 0 , 24 ) ) + '</td>' +
217+ '<td>' + esc ( ( m . conversation || '' ) . substring ( 0 , 24 ) ) + '</td>' +
218218 '<td>' + esc ( sender ) + '</td>' +
219- '<td>' + esc ( m . content . substring ( 0 , 40 ) ) + '</td>' +
219+ '<td>' + esc ( ( m . content || '' ) . substring ( 0 , 40 ) ) + '</td>' +
220220 '<td>' + esc ( m . message_type ) + '</td>' +
221- '<td><span class="badge success">已接收</span> </td>' +
221+ '<td>' + statusBadge ( m . status || 'Pending' ) + ' </td>' +
222222 '<td>' + time + '</td>' +
223223 '</tr>' ;
224224 } ) . join ( '' ) ;
@@ -299,6 +299,25 @@ function esc(s) {
299299 return String ( s ) . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) . replace ( / " / g, '"' ) ;
300300}
301301
302+ function statusBadge ( status ) {
303+ var map = {
304+ Sent : 'success' ,
305+ Pending : 'warning' ,
306+ Sending : 'info' ,
307+ Failed : 'danger' ,
308+ Canceled : 'danger'
309+ } ;
310+ var label = {
311+ Sent : '已发送' ,
312+ Pending : '待发送' ,
313+ Sending : '发送中' ,
314+ Failed : '失败' ,
315+ Canceled : '已取消'
316+ } ;
317+ var cls = map [ status ] || 'info' ;
318+ return '<span class="badge ' + cls + '">' + ( label [ status ] || status || '未知' ) + '</span>' ;
319+ }
320+
302321// ========== Boot ==========
303322
304323if ( accessToken ) {
0 commit comments