Procházet zdrojové kódy

写入逻辑优化

john před 1 rokem
rodič
revize
53232d4ca3

binární
src-tauri/tauri.db


+ 14 - 13
src/pages/DuplicateFile/DuplicateFile.tsx

@@ -28,7 +28,7 @@ const { TextArea } = Input;
 export default function DuplicateFile() {
   const [usePath, setUsePath] = useState<string>();
   const [historyList, setHistoryList] = useState<historyListType[]>([]);
-  const [fileList, setFileList] = useState<insertSearchFilesPasamsType[]>([
+  const [fileList, setFileList] = useState<FileInfoType[]>([
     {
       id: 1,
       path: "D:/code/wb_project/bar_association_app",
@@ -51,6 +51,8 @@ export default function DuplicateFile() {
   const [isModalOpen, setIsModalOpen] = useState(false);
   const [fileInfo, setFileInfo] = useState<any>({});
   const [fileInfoSource, setFileInfoSource] = useState<FileInfoType>({});
+  const [current, setCurrent] = useState(1)
+  const [total, setTotal] = useState(0)
 
   const columns = [
     {
@@ -58,8 +60,8 @@ export default function DuplicateFile() {
       dataIndex: "id",
       key: "id",
       width: 30,
-      render: (text: string, record: { id: number }) => (
-        <CopyText width="30px" color="#333" name={record.id}></CopyText>
+      render: (text: string, record: { id?: number }) => (
+        <CopyText width="30px" color="#333" name={record.id || ''}></CopyText>
       ),
     },
     {
@@ -67,12 +69,12 @@ export default function DuplicateFile() {
       dataIndex: "path",
       key: "path",
       width: 300,
-      render: (text: string, record: { path: string }) => (
+      render: (text: string, record: { path?: string }) => (
         <CopyText
           width="300px"
           ellipsisLine={1}
           color="#333"
-          name={record.path}
+          name={record.path || ''}
         ></CopyText>
       ),
     },
@@ -81,12 +83,12 @@ export default function DuplicateFile() {
       dataIndex: "time",
       key: "time",
       width: 100,
-      render: (text: string, record: { time: string }) => (
+      render: (text: string, record: { time?: string }) => (
         <CopyText
           width="100px"
           ellipsisLine={1}
           color="#333"
-          name={record.time}
+          name={record.time || ''}
         ></CopyText>
       ),
     },
@@ -95,7 +97,7 @@ export default function DuplicateFile() {
       dataIndex: "time",
       key: "time",
       with: 200,
-      render: (text: string, record: { progress: number }) => (
+      render: (text: string, record: { progress?: number }) => (
         <div style={{ width: "200px" }}>
           <Progress percent={record.progress} />
         </div>
@@ -148,8 +150,8 @@ export default function DuplicateFile() {
       checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)"],
       addType: "2131231231231"
     }); */
-    /* 
-    
+    /*
+
     {path: "/Users/sysadmin/Downloads", checkedTypeValues: ["音频", "图片"], checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)"]}
 
 
@@ -171,9 +173,8 @@ Object Prototype
   }
 
   async function getFileList() {
-    const list = await get_all_history();
-    console.log(173, list);
-    const newFileList = list.map(item => {
+    const {data: dataList, total} = await get_all_history(0, 10);
+    const newFileList = dataList.map(item => {
       return {
         ...item,
         time: dayjs(item.time).format(DEFAULT_TIME_FORMAT)

+ 2 - 1
src/pages/DuplicateFile/FileInfoEditer.tsx

@@ -52,11 +52,12 @@ export default function FileInfoEditer({
       multiple: false,
       defaultPath: await appDataDir(),
     });
+    console.log(55, selected);
 
     if (selected && selected.length) {
       setFileInfo({
         ...fileInfo,
-        path: selected[0],
+        path: `${selected}`,
       });
       // setUsePath(`${selected}`);
       // 最多记录 100 条用户操作的历史数据

+ 13 - 11
src/services/file-service.ts

@@ -10,7 +10,7 @@ import { FileInfoType, historyListType, insertSearchFilesPasamsType } from "@/ty
  * @returns false 表示写入成功
  */
 export async function insertSeletedFileHistory(path?: string, fileInfoParams?: FileInfoType) {
-  /* 
+  /*
     addType: ".1231,.kidd"
     checkboxAll: true
     checkboxSizeAll: true
@@ -35,7 +35,7 @@ export async function insertSeletedFileHistory(path?: string, fileInfoParams?: F
         ":checkedTypeValues": fileInfoParams?.checkedTypeValues?.toString() || '',
         ":passType": fileInfoParams?.passType || '',
       }
-    );    
+    );
     return false;
   } catch (err) {
     if (err && `${err}`.indexOf("UNIQUE constraint failed") > -1) {
@@ -46,7 +46,7 @@ export async function insertSeletedFileHistory(path?: string, fileInfoParams?: F
 }
 
 /**
- * 
+ *
  * @param path 文件的路径
  * @returns FileInfoType
  */
@@ -58,9 +58,9 @@ export async function get_info_by_path(path: string):Promise<[FileInfoType|boole
       "SELECT * FROM select_history WHERE path = :path",
       { ":path": path }
     );
-    
+
     if(res.length) {
-      return [res[0], ""];  
+      return [res[0], ""];
     }
     return [false, "暂无数据"];
   } catch (err) {
@@ -106,14 +106,16 @@ export async function get_info_by_path(path: string):Promise<[FileInfoType|boole
 /**
  * 获取“select_history”表中的历史记录,并进行分页。
  * 此函数首先计算总记录数,然后根据提供的页码和页面大小参数返回相应的记录。
- * 
+ *
  * @param page 当前请求的页码,代表用户想要访问的数据页。
  * @param pageSize 每页展示的记录数量,决定了每次查询返回的数据条数。
  * @returns 返回一个对象,其中包含两个属性:
  *          - data: FileInfoType[] - 当前页的记录数据数组。
  *          - total: number - 表中的总记录数,用于前端计算总页数。
  */
-export async function get_all_history(page: number, pageSize: number): Promise<{ data: insertSearchFilesPasamsType[], total: number }> {
+export async function get_all_history(page: number, pageSize: number): Promise<{ data: FileInfoType[], total: number }> {
+  console.log(117, page, pageSize);
+
   await table_init(FILE_DB_PATH, "select_history");
   const DB = await SQLite.open(FILE_DB_PATH);
   // 查询总记录数
@@ -123,7 +125,7 @@ export async function get_all_history(page: number, pageSize: number): Promise<{
   const offset = (page - 1) * pageSize;
 
   // 获取当前页的数据
-  const data = await DB.queryWithArgs<Array<insertSearchFilesPasamsType>>(
+  const data = await DB.queryWithArgs<Array<FileInfoType>>(
     "SELECT * FROM select_history LIMIT ? OFFSET ?", [pageSize, offset]
   );
 
@@ -141,15 +143,15 @@ export async function get_list_by_sourceid(sourceId: number):Promise<[insertSear
       { ":sourceId": sourceId }
     );
     console.log(969696, sourceId);
-    
+
     /* const res = await DB.queryWithArgs<Array<insertSearchFilesPasamsType>>(
       "SELECT * FROM search_files WHERE sourceId = :sourceId GROUP BY hash HAVING COUNT(*) > 1",
       { ":sourceId": sourceid }
     ); */
     console.log(3434, res);
-    
+
     if(res.length) {
-      return [res, ""];  
+      return [res, ""];
     }
     return [false, "暂无数据"];
   } catch (err) {

+ 3 - 0
src/types/files.d.ts

@@ -6,6 +6,9 @@ export interface FileInfoType {
   checkedSizeValues?: unknown[];
   checkboxSizeAll?: boolean;
   checkedTypeValues?: unknown[];
+  time?: string;
+  id?: number;
+  progress?: number;
 }
 
 export interface FileInfoEditerType {