From 610b3b54220a3056296dff1ec94a36d8ec403eb5 Mon Sep 17 00:00:00 2001 From: lsy Date: Sat, 30 Nov 2024 22:24:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E4=B8=BA"echoes"=EF=BC=9B=E5=89=8D=E7=AB=AF=EF=BC=9A?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E6=A8=A1=E6=9D=BF=E5=92=8C=E8=83=BD=E5=8A=9B=E4=B8=BA?= =?UTF-8?q?=E6=A0=B8=E5=BF=83=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=92=8C=E6=8F=92=E4=BB=B6=E6=9C=8D=E5=8A=A1=EF=BC=8C=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E6=9C=8D=E5=8A=A1=E7=BB=9F=E4=B8=80=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E5=AE=9E=E7=8E=B0=E4=BA=92=E7=9B=B8=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=9C=8D=E5=8A=A1=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/api/settings.rs | 2 +- frontend/app/init.tsx | 60 +++++------ frontend/app/root.tsx | 83 +++++++------- frontend/app/routes.tsx | 16 ++- frontend/core/hub.ts | 34 ++++++ frontend/core/plugin.ts | 64 ----------- frontend/core/template.ts | 11 -- frontend/core/theme.ts | 79 -------------- frontend/hooks/error.tsx | 43 ++++++++ frontend/hooks/loading.tsx | 101 ++++++++++++++++++ frontend/hooks/message.tsx | 5 - frontend/hooks/servicesProvider.tsx | 29 ----- frontend/hooks/stylesProvider.tsx | 10 -- frontend/interface/plugin.ts | 14 +++ frontend/interface/template.ts | 25 +++++ frontend/interface/theme.ts | 24 +++++ frontend/package.json | 3 - frontend/tailwind.config.ts | 2 +- frontend/themes/echoes/templates/page.tsx | 15 +++ .../{default => echoes}/theme.config.ts | 21 +++- 20 files changed, 355 insertions(+), 286 deletions(-) create mode 100644 frontend/core/hub.ts delete mode 100644 frontend/core/plugin.ts delete mode 100644 frontend/core/template.ts delete mode 100644 frontend/core/theme.ts create mode 100644 frontend/hooks/error.tsx create mode 100644 frontend/hooks/loading.tsx delete mode 100644 frontend/hooks/servicesProvider.tsx delete mode 100644 frontend/hooks/stylesProvider.tsx create mode 100644 frontend/interface/plugin.ts create mode 100644 frontend/interface/template.ts create mode 100644 frontend/interface/theme.ts create mode 100644 frontend/themes/echoes/templates/page.tsx rename frontend/themes/{default => echoes}/theme.config.ts (57%) diff --git a/backend/src/api/settings.rs b/backend/src/api/settings.rs index 0ca75ae..70e1354 100644 --- a/backend/src/api/settings.rs +++ b/backend/src/api/settings.rs @@ -25,7 +25,7 @@ impl Default for SystemConfigure { fn default() -> Self { Self { author_name: "lsy".to_string(), - current_theme: "default".to_string(), + current_theme: "echoes".to_string(), site_keyword: "echoes".to_string(), site_description: "echoes是一个高效、可扩展的博客平台".to_string(), admin_path: "admin".to_string(), diff --git a/frontend/app/init.tsx b/frontend/app/init.tsx index 37c9743..939e894 100644 --- a/frontend/app/init.tsx +++ b/frontend/app/init.tsx @@ -1,7 +1,7 @@ import React, { createContext, useState, useEffect } from "react"; -import {useHttp} from 'hooks/servicesProvider' -import { message} from "hooks/message"; +import { message } from "hooks/message"; import {DEFAULT_CONFIG} from "app/env" +import { useHub } from "core/hub"; interface SetupContextType { @@ -94,7 +94,7 @@ const Introduction: React.FC = ({ onNext }) => ( const DatabaseConfig: React.FC = ({ onNext }) => { const [dbType, setDbType] = useState("postgresql"); const [loading, setLoading] = useState(false); - const api = useHttp(); + const http = useHub().http; const validateForm = () => { const getRequiredFields = () => { @@ -131,7 +131,7 @@ const DatabaseConfig: React.FC = ({ onNext }) => { default: return field; } }); - message.error(`请填写以下必填项:${fieldNames.join('、')}`, '验证失败'); + message.error(`请填写以下必填项:${fieldNames.join('、')}`); return false; } return true; @@ -154,37 +154,33 @@ const DatabaseConfig: React.FC = ({ onNext }) => { db_name: (document.querySelector('[name="db_name"]') as HTMLInputElement)?.value?.trim()??"", }; - await api.post('/sql', formData); - - let oldEnv = import.meta.env?? DEFAULT_CONFIG - + await http.post('/sql', formData); + let oldEnv = import.meta.env ?? DEFAULT_CONFIG; const viteEnv = Object.entries(oldEnv).reduce((acc, [key, value]) => { - if (key.startsWith('VITE_')) { - acc[key] = value; - } - return acc; - }, {} as Record); - + if (key.startsWith('VITE_')) { + acc[key] = value; + } + return acc; + }, {} as Record); const newEnv = { ...viteEnv, VITE_INIT_STATUS: '2' }; - - await api.dev("/env", { + await http.dev("/env", { method: "POST", body: JSON.stringify(newEnv), }); - Object.assign( newEnv) + Object.assign(import.meta.env, newEnv); - message.success('数据库配置已保存', '配置成功'); + message.success('数据库配置成功!'); setTimeout(() => onNext(), 1000); } catch (error: any) { console.error( error); - message.error(error.message , error.title || '配置失败'); + message.error(error.message ); } finally { setLoading(false); } @@ -331,7 +327,7 @@ interface InstallReplyData { const AdminConfig: React.FC = ({ onNext }) => { const [loading, setLoading] = useState(false); - const api = useHttp(); + const http = useHub().http; const handleNext = async () => { setLoading(true); @@ -342,7 +338,7 @@ const AdminConfig: React.FC = ({ onNext }) => { email: (document.querySelector('[name="admin_email"]') as HTMLInputElement)?.value, }; - const response = await api.post('/administrator', formData) as InstallReplyData; + const response = await http.post('/administrator', formData) as InstallReplyData; const data = response; localStorage.setItem('token', data.token); @@ -358,22 +354,22 @@ const AdminConfig: React.FC = ({ onNext }) => { const newEnv = { ...viteEnv, VITE_INIT_STATUS: '3', - VITE_API_USERNAME:data.username, - VITE_API_PASSWORD:data.password + VITE_API_USERNAME: data.username, + VITE_API_PASSWORD: data.password }; - - - await api.dev("/env", { + await http.dev("/env", { method: "POST", body: JSON.stringify(newEnv), }); - message.success('管理员账号已创建,即将进入下一步', '创建成功'); + Object.assign(import.meta.env, newEnv); + + message.success('管理员账号创建成功!'); onNext(); } catch (error: any) { console.error(error); - message.error(error.message, error.title || '创建失败'); + message.error(error.message); } finally { setLoading(false); } @@ -392,7 +388,7 @@ const AdminConfig: React.FC = ({ onNext }) => { }; const SetupComplete: React.FC = () => { - const api = useHttp(); + const http = useHub().http; @@ -458,9 +454,9 @@ const ThemeToggle: React.FC = () => { }; export default function SetupPage() { - let step = Number(import.meta.env.VITE_INIT_STATUS)+1; - - const [currentStep, setCurrentStep] = useState(step); + const [currentStep, setCurrentStep] = useState(() => { + return Number(import.meta.env.VITE_INIT_STATUS ?? 0) + 1; + }); return (
diff --git a/frontend/app/root.tsx b/frontend/app/root.tsx index c6e4ce9..7e5ab34 100644 --- a/frontend/app/root.tsx +++ b/frontend/app/root.tsx @@ -6,8 +6,8 @@ import { ScrollRestoration, } from "@remix-run/react"; -import { BaseProvider } from "hooks/servicesProvider"; - +import { HubProvider } from "core/hub"; +import { MessageProvider, MessageContainer } from "hooks/message"; import "~/index.css"; @@ -16,47 +16,56 @@ export function Layout({ children }: { children: React.ReactNode }) { - - + + - + + + - + + - -