Refactor(URL): Optimize url

This commit is contained in:
2024-05-21 14:38:28 +08:00
parent 2b1bd719ad
commit 31a458416d
8 changed files with 30 additions and 15 deletions

View File

@@ -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

View File

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

View File

@@ -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

View File

@@ -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}
<Icon component={IconOxygenCopy} />
</a>
</FlexBox>

View File

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