更新文件结构
This commit is contained in:
parent
291b8d9060
commit
2111bb54de
50
.vscode/tasks.json
vendored
50
.vscode/tasks.json
vendored
@ -2,75 +2,85 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"label": "backend",
|
"label": "server",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cargo run",
|
"command": "cargo run",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/backend"
|
"cwd": "${workspaceFolder}/server"
|
||||||
},
|
},
|
||||||
"problemMatcher": [
|
"problemMatcher": [
|
||||||
"$armcc5"
|
"$rustc"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "backend-fmt",
|
"label": "server-fmt",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cargo fmt",
|
"command": "cargo fmt",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/backend"
|
"cwd": "${workspaceFolder}/server"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "frontend-dev",
|
"label": "client-dev",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "dx serve",
|
"command": "dx serve",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/frontend"
|
"cwd": "${workspaceFolder}/client"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "frontend-start",
|
"label": "client-start",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "serve .",
|
"command": "serve .",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/frontend/target/dx/frontend/release/web/public"
|
"cwd": "${workspaceFolder}/client/target/dx/client/release/web/public"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "frontend-build",
|
"label": "client-build",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "dx build --release",
|
"command": "dx build --release",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/frontend"
|
"cwd": "${workspaceFolder}/client"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "frontend-tailwind-build",
|
"label": "client-tailwind-build",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "npx tailwindcss -i ./tailwind.css -o ./assets/styling/tailwind.css",
|
"command": "npx tailwindcss -i ./tailwind.css -o ./assets/styling/tailwind.css",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/frontend"
|
"cwd": "${workspaceFolder}/client"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "frontend-fmt",
|
"label": "client-fmt",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cargo fmt",
|
"command": "cargo fmt",
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/frontend"
|
"cwd": "${workspaceFolder}/client"
|
||||||
|
},
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "common-fmt",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cargo fmt",
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceFolder}/common"
|
||||||
},
|
},
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "format-all",
|
"label": "format-all",
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"backend-fmt",
|
"server-fmt",
|
||||||
"frontend-fmt"
|
"client-fmt",
|
||||||
|
"common-fmt"
|
||||||
],
|
],
|
||||||
"dependsOrder": "parallel",
|
"dependsOrder": "parallel",
|
||||||
"problemMatcher": []
|
"problemMatcher": []
|
||||||
@ -78,8 +88,8 @@
|
|||||||
{
|
{
|
||||||
"label": "run-all",
|
"label": "run-all",
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"backend",
|
"server",
|
||||||
"frontend-dev"
|
"client-dev"
|
||||||
],
|
],
|
||||||
"dependsOrder": "parallel",
|
"dependsOrder": "parallel",
|
||||||
"group": {
|
"group": {
|
||||||
|
4509
frontend/Cargo.lock → Cargo.lock
generated
4509
frontend/Cargo.lock → Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[workspace]
|
||||||
name = "frontend"
|
members = ["client", "server", "common"]
|
||||||
|
|
||||||
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["lsy <lsy22@vip.qq.com>"]
|
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
authors = ["lsy <lsy22@vip.qq.com>"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[workspace.dependencies]
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
dioxus = { version = "0.6.0", features = ["router"] }
|
dioxus = { version = "0.6.0", features = ["router"] }
|
||||||
dioxus-free-icons = { version = "0.9", features = ["bootstrap"] }
|
dioxus-free-icons = { version = "0.9", features = ["bootstrap"] }
|
||||||
wasm-bindgen = "0.2.99"
|
wasm-bindgen = "0.2.99"
|
||||||
@ -15,13 +15,10 @@ web-sys = { version = "0.3.76", features = ["Window","Storage","MediaQueryList",
|
|||||||
js-sys = "0.3.76"
|
js-sys = "0.3.76"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
getrandom = { version = "0.2", features = ["js"] }
|
getrandom = { version = "0.2", features = ["js"] }
|
||||||
|
rocket = "0.5.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
[features]
|
tokio = { version = "1.0", features = ["full"] }
|
||||||
default = ["dioxus/web"]
|
surrealdb = "2.1.4"
|
||||||
web = ["dioxus/web"]
|
|
||||||
desktop = ["dioxus/desktop"]
|
|
||||||
mobile = ["dioxus/mobile"]
|
|
||||||
|
|
||||||
[profile]
|
[profile]
|
||||||
|
|
17
client/Cargo.toml
Normal file
17
client/Cargo.toml
Normal 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 }
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 130 KiB |
@ -1,7 +1,7 @@
|
|||||||
use std::format;
|
use std::format;
|
||||||
|
|
||||||
use crate::common::dom::add_element_class;
|
use crate::utils::dom::add_element_class;
|
||||||
use crate::common::helps::generate_random_string;
|
use common::helps::generate_random_string;
|
||||||
use crate::Route;
|
use crate::Route;
|
||||||
use dioxus::{logger::tracing, prelude::*};
|
use dioxus::{logger::tracing, prelude::*};
|
||||||
use dioxus_free_icons::icons::bs_icons::{BsCheckCircle, BsInfoCircle, BsXCircle, BsXLg};
|
use dioxus_free_icons::icons::bs_icons::{BsCheckCircle, BsInfoCircle, BsXCircle, BsXLg};
|
@ -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,
|
add_element_class, get_local_storage_value, get_media_theme, remove_element_class,
|
||||||
remove_local_storage_value, set_local_storage_value,
|
remove_local_storage_value, set_local_storage_value,
|
||||||
};
|
};
|
@ -1,14 +1,15 @@
|
|||||||
use dioxus::{logger::tracing, prelude::*};
|
use dioxus::{logger::tracing, prelude::*};
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
mod common;
|
mod utils;
|
||||||
use common::dom::{add_element_class, get_media_theme, remove_element_class};
|
mod components;
|
||||||
|
mod views;
|
||||||
|
use utils::dom::{add_element_class, get_media_theme, remove_element_class};
|
||||||
use components::notification::{Notification, NotificationProvider};
|
use components::notification::{Notification, NotificationProvider};
|
||||||
use components::theme_toggle::{get_theme, ThemeProvider};
|
use components::theme_toggle::{get_theme, ThemeProvider};
|
||||||
use components::Navbar;
|
use components::Navbar;
|
||||||
use views::Home;
|
use views::Home;
|
||||||
|
|
||||||
mod components;
|
|
||||||
mod views;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Routable, PartialEq)]
|
#[derive(Debug, Clone, Routable, PartialEq)]
|
||||||
enum Route {
|
enum Route {
|
@ -2,7 +2,7 @@ use super::error::{CustomErrorInto, CustomResult};
|
|||||||
use web_sys::{window, Document, Element, Storage, Window};
|
use web_sys::{window, Document, Element, Storage, Window};
|
||||||
|
|
||||||
fn get_window() -> CustomResult<Window> {
|
fn get_window() -> CustomResult<Window> {
|
||||||
Ok(window().ok_or("浏览器window对象不存在")?)
|
Ok(window().ok_or("浏览器window对象不存在".into_custom_error())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_storage() -> CustomResult<Storage> {
|
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<()> {
|
pub fn remove_element(ele_name: &str) -> CustomResult<()> {
|
||||||
let e = get_element(ele_name)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
@ -1,13 +1,7 @@
|
|||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
|
use common::error::CommonError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
pub struct CustomError(pub String);
|
||||||
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 trait CustomErrorInto {
|
pub trait CustomErrorInto {
|
||||||
fn into_custom_error(self) -> CustomError;
|
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 {
|
impl From<CommonError> for CustomError {
|
||||||
CustomError(error.to_string())
|
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>;
|
pub type CustomResult<T> = Result<T, CustomError>;
|
||||||
|
|
@ -1,3 +1,2 @@
|
|||||||
pub mod dom;
|
pub mod dom;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod helps;
|
|
8
common/Cargo.toml
Normal file
8
common/Cargo.toml
Normal 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
26
common/src/error.rs
Normal 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
2
common/src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod error;
|
||||||
|
pub mod helps;
|
12
server/Cargo.toml
Normal file
12
server/Cargo.toml
Normal 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
31
server/src/main.rs
Normal 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
30
server/src/utils/error.rs
Normal 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
1
server/src/utils/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod error;
|
Loading…
Reference in New Issue
Block a user