完善提取页面错误提示,优化复制链接和打开链接操作

This commit is contained in:
2025-04-15 14:29:54 +08:00
parent 3eebe48267
commit 1f1f603523
3 changed files with 26 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ import {Button} from '@/components/ui/button'
import {useForm} from 'react-hook-form'
import {Alert, AlertTitle} from '@/components/ui/alert'
import {Box, CircleAlert, CopyIcon, ExternalLinkIcon, Loader, Timer} from 'lucide-react'
import {useEffect, useMemo, useState} from 'react'
import {useEffect, useMemo, useRef, useState} from 'react'
import {useStatus} from '@/lib/states'
import {allResource} from '@/actions/resource'
import {Resource, name} from '@/lib/models'
@@ -92,8 +92,22 @@ export default function Extract(props: ExtractProps) {
return `/proxies?${sp.toString()}`
}, [resource, authType, proto, isp, distinct, formatType, separator, breaker, count, prov, city])
const onSubmit = (values: z.infer<typeof schema>) => {
console.log(values)
const type = useRef<'copy' | 'open'>('open')
const onSubmit = async (values: z.infer<typeof schema>) => {
console.log('222', type.current)
switch (type.current) {
case 'copy':
console.log('copy')
const url = new URL(window.location.href).origin
await navigator.clipboard.writeText(`${url}${params}`)
toast.success('链接已复制到剪贴板')
break
case 'open':
console.log('open')
window.open(params, '_blank')
break
}
console.log('333')
}
const getResources = async () => {
@@ -269,11 +283,11 @@ export default function Extract(props: ExtractProps) {
</FormLabel>
<FormLabel htmlFor={`${id}-v-mobile`} className={`px-3 h-10 border rounded-md flex items-center w-40 text-sm`}>
<RadioGroupItem value="2" id={`${id}-v-mobile`}/>
<span></span>
<span></span>
</FormLabel>
<FormLabel htmlFor={`${id}-v-unicom`} className={`px-3 h-10 border rounded-md flex items-center w-40 text-sm`}>
<RadioGroupItem value="3" id={`${id}-v-unicom`}/>
<span></span>
<span></span>
</FormLabel>
</RadioGroup>
)}
@@ -453,23 +467,14 @@ export default function Extract(props: ExtractProps) {
<div className="flex gap-4">
<Button
type="submit"
onClick={async () => {
if (!form.formState.isValid) return
const url = new URL(window.location.href).origin
await navigator.clipboard.writeText(`${url}${params}`)
toast.success('链接已复制到剪贴板')
}}
onClick={() => type.current = 'copy'}
>
<CopyIcon/>
<span></span>
</Button>
<Button
type="submit"
onClick={async () => {
if (!form.formState.isValid) return
window.open(params, '_blank')
}}
onClick={() => type.current = 'open'}
>
<ExternalLinkIcon/>
<span></span>