fix(ui): 完善控制台列表并优化企业中心与个人操作
This commit is contained in:
@@ -24,43 +24,24 @@ const { Text, Title, Paragraph } = Typography;
|
||||
|
||||
// 默认海报模板配置
|
||||
const DEFAULT_TEMPLATES = [
|
||||
{
|
||||
id: 'blue',
|
||||
name: '科技蓝',
|
||||
bgGradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
||||
textColor: '#ffffff',
|
||||
},
|
||||
{
|
||||
id: 'orange',
|
||||
name: '活力橙',
|
||||
bgGradient: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
|
||||
textColor: '#ffffff',
|
||||
},
|
||||
{
|
||||
id: 'green',
|
||||
name: '清新绿',
|
||||
bgGradient: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)',
|
||||
textColor: '#ffffff',
|
||||
},
|
||||
{
|
||||
id: 'dark',
|
||||
name: '暗夜黑',
|
||||
bgGradient: 'linear-gradient(135deg, #232526 0%, #414345 100%)',
|
||||
textColor: '#ffffff',
|
||||
},
|
||||
{ id: 'blue', name: '科技蓝' },
|
||||
{ id: 'orange', name: '活力橙' },
|
||||
{ id: 'green', name: '清新绿' },
|
||||
{ id: 'dark', name: '暗夜黑' },
|
||||
];
|
||||
|
||||
const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const canvasRef = useRef(null);
|
||||
const previewRef = useRef(null);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [affCode, setAffCode] = useState('');
|
||||
const [affLink, setAffLink] = useState('');
|
||||
const [systemName, setSystemName] = useState('');
|
||||
const [selectedTemplate, setSelectedTemplate] = useState(
|
||||
DEFAULT_TEMPLATES[0],
|
||||
DEFAULT_TEMPLATES[0].id,
|
||||
);
|
||||
const [downloading, setDownloading] = useState(false);
|
||||
const [posterConfig, setPosterConfig] = useState(null);
|
||||
@@ -123,9 +104,7 @@ const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
|
||||
// 绘制海报内容
|
||||
const drawContent = useCallback(
|
||||
(ctx, width, height) => {
|
||||
const textColor = selectedTemplate.textColor;
|
||||
|
||||
(ctx, width, height, textColor) => {
|
||||
ctx.fillStyle = textColor;
|
||||
ctx.font =
|
||||
'bold 28px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
|
||||
@@ -187,15 +166,17 @@ const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
height - 45,
|
||||
);
|
||||
},
|
||||
[selectedTemplate, posterConfig, systemName, affCode, t],
|
||||
[posterConfig, systemName, affCode, t],
|
||||
);
|
||||
|
||||
// 绘制海报到 Canvas
|
||||
const drawPoster = useCallback(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas || !affLink) return null;
|
||||
const preview = previewRef.current;
|
||||
if (!canvas || !preview || !affLink) return null;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
const { backgroundColor, color } = getComputedStyle(preview);
|
||||
const width = 375;
|
||||
const height = 667;
|
||||
|
||||
@@ -203,26 +184,12 @@ const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
canvas.height = height * 2;
|
||||
ctx.scale(2, 2);
|
||||
|
||||
const gradient = ctx.createLinearGradient(0, 0, width, height);
|
||||
if (selectedTemplate.id === 'blue') {
|
||||
gradient.addColorStop(0, '#667eea');
|
||||
gradient.addColorStop(1, '#764ba2');
|
||||
} else if (selectedTemplate.id === 'orange') {
|
||||
gradient.addColorStop(0, '#f093fb');
|
||||
gradient.addColorStop(1, '#f5576c');
|
||||
} else if (selectedTemplate.id === 'green') {
|
||||
gradient.addColorStop(0, '#4facfe');
|
||||
gradient.addColorStop(1, '#00f2fe');
|
||||
} else {
|
||||
gradient.addColorStop(0, '#232526');
|
||||
gradient.addColorStop(1, '#414345');
|
||||
}
|
||||
ctx.fillStyle = gradient;
|
||||
ctx.fillStyle = backgroundColor;
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
drawContent(ctx, width, height);
|
||||
drawContent(ctx, width, height, color);
|
||||
|
||||
return canvas;
|
||||
}, [affLink, selectedTemplate, drawContent]);
|
||||
}, [affLink, drawContent]);
|
||||
|
||||
// 下载海报
|
||||
const handleDownload = async () => {
|
||||
@@ -354,14 +321,12 @@ const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
|
||||
const renderPosterMode = () => (
|
||||
<div className='pm-poster-layout'>
|
||||
<div className='pm-preview-stage'>
|
||||
<div
|
||||
className='pm-poster'
|
||||
style={{
|
||||
'--pm-poster-background': selectedTemplate.bgGradient,
|
||||
'--pm-poster-ink': selectedTemplate.textColor,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className='pm-preview-stage'
|
||||
data-poster-template={selectedTemplate}
|
||||
ref={previewRef}
|
||||
>
|
||||
<div className='pm-poster'>
|
||||
<h2>{posterConfig?.slogan || t('邀请好友,共享AI')}</h2>
|
||||
<p className='pm-poster-subtitle'>
|
||||
{posterConfig?.sub_slogan || t('注册即可获得免费额度')}
|
||||
@@ -393,21 +358,15 @@ const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
<Radio.Group
|
||||
className='pm-template-list'
|
||||
aria-labelledby='promotion-template-label'
|
||||
value={selectedTemplate.id}
|
||||
onChange={(event) =>
|
||||
setSelectedTemplate(
|
||||
DEFAULT_TEMPLATES.find(
|
||||
(item) => item.id === event.target.value,
|
||||
),
|
||||
)
|
||||
}
|
||||
value={selectedTemplate}
|
||||
onChange={(event) => setSelectedTemplate(event.target.value)}
|
||||
>
|
||||
{DEFAULT_TEMPLATES.map((template) => (
|
||||
<Radio key={template.id} value={template.id}>
|
||||
<span className='pm-template-label'>
|
||||
<span
|
||||
className='pm-template-swatch'
|
||||
style={{ '--pm-template-background': template.bgGradient }}
|
||||
data-poster-template={template.id}
|
||||
/>
|
||||
{t(template.name)}
|
||||
</span>
|
||||
@@ -447,7 +406,7 @@ const PromotionPosterModal = ({ visible, onClose }) => {
|
||||
footer={null}
|
||||
width={800}
|
||||
centered
|
||||
className='promotion-modal'
|
||||
className={`promotion-modal${activeTab === 'poster' ? ' promotion-modal--poster' : ''}`}
|
||||
>
|
||||
{loading ? (
|
||||
<div className='pm-loading' aria-label={t('加载中...')}>
|
||||
|
||||
Reference in New Issue
Block a user