From e31ef0c1ec7e70809c7059f86cbbae94c713836b Mon Sep 17 00:00:00 2001 From: "qing.deng" Date: Mon, 29 Aug 2022 16:43:51 +0800 Subject: [PATCH] fix: incorrect language switch data feat: remove deprecated usage refactor: remove unused code chore: release v0.4.1 --- packages/create-ant-design-pro/package.json | 2 +- .../src/components/SelectLang/index.tsx | 46 ++++++++++--------- .../src/components/SelectLang/utils.ts | 4 +- .../src/pages/user/Login/index.tsx | 1 - packages/layout/package.json | 2 +- packages/vite-plugin-antd-layout/package.json | 2 +- .../src/components/SelectLang/index.tsx | 46 ++++++++++--------- playground/src/components/SelectLang/utils.ts | 4 +- playground/src/pages/user/Login/index.tsx | 1 - 9 files changed, 55 insertions(+), 53 deletions(-) diff --git a/packages/create-ant-design-pro/package.json b/packages/create-ant-design-pro/package.json index 9f0ae95..e03c409 100644 --- a/packages/create-ant-design-pro/package.json +++ b/packages/create-ant-design-pro/package.json @@ -1,6 +1,6 @@ { "name": "create-ant-design-pro", - "version": "0.4.0", + "version": "0.4.1", "packageManager": "pnpm@6.32.3", "description": "", "keywords": [ diff --git a/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/index.tsx b/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/index.tsx index c51a87d..2df4392 100644 --- a/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/index.tsx +++ b/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/index.tsx @@ -2,6 +2,7 @@ import { defaultLangUConfigMap } from './constants' import { getAllLocales } from './utils' import React from 'react' import { Dropdown, Menu } from 'antd' +import { ItemType } from 'antd/lib/menu/hooks/useItems' import type { CSSProperties } from 'react' import type { DropDownProps, MenuProps } from 'antd' import { useLayout } from '@/layouts' @@ -70,34 +71,35 @@ export const SelectLang: React.FC = (props) => { } ) - const allLangUIConfig: LocalData[] = + const allLangUIConfig: ItemType[] = ( postLocalesData?.(defaultLangUConfig) || defaultLangUConfig + ).map((item) => { + return { + ...item, + key: item.lang, + style: { minWidth: '160px' }, + icon: ( + + {item?.icon || '🌐'} + + ), + } + }) + const handleClick: MenuProps['onClick'] = onItemClick ? (params) => onItemClick(params) : changeLang - const menuItemStyle = { minWidth: '160px' } - const menuItemIconStyle = { marginRight: '8px' } const langMenu = ( - - {allLangUIConfig.map((localeObj) => { - return ( - - - {localeObj?.icon || '🌐'} - - {localeObj?.label || 'en-US'} - - ) - })} - + ) const inlineStyle = { diff --git a/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/utils.ts b/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/utils.ts index 90c32c0..81e47cf 100644 --- a/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/utils.ts +++ b/packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/utils.ts @@ -1,7 +1,7 @@ import type { defaultLangUConfigMap } from './constants' export const getAllLocales = () => { - return Object.keys(import.meta.glob('../../*.ts')).map((key) => - key.replace('../../', '').replace('.ts', '') + return Object.keys(import.meta.glob('../../locales/*.ts')).map((key) => + key.replace('../../locales/', '').replace('.ts', '') ) as (keyof typeof defaultLangUConfigMap)[] } diff --git a/packages/create-ant-design-pro/template-react-ts/src/pages/user/Login/index.tsx b/packages/create-ant-design-pro/template-react-ts/src/pages/user/Login/index.tsx index 8a2d1bc..0d66990 100644 --- a/packages/create-ant-design-pro/template-react-ts/src/pages/user/Login/index.tsx +++ b/packages/create-ant-design-pro/template-react-ts/src/pages/user/Login/index.tsx @@ -59,7 +59,6 @@ const Login: React.FC = () => { }) message.success(defaultLoginSuccessMessage) /** 此方法会跳转到 redirect 参数所在的位置 */ - if (!history) return const query = new URLSearchParams(location.search) const redirect = query.get('redirect') navigate(redirect || '/') diff --git a/packages/layout/package.json b/packages/layout/package.json index f1734a3..922f6ab 100644 --- a/packages/layout/package.json +++ b/packages/layout/package.json @@ -1,6 +1,6 @@ { "name": "ant-design-pro-layout", - "version": "0.4.0", + "version": "0.4.1", "packageManager": "pnpm@6.32.3", "description": "", "keywords": [], diff --git a/packages/vite-plugin-antd-layout/package.json b/packages/vite-plugin-antd-layout/package.json index 0ea5202..178a6ca 100644 --- a/packages/vite-plugin-antd-layout/package.json +++ b/packages/vite-plugin-antd-layout/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-antd-layout", - "version": "0.4.0", + "version": "0.4.1", "packageManager": "pnpm@6.32.3", "description": "", "keywords": [], diff --git a/playground/src/components/SelectLang/index.tsx b/playground/src/components/SelectLang/index.tsx index c51a87d..2df4392 100644 --- a/playground/src/components/SelectLang/index.tsx +++ b/playground/src/components/SelectLang/index.tsx @@ -2,6 +2,7 @@ import { defaultLangUConfigMap } from './constants' import { getAllLocales } from './utils' import React from 'react' import { Dropdown, Menu } from 'antd' +import { ItemType } from 'antd/lib/menu/hooks/useItems' import type { CSSProperties } from 'react' import type { DropDownProps, MenuProps } from 'antd' import { useLayout } from '@/layouts' @@ -70,34 +71,35 @@ export const SelectLang: React.FC = (props) => { } ) - const allLangUIConfig: LocalData[] = + const allLangUIConfig: ItemType[] = ( postLocalesData?.(defaultLangUConfig) || defaultLangUConfig + ).map((item) => { + return { + ...item, + key: item.lang, + style: { minWidth: '160px' }, + icon: ( + + {item?.icon || '🌐'} + + ), + } + }) + const handleClick: MenuProps['onClick'] = onItemClick ? (params) => onItemClick(params) : changeLang - const menuItemStyle = { minWidth: '160px' } - const menuItemIconStyle = { marginRight: '8px' } const langMenu = ( - - {allLangUIConfig.map((localeObj) => { - return ( - - - {localeObj?.icon || '🌐'} - - {localeObj?.label || 'en-US'} - - ) - })} - + ) const inlineStyle = { diff --git a/playground/src/components/SelectLang/utils.ts b/playground/src/components/SelectLang/utils.ts index 90c32c0..81e47cf 100644 --- a/playground/src/components/SelectLang/utils.ts +++ b/playground/src/components/SelectLang/utils.ts @@ -1,7 +1,7 @@ import type { defaultLangUConfigMap } from './constants' export const getAllLocales = () => { - return Object.keys(import.meta.glob('../../*.ts')).map((key) => - key.replace('../../', '').replace('.ts', '') + return Object.keys(import.meta.glob('../../locales/*.ts')).map((key) => + key.replace('../../locales/', '').replace('.ts', '') ) as (keyof typeof defaultLangUConfigMap)[] } diff --git a/playground/src/pages/user/Login/index.tsx b/playground/src/pages/user/Login/index.tsx index 8a2d1bc..0d66990 100644 --- a/playground/src/pages/user/Login/index.tsx +++ b/playground/src/pages/user/Login/index.tsx @@ -59,7 +59,6 @@ const Login: React.FC = () => { }) message.success(defaultLoginSuccessMessage) /** 此方法会跳转到 redirect 参数所在的位置 */ - if (!history) return const query = new URLSearchParams(location.search) const redirect = query.get('redirect') navigate(redirect || '/')