前端添加中英文切换
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Task, TaskPriority } from '../types';
|
||||
import { useLanguage } from '../i18n/LanguageContext';
|
||||
|
||||
interface AddTaskModalProps {
|
||||
mode: 'child' | 'sibling';
|
||||
@@ -22,6 +23,7 @@ interface AddTaskModalProps {
|
||||
}
|
||||
|
||||
const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTask, allTasks, planId, onSave, onCancel }) => {
|
||||
const { t } = useLanguage();
|
||||
const [title, setTitle] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [taskId, setTaskId] = useState('');
|
||||
@@ -86,8 +88,8 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
const modeLabel = mode === 'child' ? '子任务' : '同级任务';
|
||||
const parentLabel = mode === 'child' ? siblingTask.title : (parentTask?.title || '根级');
|
||||
const modeLabel = mode === 'child' ? t('addChildTitle') : t('addSiblingTitle');
|
||||
const parentLabel = mode === 'child' ? siblingTask.title : (parentTask?.title || t('rootLevel'));
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -103,34 +105,34 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
<button
|
||||
onClick={onCancel}
|
||||
className="absolute top-4 right-4 text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors"
|
||||
aria-label="Close"
|
||||
aria-label={t('close')}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<h2 className="text-2xl font-bold text-slate-800 dark:text-slate-100 mb-1">添加{modeLabel}</h2>
|
||||
<h2 className="text-2xl font-bold text-slate-800 dark:text-slate-100 mb-1">{modeLabel}</h2>
|
||||
<p className="text-sm text-slate-400 dark:text-slate-500 mb-6">
|
||||
{mode === 'child' ? `在 "${siblingTask.title}" 下添加子任务` : `与 "${siblingTask.title}" 同级添加任务`}
|
||||
{mode === 'child' ? t('addChildHint', { title: siblingTask.title }) : t('addSiblingHint', { title: siblingTask.title })}
|
||||
<span className="text-slate-300 dark:text-slate-600 mx-1">·</span>
|
||||
归属于 <span className="text-slate-600 dark:text-slate-300 font-medium">{parentLabel}</span>
|
||||
{t('belongsTo')} <span className="text-slate-600 dark:text-slate-300 font-medium">{parentLabel}</span>
|
||||
</p>
|
||||
|
||||
<form onSubmit={handleSave} className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="add-task-id" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">任务ID</label>
|
||||
<label htmlFor="add-task-id" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('taskId')}</label>
|
||||
<input
|
||||
type="text"
|
||||
id="add-task-id"
|
||||
value={taskId}
|
||||
onChange={(e) => setTaskId(e.target.value)}
|
||||
className="w-full p-2 bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 border border-slate-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-shadow"
|
||||
placeholder="如: phase-2-design(留空自动生成)"
|
||||
placeholder={t('taskIdPlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="add-title" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">标题 <span className="text-red-400">*</span></label>
|
||||
<label htmlFor="add-title" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('title')} <span className="text-red-400">*</span></label>
|
||||
<input
|
||||
type="text"
|
||||
id="add-title"
|
||||
@@ -138,11 +140,11 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
className="w-full p-2 bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 border border-slate-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-shadow"
|
||||
required
|
||||
placeholder="任务标题"
|
||||
placeholder={t('titlePlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="add-description" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">描述 <span className="text-red-400">*</span></label>
|
||||
<label htmlFor="add-description" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('description')} <span className="text-red-400">*</span></label>
|
||||
<textarea
|
||||
id="add-description"
|
||||
value={description}
|
||||
@@ -150,12 +152,12 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
className="w-full p-2 bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 border border-slate-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-shadow"
|
||||
rows={3}
|
||||
required
|
||||
placeholder="任务描述"
|
||||
placeholder={t('descPlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label htmlFor="add-duration" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">预估工时 (小时)</label>
|
||||
<label htmlFor="add-duration" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('durationHours')}</label>
|
||||
<input
|
||||
type="number"
|
||||
id="add-duration"
|
||||
@@ -164,25 +166,25 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
className="w-full p-2 bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 border border-slate-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-shadow"
|
||||
min="0"
|
||||
step="0.5"
|
||||
placeholder="如: 4"
|
||||
placeholder={t('durationPlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="add-priority" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">优先级</label>
|
||||
<label htmlFor="add-priority" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('priority')}</label>
|
||||
<select
|
||||
id="add-priority"
|
||||
value={priority}
|
||||
onChange={(e) => setPriority(e.target.value as TaskPriority)}
|
||||
className="w-full p-2 bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 border border-slate-300 dark:border-slate-600 rounded-lg focus:ring-2 focus:ring-green-500"
|
||||
>
|
||||
<option value="low">低</option>
|
||||
<option value="medium">中</option>
|
||||
<option value="high">高</option>
|
||||
<option value="low">{t('priorityLow')}</option>
|
||||
<option value="medium">{t('priorityMedium')}</option>
|
||||
<option value="high">{t('priorityHigh')}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="add-due-date" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">截止日期</label>
|
||||
<label htmlFor="add-due-date" className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('dueDate')}</label>
|
||||
<input
|
||||
type="date"
|
||||
id="add-due-date"
|
||||
@@ -192,7 +194,7 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
/>
|
||||
</div>
|
||||
<div ref={dropdownRef}>
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">依赖</label>
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1">{t('dependencies')}</label>
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
@@ -201,7 +203,7 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
>
|
||||
<span className={`${selectedDeps.length === 0 ? 'text-slate-400 dark:text-slate-500' : 'text-slate-900 dark:text-slate-100'} truncate`}>
|
||||
{selectedDeps.length === 0
|
||||
? '选择依赖任务...'
|
||||
? t('selectDeps')
|
||||
: selectedDeps.map(depId => {
|
||||
const item = availableTasks.find(at => at.task.task_id === depId);
|
||||
return item ? item.task.title : depId;
|
||||
@@ -219,7 +221,7 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
{dropdownOpen && (
|
||||
<div className="absolute z-10 mt-1 w-full bg-white dark:bg-slate-700 border border-slate-200 dark:border-slate-600 rounded-lg shadow-lg max-h-52 overflow-y-auto">
|
||||
{availableTasks.length === 0 ? (
|
||||
<div className="px-3 py-2 text-sm text-slate-400 dark:text-slate-500">暂无可选任务</div>
|
||||
<div className="px-3 py-2 text-sm text-slate-400 dark:text-slate-500">{t('noTasks')}</div>
|
||||
) : (
|
||||
availableTasks.map(({ task: t, depth }) => (
|
||||
<label
|
||||
@@ -280,13 +282,13 @@ const AddTaskModal: React.FC<AddTaskModalProps> = ({ mode, parentTask, siblingTa
|
||||
onClick={onCancel}
|
||||
className="bg-slate-100 dark:bg-slate-700 text-slate-800 dark:text-slate-200 font-semibold px-4 py-2 rounded-lg hover:bg-slate-200 dark:hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
取消
|
||||
{t('cancel')}
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-green-600 text-white font-semibold px-4 py-2 rounded-lg hover:bg-green-700 transition-colors"
|
||||
>
|
||||
添加任务
|
||||
{t('addTask')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user