Parcourir la source

优化文件上传组件,隐藏上传列表以避免显示HTML错误信息的tooltip;增强问答列表的前端过滤功能,支持关键字搜索并保存原始数据以提高性能。

刘博博 il y a 4 jours
Parent
commit
3b31eadd36

+ 1 - 0
src/pages/deepseek/knowledgeLib/detail/drawerIndex.tsx

@@ -81,6 +81,7 @@ const KnowledgeLibInfo : React.FC<Props> = ({drawerItem}:Props) => {
     multiple: true,
     action: '/api/deepseek/api/uploadDocument/' + params.knowledgeId,
     headers: getHeaders(),
+    showUploadList: false, // 隐藏上传列表,避免显示HTML错误信息的tooltip
     beforeUpload( file, fileList ) {
       setUploadLoading( true );
       // const allowedExtensions = ['md', 'txt', 'pdf', 'jpg', 'png', 'jpeg', 'docx', 'xlsx', 'pptx', 'eml', 'csv', 'tar', 'gz', 'bz2', 'zip', 'rar', 'jar'];

+ 1 - 0
src/pages/deepseek/knowledgeLib/detail/index.tsx

@@ -81,6 +81,7 @@ const KnowledgeLibInfo : React.FC = () => {
     multiple: true,
     action: '/api/deepseek/api/uploadDocument/' + params.knowledgeId,
     headers: getHeaders(),
+    showUploadList: false, // 隐藏上传列表,避免显示HTML错误信息的tooltip
     beforeUpload( file, fileList ) {
       setUploadLoading( true );
       // const allowedExtensions = ['md', 'txt', 'pdf', 'jpg', 'png', 'jpeg', 'docx', 'xlsx', 'pptx', 'eml', 'csv', 'tar', 'gz', 'bz2', 'zip', 'rar', 'jar'];

+ 105 - 13
src/pages/deepseek/questionAnswer/list/index.tsx

@@ -115,6 +115,7 @@ const QuestionAnswerList: React.FC = () => {
 
   const [listLoading, setListLoading] = React.useState(false);
   const [list, setList] = React.useState<Item[]>([]);
+  const [originalList, setOriginalList] = React.useState<Item[]>([]); // 保存原始列表数据,用于前端过滤
   const [page, setPage] = React.useState<PageInfo>({
     pageNumber: 1,
     pageSize: 10,
@@ -141,22 +142,31 @@ const QuestionAnswerList: React.FC = () => {
   // 搜索输入框展开状态
   const [isSearchExpanded, setIsSearchExpanded] = React.useState(false);
   const searchWrapperRef = React.useRef<HTMLDivElement>(null);
+  // 标记是否正在重置,避免触发 useEffect 循环
+  const isResettingRef = React.useRef(false);
 
   const appApi = {
-    fetchList: async (typeId: any, projectId: any) => {
+    fetchList: async (typeId: any, projectId: any, forceRefresh: boolean = false) => {
+      const keyword = form.getFieldValue('keyword');
+      
+      // 如果有关键字且不是强制刷新,直接从现有数据筛选,不请求接口
+      if (keyword && keyword.trim() !== '' && !forceRefresh) {
+        applyFrontendFilter(originalList, keyword, page.pageNumber);
+        return;
+      }
+
       setListLoading(true);
       try {
         const userInfo = LocalStorage.getUserInfo();
         const userId = (userInfo?.id ?? '').toString();
-        const keyword = form.getFieldValue('keyword');
         const res = await apis.fetchTakaiAppList({
           pageSize: page.pageSize,
           pageNumber: page.pageNumber,
           userId: userId,
           typeId: typeId,
           projectId: projectId?.toString(),
-          keyword: keyword,
-          name: keyword,
+          keyword: '', // 不传关键字给后端
+          name: '', // 不传name给后端
         })
         const list = res.rows.map((item: any) => {
           return {
@@ -182,6 +192,9 @@ const QuestionAnswerList: React.FC = () => {
           // 没有权限时排除 status='5' 的数据
           return item.status !== '5';
         });
+        // 保存原始数据
+        setOriginalList(filteredList);
+        // 没有关键字时,显示当前页的数据
         setList(filteredList);
         setPage({
           pageNumber: page.pageNumber,
@@ -333,7 +346,7 @@ const QuestionAnswerList: React.FC = () => {
   };
 
   const init = async () => {
-    await appApi.fetchList(null, null);
+    await appApi.fetchList(null, null, true); // 强制刷新
     await indexApi.fetchIndex(null, null);
     await appTypeApi.fetchAppType();
     await projectApi.fetchProject();
@@ -345,6 +358,11 @@ const QuestionAnswerList: React.FC = () => {
   }
 
   React.useEffect(() => {
+    // 如果正在重置,跳过执行,避免循环
+    if (isResettingRef.current) {
+      isResettingRef.current = false;
+      return;
+    }
     setCreateFlag(LocalStorage.getStatusFlag('deepseek:application:create'));
     setDeleteFlag(LocalStorage.getStatusFlag('deepseek:application:delete'));
     setUpdateFlag(LocalStorage.getStatusFlag('deepseek:application:update'));
@@ -367,17 +385,82 @@ const QuestionAnswerList: React.FC = () => {
     pageSize: page.pageSize,
     total: page.total,
     onChange: (pageNumber, pageSize) => {
+      const keyword = form.getFieldValue('keyword');
+      // 根据是否有搜索关键字,决定使用哪个数据源
+      const dataSource = keyword && keyword.trim() !== '' 
+        ? originalList.filter((item: Item) => 
+            item.name && item.name.toLowerCase().includes(keyword.toLowerCase().trim())
+          )
+        : originalList;
+      
+      // 获取新页的数据
+      const startIndex = (pageNumber - 1) * pageSize;
+      const endIndex = startIndex + pageSize;
+      const paginatedData = dataSource.slice(startIndex, endIndex);
+      
+      setList(paginatedData);
       setPage({
         pageNumber: pageNumber,
         pageSize: pageSize,
-        total: page.total,
+        total: dataSource.length,
       });
     },
   };
 
+  // 前端模糊查询过滤函数
+  const applyFrontendFilter = (dataList: Item[], keyword: string | undefined, currentPageNumber: number = 1) => {
+    if (!keyword || keyword.trim() === '') {
+      // 如果没有关键字,显示所有数据
+      const paginatedData = getPaginatedData(dataList, currentPageNumber, page.pageSize);
+      setList(paginatedData);
+      setPage(prev => ({
+        ...prev,
+        total: dataList.length,
+        pageNumber: currentPageNumber,
+      }));
+      return;
+    }
+
+    // 对标题进行模糊匹配(不区分大小写)
+    const filtered = dataList.filter((item: Item) => {
+      return item.name && item.name.toLowerCase().includes(keyword.toLowerCase().trim());
+    });
+
+    // 计算过滤后的总页数
+    const totalPages = Math.ceil(filtered.length / page.pageSize);
+    // 如果当前页码超出了总页数,调整到最后一页(至少为1)
+    const adjustedPageNumber = Math.min(currentPageNumber, Math.max(1, totalPages));
+
+    // 获取调整后页码的数据
+    const paginatedData = getPaginatedData(filtered, adjustedPageNumber, page.pageSize);
+    setList(paginatedData);
+    setPage(prev => ({
+      ...prev,
+      total: filtered.length,
+      pageNumber: adjustedPageNumber,
+    }));
+  };
+
+  // 获取分页数据
+  const getPaginatedData = (dataList: Item[], pageNumber: number, pageSize: number) => {
+    const startIndex = (pageNumber - 1) * pageSize;
+    const endIndex = startIndex + pageSize;
+    return dataList.slice(startIndex, endIndex);
+  };
+
   // 点击查询
   const handleClickSearch = async () => {
     form.validateFields().then(async (values) => {
+      const keyword = values.keyword;
+      
+      // 如果有关键字,直接从现有数据中筛选,不请求接口
+      if (keyword && keyword.trim() !== '') {
+        // 模糊查询:从现有数据中筛选,保持当前页码
+        applyFrontendFilter(originalList, keyword, page.pageNumber);
+        return;
+      }
+
+      // 如果没有关键字,正常查询接口
       if (values.proTypeId) {
         values.typeId = values.proTypeId;
       }
@@ -387,8 +470,10 @@ const QuestionAnswerList: React.FC = () => {
       if (values.projectId instanceof Array && values.projectId.length == 2) {
         values.projectId = values.projectId[1];
       }
+      // 重置到第一页
+      setPage(prev => ({ ...prev, pageNumber: 1 }));
       await indexApi.fetchIndex(values.typeId, values.projectId);
-      await appApi.fetchList(values.typeId, values.projectId);
+      await appApi.fetchList(values.typeId, values.projectId, true); // 强制刷新
     }).catch((error) => {
       console.error(error);
     });
@@ -399,9 +484,16 @@ const QuestionAnswerList: React.FC = () => {
     form.resetFields();
     setShowSubPanel(false);
     setSelectedType('全部'); // 重置为"全部"
-    page.pageNumber = 1;
-    page.pageSize = 10;
-    await appApi.fetchList(null, null);
+    // 标记正在重置,避免触发 useEffect 循环
+    isResettingRef.current = true;
+    // 先更新 page 到第一页
+    setPage({
+      pageNumber: 1,
+      pageSize: 10,
+      total: 0,
+    });
+    // 调用接口获取数据
+    await appApi.fetchList(null, null, true); // 强制刷新
     await indexApi.fetchIndex(null, null);
   };
 
@@ -435,11 +527,11 @@ const QuestionAnswerList: React.FC = () => {
     // 自动提交逻辑
     if (value === '全部') {
       // 全部选项,传递null给后端
-      appApi.fetchList(null, null);
+      appApi.fetchList(null, null, true); // 强制刷新
       indexApi.fetchIndex(null, null);
     } else {
       // 其他选项,传递对应的typeId
-      appApi.fetchList(value, null);
+      appApi.fetchList(value, null, true); // 强制刷新
       indexApi.fetchIndex(value, null);
     }
   };
@@ -521,7 +613,7 @@ const QuestionAnswerList: React.FC = () => {
                   onChange={(value) => {
                     // 项目类型选择器自动提交逻辑
                     const currentProjectId = form.getFieldValue('projectId');
-                    appApi.fetchList(value, currentProjectId);
+                    appApi.fetchList(value, currentProjectId, true); // 强制刷新
                     indexApi.fetchIndex(value, currentProjectId);
                   }}
                 >