diff --git a/web/src/pages/admin/components/analytics-panel.tsx b/web/src/pages/admin/components/analytics-panel.tsx index 33e969df0..855e9092f 100644 --- a/web/src/pages/admin/components/analytics-panel.tsx +++ b/web/src/pages/admin/components/analytics-panel.tsx @@ -77,6 +77,7 @@ export default function AnalyticsPanel({ users, channels }: Props) { const [pricingWorkspaceOpen, setPricingWorkspaceOpen] = useState(false); const [pendingPricing, setPendingPricing] = useState(undefined); const [form] = Form.useForm(); + const pricingChannelId = Form.useWatch("channelId", form); const analyticsPageSize = 20; const filters = useMemo( @@ -148,11 +149,13 @@ export default function AnalyticsPanel({ users, channels }: Props) { const pricingModelOptions = useMemo(() => { const names = new Set(); - const sourceChannels = channels.filter((channel) => channel.enabled !== false); + const sourceChannels = channels.filter((channel) => channel.enabled !== false && (!pricingChannelId || channel.id === pricingChannelId)); sourceChannels.forEach((channel) => channel.models?.forEach((name) => names.add(name))); - if (editingPricing?.model) names.add(editingPricing.model); + if (editingPricing?.model && (!pricingChannelId || editingPricing.channelId === pricingChannelId)) { + names.add(editingPricing.model); + } return [...names].sort().map((name) => ({ label: name, value: name })); - }, [channels, editingPricing?.model]); + }, [channels, editingPricing?.channelId, editingPricing?.model, pricingChannelId]); const preparePricingForm = (pricing: ModelPricing | null) => { setEditingPricing(pricing); @@ -188,9 +191,7 @@ export default function AnalyticsPanel({ users, channels }: Props) { const handlePricingValuesChange = (changedValues: Partial, values: PricingFormValues) => { if (Object.prototype.hasOwnProperty.call(changedValues, "channelId")) { - const nextModels = channels - .filter((channel) => channel.enabled !== false && (!values.channelId || channel.id === values.channelId)) - .flatMap((channel) => channel.models || []); + const nextModels = channels.filter((channel) => channel.enabled !== false && (!values.channelId || channel.id === values.channelId)).flatMap((channel) => channel.models || []); if (values.model && !nextModels.includes(values.model)) form.setFieldValue("model", undefined); return; } @@ -642,11 +643,30 @@ export default function AnalyticsPanel({ users, channels }: Props) { /> - setPricingModalOpen(false)} onOk={() => void savePricing()} confirmLoading={savingPricing} okText="保存" cancelText="取消" width={760} zIndex={1200} destroyOnHidden> + setPricingModalOpen(false)} + onOk={() => void savePricing()} + confirmLoading={savingPricing} + okText="保存" + cancelText="取消" + width={760} + zIndex={1200} + destroyOnHidden + >
-