/**
* KRA - Settings Drawer Component
* System configuration panel with appearance, layout, and general settings
*/
import React, { useState, useEffect } from 'react';
import { Drawer, Tabs, Switch, Select, InputNumber, Button, message, Modal, Upload } from 'antd';
import {
BgColorsOutlined,
LayoutOutlined,
SettingOutlined,
CheckOutlined,
SunOutlined,
MoonOutlined,
DesktopOutlined,
ReloadOutlined,
ExportOutlined,
ImportOutlined,
GithubOutlined,
BookOutlined,
} from '@ant-design/icons';
import { useAppStore, type DarkMode, type SideMode, type TransitionType, type GlobalSize } from '@/models/app';
import Logo from '@/components/Logo/Logo';
import './SettingDrawer.less';
interface SettingDrawerProps {
open: boolean;
onClose: () => void;
}
// Theme colors
const themeColors = [
{ name: '拂晓蓝', color: '#1890ff' },
{ name: '薄暮红', color: '#f5222d' },
{ name: '火山橙', color: '#fa541c' },
{ name: '日暮黄', color: '#faad14' },
{ name: '极光绿', color: '#52c41a' },
{ name: '明青', color: '#13c2c2' },
{ name: '酱紫', color: '#722ed1' },
{ name: '洋红', color: '#eb2f96' },
];
// Layout modes
const layoutModes: { key: SideMode; title: string; icon: React.ReactNode }[] = [
{ key: 'normal', title: '侧边菜单', icon: },
{ key: 'head', title: '顶部菜单', icon: },
{ key: 'combination', title: '混合菜单', icon: },
];
// Section Header Component
const SectionHeader: React.FC<{ title: string }> = ({ title }) => (
);
// Setting Item Component
const SettingItem: React.FC<{
label: string;
description?: string;
children: React.ReactNode;
}> = ({ label, description, children }) => (
{label}
{description && {description}}
{children}
);
// Appearance Settings Tab
const AppearanceSettings: React.FC = () => {
const { config, setDarkMode, setPrimaryColor, setWeakness, setGrey, setShowWatermark, setGlobalSize } = useAppStore();
const darkModeOptions: { key: DarkMode; icon: React.ReactNode; label: string }[] = [
{ key: 'light', icon: , label: '浅色' },
{ key: 'dark', icon: , label: '深色' },
{ key: 'auto', icon: , label: '跟随系统' },
];
return (
{/* Theme Mode */}
{darkModeOptions.map((option) => (
setDarkMode(option.key)}
style={config.darkMode === option.key ? { backgroundColor: config.primaryColor } : {}}
>
{option.icon}
{option.label}
))}
{/* Theme Color */}
{themeColors.map((item) => (
setPrimaryColor(item.color)}
title={item.name}
>
{config.primaryColor === item.color && }
))}
{/* Global Size */}
{/* Visual Accessibility */}
);
};
// Layout Settings Tab
const LayoutSettings: React.FC = () => {
const {
config,
setSideMode,
setShowTabs,
setTransitionType,
setLayoutSideWidth,
setLayoutSideCollapsedWidth,
} = useAppStore();
return (
{/* Layout Mode */}
{layoutModes.map((mode) => (
setSideMode(mode.key)}
style={config.sideMode === mode.key ? { borderColor: config.primaryColor } : {}}
>
{mode.key === 'normal' && (
<>
>
)}
{mode.key === 'head' && (
<>
>
)}
{mode.key === 'combination' && (
<>
>
)}
{mode.title}
{config.sideMode === mode.key && (
)}
))}
{/* Interface Config */}
{/* Size Config */}
value && setLayoutSideWidth(value)}
/>
px
value && setLayoutSideCollapsedWidth(value)}
/>
px
);
};
// General Settings Tab
const GeneralSettings: React.FC = () => {
const { config, resetConfig, updateConfig } = useAppStore();
const [browserInfo, setBrowserInfo] = useState('');
const [screenResolution, setScreenResolution] = useState('');
useEffect(() => {
const userAgent = navigator.userAgent;
if (userAgent.includes('Chrome')) {
setBrowserInfo('Chrome');
} else if (userAgent.includes('Firefox')) {
setBrowserInfo('Firefox');
} else if (userAgent.includes('Safari')) {
setBrowserInfo('Safari');
} else if (userAgent.includes('Edge')) {
setBrowserInfo('Edge');
} else {
setBrowserInfo('Unknown');
}
setScreenResolution(`${screen.width}×${screen.height}`);
}, []);
const handleResetConfig = () => {
Modal.confirm({
title: '重置配置',
content: '确定要重置所有配置吗?此操作不可撤销。',
okText: '确定',
cancelText: '取消',
onOk: () => {
resetConfig();
message.success('配置已重置');
},
});
};
const handleExportConfig = () => {
const configData = JSON.stringify(config, null, 2);
const blob = new Blob([configData], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `kra-config-${new Date().toISOString().split('T')[0]}.json`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
message.success('配置已导出');
};
const handleImportConfig = (file: File) => {
const reader = new FileReader();
reader.onload = (e) => {
try {
const importedConfig = JSON.parse(e.target?.result as string);
updateConfig(importedConfig);
message.success('配置已导入');
} catch {
message.error('配置文件格式错误');
}
};
reader.readAsText(file);
return false;
};
return (
{/* System Info */}
版本
v1.0.0
前端框架
React 19
UI 组件库
Ant Design
构建工具
UMI
浏览器
{browserInfo}
屏幕分辨率
{screenResolution}
{/* Config Management */}
{/* About Project */}
Kratos Admin
基于 React 19 + Go Kratos 的全栈开发基础平台,提供完整的后台管理解决方案
);
};
// Main Setting Drawer Component
const SettingDrawer: React.FC = ({ open, onClose }) => {
const { config, resetConfig } = useAppStore();
const tabItems = [
{
key: 'appearance',
label: '外观',
children: ,
},
{
key: 'layout',
label: '布局',
children: ,
},
{
key: 'general',
label: '通用',
children: ,
},
];
return (
系统配置
}
placement="right"
width={500}
open={open}
onClose={onClose}
className="kra-setting-drawer"
>
);
};
export default SettingDrawer;