From bc9ce9e5df805136ad264da269d275e40d9f3fc2 Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Wed, 18 Mar 2026 17:00:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20PWA=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E5=A4=84=E7=90=86=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8F=AF=E8=A7=81=E6=80=A7=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + public/auth.json | 7 ++++--- src/modules/basename.ts | 10 ++++++++++ src/pages/auth/modules/BaseHeader.tsx | 1 - src/pages/repos/modules/CreateRepoDialog.tsx | 14 +++++++------- vite.config.ts | 13 +++++++++---- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 7d4ea91..c56bd68 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "react-dom": "^19.2.4", "react-hook-form": "^7.71.2", "sonner": "^2.0.7", + "vite-plugin-pwa": "^1.2.0", "zod": "^4.3.6", "zustand": "^5.0.12" }, diff --git a/public/auth.json b/public/auth.json index f07c50c..acf0250 100644 --- a/public/auth.json +++ b/public/auth.json @@ -17,16 +17,17 @@ "registry": "" } ], + "scripts": { + "auth": "ev sync clone -l -i https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/public/auth.json" + }, "sync": { "AGENTS.md": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/AGENTS.md", "vite.config.ts": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/vite.config.ts", "src/main.tsx": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/main.tsx", - "src/agents/app.ts": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/agents/app.ts", + "public/auth.json": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/public/auth.json", "src/agents/index.ts": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/agents/index.ts", "src/modules/basename.ts": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/modules/basename.ts", "src/modules/query.ts": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/modules/query.ts", - "src/pages/page.tsx": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/pages/page.tsx", - "src/routes/__root.tsx": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/routes/__root.tsx", "src/routes/demo.tsx": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/routes/demo.tsx", "src/routes/index.tsx": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/routes/index.tsx", "src/routes/login.tsx": "https://kevisual.cn/root/ai/kevisual/frontend/vite-react-template/src/routes/login.tsx", diff --git a/src/modules/basename.ts b/src/modules/basename.ts index 0516610..4792606 100644 --- a/src/modules/basename.ts +++ b/src/modules/basename.ts @@ -19,4 +19,14 @@ export const getDynamicBasename = (): string => { } // 默认使用构建时的 basename return basename +} + +export const openLink = (path: string, target: string = '_self') => { + if (path.startsWith('http://') || path.startsWith('https://')) { + window.open(path, target); + return; + } + const url = new URL(path, window.location.origin); + url.pathname = wrapBasename(url.pathname); + window.open(url.toString(), target); } \ No newline at end of file diff --git a/src/pages/auth/modules/BaseHeader.tsx b/src/pages/auth/modules/BaseHeader.tsx index 551ad39..3136210 100644 --- a/src/pages/auth/modules/BaseHeader.tsx +++ b/src/pages/auth/modules/BaseHeader.tsx @@ -83,7 +83,6 @@ export const BaseHeader = (props: { main?: React.ComponentType | null }) => { {meInfo} -
) } diff --git a/src/pages/repos/modules/CreateRepoDialog.tsx b/src/pages/repos/modules/CreateRepoDialog.tsx index ecc830a..46b3683 100644 --- a/src/pages/repos/modules/CreateRepoDialog.tsx +++ b/src/pages/repos/modules/CreateRepoDialog.tsx @@ -49,7 +49,7 @@ export function CreateRepoDialog({ open, onOpenChange }: CreateRepoDialogProps) path: '', license: '', description: '', - visibility: 'public' + visibility: 'Public' }) } }, [open, reset]) @@ -104,16 +104,16 @@ export function CreateRepoDialog({ open, onOpenChange }: CreateRepoDialogProps) ( - - 公开 (public) - 私有 (private) - 保护 (protected) + 公开 (public) + 私有 (private) + 保护 (protected) )} diff --git a/vite.config.ts b/vite.config.ts index a97df75..45c0e9c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,12 +4,14 @@ import path from 'path'; import pkgs from './package.json'; import tailwindcss from '@tailwindcss/vite'; import { tanstackRouter } from '@tanstack/router-plugin/vite' -import 'dotenv/config'; +import dotenv from 'dotenv'; +import { VitePWA } from 'vite-plugin-pwa'; -const isDev = process.env.NODE_ENV === 'development'; +const env = dotenv.config().parsed || {}; +const isDev = env.NODE_ENV === 'development' || process.env.NODE_ENV === 'development'; const basename = isDev ? '/' : pkgs?.basename || '/'; -let target = process.env.VITE_API_URL || 'http://localhost:51515'; +let target = env.VITE_API_URL || process.env.API_URL || 'http://localhost:51515'; const apiProxy = { target: target, changeOrigin: true, ws: true, rewriteWsOrigin: true, secure: false, cookieDomainRewrite: 'localhost' }; let proxy = { '/root/': apiProxy, @@ -27,7 +29,10 @@ export default defineConfig({ autoCodeSplitting: true, }), react(), - tailwindcss() + tailwindcss(), + VitePWA({ + injectRegister: 'auto', + }), ], resolve: { alias: {