From b2411542eb544f971a76baf5142a819a2ed386fe Mon Sep 17 00:00:00 2001 From: wizardchen Date: Sat, 16 May 2026 04:09:30 +0800 Subject: [PATCH] feat(tenant): add tenant name update functionality and enhance UI Implemented a new API endpoint for updating tenant names, allowing owners to edit tenant information directly within the UI. The frontend now supports inline editing with success and error notifications. Additionally, internationalization files have been updated to include relevant messages for the new functionality across English, Korean, Russian, and Chinese languages, ensuring a consistent user experience. Refs: #1303 --- frontend/src/api/tenant/index.ts | 23 ++- frontend/src/i18n/locales/en-US.ts | 10 +- frontend/src/i18n/locales/ko-KR.ts | 8 + frontend/src/i18n/locales/ru-RU.ts | 12 +- frontend/src/i18n/locales/zh-CN.ts | 8 + frontend/src/views/settings/TenantInfo.vue | 167 +++++++++++++++--- frontend/src/views/settings/TenantMembers.vue | 167 +++++++++++++++--- 7 files changed, 339 insertions(+), 56 deletions(-) diff --git a/frontend/src/api/tenant/index.ts b/frontend/src/api/tenant/index.ts index 15055ebd..2b728fab 100644 --- a/frontend/src/api/tenant/index.ts +++ b/frontend/src/api/tenant/index.ts @@ -1,4 +1,4 @@ -import { get, post } from '@/utils/request' +import { get, post, put } from '@/utils/request' import i18n from '@/i18n' const t = (key: string) => i18n.global.t(key) @@ -70,6 +70,27 @@ export async function resetTenantApiKey( } } +/** + * 更新租户信息(目前仅暴露租户名称编辑入口)。 + * 后端 `PUT /tenants/:id` 走 GORM 的 `Updates(tenant)`,只会写入请求体里 + * 出现的非零字段;这里只发送 `name` 就只会改名字,不会把其它字段清空。 + * 权限:owner(与 router.go 中的 g.Owner() 守卫保持一致)。 + */ +export async function updateTenant( + tenantId: number, + payload: { name: string }, +): Promise<{ success: boolean; data?: TenantInfo; message?: string }> { + try { + const response = await put(`/api/v1/tenants/${tenantId}`, payload) + return response as unknown as { success: boolean; data?: TenantInfo; message?: string } + } catch (error: any) { + return { + success: false, + message: error.message || t('error.tenant.updateFailed'), + } + } +} + /** * 搜索租户(支持分页、关键词搜索和租户ID过滤) */ diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index d6e7f020..a63f714e 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -2354,7 +2354,14 @@ export default { statusLabel: 'Tenant Status', statusDescription: 'Current operational status of the tenant', createdAtLabel: 'Tenant Creation Time', - createdAtDescription: 'Time when the tenant was created' + createdAtDescription: 'Time when the tenant was created', + editName: 'Edit name', + editNamePlaceholder: 'Enter the new tenant name', + editNameConfirm: 'Save', + editNameCancel: 'Cancel', + editNameRequired: 'Tenant name cannot be empty', + editNameSuccess: 'Tenant name updated', + editNameFailed: 'Failed to update tenant name' }, storage: { quotaLabel: 'Storage Quota', @@ -2508,6 +2515,7 @@ export default { listFailed: 'Failed to list tenants', searchFailed: 'Failed to search tenants', resetApiKeyFailed: 'Failed to reset API Key', + updateFailed: 'Failed to update tenant information', }, initialization: { checkFailed: 'Check failed', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 9e5249b2..a782f750 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -1612,6 +1612,13 @@ export default { statusDescription: "테넌트의 현재 운영 상태", createdAtLabel: "테넌트 생성 시간", createdAtDescription: "테넌트가 생성된 시간", + editName: "이름 수정", + editNamePlaceholder: "새 테넌트 이름을 입력하세요", + editNameConfirm: "저장", + editNameCancel: "취소", + editNameRequired: "테넌트 이름은 비어 있을 수 없습니다", + editNameSuccess: "테넌트 이름이 업데이트되었습니다", + editNameFailed: "테넌트 이름 업데이트 실패", }, storage: { quotaLabel: "저장소 할당량", @@ -1765,6 +1772,7 @@ export default { listFailed: '테넌트 목록 조회 실패', searchFailed: '테넌트 검색 실패', resetApiKeyFailed: 'API 키 재설정 실패', + updateFailed: '테넌트 정보 업데이트 실패', }, initialization: { checkFailed: '검사 실패', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 35ced6b5..14c20650 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -1429,7 +1429,14 @@ export default { statusLabel: 'Статус арендатора', statusDescription: 'Текущий рабочий статус арендатора', createdAtLabel: 'Время создания арендатора', - createdAtDescription: 'Дата и время создания арендатора' + createdAtDescription: 'Дата и время создания арендатора', + editName: 'Изменить имя', + editNamePlaceholder: 'Введите новое имя арендатора', + editNameConfirm: 'Сохранить', + editNameCancel: 'Отмена', + editNameRequired: 'Имя арендатора не может быть пустым', + editNameSuccess: 'Имя арендатора обновлено', + editNameFailed: 'Не удалось обновить имя арендатора' }, storage: { quotaLabel: 'Квота хранения', @@ -1580,7 +1587,8 @@ export default { tenant: { listFailed: 'Не удалось получить список тенантов', searchFailed: 'Не удалось выполнить поиск тенантов', - resetApiKeyFailed: 'Не удалось сбросить API Key' + resetApiKeyFailed: 'Не удалось сбросить API Key', + updateFailed: 'Не удалось обновить информацию об арендаторе' }, initialization: { checkFailed: 'Проверка не пройдена', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index dd546843..9fbf9639 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1592,6 +1592,13 @@ export default { statusDescription: "租户当前的运行状态", createdAtLabel: "租户创建时间", createdAtDescription: "租户创建的时间", + editName: "修改名称", + editNamePlaceholder: "请输入新的租户名称", + editNameConfirm: "保存", + editNameCancel: "取消", + editNameRequired: "租户名称不能为空", + editNameSuccess: "租户名称已更新", + editNameFailed: "更新租户名称失败", }, storage: { quotaLabel: "存储配额", @@ -1744,6 +1751,7 @@ export default { listFailed: "获取租户列表失败", searchFailed: "搜索租户失败", resetApiKeyFailed: "重置 API Key 失败", + updateFailed: "更新租户信息失败", }, initialization: { checkFailed: "检查失败", diff --git a/frontend/src/views/settings/TenantInfo.vue b/frontend/src/views/settings/TenantInfo.vue index 8084d301..af6f02f9 100644 --- a/frontend/src/views/settings/TenantInfo.vue +++ b/frontend/src/views/settings/TenantInfo.vue @@ -40,7 +40,30 @@

{{ $t('tenant.details.nameDescription') }}

- {{ tenantInfo?.name || '-' }} + + + +
+ + + {{ $t('tenant.details.editNameConfirm') }} + + + {{ $t('tenant.details.editNameCancel') }} + +
@@ -73,11 +96,7 @@

{{ $t('tenant.details.statusDescription') }}

- + {{ getStatusText(tenantInfo?.status) }}
@@ -125,13 +144,8 @@
{{ getUsagePercentage() }}% - +
@@ -141,25 +155,109 @@