Refactor(URL): Optimize url

This commit is contained in:
2024-05-21 14:37:46 +08:00
parent b8ed24d320
commit 1306872885
7 changed files with 26 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
VITE_PLATFORM=WEB VITE_PLATFORM=WEB
VITE_UI_URL=${DEV_UI_URL}
VITE_API_URL=${DEV_API_URL} VITE_API_URL=${DEV_API_URL}
VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_API_TOKEN_URL=${VITE_API_URL}/token
VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY} VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY}

View File

@@ -1,4 +1,5 @@
VITE_PLATFORM=WEB VITE_PLATFORM=WEB
VITE_UI_URL=${PRODUCT_UI_URL}
VITE_API_URL=${PRODUCT_API_URL} VITE_API_URL=${PRODUCT_API_URL}
VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_API_TOKEN_URL=${VITE_API_URL}/token
VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY} VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY}

View File

@@ -1,5 +1,6 @@
NODE_ENV=development NODE_ENV=development
VITE_PLATFORM=WEB VITE_PLATFORM=WEB
VITE_UI_URL=${TEST_UI_URL}
VITE_API_URL=${TEST_API_URL} VITE_API_URL=${TEST_API_URL}
VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_API_TOKEN_URL=${VITE_API_URL}/token
VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY} VITE_TURNSTILE_SITE_KEY=${TURNSTILE_SITE_KEY}

View File

@@ -70,6 +70,8 @@
} }
.url { .url {
cursor: pointer;
> span { > span {
margin-left: 8px; margin-left: 8px;
} }

1
src/global.d.ts vendored
View File

@@ -5,6 +5,7 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID'
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_PLATFORM: Platform readonly VITE_PLATFORM: Platform
readonly VITE_UI_URL: string
readonly VITE_API_URL: string readonly VITE_API_URL: string
readonly VITE_API_TOKEN_URL: string readonly VITE_API_TOKEN_URL: string
readonly VITE_TURNSTILE_SITE_KEY: string readonly VITE_TURNSTILE_SITE_KEY: string

View File

@@ -30,7 +30,7 @@ const User = () => {
return username return username
? () => { ? () => {
void navigator.clipboard void navigator.clipboard
.writeText(new URL(`/store/${username}`, location.href).href) .writeText(new URL(`/store/${username}`, import.meta.env.VITE_UI_URL).href)
.then(() => { .then(() => {
void message.success('已复制到剪切板') void message.success('已复制到剪切板')
}) })
@@ -153,8 +153,10 @@ const User = () => {
onClick={handleOnCopyToClipboard(userWithInfoVo?.username)} onClick={handleOnCopyToClipboard(userWithInfoVo?.username)}
> >
{userWithInfoVo?.username && {userWithInfoVo?.username &&
new URL(`/store/${userWithInfoVo.username}`, location.href) new URL(
.href} `/store/${userWithInfoVo.username}`,
import.meta.env.VITE_UI_URL
).href}
<Icon component={IconOxygenCopy} /> <Icon component={IconOxygenCopy} />
</a> </a>
</FlexBox> </FlexBox>

View File

@@ -39,6 +39,18 @@ const User = () => {
const [userWithPowerInfoVo, setUserWithPowerInfoVo] = useState<UserWithPowerInfoVo>() const [userWithPowerInfoVo, setUserWithPowerInfoVo] = useState<UserWithPowerInfoVo>()
const [changePasswordForm] = AntdForm.useForm<ChangePasswordFields>() const [changePasswordForm] = AntdForm.useForm<ChangePasswordFields>()
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 = () => { const handleOnReset = () => {
getProfile() getProfile()
} }
@@ -474,20 +486,14 @@ const User = () => {
</div> </div>
<a <a
className={'url'} className={'url'}
href={ onClick={handleOnCopyToClipboard(userWithPowerInfoVo?.username)}
userWithPowerInfoVo?.username &&
new URL(
`/store/${userWithPowerInfoVo.username}`,
location.href
).href
}
> >
{userWithPowerInfoVo?.username && {userWithPowerInfoVo?.username &&
new URL( new URL(
`/store/${userWithPowerInfoVo.username}`, `/store/${userWithPowerInfoVo.username}`,
location.href import.meta.env.VITE_UI_URL
).href} ).href}
<Icon component={IconOxygenShare} /> <Icon component={IconOxygenCopy} />
</a> </a>
</FlexBox> </FlexBox>
</FlexBox> </FlexBox>