index.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2022-05-30 10:49:32
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-12-27 14:51:13
  6. * @FilePath: /KC-MiddlePlatform/src/pages/index/components/TodoList/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. //待办事项模块
  10. import { useEffect, useState } from 'react';
  11. import './style.less';
  12. export type todoItem = {
  13. recordTitle: string;
  14. id: number;
  15. status: number;
  16. taskLevel: number;
  17. createDate: number;
  18. content: string;
  19. };
  20. export interface TodoList {
  21. todoList: todoItem[];
  22. todoListClickHandle?: (id: number) => void;
  23. }
  24. export const TodoList = (props: TodoList) => {
  25. const { todoList, todoListClickHandle } = props;
  26. const [todoLists, set_todoLists] = useState<todoItem[]>([]);
  27. const setTodoClass = (val: todoItem) => {
  28. if (val.taskLevel == 3) return 'todoStatus green';
  29. if (val.taskLevel == 2) return 'todoStatus orange';
  30. if (val.taskLevel == 1) return 'todoStatus red';
  31. };
  32. const checkBtnHandle = (item: todoItem) => {
  33. todoListClickHandle && todoListClickHandle(item.id);
  34. };
  35. useEffect(() => {
  36. set_todoLists(todoList.splice(0, 4));
  37. }, [todoList]);
  38. return (
  39. <div className="TodoList">
  40. <div className="topTitle">
  41. <span className="name">待办事项</span>
  42. {/* <span className='actBtn'>全部处理</span> */}
  43. </div>
  44. <div className="wrap">
  45. {todoLists.map((item, index) => {
  46. return (
  47. <div className="todoList" key={index}>
  48. <div className="checkBtn" onClick={() => checkBtnHandle(item)}></div>
  49. <div className="status">
  50. <div className={setTodoClass(item)}>{item.recordTitle}</div>
  51. <span className="date">{item.createDate ? `${item.createDate}`.replace(/:\d{2}$/, '') : ''}</span>
  52. </div>
  53. <div className="detail" dangerouslySetInnerHTML={{ __html: item.content }}></div>
  54. </div>
  55. );
  56. })}
  57. {todoLists.length == 0 && (
  58. <div className="empty">
  59. <img src={require('../../../../../public/images/empty.png')} alt="" />
  60. <span>待办事项已全部处理</span>
  61. </div>
  62. )}
  63. </div>
  64. </div>
  65. );
  66. };