瀏覽代碼

获取文件的hash

John-Hong 2 年之前
父節點
當前提交
04e1942d59
共有 2 個文件被更改,包括 16 次插入9 次删除
  1. 6 5
      src-tauri/src/event_loop.rs
  2. 10 4
      src/pages/FileSort/FileSort.tsx

+ 6 - 5
src-tauri/src/event_loop.rs

@@ -81,7 +81,7 @@ use std::{fs, io};
 #[derive(Debug)]
 struct UseHashInfoStruct {
     path: String,
-    processed: u64,
+    processed: String,
     hash: String,
 }
 
@@ -97,14 +97,15 @@ fn get_file_hase(path: &str) -> UseHashInfoStruct {
     // println!("Hash value: {}", hash_str);
     let info = UseHashInfoStruct {
         path: file_path.to_string(),
-        processed: n,
+        processed: format!("{:x}", n),
         hash: hash_str,
     };
     info
 }
 
 #[tauri::command(name = "file_sort")]
-pub fn file_sort(path: &str) {
-    let hash_info: UseHashInfoStruct = get_file_hase(&path);
-    println!("{:?}", hash_info)
+pub fn file_sort(path: &str) -> String {
+    let hash_info = get_file_hase(&path);
+    println!("{:?}", hash_info.path);
+    format!("{{ 'path': {},'processed': {},'hash': {} }}`", hash_info.path, hash_info.processed, hash_info.hash)
 }

+ 10 - 4
src/pages/FileSort/FileSort.tsx

@@ -1,22 +1,28 @@
 import styles from "./FileSort.module.less";
-import { Button } from "antd";
+import { Button, Card } from "antd";
 import { invoke } from "@tauri-apps/api/tauri";
 import { open } from "@tauri-apps/api/dialog";
+import { useState } from "react";
 export default function FileSort() {
+  const [fileStr, setFile] = useState<string[]>([]);
   async function sort() {
-
     const selected = await open({
       directory: false,
-        multiple: false,
+      multiple: false,
       //   defaultPath: await appDataDir(),
     });
-    await invoke("file_sort", {path: selected});
+    setFile([...fileStr, await invoke("file_sort", { path: selected })]);
   }
   return (
     <div className={styles.FileSortBox}>
       {/* <div style={{ backgroundColor: "green", height: "200vh" }}>FileClear</div> */}
       <div>
         <Button onClick={() => sort()}>Sort</Button>
+        <div>
+          {fileStr.map((item) => (
+            <Card key={item}>{item}</Card>
+          ))}
+        </div>
       </div>
     </div>
   );