From 4e641bd38dd0944bf5e4c9641a818378e0fbf6c8 Mon Sep 17 00:00:00 2001 From: iven Date: Sat, 11 Apr 2026 02:09:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(desktop):=20SaaS=20URL=20=E9=9B=86?= =?UTF-8?q?=E4=B8=AD=E9=85=8D=E7=BD=AE=E5=8C=96=EF=BC=8C=E6=B6=88=E9=99=A4?= =?UTF-8?q?=205=20=E5=A4=84=E7=A1=AC=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 .env.development / .env.production (VITE_SAAS_URL) - saasStore.ts / LoginPage.tsx / saas-client.ts / SaaSLogin.tsx 统一读取 import.meta.env.VITE_SAAS_URL - 移除 LoginPage 中未使用的 isTauriRuntime import --- desktop/.env.development | 5 +++++ desktop/.env.production | 5 +++++ desktop/src/components/LoginPage.tsx | 7 ++----- desktop/src/components/SaaS/SaaSLogin.tsx | 2 +- desktop/src/lib/saas-client.ts | 2 +- desktop/src/store/saasStore.ts | 4 +--- 6 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 desktop/.env.development create mode 100644 desktop/.env.production diff --git a/desktop/.env.development b/desktop/.env.development new file mode 100644 index 0000000..9805f79 --- /dev/null +++ b/desktop/.env.development @@ -0,0 +1,5 @@ +# SaaS 服务地址(开发环境) +VITE_SAAS_URL=http://127.0.0.1:8080 +# Gateway 服务地址(开发环境) +VITE_GATEWAY_HTTP=http://127.0.0.1:50051 +VITE_GATEWAY_WS=ws://127.0.0.1:50051/ws diff --git a/desktop/.env.production b/desktop/.env.production new file mode 100644 index 0000000..0e2649f --- /dev/null +++ b/desktop/.env.production @@ -0,0 +1,5 @@ +# SaaS 服务地址(生产环境) +VITE_SAAS_URL=https://saas.zclaw.com +# Gateway 服务地址(生产环境) +VITE_GATEWAY_HTTP=https://gateway.zclaw.com +VITE_GATEWAY_WS=wss://gateway.zclaw.com/ws diff --git a/desktop/src/components/LoginPage.tsx b/desktop/src/components/LoginPage.tsx index 40c65a4..19ce45e 100644 --- a/desktop/src/components/LoginPage.tsx +++ b/desktop/src/components/LoginPage.tsx @@ -22,12 +22,10 @@ import { } from 'lucide-react'; import { useSaaSStore } from '../store/saasStore'; import { cn } from '../lib/utils'; -import { isTauriRuntime } from '../lib/tauri-gateway'; // === Constants === -const PRODUCTION_SAAS_URL = 'https://saas.zclaw.com'; -const DEV_SAAS_URL = 'http://127.0.0.1:8080'; +const SAAS_URL = import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080'; // === Animation Variants === @@ -86,8 +84,7 @@ function ZclawLogo({ className }: { className?: string }) { /** 根据运行环境自动选择 SaaS 服务器地址 */ function getSaasUrl(): string { - if (import.meta.env.DEV) return DEV_SAAS_URL; - return isTauriRuntime() ? PRODUCTION_SAAS_URL : DEV_SAAS_URL; + return SAAS_URL; } // === Component === diff --git a/desktop/src/components/SaaS/SaaSLogin.tsx b/desktop/src/components/SaaS/SaaSLogin.tsx index e6440b7..0f3412e 100644 --- a/desktop/src/components/SaaS/SaaSLogin.tsx +++ b/desktop/src/components/SaaS/SaaSLogin.tsx @@ -246,7 +246,7 @@ export function SaaSLogin({ onLogin, onLoginWithTotp, onRegister, initialUrl, is type="url" value={serverUrl} onChange={(e) => setServerUrl(e.target.value)} - placeholder="https://saas.zclaw.com" + placeholder={import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080'} className="w-full pl-10 pr-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 bg-white text-gray-900" disabled={isLoggingIn} /> diff --git a/desktop/src/lib/saas-client.ts b/desktop/src/lib/saas-client.ts index fa95fa0..a3726b1 100644 --- a/desktop/src/lib/saas-client.ts +++ b/desktop/src/lib/saas-client.ts @@ -508,4 +508,4 @@ export interface SaaSClient { * Global SaaS client singleton. * Initialized with a default URL; the URL and token are updated on login. */ -export const saasClient = new SaaSClient('https://saas.zclaw.com'); +export const saasClient = new SaaSClient(import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080'); diff --git a/desktop/src/store/saasStore.ts b/desktop/src/store/saasStore.ts index dedbc30..411a7dc 100644 --- a/desktop/src/store/saasStore.ts +++ b/desktop/src/store/saasStore.ts @@ -128,9 +128,7 @@ export type SaaSStore = SaaSStateSlice & SaaSActionsSlice; // === Constants === -const DEFAULT_SAAS_URL = import.meta.env.DEV - ? 'http://127.0.0.1:8080' - : 'https://saas.zclaw.com'; +const DEFAULT_SAAS_URL = import.meta.env.VITE_SAAS_URL || 'http://127.0.0.1:8080'; // === Helpers ===