前端添加中英文切换
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Task, TaskPriority } from '../types';
|
||||
import { useLanguage } from '../i18n/LanguageContext';
|
||||
import { MessageKey } from '../i18n/translations';
|
||||
|
||||
interface TaskCompleteModalProps {
|
||||
task: Task;
|
||||
@@ -8,31 +10,16 @@ interface TaskCompleteModalProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const ENCOURAGEMENTS: Record<TaskPriority, string[]> = {
|
||||
high: [
|
||||
'太棒了!你攻克了最难的一关!🔥',
|
||||
'出色的工作!高难度任务也难不倒你!💪',
|
||||
'了不起!挑战完成了,你是最强的!⭐',
|
||||
'征服高难度任务的感觉真好!继续保持!🎯',
|
||||
],
|
||||
medium: [
|
||||
'干得漂亮!稳步前进中!🚀',
|
||||
'出色的工作!继续保持这个节奏!✨',
|
||||
'又完成了一项!你正在不断进步!🌟',
|
||||
'很棒!一步一个脚印,离目标更近了!👏',
|
||||
],
|
||||
low: [
|
||||
'轻松搞定!积少成多!💧',
|
||||
'完成啦!每一个小任务都算数!🌱',
|
||||
'搞定!小胜利也是胜利!🎯',
|
||||
'又一步完成了!保持节奏!😊',
|
||||
],
|
||||
const ENCOURAGE_KEYS: Record<TaskPriority, MessageKey[]> = {
|
||||
high: ['encourageHigh1', 'encourageHigh2', 'encourageHigh3', 'encourageHigh4'],
|
||||
medium: ['encourageMid1', 'encourageMid2', 'encourageMid3', 'encourageMid4'],
|
||||
low: ['encourageLow1', 'encourageLow2', 'encourageLow3', 'encourageLow4'],
|
||||
};
|
||||
|
||||
const LEVEL_LABELS: Record<number, string> = {
|
||||
0: '阶段',
|
||||
1: '任务',
|
||||
2: '子任务',
|
||||
const LEVEL_KEYS: Record<number, MessageKey> = {
|
||||
0: 'levelPhase',
|
||||
1: 'levelTask',
|
||||
2: 'levelSubtask',
|
||||
};
|
||||
|
||||
const EMOJIS_BY_LEVEL: Record<number, string[]> = {
|
||||
@@ -41,13 +28,8 @@ const EMOJIS_BY_LEVEL: Record<number, string[]> = {
|
||||
2: ['👍', '👏', '💪', '🎯'],
|
||||
};
|
||||
|
||||
function getEncouragement(priority: TaskPriority, level: number): string {
|
||||
const pool = ENCOURAGEMENTS[priority] || ENCOURAGEMENTS.medium;
|
||||
const idx = (priority.charCodeAt(0) + level) % pool.length;
|
||||
return pool[idx];
|
||||
}
|
||||
|
||||
const TaskCompleteModal: React.FC<TaskCompleteModalProps> = ({ task, level, onClose }) => {
|
||||
const { t } = useLanguage();
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -61,8 +43,9 @@ const TaskCompleteModal: React.FC<TaskCompleteModalProps> = ({ task, level, onCl
|
||||
setTimeout(onClose, 300);
|
||||
};
|
||||
|
||||
const encouragement = getEncouragement(task.priority, level);
|
||||
const levelLabel = LEVEL_LABELS[level] || '任务';
|
||||
const encouragePool = ENCOURAGE_KEYS[task.priority] || ENCOURAGE_KEYS.medium;
|
||||
const encouragement = t(encouragePool[(task.priority.charCodeAt(0) + level) % encouragePool.length]);
|
||||
const levelLabel = t(LEVEL_KEYS[level] || 'levelTask');
|
||||
const emojis = EMOJIS_BY_LEVEL[level] || EMOJIS_BY_LEVEL[2];
|
||||
const mainEmoji = emojis[Math.floor(Math.random() * emojis.length)];
|
||||
|
||||
@@ -104,7 +87,7 @@ const TaskCompleteModal: React.FC<TaskCompleteModalProps> = ({ task, level, onCl
|
||||
|
||||
{/* Level badge */}
|
||||
<span className="inline-block text-[10px] font-bold px-2 py-0.5 rounded-full bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300 mb-2">
|
||||
{levelLabel}完成
|
||||
{t('levelDone', { label: levelLabel })}
|
||||
</span>
|
||||
|
||||
{/* Task title */}
|
||||
@@ -136,7 +119,7 @@ const TaskCompleteModal: React.FC<TaskCompleteModalProps> = ({ task, level, onCl
|
||||
className="fill-emerald-600 dark:fill-emerald-400 text-[9px] font-bold"
|
||||
>✓</text>
|
||||
</svg>
|
||||
<span className="text-xs text-slate-400 dark:text-slate-500">已完成</span>
|
||||
<span className="text-xs text-slate-400 dark:text-slate-500">{t('completed')}</span>
|
||||
</div>
|
||||
|
||||
{/* Close button */}
|
||||
@@ -144,7 +127,7 @@ const TaskCompleteModal: React.FC<TaskCompleteModalProps> = ({ task, level, onCl
|
||||
onClick={handleClose}
|
||||
className="w-full bg-gradient-to-r from-emerald-500 to-green-500 text-white font-semibold py-2.5 rounded-xl hover:from-emerald-600 hover:to-green-600 transition-all shadow-md shadow-emerald-200 dark:shadow-emerald-900/30 active:scale-[0.97]"
|
||||
>
|
||||
继续前进
|
||||
{t('keepGoing')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user