From 122f544df21f27f422a09f1894b82d791be8b303 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 22 Jun 2026 14:39:29 +0800 Subject: [PATCH] feat: Optimize the multilingual management module --- .../packages/@abp/localization/package.json | 1 + .../localization/src/api/useLanguagesApi.ts | 25 +++--- .../localization/src/api/useResourcesApi.ts | 25 +++--- .../@abp/localization/src/api/useTextsApi.ts | 17 +++- .../languages/LocalizationLanguageTable.vue | 55 +++---------- .../resources/LocalizationResourceTable.vue | 54 +++---------- .../texts/LocalizationTextModal.vue | 30 +++---- .../texts/LocalizationTextTable.vue | 78 +++++++++++++++---- .../@abp/localization/src/types/languages.ts | 9 ++- .../@abp/localization/src/types/resources.ts | 9 ++- .../@abp/localization/src/types/texts.ts | 4 +- .../AIServiceModule.cs | 2 - .../LINGYUN.Abp.MicroService.AIService.csproj | 1 - .../AdminServiceModule.cs | 2 - ...NGYUN.Abp.MicroService.AdminService.csproj | 1 - .../IdentityServiceModule.cs | 3 - ...UN.Abp.MicroService.IdentityService.csproj | 1 - ...YUN.Abp.MicroService.MessageService.csproj | 1 - .../MessageServiceModule.cs | 2 - .../appsettings.json | 3 - ...UN.Abp.MicroService.PlatformService.csproj | 1 - .../PlatformServiceModule.cs | 2 - ...INGYUN.Abp.MicroService.TaskService.csproj | 1 - .../TaskServiceModule.cs | 2 - ...GYUN.Abp.MicroService.WeChatService.csproj | 1 - .../WeChatServiceModule.cs | 2 - ...YUN.Abp.MicroService.WebhookService.csproj | 1 - .../WebhookServiceModule.cs | 2 - ...UN.Abp.MicroService.WorkflowService.csproj | 1 - .../WorkflowServiceModule.cs | 2 - .../AbpAspNetCoreMvcLocalizationModule.cs | 2 + .../ILanguageAppService.cs | 6 +- .../IResourceAppService.cs | 3 + .../LocalizationManagement/ITextAppService.cs | 11 ++- .../LanguageGetPagedListInput.cs | 8 ++ .../ResourceGetPagedListInput.cs | 8 ++ .../LocalizationManagement/TextDeleteInput.cs | 19 +++++ .../TextDifferenceDto.cs | 11 +++ .../TextDifferenceGetListInput.cs | 18 +++++ .../Abp/LocalizationManagement/TextDto.cs | 9 +++ .../TextGetByKeyInput.cs | 15 ++++ .../LanguageAppService.cs | 23 ++++++ .../ResourceAppService.cs | 23 ++++++ .../LocalizationManagement/TextAppService.cs | 78 +++++++++++++++++++ .../Localization/Resources/en.json | 20 ++++- .../Localization/Resources/zh-Hans.json | 20 ++++- ...micLocalizationInitializerEventHandler.cs} | 65 ++++++++++++++-- .../ILanguageRepository.cs | 15 +++- .../IResourceRepository.cs | 15 +++- .../EfCoreLanguageRepository.cs | 25 ++++++ .../EfCoreResourceRepository.cs | 25 ++++++ ....Abp.LocalizationManagement.HttpApi.csproj | 5 +- .../AbpLocalizationManagementHttpApiModule.cs | 8 +- .../LanguageController.cs | 7 ++ .../ResourceController.cs | 7 ++ .../LocalizationManagement/TextController.cs | 24 +++++- ...LY.MicroService.Applications.Single.csproj | 1 - .../MicroServiceApplicationsSingleModule.cs | 3 - .../AuthServerHttpApiHostModule.cs | 3 - ...icroService.AuthServer.HttpApi.Host.csproj | 1 - .../BackendAdminHttpApiHostModule.cs | 2 - ...roService.BackendAdmin.HttpApi.Host.csproj | 1 - ...ice.PlatformManagement.HttpApi.Host.csproj | 1 - .../PlatformManagementHttpApiHostModule.cs | 2 - ...ervice.RealtimeMessage.HttpApi.Host.csproj | 1 - .../RealtimeMessageHttpApiHostModule.cs | 2 - ...Service.TaskManagement.HttpApi.Host.csproj | 1 - .../TaskManagementHttpApiHostModule.cs | 2 - ...ice.WebhooksManagement.HttpApi.Host.csproj | 1 - .../WebhooksManagementHttpApiHostModule.cs | 2 - ...rvice.WechatManagement.HttpApi.Host.csproj | 1 - .../WechatManagementHttpApiHostModule.cs | 2 - ...ice.WorkflowManagement.HttpApi.Host.csproj | 1 - .../WorkflowManagementHttpApiHostModule.cs | 2 - 74 files changed, 599 insertions(+), 238 deletions(-) create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/LanguageGetPagedListInput.cs create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/ResourceGetPagedListInput.cs create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/TextDeleteInput.cs create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/TextDifferenceDto.cs create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/TextDifferenceGetListInput.cs create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/TextDto.cs create mode 100644 aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Application.Contracts/LINGYUN/Abp/LocalizationManagement/TextGetByKeyInput.cs rename aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Domain/LINGYUN/Abp/LocalizationManagement/{DynamicLocalizationInitializerEeventHandler.cs => DynamicLocalizationInitializerEventHandler.cs} (84%) diff --git a/apps/vben5/packages/@abp/localization/package.json b/apps/vben5/packages/@abp/localization/package.json index 2f4edeac4..bb9d92254 100644 --- a/apps/vben5/packages/@abp/localization/package.json +++ b/apps/vben5/packages/@abp/localization/package.json @@ -32,6 +32,7 @@ "@vben/icons": "workspace:*", "@vben/layouts": "workspace:*", "@vben/locales": "workspace:*", + "@vueuse/core": "catalog:", "ant-design-vue": "catalog:", "dayjs": "catalog:", "vue": "catalog:", diff --git a/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts b/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts index 3b6469063..030038d21 100644 --- a/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts +++ b/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts @@ -1,9 +1,9 @@ -import type { ListResultDto } from '@abp/core'; +import type { PagedResultDto } from '@abp/core'; import type { LanguageCreateDto, LanguageDto, - LanguageGetListInput, + LanguageGetPagedListInput, LanguageUpdateDto, } from '../types/languages'; @@ -13,20 +13,17 @@ export function useLanguagesApi() { const { cancel, request } = useRequest(); /** - * 查询语言列表 + * 查询语言分页列表 * @param input 参数 * @returns 语言列表 */ - function getListApi( - input?: LanguageGetListInput, - ): Promise> { - return request>( - '/api/abp/localization/languages', - { - method: 'GET', - params: input, - }, - ); + function getPagedListApi( + input?: LanguageGetPagedListInput, + ): Promise> { + return request>('/api/localization/languages', { + method: 'GET', + params: input, + }); } /** @@ -83,7 +80,7 @@ export function useLanguagesApi() { createApi, deleteApi, getApi, - getListApi, + getPagedListApi, updateApi, }; } diff --git a/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts b/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts index a8bcd38e5..8db0ab7aa 100644 --- a/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts +++ b/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts @@ -1,9 +1,9 @@ -import type { ListResultDto } from '@abp/core'; +import type { PagedResultDto } from '@abp/core'; import type { ResourceCreateDto, ResourceDto, - ResourceGetListInput, + ResourceGetPagedListInput, ResourceUpdateDto, } from '../types/resources'; @@ -13,20 +13,17 @@ export function useResourcesApi() { const { cancel, request } = useRequest(); /** - * 查询资源列表 + * 查询资源分页列表 * @param input 参数 * @returns 资源列表 */ - function getListApi( - input?: ResourceGetListInput, - ): Promise> { - return request>( - '/api/abp/localization/resources', - { - method: 'GET', - params: input, - }, - ); + function getPagedListApi( + input?: ResourceGetPagedListInput, + ): Promise> { + return request>('/api/localization/resources', { + method: 'GET', + params: input, + }); } /** @@ -83,7 +80,7 @@ export function useResourcesApi() { createApi, deleteApi, getApi, - getListApi, + getPagedListApi, updateApi, }; } diff --git a/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts b/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts index d3fa49576..49e55ef47 100644 --- a/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts +++ b/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts @@ -1,6 +1,7 @@ import type { ListResultDto } from '@abp/core'; import type { + DeleteTextInput, GetTextByKeyInput, GetTextsInput, SetTextInput, @@ -22,7 +23,7 @@ export function useTextsApi() { input: GetTextsInput, ): Promise> { return request>( - '/api/abp/localization/texts', + '/api/localization/texts', { method: 'GET', params: input, @@ -36,7 +37,7 @@ export function useTextsApi() { * @returns 查询的文本 */ function getApi(input: GetTextByKeyInput): Promise { - return request('/api/abp/localization/texts/by-culture-key', { + return request('/api/localization/texts/by-key', { method: 'GET', params: input, }); @@ -53,8 +54,20 @@ export function useTextsApi() { }); } + /** + * 删除文本 + * @param input 参数 + */ + function deleteApi(input: DeleteTextInput): Promise { + return request('/api/localization/texts', { + data: input, + method: 'DELETE', + }); + } + return { cancel, + deleteApi, getApi, getListApi, setApi, diff --git a/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue index 5bce04b41..90aebacf9 100644 --- a/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue +++ b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue @@ -5,12 +5,12 @@ import type { VbenFormProps } from '@vben/common-ui'; import type { LanguageDto } from '../../types/languages'; -import { defineAsyncComponent, h, onMounted, ref } from 'vue'; +import { defineAsyncComponent, h } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { sortby, useAbpStore } from '@abp/core'; +import { useAbpStore } from '@abp/core'; import { useVbenVxeGrid } from '@abp/ui'; import { DeleteOutlined, @@ -27,19 +27,13 @@ defineOptions({ name: 'LocalizationLanguageTable', }); -const dataSource = ref([]); - const abpStore = useAbpStore(); -const { deleteApi, getListApi } = useLanguagesApi(); +const { deleteApi, getPagedListApi } = useLanguagesApi(); const { getLocalizationApi } = useLocalizationsApi(); const formOptions: VbenFormProps = { // 默认展开 collapsed: false, - handleReset: onReset, - async handleSubmit(params) { - await onGet(params); - }, schema: [ { component: 'Input', @@ -89,20 +83,13 @@ const gridOptions: VxeGridProps = { keepSource: true, proxyConfig: { ajax: { - query: async ({ page, sort }) => { - let items = sortby(dataSource.value, sort.field); - if (sort.order === 'desc') { - items = items.toReversed(); - } - const result = { - totalCount: dataSource.value.length, - items: items.slice( - (page.currentPage - 1) * page.pageSize, - page.currentPage * page.pageSize, - ), - }; - return new Promise((resolve) => { - resolve(result); + query: async ({ page, sort }, formValues) => { + const sorting = sort.order ? `${sort.field} ${sort.order}` : undefined; + return await getPagedListApi({ + sorting, + maxResultCount: page.pageSize, + skipCount: (page.currentPage - 1) * page.pageSize, + ...formValues, }); }, }, @@ -137,23 +124,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ gridOptions, }); -async function onGet(input?: Record) { - try { - gridApi.setLoading(true); - const { items } = await getListApi(input); - dataSource.value = items; - setTimeout(() => gridApi.reload(), 100); - } finally { - gridApi.setLoading(false); - } -} - -async function onReset() { - await gridApi.formApi.resetForm(); - const input = await gridApi.formApi.getValues(); - await onGet(input); -} - function onCreate() { modalApi.setData({}); modalApi.open(); @@ -178,8 +148,6 @@ function onDelete(row: LanguageDto) { } async function onChange(data: LanguageDto) { - const input = await gridApi.formApi.getValues(); - onGet(input); // 资源变化刷新本地多语言缓存 const cultureName = abpStore.application!.localization.currentCulture.cultureName; @@ -190,8 +158,6 @@ async function onChange(data: LanguageDto) { abpStore.setLocalization(localization); } } - -onMounted(onGet);