fix(ui): 修复固定列表头并优化官网指标配置
This commit is contained in:
@@ -123,10 +123,10 @@ html.dark .km-page {
|
||||
|
||||
/* 表格:表头 46px、底色 #f8f9fc、常规字重;行分隔 #f0f0f0(middle 尺寸 12px 8px) */
|
||||
.km-table .ant-table-thead > tr > th {
|
||||
--center-table-head-bg: var(--km-head-bg);
|
||||
height: 46px;
|
||||
padding-block: 0;
|
||||
border-bottom-color: var(--km-row-split);
|
||||
background: var(--km-head-bg);
|
||||
color: var(--km-head-text);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
@@ -180,10 +180,10 @@ html.dark .usage-record-tabs .ant-tabs-ink-bar {
|
||||
margin: 0;
|
||||
}
|
||||
.usage-record-table .ant-table-thead > tr > th {
|
||||
--center-table-head-bg: var(--ur-head-bg);
|
||||
height: 46px;
|
||||
padding-block: 0;
|
||||
border-bottom-color: var(--ur-row-split);
|
||||
background: var(--ur-head-bg);
|
||||
color: var(--ur-head-text);
|
||||
font-weight: 400;
|
||||
}
|
||||
@@ -217,7 +217,6 @@ html.dark .usage-record-consume-card {
|
||||
> th {
|
||||
padding-block: 0;
|
||||
padding-inline: 8px;
|
||||
background: var(--ur-head-bg);
|
||||
color: var(--ur-head-text);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,15 @@ teamMembers/researchRatio 映射 about.teamMembers/researchStaffRatio;首页
|
||||
其余总部、服务网络和商务字段依联调文档映射。保存保留后端返回的未知字段。
|
||||
|
||||
严格检查 success === true 后才提示成功,失败保留当前编辑。提交期间防止重复请求。
|
||||
完整配置按 UTF-8 字节限制为 60 KiB,超限时提示精简内容。
|
||||
客户数和人数支持正整数及末尾 +;Token 支持正数、万/亿单位及末尾 +。
|
||||
百分比支持 0~100,最多两位小数,% 可选。上述展示值以字符串提交。
|
||||
后端以 LONGTEXT 存储完整配置,前端不再限制总大小;单篇正文由编辑器限制为 20000 字。
|
||||
|
||||
指标字段只填数字,单位由官网展示(后台输入框右侧灰字同步显示,下方实时预览“官网展示”):
|
||||
|
||||
- 付费企业客户、团队成员:大于 0 的整数,不含前导零,存 "300",官网显示 300+。
|
||||
- 平台日均 Token 调用:大于 0、最多两位小数的数字 + 下拉单位(万/亿,默认亿),合成存 "500亿",官网显示 500亿+。
|
||||
- 客户月度 AI 调用成本(降幅)、研发人员占比:0~100、最多两位小数,存 "20",官网显示 ↓20% / 60%。
|
||||
|
||||
输入时全角数字与句号自动转半角,其他字符直接丢弃。官网尚未对接,不兼容带 + / % 的旧值。
|
||||
|
||||
## 二维码上传
|
||||
|
||||
|
||||
@@ -17,10 +17,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Select as AntSelect, Space } from 'antd';
|
||||
import { Form, Input } from '@/components/ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { FIELDS } from './model';
|
||||
import {
|
||||
AMOUNT_UNITS,
|
||||
FIELDS,
|
||||
joinAmount,
|
||||
metricPreview,
|
||||
sanitizeMetricInput,
|
||||
splitAmount,
|
||||
} from './model';
|
||||
|
||||
export default function WebsiteField({
|
||||
name,
|
||||
@@ -29,18 +37,43 @@ export default function WebsiteField({
|
||||
onChange,
|
||||
onBlur,
|
||||
disabled,
|
||||
labelSuffix,
|
||||
preview,
|
||||
children,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const field = FIELDS[name];
|
||||
const metric = field.metric;
|
||||
const amount = metric?.kind === 'amount' ? splitAmount(value) : null;
|
||||
// Keep the chosen unit while the number is still empty (the stored value is '' then).
|
||||
const [pendingUnit, setPendingUnit] = useState(amount?.unit);
|
||||
const unit = amount?.number ? amount.unit : pendingUnit;
|
||||
const previewText = preview ?? metricPreview(name, value);
|
||||
const inputProps = {
|
||||
id: `website-${name}`,
|
||||
'aria-label': t(field.label),
|
||||
'aria-required': true,
|
||||
'aria-invalid': Boolean(error),
|
||||
'aria-describedby': error ? `website-${name}-error` : undefined,
|
||||
onBlur,
|
||||
disabled,
|
||||
placeholder: t(field.placeholder),
|
||||
validateStatus: error ? 'error' : 'default',
|
||||
showClear: true,
|
||||
};
|
||||
const unitAddon = metric ? (
|
||||
<Space.Addon className='website-metric-unit' aria-hidden='true'>
|
||||
{metric.suffix}
|
||||
</Space.Addon>
|
||||
) : null;
|
||||
return (
|
||||
<Form.Slot
|
||||
label={{
|
||||
text: (
|
||||
<>
|
||||
{t(field.label)}
|
||||
{labelSuffix}
|
||||
{field.note ? (
|
||||
<span className='website-field-note'>({t(field.note)})</span>
|
||||
) : null}
|
||||
</>
|
||||
),
|
||||
required: true,
|
||||
@@ -50,24 +83,56 @@ export default function WebsiteField({
|
||||
error: error ? t(error) : undefined,
|
||||
errorMessageId: `website-${name}-error`,
|
||||
}}
|
||||
extra={
|
||||
metric ? (
|
||||
<span className='website-metric-preview' aria-live='polite'>
|
||||
{previewText
|
||||
? t('官网展示:{{value}}', { value: previewText })
|
||||
: ''}
|
||||
</span>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
{children || (
|
||||
<Input
|
||||
id={`website-${name}`}
|
||||
aria-label={t(field.label)}
|
||||
aria-required={true}
|
||||
aria-invalid={Boolean(error)}
|
||||
aria-describedby={error ? `website-${name}-error` : undefined}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
onBlur={onBlur}
|
||||
disabled={disabled}
|
||||
placeholder={t(field.placeholder)}
|
||||
validateStatus={error ? 'error' : 'default'}
|
||||
maxLength={name === 'businessEmail' ? 254 : 200}
|
||||
showClear
|
||||
/>
|
||||
)}
|
||||
{children ||
|
||||
(metric ? (
|
||||
<Space.Compact block>
|
||||
<Input
|
||||
{...inputProps}
|
||||
inputMode={metric.kind === 'integer' ? 'numeric' : 'decimal'}
|
||||
value={amount ? amount.number : value}
|
||||
maxLength={12}
|
||||
onChange={(next) => {
|
||||
const number = sanitizeMetricInput(next);
|
||||
onChange(amount ? joinAmount(number, unit) : number);
|
||||
}}
|
||||
/>
|
||||
{amount ? (
|
||||
<AntSelect
|
||||
className='website-metric-unit-select'
|
||||
aria-label={t('计量单位')}
|
||||
value={unit}
|
||||
disabled={disabled}
|
||||
status={error ? 'error' : undefined}
|
||||
options={AMOUNT_UNITS.map((item) => ({
|
||||
value: item,
|
||||
label: item,
|
||||
}))}
|
||||
onChange={(next) => {
|
||||
setPendingUnit(next);
|
||||
if (amount.number) onChange(joinAmount(amount.number, next));
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{unitAddon}
|
||||
</Space.Compact>
|
||||
) : (
|
||||
<Input
|
||||
{...inputProps}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
maxLength={name === 'businessEmail' ? 254 : 200}
|
||||
/>
|
||||
))}
|
||||
</Form.Slot>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,8 +47,27 @@
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.website-settings-page .website-research-ratio-hint {
|
||||
opacity: 0.9;
|
||||
.website-settings-page .website-field-note {
|
||||
color: var(--ui-color-text-2);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.website-settings-page .website-metric-unit {
|
||||
min-width: 40px;
|
||||
justify-content: center;
|
||||
color: var(--ui-color-text-2);
|
||||
}
|
||||
|
||||
.website-settings-page .website-metric-unit-select {
|
||||
width: 72px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.website-settings-page .website-metric-preview {
|
||||
display: block;
|
||||
min-height: 22px;
|
||||
color: var(--ui-color-text-2);
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.website-settings-page .website-settings-tab-description {
|
||||
|
||||
@@ -32,6 +32,7 @@ import { showError, showSuccess, showWarning } from '../../helpers';
|
||||
import {
|
||||
TABS,
|
||||
emptySettings,
|
||||
metricPreview,
|
||||
settingsFromConfig,
|
||||
serializeSettings,
|
||||
validateField,
|
||||
@@ -91,6 +92,17 @@ export default function WebsiteSettings() {
|
||||
}, [dirty]);
|
||||
const tab = TABS.find((item) => item.key === activeTab);
|
||||
|
||||
// Home team card on the official site: "50+ · 研发占比60%" (ratio is edited in the about tab).
|
||||
const teamPreview = () => {
|
||||
const team = metricPreview('teamMembers', values.teamMembers);
|
||||
if (!team) return '';
|
||||
const ratio = metricPreview('researchRatio', values.researchRatio);
|
||||
return t('{{team}} · 研发占比 {{ratio}}', {
|
||||
team,
|
||||
ratio: ratio || t('未配置'),
|
||||
});
|
||||
};
|
||||
|
||||
const change = (name, value) => {
|
||||
setDirty(true);
|
||||
setValues((previous) => ({ ...previous, [name]: value }));
|
||||
@@ -209,13 +221,10 @@ export default function WebsiteSettings() {
|
||||
>
|
||||
<WebsiteField
|
||||
name={name}
|
||||
labelSuffix={
|
||||
activeTab === 'home' && name === 'teamMembers' ? (
|
||||
<span className='website-research-ratio-hint'>
|
||||
({t('研发人员占比')}:
|
||||
{values.researchRatio || t('未配置')})
|
||||
</span>
|
||||
) : undefined
|
||||
preview={
|
||||
activeTab === 'home' && name === 'teamMembers'
|
||||
? teamPreview()
|
||||
: undefined
|
||||
}
|
||||
value={values[name]}
|
||||
error={errors[name]}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -87,8 +87,7 @@ export async function saveWebsiteSettings(configurationJson) {
|
||||
}
|
||||
}
|
||||
configurationJson = JSON.stringify(payload);
|
||||
if (new TextEncoder().encode(configurationJson).byteLength > 60 * 1024)
|
||||
throw new Error('官网配置不能超过 60 KiB,请精简内容或减少图片');
|
||||
// Backend stores config as LONGTEXT; article bodies are capped at ARTICLE_BODY_LIMIT in the editor.
|
||||
await requestWebsite(
|
||||
'post',
|
||||
'/api/website/page-config',
|
||||
|
||||
Reference in New Issue
Block a user