From 0598f8065fac42b2eb32dd52ea18173553d40baf Mon Sep 17 00:00:00 2001 From: overtrue Date: Fri, 31 Oct 2025 22:50:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E5=A4=8D=20API=20?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=20composables=20=E6=BB=A5=E7=94=A8?= =?UTF-8?q?=E5=92=8C=E7=A1=AC=E7=BC=96=E7=A0=81=E8=B7=AF=E5=BE=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 lib/api-client.ts 中在类方法中直接调用 composables 的问题 - 添加 ApiErrorHandler 错误处理器,通过依赖注入方式处理 401 错误 - 创建路由工具函数 utils/routes.ts,统一管理路由路径 - 修复 composables/useAuth.ts 中的硬编码路径,使用工具函数 - 修复 components/copy-input.vue 的生命周期问题,在 onMounted 中创建 ClipboardJS 实例 - 修复 plugins/03.s3.ts 中的错误处理,使用 navigateTo 替代直接操作 window.location - 修复 pages/config.vue 中的硬编码路径 - 添加 composables/useFormValidation.ts、useAsyncOperation.ts、useErrorHandler.ts 工具函数(供后续使用) - 添加 types/api.ts 类型定义 --- components/copy-input.vue | 69 ++++++++-------- composables/useAsyncOperation.ts | 136 +++++++++++++++++++++++++++++++ composables/useAuth.ts | 53 ++++++------ composables/useErrorHandler.ts | 106 ++++++++++++++++++++++++ composables/useFormValidation.ts | 102 +++++++++++++++++++++++ lib/api-client.ts | 128 +++++++++++++++-------------- lib/utils/api-error-handler.ts | 70 ++++++++++++++++ pages/config.vue | 9 +- plugins/02.api.ts | 54 +++++++----- plugins/03.s3.ts | 55 ++++++++----- types/api.ts | 57 +++++++++++++ utils/routes.ts | 61 ++++++++++++++ 12 files changed, 732 insertions(+), 168 deletions(-) create mode 100644 composables/useAsyncOperation.ts create mode 100644 composables/useErrorHandler.ts create mode 100644 composables/useFormValidation.ts create mode 100644 lib/utils/api-error-handler.ts create mode 100644 types/api.ts create mode 100644 utils/routes.ts diff --git a/components/copy-input.vue b/components/copy-input.vue index 3ef4769..ac02040 100644 --- a/components/copy-input.vue +++ b/components/copy-input.vue @@ -1,11 +1,11 @@