Selaa lähdekoodia

补充筛选进度

John 1 vuosi sitten
vanhempi
sitoutus
4de60eed7b

+ 19 - 9
src/pages/DuplicateFile/CalculateDuplicateFiles.tsx

@@ -14,7 +14,7 @@ import {
 import { message } from "@tauri-apps/api/dialog";
 import styles from "./CalculateDuplicateFiles.module.less";
 import File from "@/plugins/tauri-plugin-file/file";
-import { Button, Col, Row, Steps } from "antd";
+import { Button, Col, Row, Steps, Space } from "antd";
 import { fileTypeList } from "./config";
 import get_progress_by_sourceId, {
   get_fileInfo_by_path,
@@ -218,7 +218,7 @@ export default function CalculateDuplicateFiles() {
   // 计算每一个文件的hash
   async function computeFileChecksums_2() {
     const [progressRes] = await get_progress_by_sourceId(`${fileId}`);
-    console.log(178, progressRes)
+    // console.log(178, progressRes)
 
     // 已经存在的数据中,计算过的 hash 总量跟 文件总数不是一样的,并且存在有记录的文件
     if (progressRes.hash_null_count && progressRes.total_entries) {
@@ -251,13 +251,14 @@ export default function CalculateDuplicateFiles() {
               const hash = await File.getHash(fileinfo.path);
               await updateFileHsah(fileinfo.path, hash, `${fileId}`);
             }
-            console.clear();  // 清除控制台
+            // console.clear();  // 清除控制台
             // console.log(223, window.location.href, location.pathname, fileinfo);
-            console.log(223, window.location.href.indexOf(location.pathname), location.pathname);
+            // console.log(223, window.location.href.indexOf(location.pathname), location.pathname);
             fileIndex++;
             await waittime();
-            setPercent(Math.floor((fileIndex / allFilesLength) * 100));
-            setDuplicateFilesStep(`: ${fileIndex} / ${allFilesLength}`);
+            const [newProgressRes] = await get_progress_by_sourceId(`${fileId}`);
+            setPercent(Math.floor((fileIndex / newProgressRes.hash_null_count) * 100));
+            setDuplicateFilesStep(`: ${fileIndex} / ${newProgressRes.hash_null_count}`);
             return Promise.resolve(0)
           },
           Promise.resolve(0)
@@ -294,6 +295,10 @@ export default function CalculateDuplicateFiles() {
     return types;
   }
 
+
+  function toNextPage() {
+    navigate("/calculate-list/" + fileId);
+  }
   return (
     <div className={styles.CalculateDuplicateFiles}>
       <Row justify="start" align="middle">
@@ -303,9 +308,14 @@ export default function CalculateDuplicateFiles() {
           </div>
         </Col>
         <Col>
-          <Button type="primary" onClick={() => scanDirAll()}>
-            开始
-          </Button>
+          <Space>
+            <Button type="primary" onClick={() => scanDirAll()}>
+              开始
+            </Button>
+            <Button type="primary" onClick={() => toNextPage()}>
+              预览重复数据
+            </Button>
+          </Space>
         </Col>
       </Row>
 

+ 12 - 2
src/pages/DuplicateFile/CalculateListPage.tsx

@@ -35,6 +35,7 @@ export default function CalculateListPage() {
   let { fileId } = useParams();
   const [data, setData] = useState<FileItem[]>([]);
   const [loading, setLoading] = useState<boolean>(false);
+  const [tip, setTip] = useState<string>('');
   const [removeList, setRemoveList] = useState<string[]>([]);
   interface FileItem {
     sourceId: number;
@@ -45,9 +46,12 @@ export default function CalculateListPage() {
     otherItems: insertSearchFilesPasamsType[];
   }
   const appendData = async () => {
+    setLoading(true)
+    setTip('正在统计中');
     const [isError, searchDuplicateFileRes] = await searchDuplicateFile({
       sourceId: `${fileId}`,
     });
+    console.log(5151, isError)
     if (!isError) {
       typeof searchDuplicateFileRes === "string" &&
         (await tauriMessage(searchDuplicateFileRes, {
@@ -57,11 +61,13 @@ export default function CalculateListPage() {
     }
 
     if (Array.isArray(searchDuplicateFileRes)) {
+      let index = -1
       const newData: any[] = [];
       await searchDuplicateFileRes.reduce(
         async (prevPromise: any, currentFile: any) => {
           // 等待上一个 Promise 完成
           await prevPromise;
+          index++
           const ids = currentFile.ids.split(",");
           const firstItem = await get_fileInfo_by_id(ids[0], `${fileId}`);
           const otherItems = await Promise.allSettled(
@@ -88,12 +94,15 @@ export default function CalculateListPage() {
               })
               .filter((elm: any) => elm),
           });
+          setTip(`正在统计中: ${Math.floor((index / searchDuplicateFileRes.length) * 100)}% : ${searchDuplicateFileRes.length - index}`);
           return Promise.resolve(0);
         },
         Promise.resolve(0)
       );
       setData(newData);
     }
+    setLoading(false)
+    setTip('')
   };
 
   useEffect(() => {
@@ -226,10 +235,11 @@ export default function CalculateListPage() {
   }
   return (
     <div className={styles.CalculateListPage}>
-      <Spin spinning={loading}>
+      <Spin spinning={loading} tip={tip}>
         <div
           style={{
             padding: "24px",
+            minHeight: '50vh'
           }}
         >
           <Space>
@@ -280,7 +290,7 @@ export default function CalculateListPage() {
               ))}
             </div>
           </Checkbox.Group>
-          {!data.length && (
+          {!data.length && !loading && (
             <div
               style={{
                 padding: "48px 0",