Commit de0cf3da authored by 陈帅's avatar 陈帅

use new local

parent 37644852
...@@ -31,7 +31,7 @@ export interface DefaultSettings { ...@@ -31,7 +31,7 @@ export interface DefaultSettings {
* sticky siderbar * sticky siderbar
*/ */
fixSiderbar: boolean; fixSiderbar: boolean;
menu: { disableLocal: boolean }; menu: { locale: boolean };
title: string; title: string;
pwa: boolean; pwa: boolean;
// Your custom iconfont Symbol script Url // Your custom iconfont Symbol script Url
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
fixSiderbar: false, fixSiderbar: false,
colorWeak: false, colorWeak: false,
menu: { menu: {
disableLocal: false, locale: true,
}, },
title: 'Ant Design Pro', title: 'Ant Design Pro',
pwa: true, pwa: true,
......
...@@ -132,7 +132,7 @@ ...@@ -132,7 +132,7 @@
"umi": "^2.6.17", "umi": "^2.6.17",
"umi-plugin-ga": "^1.1.3", "umi-plugin-ga": "^1.1.3",
"umi-plugin-pro-block": "^1.3.0", "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" "umi-request": "^1.0.0"
}, },
"optionalDependencies": { "optionalDependencies": {
......
...@@ -4,6 +4,7 @@ import PromiseRender from './PromiseRender'; ...@@ -4,6 +4,7 @@ import PromiseRender from './PromiseRender';
import { CURRENT } from './renderAuthorize'; import { CURRENT } from './renderAuthorize';
export type IAuthorityType = export type IAuthorityType =
| undefined
| string | string
| string[] | string[]
| Promise<any> | Promise<any>
......
...@@ -12,7 +12,7 @@ interface SelectLangProps { ...@@ -12,7 +12,7 @@ interface SelectLangProps {
const SelectLang: React.FC<SelectLangProps> = props => { const SelectLang: React.FC<SelectLangProps> = props => {
const { className } = props; const { className } = props;
const selectedLang = getLocale(); 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 locales = ['zh-CN', 'zh-TW', 'en-US', 'pt-BR'];
const languageLabels = { const languageLabels = {
'zh-CN': '简体中文', 'zh-CN': '简体中文',
......
...@@ -3,6 +3,8 @@ import RightContent from '@/components/GlobalHeader/RightContent'; ...@@ -3,6 +3,8 @@ import RightContent from '@/components/GlobalHeader/RightContent';
import { connect } from 'dva'; import { connect } from 'dva';
import React, { useState } from 'react'; import React, { useState } from 'react';
import logo from '../assets/logo.svg'; import logo from '../assets/logo.svg';
import Authorized from '@/utils/Authorized';
import { formatMessage } from 'umi-plugin-react/locale';
import { import {
BasicLayout as BasicLayoutComponents, BasicLayout as BasicLayoutComponents,
BasicLayoutProps as BasicLayoutComponentsProps, BasicLayoutProps as BasicLayoutComponentsProps,
...@@ -21,6 +23,19 @@ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & { ...@@ -21,6 +23,19 @@ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
breadcrumbNameMap: { [path: string]: MenuDataItem }; 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<BasicLayoutProps> = props => { const BasicLayout: React.FC<BasicLayoutProps> = props => {
const { dispatch, children, settings } = props; const { dispatch, children, settings } = props;
/** /**
...@@ -35,7 +50,9 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => { ...@@ -35,7 +50,9 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
*/ */
const handleMenuCollapse = (payload: boolean) => const handleMenuCollapse = (payload: boolean) =>
dispatch!({ type: 'global/changeLayoutCollapsed', payload }); dispatch!({ type: 'global/changeLayoutCollapsed', payload });
const {
menu: { locale },
} = settings;
return ( return (
<> <>
<BasicLayoutComponents <BasicLayoutComponents
...@@ -44,6 +61,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => { ...@@ -44,6 +61,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
menuItemRender={(menuItemProps, defaultDom) => { menuItemRender={(menuItemProps, defaultDom) => {
return <Link to={menuItemProps.path}>{defaultDom}</Link>; return <Link to={menuItemProps.path}>{defaultDom}</Link>;
}} }}
filterMenuData={menuList => filterMenuData(menuList, locale)}
rightContentRender={rightProps => <RightContent {...rightProps} />} rightContentRender={rightProps => <RightContent {...rightProps} />}
{...props} {...props}
{...settings} {...settings}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment