John 1 год назад
Родитель
Сommit
72f24587c2

+ 1 - 1
package.json

@@ -21,7 +21,7 @@
     "react-dom": "^18.3.1",
     "react-router": "^6.23.1",
     "react-router-dom": "^6.23.1",
-    "tauri-plugin-sql-api": "https://github.com/tauri-apps/tauri-plugin-sql#v1"
+    "tauri-plugin-sql-api": "https://github.com/Johnhong9527/tauri-plugin-sql.git#v1"
   },
   "devDependencies": {
     "@rollup/plugin-alias": "^5.1.0",

+ 1 - 1
src-tauri/Cargo.lock

@@ -4398,7 +4398,7 @@ dependencies = [
 [[package]]
 name = "tauri-plugin-sql"
 version = "0.0.0"
-source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#bd3d9ca152ee8b55e3e669dac68476ce6150c57f"
+source = "git+https://github.com/Johnhong9527/plugins-workspace?branch=v1#0d649843c6b49b7a69200816c8d5195f9953a4fb"
 dependencies = [
  "futures-core",
  "log",

+ 1 - 1
src-tauri/Cargo.toml

@@ -34,7 +34,7 @@ home = "0.5.9"
 trash = "1.3"
 
 [dependencies.tauri-plugin-sql]
-git = "https://github.com/tauri-apps/plugins-workspace"
+git = "https://github.com/Johnhong9527/plugins-workspace"
 branch = "v1"
 features = ["sqlite"] # or "postgres", or "mysql"
 

+ 4 - 0
src-tauri/src/self_plugin/tauri_plugin_file/files.rs

@@ -279,20 +279,24 @@ pub fn get_file_info(file_path: String) -> Result<FileInfos> {
 pub struct RequestMvFile {
     code: Option<u64>,
     msg: Option<String>,
+    data: Option<String>,
 }
 
 #[command]
 pub fn mv_file_to_trash(file_path: String) -> RequestMvFile {
+    let data = file_path.clone();
     if let Err(e) = trash::delete(file_path) {
         RequestMvFile {
             code: Some(500),
             msg: Some(format!("Error moving file to trash: {}", e)),
+            data: Some(format!("{}", data)),
         }
     } else {
         println!("File successfully moved to trash.");
         RequestMvFile {
             code: Some(200),
             msg: Some("File successfully moved to trash.".to_string()),
+            data: Some(format!("{}", data)),
         }
     }
 }

+ 8 - 2
src/components/Table/CopyText.tsx

@@ -52,10 +52,16 @@ export function CopyText({
     </div>
   );
 
-  return isTruncated ? <Tooltip placement="top" title={(
+  /* return isTruncated ? <Tooltip placement="top" title={(
     <div>
         <div>点记复制全文:</div>
         {name}
     </div>
-  )}>{content}</Tooltip> : content;
+  )}>{content}</Tooltip> : content; */
+  return <Tooltip placement="top" title={(
+    <div>
+        <div>点记复制全文:</div>
+        {name}
+    </div>
+  )}>{content}</Tooltip>;
 }

+ 1 - 0
src/databases/createTableSql.ts

@@ -10,6 +10,7 @@ export const createSql = {
         checkedSizeValues TEXT,
         checkboxSizeAll INTEGER NOT NULL CHECK (checkboxSizeAll IN (0, 1)),
         checkedTypeValues TEXT,
+        files INTEGER,
         UNIQUE (path)
     );`,
     search_files: `CREATE TABLE IF NOT EXISTS search_files (

+ 13 - 2
src/pages/DuplicateFile/CalculateDuplicateFiles.tsx

@@ -7,6 +7,7 @@ import {
   updateSelectedFileHistory,
   insertSearchFiles,
   searchDuplicateFile,
+  updateSelectedFileHistoryFiles,
 } from "@/services";
 import { useEffect, useState } from "react";
 import { useNavigate, useParams } from "react-router-dom";
@@ -88,12 +89,15 @@ export default function CalculateDuplicateFiles() {
   async function scanDirAll() {
     // const aabb = await get_progress_by_sourceId(`${fileId}`);
     // console.log(737373, aabb);
-
+    // const progressRes = await get_progress_by_sourceId(fileId || '')
+    // console.log(93, progressRes, fileInfo);
+    
     // return
 
     // navigate('/calculate-list/' + fileId)
     if (fileInfo.path) {
       // 扫描目录文件
+      console.log('扫描目录文件 开始');
       setStepsStatus({
         ...stepsStatus,
         scanDir: "process",
@@ -111,11 +115,17 @@ export default function CalculateDuplicateFiles() {
         types,
       });
       setPercent(100);
+      console.log('扫描目录文件 结束');
+
+      
 
-      // console.log(636363, files);
+      console.log(118, files);
 
       // 计算文件属性
+      console.log('计算文件属性 开始');
       if (files.length) {
+        // 更新当前查询目录的总文件数目
+        await updateSelectedFileHistoryFiles(fileInfo.path, files.length, )
         setStepsStatus({
           ...stepsStatus,
           scanDir: "finish",
@@ -152,6 +162,7 @@ export default function CalculateDuplicateFiles() {
           },
           Promise.resolve(0)
         );
+        console.log('计算文件属性 结束');
         setPercent(100);
         await waittime(1000);
         // 计算文件具体内容

+ 22 - 0
src/pages/DuplicateFile/CalculateListPage.module.less

@@ -1,4 +1,26 @@
 .CalculateListPage {
   background-color: #99999908;
+  .CheckboxGroup {
+    margin-bottom: 12px;
+    width: 100%;
+    .CheckboxContent {
+      display: flex;
+      .path {
+        // width: 300px;
+        color: black;
+      }
+      .modified_time {
+        margin-left: 20px;
+      }
+      &:hover {
+        transition: all ease-in-out .2s;
+        background-color: var(--color-1);
+        padding: 0 2px;
+      }
+    }
+    /* backgroundColor: "var(--color-1)", */
+  
+  }
+  
   
 }

+ 60 - 19
src/pages/DuplicateFile/CalculateListPage.tsx

@@ -12,6 +12,7 @@ import { useParams } from "react-router";
 import { insertSearchFilesPasamsType } from "@/types/files";
 import type { GetProp } from "antd";
 import File from "@/plugins/tauri-plugin-file/file";
+import { CopyText } from "@/components/Table/CopyText";
 
 export default function CalculateListPage() {
   let { fileId } = useParams();
@@ -63,6 +64,7 @@ export default function CalculateListPage() {
             otherItems: otherItems
               .map((elm) => {
                 if (elm.status === "fulfilled" && !elm.value[1]) {
+                  setRemoveList()
                   return elm.value[0];
                 }
                 return false;
@@ -81,35 +83,72 @@ export default function CalculateListPage() {
     appendData();
   }, []);
 
-  const onChange: GetProp<typeof Checkbox.Group, "onChange"> = (
-    checkedValues
+  const onChange = (
+    checkedValues: string[]
   ) => {
     console.log("checked = ", checkedValues);
     if (Array.isArray(checkedValues)) {
       // setRemoveList(checkedValues.filter(elm => typeof elm === 'string'));
-      // setRemoveList(checkedValues)
+      setRemoveList(checkedValues)
     }
     // value={removeList}
   };
 
   const CheckboxContent = (item: insertSearchFilesPasamsType) => (
-    <div>{item.path}</div>
+    <div className={styles.CheckboxContent}>
+      <div className={styles.path}>
+        <CopyText width="300px" color="#333" ellipsisLine={1} name={item.path || ''}></CopyText>
+      </div>
+      <div className={styles.modified_time}>
+        <CopyText width="100px" color="#333" name={item.modified_time || ''}></CopyText>
+      </div>
+      <div className={styles.modified_time}>
+        <CopyText width="100px" color="#333" name={item.file_size || ''}></CopyText>
+      </div>
+      <div className={styles.modified_time}>
+        <CopyText width="100px" color="#333" ellipsisLine={1} name={item.name || ''}></CopyText>
+      </div>
+    </div>
   );
 
   async function removeFilesByDB() {
-    const filesRes = await File.rmFile(
-      "/Users/sysadmin/Pictures/test/欧洲4_副本5.jpeg"
-    );
-    console.log(9797, filesRes);
-    if (filesRes.code === 200) {
-      await del_file_by_id(
-        "/Users/sysadmin/Pictures/test/欧洲4_副本5.jpeg",
-        "24"
-      );
-      message.success('删除成功!')
+    const filesRes = await Promise.allSettled(removeList.map(path => File.rmFile(path)))
+    if(removeList.length === 1) {
+      console.log(106, filesRes);
+      if(filesRes[0].status === "fulfilled" && filesRes[0].value.code === 200) {
+        setRemoveList([])
+        del_file_by_id(
+          removeList[0],
+          `${fileId}`
+        );
+        message.success(`${removeList[0]} 删除成功!`)
+        appendData();
+        return
+      } 
+      await tauriMessage(removeList[0], {
+        title: "删除失败",
+        type: "error",
+      });
+    }
+    const rmSuccess = filesRes.filter(res => {
+      console.log(116, res);
+      return res.status === 'fulfilled' && res.value.code === 200
+    })
+    if (rmSuccess.length) {
+      await rmSuccess.reduce(async(prev: any, item: any)=> {
+        await prev();
+        console.log(119, item.value.data);
+        
+        return del_file_by_id(
+          item.value.data,
+          `${fileId}`
+        );
+      }, Promise.resolve(0));
+      message.success( `${rmSuccess.length}个文件删除成功! ${filesRes.length - rmSuccess.length}个文件删除失败!`)
+      appendData();
       return;
     }
-    await tauriMessage(filesRes.msg, {
+    await tauriMessage('当前操作异常,请重新尝试!', {
       title: "删除失败",
       type: "error",
     });
@@ -130,25 +169,27 @@ export default function CalculateListPage() {
           <Button type="primary">导出</Button>
         </Space>
         <div style={{ marginBottom: "12px" }}></div>
-        <Checkbox.Group onChange={onChange} style={{ width: "100%" }}>
+        <Checkbox.Group onChange={onChange} style={{ width: "100%" }} value={removeList}>
           <div style={{ width: "100%" }}>
             {data.map((item: FileItem) => (
               <div
                 key={item.hash}
                 style={{
-                  marginBottom: "12px",
+                  backgroundColor: 'var(--color-2)',
+                  marginBottom: '24px'
                 }}
               >
-                <div>
+                <div className={styles.CheckboxGroup}>
                   <Checkbox value={item.firstItem.path}>
                     {CheckboxContent(item.firstItem)}
                   </Checkbox>
                 </div>
                 <div
                   style={{
-                    backgroundColor: "var(--color-1)",
+                    border: '1px solid var(--color-1)',
                     padding: "12px 3px",
                   }}
+                  className={styles.CheckboxGroup}
                 >
                   {item.otherItems.map((otherItem) => (
                     <div key={otherItem.path}>

+ 27 - 0
src/services/file-service.ts

@@ -90,6 +90,33 @@ export async function updateSelectedFileHistory(
   }
 }
 
+export async function updateSelectedFileHistoryFiles(
+  path: string,
+  filesNum: number
+) {
+  try {
+    const DB = await Database.load("sqlite:files.db");
+    // 创建表
+    await DB.execute(createSql.select_history);
+    const result = await DB.execute(
+      `UPDATE select_history 
+             SET files = $1
+             WHERE path = $2;`,
+      [
+        filesNum,
+        path, // 假设 path 变量是预定义的
+      ]
+    );
+    return false;
+  } catch (error) {
+    console.log(595959, error);
+    if (error && `${error}`.indexOf("UNIQUE constraint failed") > -1) {
+      return "当前数据格式异常";
+    }
+    return error;
+  }
+}
+
 /**
  *
  * @param path 文件的路径

+ 2 - 2
yarn.lock

@@ -1606,9 +1606,9 @@ supports-color@^5.3.0:
   dependencies:
     has-flag "^3.0.0"
 
-"tauri-plugin-sql-api@https://github.com/tauri-apps/tauri-plugin-sql#v1":
+"tauri-plugin-sql-api@https://github.com/Johnhong9527/tauri-plugin-sql.git#v1":
   version "0.0.0"
-  resolved "https://github.com/tauri-apps/tauri-plugin-sql#6a4a14c36b1ad49c9f468351706d104a54e0540c"
+  resolved "https://github.com/Johnhong9527/tauri-plugin-sql.git#6a4a14c36b1ad49c9f468351706d104a54e0540c"
   dependencies:
     "@tauri-apps/api" "1.5.6"