From 726bbe4f6f56f7f396dcf4eaea994c86a6c0b7e8 Mon Sep 17 00:00:00 2001 From: ningyv <1793599591@qq.com> Date: Fri, 29 Nov 2024 10:22:40 +0800 Subject: [PATCH] fix: Fix the issue where copying the URL doesn't work --- frontend/packages/common/src/hooks/copy.ts | 1 + frontend/packages/market/src/pages/serviceHub/integrate.tsx | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/packages/common/src/hooks/copy.ts b/frontend/packages/common/src/hooks/copy.ts index 351e5495..5d682628 100644 --- a/frontend/packages/common/src/hooks/copy.ts +++ b/frontend/packages/common/src/hooks/copy.ts @@ -1,6 +1,7 @@ import { RESPONSE_TIPS } from '@common/const/const'; import { message } from 'antd'; +import { $t } from "@common/locales" import { useEffect, useState } from 'react'; const useCopyToClipboard = () => { diff --git a/frontend/packages/market/src/pages/serviceHub/integrate.tsx b/frontend/packages/market/src/pages/serviceHub/integrate.tsx index 9251abf5..2eb31929 100644 --- a/frontend/packages/market/src/pages/serviceHub/integrate.tsx +++ b/frontend/packages/market/src/pages/serviceHub/integrate.tsx @@ -5,6 +5,7 @@ import { BasicResponse, RESPONSE_TIPS, STATUS_CODE } from '@common/const/const' import { useParams } from "react-router-dom" import { useState, useEffect } from "react" import { RouterParams } from "@common/const/type" +import useCopyToClipboard from "@common/hooks/copy.ts"; import { useFetch } from "@common/hooks/http" const Integrate = ({ service }: { service: ServiceDetailType }) => { @@ -12,6 +13,7 @@ const Integrate = ({ service }: { service: ServiceDetailType }) => { const [url, setUrl] = useState(''); const { serviceId} = useParams() const {fetchData} = useFetch() + const { copyToClipboard } = useCopyToClipboard(); useEffect(()=>{ setUrl(`${service?.basic?.sitePrefix || window.location?.origin}/api/v1/service/swagger/${serviceId}` ) @@ -28,8 +30,7 @@ const Integrate = ({ service }: { service: ServiceDetailType }) => { * 复制代码 */ const copyURL = async (): Promise => { - await navigator.clipboard.writeText(url) - message.success($t(RESPONSE_TIPS.copySuccess)) + copyToClipboard(url) } /** * 下载文件