mirror of
https://github.com/whyour/qinglong.git
synced 2025-11-23 00:49:19 +08:00
Fix environment variable copy reliability by validating clipboard operation (#2833)
* Initial plan * Fix env variable copy issue by using onCopy callback Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
d01ec3b310
commit
e84ddb6cfc
|
|
@ -1,6 +1,6 @@
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import React, { useRef, useState, useEffect } from 'react';
|
import React, { useRef, useState, useEffect } from 'react';
|
||||||
import { Tooltip, Typography } from 'antd';
|
import { Tooltip, Typography, message } from 'antd';
|
||||||
import { CopyOutlined, CheckOutlined } from '@ant-design/icons';
|
import { CopyOutlined, CheckOutlined } from '@ant-design/icons';
|
||||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||||
|
|
||||||
|
|
@ -10,16 +10,21 @@ const Copy = ({ text }: { text: string }) => {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
const copyIdRef = useRef<number>();
|
const copyIdRef = useRef<number>();
|
||||||
|
|
||||||
const copyText = (e?: React.MouseEvent) => {
|
const handleCopy = (text: string, result: boolean) => {
|
||||||
e?.preventDefault();
|
if (result) {
|
||||||
e?.stopPropagation();
|
|
||||||
|
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
|
message.success(intl.get('复制成功'));
|
||||||
|
|
||||||
cleanCopyId();
|
cleanCopyId();
|
||||||
copyIdRef.current = window.setTimeout(() => {
|
copyIdRef.current = window.setTimeout(() => {
|
||||||
setCopied(false);
|
setCopied(false);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClick = (e?: React.MouseEvent) => {
|
||||||
|
e?.preventDefault();
|
||||||
|
e?.stopPropagation();
|
||||||
};
|
};
|
||||||
|
|
||||||
const cleanCopyId = () => {
|
const cleanCopyId = () => {
|
||||||
|
|
@ -27,8 +32,8 @@ const Copy = ({ text }: { text: string }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link onClick={copyText} style={{ marginLeft: 1 }}>
|
<Link onClick={handleClick} style={{ marginLeft: 1 }}>
|
||||||
<CopyToClipboard text={text}>
|
<CopyToClipboard text={text} onCopy={handleCopy}>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
key="copy"
|
key="copy"
|
||||||
title={copied ? intl.get('复制成功') : intl.get('复制')}
|
title={copied ? intl.get('复制成功') : intl.get('复制')}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user