CzRger 2 ヶ月 前
コミット
7c3784c3ba

+ 2 - 2
web/app/components/skill/corpus/detail-modal.tsx

@@ -3,7 +3,7 @@ import React, { useCallback, useState } from 'react'
 import { RiCloseLine } from '@remixicon/react'
 import Modal from '@/app/components/base/modal'
 import Button from '@/app/components/base/button'
-import { delCorpusQuestion, fetchIntentName, fetchIntentType } from '@/service/common'
+import { delCorpusQuestion, fetchIntent, fetchIntentType } from '@/service/common'
 import 'react-multi-email/dist/style.css'
 import Input from '@/app/components/base/input'
 import { SimpleSelect } from '@/app/components/base/select'
@@ -47,7 +47,7 @@ const DetailModal = ({
         intentType,
       },
     },
-    fetchIntentName,
+    fetchIntent,
   )
   const optionsIntentName: any = dataOptionsIntentName?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
   const [questionList, setQuestionList] = useState<any>([{ id: uuid4(), name: '啊啊啊啊啊啊啊啊啊啊' }, { id: uuid4(), name: '啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊' }])

+ 2 - 2
web/app/components/skill/corpus/index.tsx

@@ -7,7 +7,7 @@ import cn from '@/utils/classnames'
 import { RiAddLine, RiRefreshLine, RiSearchLine } from '@remixicon/react'
 import Button from '@/app/components/base/button'
 import useSWR from 'swr'
-import { fetchCorpus, fetchIntentName, fetchIntentType } from '@/service/common'
+import { fetchCorpus, fetchIntent, fetchIntentType } from '@/service/common'
 import { SimpleSelect } from '@/app/components/base/select'
 import DetailModal from './detail-modal'
 
@@ -37,7 +37,7 @@ const CorpusIndex = () => {
         intentType,
       },
     },
-    fetchIntentName,
+    fetchIntent,
   )
   const optionsIntentName: any = dataOptionsIntentName?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
   const [query, setQuery] = useState<any>({})

+ 2 - 2
web/app/components/skill/intent/detail-modal.tsx

@@ -3,7 +3,7 @@ import React, { useCallback, useState } from 'react'
 import { RiCloseLine } from '@remixicon/react'
 import Modal from '@/app/components/base/modal'
 import Button from '@/app/components/base/button'
-import { delCorpusQuestion, fetchIntentName, fetchIntentType } from '@/service/common'
+import { delCorpusQuestion, fetchIntent, fetchIntentType } from '@/service/common'
 import 'react-multi-email/dist/style.css'
 import Input from '@/app/components/base/input'
 import { SimpleSelect } from '@/app/components/base/select'
@@ -46,7 +46,7 @@ const DetailModal = ({
         intentType,
       },
     },
-    fetchIntentName,
+    fetchIntent,
   )
   const optionsIntentName: any = dataOptionsIntentName?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
   const [questionList, setQuestionList] = useState<any>([{ id: uuid4(), name: '啊啊啊啊啊啊啊啊啊啊' }, { id: uuid4(), name: '啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊' }])

+ 47 - 54
web/app/components/skill/intent/index.tsx

@@ -1,25 +1,25 @@
 'use client'
 
 import List from './list'
-import React, { useEffect, useState } from 'react'
+import React, { useEffect, useRef, useState } from 'react'
 import Input from '@/app/components/base/input'
 import cn from '@/utils/classnames'
 import { RiAddLine, RiPriceTagLine, RiRefreshLine, RiSearchLine } from '@remixicon/react'
 import Button from '@/app/components/base/button'
 import useSWR from 'swr'
-import { fetchCorpus, fetchIntentName, fetchIntentType } from '@/service/common'
+import { fetchIntent, fetchIntentType } from '@/service/common'
 import { SimpleSelect } from '@/app/components/base/select'
 import DetailModal from './detail-modal'
 import TypeModal from './type-modal'
 
 const CorpusIndex = () => {
-  const [page, setPage] = React.useState<number>(0)
+  const [page, setPage] = useState<number>(0)
   const [limit, setLimit] = useState<number>(10)
-  const [question, setQuestion] = useState<string>('') // the input value
+  const [intentName, setIntentName] = useState<string>('') // the input value
   const [intentType, setIntentType] = useState<string>('') // the input value
-  const { data: dataOptionsIntentType }: any = useSWR(
+  const { data: dataOptionsIntentType, mutate: mutateOptionsIntentType }: any = useSWR(
     {
-      url: '/xxx',
+      url: '/intentions/types',
       params: {
         page: 1,
         limit: 1000,
@@ -28,53 +28,47 @@ const CorpusIndex = () => {
     fetchIntentType,
   )
   const optionsIntentType: any = dataOptionsIntentType?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
-  const [intentName, setIntentName] = useState<string>('') // the input value
-  const { data: dataOptionsIntentName }: any = useSWR(
-    {
-      url: '/xxx',
-      params: {
-        page: 1,
-        limit: 1000,
-        intentType,
-      },
-    },
-    fetchIntentName,
-  )
-  const optionsIntentName: any = dataOptionsIntentName?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
-  const [query, setQuery] = useState<any>({})
-  const { data, mutate }: any = useSWR(
-    {
-      url: '/xxx',
-      params: {
-        page: page + 1,
-        limit,
-        ...query,
-      },
-    },
-    fetchCorpus,
-  )
-  const list: any = data?.data || []
-  const total = data?.total || 0
+  const query = useRef<any>({})
+  const [list, setList] = useState<any>([])
+  const [total, setTotal] = useState(0)
+  const handlePage = () => {
+    const params: any = {
+      page: page + 1,
+      limit,
+    }
+    if (query.current.intentType)
+      params.type_id = query.current.intentType
+    if (query.current.intentName)
+      params.name_search = query.current.intentName
+    fetchIntent({
+      url: '/intentions',
+      params,
+    }).then((res: any) => {
+      setList(res.data)
+      setTotal(res.total)
+    })
+  }
+  const [refresh, setRefresh] = useState<boolean>(false)
   const handleSearch = (reset = false) => {
+    setRefresh(true)
+    setPage(0)
     if (reset) {
-      setQuestion('')
       setIntentName('')
       setIntentType('')
+      query.current = {}
     }
-    const params: any = {}
-    if (question)
-      params.question = question
-    if (intentType)
-      params.intentType = intentType
-    if (intentName)
-      params.intentName = intentName
-    setQuery(params)
-    setPage(0)
+    else {
+      query.current = {
+        intentType, intentName,
+      }
+    }
+    handlePage()
+    setRefresh(false)
   }
   useEffect(() => {
-    mutate()
+    if (!refresh)
+      handlePage()
   }, [page, limit])
-
   const [detailModalVisible, setDetailModalVisible] = useState(false)
   const [transfer, setTransfer] = useState<any>({
     mode: 'add',
@@ -106,9 +100,9 @@ const CorpusIndex = () => {
               className="ml-2"
               showClearIcon
               wrapperClassName='!w-[200px]'
-              value={question}
-              onChange={e => setQuestion(e.target.value)}
-              onClear={() => setQuestion('')}
+              value={intentName}
+              onChange={e => setIntentName(e.target.value)}
+              onClear={() => setIntentName('')}
             />
           </div>
           <Button variant='primary' className={cn('ml-auto shrink-0')} onClick={() => {
@@ -143,8 +137,8 @@ const CorpusIndex = () => {
         </div>
         <div className="flex-1">
           <List
-            list={list || []}
-            onUpdate={mutate}
+            list={list}
+            onUpdate={() => handleSearch(false)}
             pagination={{
               total,
               limit,
@@ -162,7 +156,7 @@ const CorpusIndex = () => {
             onCancel={() => setDetailModalVisible(false)}
             onSend={() => {
               setDetailModalVisible(false)
-              mutate()
+              handleSearch()
             }}
           />
         )
@@ -170,10 +164,9 @@ const CorpusIndex = () => {
       {
         showIntentTypeModalVisible && (
           <TypeModal
-            onCancel={() => setShowIntentTypeModalVisible(false)}
-            onSend={() => {
+            onCancel={() => {
+              mutateOptionsIntentType()
               setShowIntentTypeModalVisible(false)
-              // mutate()
             }}
           />
         )

+ 9 - 5
web/app/components/skill/intent/list.tsx

@@ -7,6 +7,8 @@ import cn from '@/utils/classnames'
 import { delCorpus } from '@/service/common'
 import Confirm from '@/app/components/base/confirm'
 import DetailModal from './detail-modal'
+import useTimestamp from '@/hooks/use-timestamp'
+import { useTranslation } from 'react-i18next'
 
 type PageListProps = {
   list: []
@@ -19,6 +21,8 @@ const IntentPageList: FC<PageListProps> = ({
   pagination,
   onUpdate,
 }) => {
+  const { t } = useTranslation()
+  const { formatTime } = useTimestamp()
   const [showConfirmDelete, setShowConfirmDelete] = useState(false)
   const [row, setRow] = useState<any>({})
   const handleDel = async () => {
@@ -59,11 +63,11 @@ const IntentPageList: FC<PageListProps> = ({
                   key={item.id}
                   className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
                 >
-                  <td>1</td>
-                  <td>2</td>
-                  <td>3</td>
-                  <td>4</td>
-                  <td>2025-02-02 22:44:33</td>
+                  <td>{item.type_name}</td>
+                  <td>{item.name}</td>
+                  <td>{item.corpus_count}</td>
+                  <td>{item.keywords_count}</td>
+                  <td>{formatTime(item.created_at, t('datasetHitTesting.dateTimeFormat') as string)}</td>
                   <td className="flex justify-center gap-2">
                     <Button variant='ghost-accent' size='small' className={cn('shrink-0')} onClick={() => {
                       setTransfer({

+ 0 - 1
web/app/components/skill/intent/type-modal.tsx

@@ -13,7 +13,6 @@ import Confirm from '@/app/components/base/confirm'
 
 const TypeModal = ({
   onCancel,
-  onSend,
 }: any) => {
   const [page, setPage] = React.useState<number>(0)
   const [limit, setLimit] = useState<number>(10)

+ 17 - 21
web/service/common.ts

@@ -532,27 +532,23 @@ export const delIntentType = ({ url, body }: any) => {
   return del(url, { body })
 }
 
-export const fetchIntentName = ({ url, params }: any) => {
-  console.log('查询意图名称', url, params)
-  // return get(url, { params })
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      const arr: any = []
-      for (let i = 1; i < 10; i++) {
-        arr.push({
-          id: i,
-          name: `意图名称_${i}`,
-        })
-      }
-      resolve({
-        data: arr,
-        has_more: false,
-        limit: 10,
-        total: 100,
-        page: 1,
-      })
-    }, 1000)
-  })
+export const fetchIntent = ({ url, params }: any) => {
+  console.log('查询意图', url, params)
+  return get(url, { params })
+}
+export const addIntent = ({ url, body }: any) => {
+  console.log('新增意图', url, body)
+  return post(url, { body })
+}
+
+export const editIntent = ({ url, body }: any) => {
+  console.log('编辑意图', url, body)
+  return patch(url, { body })
+}
+
+export const delIntent = ({ url, body }: any) => {
+  console.log('删除意图', url, body)
+  return del(url, { body })
 }
 
 export const fetchCorpus = ({ url, params }: any) => {