merge: 合入总仓库 weiyuan(bfdfb339) web/ 新功能,保留 ui-optimization 的 UI 重构
来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2
冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { InputNumber } from '@/components/ui';
|
||||
import { SlidersHorizontal } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
OptionGroup,
|
||||
RatioShape,
|
||||
} from '../../../../../components/creation/params';
|
||||
import {
|
||||
clampSizeSide,
|
||||
customSizeRangeOf,
|
||||
parseSize,
|
||||
sizePresetsOf,
|
||||
} from '../../../../../hooks/image/imageCreation';
|
||||
|
||||
const CUSTOM = '__custom__';
|
||||
|
||||
/**
|
||||
* 图像尺寸(schema type = 'size'):预设按宽高比图标展示;仅当 schema 下发 custom_size 时
|
||||
* 提供"自定义",宽高输入框失焦 / 回车时按 min / max / step 吸附。
|
||||
*
|
||||
* props: { param, value: "WxH", onChange(value) }
|
||||
*/
|
||||
const ImageSizePicker = ({ param, value, onChange }) => {
|
||||
const { t } = useTranslation();
|
||||
const presets = useMemo(() => sizePresetsOf(param), [param]);
|
||||
const range = useMemo(() => customSizeRangeOf(param), [param]);
|
||||
const matched = presets.find(
|
||||
(p) => p.value.toLowerCase() === String(value || '').toLowerCase(),
|
||||
);
|
||||
// 用户点了"自定义"、或当前取值不是预设时进入自定义态
|
||||
const [customActive, setCustomActive] = useState(Boolean(range && !matched));
|
||||
useEffect(() => {
|
||||
if (!range) setCustomActive(false);
|
||||
else if (value && !matched) setCustomActive(true);
|
||||
}, [range, value, matched]);
|
||||
|
||||
const parsed = parseSize(String(value || '')) ||
|
||||
(presets[0] && { width: presets[0].width, height: presets[0].height }) || {
|
||||
width: 1024,
|
||||
height: 1024,
|
||||
};
|
||||
const [draft, setDraft] = useState(parsed);
|
||||
useEffect(() => {
|
||||
setDraft(parsed);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [value]);
|
||||
|
||||
const options = useMemo(() => {
|
||||
const list = presets.map((p) => p.value);
|
||||
if (range) list.push(CUSTOM);
|
||||
return list;
|
||||
}, [presets, range]);
|
||||
|
||||
const commit = (next) => {
|
||||
const w = clampSizeSide(next.width, range);
|
||||
const h = clampSizeSide(next.height, range);
|
||||
setDraft({ width: w, height: h });
|
||||
const v = `${w}x${h}`;
|
||||
if (v !== value) onChange && onChange(v);
|
||||
};
|
||||
|
||||
const onSelect = (v) => {
|
||||
if (v === CUSTOM) {
|
||||
setCustomActive(true);
|
||||
commit(draft);
|
||||
return;
|
||||
}
|
||||
setCustomActive(false);
|
||||
onChange && onChange(v);
|
||||
};
|
||||
|
||||
const selected = customActive ? CUSTOM : matched ? matched.value : undefined;
|
||||
|
||||
return (
|
||||
<div className='igf-size'>
|
||||
<OptionGroup
|
||||
variant='ratio'
|
||||
options={options}
|
||||
value={selected}
|
||||
onChange={onSelect}
|
||||
ariaLabel={t('尺寸')}
|
||||
getOptionAriaLabel={(opt) => {
|
||||
if (opt === CUSTOM) return t('自定义尺寸');
|
||||
const p = presets.find((x) => x.value === opt);
|
||||
return p ? `${p.label || ''} ${p.width}×${p.height}`.trim() : opt;
|
||||
}}
|
||||
renderOption={(opt) => {
|
||||
if (opt === CUSTOM) {
|
||||
return (
|
||||
<>
|
||||
<span className='cp-ratio-shape-box' aria-hidden='true'>
|
||||
<SlidersHorizontal size={14} />
|
||||
</span>
|
||||
<span className='cp-option-label'>{t('自定义')}</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
const p = presets.find((x) => x.value === opt);
|
||||
return (
|
||||
<>
|
||||
<RatioShape ratio={`${p.width}:${p.height}`} />
|
||||
<span className='cp-option-label tabular-nums'>
|
||||
{p.label || `${p.width}×${p.height}`}
|
||||
</span>
|
||||
{p.label ? (
|
||||
<span className='igf-size-dims tabular-nums'>
|
||||
{p.width}×{p.height}
|
||||
</span>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{range && customActive ? (
|
||||
<div className='igf-size-custom'>
|
||||
<InputNumber
|
||||
value={draft.width}
|
||||
onChange={(v) => setDraft((d) => ({ ...d, width: v }))}
|
||||
onBlur={() => commit(draft)}
|
||||
onPressEnter={() => commit(draft)}
|
||||
min={range.min}
|
||||
max={range.max}
|
||||
step={range.step}
|
||||
prefix={t('宽')}
|
||||
suffix='px'
|
||||
size='small'
|
||||
aria-label={t('宽度(像素)')}
|
||||
/>
|
||||
<span className='igf-size-x' aria-hidden='true'>
|
||||
×
|
||||
</span>
|
||||
<InputNumber
|
||||
value={draft.height}
|
||||
onChange={(v) => setDraft((d) => ({ ...d, height: v }))}
|
||||
onBlur={() => commit(draft)}
|
||||
onPressEnter={() => commit(draft)}
|
||||
min={range.min}
|
||||
max={range.max}
|
||||
step={range.step}
|
||||
prefix={t('高')}
|
||||
suffix='px'
|
||||
size='small'
|
||||
aria-label={t('高度(像素)')}
|
||||
/>
|
||||
<div className='igf-hint'>
|
||||
{t('宽高范围 {{min}}–{{max}} 像素,按 {{step}} 像素取整', range)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImageSizePicker;
|
||||
Reference in New Issue
Block a user