mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-20 02:26:38 +08:00
[bugfix]修复copy问题
This commit is contained in:
parent
3915ce9814
commit
54c6e6ade4
@ -236,12 +236,24 @@ export function getChannelModels(type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function copy(text, name = '') {
|
export function copy(text, name = '') {
|
||||||
try {
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||||
navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(text).then(() => {
|
||||||
} catch (error) {
|
showNotice(`复制${name}成功!`, true);
|
||||||
|
}, () => {
|
||||||
|
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
|
||||||
|
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text} />, getSnackbarOptions('COPY'));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const textArea = document.createElement("textarea");
|
||||||
|
textArea.value = text;
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.select();
|
||||||
|
try {
|
||||||
|
document.execCommand('copy');
|
||||||
|
showNotice(`复制${name}成功!`, true);
|
||||||
|
} catch (err) {
|
||||||
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
|
text = `复制${name}失败,请手动复制:<br /><br />${text}`;
|
||||||
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text} />, getSnackbarOptions('COPY'));
|
enqueueSnackbar(<SnackbarHTMLContent htmlContent={text} />, getSnackbarOptions('COPY'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
showSuccess(`复制${name}成功!`);
|
document.body.removeChild(textArea);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user