index.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-02-24 15:53:38
  4. * @LastEditTime: 2022-02-28 10:02:15
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /MedicalQualificationMana/src/components/qualificationClassTree/index.tsx
  8. */
  9. import react, { useState } from 'react';
  10. import { Input } from 'antd';
  11. import './style.less';
  12. const treeData = [
  13. {
  14. title: 'parent 1',
  15. key: '0-0',
  16. children: [
  17. {
  18. title: 'parent 1-0',
  19. key: '0-0-0',
  20. disabled: true,
  21. children: [
  22. {
  23. title: 'leaf',
  24. key: '0-0-0-0',
  25. disableCheckbox: true,
  26. },
  27. {
  28. title: 'leaf',
  29. key: '0-0-0-1',
  30. },
  31. ],
  32. },
  33. {
  34. title: 'parent 1-1',
  35. key: '0-0-1',
  36. children: [{ title: <span style={{ color: '#1890ff' }}>sss</span>, key: '0-0-1-0' }],
  37. },
  38. ],
  39. },
  40. ];
  41. export interface QualificationClassTreePropsType {
  42. }
  43. export interface TreeType {
  44. [key: string]: any;
  45. children?: TreeType[]
  46. }
  47. const TreeNode = (data: TreeType, index: number, indent: number) => {
  48. const [ifShowChild, setifShowChild] = useState(false);
  49. const parentsNodeClickhandle = (e: react.MouseEvent) => {
  50. e.preventDefault();
  51. setifShowChild(!ifShowChild);
  52. }
  53. return (
  54. data.children ? (
  55. <div className='parents' key={index}>
  56. <div className={ifShowChild?'parentsNode open':'parentsNode'} style={{ paddingLeft: `${indent * 10}px` }} onClick={(e) => parentsNodeClickhandle(e)}>
  57. <div className='parentsTitle'>{data.title}</div>
  58. </div>
  59. <div className='childrenWraper' style={{ height: ifShowChild ? '100%' :0}}>
  60. {
  61. data.children.map((item, i) => (TreeNode(item, i, indent + 1)))
  62. }
  63. </div>
  64. </div>
  65. ) : (<div className='child' key={index}>{data.title}</div>)
  66. )
  67. }
  68. const QualificationClassTree: react.FC<QualificationClassTreePropsType> = () => {
  69. return (
  70. <div className='QualificationClassTree'>
  71. <div className='searchArea'>
  72. <Input className='inputArea' placeholder="请输入类目名称" /><img className='searchIcon' alt="" />
  73. </div>
  74. <div className='treeContainer'>
  75. {
  76. treeData.map((data, index) => {
  77. return (
  78. TreeNode(data, index, 0)
  79. )
  80. })
  81. }
  82. </div>
  83. </div>
  84. )
  85. }
  86. export default QualificationClassTree;