perf: chat history api;perf: full text error (#4852)

* perf: chat history api

* perf: i18n

* perf: full text
This commit is contained in:
Archer
2025-05-20 22:31:32 +08:00
committed by GitHub
parent 89c9a02650
commit aa55f059d4
12 changed files with 192 additions and 124 deletions

View File

@@ -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 {