From 80d69d1fa6ec07f49e2bf66676a17c5ed79424b8 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Wed, 4 Aug 2021 23:55:26 +0800 Subject: [PATCH] add --- package-lock.json | 61 ++++++++++++------ package.json | 1 + plugins/md.ts | 35 +++++++++++ src/main/facilities/clock/index.ts | 24 ++++++++ src/main/facilities/index.ts | 1 + src/main/facilities/main/index.ts | 8 +-- src/render/plugins/electron/index.ts | 3 + src/render/route.tsx | 5 +- src/render/views/About/a.md | 16 +++++ src/render/views/About/index.tsx | 5 +- src/render/views/Home/Dialog.tsx | 50 +++++++-------- src/render/views/Home/index.module.scss | 2 - src/render/views/Home/index.tsx | 106 +++++++++++++++++++------------- src/render/views/Home/useLocation.ts | 7 +++ vite.config.ts | 4 +- 15 files changed, 228 insertions(+), 100 deletions(-) create mode 100644 plugins/md.ts create mode 100644 src/main/facilities/clock/index.ts create mode 100644 src/render/views/About/a.md create mode 100644 src/render/views/Home/useLocation.ts diff --git a/package-lock.json b/package-lock.json index 3f8b7ba..f80c8b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1368,6 +1368,34 @@ "progress": "^2.0.3", "semver": "^6.2.0", "sumchecker": "^3.0.1" + }, + "dependencies": { + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.nlark.com/fs-extra/download/fs-extra-8.1.0.tgz", + "integrity": "sha1-SdQ8RaiM2Wd2aMt74bRu/bjS4cA=", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npm.taobao.org/jsonfile/download/jsonfile-4.0.0.tgz?cache=0&sync_timestamp=1604161797011&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjsonfile%2Fdownload%2Fjsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npm.taobao.org/universalify/download/universalify-0.1.2.tgz?cache=0&sync_timestamp=1603179967633&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Funiversalify%2Fdownload%2Funiversalify-0.1.2.tgz", + "integrity": "sha1-tkb2m+OULavOzJ1mOcgNwQXvqmY=", + "dev": true + } } }, "@electron/universal": { @@ -5758,14 +5786,13 @@ "dev": true }, "fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.nlark.com/fs-extra/download/fs-extra-8.1.0.tgz", - "integrity": "sha1-SdQ8RaiM2Wd2aMt74bRu/bjS4cA=", - "dev": true, + "version": "10.0.0", + "resolved": "https://registry.nlark.com/fs-extra/download/fs-extra-10.0.0.tgz", + "integrity": "sha1-n/YbZV3eU/s0qC34S7IUzoAuF8E=", "requires": { "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" } }, "fs.realpath": { @@ -5969,8 +5996,7 @@ "graceful-fs": { "version": "4.2.6", "resolved": "https://registry.nlark.com/graceful-fs/download/graceful-fs-4.2.6.tgz", - "integrity": "sha1-/wQLKwhTsjw9MQJ1I3BvGIXXa+4=", - "dev": true + "integrity": "sha1-/wQLKwhTsjw9MQJ1I3BvGIXXa+4=" }, "graceful-readlink": { "version": "1.0.1", @@ -6928,12 +6954,12 @@ } }, "jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npm.taobao.org/jsonfile/download/jsonfile-4.0.0.tgz?cache=0&sync_timestamp=1604161797011&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjsonfile%2Fdownload%2Fjsonfile-4.0.0.tgz", - "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, + "version": "6.1.0", + "resolved": "https://registry.npm.taobao.org/jsonfile/download/jsonfile-6.1.0.tgz?cache=0&sync_timestamp=1604161797011&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjsonfile%2Fdownload%2Fjsonfile-6.1.0.tgz", + "integrity": "sha1-vFWyY0eTxnnsZAMJTrE2mKbsCq4=", "requires": { - "graceful-fs": "^4.1.6" + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" } }, "jszip": { @@ -8226,7 +8252,7 @@ }, "react-popper": { "version": "1.3.11", - "resolved": "https://registry.npm.taobao.org/react-popper/download/react-popper-1.3.11.tgz?cache=0&sync_timestamp=1616674786422&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Freact-popper%2Fdownload%2Freact-popper-1.3.11.tgz", + "resolved": "https://registry.npm.taobao.org/react-popper/download/react-popper-1.3.11.tgz", "integrity": "sha1-osw/Cme3W2bPpi0sQJ+d0fzHH/0=", "dev": true, "requires": { @@ -10018,10 +10044,9 @@ } }, "universalify": { - "version": "0.1.2", - "resolved": "https://registry.npm.taobao.org/universalify/download/universalify-0.1.2.tgz?cache=0&sync_timestamp=1603179967633&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Funiversalify%2Fdownload%2Funiversalify-0.1.2.tgz", - "integrity": "sha1-tkb2m+OULavOzJ1mOcgNwQXvqmY=", - "dev": true + "version": "2.0.0", + "resolved": "https://registry.npm.taobao.org/universalify/download/universalify-2.0.0.tgz?cache=0&sync_timestamp=1603179967633&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Funiversalify%2Fdownload%2Funiversalify-2.0.0.tgz", + "integrity": "sha1-daSYTv7cSwiXXFrrc/Uw0C3yVxc=" }, "unpipe": { "version": "1.0.0", diff --git a/package.json b/package.json index 367eb44..545b748 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "@emotion/react": "^11.4.0", "@emotion/styled": "^11.3.0", "framer-motion": "^4.1.17", + "fs-extra": "^10.0.0", "normalize.css": "^8.0.1" }, "build": { diff --git a/plugins/md.ts b/plugins/md.ts new file mode 100644 index 0000000..4499610 --- /dev/null +++ b/plugins/md.ts @@ -0,0 +1,35 @@ +import MarkdownIt from "markdown-it" + +const mark = new MarkdownIt() + +const mdToHtml = (str: string) => { + const content = mark.render(str) + return ` + import React from "react" + export default React.createElement('div', {dangerouslySetInnerHTML:{__html: \`${content}\`} })` +} + +export default function md(): any { + return { + name: "vite-plugin-md", + enforce: "pre", + transform(raw: any, id: any) { + if (!/\.md/g.test(id)) + return + try { + return mdToHtml(raw) + } catch (e) { + this.error(e) + return "" + } + }, + async handleHotUpdate(ctx: any) { + if (!/\.md/g.test(ctx.file)) + return + const defaultRead = ctx.read + ctx.read = async function() { + return mdToHtml(await defaultRead()) + } + } + } +} diff --git a/src/main/facilities/clock/index.ts b/src/main/facilities/clock/index.ts new file mode 100644 index 0000000..e1de7c2 --- /dev/null +++ b/src/main/facilities/clock/index.ts @@ -0,0 +1,24 @@ +import { ipcMain } from "electron" +import fs from "fs-extra" +import path from "path" + +const homeDir = require("os").homedir() +const clockJsonPath = path.resolve(homeDir, ".forceClock/clock.json") +fs.ensureFileSync(clockJsonPath) + +try { + console.log(fs.readJSONSync(clockJsonPath)) + const job = schedule.scheduleJob('42 * * * *', function(){ + console.log('The answer to life, the universe, and everything!'); + }); +} catch (e) { + console.log(e) +// 读取JSON文件失败 +} + +ipcMain.on("@func:clock:saveData", function(event, data) { + fs.writeJson(clockJsonPath, data) +}) +ipcMain.handle("@func:clock:getData", function() { + return fs.readJSONSync(clockJsonPath) +}) diff --git a/src/main/facilities/index.ts b/src/main/facilities/index.ts index 93a5ebd..dd9f6e7 100644 --- a/src/main/facilities/index.ts +++ b/src/main/facilities/index.ts @@ -1,4 +1,5 @@ import Shared from "@main/share" +import "@main/facilities/clock" import setTray from "@main/facilities/tray" import { app, dialog, ipcMain } from "electron" import Share from "../share" diff --git a/src/main/facilities/main/index.ts b/src/main/facilities/main/index.ts index f6af0a8..4fdf679 100644 --- a/src/main/facilities/main/index.ts +++ b/src/main/facilities/main/index.ts @@ -21,12 +21,12 @@ export default function showWindow(url?: string) { * Initial window options */ Shared.data.mainWindow = new BrowserWindow({ - height: 95, + height: 600, useContentSize: true, - width: 260, + width: 800, resizable: true, - minWidth: 260, - minHeight: 95, + minWidth: 800, + minHeight: 600, icon: __static + "/icon.png", // show: false, // frame: false, // 去除原生的菜单 diff --git a/src/render/plugins/electron/index.ts b/src/render/plugins/electron/index.ts index 9d4b7e5..1190ea0 100644 --- a/src/render/plugins/electron/index.ts +++ b/src/render/plugins/electron/index.ts @@ -1,3 +1,6 @@ + const electron = require("electron") // 只能用require export default electron + + diff --git a/src/render/route.tsx b/src/render/route.tsx index 400f313..054a337 100644 --- a/src/render/route.tsx +++ b/src/render/route.tsx @@ -1,4 +1,5 @@ import Page404 from "@/views/Auth/Page404" +import Home from "@/views/Home" import Login from "@/views/Login" import React, { lazy } from "react" import { useLocation } from "react-router-dom" @@ -81,9 +82,9 @@ const routes = [ }, { path: "/home", - component: lazy(() => import("@/views/Home")), + component: Home,//lazy(() => import("@/views/Home")), exact: true, - loading: () => , + // loading: () => , root: true, meta: { auth: false, diff --git a/src/render/views/About/a.md b/src/render/views/About/a.md new file mode 100644 index 0000000..037873a --- /dev/null +++ b/src/render/views/About/a.md @@ -0,0 +1,16 @@ +# 天涯路远,只争朝夕 + +时间如白驹过隙,一晃而过,在茫茫中,我仿佛已经丢失了很多,曾经的路已不见痕迹,前方的海无涯无际。 +回首望去,过去的岁月如梦幻泡影,伸手一触,四散分离。 +你还记得自己的梦想是什么吗?你还记得自己曾想过要干什么吗?如今的自己是否活成了当初讨厌的样子? +在冰冷的白色灯管下,我写下了这一段话,我也将深度思考,回答。这一切是否是自己期望的。 + +> 今天是2021-08-04 00:26:00,昨天是我**25岁**生日。 + +```javascript +console.log("时间会检验出答案"); // 请带上分号,给一切一个结束 +``` + +## 曾经 + +阿松大 \ No newline at end of file diff --git a/src/render/views/About/index.tsx b/src/render/views/About/index.tsx index a3ce29f..da4fc21 100644 --- a/src/render/views/About/index.tsx +++ b/src/render/views/About/index.tsx @@ -1,7 +1,7 @@ import React from "react" import style from "./index.module.scss" import { useLocation, Route, Switch, useHistory } from "react-router-dom" -// import html from "./a.md" +import html from "./a.md" function Test() { return
test
@@ -20,8 +20,7 @@ export default function About(props: any) { return (
- {/* {html} */} -

关于

+ {html}
{/*
back()}>阿萨 阿松大asdasd
*/} {/*
22{props.children}{location.href}
*/} diff --git a/src/render/views/Home/Dialog.tsx b/src/render/views/Home/Dialog.tsx index 9901401..a91e6e0 100644 --- a/src/render/views/Home/Dialog.tsx +++ b/src/render/views/Home/Dialog.tsx @@ -1,33 +1,30 @@ -import { - Button, - ButtonGroup, - Card, - ControlGroup, - Elevation, - FormGroup, - HotkeysProvider, - Icon, - InputGroup, - Overlay, - TextArea, -} from "@blueprintjs/core" -import { Cell, Column, Table2 } from "@blueprintjs/table" -import React from "react" +import { Button, ButtonGroup, Card, FormGroup, InputGroup, Overlay, TextArea } from "@blueprintjs/core" import cs from "classnames" +import React, { useEffect, useState } from "react" import style from "./dialog.module.scss" -import { useState } from "react" export default function Dialog(props: any) { const { isOpen, setIsOpen } = props const [title, setTitle] = useState("") + const [time, setTime] = useState("") + const [desc, setDesc] = useState("") - function onInput(){ - console.log('onInput'); + function clickConfrim(){ + props.onConfrim&&props.onConfrim(title,time,desc) } - function onChange(){ - console.log('onChange'); + function clickCancel(){ + setIsOpen(false) + props.onCancel&&props.onCancel() } + useEffect(()=>{ + if(isOpen){ + setTitle("") + setTime("") + setDesc("") + } + }, [isOpen]) + return (
- setTitle(e.target.value)} id="title-input" placeholder="请输入标题" /> + setTitle(e.target.value)} id="title-input" placeholder="请输入标题"/> - onInput()} onChange={()=>onChange()} id="time-input" placeholder="请输入时间区间" /> + setTime(e.target.value)} id="time-input" placeholder="请输入时间区间"/> -