From 594b345a3d20a8ff5a985200f66f89686ab00f6c Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Mar 2025 15:25:51 +0800 Subject: [PATCH 1/6] feat(vben5): add @abp/localization package --- apps/vben5/apps/app-antd/package.json | 1 + .../app-antd/src/locales/langs/en-US/abp.json | 4 + .../app-antd/src/locales/langs/zh-CN/abp.json | 4 + .../app-antd/src/router/routes/modules/abp.ts | 20 ++ .../views/localization/resources/index.vue | 15 ++ .../packages/@abp/localization/package.json | 40 +++ .../@abp/localization/src/api/index.ts | 2 + .../src/api/useLocalizationsApi.ts | 28 +++ .../localization/src/api/useResourcesApi.ts | 89 +++++++ .../@abp/localization/src/components/index.ts | 1 + .../resources/LocalizationResourceModal.vue | 125 ++++++++++ .../resources/LocalizationResourceTable.vue | 234 ++++++++++++++++++ .../@abp/localization/src/constants/index.ts | 1 + .../localization/src/constants/permissions.ts | 10 + .../packages/@abp/localization/src/index.ts | 3 + .../@abp/localization/src/types/index.ts | 1 + .../@abp/localization/src/types/resources.ts | 33 +++ .../packages/@abp/localization/tsconfig.json | 6 + 18 files changed, 617 insertions(+) create mode 100644 apps/vben5/apps/app-antd/src/views/localization/resources/index.vue create mode 100644 apps/vben5/packages/@abp/localization/package.json create mode 100644 apps/vben5/packages/@abp/localization/src/api/index.ts create mode 100644 apps/vben5/packages/@abp/localization/src/api/useLocalizationsApi.ts create mode 100644 apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts create mode 100644 apps/vben5/packages/@abp/localization/src/components/index.ts create mode 100644 apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceModal.vue create mode 100644 apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue create mode 100644 apps/vben5/packages/@abp/localization/src/constants/index.ts create mode 100644 apps/vben5/packages/@abp/localization/src/constants/permissions.ts create mode 100644 apps/vben5/packages/@abp/localization/src/index.ts create mode 100644 apps/vben5/packages/@abp/localization/src/types/index.ts create mode 100644 apps/vben5/packages/@abp/localization/src/types/resources.ts create mode 100644 apps/vben5/packages/@abp/localization/tsconfig.json diff --git a/apps/vben5/apps/app-antd/package.json b/apps/vben5/apps/app-antd/package.json index adfaf25a1..b4b1336ef 100644 --- a/apps/vben5/apps/app-antd/package.json +++ b/apps/vben5/apps/app-antd/package.json @@ -31,6 +31,7 @@ "@abp/core": "workspace:*", "@abp/features": "workspace:*", "@abp/identity": "workspace:*", + "@abp/localization": "workspace:*", "@abp/notifications": "workspace:*", "@abp/openiddict": "workspace:*", "@abp/permissions": "workspace:*", diff --git a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json index 7e50c1168..c1bf002b0 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json @@ -45,6 +45,10 @@ "myNotifilers": "My Notifilers", "groups": "Groups", "definitions": "Definitions" + }, + "localization": { + "title": "Localization", + "resources": "Resources" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json index 7976ea8f7..9572acc11 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json @@ -45,6 +45,10 @@ "myNotifilers": "我的通知", "groups": "通知分组", "definitions": "通知定义" + }, + "localization": { + "title": "本地化管理", + "resources": "资源管理" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts index 3504f198a..8a8f6477a 100644 --- a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts +++ b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts @@ -175,6 +175,26 @@ const routes: RouteRecordRaw[] = [ }, ], }, + { + meta: { + title: $t('abp.manage.localization.title'), + icon: 'ion:globe-outline', + }, + name: 'LocalizationManagement', + path: '/manage/localization', + children: [ + { + meta: { + title: $t('abp.manage.localization.resources'), + icon: 'grommet-icons:resources', + }, + name: 'LocalizationResources', + path: '/manage/localization/resources', + component: () => + import('#/views/localization/resources/index.vue'), + }, + ], + }, { meta: { title: $t('abp.manage.identity.auditLogs'), diff --git a/apps/vben5/apps/app-antd/src/views/localization/resources/index.vue b/apps/vben5/apps/app-antd/src/views/localization/resources/index.vue new file mode 100644 index 000000000..114495512 --- /dev/null +++ b/apps/vben5/apps/app-antd/src/views/localization/resources/index.vue @@ -0,0 +1,15 @@ + + + diff --git a/apps/vben5/packages/@abp/localization/package.json b/apps/vben5/packages/@abp/localization/package.json new file mode 100644 index 000000000..121edef76 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/package.json @@ -0,0 +1,40 @@ +{ + "name": "@abp/localization", + "version": "9.0.4", + "homepage": "https://github.com/colinin/abp-next-admin", + "bugs": "https://github.com/colinin/abp-next-admin/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/colinin/abp-next-admin.git", + "directory": "packages/@abp/localization" + }, + "license": "MIT", + "type": "module", + "sideEffects": [ + "**/*.css" + ], + "exports": { + ".": { + "types": "./src/index.ts", + "default": "./src/index.ts" + } + }, + "dependencies": { + "@abp/components": "workspace:*", + "@abp/core": "workspace:*", + "@abp/request": "workspace:*", + "@abp/signalr": "workspace:*", + "@abp/ui": "workspace:*", + "@ant-design/icons-vue": "catalog:", + "@vben/access": "workspace:*", + "@vben/common-ui": "workspace:*", + "@vben/hooks": "workspace:*", + "@vben/icons": "workspace:*", + "@vben/layouts": "workspace:*", + "@vben/locales": "workspace:*", + "ant-design-vue": "catalog:", + "dayjs": "catalog:", + "vue": "catalog:*", + "vxe-table": "catalog:" + } +} diff --git a/apps/vben5/packages/@abp/localization/src/api/index.ts b/apps/vben5/packages/@abp/localization/src/api/index.ts new file mode 100644 index 000000000..d0bdf1313 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/api/index.ts @@ -0,0 +1,2 @@ +export { useLocalizationsApi } from './useLocalizationsApi'; +export { useResourcesApi } from './useResourcesApi'; diff --git a/apps/vben5/packages/@abp/localization/src/api/useLocalizationsApi.ts b/apps/vben5/packages/@abp/localization/src/api/useLocalizationsApi.ts new file mode 100644 index 000000000..bfb6975ac --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/api/useLocalizationsApi.ts @@ -0,0 +1,28 @@ +import type { ApplicationLocalizationDto } from '@abp/core'; + +import { useRequest } from '@abp/request'; + +export function useLocalizationsApi() { + const { cancel, request } = useRequest(); + /** + * 获取应用程序语言 + * @returns 本地化配置 + */ + function getLocalizationApi(options: { + cultureName: string; + onlyDynamics?: boolean; + }): Promise { + return request( + '/api/abp/application-localization', + { + method: 'GET', + params: options, + }, + ); + } + + return { + cancel, + getLocalizationApi, + }; +} diff --git a/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts b/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts new file mode 100644 index 000000000..a8bcd38e5 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/api/useResourcesApi.ts @@ -0,0 +1,89 @@ +import type { ListResultDto } from '@abp/core'; + +import type { + ResourceCreateDto, + ResourceDto, + ResourceGetListInput, + ResourceUpdateDto, +} from '../types/resources'; + +import { useRequest } from '@abp/request'; + +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, + }, + ); + } + + /** + * 查询资源 + * @param name 资源名称 + * @returns 查询的资源 + */ + function getApi(name: string): Promise { + return request(`/api/localization/resources/${name}`, { + method: 'GET', + }); + } + + /** + * 删除资源 + * @param name 资源名称 + */ + function deleteApi(name: string): Promise { + return request(`/api/localization/resources/${name}`, { + method: 'DELETE', + }); + } + + /** + * 创建资源 + * @param input 参数 + * @returns 创建的资源 + */ + function createApi(input: ResourceCreateDto): Promise { + return request(`/api/localization/resources`, { + data: input, + method: 'POST', + }); + } + + /** + * 编辑资源 + * @param name 资源名称 + * @param input 参数 + * @returns 编辑的资源 + */ + function updateApi( + name: string, + input: ResourceUpdateDto, + ): Promise { + return request(`/api/localization/resources/${name}`, { + data: input, + method: 'PUT', + }); + } + + return { + cancel, + createApi, + deleteApi, + getApi, + getListApi, + updateApi, + }; +} diff --git a/apps/vben5/packages/@abp/localization/src/components/index.ts b/apps/vben5/packages/@abp/localization/src/components/index.ts new file mode 100644 index 000000000..78dfadb28 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/components/index.ts @@ -0,0 +1 @@ +export { default as LocalizationResourceTable } from './resources/LocalizationResourceTable.vue'; diff --git a/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceModal.vue b/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceModal.vue new file mode 100644 index 000000000..5ea5f6bb9 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceModal.vue @@ -0,0 +1,125 @@ + + + + + diff --git a/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue b/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue new file mode 100644 index 000000000..9aad82e66 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue @@ -0,0 +1,234 @@ + + + + + diff --git a/apps/vben5/packages/@abp/localization/src/constants/index.ts b/apps/vben5/packages/@abp/localization/src/constants/index.ts new file mode 100644 index 000000000..c85954d3e --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/constants/index.ts @@ -0,0 +1 @@ +export * from './permissions'; diff --git a/apps/vben5/packages/@abp/localization/src/constants/permissions.ts b/apps/vben5/packages/@abp/localization/src/constants/permissions.ts new file mode 100644 index 000000000..f8efa3338 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/constants/permissions.ts @@ -0,0 +1,10 @@ +/** 资源管理权限 */ +export const ResourcesPermissions = { + /** 新增 */ + Create: 'LocalizationManagement.Resource.Create', + Default: 'LocalizationManagement.Resource', + /** 删除 */ + Delete: 'LocalizationManagement.Resource.Delete', + /** 更新 */ + Update: 'LocalizationManagement.Resource.Update', +}; diff --git a/apps/vben5/packages/@abp/localization/src/index.ts b/apps/vben5/packages/@abp/localization/src/index.ts new file mode 100644 index 000000000..314dad0cd --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/index.ts @@ -0,0 +1,3 @@ +export * from './api'; +export * from './components'; +export * from './types'; diff --git a/apps/vben5/packages/@abp/localization/src/types/index.ts b/apps/vben5/packages/@abp/localization/src/types/index.ts new file mode 100644 index 000000000..00e67e02e --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/types/index.ts @@ -0,0 +1 @@ +export * from './resources'; diff --git a/apps/vben5/packages/@abp/localization/src/types/resources.ts b/apps/vben5/packages/@abp/localization/src/types/resources.ts new file mode 100644 index 000000000..8523c0094 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/types/resources.ts @@ -0,0 +1,33 @@ +import type { AuditedEntityDto } from '@abp/core'; + +interface ResourceDto extends AuditedEntityDto { + defaultCultureName?: string; + description?: string; + displayName: string; + enable: boolean; + name: string; +} + +interface ResourceCreateOrUpdateDto { + defaultCultureName?: string; + description?: string; + displayName: string; + enable: boolean; +} + +interface ResourceCreateDto extends ResourceCreateOrUpdateDto { + name: string; +} + +type ResourceUpdateDto = ResourceCreateOrUpdateDto; + +interface ResourceGetListInput { + filter?: string; +} + +export type { + ResourceCreateDto, + ResourceDto, + ResourceGetListInput, + ResourceUpdateDto, +}; diff --git a/apps/vben5/packages/@abp/localization/tsconfig.json b/apps/vben5/packages/@abp/localization/tsconfig.json new file mode 100644 index 000000000..ce1a891fb --- /dev/null +++ b/apps/vben5/packages/@abp/localization/tsconfig.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@vben/tsconfig/web.json", + "include": ["src"], + "exclude": ["node_modules"] +} From f4cc428834bd27f25cfd8cf7590ffed1d85b2219 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Mar 2025 15:45:57 +0800 Subject: [PATCH 2/6] feat(vben5): add language manage --- .../app-antd/src/locales/langs/en-US/abp.json | 3 +- .../app-antd/src/locales/langs/zh-CN/abp.json | 3 +- .../app-antd/src/router/routes/modules/abp.ts | 10 + .../views/localization/languages/index.vue | 15 ++ .../@abp/localization/src/api/index.ts | 1 + .../localization/src/api/useLanguagesApi.ts | 89 +++++++ .../@abp/localization/src/components/index.ts | 1 + .../languages/LocalizationLanguageModal.vue | 115 +++++++++ .../languages/LocalizationLanguageTable.vue | 240 ++++++++++++++++++ .../localization/src/constants/permissions.ts | 10 + .../@abp/localization/src/types/index.ts | 1 + .../@abp/localization/src/types/languages.ts | 30 +++ 12 files changed, 516 insertions(+), 2 deletions(-) create mode 100644 apps/vben5/apps/app-antd/src/views/localization/languages/index.vue create mode 100644 apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts create mode 100644 apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageModal.vue create mode 100644 apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue create mode 100644 apps/vben5/packages/@abp/localization/src/types/languages.ts diff --git a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json index c1bf002b0..5156e2b28 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json @@ -48,7 +48,8 @@ }, "localization": { "title": "Localization", - "resources": "Resources" + "resources": "Resources", + "languages": "Languages" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json index 9572acc11..5ea364714 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json @@ -48,7 +48,8 @@ }, "localization": { "title": "本地化管理", - "resources": "资源管理" + "resources": "资源管理", + "languages": "语言管理" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts index 8a8f6477a..43b422883 100644 --- a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts +++ b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts @@ -193,6 +193,16 @@ const routes: RouteRecordRaw[] = [ component: () => import('#/views/localization/resources/index.vue'), }, + { + meta: { + title: $t('abp.manage.localization.languages'), + icon: 'cil:language', + }, + name: 'LocalizationLanguages', + path: '/manage/localization/languages', + component: () => + import('#/views/localization/languages/index.vue'), + }, ], }, { diff --git a/apps/vben5/apps/app-antd/src/views/localization/languages/index.vue b/apps/vben5/apps/app-antd/src/views/localization/languages/index.vue new file mode 100644 index 000000000..b2c23dd24 --- /dev/null +++ b/apps/vben5/apps/app-antd/src/views/localization/languages/index.vue @@ -0,0 +1,15 @@ + + + diff --git a/apps/vben5/packages/@abp/localization/src/api/index.ts b/apps/vben5/packages/@abp/localization/src/api/index.ts index d0bdf1313..6857e0bad 100644 --- a/apps/vben5/packages/@abp/localization/src/api/index.ts +++ b/apps/vben5/packages/@abp/localization/src/api/index.ts @@ -1,2 +1,3 @@ +export { useLanguagesApi } from './useLanguagesApi'; export { useLocalizationsApi } from './useLocalizationsApi'; export { useResourcesApi } from './useResourcesApi'; diff --git a/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts b/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts new file mode 100644 index 000000000..3b6469063 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/api/useLanguagesApi.ts @@ -0,0 +1,89 @@ +import type { ListResultDto } from '@abp/core'; + +import type { + LanguageCreateDto, + LanguageDto, + LanguageGetListInput, + LanguageUpdateDto, +} from '../types/languages'; + +import { useRequest } from '@abp/request'; + +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, + }, + ); + } + + /** + * 查询语言 + * @param name 语言名称 + * @returns 查询的语言 + */ + function getApi(name: string): Promise { + return request(`/api/localization/languages/${name}`, { + method: 'GET', + }); + } + + /** + * 删除语言 + * @param name 语言名称 + */ + function deleteApi(name: string): Promise { + return request(`/api/localization/languages/${name}`, { + method: 'DELETE', + }); + } + + /** + * 创建语言 + * @param input 参数 + * @returns 创建的语言 + */ + function createApi(input: LanguageCreateDto): Promise { + return request(`/api/localization/languages`, { + data: input, + method: 'POST', + }); + } + + /** + * 编辑语言 + * @param name 语言名称 + * @param input 参数 + * @returns 编辑的语言 + */ + function updateApi( + name: string, + input: LanguageUpdateDto, + ): Promise { + return request(`/api/localization/languages/${name}`, { + data: input, + method: 'PUT', + }); + } + + return { + cancel, + createApi, + deleteApi, + getApi, + getListApi, + updateApi, + }; +} diff --git a/apps/vben5/packages/@abp/localization/src/components/index.ts b/apps/vben5/packages/@abp/localization/src/components/index.ts index 78dfadb28..a338e40b0 100644 --- a/apps/vben5/packages/@abp/localization/src/components/index.ts +++ b/apps/vben5/packages/@abp/localization/src/components/index.ts @@ -1 +1,2 @@ +export { default as LocalizationLanguageTable } from './languages/LocalizationLanguageTable.vue'; export { default as LocalizationResourceTable } from './resources/LocalizationResourceTable.vue'; diff --git a/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageModal.vue b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageModal.vue new file mode 100644 index 000000000..096a9a2f0 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageModal.vue @@ -0,0 +1,115 @@ + + + + + diff --git a/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue new file mode 100644 index 000000000..20862327a --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue @@ -0,0 +1,240 @@ + + + + + diff --git a/apps/vben5/packages/@abp/localization/src/constants/permissions.ts b/apps/vben5/packages/@abp/localization/src/constants/permissions.ts index f8efa3338..20a7fb03a 100644 --- a/apps/vben5/packages/@abp/localization/src/constants/permissions.ts +++ b/apps/vben5/packages/@abp/localization/src/constants/permissions.ts @@ -8,3 +8,13 @@ export const ResourcesPermissions = { /** 更新 */ Update: 'LocalizationManagement.Resource.Update', }; +/** 语言管理权限 */ +export const LanguagesPermissions = { + /** 新增 */ + Create: 'LocalizationManagement.Language.Create', + Default: 'LocalizationManagement.Language', + /** 删除 */ + Delete: 'LocalizationManagement.Language.Delete', + /** 更新 */ + Update: 'LocalizationManagement.Language.Update', +}; diff --git a/apps/vben5/packages/@abp/localization/src/types/index.ts b/apps/vben5/packages/@abp/localization/src/types/index.ts index 00e67e02e..62604a6ae 100644 --- a/apps/vben5/packages/@abp/localization/src/types/index.ts +++ b/apps/vben5/packages/@abp/localization/src/types/index.ts @@ -1 +1,2 @@ +export * from './languages'; export * from './resources'; diff --git a/apps/vben5/packages/@abp/localization/src/types/languages.ts b/apps/vben5/packages/@abp/localization/src/types/languages.ts new file mode 100644 index 000000000..8fd933704 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/types/languages.ts @@ -0,0 +1,30 @@ +import type { AuditedEntityDto } from '@abp/core'; + +interface LanguageDto extends AuditedEntityDto { + cultureName: string; + displayName: string; + twoLetterISOLanguageName?: string; + uiCultureName: string; +} + +interface LanguageGetListInput { + filter?: string; +} + +interface LanguageCreateOrUpdateDto { + displayName: string; +} + +interface LanguageCreateDto extends LanguageCreateOrUpdateDto { + cultureName: string; + uiCultureName?: string; +} + +type LanguageUpdateDto = LanguageCreateOrUpdateDto; + +export type { + LanguageCreateDto, + LanguageDto, + LanguageGetListInput, + LanguageUpdateDto, +}; From eea3c29a247f878f78562b6b06d2fd5744505dfc Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Mar 2025 18:02:56 +0800 Subject: [PATCH 3/6] feat(vben5): add texts manage --- .../app-antd/src/locales/langs/en-US/abp.json | 3 +- .../app-antd/src/locales/langs/zh-CN/abp.json | 3 +- .../app-antd/src/router/routes/modules/abp.ts | 9 + .../src/views/localization/texts/index.vue | 15 + .../@abp/localization/src/api/useTextsApi.ts | 62 ++++ .../@abp/localization/src/components/index.ts | 1 + .../languages/LocalizationLanguageTable.vue | 40 +-- .../resources/LocalizationResourceTable.vue | 23 +- .../texts/LocalizationTextModal.vue | 196 +++++++++++ .../texts/LocalizationTextTable.vue | 317 ++++++++++++++++++ .../@abp/localization/src/types/texts.ts | 51 +++ 11 files changed, 677 insertions(+), 43 deletions(-) create mode 100644 apps/vben5/apps/app-antd/src/views/localization/texts/index.vue create mode 100644 apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts create mode 100644 apps/vben5/packages/@abp/localization/src/components/texts/LocalizationTextModal.vue create mode 100644 apps/vben5/packages/@abp/localization/src/components/texts/LocalizationTextTable.vue create mode 100644 apps/vben5/packages/@abp/localization/src/types/texts.ts diff --git a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json index 5156e2b28..920c5e943 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json @@ -49,7 +49,8 @@ "localization": { "title": "Localization", "resources": "Resources", - "languages": "Languages" + "languages": "Languages", + "texts": "Texts" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json index 5ea364714..23c6b717a 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json @@ -49,7 +49,8 @@ "localization": { "title": "本地化管理", "resources": "资源管理", - "languages": "语言管理" + "languages": "语言管理", + "texts": "文档管理" } }, "openiddict": { diff --git a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts index 43b422883..cd842c657 100644 --- a/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts +++ b/apps/vben5/apps/app-antd/src/router/routes/modules/abp.ts @@ -203,6 +203,15 @@ const routes: RouteRecordRaw[] = [ component: () => import('#/views/localization/languages/index.vue'), }, + { + meta: { + title: $t('abp.manage.localization.texts'), + icon: 'mi:text', + }, + name: 'LocalizationTexts', + path: '/manage/localization/texts', + component: () => import('#/views/localization/texts/index.vue'), + }, ], }, { diff --git a/apps/vben5/apps/app-antd/src/views/localization/texts/index.vue b/apps/vben5/apps/app-antd/src/views/localization/texts/index.vue new file mode 100644 index 000000000..ac0169dc2 --- /dev/null +++ b/apps/vben5/apps/app-antd/src/views/localization/texts/index.vue @@ -0,0 +1,15 @@ + + + diff --git a/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts b/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts new file mode 100644 index 000000000..d3fa49576 --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/api/useTextsApi.ts @@ -0,0 +1,62 @@ +import type { ListResultDto } from '@abp/core'; + +import type { + GetTextByKeyInput, + GetTextsInput, + SetTextInput, + TextDifferenceDto, + TextDto, +} from '../types/texts'; + +import { useRequest } from '@abp/request'; + +export function useTextsApi() { + const { cancel, request } = useRequest(); + + /** + * 查询文本列表 + * @param input 参数 + * @returns 文本列表 + */ + function getListApi( + input: GetTextsInput, + ): Promise> { + return request>( + '/api/abp/localization/texts', + { + method: 'GET', + params: input, + }, + ); + } + + /** + * 查询文本 + * @param input 参数 + * @returns 查询的文本 + */ + function getApi(input: GetTextByKeyInput): Promise { + return request('/api/abp/localization/texts/by-culture-key', { + method: 'GET', + params: input, + }); + } + + /** + * 设置文本 + * @param input 参数 + */ + function setApi(input: SetTextInput): Promise { + return request('/api/localization/texts', { + data: input, + method: 'PUT', + }); + } + + return { + cancel, + getApi, + getListApi, + setApi, + }; +} diff --git a/apps/vben5/packages/@abp/localization/src/components/index.ts b/apps/vben5/packages/@abp/localization/src/components/index.ts index a338e40b0..378940d70 100644 --- a/apps/vben5/packages/@abp/localization/src/components/index.ts +++ b/apps/vben5/packages/@abp/localization/src/components/index.ts @@ -1,2 +1,3 @@ export { default as LocalizationLanguageTable } from './languages/LocalizationLanguageTable.vue'; export { default as LocalizationResourceTable } from './resources/LocalizationResourceTable.vue'; +export { default as LocalizationTextTable } from './texts/LocalizationTextTable.vue'; 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 20862327a..9df0786f0 100644 --- a/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue +++ b/apps/vben5/packages/@abp/localization/src/components/languages/LocalizationLanguageTable.vue @@ -8,11 +8,7 @@ import { defineAsyncComponent, h, onMounted, reactive, ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { - useAbpStore, - useLocalization, - useLocalizationSerializer, -} from '@abp/core'; +import { useAbpStore } from '@abp/core'; import { useVbenVxeGrid } from '@abp/ui'; import { DeleteOutlined, @@ -29,7 +25,7 @@ defineOptions({ name: 'LocalizationLanguageTable', }); -const permissionGroups = ref([]); +const dataSource = ref([]); const pageState = reactive({ current: 1, size: 10, @@ -37,8 +33,6 @@ const pageState = reactive({ }); const abpStore = useAbpStore(); -const { Lr } = useLocalization(); -const { deserialize } = useLocalizationSerializer(); const { deleteApi, getListApi } = useLanguagesApi(); const { getLocalizationApi } = useLocalizationsApi(); @@ -127,13 +121,7 @@ async function onGet(input?: Record) { gridApi.setLoading(true); const { items } = await getListApi(input); pageState.total = items.length; - permissionGroups.value = items.map((item) => { - const localizableString = deserialize(item.displayName); - return { - ...item, - displayName: Lr(localizableString.resourceName, localizableString.name), - }; - }); + dataSource.value = items; onPageChange(); } finally { gridApi.setLoading(false); @@ -147,7 +135,7 @@ async function onReset() { } function onPageChange() { - const items = permissionGroups.value.slice( + const items = dataSource.value.slice( (pageState.current - 1) * pageState.size, pageState.current * pageState.size, ); @@ -178,20 +166,24 @@ function onDelete(row: LanguageDto) { onOk: async () => { await deleteApi(row.cultureName); message.success($t('AbpUi.DeletedSuccessfully')); - onChange(); + onChange(row); }, title: $t('AbpUi.AreYouSure'), }); } -async function onChange() { - gridApi.query(); +async function onChange(data: LanguageDto) { + const input = await gridApi.formApi.getValues(); + onGet(input); // 资源变化刷新本地多语言缓存 - const cultureName = abpStore.localization!.currentCulture.cultureName; - const localization = await getLocalizationApi({ - cultureName, - }); - abpStore.setLocalization(localization); + const cultureName = + abpStore.application!.localization.currentCulture.cultureName; + if (data.cultureName === cultureName) { + const localization = await getLocalizationApi({ + cultureName, + }); + abpStore.setLocalization(localization); + } } onMounted(onGet); diff --git a/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue b/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue index 9aad82e66..ba6ead397 100644 --- a/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue +++ b/apps/vben5/packages/@abp/localization/src/components/resources/LocalizationResourceTable.vue @@ -8,11 +8,7 @@ import { defineAsyncComponent, h, onMounted, reactive, ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { $t } from '@vben/locales'; -import { - useAbpStore, - useLocalization, - useLocalizationSerializer, -} from '@abp/core'; +import { useAbpStore } from '@abp/core'; import { useVbenVxeGrid } from '@abp/ui'; import { DeleteOutlined, @@ -29,7 +25,7 @@ defineOptions({ name: 'LocalizationResourceTable', }); -const permissionGroups = ref([]); +const dataSource = ref([]); const pageState = reactive({ current: 1, size: 10, @@ -37,8 +33,6 @@ const pageState = reactive({ }); const abpStore = useAbpStore(); -const { Lr } = useLocalization(); -const { deserialize } = useLocalizationSerializer(); const { deleteApi, getListApi } = useResourcesApi(); const { getLocalizationApi } = useLocalizationsApi(); @@ -121,13 +115,7 @@ async function onGet(input?: Record) { gridApi.setLoading(true); const { items } = await getListApi(input); pageState.total = items.length; - permissionGroups.value = items.map((item) => { - const localizableString = deserialize(item.displayName); - return { - ...item, - displayName: Lr(localizableString.resourceName, localizableString.name), - }; - }); + dataSource.value = items; onPageChange(); } finally { gridApi.setLoading(false); @@ -141,7 +129,7 @@ async function onReset() { } function onPageChange() { - const items = permissionGroups.value.slice( + const items = dataSource.value.slice( (pageState.current - 1) * pageState.size, pageState.current * pageState.size, ); @@ -179,7 +167,8 @@ function onDelete(row: ResourceDto) { } async function onChange() { - gridApi.query(); + const input = await gridApi.formApi.getValues(); + onGet(input); // 资源变化刷新本地多语言缓存 const cultureName = abpStore.localization!.currentCulture.cultureName; const localization = await getLocalizationApi({ diff --git a/apps/vben5/packages/@abp/localization/src/components/texts/LocalizationTextModal.vue b/apps/vben5/packages/@abp/localization/src/components/texts/LocalizationTextModal.vue new file mode 100644 index 000000000..6d7f72c8d --- /dev/null +++ b/apps/vben5/packages/@abp/localization/src/components/texts/LocalizationTextModal.vue @@ -0,0 +1,196 @@ + + +