import React from 'react'; import ReactDOM from 'react-dom'; import 'bootstrap/dist/css/bootstrap.css'; import Header from './components/Header' import Footer from './components/Footer' import CheckAll from './components/CheckAll' import ListItem from './components/ListItem' import uuid from 'uuid'; import filterTypes from './components/filter-types'; import { TransitionGroup, CSSTransition } from 'react-transition-group'; import 'animate.css'; class App extends React.Component{ constructor(){ super(); this.state = { todos:[ {id:uuid(), title:'1我是牧码人老肖..', completed:false}, {id:uuid(), title:'2我是牧码人老肖..', completed:false} ], filterType:filterTypes.ALL }; } addTodo = (item) =>{ this.setState({ todos:[ ...this.state.todos, { id:uuid(), ...item, completed:false } ] }) } toggleChange = (id) =>{ let todos = this.state.todos.map((item,index)=>{ if(item.id===id){ item.completed = !item.completed; } return item; }); this.setState({todos}); } handleDelete = (id) =>{ let todos = this.state.todos.filter((item,index)=>item.id!==id); this.setState({todos}); } toggleAll = (input) =>{ let checked = input.checked; let todos = this.state.todos.map((item,index)=>{ item.completed = checked; return item; }); this.setState({todos}); } changeFilterType = (filterType) =>{ this.setState({filterType},()=>{ console.log(this.state.filterType); }); } delCompleted = () =>{ let todos = this.state.todos.filter(item=>{ return !item.completed }); this.setState({todos}); } render(){ let todos = this.state.todos; let unCompletedCount = todos.reduce((pre,cur)=>pre+(cur.completed?0:1),0); //未完成任务数量 let completedCount = todos.length - unCompletedCount; let filterTodos = todos.filter(item=>{ switch(this.state.filterType){ case filterTypes.UNCOMPLETED: return item.completed === false; case filterTypes.COMPLETED: return item.completed === true; default: return item; } }); const bodyContent = (