diff --git a/src/forge/Branch/CloneAddress.js b/src/forge/Branch/CloneAddress.js index 38ddf5a0c..e936bb705 100644 --- a/src/forge/Branch/CloneAddress.js +++ b/src/forge/Branch/CloneAddress.js @@ -1,16 +1,10 @@ import React, { useState } from 'react'; -import { Dropdown, Menu, Tooltip } from 'antd'; +import { Menu } from 'antd'; import "./branch.scss"; +import CopyTool from '../Component/CopyTool'; function CloneAddress({http_url , ssh_url , zip_url , tar_url}) { const [ key , setKey ] = useState("HTTP"); - // 点击按钮复制功能 - function jsCopy(){ - var e = document.getElementById("copy_rep_content"); - e.select(); - document.execCommand("Copy"); - } - return (
@@ -20,9 +14,7 @@ function CloneAddress({http_url , ssh_url , zip_url , tar_url}) {
- - - +
diff --git a/src/forge/Branch/branch.scss b/src/forge/Branch/branch.scss index bdd4aa397..0c7e136a8 100644 --- a/src/forge/Branch/branch.scss +++ b/src/forge/Branch/branch.scss @@ -102,4 +102,7 @@ border-color:transparent ; } } +} +.copytool{ + margin:0px 10px; } \ No newline at end of file diff --git a/src/forge/Component/CopyTool.jsx b/src/forge/Component/CopyTool.jsx index e659c077e..df813c0ed 100644 --- a/src/forge/Component/CopyTool.jsx +++ b/src/forge/Component/CopyTool.jsx @@ -9,24 +9,32 @@ CopyTool.defaultProps = { }; -function CopyTool({ beforeText, afterText, className,inputId }) { +function CopyTool({ beforeText, afterText, className , inputId , timeOut }) { const [title, setTitle] = useState(() => { return beforeText; }); // 复制链接 const copyUrl = useCallback(() => { - let inputDom = document.getElementById(inputId); - if (!inputDom) { + const copyEle = document.querySelector(`#${inputId}`); // 获取要复制的节点 + if (!copyEle) { console.error("您的CopyTool未设置正确的inputId"); return; } - inputDom.select(); + const range = document.createRange(); // 创造range + window.getSelection().removeAllRanges(); //清除页面中已有的selection + range.selectNode(copyEle); // 选中需要复制的节点 + window.getSelection().addRange(range); // 执行选中元素 + if (document.execCommand('copy')) { document.execCommand('copy'); } setTitle(afterText); - inputDom.blur(); + if(timeOut){ + setTimeout(function(){ + setTitle(beforeText); + },1500) + } }, []); return ( diff --git a/src/forge/Main/sub/Invite.jsx b/src/forge/Main/sub/Invite.jsx index ad2a00bdc..844a49922 100644 --- a/src/forge/Main/sub/Invite.jsx +++ b/src/forge/Main/sub/Invite.jsx @@ -1,26 +1,15 @@ import React from 'react'; -import { Tooltip , message } from 'antd'; import './sub.scss'; +import CopyTool from '../../Component/CopyTool'; function Invite({code,className}) { - function jsCopy(id) { - const copyEle = document.querySelector(id); // 获取要复制的节点 - const range = document.createRange(); // 创造range - window.getSelection().removeAllRanges(); //清除页面中已有的selection - range.selectNode(copyEle); // 选中需要复制的节点 - window.getSelection().addRange(range); // 执行选中元素 - document.execCommand("Copy"); // 执行copy操作 - message.success('复制成功'); - } return(
邀请码
{code} - 可以通过邀请码邀请成员加入项目
点击复制邀请码。

} placement={"bottom"}> - jsCopy("#devitecode")}> -
+ 可以通过邀请码邀请成员加入项目
点击复制邀请码。

} className="ml8 font-16" inputId="devitecode"/>
)