diff --git a/src/pages/componentLibrary/index.tsx b/src/pages/componentLibrary/index.tsx index 19841c8..36831a5 100644 --- a/src/pages/componentLibrary/index.tsx +++ b/src/pages/componentLibrary/index.tsx @@ -1,15 +1,41 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import styles from './style/index.module.less'; import CustomCard from '@/components/CustomCard/index'; import CollapseBox from './collapseBox'; import { Space, Input, Button, Tabs, Tag } from '@arco-design/web-react'; -const InputSearch = Input.Search; const TabPane = Tabs.TabPane; function ComponentLibrary() { const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}'); const componentData = JSON.parse(sessionStorage.getItem(`compLibs${userInfo.userId}`)); + + const [inputValue, setInputValue] = useState(''); + const [activeKey, setActiveKey] = useState<'myLibs' | 'pubLibs' | 'teamLibs'>('myLibs'); + const [componentsTree, setComponentsTree] = useState([]); + const [filteredComponentsTree, setFilteredComponentsTree] = useState([]); + + const handelChangeTabs = (key) => { + if (componentData && Object.keys(componentData).length > 0) setComponentsTree(componentData[key]); + setActiveKey(key); + }; + + const handelSearch = () => { + const newTree = componentsTree.map(item => { + const filteredChildren = item.children.filter(sub => sub.label.toLowerCase().includes(inputValue.toLowerCase())); + return { + ...item, + children: filteredChildren + }; + }) + .filter(item => item.children.length > 0); + setFilteredComponentsTree(newTree); + }; + + useEffect(() => { + handelSearch(); + }, [inputValue, activeKey]); + return ( <>