fix: Fix the issue where copying the URL doesn't work

This commit is contained in:
ningyv
2024-11-29 10:22:40 +08:00
parent f1e1d94380
commit 726bbe4f6f
2 changed files with 4 additions and 2 deletions
@@ -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 = () => {
@@ -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<RouterParams>()
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<void> => {
await navigator.clipboard.writeText(url)
message.success($t(RESPONSE_TIPS.copySuccess))
copyToClipboard(url)
}
/**
* 下载文件