mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
✨ ui(autoMate): 添加SettingLoader模块,用于异步加载设置配置数据
📝 ui(autoMate): 更新Setting页面,从SettingLoader中获取配置数据填充表单 📝 ui(autoMate): 更新路由配置,使用SettingLoader加载设置页面数据 📝 types: 添加ConfigType和ConfigDataType用于表示设置配置数据
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export default async ({}) =>{
|
||||
const config = (await window.api.sql('select * from config where id=1', 'findOne', {})) as ConfigType
|
||||
return JSON.parse(config.content) as ConfigDataType
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Form, useSubmit } from 'react-router-dom'
|
||||
import { Form, useLoaderData, useSubmit } from 'react-router-dom'
|
||||
import styles from './styles.module.scss'
|
||||
|
||||
export const Setting = () => {
|
||||
const config = useLoaderData() as ConfigDataType
|
||||
const submit = useSubmit()
|
||||
return (
|
||||
<Form method="POST">
|
||||
@@ -12,6 +13,7 @@ export const Setting = () => {
|
||||
<input
|
||||
type="text"
|
||||
name="shortcut"
|
||||
defaultValue={config.shortCut}
|
||||
onKeyUp={(e)=>{
|
||||
submit(e.currentTarget.form, {method: 'POST'})
|
||||
}}
|
||||
@@ -19,7 +21,7 @@ export const Setting = () => {
|
||||
</section>
|
||||
<section>
|
||||
<h5>数据库</h5>
|
||||
<input type="text" name="databaseDirectory" defaultValue="abc"/>
|
||||
<input type="text" name="databaseDirectory" defaultValue={config.databaseDirectory}/>
|
||||
</section>
|
||||
</main>
|
||||
</Form>
|
||||
|
||||
@@ -13,6 +13,7 @@ import ContentListAction from "@renderer/pages/ContentList/ContentListAction";
|
||||
import CategoryAction from "@renderer/pages/Category/CategoryAction";
|
||||
import { Setting } from "@renderer/pages/Setting";
|
||||
import SettingAction from "@renderer/pages/Setting/SettingAction";
|
||||
import SettingLoader from "@renderer/pages/Setting/SettingLoader";
|
||||
|
||||
const router = createHashRouter([
|
||||
{
|
||||
@@ -25,6 +26,7 @@ const router = createHashRouter([
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
loader: SettingLoader,
|
||||
action: SettingAction,
|
||||
element: <Setting/>
|
||||
},
|
||||
|
||||
12
ui/autoMate/types.d.ts
vendored
12
ui/autoMate/types.d.ts
vendored
@@ -15,4 +15,14 @@ type ContentType = {
|
||||
}
|
||||
|
||||
|
||||
type WindowNameType = 'search' | 'config'
|
||||
type WindowNameType = 'search' | 'config'
|
||||
|
||||
type ConfigType = {
|
||||
id: number
|
||||
content: string
|
||||
}
|
||||
|
||||
type ConfigDataType = {
|
||||
shortCut: string
|
||||
databaseDirectory: string
|
||||
}
|
||||
Reference in New Issue
Block a user