From 2d5a57853d499ce2622546d9b9e3cbbee6ce4bf6 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Tue, 25 Mar 2025 00:57:23 +0800 Subject: [PATCH] feat --- electron.vite.config.ts | 6 +- packages/locales/index.ts | 6 ++ packages/locales/languages/en.json | 3 +- packages/locales/languages/zh.json | 3 +- src/common/event/PlatForm/index.ts | 25 ++++++++ src/common/event/Tabs/index.ts | 54 +++++++++++++++++ src/common/event/common.ts | 5 ++ src/common/event/update/common.ts | 7 --- src/common/event/update/index.ts | 14 +++++ src/common/event/update/main.ts | 6 +- src/common/event/update/renderer.ts | 14 ----- src/common/lib/_Base.ts | 12 ++++ src/common/usePlatform.ts | 9 +++ src/renderer/auto-imports.d.ts | 2 - src/renderer/src/components/NavBar.vue | 13 +++-- src/renderer/src/composables/usePlatform.ts | 9 --- src/renderer/src/platform/PlatForm.ts | 17 ------ src/renderer/src/platform/Tabs.ts | 54 ----------------- src/renderer/src/platform/_Base.ts | 12 ---- tsconfig.node.json | 67 +++++++++++++++------ tsconfig.web.json | 91 +++++++++++++++++------------ 21 files changed, 243 insertions(+), 186 deletions(-) create mode 100644 src/common/event/PlatForm/index.ts create mode 100644 src/common/event/Tabs/index.ts create mode 100644 src/common/event/common.ts delete mode 100644 src/common/event/update/common.ts create mode 100644 src/common/event/update/index.ts delete mode 100644 src/common/event/update/renderer.ts create mode 100644 src/common/lib/_Base.ts create mode 100644 src/common/usePlatform.ts delete mode 100644 src/renderer/src/composables/usePlatform.ts delete mode 100644 src/renderer/src/platform/PlatForm.ts delete mode 100644 src/renderer/src/platform/Tabs.ts delete mode 100644 src/renderer/src/platform/_Base.ts diff --git a/electron.vite.config.ts b/electron.vite.config.ts index 659b9ed..feaba98 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -18,7 +18,7 @@ export default defineConfig({ alias: { config: resolve("config"), main: resolve("src/main"), - "common": resolve("src/common"), + common: resolve("src/common"), "@res": resolve("resources"), }, }, @@ -32,7 +32,7 @@ export default defineConfig({ resolve: { alias: { config: resolve("config"), - "common": resolve("src/common"), + common: resolve("src/common"), "@": resolve("src/renderer/src"), "@res": resolve("resources"), }, @@ -41,7 +41,7 @@ export default defineConfig({ preprocessorOptions: { scss: { additionalData: `@use "@/assets/style/global" as *;\n`, - api: "modern-compiler" + api: "modern-compiler", }, }, }, diff --git a/packages/locales/index.ts b/packages/locales/index.ts index e5ad212..e518c7b 100644 --- a/packages/locales/index.ts +++ b/packages/locales/index.ts @@ -1,3 +1,9 @@ +if (import.meta.env.DEV) { + // 引入之后可以热更新 + import("./languages/zh.json") + import("./languages/en.json") +} + const datetimeFormats = { en: { short: { diff --git a/packages/locales/languages/en.json b/packages/locales/languages/en.json index bc3070e..f5d95ce 100644 --- a/packages/locales/languages/en.json +++ b/packages/locales/languages/en.json @@ -73,5 +73,6 @@ }, "qie-huan-kai-fa-zhe-gong-ju": "ToggleDevtool", "qu-xiao-quan-ping": "Canel FullScreen", - "quan-ping": "FullScreen" + "quan-ping": "FullScreen", + "caidan": "Menu" } diff --git a/packages/locales/languages/zh.json b/packages/locales/languages/zh.json index c6099ce..70a2315 100644 --- a/packages/locales/languages/zh.json +++ b/packages/locales/languages/zh.json @@ -72,5 +72,6 @@ }, "qie-huan-kai-fa-zhe-gong-ju": "切换开发者工具", "qu-xiao-quan-ping": "取消全屏", - "quan-ping": "全屏" + "quan-ping": "全屏", + "caidan": "菜单" } diff --git a/src/common/event/PlatForm/index.ts b/src/common/event/PlatForm/index.ts new file mode 100644 index 0000000..2edf73e --- /dev/null +++ b/src/common/event/PlatForm/index.ts @@ -0,0 +1,25 @@ +import { _Base } from "common/lib/_Base" + +class PlatForm extends _Base { + constructor() { + super() + } + + async showAbout() { + return await fetch("api://fuck/BasicService/showAbout") + } + + async isFullScreen() { + return await api.call("BasicCommand.isFullscreen") + } + + async toggleFullScreen() { + return api.call("BasicCommand.fullscreen") + } + + async toggleDevTools() { + return api.call("BasicCommand.toggleDevTools") + } +} + +export { PlatForm } diff --git a/src/common/event/Tabs/index.ts b/src/common/event/Tabs/index.ts new file mode 100644 index 0000000..5b8cd7c --- /dev/null +++ b/src/common/event/Tabs/index.ts @@ -0,0 +1,54 @@ +import { _Base } from "../../lib/_Base" + +export class Tabs extends _Base { + constructor() { + super() + } + + private isListen: boolean = false + + private execUpdate = (...args) => { + this.#fnList.forEach(v => v(...args)) + } + + #fnList: ((...args) => void)[] = [] + listenUpdate(cb: (...args) => void) { + if (!this.isListen) { + api.on("main:TabsCommand.update", this.execUpdate) + this.isListen = true + } + this.#fnList.push(cb) + } + + unListenUpdate(fn: (...args) => void) { + this.#fnList = this.#fnList.filter(v => { + return v !== fn + }) + if (!this.#fnList.length) { + api.off("main:TabsCommand.update", this.execUpdate) + this.isListen = false + } + } + + bindPosition(data) { + api.call("TabsCommand.bindElement", data) + } + + closeAll() { + api.call("TabsCommand.closeAll") + } + + sync() { + api.call("TabsCommand.sync") + } + + unListenerAll() { + this.#fnList = [] + api.offAll("main:TabsCommand.update") + } + + async getAllTabs() { + const res = await api.call("TabsCommand.getAllTabs") + return res + } +} diff --git a/src/common/event/common.ts b/src/common/event/common.ts new file mode 100644 index 0000000..4b75798 --- /dev/null +++ b/src/common/event/common.ts @@ -0,0 +1,5 @@ +const keys = ["progress"] as const + +type AllKeys = (typeof keys)[number] + +export type { AllKeys } diff --git a/src/common/event/update/common.ts b/src/common/event/update/common.ts deleted file mode 100644 index 6b969cf..0000000 --- a/src/common/event/update/common.ts +++ /dev/null @@ -1,7 +0,0 @@ -const keys = ["progress"] as const - -type AllKeys = (typeof keys)[number] - -export type{ - AllKeys -} \ No newline at end of file diff --git a/src/common/event/update/index.ts b/src/common/event/update/index.ts new file mode 100644 index 0000000..5d11315 --- /dev/null +++ b/src/common/event/update/index.ts @@ -0,0 +1,14 @@ +import type { AllKeys } from "../common" + +const curProgress = ref(0) +api.on("progress", () => { + curProgress.value = 10 +}) + +function useUpdate() { + return { + curProgress, + } +} + +export { useUpdate } diff --git a/src/common/event/update/main.ts b/src/common/event/update/main.ts index 7ce5aa0..2bd003c 100644 --- a/src/common/event/update/main.ts +++ b/src/common/event/update/main.ts @@ -1,10 +1,8 @@ import { broadcast } from "main/utils" -import { AllKeys } from "./common" +import { AllKeys } from "../common" function emitProgress(...argu) { broadcast("progress", ...argu) } -export { - emitProgress -} \ No newline at end of file +export { emitProgress } diff --git a/src/common/event/update/renderer.ts b/src/common/event/update/renderer.ts deleted file mode 100644 index 7ccdfaa..0000000 --- a/src/common/event/update/renderer.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { AllKeys } from "./common" - -const curProgress = ref(0) -api.on("progress", () => { - curProgress.value = 10 -}) - -function useUpdate() { - return { - curProgress, - } -} - -export { useUpdate } diff --git a/src/common/lib/_Base.ts b/src/common/lib/_Base.ts new file mode 100644 index 0000000..91d8f4b --- /dev/null +++ b/src/common/lib/_Base.ts @@ -0,0 +1,12 @@ +export abstract class _Base { + static instance + + static getInstance(): T { + if (!this.instance) { + // 如果实例不存在,则创建一个新的实例 + // @ts-ignore ... + this.instance = new this() + } + return this.instance + } +} diff --git a/src/common/usePlatform.ts b/src/common/usePlatform.ts new file mode 100644 index 0000000..1316845 --- /dev/null +++ b/src/common/usePlatform.ts @@ -0,0 +1,9 @@ +import { PlatForm } from "./event/PlatForm" +import { Tabs } from "./event/Tabs" + +export function usePlatForm() { + return { + Tabs: Tabs.getInstance(), + PlatForm: PlatForm.getInstance(), + } +} diff --git a/src/renderer/auto-imports.d.ts b/src/renderer/auto-imports.d.ts index 4098275..ce4d49e 100644 --- a/src/renderer/auto-imports.d.ts +++ b/src/renderer/auto-imports.d.ts @@ -212,7 +212,6 @@ declare global { const useParentElement: typeof import('@vueuse/core')['useParentElement'] const usePerformanceObserver: typeof import('@vueuse/core')['usePerformanceObserver'] const usePermission: typeof import('@vueuse/core')['usePermission'] - const usePlatForm: typeof import('./src/composables/usePlatform')['usePlatForm'] const usePointer: typeof import('@vueuse/core')['usePointer'] const usePointerLock: typeof import('@vueuse/core')['usePointerLock'] const usePointerSwipe: typeof import('@vueuse/core')['usePointerSwipe'] @@ -514,7 +513,6 @@ declare module 'vue' { readonly useParentElement: UnwrapRef readonly usePerformanceObserver: UnwrapRef readonly usePermission: UnwrapRef - readonly usePlatForm: UnwrapRef readonly usePointer: UnwrapRef readonly usePointerLock: UnwrapRef readonly usePointerSwipe: UnwrapRef diff --git a/src/renderer/src/components/NavBar.vue b/src/renderer/src/components/NavBar.vue index 7ad502e..95a01d9 100644 --- a/src/renderer/src/components/NavBar.vue +++ b/src/renderer/src/components/NavBar.vue @@ -15,7 +15,7 @@
{{ config.app_title }}
-
菜单
+
{{ t("caidan") }}
@@ -42,19 +42,20 @@ import icon from "@res/icon.png" import config from "config" import { PopupMenu } from "@/bridge/PopupMenu" +import { usePlatForm } from "common/usePlatform" + +const { PlatForm } = usePlatForm() const router = useRouter() const route = useRoute() const isFullScreen = ref(false) onBeforeMount(async () => { - isFullScreen.value = await api.call("BasicCommand.isFullscreen") + isFullScreen.value = await PlatForm.isFullScreen() }) -const { PlatForm } = usePlatForm() - const isHome = computed(() => { - if (route?.meta?.home) { + if (route.fullPath === "/") { return true } return false @@ -85,7 +86,7 @@ const onClickMenu = e => { } const onClickAbout = () => { - fetch("api://fuck/BasicService/showAbout") + PlatForm.showAbout() } diff --git a/src/renderer/src/composables/usePlatform.ts b/src/renderer/src/composables/usePlatform.ts deleted file mode 100644 index b6268e0..0000000 --- a/src/renderer/src/composables/usePlatform.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PlatForm } from "@/platform/PlatForm" -import { Tabs } from "@/platform/Tabs" - -export function usePlatForm() { - return { - Tabs: Tabs.getInstance(), - PlatForm: PlatForm.getInstance(), - } -} diff --git a/src/renderer/src/platform/PlatForm.ts b/src/renderer/src/platform/PlatForm.ts deleted file mode 100644 index 1c7e8c0..0000000 --- a/src/renderer/src/platform/PlatForm.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { _Base } from "./_Base" - -class PlatForm extends _Base { - constructor() { - super() - } - - toggleFullScreen() { - return api.call("BasicCommand.fullscreen") - } - - toggleDevTools() { - return api.call("BasicCommand.toggleDevTools") - } -} - -export { PlatForm } diff --git a/src/renderer/src/platform/Tabs.ts b/src/renderer/src/platform/Tabs.ts deleted file mode 100644 index 2e82276..0000000 --- a/src/renderer/src/platform/Tabs.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { _Base } from "./_Base" - -export class Tabs extends _Base { - constructor() { - super() - } - - private isListen: boolean = false - - private execUpdate = (...args) => { - this.#fnList.forEach(v => v(...args)) - } - - #fnList: ((...args) => void)[] = [] - listenUpdate(cb: (...args) => void) { - if (!this.isListen) { - api.on("main:TabsCommand.update", this.execUpdate) - this.isListen = true - } - this.#fnList.push(cb) - } - - unListenUpdate(fn: (...args) => void) { - this.#fnList = this.#fnList.filter(v => { - return v !== fn - }) - if (!this.#fnList.length) { - api.off("main:TabsCommand.update", this.execUpdate) - this.isListen = false - } - } - - bindPosition(data) { - api.call("TabsCommand.bindElement", data) - } - - closeAll() { - api.call("TabsCommand.closeAll") - } - - sync() { - api.call("TabsCommand.sync") - } - - unListenerAll() { - this.#fnList = [] - api.offAll("main:TabsCommand.update") - } - - async getAllTabs() { - const res = await api.call("TabsCommand.getAllTabs") - return res - } -} diff --git a/src/renderer/src/platform/_Base.ts b/src/renderer/src/platform/_Base.ts deleted file mode 100644 index 91d8f4b..0000000 --- a/src/renderer/src/platform/_Base.ts +++ /dev/null @@ -1,12 +0,0 @@ -export abstract class _Base { - static instance - - static getInstance(): T { - if (!this.instance) { - // 如果实例不存在,则创建一个新的实例 - // @ts-ignore ... - this.instance = new this() - } - return this.instance - } -} diff --git a/tsconfig.node.json b/tsconfig.node.json index a1b5b17..c967ae0 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,22 +1,51 @@ { - "extends": "@electron-toolkit/tsconfig/tsconfig.node.json", - "include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "config/**/*", "src/types/**/*", "packages/locales/main.ts", - "src/common/**/*.main.ts", "src/common/**/main.ts", "src/common/**/*.common.ts", "src/common/**/common.ts"], - "compilerOptions": { - "composite": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "types": ["electron-vite/node", "reflect-metadata",], - "baseUrl": ".", - "paths": { - "#": ["src/types/index"], - "#/*": ["src/types/*"], - "config": ["config/index.ts"], - "config/*": ["config/*"], - "main/*": ["src/main/*"], - "common/*": ["src/common/*"], - "@res/*": ["resources/*"], - "locales/*": ["packages/locales/*"], + "extends": "@electron-toolkit/tsconfig/tsconfig.node.json", + "include": [ + "electron.vite.config.*", + "src/main/**/*", + "src/preload/**/*", + "config/**/*", + "src/types/**/*", + "packages/locales/main.ts", + "src/common/**/*.main.ts", + "src/common/**/main.ts", + "src/common/**/*.common.ts", + "src/common/**/common.ts" +, "src/common/event/_Base.ts" ], + "compilerOptions": { + "composite": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "types": [ + "electron-vite/node", + "reflect-metadata", + ], + "baseUrl": ".", + "paths": { + "#": [ + "src/types/index" + ], + "#/*": [ + "src/types/*" + ], + "config": [ + "config/index.ts" + ], + "config/*": [ + "config/*" + ], + "main/*": [ + "src/main/*" + ], + "common/*": [ + "src/common/*" + ], + "@res/*": [ + "resources/*" + ], + "locales/*": [ + "packages/locales/*" + ], + } } - } } diff --git a/tsconfig.web.json b/tsconfig.web.json index 14fed57..bbf6e3d 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -1,39 +1,56 @@ { - "extends": "@electron-toolkit/tsconfig/tsconfig.web.json", - "include": [ - "src/renderer/auto-imports.d.ts", - "src/renderer/components.d.ts", - "src/renderer/src/env.d.ts", - "src/renderer/src/**/*", - "src/renderer/src/**/*.vue", - "src/preload/*.d.ts", - "src/types/**/*", - "config/**/*", - "./typed-router.d.ts", - "src/common/**/*.renderer.ts", - "src/common/**/renderer.ts", - "src/common/**/*.common.ts", "src/common/**/common.ts", - ], - "vueCompilerOptions": { - "plugins": ["unplugin-vue-macros/volar"], - }, - "compilerOptions": { - "composite": true, - "baseUrl": ".", - "moduleResolution": "Bundler", - "types": ["unplugin-vue-macros/macros-global", "vite-plugin-vue-layouts/client"], - "paths": { - "#": ["src/types/index"], - "#/*": ["src/types/*"], - "config": ["config/index.ts"], - "config/*": ["config/*"], - "common/*": ["src/common/*"], - "@/*": [ - "src/renderer/src/*" - ], - "@res/*": [ - "resources/*" - ], + "extends": "@electron-toolkit/tsconfig/tsconfig.web.json", + "include": [ + "src/renderer/auto-imports.d.ts", + "src/renderer/components.d.ts", + "src/renderer/src/env.d.ts", + "src/renderer/src/**/*", + "src/renderer/src/**/*.vue", + "src/preload/*.d.ts", + "src/types/**/*", + "config/**/*", + "./typed-router.d.ts", + "src/common/**/*" + ], + "exclude": [ + "src/common/**/*.main.ts", + "src/common/**/main.ts" + ], + "vueCompilerOptions": { + "plugins": [ + "unplugin-vue-macros/volar" + ], + }, + "compilerOptions": { + "composite": true, + "baseUrl": ".", + "moduleResolution": "Bundler", + "types": [ + "unplugin-vue-macros/macros-global", + "vite-plugin-vue-layouts/client" + ], + "paths": { + "#": [ + "src/types/index" + ], + "#/*": [ + "src/types/*" + ], + "config": [ + "config/index.ts" + ], + "config/*": [ + "config/*" + ], + "common/*": [ + "src/common/*" + ], + "@/*": [ + "src/renderer/src/*" + ], + "@res/*": [ + "resources/*" + ], + } } - } -} +} \ No newline at end of file