Skip to content

Commit e31ef0c

Browse files
committed
fix: incorrect language switch data
feat: remove deprecated usage refactor: remove unused code chore: release v0.4.1
1 parent 30482b5 commit e31ef0c

File tree

9 files changed

+55
-53
lines changed

9 files changed

+55
-53
lines changed

packages/create-ant-design-pro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-ant-design-pro",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"packageManager": "pnpm@6.32.3",
55
"description": "",
66
"keywords": [

packages/create-ant-design-pro/template-react-ts/src/components/SelectLang/index.tsx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defaultLangUConfigMap } from './constants'
22
import { getAllLocales } from './utils'
33
import React from 'react'
44
import { Dropdown, Menu } from 'antd'
5+
import { ItemType } from 'antd/lib/menu/hooks/useItems'
56
import type { CSSProperties } from 'react'
67
import type { DropDownProps, MenuProps } from 'antd'
78
import { useLayout } from '@/layouts'
@@ -70,34 +71,35 @@ export const SelectLang: React.FC<SelectLangProps> = (props) => {
7071
}
7172
)
7273

73-
const allLangUIConfig: LocalData[] =
74+
const allLangUIConfig: ItemType[] = (
7475
postLocalesData?.(defaultLangUConfig) || defaultLangUConfig
76+
).map((item) => {
77+
return {
78+
...item,
79+
key: item.lang,
80+
style: { minWidth: '160px' },
81+
icon: (
82+
<span
83+
role="img"
84+
aria-label={item?.label || 'en-US'}
85+
style={{ marginRight: '8px' }}
86+
>
87+
{item?.icon || '🌐'}
88+
</span>
89+
),
90+
}
91+
})
92+
7593
const handleClick: MenuProps['onClick'] = onItemClick
7694
? (params) => onItemClick(params)
7795
: changeLang
7896

79-
const menuItemStyle = { minWidth: '160px' }
80-
const menuItemIconStyle = { marginRight: '8px' }
8197
const langMenu = (
82-
<Menu selectedKeys={[locale]} onClick={handleClick}>
83-
{allLangUIConfig.map((localeObj) => {
84-
return (
85-
<Menu.Item
86-
key={localeObj.lang || localeObj.key}
87-
style={menuItemStyle}
88-
>
89-
<span
90-
role="img"
91-
aria-label={localeObj?.label || 'en-US'}
92-
style={menuItemIconStyle}
93-
>
94-
{localeObj?.icon || '🌐'}
95-
</span>
96-
{localeObj?.label || 'en-US'}
97-
</Menu.Item>
98-
)
99-
})}
100-
</Menu>
98+
<Menu
99+
selectedKeys={[locale]}
100+
items={allLangUIConfig}
101+
onClick={handleClick}
102+
></Menu>
101103
)
102104

103105
const inlineStyle = {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { defaultLangUConfigMap } from './constants'
22

33
export const getAllLocales = () => {
4-
return Object.keys(import.meta.glob('../../*.ts')).map((key) =>
5-
key.replace('../../', '').replace('.ts', '')
4+
return Object.keys(import.meta.glob('../../locales/*.ts')).map((key) =>
5+
key.replace('../../locales/', '').replace('.ts', '')
66
) as (keyof typeof defaultLangUConfigMap)[]
77
}

packages/create-ant-design-pro/template-react-ts/src/pages/user/Login/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const Login: React.FC = () => {
5959
})
6060
message.success(defaultLoginSuccessMessage)
6161
/** 此方法会跳转到 redirect 参数所在的位置 */
62-
if (!history) return
6362
const query = new URLSearchParams(location.search)
6463
const redirect = query.get('redirect')
6564
navigate(redirect || '/')

packages/layout/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ant-design-pro-layout",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"packageManager": "pnpm@6.32.3",
55
"description": "",
66
"keywords": [],

packages/vite-plugin-antd-layout/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-antd-layout",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"packageManager": "pnpm@6.32.3",
55
"description": "",
66
"keywords": [],

playground/src/components/SelectLang/index.tsx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defaultLangUConfigMap } from './constants'
22
import { getAllLocales } from './utils'
33
import React from 'react'
44
import { Dropdown, Menu } from 'antd'
5+
import { ItemType } from 'antd/lib/menu/hooks/useItems'
56
import type { CSSProperties } from 'react'
67
import type { DropDownProps, MenuProps } from 'antd'
78
import { useLayout } from '@/layouts'
@@ -70,34 +71,35 @@ export const SelectLang: React.FC<SelectLangProps> = (props) => {
7071
}
7172
)
7273

73-
const allLangUIConfig: LocalData[] =
74+
const allLangUIConfig: ItemType[] = (
7475
postLocalesData?.(defaultLangUConfig) || defaultLangUConfig
76+
).map((item) => {
77+
return {
78+
...item,
79+
key: item.lang,
80+
style: { minWidth: '160px' },
81+
icon: (
82+
<span
83+
role="img"
84+
aria-label={item?.label || 'en-US'}
85+
style={{ marginRight: '8px' }}
86+
>
87+
{item?.icon || '🌐'}
88+
</span>
89+
),
90+
}
91+
})
92+
7593
const handleClick: MenuProps['onClick'] = onItemClick
7694
? (params) => onItemClick(params)
7795
: changeLang
7896

79-
const menuItemStyle = { minWidth: '160px' }
80-
const menuItemIconStyle = { marginRight: '8px' }
8197
const langMenu = (
82-
<Menu selectedKeys={[locale]} onClick={handleClick}>
83-
{allLangUIConfig.map((localeObj) => {
84-
return (
85-
<Menu.Item
86-
key={localeObj.lang || localeObj.key}
87-
style={menuItemStyle}
88-
>
89-
<span
90-
role="img"
91-
aria-label={localeObj?.label || 'en-US'}
92-
style={menuItemIconStyle}
93-
>
94-
{localeObj?.icon || '🌐'}
95-
</span>
96-
{localeObj?.label || 'en-US'}
97-
</Menu.Item>
98-
)
99-
})}
100-
</Menu>
98+
<Menu
99+
selectedKeys={[locale]}
100+
items={allLangUIConfig}
101+
onClick={handleClick}
102+
></Menu>
101103
)
102104

103105
const inlineStyle = {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { defaultLangUConfigMap } from './constants'
22

33
export const getAllLocales = () => {
4-
return Object.keys(import.meta.glob('../../*.ts')).map((key) =>
5-
key.replace('../../', '').replace('.ts', '')
4+
return Object.keys(import.meta.glob('../../locales/*.ts')).map((key) =>
5+
key.replace('../../locales/', '').replace('.ts', '')
66
) as (keyof typeof defaultLangUConfigMap)[]
77
}

playground/src/pages/user/Login/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const Login: React.FC = () => {
5959
})
6060
message.success(defaultLoginSuccessMessage)
6161
/** 此方法会跳转到 redirect 参数所在的位置 */
62-
if (!history) return
6362
const query = new URLSearchParams(location.search)
6463
const redirect = query.get('redirect')
6564
navigate(redirect || '/')

0 commit comments

Comments
 (0)