diff --git a/web/admin-spa/src/components/apikeys/NewApiKeyModal.vue b/web/admin-spa/src/components/apikeys/NewApiKeyModal.vue
index 53285009..15f29069 100644
--- a/web/admin-spa/src/components/apikeys/NewApiKeyModal.vue
+++ b/web/admin-spa/src/components/apikeys/NewApiKeyModal.vue
@@ -99,18 +99,28 @@
-
+
+
+
+
+
-
@@ -190,8 +200,33 @@ const getDisplayedApiKey = () => {
}
}
-// 复制配置信息(环境变量格式)
-const copyApiKey = async () => {
+const droidEndpoint = computed(() => {
+ return getBaseUrlPrefix() + '/droid/claude'
+})
+
+// 通用复制工具,包含降级处理
+const copyTextWithFallback = async (text, successMessage) => {
+ try {
+ await navigator.clipboard.writeText(text)
+ showToast(successMessage, 'success')
+ } catch (error) {
+ const textArea = document.createElement('textarea')
+ textArea.value = text
+ document.body.appendChild(textArea)
+ textArea.select()
+ try {
+ document.execCommand('copy')
+ showToast(successMessage, 'success')
+ } catch (fallbackError) {
+ showToast('复制失败,请手动复制', 'error')
+ } finally {
+ document.body.removeChild(textArea)
+ }
+ }
+}
+
+// 复制完整配置(包含提示信息)
+const copyFullConfig = async () => {
const key = props.apiKey.apiKey || props.apiKey.key || ''
if (!key) {
showToast('API Key 不存在', 'error')
@@ -200,27 +235,22 @@ const copyApiKey = async () => {
// 构建环境变量配置格式
const configText = `ANTHROPIC_BASE_URL="${currentBaseUrl.value}"
-ANTHROPIC_AUTH_TOKEN="${key}"`
+ANTHROPIC_AUTH_TOKEN="${key}"
- try {
- await navigator.clipboard.writeText(configText)
- showToast('配置信息已复制到剪贴板', 'success')
- } catch (error) {
- // console.error('Failed to copy:', error)
- // 降级方案:创建一个临时文本区域
- const textArea = document.createElement('textarea')
- textArea.value = configText
- document.body.appendChild(textArea)
- textArea.select()
- try {
- document.execCommand('copy')
- showToast('配置信息已复制到剪贴板', 'success')
- } catch (fallbackError) {
- showToast('复制失败,请手动复制', 'error')
- } finally {
- document.body.removeChild(textArea)
- }
+# 提示:如需调用 /droid/claude 端点(已在后台添加 Droid 账号),请将 ANTHROPIC_BASE_URL 改为 "${droidEndpoint.value}" 或根据实际环境调整。`
+
+ await copyTextWithFallback(configText, '配置信息已复制到剪贴板')
+}
+
+// 仅复制密钥
+const copyKeyOnly = async () => {
+ const key = props.apiKey.apiKey || props.apiKey.key || ''
+ if (!key) {
+ showToast('API Key 不存在', 'error')
+ return
}
+
+ await copyTextWithFallback(key, 'API Key 已复制')
}
// 关闭弹窗(带确认)