diff --git a/src/api/sys/sysI18nApi.ts b/src/api/sys/sysI18nApi.ts new file mode 100644 index 000000000..2fd57451e --- /dev/null +++ b/src/api/sys/sysI18nApi.ts @@ -0,0 +1,39 @@ +import { ApiServiceEnum, defHttp } from '@/utils/http/axios'; +import { isNull } from '@/utils/is'; + +enum Api { + listFront = 'sys/i18n/listFront', +} + +export const listFrontApi = async (locale: string) => { + const i18nData: Recordable = await defHttp.post({ + service: ApiServiceEnum.SMART_SYSTEM, + url: Api.listFront, + data: { + value: locale, + }, + }); + const result: Recordable = {}; + if (isNull(i18nData)) { + return result; + } + Object.keys(i18nData).forEach((key) => { + const value = i18nData[key]; + convertObject(result, key.split('.'), value); + }); + return result; +}; + +const convertObject = (data: any, keyList: string[], value: string) => { + if (keyList.length > 0) { + if (keyList.length === 1) { + data[keyList[0]] = value; + } else { + const firstKey = keyList[0]; + if (!data[firstKey]) { + data[firstKey] = {}; + } + convertObject(data[firstKey], keyList.slice(1), value); + } + } +}; diff --git a/src/modules/system/views/i18n/I18nMainView.vue b/src/modules/system/views/i18n/I18nMainView.vue index f2b044b03..d8ffed04d 100644 --- a/src/modules/system/views/i18n/I18nMainView.vue +++ b/src/modules/system/views/i18n/I18nMainView.vue @@ -3,10 +3,10 @@ - + - + @@ -17,29 +17,15 @@ -