From 31a458416d56e3f66a2a1e4d01dc6200265aac6d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 21 May 2024 14:38:28 +0800 Subject: [PATCH] Refactor(URL): Optimize url --- .env.development | 3 ++- .env.production | 3 ++- .env.testing | 3 ++- src/main/global.d.ts | 1 + .../src/assets/css/pages/user/index.scss | 2 ++ src/renderer/src/global.d.ts | 1 + src/renderer/src/pages/Tools/User.tsx | 8 ++++--- src/renderer/src/pages/User/index.tsx | 24 ++++++++++++------- 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.env.development b/.env.development index 9d59c2a..2c0416c 100644 --- a/.env.development +++ b/.env.development @@ -1,5 +1,6 @@ VITE_PLATFORM=DESKTOP -VITE_PROTOCOL=oxygen +VITE_PROTOCOL=oxygen-desktop +VITE_UI_URL=${DEV_UI_URL} VITE_API_URL=${DEV_API_URL} VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY} diff --git a/.env.production b/.env.production index 3fa1999..da3f3f3 100644 --- a/.env.production +++ b/.env.production @@ -1,5 +1,6 @@ VITE_PLATFORM=DESKTOP -VITE_PROTOCOL=oxygen +VITE_PROTOCOL=oxygen-desktop +VITE_UI_URL=${PRODUCT_UI_URL} VITE_API_URL=${PRODUCT_API_URL} VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY} diff --git a/.env.testing b/.env.testing index 75a1cda..d6afba7 100644 --- a/.env.testing +++ b/.env.testing @@ -1,6 +1,7 @@ NODE_ENV=development VITE_PLATFORM=DESKTOP -VITE_PROTOCOL=oxygen +VITE_PROTOCOL=oxygen-desktop +VITE_UI_URL=${TEST_UI_URL} VITE_API_URL=${TEST_API_URL} VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY} diff --git a/src/main/global.d.ts b/src/main/global.d.ts index 33ed138..f698dd2 100644 --- a/src/main/global.d.ts +++ b/src/main/global.d.ts @@ -3,6 +3,7 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID' interface ImportMetaEnv { readonly VITE_PLATFORM: Platform readonly VITE_PROTOCOL: string + readonly VITE_UI_URL: string readonly VITE_API_URL: string readonly VITE_API_TOKEN_URL: string readonly VITE_TURNSTILE_SITE_KEY: string diff --git a/src/renderer/src/assets/css/pages/user/index.scss b/src/renderer/src/assets/css/pages/user/index.scss index 6bcce1d..1b1bce0 100644 --- a/src/renderer/src/assets/css/pages/user/index.scss +++ b/src/renderer/src/assets/css/pages/user/index.scss @@ -70,6 +70,8 @@ } .url { + cursor: pointer; + > span { margin-left: 8px; } diff --git a/src/renderer/src/global.d.ts b/src/renderer/src/global.d.ts index 6adf1b3..27ebd04 100644 --- a/src/renderer/src/global.d.ts +++ b/src/renderer/src/global.d.ts @@ -7,6 +7,7 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID' interface ImportMetaEnv { readonly VITE_PLATFORM: Platform readonly VITE_PROTOCOL: string + readonly VITE_UI_URL: string readonly VITE_API_URL: string readonly VITE_API_TOKEN_URL: string readonly VITE_TURNSTILE_SITE_KEY: string diff --git a/src/renderer/src/pages/Tools/User.tsx b/src/renderer/src/pages/Tools/User.tsx index 5812528..0e4f009 100644 --- a/src/renderer/src/pages/Tools/User.tsx +++ b/src/renderer/src/pages/Tools/User.tsx @@ -30,7 +30,7 @@ const User = () => { return username ? () => { void navigator.clipboard - .writeText(new URL(`/store/${username}`, location.href).href) + .writeText(new URL(`/store/${username}`, import.meta.env.VITE_UI_URL).href) .then(() => { void message.success('已复制到剪切板') }) @@ -153,8 +153,10 @@ const User = () => { onClick={handleOnCopyToClipboard(userWithInfoVo?.username)} > {userWithInfoVo?.username && - new URL(`/store/${userWithInfoVo.username}`, location.href) - .href} + new URL( + `/store/${userWithInfoVo.username}`, + import.meta.env.VITE_UI_URL + ).href} diff --git a/src/renderer/src/pages/User/index.tsx b/src/renderer/src/pages/User/index.tsx index b4415be..f470ff4 100644 --- a/src/renderer/src/pages/User/index.tsx +++ b/src/renderer/src/pages/User/index.tsx @@ -39,6 +39,18 @@ const User = () => { const [userWithPowerInfoVo, setUserWithPowerInfoVo] = useState() const [changePasswordForm] = AntdForm.useForm() + const handleOnCopyToClipboard = (username?: string) => { + return username + ? () => { + void navigator.clipboard + .writeText(new URL(`/store/${username}`, import.meta.env.VITE_UI_URL).href) + .then(() => { + void message.success('已复制到剪切板') + }) + } + : undefined + } + const handleOnReset = () => { getProfile() } @@ -474,20 +486,14 @@ const User = () => { {userWithPowerInfoVo?.username && new URL( `/store/${userWithPowerInfoVo.username}`, - location.href + import.meta.env.VITE_UI_URL ).href} - +