Merge pull request #1853 from ZKunZhang/fix/playground-copy-newlines

fix: 修复多行代码复制换行丢失问题 & 优化API参数处理#1828
This commit is contained in:
Seefs
2025-09-27 15:25:44 +08:00
committed by GitHub
3 changed files with 21 additions and 16 deletions

View File

@@ -181,8 +181,8 @@ export function PreCode(props) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (ref.current) { if (ref.current) {
const code = const codeElement = ref.current.querySelector('code');
ref.current.querySelector('code')?.innerText ?? ''; const code = codeElement?.textContent ?? '';
copy(code).then((success) => { copy(code).then((success) => {
if (success) { if (success) {
Toast.success(t('代码已复制到剪贴板')); Toast.success(t('代码已复制到剪贴板'));

View File

@@ -118,7 +118,6 @@ export const buildApiPayload = (
model: inputs.model, model: inputs.model,
group: inputs.group, group: inputs.group,
messages: processedMessages, messages: processedMessages,
group: inputs.group,
stream: inputs.stream, stream: inputs.stream,
}; };
@@ -132,13 +131,15 @@ export const buildApiPayload = (
seed: 'seed', seed: 'seed',
}; };
Object.entries(parameterMappings).forEach(([key, param]) => { Object.entries(parameterMappings).forEach(([key, param]) => {
if ( const enabled = parameterEnabled[key];
parameterEnabled[key] && const value = inputs[param];
inputs[param] !== undefined && const hasValue = value !== undefined && value !== null;
inputs[param] !== null
) {
payload[param] = inputs[param]; if (enabled && hasValue) {
payload[param] = value;
} }
}); });

View File

@@ -75,13 +75,17 @@ export async function copy(text) {
await navigator.clipboard.writeText(text); await navigator.clipboard.writeText(text);
} catch (e) { } catch (e) {
try { try {
// 构建input 执行 复制命令 // 构建 textarea 执行复制命令,保留多行文本格式
var _input = window.document.createElement('input'); const textarea = window.document.createElement('textarea');
_input.value = text; textarea.value = text;
window.document.body.appendChild(_input); textarea.setAttribute('readonly', '');
_input.select(); textarea.style.position = 'fixed';
window.document.execCommand('Copy'); textarea.style.left = '-9999px';
window.document.body.removeChild(_input); textarea.style.top = '-9999px';
window.document.body.appendChild(textarea);
textarea.select();
window.document.execCommand('copy');
window.document.body.removeChild(textarea);
} catch (e) { } catch (e) {
okay = false; okay = false;
console.error(e); console.error(e);