alert修改
This commit is contained in:
@@ -5,6 +5,7 @@ import { AlertCircle, Copy, ExternalLink, Loader2, RefreshCw } from 'lucide-reac
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import Toast, { ToastProps } from '@/components/Toast';
|
||||||
import { PansouLink, PansouSearchResult } from '@/lib/pansou.client';
|
import { PansouLink, PansouSearchResult } from '@/lib/pansou.client';
|
||||||
|
|
||||||
interface PansouSearchProps {
|
interface PansouSearchProps {
|
||||||
@@ -60,6 +61,7 @@ export default function PansouSearch({
|
|||||||
const [selectedType, setSelectedType] = useState<string>('all'); // 'all' 表示显示全部
|
const [selectedType, setSelectedType] = useState<string>('all'); // 'all' 表示显示全部
|
||||||
const [transferingUrl, setTransferingUrl] = useState<string | null>(null);
|
const [transferingUrl, setTransferingUrl] = useState<string | null>(null);
|
||||||
const [playingUrl, setPlayingUrl] = useState<string | null>(null);
|
const [playingUrl, setPlayingUrl] = useState<string | null>(null);
|
||||||
|
const [toast, setToast] = useState<ToastProps | null>(null);
|
||||||
|
|
||||||
// 提取搜索函数,以便在重试时调用
|
// 提取搜索函数,以便在重试时调用
|
||||||
const searchPansou = useCallback(async () => {
|
const searchPansou = useCallback(async () => {
|
||||||
@@ -141,9 +143,17 @@ export default function PansouSearch({
|
|||||||
throw new Error(data.error || '转存失败');
|
throw new Error(data.error || '转存失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
window.alert(`转存成功,已保存到:${data.targetPath}`);
|
setToast({
|
||||||
|
message: `转存成功,已保存到:${data.targetPath}`,
|
||||||
|
type: 'success',
|
||||||
|
onClose: () => setToast(null),
|
||||||
|
});
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
window.alert(err?.message || '转存失败');
|
setToast({
|
||||||
|
message: err?.message || '转存失败',
|
||||||
|
type: 'error',
|
||||||
|
onClose: () => setToast(null),
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setTransferingUrl(null);
|
setTransferingUrl(null);
|
||||||
}
|
}
|
||||||
@@ -173,12 +183,17 @@ export default function PansouSearch({
|
|||||||
`/play?source=quark-temp&id=${encodeURIComponent(data.id)}&title=${encodeURIComponent(data.title || keyword)}`
|
`/play?source=quark-temp&id=${encodeURIComponent(data.id)}&title=${encodeURIComponent(data.title || keyword)}`
|
||||||
);
|
);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
window.alert(err?.message || '立即播放失败');
|
setToast({
|
||||||
|
message: err?.message || '立即播放失败',
|
||||||
|
type: 'error',
|
||||||
|
onClose: () => setToast(null),
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setPlayingUrl(null);
|
setPlayingUrl(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderBody = () => {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center justify-center py-12'>
|
<div className='flex items-center justify-center py-12'>
|
||||||
@@ -237,7 +252,7 @@ export default function PansouSearch({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='space-y-6'>
|
<>
|
||||||
{/* 搜索结果统计 */}
|
{/* 搜索结果统计 */}
|
||||||
<div className='text-sm text-gray-600 dark:text-gray-400'>
|
<div className='text-sm text-gray-600 dark:text-gray-400'>
|
||||||
找到 <span className='font-semibold text-green-600 dark:text-green-400'>{results.total}</span> 个资源
|
找到 <span className='font-semibold text-green-600 dark:text-green-400'>{results.total}</span> 个资源
|
||||||
@@ -397,6 +412,16 @@ export default function PansouSearch({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='space-y-6'>
|
||||||
|
{renderBody()}
|
||||||
</div>
|
</div>
|
||||||
|
{toast && <Toast {...toast} />}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user