@lls-a1/dsh-balance-float 1.1.54 → 1.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +77 -43
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -109,10 +109,13 @@ window.__ModuleLoader__.load({
|
|
|
109
109
|
'price.miss': '未命中',
|
|
110
110
|
'price.out': '输出',
|
|
111
111
|
history: '用量趋势',
|
|
112
|
+
'history.window.today': '今天',
|
|
112
113
|
'history.window.7': '近7天',
|
|
113
114
|
'history.window.30': '近30天',
|
|
114
115
|
'history.window.month': '本月',
|
|
115
116
|
'history.calls': '{calls} 次',
|
|
117
|
+
'history.peak': '峰段 {cost}',
|
|
118
|
+
'history.valley': '谷段 {cost}',
|
|
116
119
|
'history.total': '合计 {total}',
|
|
117
120
|
version: '版本',
|
|
118
121
|
'version.open': '打开插件页(更新在这里)',
|
|
@@ -201,10 +204,13 @@ window.__ModuleLoader__.load({
|
|
|
201
204
|
'price.miss': 'Miss',
|
|
202
205
|
'price.out': 'Out',
|
|
203
206
|
history: 'Usage trend',
|
|
207
|
+
'history.window.today': 'Today',
|
|
204
208
|
'history.window.7': '7d',
|
|
205
209
|
'history.window.30': '30d',
|
|
206
210
|
'history.window.month': 'Month',
|
|
207
211
|
'history.calls': '{calls} calls',
|
|
212
|
+
'history.peak': 'Peak {cost}',
|
|
213
|
+
'history.valley': 'Valley {cost}',
|
|
208
214
|
'history.total': 'Total {total}',
|
|
209
215
|
version: 'Version',
|
|
210
216
|
'version.open': 'Open the plugin page (updates live there)',
|
|
@@ -348,6 +354,8 @@ window.__ModuleLoader__.load({
|
|
|
348
354
|
'.dbf-trend-meta{display:flex;align-items:baseline;gap:8px;margin-top:5px}',
|
|
349
355
|
'.dbf-trend-total{font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}',
|
|
350
356
|
'.dbf-trend-calls{font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
357
|
+
'.dbf-trend-split{display:flex;align-items:center;gap:6px;margin-top:2px;font-size:11px;line-height:16px;font-variant-numeric:tabular-nums}',
|
|
358
|
+
'.dbf-trend-dot{color:var(--dsw-alias-label-secondary);opacity:.6}',
|
|
351
359
|
'.dbf-bars{display:flex;align-items:flex-end;justify-content:space-between;gap:4px;height:58px;margin-top:8px;padding-bottom:2px;overflow-x:auto;scrollbar-width:none}',
|
|
352
360
|
'.dbf-bar{flex:1 0 auto;min-width:13px;max-width:32px;height:100%;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;gap:4px}',
|
|
353
361
|
'.dbf-bar-fill{width:100%;min-height:2px;border-radius:3px 3px 0 0;background:var(--dsw-alias-border-l2)}',
|
|
@@ -608,10 +616,10 @@ window.__ModuleLoader__.load({
|
|
|
608
616
|
const [bubbleUp, setBubbleUp] = useState(false);
|
|
609
617
|
// «?» next to the current billing period: reveals the peak/valley windows.
|
|
610
618
|
const [hintOpen, setHintOpen] = useState(false);
|
|
611
|
-
// A bar of the chart opens that day's detail view; the chart shows
|
|
612
|
-
// 30 days
|
|
619
|
+
// A bar of the chart opens that day's detail view; the chart shows today,
|
|
620
|
+
// 7 or 30 days, or the current month depending on the chosen window.
|
|
613
621
|
const [selectedDay, setSelectedDay] = useState(null);
|
|
614
|
-
const [chartWindow, setChartWindow] = useState('
|
|
622
|
+
const [chartWindow, setChartWindow] = useState('today');
|
|
615
623
|
// Token buckets are collapsed until asked for.
|
|
616
624
|
const [tokensOpen, setTokensOpen] = useState(false);
|
|
617
625
|
// Auto check: null | {phase, latest, current, hasUpdate}
|
|
@@ -1056,15 +1064,32 @@ window.__ModuleLoader__.load({
|
|
|
1056
1064
|
const stale = typeof snapshot?.today === 'string' && snapshot.today !== new Date(now + 8 * 3600 * 1000).toISOString().slice(0, 10);
|
|
1057
1065
|
const prices = Array.isArray(snapshot?.prices) ? snapshot.prices : [];
|
|
1058
1066
|
const allHistory = Array.isArray(snapshot?.history) ? snapshot.history : [];
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1067
|
+
const todayWindow = chartWindow === 'today';
|
|
1068
|
+
const history = todayWindow
|
|
1069
|
+
? allHistory.filter((row) => row.day === snapshot?.today)
|
|
1070
|
+
: chartWindow === 'month'
|
|
1071
|
+
? (() => {
|
|
1072
|
+
const prefix = (snapshot?.today ?? '').slice(0, 7);
|
|
1073
|
+
return allHistory.filter((row) => row.day.startsWith(prefix));
|
|
1074
|
+
})()
|
|
1075
|
+
: allHistory.slice(-Number(chartWindow));
|
|
1076
|
+
// "Today" reads the live counters: the history row is written by the
|
|
1077
|
+
// ledger and can lag behind the current turn.
|
|
1078
|
+
const windowTotal = todayWindow
|
|
1079
|
+
? (snapshot?.todayUsed ?? 0)
|
|
1080
|
+
: history.reduce((sum, row) => sum + (row.cost ?? 0), 0);
|
|
1081
|
+
const windowPeakCost = todayWindow
|
|
1082
|
+
? (snapshot?.todayPeakCost ?? 0)
|
|
1083
|
+
: history.reduce((sum, row) => sum + (row.peakCost ?? 0), 0);
|
|
1084
|
+
const windowValleyCost = todayWindow
|
|
1085
|
+
? (snapshot?.todayValleyCost ?? 0)
|
|
1086
|
+
: history.reduce((sum, row) => sum + (row.valleyCost ?? 0), 0);
|
|
1087
|
+
const windowCalls = todayWindow
|
|
1088
|
+
? (snapshot?.todayCalls ?? 0)
|
|
1089
|
+
: history.reduce((sum, row) => sum + (row.calls ?? 0), 0);
|
|
1090
|
+
const windowModels = todayWindow
|
|
1091
|
+
? (Array.isArray(snapshot?.models) ? snapshot.models : [])
|
|
1092
|
+
: (() => {
|
|
1068
1093
|
const table = {};
|
|
1069
1094
|
for (const row of history) {
|
|
1070
1095
|
for (const model of row.models ?? []) {
|
|
@@ -1401,7 +1426,7 @@ window.__ModuleLoader__.load({
|
|
|
1401
1426
|
h(
|
|
1402
1427
|
'span',
|
|
1403
1428
|
{ className: 'dbf-windows' },
|
|
1404
|
-
['7', '30', 'month'].map((key) =>
|
|
1429
|
+
['today', '7', '30', 'month'].map((key) =>
|
|
1405
1430
|
h(
|
|
1406
1431
|
'button',
|
|
1407
1432
|
{
|
|
@@ -1422,9 +1447,16 @@ window.__ModuleLoader__.load({
|
|
|
1422
1447
|
h(
|
|
1423
1448
|
'span',
|
|
1424
1449
|
{ className: 'dbf-trend-calls' },
|
|
1425
|
-
t('history.calls', { calls:
|
|
1450
|
+
t('history.calls', { calls: windowCalls }),
|
|
1426
1451
|
),
|
|
1427
1452
|
),
|
|
1453
|
+
h(
|
|
1454
|
+
'div',
|
|
1455
|
+
{ className: 'dbf-trend-split' },
|
|
1456
|
+
h('span', { className: 'dbf-peak' }, t('history.peak', { cost: '¥' + money(windowPeakCost) })),
|
|
1457
|
+
h('span', { className: 'dbf-trend-dot' }, '·'),
|
|
1458
|
+
h('span', { className: 'dbf-valley' }, t('history.valley', { cost: '¥' + money(windowValleyCost) })),
|
|
1459
|
+
),
|
|
1428
1460
|
windowModels.length > 0
|
|
1429
1461
|
? h(
|
|
1430
1462
|
'div',
|
|
@@ -1443,36 +1475,38 @@ window.__ModuleLoader__.load({
|
|
|
1443
1475
|
}),
|
|
1444
1476
|
)
|
|
1445
1477
|
: null,
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
'
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1478
|
+
todayWindow
|
|
1479
|
+
? null
|
|
1480
|
+
: h(
|
|
1481
|
+
'div',
|
|
1482
|
+
{ className: 'dbf-bars' },
|
|
1483
|
+
history.map((row) => {
|
|
1484
|
+
const value = typeof row.cost === 'number' ? row.cost : 0;
|
|
1485
|
+
const windowMax = Math.max(...history.map((entry) => entry.cost ?? 0), 0);
|
|
1486
|
+
const ratio = windowMax > 0 ? Math.max(2, Math.round((value / windowMax) * 38)) : 2;
|
|
1487
|
+
const isToday = typeof snapshot?.today === 'string' && row.day === snapshot.today;
|
|
1488
|
+
return h(
|
|
1489
|
+
'div',
|
|
1490
|
+
{
|
|
1491
|
+
key: row.day,
|
|
1492
|
+
className: 'dbf-bar' + (isToday ? ' is-today' : ''),
|
|
1493
|
+
role: 'button',
|
|
1494
|
+
tabIndex: 0,
|
|
1495
|
+
title: row.day + ' ¥' + money(value),
|
|
1496
|
+
onClick: () => setSelectedDay(row.day),
|
|
1497
|
+
onKeyDown: (event) => {
|
|
1498
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
1499
|
+
event.preventDefault();
|
|
1500
|
+
setSelectedDay(row.day);
|
|
1501
|
+
}
|
|
1502
|
+
},
|
|
1468
1503
|
},
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
)
|
|
1473
|
-
|
|
1474
|
-
)
|
|
1475
|
-
);
|
|
1504
|
+
h('div', { className: 'dbf-bar-fill', style: { height: ratio + 'px' } }),
|
|
1505
|
+
h('div', { className: 'dbf-bar-day' }, row.day.slice(8).replace(/^0/, '')),
|
|
1506
|
+
);
|
|
1507
|
+
}),
|
|
1508
|
+
),
|
|
1509
|
+
);
|
|
1476
1510
|
|
|
1477
1511
|
const selected = selectedDay === null ? null : history.find((row) => row.day === selectedDay) ?? null;
|
|
1478
1512
|
const dayBlock =
|