fix(frontend): handle clipboard fallback and markdown word export
This commit is contained in:
1 parent
195ef3ee40
commit
db2f21191c
6 files changed
+86
-37
No files matched your search
@@ -15,6 +15,7 @@ import sql from 'react-syntax-highlighter/dist/esm/languages/prism/sql';
|
||||
import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx';
|
||||
import typescript from 'react-syntax-highlighter/dist/esm/languages/prism/typescript';
|
||||
import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
||||
import { copyTextToClipboard } from '@/core/clipboard';
|
||||
|
||||
export interface WikiLinkTarget {
|
||||
target: string;
|
||||
@@ -101,11 +102,11 @@ const CodeBlock: React.FC<{ children: React.ReactNode; className?: string }> = (
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(codeText);
|
||||
await copyTextToClipboard(codeText);
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 1500);
|
||||
} catch (error) {
|
||||
console.error('复制代码失败:', error);
|
||||
} catch {
|
||||
// The shared clipboard helper already tries the browser fallback.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
} from './GeneralQA.mock';
|
||||
import { requestCrudService } from '@/service/request-axios-service';
|
||||
import { authStorageGet } from '@/core/auth/scoped-storage';
|
||||
import { copyTextToClipboard } from '@/core/clipboard';
|
||||
|
||||
/**
|
||||
* 通用问答组件
|
||||
@@ -1763,9 +1764,9 @@ const GeneralQA: React.FC<{
|
||||
const handleCopyAssistantMessage = async (message: Message) => {
|
||||
const answerText = getAssistantAnswerText(message);
|
||||
try {
|
||||
await navigator.clipboard.writeText(answerText);
|
||||
} catch (copyError) {
|
||||
console.error('复制模型回答失败:', copyError);
|
||||
await copyTextToClipboard(answerText);
|
||||
} catch {
|
||||
// Keep the chat surface quiet when the browser blocks clipboard access.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user