Sfoglia il codice sorgente

知识库列表部门查询

CzRger 2 mesi fa
parent
commit
a6a6253953

+ 28 - 2
web/app/(commonLayout)/datasets/Container.tsx

@@ -30,8 +30,9 @@ import { useStore as useTagStore } from '@/app/components/base/tag-management/st
 import { useAppContext } from '@/context/app-context'
 import { useExternalApiPanel } from '@/context/external-api-panel-context'
 import { SimpleSelect } from '@/app/components/base/select'
-import { fetchTypes } from '@/service/common'
+import { fetchDepts, fetchTypes } from '@/service/common'
 import Statistic from '@/app/(commonLayout)/datasets/Statistic'
+import { TreeSelect as AntdTreeSelect } from 'antd'
 
 const Container = () => {
   const { t } = useTranslation()
@@ -103,6 +104,19 @@ const Container = () => {
       setOptionsType(res.data.map((v: any) => ({ name: v.name, value: v.id })) || [])
     })
   }, [])
+  const [dept, setDept] = useState<any>()
+  const [optionsDept, setOptionsDept] = useState<any>([])
+  useEffect(() => {
+    fetchDepts({
+      url: '/xxx',
+      params: {
+        page: 1,
+        limit: 1000,
+      },
+    }).then((res: any) => {
+      setOptionsDept(res.data || [])
+    })
+  }, [])
   return (
     <div ref={containerRef} className='scroll-container relative flex grow flex-col overflow-y-auto bg-background-body'>
       <div className='sticky top-0 z-10 flex flex-wrap justify-between gap-y-2 bg-background-body px-12 pb-2 pt-4 leading-[56px]'>
@@ -113,6 +127,18 @@ const Container = () => {
         />
         {activeTab === 'dataset' && (
           <div className='flex items-center justify-center gap-2'>
+            <AntdTreeSelect
+              showSearch
+              style={{ width: '200px' }}
+              value={dept}
+              dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
+              placeholder="请选择部门"
+              allowClear
+              treeDefaultExpandAll
+              onChange={v => setDept(v || '')}
+              treeData={optionsDept}
+              fieldNames={{ label: 'name', value: 'id' }}
+            />
             <SimpleSelect
               wrapperClassName="h-[32px] w-[200px]"
               defaultValue={type}
@@ -154,7 +180,7 @@ const Container = () => {
       </div>
       {activeTab === 'dataset' && (
         <>
-          <Datasets containerRef={containerRef} tags={tagIDs} keywords={searchKeywords} includeAll={includeAll} type={searchType} />
+          <Datasets containerRef={containerRef} tags={tagIDs} keywords={searchKeywords} includeAll={includeAll} type={searchType} dept={dept} />
           <DatasetFooter />
           {showTagManagementModal && (
             <TagManagementModal type='knowledge' show={showTagManagementModal} />

+ 6 - 1
web/app/(commonLayout)/datasets/Datasets.tsx

@@ -17,6 +17,7 @@ const getKey = (
   keyword: string,
   includeAll: boolean,
   type: string,
+  dept: string,
 ) => {
   if (!pageIndex || previousPageData.has_more) {
     const params: FetchDatasetsParams = {
@@ -33,6 +34,8 @@ const getKey = (
       params.params.keyword = keyword
     if (type)
       params.params.category_ids = [type]
+    if (dept)
+      params.params.dept = dept
     return params
   }
   return null
@@ -44,6 +47,7 @@ type Props = {
   keywords: string
   includeAll: boolean,
   type: string,
+  dept: string,
 }
 
 const Datasets = ({
@@ -52,10 +56,11 @@ const Datasets = ({
   keywords,
   includeAll,
   type,
+  dept,
 }: Props) => {
   const { isCurrentWorkspaceEditor } = useAppContext()
   const { data, isLoading, setSize, mutate } = useSWRInfinite(
-    (pageIndex: number, previousPageData: DataSetListResponse) => getKey(pageIndex, previousPageData, tags, keywords, includeAll, type),
+    (pageIndex: number, previousPageData: DataSetListResponse) => getKey(pageIndex, previousPageData, tags, keywords, includeAll, type, dept),
     fetchDatasets,
     { revalidateFirstPage: false, revalidateAll: true },
   )

+ 15 - 4
web/app/layout.tsx

@@ -8,6 +8,7 @@ import { ThemeProvider } from 'next-themes'
 import './styles/globals.css'
 import './styles/markdown.scss'
 import Fix from '@/utils/fix'
+import { ConfigProvider } from 'antd'
 
 export const metadata = {
   title: 'Dify',
@@ -64,10 +65,20 @@ const LocaleLayout = async ({
                 enableSystem
                 disableTransitionOnChange
               >
-                <I18nServer>
-                  <Fix/>
-                  {children}
-                </I18nServer>
+                <ConfigProvider theme={{
+                  components: {
+                    Select: {
+                      colorBgBase: '#c8ceda40',
+                      colorBorder: '#c8ceda40',
+                      algorithm: true, // 启用算法
+                    },
+                  },
+                }}>
+                  <I18nServer>
+                    <Fix/>
+                    {children}
+                  </I18nServer>
+                </ConfigProvider>
               </ThemeProvider>
             </TanstackQueryIniter>
           </SentryInitor>

+ 2 - 0
web/models/datasets.ts

@@ -158,6 +158,8 @@ export type FetchDatasetsParams = {
     include_all?: boolean
     keyword?: string,
     category_ids?: string[],
+    type?: string,
+    dept?: string,
   }
 }