Files
ele-HeiXiu/src/components/ui/LegalTextModal.tsx
YoungestSongMo 7982b69219 refactor: CSS 拆分 + auth 持久化提取 + 目录整理
- globals.css 拆分为 4 文件:tokens.css(颜色)/ transitions.css(过渡)/ base.css(重置)/ globals.css(入口)
- 提取 auth-persistence.ts 到 services/,解除 AppProvider→pages/login/hooks 反向依赖
- use-auth-state.ts 精简为纯 React Hook,持久化逻辑委托给 services/auth-persistence.ts
- components/common/ → components/ui/(目录名语义更清晰)
- TypeScript + Vite 构建通过

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 14:20:07 +08:00

78 lines
2.3 KiB
TypeScript

// ============================================================
// LegalTextModal — 协议/法律文本展示弹窗
// 从 src/assets/legal/ 加载 .txt 文件,主题适配渲染
// ============================================================
import { Modal, Typography } from 'antd';
import { FileTextOutlined } from '@ant-design/icons';
import { useTheme } from '@/components/ThemeProvider';
// Vite ?raw 导入:将 .txt 内容作为字符串直接内联
import serviceAgreement from '@/assets/legal/用户服务协议.txt?raw';
import pointsAgreement from '@/assets/legal/积分充值服务协议.txt?raw';
const { Paragraph } = Typography;
/** 协议名称 → 文本内容映射 */
const legalTexts: Record<string, { title: string; content: string }> = {
service: { title: '用户服务协议', content: serviceAgreement },
points: { title: '积分充值服务协议', content: pointsAgreement },
};
interface LegalTextModalProps {
open: boolean;
/** 协议标识:'service' | 'points' */
type: 'service' | 'points';
onClose: () => void;
}
export function LegalTextModal({ open, type, onClose }: LegalTextModalProps) {
const { isDark } = useTheme();
const legal = legalTexts[type];
if (!legal) return null;
return (
<Modal
open={open}
onCancel={onClose}
footer={null}
width={640}
centered
title={
<span className="flex items-center gap-2">
<FileTextOutlined />
{legal.title}
</span>
}
styles={{
body: {
maxHeight: '60vh',
overflowY: 'auto',
padding: '20px 24px',
background: isDark ? '#1A1730' : '#FFFFFF',
color: isDark ? '#E8E6F0' : '#1E1B4B',
fontSize: 14,
lineHeight: 2,
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
fontFamily: 'var(--font-family-base)',
},
}}
>
<Paragraph
style={{
color: isDark ? '#E8E6F0' : '#1E1B4B',
fontSize: 14,
lineHeight: 2,
whiteSpace: 'pre-wrap',
margin: 0,
}}
>
{legal.content}
</Paragraph>
</Modal>
);
}