From c8c1d0b65b4559b88625839ee791a6327c7e0d86 Mon Sep 17 00:00:00 2001 From: Meta <9798772@qq.com> Date: Wed, 10 Jun 2026 01:10:09 +0800 Subject: [PATCH] feat(classic): add rankings page with model and vendor leaderboards Add complete rankings feature to web/classic including: - Rankings page with period tabs (today/week/month/year/all) - ModelsSection with VChart history chart and ranked model list - MarketShareSection with vendor share chart and color-coded list - PulseSection showing trending up/down models - Navigation integration and admin settings for rankings module Co-Authored-By: Claude Opus 4.6 (1M context) --- web/classic/src/App.jsx | 31 ++++ .../src/components/layout/PageLayout.jsx | 2 +- .../src/components/rankings/GrowthText.jsx | 15 ++ .../rankings/MarketShareSection.jsx | 151 +++++++++++++++++ .../src/components/rankings/ModelsSection.jsx | 154 ++++++++++++++++++ .../src/components/rankings/PulseSection.jsx | 77 +++++++++ web/classic/src/components/rankings/index.jsx | 53 ++++++ web/classic/src/helpers/lobeIcon.jsx | 60 +++++++ web/classic/src/helpers/rankings.js | 13 ++ web/classic/src/hooks/common/useNavigation.js | 11 ++ .../src/hooks/rankings/useRankingsData.js | 45 +++++ web/classic/src/pages/Rankings/index.jsx | 6 + .../Operation/SettingsHeaderNavModules.jsx | 87 +++++++++- 13 files changed, 702 insertions(+), 3 deletions(-) create mode 100644 web/classic/src/components/rankings/GrowthText.jsx create mode 100644 web/classic/src/components/rankings/MarketShareSection.jsx create mode 100644 web/classic/src/components/rankings/ModelsSection.jsx create mode 100644 web/classic/src/components/rankings/PulseSection.jsx create mode 100644 web/classic/src/components/rankings/index.jsx create mode 100644 web/classic/src/helpers/lobeIcon.jsx create mode 100644 web/classic/src/helpers/rankings.js create mode 100644 web/classic/src/hooks/rankings/useRankingsData.js create mode 100644 web/classic/src/pages/Rankings/index.jsx diff --git a/web/classic/src/App.jsx b/web/classic/src/App.jsx index a5d1ebc00b32..f142ffca19ec 100644 --- a/web/classic/src/App.jsx +++ b/web/classic/src/App.jsx @@ -53,6 +53,7 @@ import SetupCheck from './components/layout/SetupCheck'; const Home = lazy(() => import('./pages/Home')); const Dashboard = lazy(() => import('./pages/Dashboard')); const About = lazy(() => import('./pages/About')); +const Rankings = lazy(() => import('./pages/Rankings')); const UserAgreement = lazy(() => import('./pages/UserAgreement')); const PrivacyPolicy = lazy(() => import('./pages/PrivacyPolicy')); @@ -87,6 +88,20 @@ function App() { return false; // 默认不需要登录 }, [statusState?.status?.HeaderNavModules]); + const rankingsRequireAuth = useMemo(() => { + const headerNavModulesConfig = statusState?.status?.HeaderNavModules; + if (headerNavModulesConfig) { + try { + const modules = JSON.parse(headerNavModulesConfig); + if (typeof modules.rankings === 'boolean') return false; + return modules.rankings?.requireAuth === true; + } catch { + return false; + } + } + return false; + }, [statusState?.status?.HeaderNavModules]); + return ( @@ -334,6 +349,22 @@ function App() { ) } /> + + } key={location.pathname}> + + + + ) : ( + } key={location.pathname}> + + + ) + } + /> { const isConsoleRoute = location.pathname.startsWith('/console'); const showSider = isConsoleRoute && (!isMobile || drawerOpen); - const isFixedLayout = isConsoleRoute || location.pathname === '/pricing'; + const isFixedLayout = isConsoleRoute || location.pathname === '/pricing' || location.pathname === '/rankings'; useEffect(() => { if (isMobile && drawerOpen && collapsed) { diff --git a/web/classic/src/components/rankings/GrowthText.jsx b/web/classic/src/components/rankings/GrowthText.jsx new file mode 100644 index 000000000000..34098a391ace --- /dev/null +++ b/web/classic/src/components/rankings/GrowthText.jsx @@ -0,0 +1,15 @@ +import React from 'react'; + +export default function GrowthText({ value, className = '' }) { + if (!Number.isFinite(value) || value === 0) { + return 0%; + } + const isUp = value > 0; + const color = isUp ? 'var(--semi-color-success)' : 'var(--semi-color-danger)'; + return ( + + {isUp ? '↑' : '↓'} + {Math.abs(value).toFixed(Math.abs(value) >= 100 ? 0 : 1)}% + + ); +} diff --git a/web/classic/src/components/rankings/MarketShareSection.jsx b/web/classic/src/components/rankings/MarketShareSection.jsx new file mode 100644 index 000000000000..d64dd1cb1239 --- /dev/null +++ b/web/classic/src/components/rankings/MarketShareSection.jsx @@ -0,0 +1,151 @@ +import React, { useMemo } from 'react'; +import { Card, Typography } from '@douyinfe/semi-ui'; +import { VChart } from '@visactor/react-vchart'; +import { PieChart } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { formatTokens, formatShare } from '../../helpers/rankings'; + +const { Title, Text } = Typography; +const CHART_CONFIG = { mode: 'desktop-browser' }; + +const VENDOR_COLOURS = { + OpenAI: '#10a37f', Anthropic: '#d97757', Google: '#4285f4', DeepSeek: '#7c5cff', + Alibaba: '#ff9900', xAI: '#1f2937', Meta: '#1877f2', Moonshot: '#ec4899', + Zhipu: '#06b6d4', Mistral: '#ff7000', ByteDance: '#3b82f6', Tencent: '#22c55e', + MiniMax: '#a855f7', Cohere: '#fb923c', Baidu: '#ef4444', Others: '#94a3b8', +}; + +const FALLBACK_PALETTE = ['#0ea5e9','#22c55e','#a855f7','#f97316','#14b8a6','#eab308','#ec4899','#84cc16','#6366f1','#10b981','#f43f5e','#0891b2','#94a3b8']; + +function buildColourMap(names) { + const result = {}; + let fi = 0; + for (const name of names) { + result[name] = VENDOR_COLOURS[name] || FALLBACK_PALETTE[fi++ % FALLBACK_PALETTE.length]; + } + return result; +} + +const PERIOD_DESCRIPTIONS = { + today: '过去24小时各厂商的Token占比', + week: '过去一周各厂商的Token占比', + month: '过去一个月各厂商的Token占比', + year: '过去一年各厂商的Token占比', + all: '所有时间各厂商的Token占比', +}; + +export default function MarketShareSection({ history, rows, period }) { + const { t } = useTranslation(); + + const colourMap = useMemo( + () => buildColourMap((history?.vendors || []).map((v) => v.name)), + [history] + ); + + const orderedPoints = useMemo(() => { + if (!history?.points) return []; + const order = new Map(history.vendors.map((v, idx) => [v.name, idx])); + return [...history.points].sort((a, b) => { + const tsCmp = a.ts.localeCompare(b.ts); + if (tsCmp !== 0) return tsCmp; + return (order.get(a.vendor) ?? 999) - (order.get(b.vendor) ?? 999); + }); + }, [history]); + + const spec = useMemo(() => { + if (orderedPoints.length === 0) return null; + return { + type: 'bar', + data: [{ id: 'vendor-share', values: orderedPoints }], + xField: 'label', + yField: 'share', + seriesField: 'vendor', + stack: true, + legends: { visible: false }, + color: { specified: colourMap }, + axes: [ + { orient: 'bottom', label: { autoHide: true, autoLimit: true }, tick: { visible: false } }, + { + orient: 'left', min: 0, max: 1, + label: { formatMethod: (val) => `${Math.round(Number(val) * 100)}%` }, + grid: { visible: true, style: { lineDash: [3, 3] } }, + }, + ], + tooltip: { + dimension: { + title: { value: (datum) => String(datum?.label ?? '') }, + content: [{ key: (datum) => String(datum?.vendor ?? ''), value: (datum) => Number(datum?.share) || 0 }], + updateContent: (array) => + array.filter((item) => Number(item.value) > 0.001) + .sort((a, b) => Number(b.value) - Number(a.value)) + .map((item) => ({ key: item.key, value: `${(Number(item.value) * 100).toFixed(1)}%` })), + }, + }, + animationAppear: { duration: 500 }, + }; + }, [colourMap, orderedPoints]); + + const visible = rows.slice(0, 12); + const half = Math.ceil(visible.length / 2); + const left = visible.slice(0, half); + const right = visible.slice(half); + + return ( + +
+ + <PieChart size={16} className='text-semi-color-primary' /> + {t('市场份额')} + + {t(PERIOD_DESCRIPTIONS[period])} +
+ +
+ {spec ? ( + + ) : ( +
+ {t('暂无历史数据')} +
+ )} +
+ +
+ {t('按厂商')} + {t('按总Token量排序的厂商')} + + {visible.length === 0 ? ( +
+ {t('暂无数据')} +
+ ) : ( +
+ + {right.length > 0 && } +
+ )} +
+
+ ); +} + +function VendorList({ rows, colourMap }) { + return ( +
    + {rows.map((vendor) => ( +
  • + {vendor.rank} + + {vendor.vendor} +
    +
    {formatTokens(vendor.total_tokens)}
    +
    {formatShare(vendor.share)}
    +
    +
  • + ))} +
+ ); +} diff --git a/web/classic/src/components/rankings/ModelsSection.jsx b/web/classic/src/components/rankings/ModelsSection.jsx new file mode 100644 index 000000000000..fef045a511cf --- /dev/null +++ b/web/classic/src/components/rankings/ModelsSection.jsx @@ -0,0 +1,154 @@ +import React, { useMemo } from 'react'; +import { Card, Typography } from '@douyinfe/semi-ui'; +import { VChart } from '@visactor/react-vchart'; +import { BarChart3, Trophy } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { formatTokens } from '../../helpers/rankings'; +import { getLobeIcon } from '../../helpers/lobeIcon'; +import GrowthText from './GrowthText'; + +const { Title, Text } = Typography; +const CHART_CONFIG = { mode: 'desktop-browser' }; + +const PERIOD_DESCRIPTIONS = { + today: '过去24小时各模型的Token使用量', + week: '过去一周各模型的Token使用量', + month: '过去一个月各模型的每日Token使用量', + year: '过去一年各模型的每周Token使用量', + all: '所有时间各模型的Token使用量', +}; + +export default function ModelsSection({ history, rows, period }) { + const { t } = useTranslation(); + + const orderedPoints = useMemo(() => { + if (!history?.points) return []; + const order = new Map(history.models.map((m, idx) => [m.name, idx])); + return [...history.points].sort((a, b) => { + const tsCmp = a.ts.localeCompare(b.ts); + if (tsCmp !== 0) return tsCmp; + return (order.get(a.model) ?? 999) - (order.get(b.model) ?? 999); + }); + }, [history]); + + const totalTokens = useMemo( + () => rows.reduce((s, r) => s + r.total_tokens, 0), + [rows] + ); + + const spec = useMemo(() => { + if (orderedPoints.length === 0) return null; + return { + type: 'bar', + data: [{ id: 'models-history', values: orderedPoints }], + xField: 'label', + yField: 'tokens', + seriesField: 'model', + stack: true, + legends: { visible: false }, + axes: [ + { orient: 'bottom', label: { autoHide: true, autoLimit: true }, tick: { visible: false } }, + { + orient: 'left', + label: { formatMethod: (val) => formatTokens(Number(val)) }, + grid: { visible: true, style: { lineDash: [3, 3] } }, + }, + ], + tooltip: { + dimension: { + title: { value: (datum) => String(datum?.label ?? '') }, + content: [{ key: (datum) => String(datum?.model ?? ''), value: (datum) => Number(datum?.tokens) || 0 }], + updateContent: (array) => { + array.sort((a, b) => Number(b.value) - Number(a.value)); + const sum = array.reduce((s, x) => s + (Number(x.value) || 0), 0); + const visible = array.slice(0, 10); + const overflow = array.slice(10); + const result = visible.map((item) => ({ key: item.key, value: formatTokens(Number(item.value) || 0) })); + if (overflow.length > 0) { + const otherSum = overflow.reduce((s, item) => s + (Number(item.value) || 0), 0); + result.push({ key: `+${overflow.length} more`, value: formatTokens(otherSum) }); + } + result.unshift({ key: t('合计'), value: formatTokens(sum) }); + return result; + }, + }, + }, + animationAppear: { duration: 500 }, + }; + }, [orderedPoints, t]); + + const half = Math.ceil(rows.length / 2); + const leftRows = rows.slice(0, half); + const rightRows = rows.slice(half); + + return ( + +
+
+ + <BarChart3 size={16} className='text-semi-color-primary' /> + {t('热门模型')} + + {t(PERIOD_DESCRIPTIONS[period])} +
+
+ {formatTokens(totalTokens)} + tokens +
+
+ +
+ {spec ? ( + + ) : ( +
+ {t('暂无历史数据')} +
+ )} +
+ +
+ + <Trophy size={14} style={{ color: '#eab308' }} /> + {t('模型排行')} + + {t('平台上最受欢迎的模型')} + + {rows.length === 0 ? ( +
+ {t('暂无数据')} +
+ ) : ( +
+ + {rightRows.length > 0 && } +
+ )} +
+
+ ); +} + +function ModelList({ rows }) { + return ( +
    + {rows.map((row) => ( +
  • + {row.rank} + {getLobeIcon(row.vendor_icon, 22)} +
    +
    {row.model_name}
    +
    {row.vendor.toLowerCase()}
    +
    +
    +
    {formatTokens(row.total_tokens)}
    + +
    +
  • + ))} +
+ ); +} diff --git a/web/classic/src/components/rankings/PulseSection.jsx b/web/classic/src/components/rankings/PulseSection.jsx new file mode 100644 index 000000000000..d542481b9ca7 --- /dev/null +++ b/web/classic/src/components/rankings/PulseSection.jsx @@ -0,0 +1,77 @@ +import React from 'react'; +import { Card, Typography } from '@douyinfe/semi-ui'; +import { TrendingUp, TrendingDown, ArrowUpRight, ArrowDownRight } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; + +const { Title, Text } = Typography; + +export default function PulseSection({ movers, droppers }) { + const { t } = useTranslation(); + + return ( +
+ + + <TrendingUp size={14} style={{ color: 'var(--semi-color-success)' }} /> + {t('上升趋势')} + + {t('排名上升最快的模型')} +
+ {movers.length === 0 ? ( +
+ {t('暂无上升模型')} +
+ ) : ( +
    + {movers.map((row) => ( + + ))} +
+ )} +
+
+ + + + <TrendingDown size={14} style={{ color: 'var(--semi-color-danger)' }} /> + {t('下降趋势')} + + {t('排名下降最多的模型')} +
+ {droppers.length === 0 ? ( +
+ {t('暂无下降模型')} +
+ ) : ( +
    + {droppers.map((row) => ( + + ))} +
+ )} +
+
+
+ ); +} + +function MoverRow({ row, intent }) { + const color = intent === 'up' ? 'var(--semi-color-success)' : 'var(--semi-color-danger)'; + + return ( +
  • +
    + {intent === 'up' ? : } +
    +
    +
    {row.model_name}
    +
    + #{row.current_rank} · {row.vendor.toLowerCase()} +
    +
    + + {intent === 'up' ? '+' : ''}{row.rank_delta} + +
  • + ); +} diff --git a/web/classic/src/components/rankings/index.jsx b/web/classic/src/components/rankings/index.jsx new file mode 100644 index 000000000000..ddeaac607375 --- /dev/null +++ b/web/classic/src/components/rankings/index.jsx @@ -0,0 +1,53 @@ +import React from 'react'; +import { Spin, Tabs, TabPane, Empty } from '@douyinfe/semi-ui'; +import { useTranslation } from 'react-i18next'; +import { useRankingsData } from '../../hooks/rankings/useRankingsData'; +import ModelsSection from './ModelsSection'; +import MarketShareSection from './MarketShareSection'; +import PulseSection from './PulseSection'; + +const PERIODS = [ + { key: 'today', label: '今天' }, + { key: 'week', label: '本周' }, + { key: 'month', label: '本月' }, + { key: 'year', label: '本年' }, + { key: 'all', label: '全部' }, +]; + +export default function RankingsPage() { + const { t } = useTranslation(); + const { period, changePeriod, snapshot, loading, error } = useRankingsData('week'); + + return ( +
    +
    +

    + {t('排行榜')} +

    +

    + {t('发现平台上最受欢迎的模型和厂商,数据来自实时使用统计。')} +

    +
    + + + {PERIODS.map((p) => ( + + ))} + + + {loading ? ( +
    + +
    + ) : error ? ( + + ) : snapshot ? ( +
    + + + +
    + ) : null} +
    + ); +} diff --git a/web/classic/src/helpers/lobeIcon.jsx b/web/classic/src/helpers/lobeIcon.jsx new file mode 100644 index 000000000000..578ad9f71023 --- /dev/null +++ b/web/classic/src/helpers/lobeIcon.jsx @@ -0,0 +1,60 @@ +import React from 'react'; +import * as LobeIcons from '@lobehub/icons'; + +function parseValue(raw) { + if (raw == null) return true; + let v = String(raw).trim(); + if (v.startsWith('{') && v.endsWith('}')) v = v.slice(1, -1).trim(); + if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) return v.slice(1, -1); + if (v === 'true') return true; + if (v === 'false') return false; + if (/^-?\d+(?:\.\d+)?$/.test(v)) return Number(v); + return v; +} + +export function getLobeIcon(iconName, size = 20) { + if (!iconName || typeof iconName !== 'string' || !iconName.trim()) { + return ( +
    + {iconName ? iconName.charAt(0).toUpperCase() : '?'} +
    + ); + } + + const segments = iconName.trim().split('.'); + const baseKey = segments[0]; + const BaseIcon = LobeIcons[baseKey]; + + let IconComponent; + let propStartIndex; + + if (BaseIcon && segments.length > 1 && BaseIcon[segments[1]]) { + IconComponent = BaseIcon[segments[1]]; + propStartIndex = 2; + } else { + IconComponent = LobeIcons[baseKey]; + propStartIndex = segments.length > 1 && /^[A-Z]/.test(segments[1]) ? 2 : 1; + } + + if (!IconComponent || (typeof IconComponent !== 'function' && typeof IconComponent !== 'object')) { + return ( +
    + {baseKey.charAt(0).toUpperCase()} +
    + ); + } + + const props = {}; + for (let i = propStartIndex; i < segments.length; i++) { + const seg = segments[i]; + if (!seg) continue; + const eqIdx = seg.indexOf('='); + if (eqIdx === -1) { props[seg.trim()] = true; continue; } + props[seg.slice(0, eqIdx).trim()] = parseValue(seg.slice(eqIdx + 1).trim()); + } + if (props.size == null) props.size = size; + + return ; +} diff --git a/web/classic/src/helpers/rankings.js b/web/classic/src/helpers/rankings.js new file mode 100644 index 000000000000..3a6b01f85d3d --- /dev/null +++ b/web/classic/src/helpers/rankings.js @@ -0,0 +1,13 @@ +export function formatTokens(value) { + if (!Number.isFinite(value) || value === 0) return '0'; + const abs = Math.abs(value); + if (abs >= 1e9) return `${(value / 1e9).toFixed(2)}B`; + if (abs >= 1e6) return `${(value / 1e6).toFixed(abs >= 1e8 ? 0 : abs >= 1e7 ? 1 : 2)}M`; + if (abs >= 1e3) return `${(value / 1e3).toFixed(abs >= 1e5 ? 0 : 1)}K`; + return String(Math.round(value)); +} + +export function formatShare(share) { + if (!Number.isFinite(share)) return '0%'; + return `${(share * 100).toFixed(1)}%`; +} diff --git a/web/classic/src/hooks/common/useNavigation.js b/web/classic/src/hooks/common/useNavigation.js index f7e61a203a8e..de3cb0238544 100644 --- a/web/classic/src/hooks/common/useNavigation.js +++ b/web/classic/src/hooks/common/useNavigation.js @@ -26,6 +26,7 @@ export const useNavigation = (t, docsLink, headerNavModules) => { home: true, console: true, pricing: true, + rankings: true, docs: true, about: true, }; @@ -49,6 +50,11 @@ export const useNavigation = (t, docsLink, headerNavModules) => { itemKey: 'pricing', to: '/pricing', }, + { + text: t('排行榜'), + itemKey: 'rankings', + to: '/rankings', + }, ...(docsLink ? [ { @@ -77,6 +83,11 @@ export const useNavigation = (t, docsLink, headerNavModules) => { ? modules.pricing.enabled : modules.pricing; } + if (link.itemKey === 'rankings') { + return typeof modules.rankings === 'object' + ? modules.rankings.enabled + : modules.rankings; + } return modules[link.itemKey] === true; }); }, [t, docsLink, headerNavModules]); diff --git a/web/classic/src/hooks/rankings/useRankingsData.js b/web/classic/src/hooks/rankings/useRankingsData.js new file mode 100644 index 000000000000..c9ff281e9d79 --- /dev/null +++ b/web/classic/src/hooks/rankings/useRankingsData.js @@ -0,0 +1,45 @@ +import { useState, useEffect, useCallback } from 'react'; +import { API } from '../../helpers/api'; +import { showError } from '../../helpers/utils'; + +const VALID_PERIODS = ['today', 'week', 'month', 'year', 'all']; + +export function useRankingsData(initialPeriod = 'week') { + const [period, setPeriod] = useState( + VALID_PERIODS.includes(initialPeriod) ? initialPeriod : 'week' + ); + const [snapshot, setSnapshot] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + const fetchRankings = useCallback(async (p) => { + setLoading(true); + setError(null); + try { + const res = await API.get('/api/rankings', { params: { period: p } }); + const { success, message, data } = res.data; + if (success) { + setSnapshot(data); + } else { + setError(message); + showError(message); + } + } catch (err) { + const msg = err?.response?.data?.message || err.message; + setError(msg); + showError(msg); + } finally { + setLoading(false); + } + }, []); + + useEffect(() => { + fetchRankings(period); + }, [period, fetchRankings]); + + const changePeriod = useCallback((p) => { + if (VALID_PERIODS.includes(p)) setPeriod(p); + }, []); + + return { period, changePeriod, snapshot, loading, error }; +} diff --git a/web/classic/src/pages/Rankings/index.jsx b/web/classic/src/pages/Rankings/index.jsx new file mode 100644 index 000000000000..747eb9f9176d --- /dev/null +++ b/web/classic/src/pages/Rankings/index.jsx @@ -0,0 +1,6 @@ +import React from 'react'; +import RankingsPage from '../../components/rankings'; + +export default function Rankings() { + return ; +} diff --git a/web/classic/src/pages/Setting/Operation/SettingsHeaderNavModules.jsx b/web/classic/src/pages/Setting/Operation/SettingsHeaderNavModules.jsx index 19943c1a8aa6..cd074a8c8d90 100644 --- a/web/classic/src/pages/Setting/Operation/SettingsHeaderNavModules.jsx +++ b/web/classic/src/pages/Setting/Operation/SettingsHeaderNavModules.jsx @@ -46,6 +46,10 @@ export default function SettingsHeaderNavModules(props) { enabled: true, requireAuth: false, // 默认不需要登录鉴权 }, + rankings: { + enabled: true, + requireAuth: false, + }, docs: true, about: true, }); @@ -54,7 +58,7 @@ export default function SettingsHeaderNavModules(props) { function handleHeaderNavModuleChange(moduleKey) { return (checked) => { const newModules = { ...headerNavModules }; - if (moduleKey === 'pricing') { + if (moduleKey === 'pricing' || moduleKey === 'rankings') { // 对于pricing模块,只更新enabled属性 newModules[moduleKey] = { ...newModules[moduleKey], @@ -77,6 +81,15 @@ export default function SettingsHeaderNavModules(props) { setHeaderNavModules(newModules); } + function handleRankingsAuthChange(checked) { + const newModules = { ...headerNavModules }; + newModules.rankings = { + ...newModules.rankings, + requireAuth: checked, + }; + setHeaderNavModules(newModules); + } + // 重置顶栏模块为默认配置 function resetHeaderNavModules() { const defaultModules = { @@ -86,6 +99,10 @@ export default function SettingsHeaderNavModules(props) { enabled: true, requireAuth: false, }, + rankings: { + enabled: true, + requireAuth: false, + }, docs: true, about: true, }; @@ -142,6 +159,12 @@ export default function SettingsHeaderNavModules(props) { }; } + if (typeof modules.rankings === 'boolean') { + modules.rankings = { enabled: modules.rankings, requireAuth: false }; + } else if (modules.rankings === undefined) { + modules.rankings = { enabled: true, requireAuth: false }; + } + setHeaderNavModules(modules); } catch (error) { // 使用默认配置 @@ -178,6 +201,12 @@ export default function SettingsHeaderNavModules(props) { description: t('模型定价,需要登录访问'), hasSubConfig: true, // 标识该模块有子配置 }, + { + key: 'rankings', + title: t('排行榜'), + description: t('模型和厂商使用排行'), + hasSubConfig: true, + }, { key: 'docs', title: t('文档'), @@ -245,7 +274,7 @@ export default function SettingsHeaderNavModules(props) {
    )} + + {/* 为排行榜添加权限控制子开关 */} + {module.key === 'rankings' && + headerNavModules.rankings?.enabled && ( +
    +
    +
    +
    + {t('需要登录访问')} +
    + + {t('开启后未登录用户无法访问排行榜')} + +
    +
    + +
    +
    +
    + )} ))}