diff --git a/src/components/Shorturlchange.jsx b/src/components/Shorturlchange.jsx index 70a0702..b2ac13d 100644 --- a/src/components/Shorturlchange.jsx +++ b/src/components/Shorturlchange.jsx @@ -1,20 +1,9 @@ import { useCallback } from 'react'; -import { message } from 'antd'; +import useConversationStore from '@/stores/ConversationStore'; const useShortUrlChange = () => { - const [messageApi, contextHolder] = message.useMessage(); - const success = (content) => { - messageApi.open({ - type: 'success', - content: content, - }); - }; - const error = (content) => { - messageApi.open({ - type: 'error', - content: content, - }); - }; + const setGlobalNotify = useConversationStore((state) => state.setGlobalNotify); + const apiPrefix = { "japanhighlights.com": "https://www.japanhighlights.com/index.php", "chinahighlights.com": "https://www.chinahighlights.com/guide-use.php", @@ -53,7 +42,12 @@ const useShortUrlChange = () => { return { base64Url, extracted2 }; } catch (error) { - error('转换失败,请检查输入的URL是否正确'); + setGlobalNotify([{ + key: Date.now().toString(), + title: '错误', + content: '转换失败,请检查输入的URL是否正确', + type: 'error' + }]); console.error('URL转换错误:', error); return { base64Url: '', extracted2: '' }; } @@ -61,7 +55,12 @@ const useShortUrlChange = () => { const convertUrl = useCallback(async (longUrl) => { if (!longUrl.trim()) { - error('不是有效的长链接'); + setGlobalNotify([{ + key: Date.now().toString(), + title: '错误', + content: '不是有效的长链接', + type: 'error' + }]); return null; } @@ -74,19 +73,34 @@ const useShortUrlChange = () => { const data = await fetchNowConversationsitems(base64Url, apiUrl); if (data) { const resultShortUrl = extracted1 + data.isl_link; - success('转换成功!'); + setGlobalNotify([{ + key: Date.now().toString(), + title: '成功', + content: '转换成功!', + type: 'success' + }]); return resultShortUrl; } else { - error('转换失败,请检查输入的URL是否正确'); + setGlobalNotify([{ + key: Date.now().toString(), + title: '错误', + content: '转换失败,请检查输入的URL是否正确', + type: 'error' + }]); return null; } } else { - error('URL格式不正确,请输入完整的URL'); + setGlobalNotify([{ + key: Date.now().toString(), + title: '错误', + content: 'URL格式不正确,请输入完整的URL', + type: 'error' + }]); return null; } - }, [messageApi]); + }, [setGlobalNotify]); - return { convertUrl, contextHolder }; + return { convertUrl }; }; export default useShortUrlChange; \ No newline at end of file diff --git a/src/views/accounts/ShorturlConversion.jsx b/src/views/accounts/ShorturlConversion.jsx index 4ab5288..7798fa9 100644 --- a/src/views/accounts/ShorturlConversion.jsx +++ b/src/views/accounts/ShorturlConversion.jsx @@ -8,7 +8,7 @@ const { Title, Text, Paragraph } = Typography function ShorturlConversion() { const [longUrl, setLongUrl] = useState('') const [shortUrl, setShortUrl] = useState('') - const { convertUrl, contextHolder } = useShortUrlChange() + const { convertUrl } = useShortUrlChange() const handleConvert = async () => { const result = await convertUrl(longUrl); @@ -18,9 +18,7 @@ function ShorturlConversion() { }; return ( - <> - {contextHolder} - +
长链接:
)}
- ); }