Optimize code

This commit is contained in:
2024-01-08 13:43:47 +08:00
parent d526d913b9
commit 88c66bd7a7
12 changed files with 68 additions and 70 deletions

View File

@@ -11,7 +11,7 @@ interface IndicatorProps {
const Indicator: React.FC<IndicatorProps> = ({ total, current, onSwitch }) => {
const handleClick = (index: number) => {
return () => {
onSwitch && onSwitch(index)
onSwitch?.(index)
}
}

View File

@@ -16,7 +16,7 @@ const Item: React.FC<ItemProps> = (props) => {
const showSubmenu = (e: React.MouseEvent) => {
const parentElement = e.currentTarget.parentElement
if (parentElement && parentElement.childElementCount === 2) {
if (parentElement?.childElementCount === 2) {
const parentClientRect = parentElement.getBoundingClientRect()
if (parentClientRect.top <= screen.height / 2) {
setSubmenuTop(parentClientRect.top)
@@ -42,18 +42,16 @@ const Item: React.FC<ItemProps> = (props) => {
}
>
<div className={'icon-box'}>
{props.icon ? (
<Icon className={'icon'} component={props.icon} />
) : undefined}
{props.icon && <Icon className={'icon'} component={props.icon} />}
</div>
<span className={'text'}>{props.text}</span>
</NavLink>
</div>
{props.children ? (
{props.children && (
<Submenu submenuTop={submenuTop} submenuLeft={submenuLeft}>
{props.children}
</Submenu>
) : undefined}
)}
</li>
)
}

View File

@@ -29,7 +29,7 @@ const Sidebar: React.FC<SidebarProps> & {
const switchSidebar = () => {
setLocalStorage('HIDE_SIDEBAR', !hideSidebar ? 'true' : 'false')
setHideSidebar(!hideSidebar)
props.onSidebarSwitch && props.onSidebarSwitch(hideSidebar)
props.onSidebarSwitch?.(hideSidebar)
}
return (

View File

@@ -529,9 +529,9 @@ const Group: React.FC = () => {
}
suffix={
<>
{!isRegexLegal ? (
{!isRegexLegal && (
<span style={{ color: COLOR_ERROR_SECONDARY }}></span>
) : undefined}
)}
<AntdCheckbox checked={isUseRegex} onChange={handleOnUseRegexChange}>
<AntdTooltip title={'正则表达式'}>.*</AntdTooltip>
</AntdCheckbox>

View File

@@ -538,9 +538,9 @@ const Role: React.FC = () => {
}
suffix={
<>
{!isRegexLegal ? (
{!isRegexLegal && (
<span style={{ color: COLOR_ERROR_SECONDARY }}></span>
) : undefined}
)}
<AntdCheckbox checked={isUseRegex} onChange={handleOnUseRegexChange}>
<AntdTooltip title={'正则表达式'}>.*</AntdTooltip>
</AntdCheckbox>

View File

@@ -123,7 +123,7 @@ const SensitiveWord: React.FC = () => {
justifyContent: 'flex-end'
}}
>
{selectedKeys?.length === 1 ? (
{selectedKeys?.length === 1 && (
<AntdTooltip title={'删除选中项'}>
<Icon
style={{ fontSize: '1.2em' }}
@@ -131,7 +131,7 @@ const SensitiveWord: React.FC = () => {
onClick={handleOnDelete}
/>
</AntdTooltip>
) : undefined}
)}
</span>,
'拦截'

View File

@@ -27,7 +27,7 @@ export const SettingsCard: React.FC<SettingsCardProps> = (props) => {
<FlexBox direction={'horizontal'} className={'head'}>
<Icon component={props.icon} className={'icon'} />
<div className={'title'}>{props.title}</div>
{!props.loading ? (
{!props.loading && (
<Permission operationCode={props.modifyOperationCode}>
{props.expand}
<AntdButton onClick={props.onReset} title={'重置'}>
@@ -37,7 +37,7 @@ export const SettingsCard: React.FC<SettingsCardProps> = (props) => {
<Icon component={IconOxygenSave} />
</AntdButton>
</Permission>
) : undefined}
)}
</FlexBox>
<LoadingMask
maskContent={<AntdSkeleton active paragraph={{ rows: 6 }} />}

View File

@@ -169,22 +169,20 @@ const User: React.FC = () => {
<AntdTag color={'green'}></AntdTag>
) : (
<>
{record.verify ? (
{record.verify && (
<>
<AntdPopover content={record.verify} trigger={'click'}>
<AntdTag style={{ cursor: 'pointer' }}></AntdTag>
</AntdPopover>
</>
) : undefined}
{record.locking ? <AntdTag></AntdTag> : undefined}
{record.expiration && isPastTime(record.expiration) ? (
)}
{record.locking && <AntdTag></AntdTag>}
{record.expiration && isPastTime(record.expiration) && (
<AntdTag></AntdTag>
) : undefined}
)}
{record.credentialsExpiration &&
isPastTime(record.credentialsExpiration) ? (
<AntdTag></AntdTag>
) : undefined}
{!record.enable ? <AntdTag></AntdTag> : undefined}
isPastTime(record.credentialsExpiration) && <AntdTag></AntdTag>}
{!record.enable && <AntdTag></AntdTag>}
</>
)}
</AntdTooltip>
@@ -215,14 +213,14 @@ const User: React.FC = () => {
</a>
</Permission>
<Permission operationCode={'system:user:delete:one'}>
{record.id !== '0' ? (
{record.id !== '0' && (
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnDeleteBtnClick(record)}
>
</a>
) : undefined}
)}
</Permission>
</AntdSpace>
</>
@@ -378,7 +376,7 @@ const User: React.FC = () => {
>
<AntdInput.Password />
</AntdForm.Item>
{value.id !== '0' ? (
{value.id !== '0' && (
<AntdForm.Item
name={'needChangePassword'}
label={'需改密'}
@@ -387,7 +385,7 @@ const User: React.FC = () => {
>
<AntdSwitch />
</AntdForm.Item>
) : undefined}
)}
</AntdForm>
),
onOk: () =>
@@ -803,7 +801,7 @@ const User: React.FC = () => {
>
<AntdInput allowClear />
</AntdForm.Item>
{!isDrawerEdit ? (
{!isDrawerEdit && (
<>
<AntdForm.Item
name={'password'}
@@ -813,7 +811,7 @@ const User: React.FC = () => {
<AntdInput.Password allowClear />
</AntdForm.Item>
</>
) : undefined}
)}
<AntdForm.Item name={'nickname'} label={'昵称'} rules={[{ whitespace: false }]}>
<AntdInput allowClear />
</AntdForm.Item>
@@ -824,7 +822,7 @@ const User: React.FC = () => {
>
<AntdInput type={'email'} allowClear />
</AntdForm.Item>
{formValues?.id !== '0' ? (
{formValues?.id !== '0' && (
<>
<AntdForm.Item name={'roleIds'} label={'角色'}>
<AntdSelect
@@ -900,7 +898,7 @@ const User: React.FC = () => {
<AntdSwitch />
</AntdForm.Item>
</>
) : undefined}
)}
</AntdForm>
)
@@ -943,9 +941,9 @@ const User: React.FC = () => {
}
suffix={
<>
{!isRegexLegal ? (
{!isRegexLegal && (
<span style={{ color: COLOR_ERROR_SECONDARY }}></span>
) : undefined}
)}
<AntdCheckbox checked={isUseRegex} onChange={handleOnUseRegexChange}>
<AntdTooltip title={'正则表达式'}>.*</AntdTooltip>
</AntdCheckbox>

View File

@@ -13,15 +13,17 @@ const SystemFramework: React.FC = () => {
<Sidebar title={'系统配置'}>
<Sidebar.ItemList>
{getSystemRouteJson().map((value) => {
return value.menu ? (
<Sidebar.Item
end={value.id === 'system' ? true : undefined}
path={value.absolutePath}
icon={value.icon}
text={value.name}
key={value.id}
/>
) : undefined
return (
value.menu && (
<Sidebar.Item
end={value.id === 'system' ? true : undefined}
path={value.absolutePath}
icon={value.icon}
text={value.name}
key={value.id}
/>
)
)
})}
</Sidebar.ItemList>
</Sidebar>

View File

@@ -42,17 +42,16 @@ const ToolsFramework: React.FC = () => {
text={tool.name}
key={tool.id}
>
{tool.children
? tool.children.map((subTool) => {
return (
<Sidebar.Item
path={subTool.absolutePath}
text={subTool.name}
key={subTool.id}
/>
)
})
: undefined}
{tool.children &&
tool.children.map((subTool) => {
return (
<Sidebar.Item
path={subTool.absolutePath}
text={subTool.name}
key={subTool.id}
/>
)
})}
</Sidebar.Item>
) : undefined
})}

View File

@@ -15,13 +15,13 @@ const ToolsFramework: React.FC = () => {
title={'个人中心'}
bottomFixed={
<Sidebar.ItemList>
{hasPathPermission('/system') ? (
{hasPathPermission('/system') && (
<Sidebar.Item
path={'/system'}
icon={IconOxygenSetting}
text={'系统配置'}
/>
) : undefined}
)}
<Sidebar.Item
path={'/'}
icon={IconOxygenBack}
@@ -32,15 +32,17 @@ const ToolsFramework: React.FC = () => {
>
<Sidebar.ItemList>
{user.map((value) => {
return value.menu ? (
<Sidebar.Item
end={value.id === 'user' ? true : undefined}
path={value.absolutePath}
icon={value.icon}
text={value.name}
key={value.id}
/>
) : undefined
return (
value.menu && (
<Sidebar.Item
end={value.id === 'user' && true}
path={value.absolutePath}
icon={value.icon}
text={value.name}
key={value.id}
/>
)
)
})}
</Sidebar.ItemList>
</Sidebar>

View File

@@ -7,10 +7,9 @@ export const getRedirectUrl = (path: string, redirectUrl: string): string => {
export const getFullTitle = (data: _DataNode, preTitle?: string) => {
data.fullTitle = `${preTitle ? `${preTitle}-` : ''}${data.title as string}`
data.children &&
data.children.forEach((value) => {
getFullTitle(value, data.fullTitle)
})
data.children?.forEach((value) => {
getFullTitle(value, data.fullTitle)
})
return data
}