6d06971bb4
统一各中心表格的分页样式与切换行为,保留密钥筛选条件和兑换码搜索分页。 验证:871 项单测、ESLint、Prettier 和本地浏览器验收通过。
1287 lines
46 KiB
React
1287 lines
46 KiB
React
import { I18N_TECHNICAL_TEXT } from '../../../i18n/technicalText.js';
|
||
import React, {
|
||
useCallback,
|
||
useContext,
|
||
useEffect,
|
||
useMemo,
|
||
useRef,
|
||
useState,
|
||
} from 'react';
|
||
import {
|
||
Banner,
|
||
Button,
|
||
Input,
|
||
InputNumber,
|
||
Modal,
|
||
Radio,
|
||
RadioGroup,
|
||
Space,
|
||
Table,
|
||
Tag,
|
||
TextArea,
|
||
Tooltip,
|
||
Typography,
|
||
} from '@/components/ui';
|
||
import { IconSearch, IconRefresh } from '@/components/ui/icons';
|
||
import { useTranslation } from 'react-i18next';
|
||
import {
|
||
API,
|
||
copy,
|
||
showError,
|
||
showSuccess,
|
||
showWarning,
|
||
computeDiscountRatio,
|
||
formatDiscountLabel,
|
||
officialFillState,
|
||
isOfficialEntryInert,
|
||
tierPricingOf,
|
||
tierPriceOf,
|
||
buildTierComparison,
|
||
normalizeTierKey,
|
||
isOfficialTierField,
|
||
canonicalOfficialPriceJSON,
|
||
sanitizeOfficialPriceMap,
|
||
OFFICIAL_FILL_EMPTY,
|
||
OFFICIAL_FILL_PARTIAL,
|
||
OFFICIAL_FILL_FILLED,
|
||
OFFICIAL_FILL_NA,
|
||
} from '../../../helpers';
|
||
import { StatusContext } from '../../../context/Status';
|
||
import i18next from 'i18next';
|
||
|
||
// ============================================================================
|
||
// 模型原厂价格(官方牌价)编辑器
|
||
// ----------------------------------------------------------------------------
|
||
// 模型列表自动来自模型广场(/api/pricing?admin_view=1,管理员视角不受等级可见性
|
||
// 过滤),管理员仅需填价格。单位一律 ¥(平台按人民币兑美元 1:1 口径,数值与站内
|
||
// 基准价同量纲直接可比):
|
||
// 按量计费 → 官方输入/输出价(¥ / 1M tokens)
|
||
// 按次计费 → 官方单次价(¥ / 次)
|
||
// 按秒分档(视频)→ 逐档官方秒价(¥ / 秒)
|
||
// 按分辨率分档(图片)→ 逐档官方张价(¥ / 张)
|
||
// 按缓存计价的模型 → 再加官方缓存读取价 / 缓存创建价(¥ / 1M tokens)
|
||
// 保存写入 option `ModelOfficialPrice`,不参与计费。输入/输出/单次价用于市场页折扣
|
||
// 展示;缓存两项不上市场页,只作为【模型成本价格】的原厂参照——收入侧对缓存读取与
|
||
// 缓存创建单独计价,成本侧要做到「扣费的每一项都有成本价」就必须有对应牌价。
|
||
//
|
||
// 交互约定(踩过的坑,改动前务必读):
|
||
// 1. 「已填写/未填写」筛选走**快照**分类,不随每次按键重算。否则在「未填写」下
|
||
// 刚敲下第一个字符,该行就因为「已变成已填写」被过滤掉——按量计费模型的输出价
|
||
// 因此永远填不了,用户看到的现象就是「随便输一个值就跳到已填写」。
|
||
// 2. 非法输入(0/负数/非数字)保留在输入框里并标红,绝不静默丢弃:受控组件下把
|
||
// 值抹掉等于用户白输,且保存后凭空消失。
|
||
// 3. 「是否有未保存修改」用 canonicalOfficialPriceJSON 比较,键序不敏感。
|
||
// ============================================================================
|
||
|
||
const PRICE_STEP = 0.01;
|
||
|
||
// 站内基准价(分组倍率=1、未含等级折扣):与市场页 calculateModelPrice 同公式
|
||
const basePrices = (record) => {
|
||
if (record.quota_type === 0) {
|
||
const input = record.model_ratio * 2;
|
||
const output = record.model_ratio * (record.completion_ratio ?? 1) * 2;
|
||
return { input, output };
|
||
}
|
||
if (record.quota_type === 1) {
|
||
return { perCall: parseFloat(record.model_price) };
|
||
}
|
||
return {};
|
||
};
|
||
|
||
// 分档字段的输入框按「模型::字段::档位」建键:同一模型同一字段有多个档位输入框,
|
||
// 不带档位会让所有档位共用一个草稿/错误状态(一个档位填错,整列一起标红)
|
||
const fieldKey = (modelName, field, tier) =>
|
||
isOfficialTierField(field)
|
||
? `${modelName}::${field}::${tier || ''}`
|
||
: `${modelName}::${field}`;
|
||
|
||
const isFilledValue = (v) =>
|
||
typeof v === 'number' && Number.isFinite(v) && v > 0;
|
||
|
||
// 分档单位后缀的专用文案键。不能复用 t('秒')/t('张')——后者在 en.json 里是
|
||
// "Second" / " images"(复数且带前导空格),拼进「/单位」后缀会读不通。
|
||
const tierUnitSuffix = (unit, t) => (unit === '秒' ? t('/秒') : t('/张'));
|
||
|
||
export default function ModelOfficialPriceSettings(props) {
|
||
const { t } = useTranslation();
|
||
const [statusState] = useContext(StatusContext);
|
||
|
||
// 站点美元汇率:市场页人民币视图会把这里填的官方价一并 ×汇率展示(displayPrice),
|
||
// 汇率 ≠ 1 时「1:1 口径」的填写说明会导致展示原价被整体放大,必须显式告警。
|
||
const usdExchangeRate = useMemo(() => {
|
||
const r = Number(statusState?.status?.usd_exchange_rate);
|
||
return Number.isFinite(r) && r > 0 ? r : 1;
|
||
}, [statusState]);
|
||
|
||
const [models, setModels] = useState([]);
|
||
const [vendorMap, setVendorMap] = useState({});
|
||
const [modelsLoading, setModelsLoading] = useState(false);
|
||
const [modelsLoaded, setModelsLoaded] = useState(false);
|
||
|
||
// model_name -> {input?, output?, per_call?, cache_*?, per_second?{档位:价}, per_image?{档位:价}}
|
||
const [prices, setPrices] = useState({});
|
||
const [drafts, setDrafts] = useState({}); // 非法输入原样回显:key -> 用户输入
|
||
const [errors, setErrors] = useState({}); // 校验错误:key -> 文案
|
||
const [savedCanon, setSavedCanon] = useState('{}');
|
||
const [conflict, setConflict] = useState(false);
|
||
const [saving, setSaving] = useState(false);
|
||
|
||
const [search, setSearch] = useState('');
|
||
const [fillFilter, setFillFilter] = useState('all'); // all | filled | partial | unfilled
|
||
const [snapshotTick, setSnapshotTick] = useState(0);
|
||
const [currentPage, setCurrentPage] = useState(1);
|
||
const [pageSize, setPageSize] = useState(10);
|
||
|
||
const [transferVisible, setTransferVisible] = useState(false);
|
||
const [importText, setImportText] = useState('');
|
||
const [importMode, setImportMode] = useState('merge'); // merge | replace
|
||
|
||
const currentCanon = useMemo(
|
||
() => canonicalOfficialPriceJSON(prices),
|
||
[prices],
|
||
);
|
||
const dirty = currentCanon !== savedCanon;
|
||
const errorCount = Object.keys(errors).length;
|
||
|
||
// 副作用里要读「当前是否有未保存修改 / 当前基线」,用 ref 避免把 effect 依赖
|
||
// 扩到 prices(会让服务端同步 effect 每次按键都重跑)
|
||
const dirtyRef = useRef(dirty);
|
||
const savedCanonRef = useRef(savedCanon);
|
||
useEffect(() => {
|
||
dirtyRef.current = dirty;
|
||
}, [dirty]);
|
||
useEffect(() => {
|
||
savedCanonRef.current = savedCanon;
|
||
}, [savedCanon]);
|
||
|
||
const applyServerValue = useCallback((parsed) => {
|
||
const canon = canonicalOfficialPriceJSON(parsed);
|
||
setPrices(JSON.parse(canon));
|
||
setSavedCanon(canon);
|
||
savedCanonRef.current = canon;
|
||
setDrafts({});
|
||
setErrors({});
|
||
setConflict(false);
|
||
setSnapshotTick((v) => v + 1);
|
||
}, []);
|
||
|
||
// 从 option 同步已保存的官方价
|
||
useEffect(() => {
|
||
const raw = props.options?.ModelOfficialPrice;
|
||
if (raw === undefined) return;
|
||
let parsed;
|
||
try {
|
||
parsed = raw ? JSON.parse(raw) : {};
|
||
} catch (e) {
|
||
showError(t('模型原厂价格配置解析失败,请检查系统配置'));
|
||
return;
|
||
}
|
||
if (canonicalOfficialPriceJSON(parsed) === savedCanonRef.current) return;
|
||
// 服务端值与本地基线不一致:有未保存修改时不覆盖用户输入,改为提示冲突
|
||
if (dirtyRef.current) {
|
||
setConflict(true);
|
||
return;
|
||
}
|
||
applyServerValue(parsed);
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [props.options?.ModelOfficialPrice]);
|
||
|
||
// 模型列表自动来自模型广场;admin_view=1 让后端跳过等级可见性过滤,
|
||
// 否则管理员本人(或其所属企业)的等级隐藏了某些模型时,这些模型会
|
||
// 从维护页静默消失、永远配不了官方价。
|
||
const loadModels = async () => {
|
||
setModelsLoading(true);
|
||
try {
|
||
// skipErrorHandler:全局响应拦截器对网络/HTTP 错误会直接 showError(error)(英文原文),
|
||
// 不跳过就会与下方 catch 的中文提示双弹
|
||
const res = await API.get('/api/pricing', {
|
||
params: { admin_view: 1 },
|
||
skipErrorHandler: true,
|
||
});
|
||
const { success, message, data, vendors } = res.data;
|
||
if (success) {
|
||
const vm = {};
|
||
(Array.isArray(vendors) ? vendors : []).forEach((v) => {
|
||
vm[v.id] = v.name;
|
||
});
|
||
setVendorMap(vm);
|
||
const list = Array.isArray(data) ? [...data] : [];
|
||
list.sort((a, b) => a.model_name.localeCompare(b.model_name));
|
||
setModels(list);
|
||
setModelsLoaded(true);
|
||
setSnapshotTick((v) => v + 1);
|
||
// 清理指向「已不存在的输入框」的草稿与错误:档位被下线 / 模型下架后,
|
||
// 残留的 errors 条目会让顶部一直显示「N 处非法输入」并挡住保存,
|
||
// 而页面上根本找不到那个标红的框(无从修正 = 死锁)
|
||
const liveKeys = new Set();
|
||
list.forEach((m) => {
|
||
const pricing = tierPricingOf(m);
|
||
if (!pricing) return;
|
||
pricing.tiers.forEach((tier) =>
|
||
liveKeys.add(fieldKey(m.model_name, pricing.field, tier.key)),
|
||
);
|
||
});
|
||
const known = new Set(list.map((m) => m.model_name));
|
||
const pruneStale = (obj) => {
|
||
const next = {};
|
||
Object.keys(obj).forEach((k) => {
|
||
const modelName = k.slice(0, k.indexOf('::'));
|
||
if (!known.has(modelName)) return; // 模型已下架
|
||
// 分档键(三段)必须仍在当前档位表里;标量键(两段)一律保留
|
||
if (k.split('::').length > 2 && !liveKeys.has(k)) return;
|
||
next[k] = obj[k];
|
||
});
|
||
return next;
|
||
};
|
||
setDrafts(pruneStale);
|
||
setErrors(pruneStale);
|
||
} else {
|
||
showError(message);
|
||
}
|
||
} catch (e) {
|
||
showError(t('加载模型列表失败'));
|
||
} finally {
|
||
setModelsLoading(false);
|
||
}
|
||
};
|
||
|
||
useEffect(() => {
|
||
loadModels();
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, []);
|
||
|
||
// 有未保存修改时离开页面给出浏览器级确认(整页刷新/关闭标签)
|
||
useEffect(() => {
|
||
if (!dirty) return undefined;
|
||
const handler = (e) => {
|
||
e.preventDefault();
|
||
e.returnValue = '';
|
||
};
|
||
window.addEventListener('beforeunload', handler);
|
||
return () => window.removeEventListener('beforeunload', handler);
|
||
}, [dirty]);
|
||
|
||
// 实时填写状态(用于计数与行内标记)
|
||
// 该模型是否按缓存计价:/api/pricing 直接带出收入侧的缓存倍率。只有真按缓存计费的
|
||
// 模型才要求填缓存原厂价——给所有模型都要求会让绝大多数模型永远停在「部分填写」。
|
||
// 分档模型(按秒/按分辨率)的必填集 = 该模型收入侧配置的全部档位:收入侧逐档
|
||
// 定价,成本侧就要逐档有牌价,缺一档就是那一档的毛利算不出来。
|
||
const cacheNeedOf = useCallback(
|
||
(record) => ({
|
||
needCacheRead: isFilledValue(record?.cache_ratio),
|
||
needCacheCreation: isFilledValue(record?.cache_creation_ratio),
|
||
tierKeys: (tierPricingOf(record)?.tiers || []).map((t) => t.key),
|
||
}),
|
||
[],
|
||
);
|
||
|
||
const liveStateOf = useCallback(
|
||
(record) =>
|
||
officialFillState(
|
||
record.quota_type,
|
||
prices[record.model_name],
|
||
cacheNeedOf(record),
|
||
),
|
||
[prices, cacheNeedOf],
|
||
);
|
||
|
||
// 分类快照(列表过滤口径):故意不依赖 prices。跟着按键实时重算会让正在编辑的
|
||
// 那一行立刻被过滤掉——这正是「在未填写页输一个值就跳到已填写」的成因。
|
||
const snapshot = useMemo(() => {
|
||
const map = {};
|
||
models.forEach((m) => {
|
||
map[m.model_name] = officialFillState(
|
||
m.quota_type,
|
||
prices[m.model_name],
|
||
cacheNeedOf(m),
|
||
);
|
||
});
|
||
return map;
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [models, fillFilter, snapshotTick]);
|
||
|
||
const counts = useMemo(() => {
|
||
const c = { total: models.length, filled: 0, partial: 0, empty: 0, na: 0 };
|
||
models.forEach((m) => {
|
||
const s = liveStateOf(m);
|
||
if (s === OFFICIAL_FILL_FILLED) c.filled += 1;
|
||
else if (s === OFFICIAL_FILL_PARTIAL) c.partial += 1;
|
||
else if (s === OFFICIAL_FILL_NA) c.na += 1;
|
||
else c.empty += 1;
|
||
});
|
||
return c;
|
||
}, [models, liveStateOf]);
|
||
|
||
// 快照与实时状态不一致的行数:提示用户「刷新筛选」后列表才会重排
|
||
const staleCount = useMemo(() => {
|
||
if (fillFilter === 'all') return 0;
|
||
return models.filter((m) => snapshot[m.model_name] !== liveStateOf(m))
|
||
.length;
|
||
}, [models, snapshot, liveStateOf, fillFilter]);
|
||
|
||
const filteredModels = useMemo(() => {
|
||
let result = models;
|
||
const kw = search.trim().toLowerCase();
|
||
if (kw) {
|
||
result = result.filter((m) => {
|
||
const vendor = (vendorMap[m.vendor_id] || '').toLowerCase();
|
||
return m.model_name.toLowerCase().includes(kw) || vendor.includes(kw);
|
||
});
|
||
}
|
||
if (fillFilter !== 'all') {
|
||
const want =
|
||
fillFilter === 'filled'
|
||
? OFFICIAL_FILL_FILLED
|
||
: fillFilter === 'partial'
|
||
? OFFICIAL_FILL_PARTIAL
|
||
: OFFICIAL_FILL_EMPTY;
|
||
result = result.filter((m) => snapshot[m.model_name] === want);
|
||
}
|
||
return result;
|
||
}, [models, search, fillFilter, snapshot, vendorMap]);
|
||
|
||
// 搜索/筛选变化后回到第一页,避免停留在越界空页
|
||
useEffect(() => {
|
||
setCurrentPage(1);
|
||
}, [search, fillFilter]);
|
||
|
||
// 列表里没有对应行的官方价条目:看不见、删不掉,但每次保存都会被原样写回。
|
||
// 注意 /api/pricing 只返回「当前有启用渠道」的模型,渠道被临时禁用(含自动禁用)
|
||
// 也会落到这里——所以文案与清理动作都必须按「当前不可用」而不是「已删除」来处理,
|
||
// 清理前必须让管理员看到完整名单再确认,否则会误删仍在用的配置。
|
||
// 模型列表加载成功后才统计(避免拉取失败时把全部条目误判为失效)。
|
||
const orphanModels = useMemo(() => {
|
||
if (!modelsLoaded || models.length === 0) return [];
|
||
const known = new Set(models.map((m) => m.model_name));
|
||
return Object.keys(prices).filter((name) => !known.has(name));
|
||
}, [prices, models, modelsLoaded]);
|
||
|
||
// 字段与当前计费类型不匹配、整条不生效的条目(模型改过计费方式 / 导入填错字段):
|
||
// 行上看起来是「未填写」,实际存了值且永远不产生折扣,必须显式点名。
|
||
const inertModels = useMemo(
|
||
() =>
|
||
models
|
||
.filter((m) => isOfficialEntryInert(m.quota_type, prices[m.model_name]))
|
||
.map((m) => m.model_name),
|
||
[models, prices],
|
||
);
|
||
|
||
const fieldValue = (modelName, field, tier) => {
|
||
const key = fieldKey(modelName, field, tier);
|
||
if (drafts[key] !== undefined) return drafts[key];
|
||
const entry = prices[modelName];
|
||
// 分档字段一律走档位读法:按 tier 真值判断的话,空档位键会掉进标量分支,
|
||
// 把一个数字写进本该是映射的字段,序列化时被静默丢弃
|
||
const v = isOfficialTierField(field)
|
||
? tierPriceOf(entry, field, tier)
|
||
: entry?.[field];
|
||
return isFilledValue(v) ? v : '';
|
||
};
|
||
|
||
const updatePrice = (modelName, field, value, tier) => {
|
||
const key = fieldKey(modelName, field, tier);
|
||
const isEmpty = value === '' || value === null || value === undefined;
|
||
const num = isEmpty ? null : Number(value);
|
||
const valid = !isEmpty && Number.isFinite(num) && num > 0;
|
||
|
||
// 非法值原样保留在输入框(受控组件下抹掉 = 用户白输),并给出行内错误
|
||
setDrafts((prev) => {
|
||
const next = { ...prev };
|
||
if (isEmpty || valid) delete next[key];
|
||
else next[key] = value;
|
||
return next;
|
||
});
|
||
setErrors((prev) => {
|
||
const next = { ...prev };
|
||
if (isEmpty || valid) delete next[key];
|
||
else if (!Number.isFinite(num)) next[key] = t('请输入数字');
|
||
else next[key] = t('官方价必须大于 0');
|
||
return next;
|
||
});
|
||
setPrices((prev) => {
|
||
const next = { ...prev };
|
||
const entry = { ...(next[modelName] || {}) };
|
||
if (isOfficialTierField(field)) {
|
||
// 档位键按归一键落盘,并顺手清掉只差大小写的历史写法(导入来的 1080P /
|
||
// 1080p 同时存在时,两条会互相覆盖,页面上改一个另一个还在)
|
||
const nk = normalizeTierKey(tier);
|
||
const map = { ...(entry[field] || {}) };
|
||
Object.keys(map).forEach((k) => {
|
||
if (normalizeTierKey(k) === nk) delete map[k];
|
||
});
|
||
if (valid) map[nk] = num;
|
||
if (Object.keys(map).length > 0) entry[field] = map;
|
||
else delete entry[field];
|
||
} else if (valid) {
|
||
entry[field] = num;
|
||
} else {
|
||
delete entry[field];
|
||
}
|
||
if (Object.keys(entry).length > 0) next[modelName] = entry;
|
||
else delete next[modelName];
|
||
return next;
|
||
});
|
||
};
|
||
|
||
const clearModel = (modelName) => {
|
||
setPrices((prev) => {
|
||
const next = { ...prev };
|
||
delete next[modelName];
|
||
return next;
|
||
});
|
||
const strip = (obj) => {
|
||
const next = { ...obj };
|
||
Object.keys(next).forEach((k) => {
|
||
if (k.startsWith(`${modelName}::`)) delete next[k];
|
||
});
|
||
return next;
|
||
};
|
||
setDrafts(strip);
|
||
setErrors(strip);
|
||
};
|
||
|
||
const cleanOrphans = () => {
|
||
const removed = orphanModels.length;
|
||
Modal.confirm({
|
||
title: t('确认清理这些官方价配置?'),
|
||
content: (
|
||
<div className='text-xs'>
|
||
<div className='mb-2'>
|
||
{t(
|
||
'渠道被临时禁用(含错误自动禁用)的模型也会出现在这里。清理后这些模型的官方价将被删除,渠道恢复后需要重新填写。',
|
||
)}
|
||
</div>
|
||
<div className='max-h-40 overflow-auto font-mono break-all'>
|
||
{orphanModels.join('、')}
|
||
</div>
|
||
</div>
|
||
),
|
||
okText: t('确认清理'),
|
||
cancelText: t('取消'),
|
||
onOk: () => {
|
||
setPrices((prev) => {
|
||
const next = { ...prev };
|
||
orphanModels.forEach((name) => delete next[name]);
|
||
return next;
|
||
});
|
||
showWarning(
|
||
t('已移除 {{count}} 条失效配置,点击「保存官方价格」后生效', {
|
||
count: removed,
|
||
}),
|
||
);
|
||
},
|
||
});
|
||
};
|
||
|
||
const onSave = async () => {
|
||
if (errorCount > 0) {
|
||
showError(t('存在非法输入,请先修正标红的价格'));
|
||
return;
|
||
}
|
||
if (!dirty) {
|
||
showWarning(t('你似乎并没有修改什么'));
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
try {
|
||
const res = await API.put(
|
||
'/api/option/',
|
||
{ key: 'ModelOfficialPrice', value: currentCanon },
|
||
{ skipErrorHandler: true }, // 同上:错误文案统一由本组件给中文
|
||
);
|
||
if (res?.data?.success) {
|
||
showSuccess(t('保存成功'));
|
||
applyServerValue(JSON.parse(currentCanon));
|
||
props.refresh?.();
|
||
} else {
|
||
showError(res?.data?.message || t('保存失败'));
|
||
}
|
||
} catch (e) {
|
||
showError(t('保存失败,请重试'));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
const onImport = () => {
|
||
let raw;
|
||
try {
|
||
raw = JSON.parse(importText);
|
||
} catch (e) {
|
||
showError(t('不是合法 JSON,请检查后重试'));
|
||
return;
|
||
}
|
||
const { value, errors: importErrors } = sanitizeOfficialPriceMap(raw);
|
||
if (importErrors.length > 0) {
|
||
showError(`${t('导入失败')}:${importErrors.slice(0, 3).join(';')}`);
|
||
return;
|
||
}
|
||
// 整体替换会丢掉未包含在导入内容里的既有条目,数量必须当场告知
|
||
const droppedCount =
|
||
importMode === 'replace'
|
||
? Object.keys(prices).filter((name) => value[name] === undefined).length
|
||
: 0;
|
||
setPrices((prev) =>
|
||
importMode === 'replace' ? value : { ...prev, ...value },
|
||
);
|
||
setDrafts({});
|
||
setErrors({});
|
||
setTransferVisible(false);
|
||
setImportText('');
|
||
showWarning(
|
||
droppedCount > 0
|
||
? t(
|
||
'已载入 {{count}} 个模型的官方价,并移除未包含的 {{dropped}} 条,点击「保存官方价格」后生效',
|
||
{ count: Object.keys(value).length, dropped: droppedCount },
|
||
)
|
||
: t('已载入 {{count}} 个模型的官方价,点击「保存官方价格」后生效', {
|
||
count: Object.keys(value).length,
|
||
}),
|
||
);
|
||
};
|
||
|
||
// 只在弹窗打开时生成:否则每次按键都会把整份配置 parse + stringify 一遍
|
||
const exportJSON = useMemo(
|
||
() =>
|
||
transferVisible ? JSON.stringify(JSON.parse(currentCanon), null, 2) : '',
|
||
[currentCanon, transferVisible],
|
||
);
|
||
|
||
const downloadJSON = () => {
|
||
const blob = new Blob([exportJSON], { type: 'application/json' });
|
||
const url = URL.createObjectURL(blob);
|
||
const a = document.createElement('a');
|
||
a.href = url;
|
||
a.download = 'model-official-price.json';
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
document.body.removeChild(a);
|
||
// 同步 revoke 在部分浏览器会掐断刚触发的下载,挪到下一个事件循环
|
||
setTimeout(() => URL.revokeObjectURL(url), 0);
|
||
};
|
||
|
||
// 单方向折扣标签:站内基准价按分组倍率 1 计算
|
||
const renderDirectionDiscount = (label, actual, official) => {
|
||
const wrap = (node) => (
|
||
<div className='text-xs'>
|
||
<span className='text-gray-400'>{label}</span> {node}
|
||
</div>
|
||
);
|
||
if (official === undefined) {
|
||
return wrap(
|
||
<Typography.Text type='tertiary' size='small'>
|
||
{t('未填')}
|
||
</Typography.Text>,
|
||
);
|
||
}
|
||
if (!isFilledValue(actual)) {
|
||
// 站内该方向价格为 0(未设倍率/免费):computeDiscountRatio 会返回 null,
|
||
// 若沿用「无折扣」文案会把免费模型误标成「站内价高于官方价」
|
||
return wrap(
|
||
<Tooltip
|
||
content={t('站内该方向价格为 0(未设倍率或免费),无法计算折扣')}
|
||
>
|
||
<Tag color='grey' shape='circle' size='small'>
|
||
{t('站内未计价')}
|
||
</Tag>
|
||
</Tooltip>,
|
||
);
|
||
}
|
||
const ratio = computeDiscountRatio(actual, official);
|
||
if (ratio === null) {
|
||
return wrap(
|
||
<Tooltip content={t('站内实付价不低于官方价,市场页不会展示折扣标签')}>
|
||
<Tag color='orange' shape='circle' size='small'>
|
||
{t('无折扣')}
|
||
</Tag>
|
||
</Tooltip>,
|
||
);
|
||
}
|
||
return wrap(
|
||
<Tag color='red' shape='circle' size='small'>
|
||
{formatDiscountLabel(ratio, i18next.language)}
|
||
</Tag>,
|
||
);
|
||
};
|
||
|
||
const renderDiscountPreview = (record) => {
|
||
const official = prices[record.model_name];
|
||
const state = liveStateOf(record);
|
||
if (state === OFFICIAL_FILL_NA || !official) {
|
||
return <Typography.Text type='tertiary'>-</Typography.Text>;
|
||
}
|
||
// 分档计费:逐档独立对照(档位之间互不影响,一个整体徽标反而会掩盖亏档)
|
||
const tierComparison = buildTierComparison(record, official);
|
||
if (tierComparison) {
|
||
return (
|
||
<Tooltip
|
||
content={t(
|
||
'按基准倍率 1 预览;逐档独立计算。分档模型的官方价只用于成本核算与毛利,不在模型超市展示折扣。',
|
||
)}
|
||
>
|
||
<div className='flex flex-col gap-1'>
|
||
{tierComparison.map((tc) => (
|
||
<React.Fragment key={tc.key}>
|
||
{renderDirectionDiscount(tc.label, tc.basePrice, tc.official)}
|
||
</React.Fragment>
|
||
))}
|
||
</div>
|
||
</Tooltip>
|
||
);
|
||
}
|
||
const base = basePrices(record);
|
||
const body =
|
||
record.quota_type === 0 ? (
|
||
<div className='flex flex-col gap-1'>
|
||
{renderDirectionDiscount(t('输入'), base.input, official.input)}
|
||
{renderDirectionDiscount(t('输出'), base.output, official.output)}
|
||
</div>
|
||
) : (
|
||
renderDirectionDiscount(t('单次'), base.perCall, official.per_call)
|
||
);
|
||
return (
|
||
<Tooltip
|
||
content={t(
|
||
'按基准倍率 1 预览;用户实际看到的折扣还会叠加其分组倍率与等级折扣。任一方向无折扣时,市场页整体不出折扣徽标。',
|
||
)}
|
||
>
|
||
<div>{body}</div>
|
||
</Tooltip>
|
||
);
|
||
};
|
||
|
||
const renderBasePrice = (record) => {
|
||
const base = basePrices(record);
|
||
if (record.quota_type === 0) {
|
||
return (
|
||
<div className='text-xs font-mono leading-5'>
|
||
<div>
|
||
{t('输入')} ¥{base.input.toFixed(4)} / 1M
|
||
</div>
|
||
<div>
|
||
{t('输出')} ¥{base.output.toFixed(4)} / 1M
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
if (record.quota_type === 1) {
|
||
return (
|
||
<span className='text-xs font-mono'>
|
||
¥{Number.isFinite(base.perCall) ? base.perCall.toFixed(4) : '-'} /{' '}
|
||
{t('次')}
|
||
</span>
|
||
);
|
||
}
|
||
// 分档计费(按秒 / 按分辨率):逐档列出站内档位价,与右侧逐档官方价一一对齐
|
||
const pricing = tierPricingOf(record);
|
||
if (pricing) {
|
||
if (pricing.tiers.length === 0) {
|
||
return <Typography.Text type='tertiary'>-</Typography.Text>;
|
||
}
|
||
return (
|
||
<div className='text-xs font-mono leading-5'>
|
||
{pricing.tiers.map((tier) => (
|
||
<div key={tier.key}>
|
||
{tier.label} ¥
|
||
{Number.isFinite(tier.basePrice)
|
||
? tier.basePrice.toFixed(4)
|
||
: '-'}{' '}
|
||
{tierUnitSuffix(pricing.unit, t)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
);
|
||
}
|
||
return <Typography.Text type='tertiary'>-</Typography.Text>;
|
||
};
|
||
|
||
const renderPriceInput = (
|
||
record,
|
||
field,
|
||
suffixLabel,
|
||
placeholder,
|
||
hint,
|
||
tier,
|
||
) => {
|
||
const key = fieldKey(record.model_name, field, tier);
|
||
const err = errors[key];
|
||
const value = fieldValue(record.model_name, field, tier);
|
||
return (
|
||
<div key={key}>
|
||
<InputNumber
|
||
prefix='¥'
|
||
suffix={<span className='text-xs text-gray-400'>{suffixLabel}</span>}
|
||
value={value}
|
||
step={PRICE_STEP}
|
||
hideButtons
|
||
validateStatus={err ? 'error' : 'default'}
|
||
style={{ width: 190 }}
|
||
placeholder={placeholder}
|
||
onChange={(v) => updatePrice(record.model_name, field, v, tier)}
|
||
/>
|
||
{err && (
|
||
<div className='text-xs mt-0.5'>
|
||
<Typography.Text type='danger' size='small'>
|
||
{err}
|
||
</Typography.Text>
|
||
</div>
|
||
)}
|
||
{/* 推算提示只在真的空着时给:填了值再提示"留空会怎样"是噪音 */}
|
||
{!err && hint && !isFilledValue(value) && (
|
||
<div className='text-xs mt-0.5'>
|
||
<Typography.Text type='tertiary' size='small'>
|
||
{hint}
|
||
</Typography.Text>
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
};
|
||
|
||
const renderOfficialEditor = (record) => {
|
||
if (record.quota_type === 0) {
|
||
const need = cacheNeedOf(record);
|
||
// 缓存两项只对按缓存计价的模型展示:收入侧对缓存读取/创建单独计价,
|
||
// 成本侧要「扣费的每一项都有成本价」,就必须有对应的原厂参照价。
|
||
// 留空时成本侧回退「输入价 × 厂商缓存倍率」推算,故给出推算值提示。
|
||
const inputVal = fieldValue(record.model_name, 'input');
|
||
const hint = (ratio) =>
|
||
isFilledValue(inputVal) && isFilledValue(ratio)
|
||
? t('留空按输入价 × {{ratio}}× ≈ ¥{{price}} 推算', {
|
||
ratio,
|
||
price: Number((inputVal * ratio).toFixed(4)),
|
||
})
|
||
: t('留空按输入价 × {{ratio}}× 推算', { ratio: ratio ?? '—' });
|
||
return (
|
||
<Space vertical align='start' spacing={4}>
|
||
{renderPriceInput(
|
||
record,
|
||
'input',
|
||
`/1M ${t('输入')}`,
|
||
t('官方输入价'),
|
||
)}
|
||
{renderPriceInput(
|
||
record,
|
||
'output',
|
||
`/1M ${t('输出')}`,
|
||
t('官方输出价'),
|
||
)}
|
||
{need.needCacheRead &&
|
||
renderPriceInput(
|
||
record,
|
||
'cache_read',
|
||
`/1M ${t('缓存读取')}`,
|
||
t('官方缓存读取价'),
|
||
hint(record.cache_ratio),
|
||
)}
|
||
{need.needCacheCreation &&
|
||
renderPriceInput(
|
||
record,
|
||
'cache_creation',
|
||
`/1M ${t('缓存创建')}`,
|
||
t('官方缓存创建价'),
|
||
hint(record.cache_creation_ratio),
|
||
)}
|
||
</Space>
|
||
);
|
||
}
|
||
if (record.quota_type === 1) {
|
||
return renderPriceInput(
|
||
record,
|
||
'per_call',
|
||
`/${t('次')}`,
|
||
t('官方单次价'),
|
||
);
|
||
}
|
||
// 分档计费:逐档一个输入框。收入侧对每个档位单独定价(720p 与 1080p 可差数倍),
|
||
// 只登记一个"整模型均价"会让高档位算亏、低档位虚高,毛利与分佣一起失真。
|
||
const pricing = tierPricingOf(record);
|
||
if (pricing) {
|
||
if (pricing.tiers.length === 0) {
|
||
return (
|
||
<Typography.Text type='tertiary' size='small'>
|
||
{t('该模型未配置任何计费档位,请先在模型价格设置中配置档位')}
|
||
</Typography.Text>
|
||
);
|
||
}
|
||
// 收入侧下线过档位时,旧档位的牌价会留在条目里:页面上看不见、删不掉,却会被
|
||
// 原样保存并按它生成成本行。必须点名,否则管理员永远不知道那笔配置还在。
|
||
const known = new Set(
|
||
pricing.tiers.map((tier) => normalizeTierKey(tier.key)),
|
||
);
|
||
const staleTiers = Object.keys(
|
||
prices[record.model_name]?.[pricing.field] || {},
|
||
).filter((k) => !known.has(normalizeTierKey(k)));
|
||
return (
|
||
<Space vertical align='start' spacing={4}>
|
||
{pricing.tiers.map((tier) =>
|
||
renderPriceInput(
|
||
record,
|
||
pricing.field,
|
||
`${tierUnitSuffix(pricing.unit, t)} ${tier.label}`,
|
||
t('官方{{tier}}价', { tier: tier.label }),
|
||
undefined,
|
||
tier.key,
|
||
),
|
||
)}
|
||
{staleTiers.length > 0 && (
|
||
<Typography.Text type='warning' size='small'>
|
||
{t(
|
||
'存有已下线档位的官方价:{{tiers}}(当前计费不再使用,可点「清空」后重填)',
|
||
{ tiers: staleTiers.join('、') },
|
||
)}
|
||
</Typography.Text>
|
||
)}
|
||
</Space>
|
||
);
|
||
}
|
||
return (
|
||
<Typography.Text type='tertiary' size='small'>
|
||
{t('未知计费类型,暂不支持配置官方价')}
|
||
</Typography.Text>
|
||
);
|
||
};
|
||
|
||
const renderFillTag = (record) => {
|
||
const state = liveStateOf(record);
|
||
// 存了值但字段与当前计费类型对不上:显示成「未填写」会让管理员以为没配过
|
||
if (isOfficialEntryInert(record.quota_type, prices[record.model_name])) {
|
||
return (
|
||
<Tooltip
|
||
content={t(
|
||
'该模型存有官方价,但字段与当前计费类型不匹配(模型改过计费方式或导入填错),市场页不会使用。请清空后按当前计费类型重填。',
|
||
)}
|
||
>
|
||
<Tag color='red' shape='circle' size='small'>
|
||
{t('配置不生效')}
|
||
</Tag>
|
||
</Tooltip>
|
||
);
|
||
}
|
||
if (state === OFFICIAL_FILL_FILLED) {
|
||
return (
|
||
<Tag color='green' shape='circle' size='small'>
|
||
{t('已填写')}
|
||
</Tag>
|
||
);
|
||
}
|
||
if (state === OFFICIAL_FILL_PARTIAL) {
|
||
const tiered = tierPricingOf(record) !== null;
|
||
return (
|
||
<Tooltip
|
||
content={
|
||
tiered
|
||
? t(
|
||
'分档计费模型需逐档填齐官方价:收入侧对每个档位单独计价,缺一档就是那一档的成本只能靠收入价推算,毛利与分佣都会失真。',
|
||
)
|
||
: t(
|
||
'按量计费模型需填齐输入价与输出价,市场页才会展示折扣(缺一侧整体不出徽标);若该模型按缓存计价,缓存读取/创建价也要填齐,成本核算才能做到「扣费的每一项都有成本价」。',
|
||
)
|
||
}
|
||
>
|
||
<Tag color='amber' shape='circle' size='small'>
|
||
{t('部分填写')}
|
||
</Tag>
|
||
</Tooltip>
|
||
);
|
||
}
|
||
if (state === OFFICIAL_FILL_NA) return null;
|
||
return (
|
||
<Tag color='grey' shape='circle' size='small'>
|
||
{t('未填写')}
|
||
</Tag>
|
||
);
|
||
};
|
||
|
||
const columns = [
|
||
{
|
||
title: t('模型'),
|
||
dataIndex: 'model_name',
|
||
sorter: (a, b) => a.model_name.localeCompare(b.model_name),
|
||
render: (text, record) => (
|
||
<div className='flex flex-col gap-1'>
|
||
<Typography.Text
|
||
copyable={{ text: text }}
|
||
strong
|
||
className='!text-[13px]'
|
||
>
|
||
{text}
|
||
</Typography.Text>
|
||
<div className='flex flex-wrap gap-1'>
|
||
{record.quota_type === 0 && (
|
||
<Tag color='violet' shape='circle' size='small'>
|
||
{t('按量计费')}
|
||
</Tag>
|
||
)}
|
||
{record.quota_type === 1 && (
|
||
<Tag color='teal' shape='circle' size='small'>
|
||
{t('按次计费')}
|
||
</Tag>
|
||
)}
|
||
{record.quota_type === 2 && (
|
||
<Tag color='blue' shape='circle' size='small'>
|
||
{t('按秒计费')}
|
||
</Tag>
|
||
)}
|
||
{record.quota_type === 3 && (
|
||
<Tag color='blue' shape='circle' size='small'>
|
||
{t('按分辨率计费')}
|
||
</Tag>
|
||
)}
|
||
{vendorMap[record.vendor_id] && (
|
||
<Tag color='white' shape='circle' size='small'>
|
||
{vendorMap[record.vendor_id]}
|
||
</Tag>
|
||
)}
|
||
</div>
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
title: (
|
||
<Tooltip content={t('分组倍率按 1 计算的站内牌价,未含分组与等级折扣')}>
|
||
<span>{t('站内基准价')}</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'base_price',
|
||
width: 200,
|
||
render: (_, record) => renderBasePrice(record),
|
||
},
|
||
{
|
||
title: t('官方价格(¥,汇率按 1:1)'),
|
||
dataIndex: 'official',
|
||
width: 240,
|
||
render: (_, record) => renderOfficialEditor(record),
|
||
},
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'fill_state',
|
||
width: 110,
|
||
render: (_, record) => renderFillTag(record),
|
||
},
|
||
{
|
||
title: t('折扣预览'),
|
||
dataIndex: 'discount',
|
||
width: 170,
|
||
render: (_, record) => renderDiscountPreview(record),
|
||
},
|
||
{
|
||
title: t('操作'),
|
||
dataIndex: 'op',
|
||
width: 90,
|
||
render: (_, record) => (
|
||
<Button
|
||
disabled={
|
||
!prices[record.model_name] &&
|
||
!Object.keys(drafts).some((k) =>
|
||
k.startsWith(`${record.model_name}::`),
|
||
)
|
||
}
|
||
onClick={() => clearModel(record.model_name)}
|
||
type='link'
|
||
size='small'
|
||
>
|
||
{t('清空')}
|
||
</Button>
|
||
),
|
||
},
|
||
];
|
||
|
||
const emptyText =
|
||
models.length === 0
|
||
? t('暂无模型,请先在渠道中配置可用模型')
|
||
: t('没有符合当前搜索与筛选条件的模型');
|
||
|
||
return (
|
||
<div className='pt-2'>
|
||
<Banner
|
||
type='info'
|
||
closeIcon={null}
|
||
className='!rounded-lg mb-3'
|
||
description={t(
|
||
'官方价格不参与任何计费。输入/输出/单次价用于模型超市展示原价与折扣;缓存两项与分档价(按秒/按分辨率)不上市场页,只作为成本核算的原厂参照(收入侧对它们单独计价,成本侧也必须有对应单价)。单位为 ¥(平台按人民币兑美元 1:1 口径):按量计费填每 1M tokens 官方价,按次计费填每次官方价,视频按秒分档逐档填每秒官方价,图片按分辨率分档逐档填每张官方价。缓存两项留空时成本侧按「输入价 × 厂商缓存倍率」推算;分档价留空时成本侧退回「站内档位价 × 全局成本折扣」,比按原厂价更偏离真实进价。注意:牌价只是**兜底基准**,按它记的成本一律标记为「预估」——要让账目不再预估,仍须在「模型成本价格」页配置实际进价。',
|
||
)}
|
||
/>
|
||
|
||
{usdExchangeRate !== 1 && (
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
className='!rounded-lg mb-3'
|
||
description={t(
|
||
'当前站点美元汇率为 {{rate}}:模型超市在人民币视图下会把这里填写的官方价同样乘以该汇率展示。请按左侧「站内基准价」的同一量纲填写(真实官方价 ¥X 应填 X÷{{rate}}),否则超市展示的原价会被整体放大。',
|
||
{ rate: usdExchangeRate },
|
||
)}
|
||
/>
|
||
)}
|
||
|
||
{conflict && (
|
||
<Banner
|
||
type='danger'
|
||
closeIcon={null}
|
||
className='!rounded-lg mb-3'
|
||
description={
|
||
<div className='flex flex-wrap items-center gap-2'>
|
||
<span>
|
||
{t(
|
||
'服务器上的原厂价配置与页面载入时不一致(可能由其他管理员保存,或本页基线尚未载入完就开始了编辑)。请先裁决:保存已暂时锁定,避免把整份配置覆盖成本地这一份。',
|
||
)}
|
||
</span>
|
||
<Button
|
||
size='small'
|
||
onClick={() => {
|
||
try {
|
||
const raw = props.options?.ModelOfficialPrice;
|
||
applyServerValue(raw ? JSON.parse(raw) : {});
|
||
showSuccess(t('已载入服务器最新配置'));
|
||
} catch (e) {
|
||
showError(t('模型原厂价格配置解析失败,请检查系统配置'));
|
||
}
|
||
}}
|
||
>
|
||
{t('放弃本地修改并载入最新')}
|
||
</Button>
|
||
<Button
|
||
size='small'
|
||
type='danger'
|
||
onClick={() => {
|
||
// 以服务端当前值作为新基线:dirty 随即按「本地 vs 服务端」重算,
|
||
// 保存解锁且语义明确——覆盖对方改动是管理员的显式选择
|
||
try {
|
||
const raw = props.options?.ModelOfficialPrice;
|
||
const canon = canonicalOfficialPriceJSON(
|
||
raw ? JSON.parse(raw) : {},
|
||
);
|
||
setSavedCanon(canon);
|
||
savedCanonRef.current = canon;
|
||
setConflict(false);
|
||
showWarning(
|
||
t('已改为以本地修改为准,保存将覆盖服务器配置'),
|
||
);
|
||
} catch (e) {
|
||
showError(t('模型原厂价格配置解析失败,请检查系统配置'));
|
||
}
|
||
}}
|
||
>
|
||
{t('以我的为准(覆盖服务器)')}
|
||
</Button>
|
||
</div>
|
||
}
|
||
/>
|
||
)}
|
||
|
||
{(orphanModels.length > 0 || inertModels.length > 0) && (
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
className='!rounded-lg mb-3'
|
||
description={
|
||
<div className='flex flex-col gap-1'>
|
||
{orphanModels.length > 0 && (
|
||
<div className='flex flex-wrap items-center gap-2'>
|
||
<span>
|
||
{t(
|
||
'有 {{count}} 条官方价对应的模型当前不在列表中(已下线、改名,或其渠道被禁用):{{names}}。它们不会出现在下方列表,但每次保存都会被写回。',
|
||
{
|
||
count: orphanModels.length,
|
||
names: orphanModels.slice(0, 5).join('、'),
|
||
},
|
||
)}
|
||
</span>
|
||
<Button size='small' type='warning' onClick={cleanOrphans}>
|
||
{t('清理失效条目')}
|
||
</Button>
|
||
</div>
|
||
)}
|
||
{inertModels.length > 0 && (
|
||
<div>
|
||
{t(
|
||
'有 {{count}} 条官方价的字段与模型当前计费类型不匹配,整条不生效(列表中标记为「配置不生效」):{{names}}',
|
||
{
|
||
count: inertModels.length,
|
||
names: inertModels.slice(0, 5).join('、'),
|
||
},
|
||
)}
|
||
</div>
|
||
)}
|
||
</div>
|
||
}
|
||
/>
|
||
)}
|
||
|
||
<div className='flex flex-wrap items-center justify-between gap-2 mb-2'>
|
||
<Space wrap>
|
||
<Input
|
||
prefix={<IconSearch />}
|
||
placeholder={t('搜索模型名称或厂商')}
|
||
value={search}
|
||
onChange={(v) => setSearch(v)}
|
||
showClear
|
||
style={{ width: 220 }}
|
||
/>
|
||
<RadioGroup
|
||
type='button'
|
||
value={fillFilter}
|
||
onChange={(e) => {
|
||
setFillFilter(e.target.value);
|
||
setSnapshotTick((v) => v + 1);
|
||
}}
|
||
>
|
||
<Radio value='all'>
|
||
{t('全部')} ({counts.total})
|
||
</Radio>
|
||
<Radio value='filled'>
|
||
{t('已填写')} ({counts.filled})
|
||
</Radio>
|
||
<Radio value='partial'>
|
||
{t('部分填写')} ({counts.partial})
|
||
</Radio>
|
||
<Radio value='unfilled'>
|
||
{t('未填写')} ({counts.empty})
|
||
</Radio>
|
||
</RadioGroup>
|
||
</Space>
|
||
<Space wrap>
|
||
{errorCount > 0 && (
|
||
<Typography.Text type='danger' size='small'>
|
||
{t('{{count}} 处非法输入', { count: errorCount })}
|
||
</Typography.Text>
|
||
)}
|
||
{dirty && errorCount === 0 && (
|
||
<Typography.Text type='warning' size='small'>
|
||
{t('有未保存的修改')}
|
||
</Typography.Text>
|
||
)}
|
||
<Button onClick={() => setTransferVisible(true)}>
|
||
{t('导入 / 导出')}
|
||
</Button>
|
||
<Button onClick={loadModels} loading={modelsLoading}>
|
||
{t('刷新模型')}
|
||
</Button>
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
loading={saving}
|
||
disabled={!dirty || errorCount > 0 || conflict}
|
||
onClick={onSave}
|
||
>
|
||
{t('保存官方价格')}
|
||
</Button>
|
||
</Space>
|
||
</div>
|
||
|
||
{fillFilter !== 'all' && (
|
||
<div className='flex flex-wrap items-center gap-2 mb-2'>
|
||
<Typography.Text type='tertiary' size='small'>
|
||
{t(
|
||
'筛选结果按进入筛选时的状态固定,编辑中的行不会突然消失;上方计数为实时值。',
|
||
)}
|
||
</Typography.Text>
|
||
{staleCount > 0 && (
|
||
<Button
|
||
size='small'
|
||
theme='borderless'
|
||
icon={<IconRefresh />}
|
||
onClick={() => setSnapshotTick((v) => v + 1)}
|
||
>
|
||
{t('{{count}} 行状态已变化,刷新筛选', { count: staleCount })}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
<Table
|
||
// 列宽合计远超窄屏视口;没有 scroll 时表格会压缩到 min-content 硬塞进去,
|
||
// 末尾的操作列落在视口外,且 iOS 上滚动条不可见、毫无可拖动提示
|
||
scroll={{ x: 'max-content' }}
|
||
columns={columns}
|
||
dataSource={filteredModels}
|
||
rowKey='model_name'
|
||
loading={modelsLoading}
|
||
size='small'
|
||
pagination={{
|
||
currentPage,
|
||
pageSize,
|
||
showSizeChanger: true,
|
||
pageSizeOpts: [10, 20, 50, 100],
|
||
onPageChange: (page) => setCurrentPage(page),
|
||
onPageSizeChange: (size) => {
|
||
setPageSize(size);
|
||
setCurrentPage(1);
|
||
},
|
||
}}
|
||
empty={emptyText}
|
||
/>
|
||
|
||
<Modal
|
||
title={t('导入 / 导出官方价格')}
|
||
visible={transferVisible}
|
||
onCancel={() => setTransferVisible(false)}
|
||
footer={null}
|
||
width={640}
|
||
>
|
||
<div className='flex flex-col gap-3'>
|
||
<div>
|
||
<div className='flex items-center justify-between mb-1'>
|
||
<Typography.Text strong>{t('当前配置')}</Typography.Text>
|
||
<Space>
|
||
<Button
|
||
size='small'
|
||
onClick={async () => {
|
||
if (await copy(exportJSON))
|
||
showSuccess(t('已复制到剪贴板'));
|
||
else showError(t('复制失败,请手动选择文本复制'));
|
||
}}
|
||
>
|
||
{t('复制')}
|
||
</Button>
|
||
<Button size='small' onClick={downloadJSON}>
|
||
{t('下载 JSON')}
|
||
</Button>
|
||
</Space>
|
||
</div>
|
||
<TextArea value={exportJSON} readOnly rows={6} />
|
||
</div>
|
||
<div>
|
||
<Typography.Text strong>{t('批量导入')}</Typography.Text>
|
||
<Typography.Text
|
||
type='tertiary'
|
||
size='small'
|
||
className='block mb-1'
|
||
>
|
||
{t(
|
||
'格式:{"模型名": {"input": 8, "output": 24, "cache_read": 0.8, "cache_creation": 10}, "按次模型": {"per_call": 0.4}, "视频模型": {"per_second": {"1080p": 0.5}}, "图片模型": {"per_image": {"hd": 0.3}}}。cache_read / cache_creation 为选填的缓存原厂价;per_second / per_image 为分档原厂价,键是收入侧的档位键(大小写不敏感)。导入只改动本地编辑态,仍需点击「保存官方价格」。',
|
||
)}
|
||
</Typography.Text>
|
||
<TextArea
|
||
value={importText}
|
||
onChange={(v) => setImportText(v)}
|
||
rows={6}
|
||
placeholder={I18N_TECHNICAL_TEXT.MODEL_PRICE_EXAMPLE}
|
||
/>
|
||
<div className='flex items-center justify-between mt-2'>
|
||
<RadioGroup
|
||
type='button'
|
||
buttonSize='small'
|
||
value={importMode}
|
||
onChange={(e) => setImportMode(e.target.value)}
|
||
>
|
||
<Radio value='merge'>{t('合并(同名覆盖)')}</Radio>
|
||
<Radio value='replace'>{t('整体替换')}</Radio>
|
||
</RadioGroup>
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
disabled={!importText.trim()}
|
||
onClick={onImport}
|
||
>
|
||
{t('校验并导入')}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</Modal>
|
||
</div>
|
||
);
|
||
}
|