@angelyeye/dsh-cost-tracker 1.8.15 → 1.9.2

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