import React, { useEffect, useState } from 'react'; import { Icon } from '@iconify/react'; import mdiAccount from '@iconify-icons/mdi/account'; import mdiBell from '@iconify-icons/mdi/bell'; import mdiHeart from '@iconify-icons/mdi/heart'; import mdiHome from '@iconify-icons/mdi/home'; import mdiLoading from '@iconify-icons/mdi/loading'; import mdiSettings from '@iconify-icons/mdi/settings'; import Button from 'antd/es/button'; import Card from 'antd/es/card'; import Space from 'antd/es/space'; import Typography from 'antd/es/typography'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import multiColorIcon from '@/assets/iconify/multi-color/logo.svg'; import singleColorIcon from '@/assets/iconify/single-color/home.svg'; import infoIcon from '@/assets/iconify/single-color/info.svg'; import LanguageSwitch from '@/components/LanguageSwitch'; import { reportEvent } from '@/firebase'; import { dialogModel } from '@/models/dialogModel'; import { userModel } from '@/models/userModel'; import { fetchLogin } from '@/services/login'; import { createLocalTools } from '@/utils/localUtils'; const { Title } = Typography; const Home: React.FC = () => { const { t, i18n } = useTranslation(); const navigate = useNavigate(); const user = userModel.useModel(); const { openDialog, closeDialog } = dialogModel.useModel(); const [loading, setLoading] = useState(false); const [loginStatus, setLoginStatus] = useState(''); const [storageStatus, setStorageStatus] = useState(''); useEffect(() => { console.log('✅ home组件挂载:componentDidMount'); reportEvent('homePage_show'); return () => { console.log('❌ home组件卸载:componentWillUnmount'); reportEvent('homePage_hide'); }; }, []); // 创建加密存储工具实例 const encryptedLs = createLocalTools({ encryptKey: true, encryptData: true, }); // 创建明文存储工具实例 const plainLs = createLocalTools({ encryptKey: false, encryptData: false, }); // 演示加密存储 - 添加数据 const handleEncryptedStorageAdd = () => { encryptedLs.setLocal('encryptedData', { name: '加密数据', timestamp: Date.now() }); setStorageStatus('加密数据添加成功'); }; // 演示加密存储 - 获取数据 const handleEncryptedStorageGet = () => { const data = encryptedLs.getLocal<{ name: string; timestamp: number }>('encryptedData'); setStorageStatus(`获取加密数据: ${JSON.stringify(data)}`); }; // 演示加密存储 - 删除数据 const handleEncryptedStorageRemove = () => { encryptedLs.removeLocal('encryptedData'); setStorageStatus('加密数据删除成功'); }; // 演示明文存储 - 添加数据 const handlePlainStorageAdd = () => { plainLs.setLocal('plainData', { name: '明文数据', timestamp: Date.now() }); setStorageStatus('明文数据添加成功'); }; // 演示明文存储 - 获取数据 const handlePlainStorageGet = () => { const data = plainLs.getLocal<{ name: string; timestamp: number }>('plainData'); setStorageStatus(`获取明文数据: ${JSON.stringify(data)}`); }; // 演示明文存储 - 删除数据 const handlePlainStorageRemove = () => { plainLs.removeLocal('plainData'); setStorageStatus('明文数据删除成功'); }; // 演示清除所有数据 const handleStorageClear = () => { encryptedLs.clearLocal(); plainLs.clearLocal(); setStorageStatus('所有数据清除成功'); }; // 演示网络请求 const handleLoginDemo = async () => { setLoading(true); try { const result = await fetchLogin({ username: 'test', password: '123456', captchaId: 'test-captcha', captchaCode: '1234', }); setLoginStatus('登录成功'); console.log('登录结果:', result); } catch (error) { setLoginStatus('登录失败'); console.error('登录错误:', error); } finally { setLoading(false); } }; // 演示路由跳转 const handleNavigation = (path: string) => { navigate(path); }; // 切换语言 const handleLanguageChange = (lang: string) => { i18n.changeLanguage(lang); }; // 对话框演示 - 单个按钮 const handleOpenSingleButtonDialog = () => { openDialog({ icon: infoIcon, title: 'Payment Failure', content: 'Oops! Your transaction failed due to some errors, please try again.', buttons: [ { label: 'OK', onClick: (_event, id) => { closeDialog(id); }, }, ], }); }; // 对话框演示 - 两个按钮 const handleOpenTwoButtonDialog = () => { openDialog({ icon: infoIcon, title: 'Payment verification', content: 'Orders are being verified, if there is no response for a long time, please contact customer service if you have any questions!', buttons: [ { label: 'Cancel', variant: 'secondary', onClick: (_event, id) => { closeDialog(id); }, }, { label: 'Contact us', onClick: (_event, id) => { closeDialog(id); }, }, ], }); }; // 对话框演示 - 无图标 const handleOpenNoIconDialog = () => { openDialog({ title: 'Simple Dialog', content: 'This is a dialog without an icon.', buttons: [ { label: 'Close', onClick: (_event, id) => { closeDialog(id); }, }, ], }); }; // 对话框演示 - 自定义内容 const handleOpenCustomContentDialog = () => { openDialog({ icon: infoIcon, title: ( Custom Title ), content: (

This dialog has custom ReactNode content.

  • Feature 1
  • Feature 2
  • Feature 3
), buttons: [ { label: 'Got it', onClick: (_event, id) => { closeDialog(id); }, }, ], }); }; // 对话框演示 - 禁止点击遮罩层关闭 const handleOpenNonClosableDialog = () => { openDialog({ icon: infoIcon, title: 'Important Notice', content: 'This dialog cannot be closed by clicking the mask. You must click the button to close it.', maskClosable: false, buttons: [ { label: 'I Understand', onClick: (_event, id) => { closeDialog(id); }, }, ], }); }; // 对话框演示 - 嵌套对话框 const handleOpenNestedDialog = () => { openDialog({ icon: infoIcon, title: 'First Dialog', content: 'This is the first dialog. Click the button below to open a nested dialog.', buttons: [ { label: 'Open Nested Dialog', onClick: (_event, id) => { openDialog({ icon: infoIcon, title: 'Nested Dialog', content: 'This is a nested dialog opened from the first dialog. Notice how the z-index is automatically managed.', buttons: [ { label: 'Close Nested', variant: 'secondary', onClick: (_event, nestedId) => { closeDialog(nestedId); }, }, { label: 'Close All', onClick: (_event, nestedId) => { closeDialog(nestedId); closeDialog(id); }, }, ], }); }, }, { label: 'Close First', variant: 'secondary', onClick: (_event, id) => { closeDialog(id); }, }, ], }); }; return (

