Add 1 files
Browse files- index.html +307 -38
index.html
CHANGED
|
@@ -1,41 +1,310 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
<
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0"
|
| 6 |
-
<
|
|
|
|
|
|
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
</style>
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
<
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-CN">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>任务清单</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
<style>
|
| 10 |
+
@keyframes fadeIn {
|
| 11 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 12 |
+
to { opacity: 1; transform: translateY(0); }
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.task-item {
|
| 16 |
+
animation: fadeIn 0.3s ease-out forwards;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.completed {
|
| 20 |
+
position: relative;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.completed::after {
|
| 24 |
+
content: '';
|
| 25 |
+
position: absolute;
|
| 26 |
+
left: 0;
|
| 27 |
+
top: 50%;
|
| 28 |
+
width: 100%;
|
| 29 |
+
height: 1px;
|
| 30 |
+
background: #000;
|
| 31 |
+
transform: scaleX(0);
|
| 32 |
+
transform-origin: left;
|
| 33 |
+
animation: strike 0.3s ease-out forwards;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
@keyframes strike {
|
| 37 |
+
to { transform: scaleX(1); }
|
| 38 |
+
}
|
| 39 |
</style>
|
| 40 |
+
</head>
|
| 41 |
+
<body class="bg-gray-50 min-h-screen">
|
| 42 |
+
<div class="container mx-auto px-4 py-8 max-w-3xl">
|
| 43 |
+
<!-- 标题 -->
|
| 44 |
+
<header class="mb-8 text-center">
|
| 45 |
+
<h1 class="text-3xl font-bold text-gray-900 mb-2">任务清单</h1>
|
| 46 |
+
<p class="text-gray-600">专注当下,高效生活</p>
|
| 47 |
+
<div class="mt-6 relative">
|
| 48 |
+
<input
|
| 49 |
+
type="text"
|
| 50 |
+
id="newTaskInput"
|
| 51 |
+
placeholder="添加新任务..."
|
| 52 |
+
class="w-full px-6 py-3 rounded-lg border border-gray-300 focus:outline-none focus:border-gray-500 bg-white text-gray-900"
|
| 53 |
+
>
|
| 54 |
+
<button
|
| 55 |
+
id="addTaskBtn"
|
| 56 |
+
class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-gray-900 text-white p-2 rounded-lg hover:bg-gray-800 transition-colors"
|
| 57 |
+
>
|
| 58 |
+
<i class="fas fa-plus"></i>
|
| 59 |
+
</button>
|
| 60 |
+
</div>
|
| 61 |
+
</header>
|
| 62 |
+
|
| 63 |
+
<!-- 任务控制 -->
|
| 64 |
+
<div class="flex justify-between items-center mb-6">
|
| 65 |
+
<div class="flex space-x-2">
|
| 66 |
+
<button id="filterAll" class="filter-btn active px-4 py-2 rounded-lg bg-gray-900 text-white font-medium">全部</button>
|
| 67 |
+
<button id="filterActive" class="filter-btn px-4 py-2 rounded-lg border border-gray-300 hover:bg-gray-100 text-gray-700">待办</button>
|
| 68 |
+
<button id="filterCompleted" class="filter-btn px-4 py-2 rounded-lg border border-gray-300 hover:bg-gray-100 text-gray-700">已完成</button>
|
| 69 |
+
</div>
|
| 70 |
+
<button id="clearCompleted" class="text-gray-700 hover:text-gray-900 text-sm">
|
| 71 |
+
<i class="fas fa-trash-alt mr-1"></i> 清除已完成
|
| 72 |
+
</button>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<!-- 任务统计 -->
|
| 76 |
+
<div class="bg-white rounded-lg p-4 mb-6 border border-gray-200 flex justify-between items-center">
|
| 77 |
+
<div>
|
| 78 |
+
<span class="text-gray-600">总任务:</span>
|
| 79 |
+
<span id="totalTasks" class="font-bold ml-1">0</span>
|
| 80 |
+
</div>
|
| 81 |
+
<div>
|
| 82 |
+
<span class="text-gray-600">已完成:</span>
|
| 83 |
+
<span id="completedTasks" class="font-bold ml-1">0</span>
|
| 84 |
+
</div>
|
| 85 |
+
<div>
|
| 86 |
+
<span class="text-gray-600">待完成:</span>
|
| 87 |
+
<span id="remainingTasks" class="font-bold ml-1">0</span>
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
+
|
| 91 |
+
<!-- 任务列表 -->
|
| 92 |
+
<div id="taskList" class="space-y-3">
|
| 93 |
+
<!-- 任务将动态添加在这里 -->
|
| 94 |
+
<div class="text-center py-10 text-gray-500" id="emptyState">
|
| 95 |
+
<i class="fas fa-tasks text-4xl mb-3 text-gray-300"></i>
|
| 96 |
+
<p class="text-lg">暂无任务</p>
|
| 97 |
+
<p class="mt-1">添加你的第一个任务开始吧</p>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<script>
|
| 103 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 104 |
+
// DOM元素
|
| 105 |
+
const newTaskInput = document.getElementById('newTaskInput');
|
| 106 |
+
const addTaskBtn = document.getElementById('addTaskBtn');
|
| 107 |
+
const taskList = document.getElementById('taskList');
|
| 108 |
+
const emptyState = document.getElementById('emptyState');
|
| 109 |
+
const filterAll = document.getElementById('filterAll');
|
| 110 |
+
const filterActive = document.getElementById('filterActive');
|
| 111 |
+
const filterCompleted = document.getElementById('filterCompleted');
|
| 112 |
+
const clearCompleted = document.getElementById('clearCompleted');
|
| 113 |
+
const totalTasks = document.getElementById('totalTasks');
|
| 114 |
+
const completedTasks = document.getElementById('completedTasks');
|
| 115 |
+
const remainingTasks = document.getElementById('remainingTasks');
|
| 116 |
+
|
| 117 |
+
// 状态
|
| 118 |
+
let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
|
| 119 |
+
let currentFilter = 'all';
|
| 120 |
+
|
| 121 |
+
// 初始化
|
| 122 |
+
renderTasks();
|
| 123 |
+
updateStats();
|
| 124 |
+
|
| 125 |
+
// 事件监听
|
| 126 |
+
addTaskBtn.addEventListener('click', addTask);
|
| 127 |
+
newTaskInput.addEventListener('keypress', function(e) {
|
| 128 |
+
if (e.key === 'Enter') addTask();
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
filterAll.addEventListener('click', () => setFilter('all'));
|
| 132 |
+
filterActive.addEventListener('click', () => setFilter('active'));
|
| 133 |
+
filterCompleted.addEventListener('click', () => setFilter('completed'));
|
| 134 |
+
|
| 135 |
+
clearCompleted.addEventListener('click', clearCompletedTasks);
|
| 136 |
+
|
| 137 |
+
// 功能函数
|
| 138 |
+
function addTask() {
|
| 139 |
+
const taskText = newTaskInput.value.trim();
|
| 140 |
+
if (taskText === '') return;
|
| 141 |
+
|
| 142 |
+
const task = {
|
| 143 |
+
id: Date.now().toString(),
|
| 144 |
+
text: taskText,
|
| 145 |
+
completed: false,
|
| 146 |
+
createdAt: new Date().toISOString()
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
tasks.unshift(task);
|
| 150 |
+
saveTasks();
|
| 151 |
+
renderTasks();
|
| 152 |
+
updateStats();
|
| 153 |
+
newTaskInput.value = '';
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
function renderTasks() {
|
| 157 |
+
// 根据当前筛选条件过滤任务
|
| 158 |
+
let filteredTasks = [];
|
| 159 |
+
|
| 160 |
+
switch(currentFilter) {
|
| 161 |
+
case 'active':
|
| 162 |
+
filteredTasks = tasks.filter(task => !task.completed);
|
| 163 |
+
break;
|
| 164 |
+
case 'completed':
|
| 165 |
+
filteredTasks = tasks.filter(task => task.completed);
|
| 166 |
+
break;
|
| 167 |
+
default:
|
| 168 |
+
filteredTasks = [...tasks];
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (filteredTasks.length === 0) {
|
| 172 |
+
emptyState.classList.remove('hidden');
|
| 173 |
+
taskList.innerHTML = '';
|
| 174 |
+
taskList.appendChild(emptyState);
|
| 175 |
+
} else {
|
| 176 |
+
emptyState.classList.add('hidden');
|
| 177 |
+
taskList.innerHTML = '';
|
| 178 |
+
|
| 179 |
+
filteredTasks.forEach(task => {
|
| 180 |
+
const taskElement = createTaskElement(task);
|
| 181 |
+
taskList.appendChild(taskElement);
|
| 182 |
+
});
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
function createTaskElement(task) {
|
| 187 |
+
const taskElement = document.createElement('div');
|
| 188 |
+
taskElement.className = `task-item bg-white rounded-lg p-4 border border-gray-200 flex items-center justify-between`;
|
| 189 |
+
taskElement.dataset.id = task.id;
|
| 190 |
+
|
| 191 |
+
if (task.completed) {
|
| 192 |
+
taskElement.classList.add('completed');
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
taskElement.innerHTML = `
|
| 196 |
+
<div class="flex items-center space-x-3 flex-1">
|
| 197 |
+
<button class="complete-btn w-5 h-5 rounded border ${task.completed ? 'bg-gray-900 border-gray-900 text-white' : 'border-gray-400'} flex items-center justify-center">
|
| 198 |
+
${task.completed ? '<i class="fas fa-check text-xs"></i>' : ''}
|
| 199 |
+
</button>
|
| 200 |
+
<span class="task-text ${task.completed ? 'text-gray-400' : 'text-gray-800'} flex-1">${task.text}</span>
|
| 201 |
+
</div>
|
| 202 |
+
<div class="flex space-x-2">
|
| 203 |
+
<button class="edit-btn text-gray-500 hover:text-gray-700">
|
| 204 |
+
<i class="fas fa-pencil-alt text-sm"></i>
|
| 205 |
+
</button>
|
| 206 |
+
<button class="delete-btn text-gray-500 hover:text-gray-700">
|
| 207 |
+
<i class="fas fa-trash-alt text-sm"></i>
|
| 208 |
+
</button>
|
| 209 |
+
</div>
|
| 210 |
+
`;
|
| 211 |
+
|
| 212 |
+
// 为按钮添加事件监听
|
| 213 |
+
const completeBtn = taskElement.querySelector('.complete-btn');
|
| 214 |
+
const editBtn = taskElement.querySelector('.edit-btn');
|
| 215 |
+
const deleteBtn = taskElement.querySelector('.delete-btn');
|
| 216 |
+
|
| 217 |
+
completeBtn.addEventListener('click', () => toggleComplete(task.id));
|
| 218 |
+
editBtn.addEventListener('click', () => editTask(task.id));
|
| 219 |
+
deleteBtn.addEventListener('click', () => deleteTask(task.id));
|
| 220 |
+
|
| 221 |
+
return taskElement;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
function toggleComplete(taskId) {
|
| 225 |
+
const taskIndex = tasks.findIndex(task => task.id === taskId);
|
| 226 |
+
if (taskIndex !== -1) {
|
| 227 |
+
tasks[taskIndex].completed = !tasks[taskIndex].completed;
|
| 228 |
+
saveTasks();
|
| 229 |
+
renderTasks();
|
| 230 |
+
updateStats();
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
function editTask(taskId) {
|
| 235 |
+
const task = tasks.find(task => task.id === taskId);
|
| 236 |
+
if (!task) return;
|
| 237 |
+
|
| 238 |
+
const taskElement = document.querySelector(`.task-item[data-id="${taskId}"]`);
|
| 239 |
+
const taskTextElement = taskElement.querySelector('.task-text');
|
| 240 |
+
|
| 241 |
+
const input = document.createElement('input');
|
| 242 |
+
input.type = 'text';
|
| 243 |
+
input.value = task.text;
|
| 244 |
+
input.className = 'border border-gray-300 px-2 py-1 rounded flex-1';
|
| 245 |
+
|
| 246 |
+
taskTextElement.replaceWith(input);
|
| 247 |
+
input.focus();
|
| 248 |
+
|
| 249 |
+
const handleEdit = (e) => {
|
| 250 |
+
if (e.key === 'Enter' || e.type === 'blur') {
|
| 251 |
+
const newText = input.value.trim();
|
| 252 |
+
if (newText !== '' && newText !== task.text) {
|
| 253 |
+
task.text = newText;
|
| 254 |
+
saveTasks();
|
| 255 |
+
}
|
| 256 |
+
renderTasks();
|
| 257 |
+
}
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
input.addEventListener('keypress', handleEdit);
|
| 261 |
+
input.addEventListener('blur', handleEdit);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
function deleteTask(taskId) {
|
| 265 |
+
tasks = tasks.filter(task => task.id !== taskId);
|
| 266 |
+
saveTasks();
|
| 267 |
+
renderTasks();
|
| 268 |
+
updateStats();
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
function clearCompletedTasks() {
|
| 272 |
+
tasks = tasks.filter(task => !task.completed);
|
| 273 |
+
saveTasks();
|
| 274 |
+
renderTasks();
|
| 275 |
+
updateStats();
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
function setFilter(filter) {
|
| 279 |
+
currentFilter = filter;
|
| 280 |
+
|
| 281 |
+
// 更新筛选按钮的活动状态
|
| 282 |
+
document.querySelectorAll('.filter-btn').forEach(btn => {
|
| 283 |
+
btn.classList.remove('active', 'bg-gray-900', 'text-white');
|
| 284 |
+
btn.classList.add('border', 'border-gray-300', 'hover:bg-gray-100', 'text-gray-700');
|
| 285 |
+
});
|
| 286 |
+
|
| 287 |
+
const activeBtn = document.getElementById(`filter${filter.charAt(0).toUpperCase() + filter.slice(1)}`);
|
| 288 |
+
activeBtn.classList.add('active', 'bg-gray-900', 'text-white');
|
| 289 |
+
activeBtn.classList.remove('border', 'hover:bg-gray-100', 'text-gray-700');
|
| 290 |
+
|
| 291 |
+
renderTasks();
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
function updateStats() {
|
| 295 |
+
const total = tasks.length;
|
| 296 |
+
const completed = tasks.filter(task => task.completed).length;
|
| 297 |
+
const remaining = total - completed;
|
| 298 |
+
|
| 299 |
+
totalTasks.textContent = total;
|
| 300 |
+
completedTasks.textContent = completed;
|
| 301 |
+
remainingTasks.textContent = remaining;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
function saveTasks() {
|
| 305 |
+
localStorage.setItem('tasks', JSON.stringify(tasks));
|
| 306 |
+
}
|
| 307 |
+
});
|
| 308 |
+
</script>
|
| 309 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=uu531/web" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 310 |
+
</html>
|