@angelyeye/dsh-cost-tracker 1.8.15 → 1.9.1
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/CHANGELOG.md +163 -0
- package/README.en.md +90 -1
- package/README.md +95 -3
- package/client.js +738 -149
- package/config.js +132 -1
- package/credstore.js +248 -0
- package/docs/THIRD-PARTY-NOTICES.md +60 -0
- package/docs/provider-pricing.json +777 -0
- package/import.js +363 -0
- package/index.js +581 -85
- package/package.json +11 -3
- package/price-sync.js +216 -0
- package/pricing.js +111 -8
- package/schema.js +4 -0
- package/sync.js +25 -4
- package/vendor-catalog.js +198 -0
package/client.js
CHANGED
|
@@ -241,6 +241,31 @@ window.__ModuleLoader__.load({
|
|
|
241
241
|
.cost-pcard-chevron { color: var(--dsw-alias-label-tertiary, #8b93a1); flex: none; transition: transform .16s; }
|
|
242
242
|
.cost-pcard-chevron.is-open { transform: rotate(180deg); }
|
|
243
243
|
.cost-pcard-body { border-top: .5px solid var(--dsw-alias-border-l2, #e5e7eb); margin: 0 16px; padding: 12px 0 10px; }
|
|
244
|
+
/* ---------- 插件配置卡片 v1.9.0:顶部状态条 + 折叠分组 ---------- */
|
|
245
|
+
.cost-cfg-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0 10px; }
|
|
246
|
+
.cost-cfg-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 1.6; padding: 2px 9px; border-radius: 999px; border: .5px solid var(--dsw-alias-border-l2, #e5e7eb); background: var(--dsw-alias-bg-layer-3, transparent); color: var(--dsw-alias-label-secondary, #5b6472); white-space: nowrap; }
|
|
247
|
+
.cost-cfg-chip b { color: var(--dsw-alias-label-primary, #171a1f); font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
248
|
+
.cost-cfg-chip.is-on { border-color: var(--dsw-alias-brand-primary, #2563eb); color: var(--dsw-alias-brand-primary, #2563eb); }
|
|
249
|
+
.cost-sec { border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); border-radius: 10px; margin-top: 10px; overflow: hidden; }
|
|
250
|
+
.cost-sec-head { appearance: none; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; background: none; border: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
|
|
251
|
+
.cost-sec-head:hover { background: var(--dsw-alias-bg-layer-2, transparent); }
|
|
252
|
+
.cost-sec-head:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #2563eb); outline-offset: -2px; }
|
|
253
|
+
.cost-sec-title { font-size: 13px; font-weight: 600; color: var(--dsw-alias-label-primary, #171a1f); flex: none; }
|
|
254
|
+
.cost-sec-sum { font-size: 12px; color: var(--dsw-alias-label-tertiary, #8b93a1); margin-left: auto; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
255
|
+
.cost-sec-arrow { color: var(--dsw-alias-label-tertiary, #8b93a1); flex: none; transition: transform .16s; }
|
|
256
|
+
.cost-sec-arrow.is-open { transform: rotate(180deg); }
|
|
257
|
+
.cost-sec-body { padding: 2px 12px 12px; }
|
|
258
|
+
.cost-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
259
|
+
.cost-tbl th, .cost-tbl td { text-align: left; padding: 4px 6px; border-bottom: .5px solid var(--dsw-alias-border-l2, #e5e7eb); }
|
|
260
|
+
.cost-tbl th { color: var(--dsw-alias-label-secondary, #5b6472); font-weight: 500; }
|
|
261
|
+
.cost-tbl tr:last-child td { border-bottom: 0; }
|
|
262
|
+
.cost-tbl .cost-num { text-align: right; font-variant-numeric: tabular-nums; }
|
|
263
|
+
.cost-kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 12px; align-items: center; }
|
|
264
|
+
.cost-kv .k { color: var(--dsw-alias-label-secondary, #5b6472); }
|
|
265
|
+
.cost-danger { color: var(--dsw-alias-status-error, #dc2626); }
|
|
266
|
+
.cost-plan-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dsw-alias-label-secondary, #5b6472); cursor: pointer; user-select: none; }
|
|
267
|
+
.cost-subblock { border-top: .5px dashed var(--dsw-alias-border-l2, #e5e7eb); margin-top: 10px; padding-top: 10px; }
|
|
268
|
+
.cost-list { font-size: 12px; color: var(--dsw-alias-label-secondary, #5b6472); line-height: 1.7; }
|
|
244
269
|
`;
|
|
245
270
|
const tag = document.createElement("style");
|
|
246
271
|
tag.setAttribute("data-plugin-css", "cost-tracker-plugin");
|
|
@@ -763,7 +788,37 @@ window.__ModuleLoader__.load({
|
|
|
763
788
|
const mergeDash = VIEW.mergeDash;
|
|
764
789
|
const mergeUsageHeat = VIEW.mergeUsageHeat || vMergeUsageHeat;
|
|
765
790
|
|
|
766
|
-
|
|
791
|
+
/**
|
|
792
|
+
* 双轨计费口径开关(v1.9.0):金额是否含 Plan 等值总额。
|
|
793
|
+
* off(默认)= 只算按量真金白银,订阅以附注展示(与 v1.8.x 一致);
|
|
794
|
+
* on = 金额 = 按量 + 订阅等值,图表也把订阅并入堆叠。
|
|
795
|
+
* 取值优先级:服务端配置 showTotalWithPlan → 浏览器 localStorage(跨设备各存各的)
|
|
796
|
+
* 用户一改就同时写两处:localStorage 立即可用,服务端让其它浏览器/看板默认一致。
|
|
797
|
+
*/
|
|
798
|
+
const PLAN_TOTAL_KEY = "cost-tracker:showTotalWithPlan";
|
|
799
|
+
function planTotalInit(serverValue) {
|
|
800
|
+
try {
|
|
801
|
+
const ls = window.localStorage.getItem(PLAN_TOTAL_KEY);
|
|
802
|
+
if (ls === "1") return true;
|
|
803
|
+
if (ls === "0") return false;
|
|
804
|
+
} catch (_) { /* 隐私模式禁用 localStorage:回落服务端配置 */ }
|
|
805
|
+
return serverValue === true;
|
|
806
|
+
}
|
|
807
|
+
function planTotalStore(on) {
|
|
808
|
+
try { window.localStorage.setItem(PLAN_TOTAL_KEY, on ? "1" : "0"); } catch (_) {}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function planSwitch(planTotal, setPlanTotal) {
|
|
812
|
+
return e("label", { className: "cost-plan-switch", title: "开启后金额含订阅套餐等值费用(Plan 总额);关闭只统计按量真金白银" },
|
|
813
|
+
e("input", {
|
|
814
|
+
type: "checkbox",
|
|
815
|
+
checked: !!planTotal,
|
|
816
|
+
onChange: ev => setPlanTotal(ev.target.checked),
|
|
817
|
+
}),
|
|
818
|
+
e("span", null, "含 Plan 总额"));
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
function filterRow(days, setDays, onExport, onRefresh, msg, busy, peakWindows, viewCtl, onOpenVolc, planTotal, setPlanTotal) {
|
|
767
822
|
const views = viewCtl && viewCtl.available ? BOARD_VIEWS : [BOARD_VIEWS[0]];
|
|
768
823
|
return e("div", { className: "cost-row" },
|
|
769
824
|
e("select", { className: "cost-select", value: String(days), onChange: ev => setDays(parseInt(ev.target.value, 10)) },
|
|
@@ -785,6 +840,7 @@ window.__ModuleLoader__.load({
|
|
|
785
840
|
onOpenVolc
|
|
786
841
|
? e("button", { className: "cost-btn", title: "配置火山方舟 AccessKeyID / SecretAccessKey 并查看 Coding Plan 配额", onClick: onOpenVolc }, "火山方舟配额")
|
|
787
842
|
: null,
|
|
843
|
+
planSwitch(planTotal, setPlanTotal),
|
|
788
844
|
e("button", { className: "cost-btn", onClick: onExport, disabled: busy }, "导出 CSV"),
|
|
789
845
|
e("button", { className: "cost-btn", onClick: onRefresh, disabled: busy }, busy ? "刷新中…" : "刷新"),
|
|
790
846
|
msg ? e("span", { className: "cost-hint" }, msg) : null,
|
|
@@ -794,12 +850,22 @@ window.__ModuleLoader__.load({
|
|
|
794
850
|
: e("span", { className: "cost-hint" }, "峰谷时段(北京时间):" + peakWindows + " · 闲时半价"));
|
|
795
851
|
}
|
|
796
852
|
|
|
797
|
-
function statCards(dash, balance, viewCtl) {
|
|
853
|
+
function statCards(dash, balance, viewCtl, planTotal) {
|
|
798
854
|
const today = dash.today || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
|
|
799
855
|
const month = dash.month || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
|
|
800
856
|
const all = dash.all || { real: 0, calls: 0, tokens: 0, sub: 0, subCalls: 0, subTokens: 0 };
|
|
801
|
-
//
|
|
802
|
-
|
|
857
|
+
// 金额卡:口径由「含 Plan 总额」开关决定
|
|
858
|
+
// off:主值 = 按量消费(不含订阅会员等效费用);副行附注订阅等效
|
|
859
|
+
// on :主值 = 按量 + 订阅等值(Plan 总额);副行说明拆分,避免看数不明口径
|
|
860
|
+
const money = (t) => planTotal ? (Number(t.real) || 0) + (Number(t.sub) || 0) : (Number(t.real) || 0);
|
|
861
|
+
const moneySub = (t) => {
|
|
862
|
+
const base = "调用 " + fmtInt(t.calls) + " 次 · Tokens " + fmtCompact(t.tokens);
|
|
863
|
+
if (planTotal) {
|
|
864
|
+
return base + " · 含订阅 ¥" + fmtMoney(t.sub) + (t.subCalls ? "(" + fmtInt(t.subCalls) + " 次)" : "");
|
|
865
|
+
}
|
|
866
|
+
return base + (t.sub > 0 ? " · 订阅 ¥" + fmtMoney(t.sub) : "");
|
|
867
|
+
};
|
|
868
|
+
const planBadge = planTotal ? "(含 Plan)" : "";
|
|
803
869
|
// 余额卡
|
|
804
870
|
let balValue = "—", balSub = "查询中…";
|
|
805
871
|
if (balance && balance.ok) {
|
|
@@ -819,9 +885,9 @@ window.__ModuleLoader__.load({
|
|
|
819
885
|
: "本机";
|
|
820
886
|
const tag = (t) => scopeNote + (viewCtl && viewCtl.pending > 0 && viewCtl.view !== "local" ? " · 待同步 " + viewCtl.pending + " 条" : "");
|
|
821
887
|
return e("div", { className: "cost-cards" },
|
|
822
|
-
statCard("今日费用(CNY)[" + tag() + "]", "¥" + fmtMoney(today
|
|
823
|
-
statCard("本月费用(CNY)", "¥" + fmtMoney(month
|
|
824
|
-
statCard("总花费(CNY)", "¥" + fmtMoney(all
|
|
888
|
+
statCard("今日费用(CNY)" + planBadge + "[" + tag() + "]", "¥" + fmtMoney(money(today)), moneySub(today)),
|
|
889
|
+
statCard("本月费用(CNY)" + planBadge, "¥" + fmtMoney(money(month)), moneySub(month)),
|
|
890
|
+
statCard("总花费(CNY)" + planBadge, "¥" + fmtMoney(money(all)), "调用 " + fmtInt(all.calls) + " 次 · Tokens " + fmtCompact(all.tokens) + (all.sub > 0 ? (planTotal ? " · 含订阅 ¥" + fmtMoney(all.sub) : " · 订阅 ¥" + fmtMoney(all.sub)) : "")),
|
|
825
891
|
statCard("API 请求次数", fmtInt(all.calls + all.subCalls),
|
|
826
892
|
"按量 " + fmtInt(all.calls) + " · 订阅 " + fmtInt(all.subCalls)),
|
|
827
893
|
statCard("Tokens", fmtInt(all.tokens + all.subTokens),
|
|
@@ -829,12 +895,17 @@ window.__ModuleLoader__.load({
|
|
|
829
895
|
statCard("总余额(CNY)", balValue, balSub));
|
|
830
896
|
}
|
|
831
897
|
|
|
832
|
-
function mainPanel(dash, tab, setTab, scheme, setScheme) {
|
|
898
|
+
function mainPanel(dash, tab, setTab, scheme, setScheme, planTotal) {
|
|
833
899
|
let chart = null;
|
|
834
900
|
let legend = [];
|
|
835
901
|
const labels = dash.byDay.map(d => d.label);
|
|
836
902
|
const titles = dash.byDay.map(d => d.date);
|
|
837
903
|
const fmtMoneyValue = (v) => "¥" + fmtMoney(v);
|
|
904
|
+
// 含 Plan 总额:订阅等值按天并入图(byDay[].sub 由服务端单独给出),
|
|
905
|
+
// 作为独立图例项而不是混进峰谷段 —— 订阅本就不分峰谷,混进去会污染时段口径。
|
|
906
|
+
const subTotal = dash.byDay.reduce((s, d) => s + (Number(d.sub) || 0), 0);
|
|
907
|
+
const showSub = !!planTotal && subTotal > 0;
|
|
908
|
+
const totalCost = planTotal ? (Number(dash.realCost) || 0) + (Number(dash.subEquivalent) || 0) : (Number(dash.realCost) || 0);
|
|
838
909
|
if (tab === "period") {
|
|
839
910
|
// 图例只列真实存在的档位:官方定价只有「高峰 / 闲时」两档;
|
|
840
911
|
// flat(不分峰谷:订阅套餐、非 DeepSeek provider 兜底价等)**为 0 时不占图例位置**——
|
|
@@ -842,16 +913,20 @@ window.__ModuleLoader__.load({
|
|
|
842
913
|
const flatTotal = dash.byDay.reduce((s, d) => s + (Number(d.flat) || 0), 0);
|
|
843
914
|
const hasFlat = flatTotal > 0;
|
|
844
915
|
const segs = [{ name: "闲时", color: BLUE }, { name: "高峰", color: AMBER }]
|
|
845
|
-
.concat(hasFlat ? [{ name: "不分峰谷", color: GRAY }] : [])
|
|
846
|
-
|
|
916
|
+
.concat(hasFlat ? [{ name: "不分峰谷", color: GRAY }] : [])
|
|
917
|
+
.concat(showSub ? [{ name: "订阅等值", color: GREEN }] : []);
|
|
918
|
+
const rows = dash.byDay.map(d => {
|
|
919
|
+
const base = hasFlat ? [d.off, d.peak, d.flat] : [d.off, d.peak];
|
|
920
|
+
return showSub ? base.concat([d.sub || 0]) : base;
|
|
921
|
+
});
|
|
847
922
|
chart = e(StackedBarsChart, { labels, titles, segs, rows, fmtY: fmtAxisMoney, fmtValue: fmtMoneyValue });
|
|
848
923
|
legend = segs;
|
|
849
924
|
} else {
|
|
850
925
|
// 模型按总消费降序排名(byModelDay 已按费用降序),全部展示、不合并、不循环:
|
|
851
926
|
// 第 1 名取色阶首色(最深,垫底),名次越靠后越浅;色相按所选方案漂移
|
|
852
|
-
const models = dash.byModelDay.filter(m => !m.subscription);
|
|
927
|
+
const models = dash.byModelDay.filter(m => planTotal || !m.subscription);
|
|
853
928
|
const sc = COLOR_SCHEMES[scheme] || COLOR_SCHEMES["orange-yellow"];
|
|
854
|
-
const segs = models.map((m, i) => ({ name: shortModel(m.model), color: schemeColor(i, sc) }));
|
|
929
|
+
const segs = models.map((m, i) => ({ name: shortModel(m.model) + (m.subscription ? "(订阅)" : ""), color: schemeColor(i, sc) }));
|
|
855
930
|
const daySegs = dash.byDay.map((d, di) => {
|
|
856
931
|
const list = [];
|
|
857
932
|
for (let i = 0; i < models.length; i++) {
|
|
@@ -865,7 +940,7 @@ window.__ModuleLoader__.load({
|
|
|
865
940
|
}
|
|
866
941
|
return e("div", { className: "cost-panel" },
|
|
867
942
|
e("div", { className: "cost-row" },
|
|
868
|
-
e("span", { className: "cost-panel-title" }, "消费金额(CNY)¥" + fmtMoney(
|
|
943
|
+
e("span", { className: "cost-panel-title" }, "消费金额(CNY)¥" + fmtMoney(totalCost) + (planTotal ? "(含 Plan 总额)" : "")),
|
|
869
944
|
tab === "model" ? e("span", { style: { display: "inline-flex", alignItems: "center", gap: "4px", marginLeft: "10px" } },
|
|
870
945
|
Object.keys(COLOR_SCHEMES).map(k => e("button", {
|
|
871
946
|
key: k,
|
|
@@ -1430,97 +1505,50 @@ window.__ModuleLoader__.load({
|
|
|
1430
1505
|
}
|
|
1431
1506
|
|
|
1432
1507
|
// 设置面板:峰谷计价与提示
|
|
1508
|
+
/**
|
|
1509
|
+
* 「峰谷计价与提示」看板面板(v1.9.0 起**只读**)。
|
|
1510
|
+
* 设置入口统一到「设置 → 插件 → 插件配置 → 花费统计 → 峰谷计价与提示」,
|
|
1511
|
+
* 这里只回显当前档位与生效配置,避免两处都能改造成口径不一致。
|
|
1512
|
+
* 预览按钮保留:它只是本地弹窗预览,不改任何持久化状态。
|
|
1513
|
+
*/
|
|
1433
1514
|
function PeakPanel(props) {
|
|
1434
1515
|
const [snap, setSnap] = useState(null);
|
|
1435
|
-
const [draft, setDraft] = useState(null);
|
|
1436
1516
|
const [now, setNow] = useState(Date.now());
|
|
1437
|
-
const [savedMsg, setSavedMsg] = useState("");
|
|
1438
1517
|
function load() {
|
|
1439
|
-
apiCall("peak", {}).then(v => {
|
|
1440
|
-
if (v && v.ok) {
|
|
1441
|
-
setSnap(v);
|
|
1442
|
-
setDraft(Object.assign({}, v.config || {}));
|
|
1443
|
-
}
|
|
1444
|
-
}).catch(() => {});
|
|
1518
|
+
apiCall("peak", {}).then(v => { if (v && v.ok) setSnap(v); }).catch(() => {});
|
|
1445
1519
|
}
|
|
1446
1520
|
useEffect(() => { load(); }, []);
|
|
1447
1521
|
useEffect(() => {
|
|
1448
1522
|
const id = setInterval(() => setNow(Date.now()), 30000);
|
|
1449
1523
|
return () => clearInterval(id);
|
|
1450
1524
|
}, []);
|
|
1451
|
-
function setField(k, v) {
|
|
1452
|
-
setDraft(d => Object.assign({}, d, { [k]: v }));
|
|
1453
|
-
}
|
|
1454
|
-
function save() {
|
|
1455
|
-
apiCall("peak-config", draft || {}).then(v => {
|
|
1456
|
-
if (v && typeof v === 'object') {
|
|
1457
|
-
setSnap(s => Object.assign({}, s, { config: v, enabled: v.peakEnabled, notice: v.peakNotice, style: v.peakStyle, alert: { enabled: v.peakAlertEnabled, ahead: v.peakAlertAhead, target: v.peakAlertTarget, position: v.peakAlertPosition, webNotify: v.peakAlertWebNotify } }));
|
|
1458
|
-
setDraft(Object.assign({}, v));
|
|
1459
|
-
setSavedMsg("已保存");
|
|
1460
|
-
setTimeout(() => setSavedMsg(""), 2000);
|
|
1461
|
-
}
|
|
1462
|
-
}).catch(() => setSavedMsg("保存失败"));
|
|
1463
|
-
}
|
|
1464
1525
|
function preview(kind) {
|
|
1465
1526
|
window.dispatchEvent(new CustomEvent(PEAK_PREVIEW_EVENT, { detail: { kind } }));
|
|
1466
1527
|
}
|
|
1467
|
-
const
|
|
1468
|
-
const
|
|
1469
|
-
const
|
|
1528
|
+
const cfg = (snap && snap.config) || {};
|
|
1529
|
+
const noticeOn = snap && snap.notice !== false && cfg.peakNotice !== false;
|
|
1530
|
+
const rows = [
|
|
1531
|
+
["峰谷计价", cfg.peakEnabled !== false ? "已启用" : "已停用"],
|
|
1532
|
+
["时段条样式", cfg.peakStyle === "classic" ? "环形表盘(24h)" : "简洁(单行紧凑)"],
|
|
1533
|
+
["切换提醒", cfg.peakAlertEnabled !== false ? ("提前 " + (cfg.peakAlertAhead == null ? 2 : cfg.peakAlertAhead) + " 分钟 · " + (cfg.peakAlertTarget === "peak" ? "进入峰时" : cfg.peakAlertTarget === "offpeak" ? "进入谷时" : "峰和谷")) : "已关闭"],
|
|
1534
|
+
["系统通知", cfg.peakAlertWebNotify === true ? "已开启" : "未开启"],
|
|
1535
|
+
["当前档位", snap && snap.phase ? (snap.phase.weekend ? "周末全谷价" : snap.phase.inPeak ? "高峰时段" : "平价时段") : "…"],
|
|
1536
|
+
];
|
|
1470
1537
|
return e("div", { className: "cost-panel" },
|
|
1471
1538
|
e("div", { className: "cost-row" },
|
|
1472
1539
|
e("span", { className: "cost-panel-title" }, "峰谷计价与提示"),
|
|
1473
1540
|
e("span", { className: "cost-spacer" }),
|
|
1474
|
-
e("button", { className: "cost-btn", onClick:
|
|
1475
|
-
|
|
1476
|
-
e("
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
e("
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
e("option", { value: "compact" }, "简洁(单行紧凑)"),
|
|
1486
|
-
e("option", { value: "classic" }, "环形表盘(24h)"))),
|
|
1487
|
-
d.peakStyle === "classic" ? e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1488
|
-
e("input", { type: "checkbox", checked: d.peakShowTickLabels !== false, onChange: ev => setField("peakShowTickLabels", ev.target.checked) }),
|
|
1489
|
-
e("span", null, "显示时间(00:00–21:00 刻度)"))
|
|
1490
|
-
: e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1491
|
-
e("input", { type: "checkbox", checked: d.peakCompactStack === true, onChange: ev => setField("peakCompactStack", ev.target.checked) }),
|
|
1492
|
-
e("span", null, "双行紧凑(上下布局)"),
|
|
1493
|
-
d.peakCompactStack === true ? e("select", { className: "cost-select", value: d.peakCompactOrder === "text-first" ? "text-first" : "bar-first", onChange: ev => setField("peakCompactOrder", ev.target.value) },
|
|
1494
|
-
e("option", { value: "bar-first" }, "时段条在上·文字在下"),
|
|
1495
|
-
e("option", { value: "text-first" }, "文字在上·时段条在下"))
|
|
1496
|
-
: null),
|
|
1497
|
-
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1498
|
-
e("input", { type: "checkbox", checked: d.peakAlertEnabled !== false, onChange: ev => setField("peakAlertEnabled", ev.target.checked) }),
|
|
1499
|
-
e("span", null, "峰/谷切换前弹窗提醒")),
|
|
1500
|
-
d.peakAlertEnabled !== false ? e("div", { className: "cost-row", style: { gap: "8px" } },
|
|
1501
|
-
e("span", null, "提前提醒(分钟,1-30)"),
|
|
1502
|
-
e("input", { className: "cost-input", style: { width: "80px" }, type: "number", min: 1, max: 30, value: String(d.peakAlertAhead == null ? 2 : d.peakAlertAhead), onChange: ev => { const n = parseInt(ev.target.value, 10); if (Number.isInteger(n) && n >= 1 && n <= 30) setField("peakAlertAhead", n); } }),
|
|
1503
|
-
e("span", null, "提醒类型"),
|
|
1504
|
-
e("select", { className: "cost-select", value: d.peakAlertTarget === "peak" || d.peakAlertTarget === "offpeak" ? d.peakAlertTarget : "both", onChange: ev => setField("peakAlertTarget", ev.target.value) },
|
|
1505
|
-
e("option", { value: "both" }, "峰和谷"),
|
|
1506
|
-
e("option", { value: "peak" }, "进入峰时"),
|
|
1507
|
-
e("option", { value: "offpeak" }, "进入谷时")),
|
|
1508
|
-
e("span", null, "弹窗位置"),
|
|
1509
|
-
e("select", { className: "cost-select", value: d.peakAlertPosition === "center" ? "center" : "corner", onChange: ev => setField("peakAlertPosition", ev.target.value) },
|
|
1510
|
-
e("option", { value: "corner" }, "右下角"),
|
|
1511
|
-
e("option", { value: "center" }, "屏幕中心")))
|
|
1512
|
-
: null,
|
|
1513
|
-
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1514
|
-
e("input", { type: "checkbox", checked: d.peakAlertWebNotify === true, onChange: ev => setField("peakAlertWebNotify", ev.target.checked) }),
|
|
1515
|
-
e("span", null, "同步发送系统通知(需授权通知权限)")),
|
|
1516
|
-
e("div", { className: "cost-row", style: { gap: "8px", marginTop: "4px" } },
|
|
1517
|
-
e("span", null, "预览弹窗"),
|
|
1518
|
-
e("button", { className: "cost-btn", onClick: () => preview("peak") }, "预览进入峰"),
|
|
1519
|
-
e("button", { className: "cost-btn", onClick: () => preview("offpeak") }, "预览进入谷"),
|
|
1520
|
-
savedMsg ? e("span", { className: "cost-hint" }, savedMsg) : null),
|
|
1521
|
-
e("div", { className: "cost-hint", style: { marginTop: "6px" } },
|
|
1522
|
-
"峰时段(北京时间):" + (snap ? snap.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)") + "。生效时间:" + (snap ? snap.effectiveAt : "2026-08-01T00:00:00Z") + "。当前:" + (cfgSnap && cfgSnap.phase ? (cfgSnap.phase.weekend ? "周末全谷价" : cfgSnap.phase.inPeak ? "高峰时段" : "平价时段") : "…"))),
|
|
1523
|
-
noticeOn ? e("div", { style: { marginTop: "8px" } }, e(PeakStrip, { snap: cfgSnap, style: d.peakStyle || "compact", wide: true, now, ringSize: 150 }))
|
|
1541
|
+
e("button", { className: "cost-btn", onClick: () => preview("peak") }, "预览进入峰"),
|
|
1542
|
+
e("button", { className: "cost-btn", onClick: () => preview("offpeak") }, "预览进入谷"),
|
|
1543
|
+
e("button", { className: "cost-btn", onClick: load }, "刷新")),
|
|
1544
|
+
e("div", { className: "cost-sync-ro", style: { marginTop: "8px" } },
|
|
1545
|
+
rows.map(r => e("div", { key: "pk" + r[0], className: "cost-row", style: { gap: "8px" } },
|
|
1546
|
+
e("span", { className: "k", style: { minWidth: "90px" } }, r[0]),
|
|
1547
|
+
e("span", { className: "v" }, r[1])))),
|
|
1548
|
+
e("div", { className: "cost-hint", style: { marginTop: "6px" } },
|
|
1549
|
+
"峰时段(北京时间):" + (snap ? snap.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)") +
|
|
1550
|
+
"。当前:" + (snap && snap.phase ? (snap.phase.weekend ? "周末全谷价" : snap.phase.inPeak ? "高峰时段" : "平价时段") : "…")),
|
|
1551
|
+
noticeOn ? e("div", { style: { marginTop: "8px" } }, e(PeakStrip, { snap, style: cfg.peakStyle || "compact", wide: true, now, ringSize: 150 }))
|
|
1524
1552
|
: e("p", { className: "cost-hint", style: { marginTop: "8px" } }, "提示已隐藏:需启用峰谷计价并开启「峰时高价时段显著提示」。"),
|
|
1525
1553
|
e(SyncReadonlyCard, { sync: props.sync }));
|
|
1526
1554
|
}
|
|
@@ -1567,15 +1595,47 @@ window.__ModuleLoader__.load({
|
|
|
1567
1595
|
// ============================================================
|
|
1568
1596
|
function PluginConfigCard() {
|
|
1569
1597
|
const [st, setSt] = useState(null);
|
|
1598
|
+
const [prices, setPrices] = useState(null);
|
|
1599
|
+
const [imp, setImp] = useState(null);
|
|
1600
|
+
const [peakSnap, setPeakSnap] = useState(null);
|
|
1570
1601
|
const [draft, setDraft] = useState({});
|
|
1571
|
-
|
|
1572
|
-
const [
|
|
1573
|
-
const [
|
|
1574
|
-
|
|
1602
|
+
// 分组草稿(各自独立保存;互不覆盖)
|
|
1603
|
+
const [peakDraft, setPeakDraft] = useState({});
|
|
1604
|
+
const [bill, setBill] = useState({ showTotalWithPlan: false, priceMatch: "fuzzy", catalogFxRate: 7.2, planRows: [], priceRows: [] });
|
|
1605
|
+
const [psDraft, setPsDraft] = useState({ priceSyncUrl: "", priceSyncAutoCheck: true });
|
|
1606
|
+
const [impDraft, setImpDraft] = useState({ autoImport: true });
|
|
1607
|
+
const [volcId, setVolcId] = useState("");
|
|
1608
|
+
const [volcSecret, setVolcSecret] = useState("");
|
|
1609
|
+
const [volcHasSecret, setVolcHasSecret] = useState(false);
|
|
1610
|
+
const [volcBackend, setVolcBackend] = useState("");
|
|
1611
|
+
const [volcData, setVolcData] = useState(null);
|
|
1612
|
+
const [recomputeRes, setRecomputeRes] = useState(null);
|
|
1613
|
+
const [confirmClear, setConfirmClear] = useState(false);
|
|
1614
|
+
const [msg, setMsg] = useState({});
|
|
1615
|
+
const [busy, setBusy] = useState("");
|
|
1616
|
+
const [now, setNow] = useState(Date.now());
|
|
1617
|
+
// 界面显示三开关(独立于其它草稿:勾选即刻生效并落盘)
|
|
1575
1618
|
const [uiDraft, setUiDraft] = useState({ uiDockEnabled: true, uiPeakEnabled: true, uiDashboardEnabled: true });
|
|
1576
1619
|
const [uiMsg, setUiMsg] = useState("");
|
|
1577
1620
|
// 折叠态:与宿主「插件配置」里其它卡片一致——默认收起,点标题展开
|
|
1578
1621
|
const [open, setOpen] = useState(false);
|
|
1622
|
+
// 当前展开的分组(手风琴;默认展开「多机汇总」,其余收起)
|
|
1623
|
+
const [openSec, setOpenSec] = useState("cloud");
|
|
1624
|
+
function say(group, text) {
|
|
1625
|
+
setMsg(prev => Object.assign({}, prev, { [group]: text }));
|
|
1626
|
+
setTimeout(() => setMsg(prev => Object.assign({}, prev, { [group]: "" })), 4000);
|
|
1627
|
+
}
|
|
1628
|
+
function loadPrices() {
|
|
1629
|
+
apiCall("prices", {}).then(v => { if (v && v.ok) setPrices(v); }).catch(() => {});
|
|
1630
|
+
}
|
|
1631
|
+
function loadImport() {
|
|
1632
|
+
apiCall("import-status", {}).then(v => { if (v && v.ok) setImp(v); }).catch(() => {});
|
|
1633
|
+
}
|
|
1634
|
+
function loadPeak() {
|
|
1635
|
+
apiCall("peak", {}).then(v => {
|
|
1636
|
+
if (v && v.ok) { setPeakSnap(v); setPeakDraft(Object.assign({}, v.config || {})); }
|
|
1637
|
+
}).catch(() => {});
|
|
1638
|
+
}
|
|
1579
1639
|
function load() {
|
|
1580
1640
|
apiCall("sync", {}).then(v => {
|
|
1581
1641
|
if (!v) return;
|
|
@@ -1586,8 +1646,11 @@ window.__ModuleLoader__.load({
|
|
|
1586
1646
|
cloudUrl: v.url || "",
|
|
1587
1647
|
cloudToken: "",
|
|
1588
1648
|
syncIntervalSec: v.intervalSec || 60,
|
|
1649
|
+
syncBatchSize: v.syncBatchSize || 500,
|
|
1589
1650
|
maskSessionId: !!v.maskSessionId,
|
|
1590
1651
|
includePurpose: v.includePurpose !== false,
|
|
1652
|
+
syncRollups: v.syncRollups !== false,
|
|
1653
|
+
syncSinceDays: typeof v.syncSinceDays === "number" ? v.syncSinceDays : 180,
|
|
1591
1654
|
cloudView: v.view || "local",
|
|
1592
1655
|
});
|
|
1593
1656
|
// 界面显示:缺省视为可见(与 normalizeUiConfig 同一真值语义)
|
|
@@ -1596,40 +1659,168 @@ window.__ModuleLoader__.load({
|
|
|
1596
1659
|
uiPeakEnabled: v.uiPeakEnabled !== false,
|
|
1597
1660
|
uiDashboardEnabled: v.uiDashboardEnabled !== false,
|
|
1598
1661
|
});
|
|
1662
|
+
setBill({
|
|
1663
|
+
showTotalWithPlan: v.showTotalWithPlan === true,
|
|
1664
|
+
priceMatch: v.priceMatch === "exact" ? "exact" : "fuzzy",
|
|
1665
|
+
catalogFxRate: typeof v.catalogFxRate === "number" ? v.catalogFxRate : 7.2,
|
|
1666
|
+
planRows: planOverridesToRows(v.planOverrides),
|
|
1667
|
+
priceRows: priceOverridesToRows(v.priceOverrides),
|
|
1668
|
+
});
|
|
1669
|
+
setPsDraft({ priceSyncUrl: v.priceSyncUrl || "", priceSyncAutoCheck: v.priceSyncAutoCheck !== false });
|
|
1670
|
+
setImpDraft({ autoImport: v.autoImport !== false });
|
|
1671
|
+
if (typeof v.volcengineAccessKeyId === "string" && v.volcengineAccessKeyId) setVolcId(prev => prev || v.volcengineAccessKeyId);
|
|
1672
|
+
setVolcHasSecret(!!v.volcengineHasSecret);
|
|
1673
|
+
setVolcBackend(v.volcengineSecretBackend || "");
|
|
1599
1674
|
}).catch(() => {});
|
|
1675
|
+
loadPrices();
|
|
1676
|
+
loadImport();
|
|
1677
|
+
loadPeak();
|
|
1600
1678
|
}
|
|
1601
1679
|
useEffect(() => { load(); }, []);
|
|
1680
|
+
useEffect(() => {
|
|
1681
|
+
const id = setInterval(() => setNow(Date.now()), 30000);
|
|
1682
|
+
return () => clearInterval(id);
|
|
1683
|
+
}, []);
|
|
1602
1684
|
const set = (k, v) => setDraft(prev => Object.assign({}, prev, { [k]: v }));
|
|
1685
|
+
const setPeak = (k, v) => setPeakDraft(prev => Object.assign({}, prev, { [k]: v }));
|
|
1686
|
+
const setBillField = (k, v) => setBill(prev => Object.assign({}, prev, { [k]: v }));
|
|
1603
1687
|
const field = (label, node, hint) => [
|
|
1604
1688
|
e("span", { key: "k" + label, className: "k" }, label),
|
|
1605
1689
|
e("span", { key: "v" + label }, node, hint ? e("span", { className: "cost-hint", style: { marginLeft: "8px" } }, hint) : null),
|
|
1606
1690
|
];
|
|
1691
|
+
// ---------- 各分组动作 ----------
|
|
1607
1692
|
function save() {
|
|
1608
|
-
setBusy(
|
|
1693
|
+
setBusy("cloud"); say("cloud", "");
|
|
1609
1694
|
const patch = Object.assign({}, draft);
|
|
1610
1695
|
if (!patch.cloudToken) delete patch.cloudToken; // 留空 = 不改令牌
|
|
1611
1696
|
if (!patch.cloudUrl) patch.cloudEnabled = false;
|
|
1612
1697
|
apiCall("sync-config", patch).then(v => {
|
|
1613
|
-
setBusy(
|
|
1614
|
-
|
|
1698
|
+
setBusy("");
|
|
1699
|
+
say("cloud", v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
|
|
1615
1700
|
load();
|
|
1616
|
-
}).catch(err => { setBusy(
|
|
1701
|
+
}).catch(err => { setBusy(""); say("cloud", "保存失败:" + String(err && err.message ? err.message : err)); });
|
|
1617
1702
|
}
|
|
1618
1703
|
function test() {
|
|
1619
|
-
setBusy(
|
|
1704
|
+
setBusy("cloud"); say("cloud", "测试中…");
|
|
1620
1705
|
apiCall("sync-test", { config: Object.assign({}, draft, { cloudToken: draft.cloudToken || undefined }) }).then(v => {
|
|
1621
|
-
setBusy(
|
|
1622
|
-
|
|
1623
|
-
}).catch(err => { setBusy(
|
|
1706
|
+
setBusy("");
|
|
1707
|
+
say("cloud", v && v.ok ? ("连接正常 · 服务端 " + (v.serviceVersion || "?") + (v.selfRegister ? " · 允许自注册" : "")) : ("连接失败:" + ((v && v.error) || "未知错误")));
|
|
1708
|
+
}).catch(err => { setBusy(""); say("cloud", "连接失败:" + String(err && err.message ? err.message : err)); });
|
|
1624
1709
|
}
|
|
1625
1710
|
function syncNow(full) {
|
|
1626
|
-
setBusy(
|
|
1711
|
+
setBusy("cloud"); say("cloud", "同步中…");
|
|
1627
1712
|
apiCall("sync-now", full ? { full: true } : {}).then(v => {
|
|
1628
|
-
setBusy(
|
|
1713
|
+
setBusy("");
|
|
1629
1714
|
const r = (v && v.result) || {};
|
|
1630
|
-
|
|
1715
|
+
say("cloud", r.error ? ("同步失败:" + r.error) : ("已同步:新增 " + (r.accepted || 0) + " · 去重 " + (r.duplicates || 0) + " · 日汇总 " + (r.rollups || 0)));
|
|
1631
1716
|
load();
|
|
1632
|
-
}).catch(err => { setBusy(
|
|
1717
|
+
}).catch(err => { setBusy(""); say("cloud", "同步失败:" + String(err && err.message ? err.message : err)); });
|
|
1718
|
+
}
|
|
1719
|
+
/** 峰谷计价与提示:只作用于界面提示与档位判定,不改历史记录 */
|
|
1720
|
+
function savePeak() {
|
|
1721
|
+
setBusy("peak"); say("peak", "");
|
|
1722
|
+
apiCall("peak-config", peakDraft || {}).then(v => {
|
|
1723
|
+
setBusy("");
|
|
1724
|
+
if (v && typeof v === "object") {
|
|
1725
|
+
setPeakDraft(Object.assign({}, v));
|
|
1726
|
+
setPeakSnap(s => Object.assign({}, s, {
|
|
1727
|
+
config: v, enabled: v.peakEnabled, notice: v.peakNotice, style: v.peakStyle,
|
|
1728
|
+
alert: { enabled: v.peakAlertEnabled, ahead: v.peakAlertAhead, target: v.peakAlertTarget, position: v.peakAlertPosition, webNotify: v.peakAlertWebNotify },
|
|
1729
|
+
}));
|
|
1730
|
+
say("peak", "已保存");
|
|
1731
|
+
} else say("peak", "保存失败");
|
|
1732
|
+
}).catch(err => { setBusy(""); say("peak", "保存失败:" + String(err && err.message ? err.message : err)); });
|
|
1733
|
+
}
|
|
1734
|
+
/** 计价与目录:口径开关 + 目录匹配 + 覆盖价(含订阅归类) */
|
|
1735
|
+
function saveBilling() {
|
|
1736
|
+
setBusy("bill"); say("bill", "");
|
|
1737
|
+
apiCall("billing-config", {
|
|
1738
|
+
showTotalWithPlan: !!bill.showTotalWithPlan,
|
|
1739
|
+
priceMatch: bill.priceMatch === "exact" ? "exact" : "fuzzy",
|
|
1740
|
+
catalogFxRate: Number(bill.catalogFxRate) || 7.2,
|
|
1741
|
+
planOverrides: planRowsToObj(bill.planRows),
|
|
1742
|
+
priceOverrides: priceRowsToObj(bill.priceRows),
|
|
1743
|
+
}).then(v => {
|
|
1744
|
+
setBusy("");
|
|
1745
|
+
say("bill", v && v.ok ? "已保存(对之后入库的记录生效)" : "保存失败:" + ((v && v.error) || "未知错误"));
|
|
1746
|
+
loadPrices();
|
|
1747
|
+
}).catch(err => { setBusy(""); say("bill", "保存失败:" + String(err && err.message ? err.message : err)); });
|
|
1748
|
+
}
|
|
1749
|
+
function savePriceSync() {
|
|
1750
|
+
setBusy("bill"); say("bill", "");
|
|
1751
|
+
apiCall("prices-config", { priceSyncUrl: psDraft.priceSyncUrl, priceSyncAutoCheck: !!psDraft.priceSyncAutoCheck }).then(v => {
|
|
1752
|
+
setBusy("");
|
|
1753
|
+
say("bill", v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
|
|
1754
|
+
}).catch(err => { setBusy(""); say("bill", "保存失败:" + String(err && err.message ? err.message : err)); });
|
|
1755
|
+
}
|
|
1756
|
+
function runPriceSync(apply) {
|
|
1757
|
+
setBusy("price"); say("price", apply ? "抓取并应用中…" : "核对中…");
|
|
1758
|
+
apiCall("prices-sync", { apply: !!apply }).then(v => {
|
|
1759
|
+
setBusy("");
|
|
1760
|
+
if (!v || v.ok !== true) { say("price", "失败:" + ((v && v.error) || "未知错误")); return; }
|
|
1761
|
+
say("price", v.applied ? ("已应用新价:" + (v.era || "")) : (v.diff ? ("发现差异:" + v.diff) : "与当前生效价一致"));
|
|
1762
|
+
loadPrices();
|
|
1763
|
+
}).catch(err => { setBusy(""); say("price", "失败:" + String(err && err.message ? err.message : err)); });
|
|
1764
|
+
}
|
|
1765
|
+
function saveImportCfg() {
|
|
1766
|
+
setBusy("imp"); say("imp", "");
|
|
1767
|
+
apiCall("import-config", { autoImport: !!impDraft.autoImport }).then(v => {
|
|
1768
|
+
setBusy("");
|
|
1769
|
+
say("imp", v && v.ok ? "已保存" : "保存失败:" + ((v && v.error) || "未知错误"));
|
|
1770
|
+
}).catch(err => { setBusy(""); say("imp", "保存失败:" + String(err && err.message ? err.message : err)); });
|
|
1771
|
+
}
|
|
1772
|
+
function runImport() {
|
|
1773
|
+
setBusy("imp"); say("imp", "扫描会话日志…");
|
|
1774
|
+
apiCall("import-run", {}).then(v => {
|
|
1775
|
+
setBusy("");
|
|
1776
|
+
say("imp", v && v.ok ? ("完成:扫描 " + v.scanned + " 个日志,新增 " + v.imported + " 条") : ("失败:" + ((v && v.error) || "未知错误")));
|
|
1777
|
+
loadImport();
|
|
1778
|
+
}).catch(err => { setBusy(""); say("imp", "失败:" + String(err && err.message ? err.message : err)); });
|
|
1779
|
+
}
|
|
1780
|
+
function runRecompute(apply) {
|
|
1781
|
+
setBusy("data"); say("data", apply ? "重算并写回…" : "试算中…");
|
|
1782
|
+
apiCall("recompute", { apply: !!apply }).then(v => {
|
|
1783
|
+
setBusy("");
|
|
1784
|
+
if (!v || v.ok !== true) { say("data", "失败:" + ((v && v.error) || "未知错误")); return; }
|
|
1785
|
+
setRecomputeRes(v);
|
|
1786
|
+
say("data", v.note || (apply ? "已重算" : "试算完成"));
|
|
1787
|
+
}).catch(err => { setBusy(""); say("data", "失败:" + String(err && err.message ? err.message : err)); });
|
|
1788
|
+
}
|
|
1789
|
+
function exportCsv() {
|
|
1790
|
+
setBusy("data"); say("data", "导出中…");
|
|
1791
|
+
apiCall("export", {}).then(v => {
|
|
1792
|
+
setBusy("");
|
|
1793
|
+
say("data", v && v.ok ? "已导出 " + v.count + " 条到 " + v.path : "导出失败:" + ((v && v.error) || "未知错误"));
|
|
1794
|
+
}).catch(err => { setBusy(""); say("data", "导出失败:" + String(err && err.message ? err.message : err)); });
|
|
1795
|
+
}
|
|
1796
|
+
function clearData() {
|
|
1797
|
+
setBusy("data"); say("data", "清空中…");
|
|
1798
|
+
apiCall("reset", {}).then(v => {
|
|
1799
|
+
setBusy(""); setConfirmClear(false);
|
|
1800
|
+
say("data", v && v.ok ? ("已清空 " + v.cleared + " 条记录") : "清空失败:" + ((v && v.error) || "未知错误"));
|
|
1801
|
+
load();
|
|
1802
|
+
}).catch(err => { setBusy(""); say("data", "清空失败:" + String(err && err.message ? err.message : err)); });
|
|
1803
|
+
}
|
|
1804
|
+
function saveVolcEngine(clear) {
|
|
1805
|
+
setBusy("sub"); say("sub", "");
|
|
1806
|
+
const args = clear ? { clear: true } : { volcengineAccessKeyId: volcId };
|
|
1807
|
+
if (!clear && volcSecret) args.volcengineSecretAccessKey = volcSecret;
|
|
1808
|
+
apiCall("volcengine-config", args).then(v => {
|
|
1809
|
+
setBusy("");
|
|
1810
|
+
setVolcSecret("");
|
|
1811
|
+
if (v && v.ok) {
|
|
1812
|
+
setVolcHasSecret(!!v.volcengineHasKeys);
|
|
1813
|
+
setVolcBackend(v.volcengineSecretBackend || "");
|
|
1814
|
+
say("sub", clear ? "已清除凭据" : "已保存(SecretAccessKey 存入凭据库)");
|
|
1815
|
+
} else say("sub", "保存失败:" + ((v && v.error) || "未知错误"));
|
|
1816
|
+
}).catch(err => { setBusy(""); say("sub", "保存失败:" + String(err && err.message ? err.message : err)); });
|
|
1817
|
+
}
|
|
1818
|
+
function queryVolc() {
|
|
1819
|
+
setBusy("sub"); say("sub", "查询配额…");
|
|
1820
|
+
apiCall("volcengine-usage", { force: true }).then(v => {
|
|
1821
|
+
setBusy(""); setVolcData(v);
|
|
1822
|
+
say("sub", v && v.ok ? "配额已刷新" : ("查询失败:" + ((v && v.error) || "未知错误")));
|
|
1823
|
+
}).catch(err => { setBusy(""); say("sub", "查询失败:" + String(err && err.message ? err.message : err)); });
|
|
1633
1824
|
}
|
|
1634
1825
|
/**
|
|
1635
1826
|
* 界面显示开关:勾选即刻提交并落盘(无需点「保存」),随后广播 UI_EVENT,
|
|
@@ -1657,17 +1848,26 @@ window.__ModuleLoader__.load({
|
|
|
1657
1848
|
setUiMsg("保存失败:" + String(err && err.message ? err.message : err));
|
|
1658
1849
|
});
|
|
1659
1850
|
}
|
|
1660
|
-
//
|
|
1661
|
-
const
|
|
1662
|
-
e("span", { className: "cost-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1851
|
+
// ---------- 顶部状态条:一眼看清关键状态 ----------
|
|
1852
|
+
const chips = [
|
|
1853
|
+
e("span", { key: "c1", className: "cost-cfg-chip" + (st && st.enabled ? " is-on" : "") },
|
|
1854
|
+
"云端同步", e("b", null, st && st.enabled ? "已开启" : "未开启")),
|
|
1855
|
+
];
|
|
1856
|
+
if (st) {
|
|
1857
|
+
chips.push(e("span", { key: "c2", className: "cost-cfg-chip" }, "已记账 ", e("b", null, fmtInt(st.maxSeq || 0)), " 条"));
|
|
1858
|
+
chips.push(e("span", { key: "c3", className: "cost-cfg-chip" }, "待上报 ", e("b", null, fmtInt(st.pending || 0)), " 条"));
|
|
1859
|
+
chips.push(e("span", { key: "c4", className: "cost-cfg-chip" }, "上次同步 ", e("b", null, timeLabel(st.lastSyncAt))));
|
|
1860
|
+
}
|
|
1861
|
+
if (prices) chips.push(e("span", { key: "c5", className: "cost-cfg-chip" + (prices.eraSynced ? " is-on" : "") }, "计价时代 ", e("b", null, prices.eraLabel || prices.era || "—")));
|
|
1862
|
+
if (imp) chips.push(e("span", { key: "c6", className: "cost-cfg-chip" }, "历史导入 ", e("b", null, fmtInt(imp.totalImported || 0)), " 条"));
|
|
1863
|
+
chips.push(e("span", { key: "c7", className: "cost-cfg-chip" + (bill.showTotalWithPlan ? " is-on" : "") }, "金额口径 ", e("b", null, bill.showTotalWithPlan ? "含 Plan 总额" : "仅按量")));
|
|
1864
|
+
const topStrip = e("div", { className: "cost-cfg-top" }, chips);
|
|
1865
|
+
|
|
1866
|
+
const secProps = (id, title, summary) => ({ id, title, summary, open: openSec === id, onToggle: (k) => setOpenSec(prev => prev === k ? "" : k) });
|
|
1867
|
+
|
|
1868
|
+
// ---------- ① 多机汇总(云端同步) ----------
|
|
1869
|
+
const cloudBody = e("div", null,
|
|
1870
|
+
e("div", { className: "cost-hint" }, "把本机用量汇总到自建云端服务。多台电脑共用同一个地址与令牌,即可在「花费统计」看板切换查看全网数据;首次同步会自动回补历史明细。"),
|
|
1671
1871
|
e("div", { className: "cost-sync-fields" },
|
|
1672
1872
|
field("设备名", e("input", {
|
|
1673
1873
|
className: "cost-input", style: { width: "200px" }, value: draft.deviceName || "", placeholder: "如:办公台式机",
|
|
@@ -1677,55 +1877,425 @@ window.__ModuleLoader__.load({
|
|
|
1677
1877
|
field("服务地址", e("input", {
|
|
1678
1878
|
className: "cost-input", style: { width: "320px" }, value: draft.cloudUrl || "", placeholder: "https://cost.example.com",
|
|
1679
1879
|
onChange: ev => set("cloudUrl", ev.target.value),
|
|
1680
|
-
}), "仅 http/https"),
|
|
1880
|
+
}), "仅 http/https;本机地址可用 http"),
|
|
1681
1881
|
field("共享令牌", e("input", {
|
|
1682
1882
|
className: "cost-input", type: "password", style: { width: "320px" }, value: draft.cloudToken || "",
|
|
1683
|
-
placeholder: st.hasToken ? "已配置(留空则不修改)" : "dshc_...",
|
|
1883
|
+
placeholder: (st && st.hasToken) || (st && st.cloudTokenConfigured) ? "已配置(留空则不修改)" : "dshc_...",
|
|
1684
1884
|
onChange: ev => set("cloudToken", ev.target.value),
|
|
1685
|
-
}), "
|
|
1885
|
+
}), "保存后写入 DSH 凭据库,配置文件不落明文"),
|
|
1686
1886
|
field("同步间隔", e("select", { className: "cost-select", value: String(draft.syncIntervalSec || 60), onChange: ev => set("syncIntervalSec", parseInt(ev.target.value, 10)) },
|
|
1687
1887
|
[15, 30, 60, 120, 300, 600, 1800, 3600].map(s => e("option", { key: "iv" + s, value: String(s) }, s < 60 ? s + " 秒" : (s / 60) + " 分钟")))),
|
|
1888
|
+
field("单批条数", e("select", { className: "cost-select", value: String(draft.syncBatchSize || 500), onChange: ev => set("syncBatchSize", parseInt(ev.target.value, 10)) },
|
|
1889
|
+
[50, 100, 200, 500, 1000, 2000].map(s => e("option", { key: "bs" + s, value: String(s) }, String(s))))),
|
|
1688
1890
|
field("会话脱敏", e("input", { type: "checkbox", checked: !!draft.maskSessionId, onChange: ev => set("maskSessionId", ev.target.checked) }), "上报前把 sessionId 换成不可逆哈希"),
|
|
1689
1891
|
field("上报 purpose", e("input", { type: "checkbox", checked: draft.includePurpose !== false, onChange: ev => set("includePurpose", ev.target.checked) }), "项目/用途归属"),
|
|
1892
|
+
field("上报日汇总", e("input", { type: "checkbox", checked: draft.syncRollups !== false, onChange: ev => set("syncRollups", ev.target.checked) }), "保留窗口外的历史日汇总"),
|
|
1893
|
+
field("补传窗口(天)", e("input", {
|
|
1894
|
+
className: "cost-input", style: { width: "90px" }, type: "number", min: 0, max: 3650,
|
|
1895
|
+
value: String(typeof draft.syncSinceDays === "number" ? draft.syncSinceDays : 180),
|
|
1896
|
+
onChange: ev => { const n = parseInt(ev.target.value, 10); if (Number.isInteger(n) && n >= 0) set("syncSinceDays", n); },
|
|
1897
|
+
}), "0 = 不限(全量补传)"),
|
|
1690
1898
|
field("默认视图", e("select", { className: "cost-select", value: draft.cloudView || "local", onChange: ev => set("cloudView", ev.target.value) },
|
|
1691
1899
|
BOARD_VIEWS.map(v => e("option", { key: v.id, value: v.id }, v.label))))),
|
|
1692
1900
|
e("div", { className: "cost-sync-actions" },
|
|
1693
|
-
e("button", { className: "cost-btn cost-btn-primary", onClick: save, disabled: busy }, "保存"),
|
|
1694
|
-
e("button", { className: "cost-btn", onClick: test, disabled: busy }, "测试连接"),
|
|
1695
|
-
e("button", { className: "cost-btn", onClick: () => syncNow(false), disabled: busy }, "立即同步"),
|
|
1696
|
-
e("button", { className: "cost-btn", onClick: () => syncNow(true), disabled: busy }, "全量补传")),
|
|
1697
|
-
msg ? e("div", { className: "cost-sync-state" }, msg) : null,
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
st.
|
|
1702
|
-
st.
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1901
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: save, disabled: busy === "cloud" }, "保存"),
|
|
1902
|
+
e("button", { className: "cost-btn", onClick: test, disabled: busy === "cloud" }, "测试连接"),
|
|
1903
|
+
e("button", { className: "cost-btn", onClick: () => syncNow(false), disabled: busy === "cloud" }, "立即同步"),
|
|
1904
|
+
e("button", { className: "cost-btn", onClick: () => syncNow(true), disabled: busy === "cloud" }, "全量补传")),
|
|
1905
|
+
msg.cloud ? e("div", { className: "cost-sync-state" }, msg.cloud) : null,
|
|
1906
|
+
st ? e("div", { className: "cost-sync-state" },
|
|
1907
|
+
"设备 ID " + (st.deviceId || "(未生成)") + " · 水位 seq=" + st.watermark + " · 待上报 " + st.pending + " 条 · 上次同步 " + timeLabel(st.lastSyncAt)) : null,
|
|
1908
|
+
st && st.lastError ? e("div", { className: "cost-err" }, "最近错误:" + st.lastError) : null,
|
|
1909
|
+
st && st.needAuth ? e("div", { className: "cost-err" }, "令牌无效:请在云端看板重新生成共享引导令牌后填入上方「共享令牌」。") : null,
|
|
1910
|
+
st && st.url ? e("div", { className: "cost-hint", style: { marginTop: "6px" } }, "云端看板:" + st.url) : null);
|
|
1911
|
+
|
|
1912
|
+
// ---------- ② 峰谷计价与提示 ----------
|
|
1913
|
+
const pd = peakDraft || {};
|
|
1914
|
+
// 预览用快照:把草稿覆盖到服务端快照上,从而「改完即可预览、点保存才落盘」
|
|
1915
|
+
const peakPreviewSnap = peakSnap ? Object.assign({}, peakSnap, { config: pd }) : null;
|
|
1916
|
+
const noticeOn = peakSnap && peakSnap.notice !== false && pd.peakNotice !== false;
|
|
1917
|
+
const peakBody = e("div", null,
|
|
1918
|
+
e("div", { className: "cost-hint" }, "官方只有两档:高峰(工作日 9:00-12:00 / 14:00-18:00)与闲时(高峰 × 0.5,含周末全天)。此处只影响界面提示与档位判定:改价请用「计价与价格目录 → 官方价格同步」。"),
|
|
1919
|
+
e("div", { style: { marginTop: "8px", display: "grid", gap: "6px" } },
|
|
1920
|
+
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1921
|
+
e("input", { type: "checkbox", checked: pd.peakEnabled !== false, onChange: ev => setPeak("peakEnabled", ev.target.checked) }),
|
|
1922
|
+
e("span", null, "启用 DeepSeek 峰谷时段价格")),
|
|
1923
|
+
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1924
|
+
e("input", { type: "checkbox", checked: pd.peakNotice !== false, onChange: ev => setPeak("peakNotice", ev.target.checked) }),
|
|
1925
|
+
e("span", null, "峰时高价时段显著提示(时段条显示)")),
|
|
1926
|
+
e("div", { className: "cost-row", style: { gap: "8px" } },
|
|
1927
|
+
e("span", null, "时段条样式"),
|
|
1928
|
+
e("select", { className: "cost-select", value: pd.peakStyle === "classic" ? "classic" : "compact", onChange: ev => setPeak("peakStyle", ev.target.value) },
|
|
1929
|
+
e("option", { value: "compact" }, "简洁(单行紧凑)"),
|
|
1930
|
+
e("option", { value: "classic" }, "环形表盘(24h)"))),
|
|
1931
|
+
pd.peakStyle === "classic"
|
|
1932
|
+
? e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1933
|
+
e("input", { type: "checkbox", checked: pd.peakShowTickLabels !== false, onChange: ev => setPeak("peakShowTickLabels", ev.target.checked) }),
|
|
1934
|
+
e("span", null, "显示时间(00:00–21:00 刻度)"))
|
|
1935
|
+
: e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1936
|
+
e("input", { type: "checkbox", checked: pd.peakCompactStack === true, onChange: ev => setPeak("peakCompactStack", ev.target.checked) }),
|
|
1937
|
+
e("span", null, "双行紧凑(上下布局)"),
|
|
1938
|
+
pd.peakCompactStack === true ? e("select", { className: "cost-select", value: pd.peakCompactOrder === "text-first" ? "text-first" : "bar-first", onChange: ev => setPeak("peakCompactOrder", ev.target.value) },
|
|
1939
|
+
e("option", { value: "bar-first" }, "时段条在上·文字在下"),
|
|
1940
|
+
e("option", { value: "text-first" }, "文字在上·时段条在下")) : null),
|
|
1941
|
+
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1942
|
+
e("input", { type: "checkbox", checked: pd.peakAlertEnabled !== false, onChange: ev => setPeak("peakAlertEnabled", ev.target.checked) }),
|
|
1943
|
+
e("span", null, "峰/谷切换前弹窗提醒")),
|
|
1944
|
+
pd.peakAlertEnabled !== false
|
|
1945
|
+
? e("div", { className: "cost-row", style: { gap: "8px", flexWrap: "wrap" } },
|
|
1946
|
+
e("span", null, "提前提醒(分钟,1-30)"),
|
|
1713
1947
|
e("input", {
|
|
1714
|
-
type: "
|
|
1715
|
-
|
|
1716
|
-
onChange: ev =>
|
|
1948
|
+
className: "cost-input", style: { width: "80px" }, type: "number", min: 1, max: 30,
|
|
1949
|
+
value: String(pd.peakAlertAhead == null ? 2 : pd.peakAlertAhead),
|
|
1950
|
+
onChange: ev => { const n = parseInt(ev.target.value, 10); if (Number.isInteger(n) && n >= 1 && n <= 30) setPeak("peakAlertAhead", n); },
|
|
1717
1951
|
}),
|
|
1718
|
-
e("span", null,
|
|
1719
|
-
|
|
1720
|
-
e("
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1952
|
+
e("span", null, "提醒类型"),
|
|
1953
|
+
e("select", { className: "cost-select", value: pd.peakAlertTarget === "peak" || pd.peakAlertTarget === "offpeak" ? pd.peakAlertTarget : "both", onChange: ev => setPeak("peakAlertTarget", ev.target.value) },
|
|
1954
|
+
e("option", { value: "both" }, "峰和谷"), e("option", { value: "peak" }, "进入峰时"), e("option", { value: "offpeak" }, "进入谷时")),
|
|
1955
|
+
e("span", null, "弹窗位置"),
|
|
1956
|
+
e("select", { className: "cost-select", value: pd.peakAlertPosition === "center" ? "center" : "corner", onChange: ev => setPeak("peakAlertPosition", ev.target.value) },
|
|
1957
|
+
e("option", { value: "corner" }, "右下角"), e("option", { value: "center" }, "屏幕中心")))
|
|
1958
|
+
: null,
|
|
1959
|
+
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
1960
|
+
e("input", { type: "checkbox", checked: pd.peakAlertWebNotify === true, onChange: ev => setPeak("peakAlertWebNotify", ev.target.checked) }),
|
|
1961
|
+
e("span", null, "同步发送系统通知(需授权通知权限)")),
|
|
1962
|
+
e("div", { className: "cost-row", style: { gap: "8px", marginTop: "4px" } },
|
|
1963
|
+
e("span", null, "预览弹窗"),
|
|
1964
|
+
e("button", { className: "cost-btn", onClick: () => { try { window.dispatchEvent(new CustomEvent(PEAK_PREVIEW_EVENT, { detail: { kind: "peak" } })); } catch (_) {} } }, "预览进入峰"),
|
|
1965
|
+
e("button", { className: "cost-btn", onClick: () => { try { window.dispatchEvent(new CustomEvent(PEAK_PREVIEW_EVENT, { detail: { kind: "offpeak" } })); } catch (_) {} } }, "预览进入谷"),
|
|
1966
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: savePeak, disabled: busy === "peak" }, "保存"),
|
|
1967
|
+
msg.peak ? e("span", { className: "cost-hint" }, msg.peak) : null),
|
|
1968
|
+
e("div", { className: "cost-hint", style: { marginTop: "6px" } },
|
|
1969
|
+
"峰时段(北京时间):" + (peakSnap ? peakSnap.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)") +
|
|
1970
|
+
"。当前:" + (peakPreviewSnap && peakPreviewSnap.phase ? (peakPreviewSnap.phase.weekend ? "周末全谷价" : peakPreviewSnap.phase.inPeak ? "高峰时段" : "平价时段") : "…")),
|
|
1971
|
+
noticeOn ? e("div", { style: { marginTop: "8px" } }, e(PeakStrip, { snap: peakPreviewSnap, style: pd.peakStyle || "compact", wide: true, now, ringSize: 150 }))
|
|
1972
|
+
: e("p", { className: "cost-hint", style: { marginTop: "8px" } }, "提示已隐藏:需启用峰谷计价并开启「峰时高价时段显著提示」。")));
|
|
1973
|
+
|
|
1974
|
+
// ---------- ③ 订阅套餐与配额 ----------
|
|
1975
|
+
const quotaWindows = (volcData && volcData.windowList) || [];
|
|
1976
|
+
const subBody = e("div", null,
|
|
1977
|
+
e("div", { className: "cost-hint" }, "订阅制(Coding Plan / 会员)的调用**不计入按量消费金额**,只按等值费用展示;这里配置查配额所需的凭据与订阅归类。"),
|
|
1978
|
+
e("div", { className: "cost-subblock" },
|
|
1979
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "火山方舟 Coding Plan 配额凭据"),
|
|
1980
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
1981
|
+
"配额查询走方舟**管控面**,需要 IAM 的 AccessKeyID + SecretAccessKey(授予 ArkReadOnlyAccess + BillingCenterReadOnlyAccess);它与推理用的 ARK API Key 是两套凭据。SecretAccessKey 只写入凭据库,任何响应都不回显。"),
|
|
1982
|
+
e("div", { className: "cost-sync-fields" },
|
|
1983
|
+
field("AccessKeyID", e("input", {
|
|
1984
|
+
className: "cost-input", style: { width: "260px" }, value: volcId, placeholder: "AKLT...",
|
|
1985
|
+
onChange: ev => setVolcId(ev.target.value),
|
|
1986
|
+
})),
|
|
1987
|
+
field("SecretAccessKey", e("input", {
|
|
1988
|
+
className: "cost-input", type: "password", style: { width: "260px" }, value: volcSecret,
|
|
1989
|
+
placeholder: volcHasSecret ? "已存入凭据库(留空则不修改)" : "仅本机保存,不回显",
|
|
1990
|
+
onChange: ev => setVolcSecret(ev.target.value),
|
|
1991
|
+
})),
|
|
1992
|
+
field("凭据状态", e("span", null,
|
|
1993
|
+
e("span", { className: "cost-badge" }, volcHasSecret ? "已配置" : "未配置"),
|
|
1994
|
+
volcBackend === "memory" ? e("span", { className: "cost-hint", style: { marginLeft: "6px" } }, "(凭据服务缺席,仅进程内暂存)") : null))),
|
|
1995
|
+
e("div", { className: "cost-sync-actions" },
|
|
1996
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: () => saveVolcEngine(false), disabled: busy === "sub" }, "保存凭据"),
|
|
1997
|
+
e("button", { className: "cost-btn", onClick: queryVolc, disabled: busy === "sub" }, "查询配额"),
|
|
1998
|
+
e("button", { className: "cost-btn", onClick: () => saveVolcEngine(true), disabled: busy === "sub" }, "清除凭据"),
|
|
1999
|
+
msg.sub ? e("span", { className: "cost-hint" }, msg.sub) : null),
|
|
2000
|
+
quotaWindows.length
|
|
2001
|
+
? e("div", { style: { marginTop: "6px" } }, quotaWindows.map((w, i) => e("div", { key: "qw" + i }, pctBar(w.label || w.name, w.percent, w.resetsAt, now, w.used, w.quota))))
|
|
2002
|
+
: null),
|
|
2003
|
+
e("div", { className: "cost-subblock" },
|
|
2004
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "订阅归类覆盖"),
|
|
2005
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
2006
|
+
"内置规则:火山方舟**专属 Coding 端点**整档算订阅;泛 volcengine 走模型白名单;Kimi 整档算订阅。清单追不上模型 id 时,用下面的覆盖表把某个 provider(或某个模型)强制归到订阅/按量。"),
|
|
2007
|
+
planOverrideEditor(bill.planRows, rows => setBillField("planRows", rows)),
|
|
2008
|
+
e("div", { className: "cost-sync-actions", style: { marginTop: "8px" } },
|
|
2009
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: saveBilling, disabled: busy === "bill" }, "保存归类"),
|
|
2010
|
+
msg.bill ? e("span", { className: "cost-hint" }, msg.bill) : null)));
|
|
2011
|
+
|
|
2012
|
+
// ---------- ④ 计价与价格目录 ----------
|
|
2013
|
+
const cat = prices && prices.catalog;
|
|
2014
|
+
const ps = prices && prices.priceSync;
|
|
2015
|
+
const syncEras = (ps && ps.syncedEras) || [];
|
|
2016
|
+
const lastCheck = ps && ps.lastCheck;
|
|
2017
|
+
const billBody = e("div", null,
|
|
2018
|
+
e("div", { className: "cost-kv" },
|
|
2019
|
+
e("span", { className: "k" }, "金额口径"),
|
|
2020
|
+
e("label", { className: "cost-row", style: { gap: "8px" } },
|
|
2021
|
+
e("input", { type: "checkbox", checked: !!bill.showTotalWithPlan, onChange: ev => setBillField("showTotalWithPlan", ev.target.checked) }),
|
|
2022
|
+
e("span", null, "含 Plan 总额(金额 = 按量 + 订阅等值)"),
|
|
2023
|
+
e("span", { className: "cost-hint" }, "关掉只统计按量真金白银;看板右上角也有同款快捷开关")),
|
|
2024
|
+
e("span", { className: "k" }, "目录匹配"),
|
|
2025
|
+
e("div", { className: "cost-row", style: { gap: "8px" } },
|
|
2026
|
+
e("select", { className: "cost-select", value: bill.priceMatch === "exact" ? "exact" : "fuzzy", onChange: ev => setBillField("priceMatch", ev.target.value) },
|
|
2027
|
+
e("option", { value: "fuzzy" }, "宽松(归一化包含匹配,默认)"),
|
|
2028
|
+
e("option", { value: "exact" }, "严格(名称全等才命中)")),
|
|
2029
|
+
e("span", { className: "cost-hint" }, "目录用于识别内置价格表之外的模型(OpenAI / Anthropic / Gemini / Qwen 等)")),
|
|
2030
|
+
e("span", { className: "k" }, "目录汇率"),
|
|
2031
|
+
e("div", { className: "cost-row", style: { gap: "8px" } },
|
|
2032
|
+
e("input", {
|
|
2033
|
+
className: "cost-input", style: { width: "90px" }, type: "number", step: "0.1", min: "0.1", max: "100",
|
|
2034
|
+
value: String(bill.catalogFxRate == null ? 7.2 : bill.catalogFxRate),
|
|
2035
|
+
onChange: ev => setBillField("catalogFxRate", Number(ev.target.value)),
|
|
2036
|
+
}),
|
|
2037
|
+
e("span", { className: "cost-hint" }, "目录单价为 USD/1M tokens,按此汇率折算为人民币入账"))),
|
|
2038
|
+
e("div", { className: "cost-subblock" },
|
|
2039
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "手动覆盖价(CNY / 1M tokens)"),
|
|
2040
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } }, "优先级最高:命中即按此价计费(含缓存写入价 = 缓存命中价)。用于内网自建端点、议价套餐或官方页未列出的模型。"),
|
|
2041
|
+
priceOverrideEditor(bill.priceRows, rows => setBillField("priceRows", rows))),
|
|
2042
|
+
e("div", { className: "cost-subblock" },
|
|
2043
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "官方价格同步"),
|
|
2044
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
2045
|
+
"抓取官方定价页(中文页给出人民币价),解析出各模型峰价后构建**新的计费时代**:只对生效时刻之后的记录生效,历史记录口径不回改。应用前可先「核对官方价」看差异。"),
|
|
2046
|
+
e("div", { className: "cost-sync-fields" },
|
|
2047
|
+
field("定价页地址", e("input", {
|
|
2048
|
+
className: "cost-input", style: { width: "320px" }, value: psDraft.priceSyncUrl || "", placeholder: "https://api-docs.deepseek.com/zh-cn/quick_start/pricing",
|
|
2049
|
+
onChange: ev => setPsDraft(prev => Object.assign({}, prev, { priceSyncUrl: ev.target.value })),
|
|
2050
|
+
})),
|
|
2051
|
+
field("每日自动核对", e("input", {
|
|
2052
|
+
type: "checkbox", checked: psDraft.priceSyncAutoCheck !== false,
|
|
2053
|
+
onChange: ev => setPsDraft(prev => Object.assign({}, prev, { priceSyncAutoCheck: ev.target.checked })),
|
|
2054
|
+
}), "只核对并提示差异,绝不自动应用"))),
|
|
2055
|
+
e("div", { className: "cost-sync-actions" },
|
|
2056
|
+
e("button", { className: "cost-btn", onClick: savePriceSync, disabled: busy === "bill" }, "保存设置"),
|
|
2057
|
+
e("button", { className: "cost-btn", onClick: () => runPriceSync(false), disabled: busy === "price" }, "核对官方价"),
|
|
2058
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: () => runPriceSync(true), disabled: busy === "price" }, "应用新价"),
|
|
2059
|
+
msg.price ? e("span", { className: "cost-hint" }, msg.price) : null),
|
|
2060
|
+
lastCheck ? e("div", { className: "cost-sync-state" },
|
|
2061
|
+
"最近核对 " + timeLabel(lastCheck.at) + " · " + (lastCheck.ok ? (lastCheck.diff ? "差异:" + lastCheck.diff : "与当前生效价一致") : ("失败:" + (lastCheck.error || "未知错误")))) : null,
|
|
2062
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
2063
|
+
"当前时代:" + (prices ? (prices.eraLabel || prices.era) : "…") + " · 已同步时代 " + syncEras.length + " 个"
|
|
2064
|
+
+ (syncEras.length ? ":" + syncEras.map(x => x.id).join("、") : "(内置价格表)"),
|
|
2065
|
+
e("div", { className: "cost-sync-actions", style: { marginTop: "8px" } },
|
|
2066
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: saveBilling, disabled: busy === "bill" }, "保存计价设置"))),
|
|
2067
|
+
e("div", { className: "cost-subblock" },
|
|
2068
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "多厂商模型价格目录"),
|
|
2069
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
2070
|
+
cat ? ("共 " + (cat.providers || []).reduce((a, p) => a + p.count, 0) + " 个模型条目 · " + (cat.providers || []).length + " 家厂商 · 数据 " + (cat.meta && cat.meta.generatedAt ? cat.meta.generatedAt : "—") + " · 指纹 " + cat.fingerprint)
|
|
2071
|
+
: "目录数据不可用(未随包分发或读取失败)"),
|
|
2072
|
+
cat ? e("div", { className: "cost-cfg-top", style: { marginTop: "6px" } },
|
|
2073
|
+
(cat.providers || []).map(p => e("span", { key: "cp" + p.id, className: "cost-cfg-chip" }, p.id, " ", e("b", null, p.count)))) : null,
|
|
2074
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
2075
|
+
"命中目录 = 精确价(不计入「估算」);内置时代价优先于目录,手动覆盖价优先于两者;目录读取失败不影响计费,自动回落 provider 兜底。")));
|
|
2076
|
+
|
|
2077
|
+
// ---------- ⑤ 历史导入 ----------
|
|
2078
|
+
const impBody = e("div", null,
|
|
2079
|
+
e("div", { className: "cost-hint" }, "回放宿主会话日志($DSH_HOME/sessions/…),把**装插件之前**的对话调用补录进账本。幂等:重复执行不会重复计数。"),
|
|
2080
|
+
e("div", { className: "cost-list", style: { marginTop: "6px" } },
|
|
2081
|
+
e("div", null, "· 只导入「插件不可能记到」的调用:早于本机最早一条实时记录,或所在日完全没有实时覆盖(停机缺口)。"),
|
|
2082
|
+
e("div", null, "· 跨安装点的会话按切割线截断:安装前那段补录,安装后那段以实时记录为准。"),
|
|
2083
|
+
e("div", null, "· 已被实时覆盖的日子**宁可不导入**也不重复计数;导入记录标记 source=import,可在明细中区分。")),
|
|
2084
|
+
e("label", { className: "cost-row", style: { gap: "8px", marginTop: "8px" } },
|
|
2085
|
+
e("input", { type: "checkbox", checked: impDraft.autoImport !== false, onChange: ev => setImpDraft({ autoImport: ev.target.checked }) }),
|
|
2086
|
+
e("span", null, "启动时自动导入(延迟 8 秒执行,不阻塞启动)")),
|
|
2087
|
+
e("div", { className: "cost-sync-actions" },
|
|
2088
|
+
e("button", { className: "cost-btn cost-btn-primary", onClick: saveImportCfg, disabled: busy === "imp" }, "保存设置"),
|
|
2089
|
+
e("button", { className: "cost-btn", onClick: runImport, disabled: busy === "imp" }, "立即导入"),
|
|
2090
|
+
msg.imp ? e("span", { className: "cost-hint" }, msg.imp) : null),
|
|
2091
|
+
imp ? e("div", { className: "cost-sync-state" },
|
|
2092
|
+
"累计导入 " + fmtInt(imp.totalImported || 0) + " 条 · 已处理 " + fmtInt(imp.filesImported || 0) + "/" + fmtInt(imp.filesTracked || 0) + " 个日志文件 · 上次运行 " + (imp.lastRunAt ? timeLabel(imp.lastRunAt) : "从未")) : null,
|
|
2093
|
+
imp && imp.lastResult && imp.lastResult.error ? e("div", { className: "cost-err" }, "上次失败:" + imp.lastResult.error) : null,
|
|
2094
|
+
imp ? e("div", { className: "cost-hint", style: { marginTop: "4px" } }, "会话目录:" + imp.sessionsRoot) : null);
|
|
2095
|
+
|
|
2096
|
+
// ---------- ⑥ 数据与界面 ----------
|
|
2097
|
+
const dataBody = e("div", null,
|
|
2098
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "界面显示"),
|
|
2099
|
+
e("div", { className: "cost-hint", style: { marginTop: "6px" } },
|
|
2100
|
+
"控制插件在 DSH 界面上的落点,勾选后立即生效(无需点保存)。关闭只影响显示:记账、云端同步与 Agent 工具照常工作。"),
|
|
2101
|
+
e("div", { style: { marginTop: "8px", display: "grid", gap: "6px" } },
|
|
2102
|
+
UI_SURFACES.map(s => e("label", { key: s.key, className: "cost-row", style: { gap: "8px", alignItems: "flex-start" } },
|
|
2103
|
+
e("input", {
|
|
2104
|
+
type: "checkbox",
|
|
2105
|
+
checked: uiDraft[s.key] !== false,
|
|
2106
|
+
onChange: ev => saveUi({ [s.key]: ev.target.checked }),
|
|
2107
|
+
}),
|
|
2108
|
+
e("span", null,
|
|
2109
|
+
e("span", null, s.label),
|
|
2110
|
+
e("div", { className: "cost-hint" }, s.desc))))),
|
|
2111
|
+
e("div", { className: "cost-row", style: { gap: "8px", marginTop: "6px" } },
|
|
2112
|
+
e("button", { className: "cost-btn", onClick: () => saveUi({ uiDockEnabled: true, uiPeakEnabled: true, uiDashboardEnabled: true }) }, "全部显示"),
|
|
2113
|
+
uiMsg ? e("span", { className: "cost-hint" }, uiMsg) : null),
|
|
2114
|
+
e("div", { className: "cost-subblock" },
|
|
2115
|
+
e("div", { className: "cost-panel-title", style: { fontSize: "12px" } }, "数据管理"),
|
|
2116
|
+
e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
2117
|
+
"明细保留最近 180 天,更早自动压缩为永久日汇总(看板总额仍精确)。重算按「计费时代 + 覆盖价 + 目录」重算已入库记录,建议先试算。"),
|
|
2118
|
+
e("div", { className: "cost-sync-actions" },
|
|
2119
|
+
e("button", { className: "cost-btn", onClick: exportCsv, disabled: busy === "data" }, "导出 CSV"),
|
|
2120
|
+
e("button", { className: "cost-btn", onClick: () => runRecompute(false), disabled: busy === "data" }, "重算费用(试算)"),
|
|
2121
|
+
e("button", { className: "cost-btn", onClick: () => runRecompute(true), disabled: busy === "data" }, "重算并写回"),
|
|
2122
|
+
confirmClear
|
|
2123
|
+
? e("span", { className: "cost-row", style: { gap: "6px" } },
|
|
2124
|
+
e("span", { className: "cost-danger" }, "确认清空全部记录?不可恢复"),
|
|
2125
|
+
e("button", { className: "cost-btn cost-danger", onClick: clearData, disabled: busy === "data" }, "确认清空"),
|
|
2126
|
+
e("button", { className: "cost-btn", onClick: () => setConfirmClear(false) }, "取消"))
|
|
2127
|
+
: e("button", { className: "cost-btn", onClick: () => setConfirmClear(true) }, "清空数据"),
|
|
2128
|
+
msg.data ? e("span", { className: "cost-hint" }, msg.data) : null),
|
|
2129
|
+
recomputeRes ? e("div", { className: "cost-sync-state" },
|
|
2130
|
+
"扫描 " + recomputeRes.scanned + " 条 · 需修正 " + recomputeRes.changed + " 条 · 合计 ¥" + recomputeRes.oldCost + " → ¥" + recomputeRes.newCost + "(" + (recomputeRes.delta >= 0 ? "+" : "") + recomputeRes.delta + ")") : null));
|
|
2131
|
+
|
|
2132
|
+
// ---------- ⑦ 安全与凭据 ----------
|
|
2133
|
+
const secBody = e("div", null,
|
|
2134
|
+
e("div", { className: "cost-hint" }, "密钥零落盘:令牌与 SecretAccessKey 只存 DSH 凭据库(宿主托管的 .credentials.yaml),配置文件里只保留「是否已配置」。出站请求带三重防护:主机白名单、非本机强制 https、3xx 一律拒绝跟随(防止重定向把 Authorization 头带去别处)。"),
|
|
2135
|
+
e("table", { className: "cost-tbl", style: { marginTop: "8px" } },
|
|
2136
|
+
e("thead", null, e("tr", null, e("th", null, "凭据"), e("th", null, "状态"), e("th", null, "存储位置"))),
|
|
2137
|
+
e("tbody", null,
|
|
2138
|
+
e("tr", null,
|
|
2139
|
+
e("td", null, "云端共享令牌"),
|
|
2140
|
+
e("td", null, st && st.cloudTokenConfigured ? "已配置" : "未配置"),
|
|
2141
|
+
e("td", null, st && st.cloudTokenConfigured ? (st.cloudTokenBackend === "memory" ? "进程内存(凭据服务缺席)" : "DSH 凭据库") : "—")),
|
|
2142
|
+
e("tr", null,
|
|
2143
|
+
e("td", null, "火山 SecretAccessKey"),
|
|
2144
|
+
e("td", null, volcHasSecret ? "已配置" : "未配置"),
|
|
2145
|
+
e("td", null, volcHasSecret ? (volcBackend === "memory" ? "进程内存(凭据服务缺席)" : "DSH 凭据库") : "—")),
|
|
2146
|
+
e("tr", null,
|
|
2147
|
+
e("td", null, "旧版明文迁移"),
|
|
2148
|
+
e("td", null, st && st.secretsMigrated ? "已完成" : "无需迁移"),
|
|
2149
|
+
e("td", null, "配置文件不含明文")))),
|
|
2150
|
+
e("div", { className: "cost-sync-actions" },
|
|
2151
|
+
e("button", { className: "cost-btn", onClick: () => saveVolcEngine(true), disabled: busy === "sub" }, "清除火山 SK"),
|
|
2152
|
+
msg.sub ? e("span", { className: "cost-hint" }, msg.sub) : null),
|
|
2153
|
+
e("div", { className: "cost-hint", style: { marginTop: "6px" } },
|
|
2154
|
+
"提示:AccessKeyID 属非敏感标识(控制台可见),会随看板回显以便预填;SecretAccessKey 与令牌在任何响应里都只有布尔标记。"));
|
|
2155
|
+
|
|
2156
|
+
// 卡片外壳对齐宿主 PluginCard:li.cost-pcard > button.cost-pcard-head(标题+副标题+箭头)> body
|
|
2157
|
+
const head = e("button", { type: "button", className: "cost-pcard-head", "aria-expanded": open, onClick: () => setOpen(v => !v) },
|
|
2158
|
+
e("span", { className: "cost-pcard-headtext" },
|
|
2159
|
+
e("span", { className: "cost-pcard-name" }, "花费统计" + (st && st.enabled ? " · 云端同步已开启" : "")),
|
|
2160
|
+
e("span", { className: "cost-pcard-desc" }, "全部设置集中于此:云端同步(多机汇总)、峰谷计价与提示、订阅套餐与配额、计价与价格目录、历史导入、数据与界面、安全与凭据。")),
|
|
2161
|
+
e("svg", { className: "cost-pcard-chevron" + (open ? " is-open" : ""), width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
|
|
2162
|
+
e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" })));
|
|
2163
|
+
const body = e("div", null,
|
|
2164
|
+
topStrip,
|
|
2165
|
+
!st ? e("div", { className: "cost-hint", style: { margin: "4px 0 8px" } }, "加载状态…") : null,
|
|
2166
|
+
cfgSection(Object.assign({ key: "s1" }, secProps("cloud", "多机汇总(云端同步)", st && st.enabled ? ("已开启 · " + (st.deviceName || "未命名设备")) : "未开启")), cloudBody),
|
|
2167
|
+
cfgSection(Object.assign({ key: "s2" }, secProps("peak", "峰谷计价与提示", (pd.peakEnabled !== false ? "已启用" : "已停用") + " · " + (pd.peakStyle === "classic" ? "环形表盘" : "简洁样式"))), peakBody),
|
|
2168
|
+
cfgSection(Object.assign({ key: "s3" }, secProps("sub", "订阅套餐与配额", (volcHasSecret ? "火山凭据已配" : "火山凭据未配") + " · 归类覆盖 " + bill.planRows.length + " 条")), subBody),
|
|
2169
|
+
cfgSection(Object.assign({ key: "s4" }, secProps("bill", "计价与价格目录", (bill.showTotalWithPlan ? "含 Plan 总额" : "仅按量") + " · 覆盖价 " + bill.priceRows.length + " 条 · " + (cat ? (cat.providers || []).length + " 家目录" : "无目录"))), billBody),
|
|
2170
|
+
cfgSection(Object.assign({ key: "s5" }, secProps("imp", "历史导入", (impDraft.autoImport !== false ? "开机自动" : "手动") + " · 已导入 " + fmtInt((imp && imp.totalImported) || 0) + " 条")), impBody),
|
|
2171
|
+
cfgSection(Object.assign({ key: "s6" }, secProps("data", "数据与界面", "保留 180 天明细 · 界面落点 " + UI_SURFACES.filter(s => uiDraft[s.key] !== false).length + "/3")), dataBody),
|
|
2172
|
+
cfgSection(Object.assign({ key: "s7" }, secProps("sec", "安全与凭据", "密钥零落盘 · 出站白名单")), secBody));
|
|
1724
2173
|
return e("li", { className: "cost-pcard" + (open ? " is-open" : "") },
|
|
1725
2174
|
head,
|
|
1726
2175
|
open ? e("div", { className: "cost-pcard-body" }, body) : null);
|
|
1727
2176
|
}
|
|
1728
2177
|
|
|
2178
|
+
/**
|
|
2179
|
+
* 折叠分组外壳(配置卡片 v1.9.0)。
|
|
2180
|
+
* 折叠只切 CSS 显隐、**不卸载内容**:展开任一分组都无需重新取数,
|
|
2181
|
+
* 草稿也不会因为切分组而丢;同时让「按 id 手风琴」保持简单。
|
|
2182
|
+
*/
|
|
2183
|
+
function cfgSection(p, body) {
|
|
2184
|
+
const open = !!p.open;
|
|
2185
|
+
return e("div", { className: "cost-sec" + (open ? " is-open" : "") },
|
|
2186
|
+
e("button", {
|
|
2187
|
+
type: "button", className: "cost-sec-head", "aria-expanded": open,
|
|
2188
|
+
onClick: () => p.onToggle(p.id),
|
|
2189
|
+
},
|
|
2190
|
+
e("span", { className: "cost-sec-title" }, p.title),
|
|
2191
|
+
p.summary ? e("span", { className: "cost-sec-sum" }, p.summary) : null,
|
|
2192
|
+
e("svg", { className: "cost-sec-arrow" + (open ? " is-open" : ""), width: 12, height: 12, viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true" },
|
|
2193
|
+
e("path", { d: "M3.5 5.25 7 8.75l3.5-3.5", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round", strokeLinejoin: "round" }))),
|
|
2194
|
+
e("div", { className: "cost-sec-body", style: open ? null : { display: "none" } }, body));
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
/** 配置里的订阅归类对象 ⇄ 编辑行(键形如 'provider/model',model 可为 '*') */
|
|
2198
|
+
function planOverridesToRows(obj) {
|
|
2199
|
+
return Object.keys(obj || {}).map(k => {
|
|
2200
|
+
const p = String(k).split("/");
|
|
2201
|
+
return { provider: p[0] || "", model: p[1] || "*", kind: obj[k] === "api" ? "api" : "plan" };
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
function planRowsToObj(rows) {
|
|
2205
|
+
const out = {};
|
|
2206
|
+
for (const r of rows || []) {
|
|
2207
|
+
const p = String(r.provider || "").trim();
|
|
2208
|
+
const m = String(r.model || "*").trim() || "*";
|
|
2209
|
+
if (!p) continue;
|
|
2210
|
+
out[p + "/" + m] = r.kind === "api" ? "api" : "plan";
|
|
2211
|
+
}
|
|
2212
|
+
return out;
|
|
2213
|
+
}
|
|
2214
|
+
/** 配置里的覆盖价对象 ⇄ 编辑行(cacheWrite 恒等于 cacheRead,与官方口径一致) */
|
|
2215
|
+
function priceOverridesToRows(obj) {
|
|
2216
|
+
return Object.keys(obj || {}).map(k => {
|
|
2217
|
+
const p = String(k).split("/");
|
|
2218
|
+
const v = obj[k] || {};
|
|
2219
|
+
return { provider: p[0] || "", model: p[1] || "", input: v.input, output: v.output, cacheRead: v.cacheRead };
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
function priceRowsToObj(rows) {
|
|
2223
|
+
const out = {};
|
|
2224
|
+
for (const r of rows || []) {
|
|
2225
|
+
const p = String(r.provider || "").trim();
|
|
2226
|
+
const m = String(r.model || "").trim();
|
|
2227
|
+
if (!p || !m) continue;
|
|
2228
|
+
out[p + "/" + m] = {
|
|
2229
|
+
input: Number(r.input) || 0,
|
|
2230
|
+
output: Number(r.output) || 0,
|
|
2231
|
+
cacheRead: Number(r.cacheRead) || 0,
|
|
2232
|
+
cacheWrite: Number(r.cacheRead) || 0,
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
return out;
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
/** 订阅归类覆盖编辑器 */
|
|
2239
|
+
function planOverrideEditor(rows, setRows) {
|
|
2240
|
+
const list = rows || [];
|
|
2241
|
+
const upd = (i, patch) => setRows(list.map((r, j) => (j === i ? Object.assign({}, r, patch) : r)));
|
|
2242
|
+
return e("div", { style: { marginTop: "6px" } },
|
|
2243
|
+
list.length
|
|
2244
|
+
? e("table", { className: "cost-tbl" },
|
|
2245
|
+
e("thead", null, e("tr", null,
|
|
2246
|
+
e("th", null, "Provider"), e("th", null, "模型(* = 该 provider 全部)"), e("th", null, "归类"), e("th", null, ""))),
|
|
2247
|
+
e("tbody", null, list.map((r, i) => e("tr", { key: "po" + i },
|
|
2248
|
+
e("td", null, e("input", {
|
|
2249
|
+
className: "cost-input", style: { width: "170px" }, value: r.provider || "", placeholder: "byteblus-coding-plan-cn",
|
|
2250
|
+
onChange: ev => upd(i, { provider: ev.target.value }),
|
|
2251
|
+
})),
|
|
2252
|
+
e("td", null, e("input", {
|
|
2253
|
+
className: "cost-input", style: { width: "170px" }, value: r.model || "", placeholder: "*",
|
|
2254
|
+
onChange: ev => upd(i, { model: ev.target.value }),
|
|
2255
|
+
})),
|
|
2256
|
+
e("td", null, e("select", { className: "cost-select", value: r.kind === "api" ? "api" : "plan", onChange: ev => upd(i, { kind: ev.target.value }) },
|
|
2257
|
+
e("option", { value: "plan" }, "订阅(Plan)"), e("option", { value: "api" }, "按量"))),
|
|
2258
|
+
e("td", null, e("button", { className: "cost-btn", onClick: () => setRows(list.filter((_, j) => j !== i)) }, "删除"))))))
|
|
2259
|
+
: e("div", { className: "cost-hint" }, "暂无覆盖:套餐内模型按内置规则自动识别。"),
|
|
2260
|
+
e("button", {
|
|
2261
|
+
className: "cost-btn", style: { marginTop: "6px" },
|
|
2262
|
+
onClick: () => setRows(list.concat([{ provider: "", model: "*", kind: "plan" }])),
|
|
2263
|
+
}, "+ 添加归类"));
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
/** 手动覆盖价编辑器(CNY / 1M tokens;缓存写入价 = 缓存命中价) */
|
|
2267
|
+
function priceOverrideEditor(rows, setRows) {
|
|
2268
|
+
const list = rows || [];
|
|
2269
|
+
const upd = (i, patch) => setRows(list.map((r, j) => (j === i ? Object.assign({}, r, patch) : r)));
|
|
2270
|
+
const numCell = (r, i, key, width) => e("td", { className: "cost-num" }, e("input", {
|
|
2271
|
+
className: "cost-input", style: { width: width || "80px" }, type: "number", step: "0.01", min: "0",
|
|
2272
|
+
value: r[key] == null ? "" : String(r[key]),
|
|
2273
|
+
onChange: ev => upd(i, { [key]: Number(ev.target.value) }),
|
|
2274
|
+
}));
|
|
2275
|
+
return e("div", { style: { marginTop: "6px" } },
|
|
2276
|
+
list.length
|
|
2277
|
+
? e("table", { className: "cost-tbl" },
|
|
2278
|
+
e("thead", null, e("tr", null,
|
|
2279
|
+
e("th", null, "Provider"), e("th", null, "模型"), e("th", { className: "cost-num" }, "输入(未命中)"),
|
|
2280
|
+
e("th", { className: "cost-num" }, "输出"), e("th", { className: "cost-num" }, "缓存命中/写入"), e("th", null, ""))),
|
|
2281
|
+
e("tbody", null, list.map((r, i) => e("tr", { key: "pr" + i },
|
|
2282
|
+
e("td", null, e("input", {
|
|
2283
|
+
className: "cost-input", style: { width: "120px" }, value: r.provider || "", placeholder: "deepseek-official",
|
|
2284
|
+
onChange: ev => upd(i, { provider: ev.target.value }),
|
|
2285
|
+
})),
|
|
2286
|
+
e("td", null, e("input", {
|
|
2287
|
+
className: "cost-input", style: { width: "140px" }, value: r.model || "", placeholder: "deepseek-flash",
|
|
2288
|
+
onChange: ev => upd(i, { model: ev.target.value }),
|
|
2289
|
+
})),
|
|
2290
|
+
numCell(r, i, "input"), numCell(r, i, "output"), numCell(r, i, "cacheRead", "90px"),
|
|
2291
|
+
e("td", null, e("button", { className: "cost-btn", onClick: () => setRows(list.filter((_, j) => j !== i)) }, "删除"))))))
|
|
2292
|
+
: e("div", { className: "cost-hint" }, "暂无覆盖价:直接用内置价格表 / 目录价。"),
|
|
2293
|
+
e("button", {
|
|
2294
|
+
className: "cost-btn", style: { marginTop: "6px" },
|
|
2295
|
+
onClick: () => setRows(list.concat([{ provider: "", model: "", input: "", output: "", cacheRead: "" }])),
|
|
2296
|
+
}, "+ 添加覆盖价"));
|
|
2297
|
+
}
|
|
2298
|
+
|
|
1729
2299
|
/**
|
|
1730
2300
|
* 「花费统计」看板的插槽门卫。
|
|
1731
2301
|
* 关掉界面显示时**不能注册成空渲染**(会留下一个点不开的空白导航项),
|
|
@@ -1779,6 +2349,17 @@ window.__ModuleLoader__.load({
|
|
|
1779
2349
|
const [now, setNow] = useState(Date.now());
|
|
1780
2350
|
const [manualKey, setManualKey] = useState("");
|
|
1781
2351
|
const [usage, setUsage] = useState(null);
|
|
2352
|
+
// 双轨计费口径:「含 Plan 总额」开关(localStorage 优先,服务端配置兜底/回写)
|
|
2353
|
+
const [planTotal, setPlanTotalState] = useState(() => planTotalInit(null));
|
|
2354
|
+
// 用户是否已手动改过:改过之后**不再**被服务端/轮询回包覆盖
|
|
2355
|
+
// (用 state 而不是 useRef:渲染期读到的必须是最新值,测试替身也不支持持久 ref)
|
|
2356
|
+
const [planLocked, setPlanLocked] = useState(false);
|
|
2357
|
+
function setPlanTotal(on) {
|
|
2358
|
+
setPlanTotalState(on);
|
|
2359
|
+
setPlanLocked(true);
|
|
2360
|
+
planTotalStore(on);
|
|
2361
|
+
apiCall("billing-config", { showTotalWithPlan: on }).catch(() => {});
|
|
2362
|
+
}
|
|
1782
2363
|
const [usageErr, setUsageErr] = useState("");
|
|
1783
2364
|
// ---- 云端三态视图 ----
|
|
1784
2365
|
const [sync, setSync] = useState(null);
|
|
@@ -1822,6 +2403,14 @@ window.__ModuleLoader__.load({
|
|
|
1822
2403
|
setVolcId(prev => prev || v.volcengineAccessKeyId);
|
|
1823
2404
|
}
|
|
1824
2405
|
setVolcHasSecret(!!v.volcengineHasSecret);
|
|
2406
|
+
// 「含 Plan 总额」:本机偏好优先,其次服务端配置;用户手动改过后不再覆盖
|
|
2407
|
+
if (!planLocked) {
|
|
2408
|
+
let stored = null;
|
|
2409
|
+
try { stored = window.localStorage.getItem(PLAN_TOTAL_KEY); } catch (_) { stored = null; }
|
|
2410
|
+
if (stored === "1") setPlanTotalState(true);
|
|
2411
|
+
else if (stored === "0") setPlanTotalState(false);
|
|
2412
|
+
else setPlanTotalState(v.showTotalWithPlan === true);
|
|
2413
|
+
}
|
|
1825
2414
|
// 首次进入:以配置里的视图为准(三态开关的权威值在配置,便于多机一致)
|
|
1826
2415
|
if (!viewInitRef.current && (v.view === "local" || v.view === "local+cloud" || v.view === "cloud")) {
|
|
1827
2416
|
viewInitRef.current = true;
|
|
@@ -1987,7 +2576,7 @@ window.__ModuleLoader__.load({
|
|
|
1987
2576
|
|
|
1988
2577
|
return e("div", { className: "cost-wrap" },
|
|
1989
2578
|
e("div", { className: "cost-h1" }, pluginIcon(18), "花费统计"),
|
|
1990
|
-
filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)", viewCtl, openVolc),
|
|
2579
|
+
filterRow(days, setDays, onExport, onRefresh, msg, busy, dash ? dash.peakWindows : "周一至周五 9:00-12:00 · 14:00-18:00(周末全天闲时)", viewCtl, openVolc, planTotal, setPlanTotal),
|
|
1991
2580
|
!cloudAvailable
|
|
1992
2581
|
? e("div", { className: "cost-hint", style: { marginTop: "4px" } },
|
|
1993
2582
|
"仅显示本机数据。在多台电脑/多个 Agent 之间汇总:到「设置 → 插件 → 插件配置 → 花费统计」填写云端服务地址与令牌。")
|
|
@@ -2005,9 +2594,9 @@ window.__ModuleLoader__.load({
|
|
|
2005
2594
|
: null,
|
|
2006
2595
|
dashErr ? e("div", { className: "cost-err", style: { marginTop: "8px" } }, dashErr) : null,
|
|
2007
2596
|
(!viewDash && !dashErr) ? e("div", { className: "cost-hint", style: { marginTop: "12px" } }, "加载中…") : null,
|
|
2008
|
-
viewDash ? statCards(viewDash, balance, viewCtl) : null,
|
|
2597
|
+
viewDash ? statCards(viewDash, balance, viewCtl, planTotal) : null,
|
|
2009
2598
|
view !== "local" && dimension !== "total" && viewDash ? dimensionPanel(viewDash, dimension, cloudMatrix, loadingCloud => loadingCloud) : null,
|
|
2010
|
-
viewDash ? mainPanel(viewDash, tab, setTab, scheme, setScheme) : null,
|
|
2599
|
+
viewDash ? mainPanel(viewDash, tab, setTab, scheme, setScheme, planTotal) : null,
|
|
2011
2600
|
e("div", { className: "cost-panel" },
|
|
2012
2601
|
e("div", { className: "cost-row" },
|
|
2013
2602
|
e("span", { className: "cost-panel-title" }, "Token 用量统计"),
|