{t('pages.home.title')}

{/* 多语言演示卡片 */} 多语言演示

{t('pages.home.description')}

{t('pages.home.features.title')}

  • {t('pages.home.features.antd')}
  • {t('pages.home.features.tailwind')}
  • {t('pages.home.features.i18n')}
{/* 用户信息卡片 */} 用户信息

姓名:{user.name}

年龄:{user.age}

{/* 功能演示卡片 */} 功能演示
本地存储演示
加密存储
明文存储
{storageStatus &&

{storageStatus}

}
网络请求演示 {loginStatus && {loginStatus}}
路由跳转演示
{/* 图标演示卡片 */} 图标演示
离线图标
在线图标
自定义图标
动画图标
{/* 样式演示卡片 */} 样式演示
Tailwind CSS 样式
响应式卡片 1
响应式卡片 2
响应式卡片 3
Ant Design 组件
{/* 对话框演示卡片 */} 对话框演示
Dialog 组件示例
使用说明
  • 通过 dialogModel.openDialog() 打开对话框
  • openDialog 返回对话框 id,可用于后续关闭
  • 按钮的 onClick 接收 (event, dialogId) 两个参数
  • 默认情况下,点击遮罩层可以关闭对话框
  • 设置 maskClosable: false 可禁止点击遮罩层关闭
  • 支持嵌套对话框,z-index 自动管理
  • 支持图标、标题、内容的自定义
); }; export default Home;