mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-20 18:54:09 +00:00
perf: chat history api;perf: full text error (#4852)
* perf: chat history api * perf: i18n * perf: full text
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useToast } from './useToast';
|
||||
import { useCallback } from 'react';
|
||||
import { hasHttps } from '../common/system/utils';
|
||||
import { isProduction } from '@fastgpt/global/common/system/constants';
|
||||
import MyModal from '../components/common/MyModal';
|
||||
import React from 'react';
|
||||
import { Box, ModalBody } from '@chakra-ui/react';
|
||||
@@ -26,7 +24,7 @@ export const useCopyData = () => {
|
||||
data = data.trim();
|
||||
|
||||
try {
|
||||
if ((hasHttps() || !isProduction) && navigator.clipboard) {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(data);
|
||||
if (title) {
|
||||
toast({
|
||||
@@ -36,13 +34,35 @@ export const useCopyData = () => {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new Error('');
|
||||
let textArea = document.createElement('textarea');
|
||||
textArea.value = data;
|
||||
// 使text area不在viewport,同时设置不可见
|
||||
textArea.style.position = 'absolute';
|
||||
// @ts-ignore
|
||||
textArea.style.opacity = 0;
|
||||
textArea.style.left = '-999999px';
|
||||
textArea.style.top = '-999999px';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
await new Promise((res, rej) => {
|
||||
document.execCommand('copy') ? res('') : rej();
|
||||
textArea.remove();
|
||||
}).then(() => {
|
||||
if (title) {
|
||||
toast({
|
||||
title,
|
||||
status: 'success',
|
||||
duration
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
setCopyContent(data);
|
||||
}
|
||||
},
|
||||
[t, toast]
|
||||
[setCopyContent, t, toast]
|
||||
);
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user