From de0cf3da169e926f3fd7786845c0a9c9b6321b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Mon, 20 May 2019 15:23:05 +0800 Subject: [PATCH] use new local --- config/defaultSettings.ts | 4 ++-- package.json | 2 +- .../Authorized/CheckPermissions.tsx | 1 + src/components/SelectLang/index.tsx | 2 +- src/layouts/BasicLayout.tsx | 20 ++++++++++++++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config/defaultSettings.ts b/config/defaultSettings.ts index 25335aea..bdc3c554 100644 --- a/config/defaultSettings.ts +++ b/config/defaultSettings.ts @@ -31,7 +31,7 @@ export interface DefaultSettings { * sticky siderbar */ fixSiderbar: boolean; - menu: { disableLocal: boolean }; + menu: { locale: boolean }; title: string; pwa: boolean; // Your custom iconfont Symbol script Url @@ -52,7 +52,7 @@ export default { fixSiderbar: false, colorWeak: false, menu: { - disableLocal: false, + locale: true, }, title: 'Ant Design Pro', pwa: true, diff --git a/package.json b/package.json index e6da2ccc..1916a233 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,7 @@ "umi": "^2.6.17", "umi-plugin-ga": "^1.1.3", "umi-plugin-pro-block": "^1.3.0", - "umi-plugin-react": "^1.7.2", + "umi-plugin-react": "^1.8.0-beta.1", "umi-request": "^1.0.0" }, "optionalDependencies": { diff --git a/src/components/Authorized/CheckPermissions.tsx b/src/components/Authorized/CheckPermissions.tsx index e7533300..1d599e37 100644 --- a/src/components/Authorized/CheckPermissions.tsx +++ b/src/components/Authorized/CheckPermissions.tsx @@ -4,6 +4,7 @@ import PromiseRender from './PromiseRender'; import { CURRENT } from './renderAuthorize'; export type IAuthorityType = + | undefined | string | string[] | Promise diff --git a/src/components/SelectLang/index.tsx b/src/components/SelectLang/index.tsx index 0434bd2c..ac8309d9 100644 --- a/src/components/SelectLang/index.tsx +++ b/src/components/SelectLang/index.tsx @@ -12,7 +12,7 @@ interface SelectLangProps { const SelectLang: React.FC = props => { const { className } = props; const selectedLang = getLocale(); - const changeLang = ({ key }: ClickParam) => setLocale(key); + const changeLang = ({ key }: ClickParam) => setLocale(key, false); const locales = ['zh-CN', 'zh-TW', 'en-US', 'pt-BR']; const languageLabels = { 'zh-CN': '简体中文', diff --git a/src/layouts/BasicLayout.tsx b/src/layouts/BasicLayout.tsx index ff1152e9..cec925e6 100644 --- a/src/layouts/BasicLayout.tsx +++ b/src/layouts/BasicLayout.tsx @@ -3,6 +3,8 @@ import RightContent from '@/components/GlobalHeader/RightContent'; import { connect } from 'dva'; import React, { useState } from 'react'; import logo from '../assets/logo.svg'; +import Authorized from '@/utils/Authorized'; +import { formatMessage } from 'umi-plugin-react/locale'; import { BasicLayout as BasicLayoutComponents, BasicLayoutProps as BasicLayoutComponentsProps, @@ -21,6 +23,19 @@ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & { breadcrumbNameMap: { [path: string]: MenuDataItem }; }; +/** + * default menuLocal + */ +const filterMenuData = (menuList: MenuDataItem[], locale: boolean) => { + return menuList.map(item => { + const localItem = { + ...item, + name: item.locale && locale ? formatMessage({ id: item.locale }) : item.name, + }; + return Authorized.check(item.authority, localItem, null) as MenuDataItem; + }); +}; + const BasicLayout: React.FC = props => { const { dispatch, children, settings } = props; /** @@ -35,7 +50,9 @@ const BasicLayout: React.FC = props => { */ const handleMenuCollapse = (payload: boolean) => dispatch!({ type: 'global/changeLayoutCollapsed', payload }); - + const { + menu: { locale }, + } = settings; return ( <> = props => { menuItemRender={(menuItemProps, defaultDom) => { return {defaultDom}; }} + filterMenuData={menuList => filterMenuData(menuList, locale)} rightContentRender={rightProps => } {...props} {...settings} -- GitLab