import React from 'react'; import {debounce} from 'lodash'; import {Button, Col, ColorPicker, Divider, Drawer, InputNumber, Row, Select, Switch, theme, Tooltip} from 'antd'; import useGlobalStore from "@/stores/global"; import {configTheme, darkColorTheme, defaultColorTheme} from "@/layout/theme.ts"; import {algorithmOptions} from "@/layout/algorithm.ts"; import {useTranslation} from 'react-i18next'; const {useToken} = theme; // 主题配置项 const THEME_CONFIGS = [ {key: 'colorPrimary', label: 'layout.colorPrimary'}, {key: 'colorText', label: 'layout.colorText'}, {key: 'colorBg', label: 'layout.colorBg'}, {key: 'colorSuccess', label: 'layout.colorSuccess'}, {key: 'colorWarning', label: 'layout.colorWarning'}, {key: 'colorError', label: 'layout.colorError'}, {key: 'bodyBg', label: 'layout.bodyBg'}, {key: 'footerBg', label: 'layout.footerBg'}, {key: 'headerBg', label: 'layout.headerBg'}, {key: 'headerColor', label: 'layout.headerColor'}, {key: 'siderBg', label: 'layout.siderBg'}, {key: 'siderColor', label: 'layout.siderColor'}, {key: 'colorBorder', label: 'layout.colorBorder'}, ]; // 风格配置项 const STYLE_CONFIGS = [ {key: 'fixedFooter', label: 'layout.fixedFooter', type: 'switch'}, {key: 'borderRadius', label: 'layout.borderRadius', type: 'number', min: 0, max: 30}, {key: 'controlHeight', label: 'layout.controlHeight', type: 'number', min: 0}, {key: 'headerPadding', label: 'layout.headerPadding', type: 'number', min: 0}, {key: 'headerHeight', label: 'layout.headerHeight', type: 'number', min: 0}, {key: 'siderWeight', label: 'layout.siderWeight', type: 'number', min: 0}, {key: 'bodyPadding', label: 'layout.bodyPadding', type: 'number', min: 0}, ]; // 预设主题列表 const THEME_LIST = [ {background: '/static/theme/default.svg', name: 'light', title: 'layout.themeLight'}, {background: '/static/theme/dark.svg', name: 'dark', title: 'layout.themeDark'}, ]; // 布局配置 const LAYOUT_CONFIGS = [ { key: 'side', title: 'layout.layoutSide', render: (token: any) => ( <>
) }, { key: 'top', title: 'layout.layoutTop', render: (token: any) => ( <>
) }, { key: 'mix', title: 'layout.layoutMix', render: (token: any) => ( <>
) }, { key: 'columns', title: 'layout.layoutColumns', render: (token: any) => (
) }, ]; const SettingDrawer: React.FC = () => { const {t} = useTranslation(); const {token} = useToken(); const themeDrawer = useGlobalStore(state => state.themeDrawer); const setThemeDrawer = useGlobalStore(state => state.setThemeDrawer); const setThemeConfig = useGlobalStore(state => state.setThemeConfig); const themeConfig = useGlobalStore(state => state.themeConfig); const layout = useGlobalStore(state => state.layout); const setLayout = useGlobalStore(state => state.setLayout); // 翻译后的算法选项 const translatedAlgorithmOptions = algorithmOptions?.map(option => ({ ...option, label: t(option.label as string) })) || []; // 防抖更新主题配置(带过渡动画) const changeSetting = debounce((key: string, value: any) => { setThemeConfig({...themeConfig, [key]: value}); }, 400, {leading: true, trailing: false}); // 处理主题切换(带圆形扩散动画) const handleThemeChange = (e: React.MouseEvent) => { const target = (e.target as HTMLElement).closest('[data-theme]'); if (!target) return; const themeName = (target as HTMLElement).dataset.theme; const themeMap = { dark: darkColorTheme, light: defaultColorTheme }; if (themeMap[themeName as keyof typeof themeMap]) { setThemeConfig({...themeConfig, ...themeMap[themeName as keyof typeof themeMap]}); } }; // 重置主题(带过渡动画) const resetTheme = () => { setThemeConfig({...configTheme, ...defaultColorTheme}); }; return ( setThemeDrawer(false)} open={themeDrawer} footer={(
)} > {/* 布局样式 */} {t('layout.layoutStyle')} {LAYOUT_CONFIGS.map(({key, title, render}) => (
setLayout(key as any)} > {render(token)}
))}
{/* 预设主题 */} {t('layout.presetTheme')} {THEME_LIST.map((item) => (
{item.name}/
{t(item.title)}
))}
{t('layout.themeAlgorithm')}