fix(ui): 修复固定列表头并优化官网指标配置

This commit is contained in:
zhanjunhao
2026-11-17 17:47:57 +08:00
parent 92380ebab6
commit dfa5c1edd6
28 changed files with 351 additions and 108 deletions
+54 -16
View File
@@ -51,31 +51,35 @@ export const TABS = [
},
];
// Metric fields store plain numbers; the official site renders "+", "%", "万/亿" itself.
// kind: integer = positive integer, amount = positive number + 万/亿 unit, percent = 0~100.
export const FIELDS = {
paidCustomers: {
label: '付费企业客户',
placeholder: '请输入付费企业客户数量,例如 300+',
help: '正整数,可带 +。',
placeholder: '请输入付费企业客户数量,例如 300',
metric: { kind: 'integer', suffix: '+' },
},
dailyTokens: {
label: '平台日均 Token 调用',
placeholder: '请输入平台日均 Token 调用量,例如 500亿+',
help: '支持正数及万、亿单位,可带 +。',
placeholder: '请输入调用量,例如 500',
metric: { kind: 'amount', suffix: '+' },
},
costReduction: {
label: '客户月度 AI 调用成本',
placeholder: '请输入成本降幅,例如 20%',
help: '填写 0~100 的百分比,官网可展示为 ↓20%。',
note: '降幅',
placeholder: '请输入成本降幅,例如 20',
metric: { kind: 'percent', suffix: '%', prefix: '↓' },
},
teamMembers: {
label: '团队成员',
placeholder: '请输入团队成员数量,例如 50+',
help: '首页与关于微词元共用此字段,正整数,可带 +。',
note: '首页与关于微词元共用',
placeholder: '请输入团队成员数量,例如 50',
metric: { kind: 'integer', suffix: '+' },
},
researchRatio: {
label: '研发人员占比',
placeholder: '请输入研发人员占比,例如 60%',
help: '填写 0~100 的百分比。',
placeholder: '请输入研发人员占比,例如 60',
metric: { kind: 'percent', suffix: '%' },
},
headquarters: {
label: '总部',
@@ -125,6 +129,39 @@ export function isAbsoluteImageUrl(value) {
}
}
export const AMOUNT_UNITS = ['万', '亿'];
export const DEFAULT_AMOUNT_UNIT = '亿';
// Typed or pasted numbers: full-width digits / dots become half-width, everything else is dropped.
export function sanitizeMetricInput(value) {
return String(value ?? '')
.replace(/[0-9]/g, (char) =>
String.fromCharCode(char.charCodeAt(0) - 0xfee0),
)
.replace(/[.。]/g, '.')
.replace(/[^\d.]/g, '');
}
// "500亿" -> { number: '500', unit: '亿' }; values without a unit keep the default unit.
export function splitAmount(value) {
const text = String(value ?? '').trim();
const unit = AMOUNT_UNITS.find((item) => text.endsWith(item));
return {
number: unit ? text.slice(0, -unit.length) : text,
unit: unit || DEFAULT_AMOUNT_UNIT,
};
}
export const joinAmount = (number, unit) => (number ? `${number}${unit}` : '');
// Text shown under a metric input, matching how the official site renders the value.
export function metricPreview(key, value) {
const metric = FIELDS[key]?.metric;
if (!metric || validateField(key, value)) return '';
const text = String(value).trim();
return `${metric.prefix || ''}${text}${metric.suffix}`;
}
export function validateField(key, rawValue) {
if (key === 'insights') return validateInsights(rawValue);
const value = String(rawValue ?? '').trim();
@@ -134,19 +171,20 @@ export function validateField(key, rawValue) {
: `请输入${FIELDS[key].label}`;
if (
['paidCustomers', 'teamMembers'].includes(key) &&
!/^[1-9]\d*\+?$/.test(value)
!/^[1-9]\d*$/.test(value)
)
return '请输入正整数,可在末尾添加 +';
return '请输入大于 0 的整数';
if (
key === 'dailyTokens' &&
(!/^\d+(?:\.\d+)?[万亿]?\+?$/.test(value) || parseFloat(value) <= 0)
(!/^(?:0|[1-9]\d*)(?:\.\d{1,2})?[万亿]$/.test(value) ||
parseFloat(value) <= 0)
)
return '请输入大于 0 的调用量,例如 500亿+';
return '请输入大于 0 的数字,最多两位小数';
if (
['costReduction', 'researchRatio'].includes(key) &&
(!/^\d+(?:\.\d{1,2})?%?$/.test(value) || parseFloat(value) > 100)
(!/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/.test(value) || parseFloat(value) > 100)
)
return '请输入 0~100 的百分比,最多两位小数';
return '请输入 0~100 之间的数字,最多两位小数';
if (key === 'businessPhone' && !PHONE.test(value))
return '请输入有效的手机号、固定电话或 400 电话';
if (