Compare commits

..

4 Commits

Author SHA1 Message Date
左辰勇 e4b41b714c feat(huawei-review): 华为审核开关配置页
「数据配置」组下新增「华为审核开关」页,两态单选(不能关闭 / 可关闭)+ 保存,
展示当前生效值与最后修改时间。页面文案写清生效范围,避免过审后忘记切回:
仅华为 ROM 生效(荣耀 MagicOS 不受影响)、只影响快速设置步、客户端重进 App 才变。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 20:53:24 +08:00
guke 327b043b89 feat(comparison-records): 比价记录展示 LLM 实际成本(列表列 + 详情 + 价格快照) (#48)
调整LLM价格快照展示样式

---------

Co-authored-by: guke <guke@autohome.com.cn>
Reviewed-on: #48
2026-07-14 14:38:38 +08:00
guke c1854da671 feat(comparison-records): 比价记录展示 LLM 实际成本(列表列 + 详情 + 价格快照) (#47)
- 列表「成本」列优先显示后端冻结的实际成本(当时价/绿色),无则回退前端估算(灰色)
- 详情抽屉「LLM 成本」:有 llm_cost_yuan 显示实际值 +「实际·当时价」标,无则回退估算;
  另展示所用单价快照 JSON
- types.ts:ComparisonRecordListItem 加 llm_cost_yuan(详情继承)
- 顺带:InputNumber addonAfter → suffix(消 antd 弃用警告);详情 llm_calls 遍历对
  input_messages 加空值防御(残缺数据不再整页白屏)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: guke <guke@autohome.com.cn>
Reviewed-on: #47
2026-07-13 17:35:17 +08:00
guke 7269e27e24 feat(coupon-data): 点位成功率改为按券成功率的算术平均(前端从按券明细上卷) (#46)
点位成功率改为按券成功率的算术平均(前端从按券明细上卷)

---------

Co-authored-by: guke <guke@autohome.com.cn>
Reviewed-on: #46
2026-07-11 18:48:54 +08:00
5 changed files with 152 additions and 11 deletions
+41 -8
View File
@@ -38,6 +38,15 @@ const fmtCost = (c: number | null) => (c == null ? '-' : `¥${c.toFixed(4)}`);
const fmtTok = (inTok: number | null, outTok: number | null) =>
inTok == null && outTok == null ? '-' : `${inTok ?? 0}/${outTok ?? 0}`;
// LLM 价格快照只展示 prices 里各模型的单价(元/每百万 token),忽略 mode/_source 等元字段。
function llmPriceRows(snapshot: Record<string, unknown> | null): string[] {
const prices = snapshot?.prices;
if (!prices || typeof prices !== 'object') return [];
return Object.entries(prices as Record<string, { input_per_1m?: number; output_per_1m?: number }>).map(
([model, p]) => `${model} 输入 ${p?.input_per_1m ?? '-'}元/每百万tokens,输出${p?.output_per_1m ?? '-'}元/每百万tokens`,
);
}
// LLM message content 常是 json.dumps 的卡片列表;能 parse 成 JSON 就缩进展开,否则原样。
function pretty(s: string | null): string {
if (!s) return '';
@@ -215,7 +224,16 @@ export default function ComparisonRecordsPage() {
title: '成本',
key: 'cost',
width: 90,
render: (_, r) => fmtCost(calcCost(r.input_tokens, r.output_tokens, pricePerMTok)),
// 有后端冻结的实际成本(当时价)就用它;否则回退老的前端估算(需顶部填 LLM 单价)。
render: (_, r) => {
if (r.llm_cost_yuan != null) {
return <span title="实际成本(按调用时单价冻结)" style={{ color: '#389e0d' }}>{fmtCost(r.llm_cost_yuan)}</span>;
}
const est = calcCost(r.input_tokens, r.output_tokens, pricePerMTok);
return est == null
? '-'
: <span title="估算(顶部 LLM 单价 × token" style={{ color: '#999' }}>{fmtCost(est)}</span>;
},
},
{
title: '机型/ROM',
@@ -292,7 +310,7 @@ export default function ComparisonRecordsPage() {
min={0}
step={0.1}
style={{ width: 210 }}
addonAfter="元/百万token"
suffix="元/百万token"
/>
</Space>
@@ -331,12 +349,27 @@ export default function ComparisonRecordsPage() {
? '-'
: `${detail.input_tokens ?? 0} / ${detail.output_tokens ?? 0} / ${(detail.input_tokens ?? 0) + (detail.output_tokens ?? 0)}`}
</Descriptions.Item>
<Descriptions.Item label="估算成本">
{fmtCost(calcCost(detail.input_tokens, detail.output_tokens, pricePerMTok))}
{pricePerMTok == null && (detail.input_tokens != null || detail.output_tokens != null)
? <span style={{ color: '#999', fontSize: 12 }}> LLM </span>
: null}
<Descriptions.Item label="LLM 成本">
{detail.llm_cost_yuan != null ? (
<>
{fmtCost(detail.llm_cost_yuan)}
<Tag color="green" style={{ marginLeft: 6 }}>·</Tag>
</>
) : (
<>
{fmtCost(calcCost(detail.input_tokens, detail.output_tokens, pricePerMTok))}
<span style={{ color: '#999', fontSize: 12, marginLeft: 6 }}></span>
{pricePerMTok == null && (detail.input_tokens != null || detail.output_tokens != null)
? <span style={{ color: '#999', fontSize: 12 }}> LLM </span>
: null}
</>
)}
</Descriptions.Item>
{detail.llm_price_snapshot ? (
<Descriptions.Item label="LLM价格快照" span={2}>
{llmPriceRows(detail.llm_price_snapshot).map((r) => <div key={r}>{r}</div>)}
</Descriptions.Item>
) : null}
<Descriptions.Item label="源平台">{detail.source_platform_name || '-'}{cents(detail.source_price_cents)}</Descriptions.Item>
<Descriptions.Item label="最优">{detail.best_platform_name || '-'}{cents(detail.best_price_cents)}</Descriptions.Item>
<Descriptions.Item label="省" span={2}>{cents(detail.saved_amount_cents)}{detail.is_source_best ? '(源平台最便宜)' : ''}</Descriptions.Item>
@@ -432,7 +465,7 @@ export default function ComparisonRecordsPage() {
),
children: (
<div>
{c.input_messages.map((m, j) => (
{(c.input_messages ?? []).map((m, j) => (
<div key={j} style={{ marginBottom: 8 }}>
<Tag>{m.role}</Tag>
<pre style={preStyle}>{pretty(m.content)}</pre>
+3 -3
View File
@@ -11,7 +11,7 @@ interface ConfigItem {
key: string;
label: string;
group: string;
type: string; // int / int_list / dict_str_int / bool
type: string; // int / int_list / dict_str_int / bool / json
help: string | null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
default: any;
@@ -24,7 +24,7 @@ interface ConfigItem {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function toEdit(item: ConfigItem): any {
if (item.type === 'int_list') return (item.value as number[]).join(', ');
if (item.type === 'dict_str_int') return JSON.stringify(item.value);
if (item.type === 'dict_str_int' || item.type === 'json') return JSON.stringify(item.value);
return item.value;
}
@@ -37,7 +37,7 @@ function fromEdit(type: string, raw: any): any {
.split(',')
.map((s) => parseInt(s.trim(), 10));
}
if (type === 'dict_str_int') return JSON.parse(raw);
if (type === 'dict_str_int' || type === 'json') return JSON.parse(raw);
return raw;
}
+103
View File
@@ -0,0 +1,103 @@
'use client';
import { useCallback, useEffect, useState } from 'react';
import { Alert, App, Button, Card, Descriptions, Radio, Skeleton, Tag } from 'antd';
import { api, errMsg } from '@/lib/api';
import { formatUtcTime } from '@/lib/format';
// 华为审核开关:控制新手引导「快速设置」权限步能否被用户退出。
// 华为应用市场审核要求该页必须可关闭(引导视频页不在要求内),平时保持「不能关闭」以保住权限开启率,
// 送审期间切「可关闭」。落在 app_config 的 huawei_review 行,客户端经 /api/v1/platform/huawei-review 拉。
type Mode = 'default' | 'review';
interface HuaweiReview {
mode: Mode;
updated_at: string | null;
}
const MODE_LABEL: Record<Mode, string> = {
default: '不能关闭',
review: '可关闭',
};
export default function HuaweiReviewPage() {
const { message } = App.useApp();
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
// saved = 服务端当前值(用于「有没有改动」判断);mode = 编辑中的值
const [saved, setSaved] = useState<HuaweiReview | null>(null);
const [mode, setMode] = useState<Mode>('default');
const load = useCallback(async () => {
try {
const r = await api.get<HuaweiReview>('/admin/api/huawei-review');
setSaved(r.data);
setMode(r.data.mode);
} catch (e) {
message.error(errMsg(e, '华为审核开关加载失败'));
} finally {
setLoading(false);
}
}, [message]);
useEffect(() => {
load();
}, [load]);
const save = async () => {
setSaving(true);
try {
const r = await api.patch<HuaweiReview>('/admin/api/huawei-review', { mode });
setSaved(r.data);
setMode(r.data.mode);
message.success('已保存。客户端下次进新手引导时拉取生效');
} catch (e) {
message.error(errMsg(e, '保存失败'));
} finally {
setSaving(false);
}
};
const dirty = saved !== null && saved.mode !== mode;
return (
<Card
title="华为审核开关"
extra={
<Button type="primary" loading={saving} disabled={loading || !dirty} onClick={save}>
</Button>
}
>
<Alert
type="info"
style={{ marginBottom: 16 }}
message="华为应用市场审核要求「快速设置」页必须可以关闭。切到「可关闭」后,该页左上角出现退出按钮(返回键同样可退出),用户点了直接进 App 首页、本次引导视为已完成。"
description="① 只对华为机型(HarmonyOS / EMUI)生效,荣耀 MagicOS 及其它机型不受影响;② 只影响快速设置权限步,引导视频页照旧必须看完;③ 客户端在进引导前拉一次并缓存,已经停在引导页的用户要重进 App 才会变;④ 审核通过后记得切回「不能关闭」,不然会一直损失权限开启率。"
/>
{loading ? (
<Skeleton active paragraph={{ rows: 3 }} />
) : (
<>
<Descriptions column={1} style={{ marginBottom: 16 }}>
<Descriptions.Item label="当前生效">
{saved ? (
<Tag color={saved.mode === 'review' ? 'orange' : 'green'}>{MODE_LABEL[saved.mode]}</Tag>
) : (
'-'
)}
</Descriptions.Item>
<Descriptions.Item label="最后修改">
{saved?.updated_at ? formatUtcTime(saved.updated_at) : '从未修改过(默认不能关闭)'}
</Descriptions.Item>
</Descriptions>
<div style={{ marginBottom: 8 }}></div>
<Radio.Group value={mode} onChange={(e) => setMode(e.target.value as Mode)}>
<Radio.Button value="default"></Radio.Button>
<Radio.Button value="review"></Radio.Button>
</Radio.Group>
</>
)}
</Card>
);
}
+2
View File
@@ -16,6 +16,7 @@ import {
MoneyCollectOutlined,
NotificationOutlined,
ProfileOutlined,
SafetyCertificateOutlined,
SettingOutlined,
ShareAltOutlined,
TeamOutlined,
@@ -78,6 +79,7 @@ const NAV_GROUPS: NavGroup[] = [
children: [
{ key: '/config', icon: <SettingOutlined />, label: '系统配置' },
{ key: '/ad-revenue', icon: <NotificationOutlined />, label: '广告配置' },
{ key: '/huawei-review', icon: <SafetyCertificateOutlined />, label: '华为审核开关' },
{ key: '/users', icon: <UserOutlined />, label: '用户管理' },
],
},
+3
View File
@@ -354,6 +354,7 @@ export interface ComparisonRecordListItem {
retry_count: number | null;
input_tokens: number | null;
output_tokens: number | null;
llm_cost_yuan: number | null; // 后端按「当时价」冻结的实际成本(元);旧记录 null → 「成本」列回退估算
device_model: string | null;
rom_vendor: string | null;
rom_name: string | null;
@@ -396,6 +397,8 @@ export interface ComparisonRecordDetail extends ComparisonRecordListItem {
latitude: number | null;
llm_calls: LlmCall[] | null;
raw_payload: Record<string, unknown> | null;
// 算成本所用单价快照 {mode, prices:{model:{...}}}(llm_cost_yuan 继承自列表项)。
llm_price_snapshot: Record<string, unknown> | null;
}
export interface AdRevenueImpression {