From ac0df2d399a20b95b9bb4212647ff25b1a2e1434 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Mon, 1 Jun 2026 18:37:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E5=89=AA=E8=B4=B4=E6=9D=BF=E5=A4=8D=E5=88=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/project_context.md | 6 +++++ frontend/src/components/ApiDocs.vue | 22 ++---------------- frontend/src/components/ApiTokenManager.vue | 24 +++----------------- frontend/src/components/HistoryPanel.vue | 25 +-------------------- frontend/src/composables/clipboard.ts | 23 +++++++++++++++++++ 5 files changed, 35 insertions(+), 65 deletions(-) create mode 100644 frontend/src/composables/clipboard.ts 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); - } -}