diff --git a/frontend/src/api/tenant/index.ts b/frontend/src/api/tenant/index.ts index 1f99d467..15055ebd 100644 --- a/frontend/src/api/tenant/index.ts +++ b/frontend/src/api/tenant/index.ts @@ -1,4 +1,4 @@ -import { get } from '@/utils/request' +import { get, post } from '@/utils/request' import i18n from '@/i18n' const t = (key: string) => i18n.global.t(key) @@ -53,6 +53,23 @@ export async function listAllTenants(): Promise<{ success: boolean; data?: { ite } } +/** + * 重置租户的 API Key。成功后返回新的明文 Key,旧 Key 立即失效。 + */ +export async function resetTenantApiKey( + tenantId: number, +): Promise<{ success: boolean; data?: { api_key: string }; message?: string }> { + try { + const response = await post(`/api/v1/tenants/${tenantId}/api-key`) + return response as unknown as { success: boolean; data?: { api_key: string }; message?: string } + } catch (error: any) { + return { + success: false, + message: error.message || t('error.tenant.resetApiKeyFailed'), + } + } +} + /** * 搜索租户(支持分页、关键词搜索和租户ID过滤) */ diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 74f1ba87..0074845e 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -2206,6 +2206,13 @@ export default { copyUrlTitle: 'Copy API URL', urlCopySuccess: 'API URL copied to clipboard', copyTitle: 'Copy API Key', + resetTitle: 'Reset API Key', + resetConfirmTitle: 'Reset API Key?', + resetConfirmBody: 'After reset, the old API Key is revoked immediately. Every app, SDK, and script using the old key must switch to the new key to keep working. This action cannot be undone.', + resetConfirmOk: 'Reset', + resetConfirmCancel: 'Cancel', + resetSuccess: 'API Key reset; the new key is shown in the field above', + resetFailed: 'Failed to reset API Key', docLabel: 'API Documentation', docDescription: 'View complete API documentation and examples,', openDoc: 'Open documentation', @@ -2316,6 +2323,7 @@ export default { tenant: { listFailed: 'Failed to list tenants', searchFailed: 'Failed to search tenants', + resetApiKeyFailed: 'Failed to reset API Key', }, initialization: { checkFailed: 'Check failed', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 2179f17a..cb5c9116 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -1573,6 +1573,13 @@ export default { copyUrlTitle: "API URL 복사", urlCopySuccess: "API URL이 클립보드에 복사되었습니다", copyTitle: "API 키 복사", + resetTitle: "API 키 재설정", + resetConfirmTitle: "API 키를 재설정할까요?", + resetConfirmBody: "재설정하면 기존 API 키는 즉시 무효화됩니다. 기존 키를 사용하는 앱, SDK, 스크립트는 모두 새 키로 교체해야 계속 사용할 수 있습니다. 이 작업은 되돌릴 수 없습니다.", + resetConfirmOk: "재설정", + resetConfirmCancel: "취소", + resetSuccess: "API 키가 재설정되었습니다. 새 키는 위 입력란에 표시됩니다", + resetFailed: "API 키 재설정에 실패했습니다", docLabel: "API 문서", docDescription: "전체 API 호출 문서 및 예시 보기, ", openDoc: "문서 열기", @@ -1684,6 +1691,7 @@ export default { tenant: { listFailed: '테넌트 목록 조회 실패', searchFailed: '테넌트 검색 실패', + resetApiKeyFailed: 'API 키 재설정 실패', }, initialization: { checkFailed: '검사 실패', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 7eb834ed..57dd89d0 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -1391,6 +1391,13 @@ export default { copyUrlTitle: 'Скопировать URL API', urlCopySuccess: 'URL API скопирован в буфер обмена', copyTitle: 'Скопировать API Key', + resetTitle: 'Сбросить API Key', + resetConfirmTitle: 'Сбросить API Key?', + resetConfirmBody: 'После сброса прежний API Key немедленно перестаёт действовать. Все приложения, SDK и скрипты, использующие старый ключ, должны быть переведены на новый ключ. Это действие нельзя отменить.', + resetConfirmOk: 'Сбросить', + resetConfirmCancel: 'Отмена', + resetSuccess: 'API Key сброшен; новый ключ показан в поле выше', + resetFailed: 'Не удалось сбросить API Key', docLabel: 'Документация API', docDescription: 'Ознакомьтесь с полной документацией и примерами API,', openDoc: 'Открыть документацию', @@ -1499,7 +1506,8 @@ export default { }, tenant: { listFailed: 'Не удалось получить список тенантов', - searchFailed: 'Не удалось выполнить поиск тенантов' + searchFailed: 'Не удалось выполнить поиск тенантов', + resetApiKeyFailed: 'Не удалось сбросить API Key' }, initialization: { checkFailed: 'Проверка не пройдена', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 28f9d837..e42782d2 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1554,6 +1554,13 @@ export default { copyUrlTitle: "复制 API 地址", urlCopySuccess: "API 地址已复制到剪贴板", copyTitle: "复制 API Key", + resetTitle: "重置 API Key", + resetConfirmTitle: "确认重置 API Key?", + resetConfirmBody: "重置后,旧的 API Key 会立即失效,所有使用旧 Key 的应用、SDK 与脚本必须更换为新 Key 才能继续访问。此操作不可撤销。", + resetConfirmOk: "确认重置", + resetConfirmCancel: "取消", + resetSuccess: "API Key 已重置,新 Key 已显示在输入框中", + resetFailed: "重置 API Key 失败", docLabel: "API 文档", docDescription: "查看完整的 API 调用文档和示例,", openDoc: "打开文档", @@ -1664,6 +1671,7 @@ export default { tenant: { listFailed: "获取租户列表失败", searchFailed: "搜索租户失败", + resetApiKeyFailed: "重置 API Key 失败", }, initialization: { checkFailed: "检查失败", diff --git a/frontend/src/views/settings/ApiInfo.vue b/frontend/src/views/settings/ApiInfo.vue index 5cc17e1c..ba1bdb66 100644 --- a/frontend/src/views/settings/ApiInfo.vue +++ b/frontend/src/views/settings/ApiInfo.vue @@ -51,6 +51,16 @@ > + + + @@ -213,8 +223,9 @@