feat(tenant): expose API Key reset from the API Info page

Add a danger-themed reset button next to the existing copy/eye buttons
on the API Info settings page. Confirmation dialog warns that the old
key is revoked immediately; on success the new plaintext key replaces
the displayed value and is auto-revealed so the user can copy it.

Backend: new POST /api/v1/tenants/:id/api-key handler that wraps the
existing TenantService.UpdateAPIKey; access is gated by the same
authorizeTenantAccess check as other tenant endpoints. The handler
returns the freshly generated plaintext key, while the encrypted form
is persisted to the database.

Frontend: new resetTenantApiKey API client, reset button + confirm
dialog wiring in ApiInfo.vue, plus matching i18n entries for zh-CN,
en-US, ko-KR, and ru-RU.
This commit is contained in:
wizardchen
2026-04-29 20:00:46 +08:00
committed by lyingbug
parent cbdfba0075
commit 7fcd92994b
8 changed files with 150 additions and 3 deletions
+18 -1
View File
@@ -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过滤)
*/