mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
feat: i18n for add sub models
This commit is contained in:
parent
5bf4233a11
commit
1f95f6d5d0
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
import { Dropdown, DropdownProps, Input, Menu, Spin, Empty, InputProps } from 'antd';
|
import { Dropdown, DropdownProps, Input, Menu, Spin, Empty, InputProps } from 'antd';
|
||||||
import React, { useEffect, useState, useMemo, useRef, FC } from 'react';
|
import React, { useEffect, useState, useMemo, useRef, FC } from 'react';
|
||||||
|
import { useFlowModel } from '../../hooks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过鼠标的位置计算出最佳的 dropdown 的高度,以尽量避免出现滚动条
|
* 通过鼠标的位置计算出最佳的 dropdown 的高度,以尽量避免出现滚动条
|
||||||
@ -72,6 +73,7 @@ interface LazyDropdownMenuProps extends Omit<DropdownProps['menu'], 'items'> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownMenuProps }> = ({ menu, ...props }) => {
|
const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownMenuProps }> = ({ menu, ...props }) => {
|
||||||
|
const model = useFlowModel();
|
||||||
const [loadedChildren, setLoadedChildren] = useState<Record<string, Item[]>>({});
|
const [loadedChildren, setLoadedChildren] = useState<Record<string, Item[]>>({});
|
||||||
const [loadingKeys, setLoadingKeys] = useState<Set<string>>(new Set());
|
const [loadingKeys, setLoadingKeys] = useState<Set<string>>(new Set());
|
||||||
const [menuVisible, setMenuVisible] = useState(false);
|
const [menuVisible, setMenuVisible] = useState(false);
|
||||||
@ -82,6 +84,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
|
|||||||
const dropdownMaxHeight = useNiceDropdownMaxHeight([menuVisible]);
|
const dropdownMaxHeight = useNiceDropdownMaxHeight([menuVisible]);
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
const searchTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
const searchTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
const t = model.flowEngine.translate.bind(model.flowEngine);
|
||||||
|
|
||||||
// 清理定时器,避免内存泄露
|
// 清理定时器,避免内存泄露
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -223,7 +226,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
|
|||||||
visible={menuVisible}
|
visible={menuVisible}
|
||||||
variant="borderless"
|
variant="borderless"
|
||||||
allowClear
|
allowClear
|
||||||
placeholder={item.searchPlaceholder || 'search'}
|
placeholder={t(item.searchPlaceholder || 'Search')}
|
||||||
value={currentSearchValue}
|
value={currentSearchValue}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@ -264,7 +267,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
|
|||||||
key: `${item.key}-empty`,
|
key: `${item.key}-empty`,
|
||||||
label: (
|
label: (
|
||||||
<div style={{ padding: '16px', textAlign: 'center' as const }}>
|
<div style={{ padding: '16px', textAlign: 'center' as const }}>
|
||||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="No Data" style={{ margin: 0 }} />
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={t('No data')} style={{ margin: 0 }} />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
@ -278,7 +281,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
|
|||||||
return {
|
return {
|
||||||
type: 'group',
|
type: 'group',
|
||||||
key: item.key,
|
key: item.key,
|
||||||
label: item.label,
|
label: typeof item.label === 'string' ? t(item.label) : item.label,
|
||||||
children: groupChildren,
|
children: groupChildren,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -289,7 +292,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
key: item.key,
|
key: item.key,
|
||||||
label: item.label,
|
label: typeof item.label === 'string' ? t(item.label) : item.label,
|
||||||
onClick: (info) => {
|
onClick: (info) => {
|
||||||
if (children) {
|
if (children) {
|
||||||
return;
|
return;
|
||||||
@ -316,7 +319,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
|
|||||||
key: `${keyPath}-empty`,
|
key: `${keyPath}-empty`,
|
||||||
label: (
|
label: (
|
||||||
<div style={{ padding: '16px', textAlign: 'center' as const }}>
|
<div style={{ padding: '16px', textAlign: 'center' as const }}>
|
||||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="No Data" style={{ margin: 0 }} />
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={t('No data')} style={{ margin: 0 }} />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user