From 7047cabbc9fdac1414ab18d8a9750fe4fc991f81 Mon Sep 17 00:00:00 2001 From: yuruo Date: Fri, 21 Jun 2024 15:25:43 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0(table.ts,=20wind?= =?UTF-8?q?ows.ts,=20data.ts,=20SettingAction.ts,=20index.tsx,=20styles.mo?= =?UTF-8?q?dule.scss,=20router/index.tsx)=EF=BC=9A=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96config=E8=A1=A8=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=86=85=E5=AE=B9=EF=BC=8C=E6=B7=BB=E5=8A=A0SettingAc?= =?UTF-8?q?tion=E7=BB=84=E4=BB=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2=E5=B8=83=E5=B1=80=E5=92=8C=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E6=9B=B4=E6=96=B0=E8=B7=AF=E7=94=B1=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/autoMate/src/main/db/tables.ts | 23 +++++++++++++++++++ ui/autoMate/src/main/windows.ts | 6 +++-- .../CategoryItem/styles.module.scss | 2 +- ui/autoMate/src/renderer/src/data.ts | 4 ++-- .../src/pages/Setting/SettingAction.ts | 11 +++++++++ .../src/renderer/src/pages/Setting/index.tsx | 14 +++++++++-- .../src/pages/Setting/styles.module.scss | 6 +++++ ui/autoMate/src/renderer/src/router/index.tsx | 2 ++ 8 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 ui/autoMate/src/renderer/src/pages/Setting/SettingAction.ts diff --git a/ui/autoMate/src/main/db/tables.ts b/ui/autoMate/src/main/db/tables.ts index 0f2ebb7..1c77d1d 100644 --- a/ui/autoMate/src/main/db/tables.ts +++ b/ui/autoMate/src/main/db/tables.ts @@ -1,5 +1,6 @@ import { Random } from "mockjs"; import { db } from "./connect"; +import { findOne } from "./query"; db.exec(` CREATE TABLE IF NOT EXISTS categories ( @@ -20,6 +21,28 @@ CREATE TABLE IF NOT EXISTS contents ( ); `) + +db.exec(` +CREATE TABLE IF NOT EXISTS config ( + id INTEGER PRIMARY KEY AUTOINCREMENT not null, + content TEXT not null +); +`) + + +function initData() { + const initData = findOne('select * from config') + if (initData) return + db.exec(`insert into config (content) values('')`) + +} + +initData() +// for (let i = 0; i < 20; i++) { +// const name = Random.title(5, 10) +// db.exec(`insert into config (content) values('${name}')`) +// } + // for (let i = 0; i < 20; i++) { // const name = Random.title(5, 10) // db.exec(`insert into categories (name, created_at) values('${name}', datetime())`) diff --git a/ui/autoMate/src/main/windows.ts b/ui/autoMate/src/main/windows.ts index be45da7..1b30f5f 100644 --- a/ui/autoMate/src/main/windows.ts +++ b/ui/autoMate/src/main/windows.ts @@ -13,9 +13,10 @@ export const config = { options: { width: 1300, height: 600, + openDevTools: true, frame: true, transparent: false, - hash: '/#config/category/contentList' + hash: '/#config' } } @@ -42,5 +43,6 @@ export const getWindowByEvent = (event: IpcMainEvent | IpcMainInvokeEvent) => { app.whenReady().then(() => { - getWindowByName('search') + // getWindowByName('search') + getWindowByName('config') }) \ No newline at end of file diff --git a/ui/autoMate/src/renderer/src/components/CategoryItem/styles.module.scss b/ui/autoMate/src/renderer/src/components/CategoryItem/styles.module.scss index 3baf80a..b00b736 100644 --- a/ui/autoMate/src/renderer/src/components/CategoryItem/styles.module.scss +++ b/ui/autoMate/src/renderer/src/components/CategoryItem/styles.module.scss @@ -2,7 +2,7 @@ $height: 32px; @mixin commonLink{ @apply px-2 py-2 truncate cursor-pointer block mx-1 my-1 rounded-md; height: $height; - + -webkit-user-drag: none; } // link 编译完是 a 标题 .link{ diff --git a/ui/autoMate/src/renderer/src/data.ts b/ui/autoMate/src/renderer/src/data.ts index a269979..66940aa 100644 --- a/ui/autoMate/src/renderer/src/data.ts +++ b/ui/autoMate/src/renderer/src/data.ts @@ -3,8 +3,8 @@ export interface DataType { content: string } export const codes = [ - {id:1, content: "Hello, how are you?"}, - {id:2, content: "I am fine, thank you"}, + {id:1, content: "月报天才猫!"}, + {id:2, content: "新闻天才猫!"}, {id:3, content: "How are you?"}, {id:4, content: "I am fine, thank you"}, {id:5, content: "How are you?"}, diff --git a/ui/autoMate/src/renderer/src/pages/Setting/SettingAction.ts b/ui/autoMate/src/renderer/src/pages/Setting/SettingAction.ts new file mode 100644 index 0000000..ab30030 --- /dev/null +++ b/ui/autoMate/src/renderer/src/pages/Setting/SettingAction.ts @@ -0,0 +1,11 @@ +export default async ({request})=>{ + const formData = await request.formData() + const data = Object.fromEntries(formData) + window.api.sql(`update config set content=@content where id = 1`, + 'update', + { + content: JSON.stringify(data) + } + ) + return {} +} \ No newline at end of file diff --git a/ui/autoMate/src/renderer/src/pages/Setting/index.tsx b/ui/autoMate/src/renderer/src/pages/Setting/index.tsx index 0923f6f..661862a 100644 --- a/ui/autoMate/src/renderer/src/pages/Setting/index.tsx +++ b/ui/autoMate/src/renderer/src/pages/Setting/index.tsx @@ -1,17 +1,27 @@ +import { Form, useSubmit } from 'react-router-dom' import styles from './styles.module.scss' export const Setting = () => { + const submit = useSubmit() return ( +

Setting

快捷键定义
- + { + submit(e.currentTarget.form, {method: 'POST'}) + }} + />
数据库
- +
+
) } \ No newline at end of file diff --git a/ui/autoMate/src/renderer/src/pages/Setting/styles.module.scss b/ui/autoMate/src/renderer/src/pages/Setting/styles.module.scss index f6f0c8b..b0c7110 100644 --- a/ui/autoMate/src/renderer/src/pages/Setting/styles.module.scss +++ b/ui/autoMate/src/renderer/src/pages/Setting/styles.module.scss @@ -5,6 +5,12 @@ } section{ + h5 { + @apply text-xs font-bold mb-2 text-slate-700 opacity-80; + } @apply border p-3 rounded-md bg-white my-5; + input { + @apply border w-full outline-none; + } } } \ No newline at end of file diff --git a/ui/autoMate/src/renderer/src/router/index.tsx b/ui/autoMate/src/renderer/src/router/index.tsx index 76919b3..d5076e2 100644 --- a/ui/autoMate/src/renderer/src/router/index.tsx +++ b/ui/autoMate/src/renderer/src/router/index.tsx @@ -12,6 +12,7 @@ import { Welcome } from "@renderer/pages/Welcome"; 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"; const router = createHashRouter([ { @@ -24,6 +25,7 @@ const router = createHashRouter([ children: [ { index: true, + action: SettingAction, element: }, {