diff --git a/docs/project_context.md b/docs/project_context.md index ee71461..fe98a8a 100644 --- a/docs/project_context.md +++ b/docs/project_context.md @@ -638,3 +638,9 @@ - `app/utils/files.py` now provides `remove_file_safely()` for best-effort temporary file cleanup. - Database table export and history archive download routes now reuse this helper instead of carrying duplicate private `_remove_file()` functions. - Verification performed: `.venv\Scripts\python.exe -m compileall app`, `npm run build`, and `cargo check --manifest-path src-tauri\Cargo.toml` with a temporary sidecar placeholder all passed. Generated build output, Python caches, and temporary Tauri sidecar files were removed after verification. + +## 2026-06-01: Clipboard helper cleanup + +- `frontend/src/composables/clipboard.ts` centralizes browser clipboard writes with the existing hidden-textarea fallback. +- API documentation, API Token management, and history detail log copying now reuse `writeClipboardText()` instead of each component carrying its own clipboard fallback. +- Verification performed: `npm run build`, `.venv\Scripts\python.exe -m compileall app`, and `cargo check --manifest-path src-tauri\Cargo.toml` with a temporary sidecar placeholder all passed. Generated build output, Python caches, and temporary Tauri sidecar files were removed after verification. diff --git a/frontend/src/components/ApiDocs.vue b/frontend/src/components/ApiDocs.vue index 6aa22de..a106599 100644 --- a/frontend/src/components/ApiDocs.vue +++ b/frontend/src/components/ApiDocs.vue @@ -26,6 +26,7 @@ import SwaggerUIBundle from 'swagger-ui-dist/swagger-ui-bundle.js'; import 'swagger-ui-dist/swagger-ui.css'; import { apiUrl, getApiBaseUrl, getToken } from '../api/client'; +import { writeClipboardText } from '../composables/clipboard'; type SwaggerSystem = { getSystem?: () => { @@ -92,28 +93,9 @@ function initSwagger() { } async function copyHeaderSample() { - await writeClipboard('Authorization: Bearer \nX-API-Token: '); + await writeClipboardText('Authorization: Bearer \nX-API-Token: '); message.success('传参示例已复制'); } - -async function writeClipboard(text: string) { - if (navigator.clipboard?.writeText) { - await navigator.clipboard.writeText(text); - return; - } - - const textarea = document.createElement('textarea'); - textarea.value = text; - textarea.style.position = 'fixed'; - textarea.style.top = '-1000px'; - document.body.appendChild(textarea); - textarea.select(); - try { - document.execCommand('copy'); - } finally { - document.body.removeChild(textarea); - } -}