更新文件结构

This commit is contained in:
lsy 2025-01-05 21:38:27 +08:00
parent 291b8d9060
commit 2111bb54de
28 changed files with 2663 additions and 2090 deletions

50
.vscode/tasks.json vendored
View File

@ -2,75 +2,85 @@
"version": "2.0.0",
"tasks": [
{
"label": "backend",
"label": "server",
"type": "shell",
"command": "cargo run",
"options": {
"cwd": "${workspaceFolder}/backend"
"cwd": "${workspaceFolder}/server"
},
"problemMatcher": [
"$armcc5"
"$rustc"
]
},
{
"label": "backend-fmt",
"label": "server-fmt",
"type": "shell",
"command": "cargo fmt",
"options": {
"cwd": "${workspaceFolder}/backend"
"cwd": "${workspaceFolder}/server"
},
"problemMatcher": []
},
{
"label": "frontend-dev",
"label": "client-dev",
"type": "shell",
"command": "dx serve",
"options": {
"cwd": "${workspaceFolder}/frontend"
"cwd": "${workspaceFolder}/client"
},
"problemMatcher": []
},
{
"label": "frontend-start",
{
"label": "client-start",
"type": "shell",
"command": "serve .",
"options": {
"cwd": "${workspaceFolder}/frontend/target/dx/frontend/release/web/public"
"cwd": "${workspaceFolder}/client/target/dx/client/release/web/public"
},
"problemMatcher": []
},
{
"label": "frontend-build",
"label": "client-build",
"type": "shell",
"command": "dx build --release",
"options": {
"cwd": "${workspaceFolder}/frontend"
"cwd": "${workspaceFolder}/client"
},
"problemMatcher": []
},
{
"label": "frontend-tailwind-build",
"label": "client-tailwind-build",
"type": "shell",
"command": "npx tailwindcss -i ./tailwind.css -o ./assets/styling/tailwind.css",
"options": {
"cwd": "${workspaceFolder}/frontend"
"cwd": "${workspaceFolder}/client"
},
"problemMatcher": []
},
{
"label": "frontend-fmt",
"label": "client-fmt",
"type": "shell",
"command": "cargo fmt",
"options": {
"cwd": "${workspaceFolder}/frontend"
"cwd": "${workspaceFolder}/client"
},
"problemMatcher": []
},
{
"label": "common-fmt",
"type": "shell",
"command": "cargo fmt",
"options": {
"cwd": "${workspaceFolder}/common"
},
"problemMatcher": []
},
{
"label": "format-all",
"dependsOn": [
"backend-fmt",
"frontend-fmt"
"server-fmt",
"client-fmt",
"common-fmt"
],
"dependsOrder": "parallel",
"problemMatcher": []
@ -78,8 +88,8 @@
{
"label": "run-all",
"dependsOn": [
"backend",
"frontend-dev"
"server",
"client-dev"
],
"dependsOrder": "parallel",
"group": {

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
[package]
name = "frontend"
[workspace]
members = ["client", "server", "common"]
[workspace.package]
version = "0.1.0"
authors = ["lsy <lsy22@vip.qq.com>"]
edition = "2021"
authors = ["lsy <lsy22@vip.qq.com>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[workspace.dependencies]
dioxus = { version = "0.6.0", features = ["router"] }
dioxus-free-icons = { version = "0.9", features = ["bootstrap"] }
wasm-bindgen = "0.2.99"
@ -15,13 +15,10 @@ web-sys = { version = "0.3.76", features = ["Window","Storage","MediaQueryList",
js-sys = "0.3.76"
rand = "0.8.5"
getrandom = { version = "0.2", features = ["js"] }
[features]
default = ["dioxus/web"]
web = ["dioxus/web"]
desktop = ["dioxus/desktop"]
mobile = ["dioxus/mobile"]
rocket = "0.5.0"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.0", features = ["full"] }
surrealdb = "2.1.4"
[profile]

17
client/Cargo.toml Normal file
View File

@ -0,0 +1,17 @@
[package]
name = "client"
version.workspace = true
edition.workspace = true
authors.workspace = true
[dependencies]
common = { path = "../common" }
dioxus = { workspace = true, features = ["web", "router"] }
dioxus-free-icons = { workspace = true }
wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }
web-sys = { workspace = true }
js-sys = { workspace = true }
rand = { workspace = true }
getrandom = { workspace = true }
serde = { workspace = true }

View File

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View File

@ -1,7 +1,7 @@
use std::format;
use crate::common::dom::add_element_class;
use crate::common::helps::generate_random_string;
use crate::utils::dom::add_element_class;
use common::helps::generate_random_string;
use crate::Route;
use dioxus::{logger::tracing, prelude::*};
use dioxus_free_icons::icons::bs_icons::{BsCheckCircle, BsInfoCircle, BsXCircle, BsXLg};

View File

@ -1,4 +1,4 @@
use crate::common::dom::{
use crate::utils::dom::{
add_element_class, get_local_storage_value, get_media_theme, remove_element_class,
remove_local_storage_value, set_local_storage_value,
};

View File

@ -1,14 +1,15 @@
use dioxus::{logger::tracing, prelude::*};
use wasm_bindgen::prelude::*;
mod common;
use common::dom::{add_element_class, get_media_theme, remove_element_class};
mod utils;
mod components;
mod views;
use utils::dom::{add_element_class, get_media_theme, remove_element_class};
use components::notification::{Notification, NotificationProvider};
use components::theme_toggle::{get_theme, ThemeProvider};
use components::Navbar;
use views::Home;
mod components;
mod views;
#[derive(Debug, Clone, Routable, PartialEq)]
enum Route {

View File

@ -2,7 +2,7 @@ use super::error::{CustomErrorInto, CustomResult};
use web_sys::{window, Document, Element, Storage, Window};
fn get_window() -> CustomResult<Window> {
Ok(window().ok_or("浏览器window对象不存在")?)
Ok(window().ok_or("浏览器window对象不存在".into_custom_error())?)
}
fn get_storage() -> CustomResult<Storage> {
@ -57,6 +57,6 @@ pub fn remove_element_class(ele_name: &str, class_name: &str) -> CustomResult<()
pub fn remove_element(ele_name: &str) -> CustomResult<()> {
let e = get_element(ele_name)?;
let _ = e.parent_node().ok_or("无法获取父节点")?.remove_child(&e)?;
let _ = e.parent_node().ok_or("无法获取父节点".into_custom_error())?.remove_child(&e)?;
Ok(())
}

View File

@ -1,13 +1,7 @@
use wasm_bindgen::JsValue;
use common::error::CommonError;
#[derive(Debug)]
pub struct CustomError(String);
impl std::fmt::Display for CustomError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
pub struct CustomError(pub String);
pub trait CustomErrorInto {
fn into_custom_error(self) -> CustomError;
@ -19,9 +13,10 @@ impl CustomErrorInto for &str {
}
}
impl From<std::io::Error> for CustomError {
fn from(error: std::io::Error) -> Self {
CustomError(error.to_string())
impl From<CommonError> for CustomError {
fn from(error: CommonError) -> Self {
CustomError(error.0)
}
}
@ -35,10 +30,5 @@ impl From<JsValue> for CustomError {
}
}
impl From<&str> for CustomError {
fn from(error: &str) -> Self {
CustomError(error.to_string())
}
}
pub type CustomResult<T> = Result<T, CustomError>;

View File

@ -1,3 +1,2 @@
pub mod dom;
pub mod error;
pub mod helps;

8
common/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "common"
version.workspace = true
edition.workspace = true
authors.workspace = true
[dependencies]
rand = { workspace = true }

26
common/src/error.rs Normal file
View File

@ -0,0 +1,26 @@
#[derive(Debug)]
pub struct CommonError(pub String);
impl std::fmt::Display for CommonError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<std::io::Error> for CommonError {
fn from(error: std::io::Error) -> Self {
CommonError(error.to_string())
}
}
impl From<String> for CommonError {
fn from(error: String) -> Self {
CommonError(error)
}
}
impl From<&str> for CommonError {
fn from(error: &str) -> Self {
CommonError(error.to_string())
}
}

2
common/src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod error;
pub mod helps;

12
server/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "server"
version.workspace = true
edition.workspace = true
authors.workspace = true
[dependencies]
common = { path = "../common" }
rocket = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
surrealdb = { workspace = true }

31
server/src/main.rs Normal file
View File

@ -0,0 +1,31 @@
mod utils;
use rocket::{get, routes};
use surrealdb;
use utils::error::CustomResult;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}
#[get("/api/theme")]
fn get_theme() -> &'static str {
"light"
}
struct Appstate{
}
#[rocket::main]
async fn main() -> CustomResult<()> {
let rocket_build = rocket::build();
let rocket = rocket_build
.mount("/", routes![index, get_theme])
.ignite().await?;
rocket.launch().await?;
std::process::exit(0);
}

30
server/src/utils/error.rs Normal file
View File

@ -0,0 +1,30 @@
use common::error::CommonError;
use rocket;
#[derive(Debug)]
pub struct CustomError(pub String);
pub trait CustomErrorInto {
fn into_custom_error(self) -> CustomError;
}
impl CustomErrorInto for &str {
fn into_custom_error(self) -> CustomError {
CustomError(self.to_string())
}
}
impl From<CommonError> for CustomError {
fn from(error: CommonError) -> Self {
CustomError(error.0)
}
}
impl From<rocket::Error> for CustomError {
fn from(error: rocket::Error) -> Self {
CustomError(error.to_string())
}
}
pub type CustomResult<T> = Result<T, CustomError>;

1
server/src/utils/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod error;