From 6dd5d4053bb572d377b4e28d1b0df54356f54f91 Mon Sep 17 00:00:00 2001 From: LiRuoChen <571244399@qq.com> Date: Thu, 6 Aug 2026 16:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=99=E9=87=8F=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=A2=84=E8=AE=A1=E5=89=A9?= =?UTF-8?q?=E4=BD=99=E4=BD=BF=E7=94=A8=E6=97=B6=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExtendWebAITokenChart.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ExtendWebAITokenChart.js b/ExtendWebAITokenChart.js index 3ced529..24aadcc 100644 --- a/ExtendWebAITokenChart.js +++ b/ExtendWebAITokenChart.js @@ -27,6 +27,7 @@ let historyByAssignment = {}; let assignmentNames = {}; + let currentQuotaByAssignment = {}; let selectedAssignmentId = ''; let selectedRange = 'today'; let myChart = null; @@ -299,11 +300,20 @@ refreshAnimationId = requestAnimationFrame(render); } + function getAverageDailyUsage(points) { + if (points.length < 2) return 0; + const first = points[0]; + const last = points[points.length - 1]; + const elapsedDays = (last.timestamp - first.timestamp) / 86400000; + return elapsedDays > 0 ? Math.max(0, (last.used - first.used) / elapsedDays) : 0; + } + const currentUsageLinePlugin = { id: 'currentUsageLine', afterDraw(chart) { const points = getAssignmentPoints(selectedAssignmentId); const currentPoint = points[points.length - 1]; + const quota = currentQuotaByAssignment[selectedAssignmentId]; const yScale = chart.scales.yUsed; if (!currentPoint || !yScale) return; @@ -311,8 +321,14 @@ const { left, right, top, bottom } = chart.chartArea; if (y < top || y > bottom) return; + const remaining = numberOrNull(quota?.remaining); + const dailyUsage = getAverageDailyUsage(points); + const estimatedDays = remaining !== null && dailyUsage > 0 ? Math.ceil(remaining / dailyUsage) : null; + const text = remaining === null + ? `当前 ${currentPoint.used.toFixed(6)} CNY` + : `当前 ${currentPoint.used.toFixed(6)} CNY / 剩余 ${remaining.toFixed(6)} CNY${estimatedDays === null ? '' : ` [预计 ${estimatedDays} 天使用完毕]`}`; + const context = chart.ctx; - const text = `当前 ${currentPoint.used.toFixed(5)} CNY`; context.save(); context.setLineDash([7, 5]); context.strokeStyle = '#facc15'; @@ -462,6 +478,7 @@ const used = numberOrNull(quota && quota.used); if (!assignmentId || used === null) return false; const point = [Date.now(), used]; + currentQuotaByAssignment[assignmentId] = { remaining: numberOrNull(quota.remaining) }; historyByAssignment[assignmentId] = historyByAssignment[assignmentId] || { recent: [], archived: [] }; historyByAssignment[assignmentId].recent.push(point); historyByAssignment[assignmentId] = compactPoints([