Files
monkey-ai-web/src/components/table/model-pricing/market/ModelMarketPage.jsx
T
2026-11-19 10:48:16 +08:00

191 lines
5.7 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
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, { useState } from 'react';
import { Image } from 'antd';
import { useModelPricingData } from '../../../../hooks/model-pricing/useModelPricingData';
import { usePricingFilterCounts } from '../../../../hooks/model-pricing/usePricingFilterCounts';
import { resetPricingFilters } from '../../../../helpers/utils';
import MarketHero from './MarketHero';
import MarketFilterSidebar from './MarketFilterSidebar';
import MarketCatalog from './MarketCatalog';
import ModelDetailSideSheet from '../modal/ModelDetailSideSheet';
import { useMarketThemeStyle } from './marketTheme';
import './market.css';
/**
* 模型超市(/market)页面:组合 Hero 搜索、顶部筛选卡、模型目录与详情抽屉。
* 数据、筛选状态、价格计算、复制与详情开关全部来自原有 useModelPricingData / usePricingFilterCounts,
* 本组件只负责视图编排。
*/
const ModelMarketPage = () => {
const pricingData = useModelPricingData();
// 只控制顶部筛选卡的更多条件,收起时保留已选条件。
const [showSettings, setShowSettings] = useState(false);
const themeStyle = useMarketThemeStyle();
const {
searchValue,
setSearchValue,
handleChange,
filterVendor,
setFilterVendor,
filteredModels,
loading,
selectedGroup,
groupRatio,
groupModelDiscount,
discountScope,
tokenUnit,
displayPrice,
currency,
showRatio,
hidePrice,
t,
copyText,
openModelDetail,
filterTag,
setFilterTag,
filterQuotaType,
setFilterQuotaType,
filterEndpointType,
setFilterEndpointType,
filterGroup,
setFilterGroup,
setCurrentPage,
autoGroups,
endpointMap,
vendorsMap,
showModelDetail,
closeModelDetail,
selectedModel,
usableGroup,
modalImageUrl,
isModalOpenurl,
setIsModalOpenurl,
models,
} = pricingData;
const { quotaTypeModels, endpointTypeModels } = usePricingFilterCounts({
models,
filterGroup,
filterQuotaType,
filterEndpointType,
filterVendor,
filterTag,
searchValue,
});
// 复用原侧栏的 resetPricingFilters:清空搜索词与五类筛选。
// 不传货币 / 单位 / 视图 setter,避免改动页面既有的计价展示口径。
const handleReset = () =>
resetPricingFilters({
handleChange,
setFilterGroup,
setFilterQuotaType,
setFilterEndpointType,
setFilterVendor,
setFilterTag,
setCurrentPage,
});
return (
<div className='mm-page mm-theme' style={themeStyle}>
<MarketHero
searchValue={searchValue}
setSearchValue={setSearchValue}
onReset={handleReset}
t={t}
/>
<div className='mm-workspace'>
<MarketCatalog
filteredModels={filteredModels}
loading={loading}
filterVendor={filterVendor}
discountScope={discountScope}
hidePrice={hidePrice}
tokenUnit={tokenUnit}
selectedGroup={selectedGroup}
groupRatio={groupRatio}
groupModelDiscount={groupModelDiscount}
displayPrice={displayPrice}
currency={currency}
t={t}
copyText={copyText}
openModelDetail={openModelDetail}
onReset={handleReset}
filters={
<MarketFilterSidebar
open={showSettings}
onToggle={() => setShowSettings((open) => !open)}
onReset={handleReset}
t={t}
vendorsMap={vendorsMap}
filterVendor={filterVendor}
setFilterVendor={setFilterVendor}
filterQuotaType={filterQuotaType}
setFilterQuotaType={setFilterQuotaType}
filterEndpointType={filterEndpointType}
setFilterEndpointType={setFilterEndpointType}
endpointMap={endpointMap}
allModels={models}
quotaTypeModels={quotaTypeModels}
endpointTypeModels={endpointTypeModels}
/>
}
/>
</div>
<ModelDetailSideSheet
visible={showModelDetail}
onClose={closeModelDetail}
modelData={selectedModel}
groupRatio={groupRatio}
groupModelDiscount={groupModelDiscount}
usableGroup={usableGroup}
currency={currency}
tokenUnit={tokenUnit}
displayPrice={displayPrice}
showRatio={showRatio}
hidePrice={hidePrice}
vendorsMap={vendorsMap}
endpointMap={endpointMap}
autoGroups={autoGroups}
t={t}
/>
{/* 原图片预览状态(modalImageUrl / isModalOpenurl)保留,改用 Ant Design Image 受控预览 */}
{modalImageUrl && (
<Image
className='hidden'
src={modalImageUrl}
preview={{
open: isModalOpenurl,
src: modalImageUrl,
onOpenChange: (visible) => setIsModalOpenurl(visible),
}}
/>
)}
</div>
);
};
export default ModelMarketPage;