diff --git a/packages/app/.umirc.ts b/packages/app/.umirc.ts index f16f7cc5c..548909ee5 100644 --- a/packages/app/.umirc.ts +++ b/packages/app/.umirc.ts @@ -12,6 +12,7 @@ process.env.MFSU_AD = 'none'; const umiConfig = getUmiConfig(); export default defineConfig({ + hash: true, define: { 'process.env.NOCOBASE_ENV': process.env.NOCOBASE_ENV, ...umiConfig.define, diff --git a/packages/client/src/antd-config-provider/index.tsx b/packages/client/src/antd-config-provider/index.tsx index b5b6b4648..5438a5e93 100644 --- a/packages/client/src/antd-config-provider/index.tsx +++ b/packages/client/src/antd-config-provider/index.tsx @@ -19,7 +19,7 @@ export function AntdConfigProvider(props) { i18n.changeLanguage(data?.data?.lang); } }, - manual: true, // !remoteLocale, + manual: !remoteLocale, }, ); if (loading) { diff --git a/packages/client/src/user/EditProfile.tsx b/packages/client/src/user/EditProfile.tsx index cfc795243..b74c9b185 100644 --- a/packages/client/src/user/EditProfile.tsx +++ b/packages/client/src/user/EditProfile.tsx @@ -3,7 +3,15 @@ import { uid } from '@formily/shared'; import { Menu } from 'antd'; import React, { useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { ActionContext, DropdownVisibleContext, SchemaComponent, useActionContext, useCurrentUserContext, useRequest } from '../'; +import { + ActionContext, + DropdownVisibleContext, + SchemaComponent, + useActionContext, + useCurrentUserContext, + useRequest +} from '../'; +import { useAPIClient } from '../api-client'; const useCloseAction = () => { const { setVisible } = useActionContext(); @@ -24,13 +32,22 @@ const useCurrentUserValues = (options) => { }; const useSaveCurrentUserValues = () => { + const ctx = useCurrentUserContext(); const { setVisible } = useActionContext(); const form = useForm(); + const api = useAPIClient(); return { async run() { - form.submit((values) => { - setVisible(false); - console.log(values); + const values = await form.submit(); + setVisible(false); + await api.resource('users').updateProfile({ + values, + }); + ctx.mutate({ + data: { + ...ctx?.data?.data, + ...values, + }, }); }, }; diff --git a/packages/client/src/user/LanguageSettings.tsx b/packages/client/src/user/LanguageSettings.tsx index ec19cd473..c8b056b0c 100644 --- a/packages/client/src/user/LanguageSettings.tsx +++ b/packages/client/src/user/LanguageSettings.tsx @@ -1,10 +1,13 @@ import { Menu, Select } from 'antd'; import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { useAPIClient, useCurrentUserContext } from '..'; export const LanguageSettings = () => { const { t, i18n } = useTranslation(); const [open, setOpen] = useState(false); + const api = useAPIClient(); + const ctx = useCurrentUserContext(); return ( { @@ -25,6 +28,11 @@ export const LanguageSettings = () => { ]} value={i18n.language} onChange={async (lang) => { + await api.resource('users').updateProfile({ + values: { + appLang: lang, + }, + }); await i18n.changeLanguage(lang); window.location.reload(); }} diff --git a/packages/plugin-client/src/plugin.ts b/packages/plugin-client/src/plugin.ts index b1e2f9dee..1cee9358f 100644 --- a/packages/plugin-client/src/plugin.ts +++ b/packages/plugin-client/src/plugin.ts @@ -32,8 +32,11 @@ export class ClientPlugin extends Plugin { name: 'app', actions: { async getLang(ctx, next) { + const SystemSetting = ctx.db.getRepository('systemSettings'); + const systemSetting = await SystemSetting.findOne(); + const currentUser = ctx.state.currentUser; ctx.body = { - lang: 'zh-CN', + lang: currentUser?.appLang || systemSetting?.appLang || process.env.APP_LANG || 'en-US', }; await next(); },