John-Hong 2 rokov pred
rodič
commit
1922d61877

+ 2 - 0
src-tauri/Cargo.lock

@@ -2680,11 +2680,13 @@ dependencies = [
 name = "tauri-app"
 version = "0.0.1"
 dependencies = [
+ "regex",
  "serde",
  "serde_json",
  "sqlite",
  "tauri",
  "tauri-build",
+ "uuid 1.2.2",
 ]
 
 [[package]]

+ 2 - 0
src-tauri/Cargo.toml

@@ -24,6 +24,8 @@ tauri = {version = "1.2", features = ["api-all"] }
 #tensorflow-sys = { version = "0.22.1", features = ["tensorflow_gpu"] }
 #tensorflow = { version = "0.19.1", features = ["tensorflow_gpu"] }
 #tensorflow-sys = "0.22.1"
+uuid = "1.2.2"
+regex = "1.7.0"
 
 [workspace]
 members = ["modules"]

+ 72 - 5
src-tauri/src/event_loop/mod.rs

@@ -1,11 +1,78 @@
-// 这里先放基础类型数据,如果不够的话再按模块拆分
 
-#[tauri::command]
+
+// 这里先放基础类型数据,如果不够的话再按模块拆分
+#[tauri::command(name = "greet")]
 pub fn greet(name: &str) -> String {
     format!("Hello, {}! You've been greeted from Rust!", name)
 }
 
-#[tauri::command]
-pub fn file_path(name: &str) -> String {
-    format!("{}", name)
+#[tauri::command(name = "file_path")]
+pub fn file_path(name: &str, parentid: &str) -> String {
+    println!("1111111");
+    // use std::fs;
+    use uuid::Uuid;
+    // #[macro_use]
+    // extern crate lazy_static;
+    extern crate regex;
+    use std::path::Path;
+    use crate::files::file_sqlite3::file_sqlite3::{inset, is_create};
+    use crate::files::file_struct::File;
+    use std::time::SystemTime;
+    // 生成 UUID
+    let uuid = Uuid::new_v4();
+   
+    let err = is_create("files");
+    println!("2424  {}", err);
+    // let parent = "".to_string();
+    // let mut parent_id: String = "".to_string();
+    // if parentid.len() > 0 {
+    //    parent_id = parentid.to_string();
+    // }
+
+    let system_time = SystemTime::now();
+    let timestamp = system_time
+        .duration_since(SystemTime::UNIX_EPOCH)
+        .expect("Failed to get timestamp");
+        
+    let filepath = Path::new(name);
+    // 获取路径的最后一个部分(即用户名)
+    let filename: String = filepath.file_name().unwrap().to_str().unwrap().to_string();
+    println!("38383838383 {}, {}", filename, parentid);
+    let file = File {
+        name: filename.to_string(),
+        path: name.to_string(),
+        history_path: name.to_string(),
+        uuid: uuid.to_string(),
+        parent_id: parentid.to_string(),
+        create_time: timestamp,
+        update_time: timestamp,
+        file_type: name.to_string(),
+        user: name.to_string(),
+        rule: name.to_string(),
+    };
+    inset(file);
+
+    // 获取当前目录中的文件和目录
+    // let entries = fs::read_dir(name).unwrap();
+    // for entry in entries {
+    //     // 获取目录的详细信息
+    //     let dir = entry.unwrap();
+    //      // 判断是否为目录
+    //     if dir.file_type().unwrap().is_dir() {
+    //         // 输出目录的名称
+    //         // println!("{} is a directory", dir.file_name().to_string_lossy());
+    //         // 如果是目录的话
+    //         let path = format!("{}/{}", name, dir.file_name().to_string_lossy());
+    //         file_path(&path);
+    //     } else {
+    //         // 输出目录的名称
+    //         println!("{}", dir.file_name().to_string_lossy());
+    //     }
+
+    // }
+
+    let res = format!("{}", name);
+    // // println!("Message from Rust: {}", res);
+    res
+    // "files"
 }

+ 21 - 4
src-tauri/src/files/file_sqlite3.rs

@@ -5,23 +5,30 @@ pub mod file_sqlite3 {
             return false;
         }
         let connection = sqlite::open("tauri.db").unwrap();
-        let query: String = format!("SELECT tbl_name FROM sqlite_master WHERE tbl_name = '{}'", table_name);
+        let query: String = format!(
+            "SELECT tbl_name FROM sqlite_master WHERE tbl_name = '{}'",
+            table_name
+        );
         let mut is_table: bool = false;
         connection
             .iterate(query, |pairs| {
                 for &(_tpl_name, value) in pairs.iter() {
-                    // println!("27__ {} = {}", tpl_name, value.unwrap());
-                    if  value.unwrap() == table_name {
+                    if value.unwrap() == table_name {
                         is_table = true
                     }
                 }
                 true
             })
             .unwrap();
+        // is_table
+        if !is_table {
+            return create(table_name);
+        }
         is_table
     }
 
-    pub fn create (table_name: &str) -> bool {
+    pub fn create(table_name: &str) -> bool {
+        println!("28");
         if table_name.len() < 1 {
             return false;
         }
@@ -29,6 +36,16 @@ pub mod file_sqlite3 {
         // CREATE TABLE users (name TEXT, age INTEGER)
         let query: String = format!("CREATE TABLE '{}' ( name TEXT, path TEXT, history_path TEXT, uuid TEXT, parent_id TEXT, create_time INTEGER, update_time INTEGER, file_type TEXT, user TEXT, rule TEXT );", table_name);
         // let mut isTable: bool = false;
+        println!("36");
+        connection.execute(query).unwrap();
+        true
+    }
+
+    use crate::files::file_struct::File;
+    pub fn inset(file: File) -> bool {
+        // INSERT INTO files (name, path, history_path, uuid, parent_id, create_time, update_time, file_type, user, rule) VALUES ('1', '1', '2', '3', '4', 5, null, null, null, null)
+        let query: String = format!("INSERT INTO files (name, path, history_path, uuid, parent_id, create_time, update_time, file_type, user, rule) VALUES ('{}', '{}', '{}', '{}', '{}', '{:?}', '{:?}', '{}', '{}', '{}')", file.name, file.path, file.history_path,  file.uuid, file.parent_id, file.create_time, file.update_time, file.file_type, file.user, file.rule);
+        let connection = sqlite::open("tauri.db").unwrap();
         connection.execute(query).unwrap();
         true
     }

+ 19 - 0
src-tauri/src/files/file_struct.rs

@@ -5,8 +5,27 @@
 //     }
 // }
 
+use std::time::Duration;
+
 #[derive(Debug)]
 pub struct Site {
     pub domain: String,
     pub nation: String,
 }
+
+
+// name TEXT, path TEXT, history_path TEXT, uuid TEXT, parent_id TEXT, create_time INTEGER, update_time INTEGER, file_type TEXT, user TEXT, rule TEXT
+
+#[derive(Debug)]
+pub struct File {
+    pub name: String,
+    pub path: String,
+    pub history_path: String,
+    pub uuid: String,
+    pub parent_id: String,
+    pub create_time: Duration,
+    pub update_time: Duration,
+    pub file_type: String,
+    pub user: String,
+    pub rule: String,
+}

+ 0 - 3
src-tauri/src/files/file_tools.rs

@@ -1,6 +1,3 @@
-// pub struct Site;
-// mod FileStruct::{Site};
-
 pub mod file_tools {
     use crate::files::file_struct::Site;
     pub fn get_base_path () -> Site {

+ 2 - 0
src-tauri/src/main.rs

@@ -1,12 +1,14 @@
 #![cfg_attr(all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows")]
 
 mod files;
+// use crate::files::{file_struct, file_tools};
 mod menus;
 mod event_loop;
 use crate::menus::default::use_memu;
 use crate::menus::event::m_event;
 use crate::event_loop::{greet, file_path};
 
+
 fn main() {
     tauri::Builder::default()
         .menu(use_memu())

+ 6 - 1
src-tauri/tauri.conf.json

@@ -12,7 +12,12 @@
 
   "tauri": {
     "allowlist": {
-      "all": true
+      "all": true,
+      "dialog": {
+        "all": true, 
+        "open": true,
+        "save": true
+      }
     },
     "bundle": {
       "active": true,

BIN
src-tauri/tauri.db


+ 5 - 1
src/Router.tsx

@@ -3,11 +3,15 @@ import {Routes, Route, Outlet, Link} from "react-router-dom";
 import Layout from '@/components/Layout/Layout'
 import Home from '@/pages/Home/Home';
 import About from "@/pages/About/About";
+import Finder from "@/pages/Finder/Finder";
 export default function Router() {
   return <Routes>
     <Route path="/" element={<Layout/>}>
-      <Route index element={<Home />} />
+      <Route index element={<Finder />} />
       <Route path={"about"} element={<About />} />
+      <Route path={"finder"} element={<Finder />} />
+      <Route path={"home"} element={<Home />} />
+      {/*<Route index element={<Home />} />*/}
     </Route>
   </Routes>
 }

+ 52 - 0
src/pages/Finder/Finder.tsx

@@ -0,0 +1,52 @@
+import {useEffect, useState} from "react";
+import {invoke} from "@tauri-apps/api/tauri";
+// import {file} from "@tauri-apps/api/tauri";
+
+import { open, message } from '@tauri-apps/api/dialog';
+import { tauri } from "@tauri-apps/api";
+// import { appDataDir } from '@tauri-apps/api/path';
+
+export default function Finder() {
+	const [selectPath, setSelectPath] = useState<string>('')
+	useEffect(() => {
+	if(selectPath) {
+
+	}
+	}, [selectPath])
+	async function selectDirectory() {
+
+		const selected = await open({
+		  directory: true,
+		//   multiple: true,
+		//   defaultPath: await appDataDir(),
+		});
+		
+		if (Array.isArray(selected)) {
+			setSelectPath(selected.toString());	
+		  // user selected multiple directories
+		} else if (selected === null) {
+		  // user cancelled the selection
+		} else {
+		  // user selected a single directory
+		  setSelectPath(selected);
+
+		//   const result = await tauri.execute({
+		// 	cmd: 'myCommand',
+		// 	args: ['arg1 value', 123]
+		//   })
+		   await invoke('file_path', {name: selected, parentid: ''})
+		//   file_path
+		}
+	}
+
+	return (
+		<div>
+			<div>finder</div>
+			<button onClick={() => selectDirectory()}>run</button>
+			<div>selectPath:</div>
+			<div>
+				{selectPath}
+			</div>
+		</div>
+	)
+}

+ 9 - 1
src/pages/Home/Home.tsx

@@ -1,4 +1,4 @@
-import {useState, useCallback} from "react";
+import {useState, useCallback, useEffect} from "react";
 import reactLogo from "../../assets/react.svg";
 import {invoke} from "@tauri-apps/api/tauri";
 // import {createDir, BaseDirectory} from '@tauri-apps/api/fs';
@@ -11,6 +11,14 @@ function Home() {
   const [name, setName] = useState("");
   const [filePath, setFilePath] = useState("");
 
+  useEffect(() => {
+    init();
+  }, [])
+
+  async function init() {
+    const files = await invoke('file_path', {name: '/'})
+    console.log(20, files);
+  }
   // const inputOther:InputHTMLAttributes
 
   async function greet() {