Skip to content

Commit baf8ed4

Browse files
author
lichunxian
committed
Merge branch 'feature/dataLogPage' into 'main'
fix: improve column width adjustment and optimize date picker performance See merge request apipark/APIPark!122
2 parents 21cd823 + dedb586 commit baf8ed4

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

frontend/packages/common/src/components/aoplatform/TableBtnWithPermission.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const TableIconName = {
3737
const TableBtnWithPermission = ({ btnTitle, access, tooltip, disabled, navigateTo, onClick, className, btnType }: TableBtnWithPermissionProps) => {
3838

3939
const [btnAccess, setBtnAccess] = useState<boolean>(false)
40+
const [btnStatus, setBtnStatus] = useState<boolean>(false)
41+
const [closeToolTip, setCloseToolTip] = useState<boolean>(false)
4042
const { accessData, checkPermission, accessInit } = useGlobalContext()
4143
const navigate = useNavigate()
4244
const lastAccess = useMemo(() => {
@@ -52,16 +54,27 @@ const TableBtnWithPermission = ({ btnTitle, access, tooltip, disabled, navigateT
5254

5355
const handleClick = useCallback((e: React.MouseEvent<HTMLButtonElement>) => {
5456
e.stopPropagation()
57+
setTimeout(() => {
58+
setBtnStatus(false)
59+
setCloseToolTip(true)
60+
})
61+
5562
navigateTo ? navigate(navigateTo) : onClick?.()
5663
}, [navigateTo, navigate, onClick])
57-
64+
const changeTooltipStatus = (open: boolean) => {
65+
setBtnStatus(open)
66+
if (closeToolTip) {
67+
setBtnStatus(false)
68+
setCloseToolTip(false)
69+
}
70+
}
5871
return (<>{
5972
!btnAccess || (disabled && tooltip) ?
6073
<Tooltip placement="top" title={tooltip ?? $t('暂无(0)权限,请联系管理员分配。', [$t(btnTitle).toLowerCase()])}>
6174
<Button type="text" disabled={true} className={`h-[22px] border-none p-0 flex items-center bg-transparent ${className}`} key={btnType} icon={<Icon icon={TableIconName[btnType as keyof typeof TableIconName]} width="18" height="18" />} >{ }</Button>
6275
</Tooltip>
6376
:
64-
<Tooltip placement="top" title={$t(btnTitle)}>
77+
<Tooltip placement="top" title={$t(btnTitle)} trigger='hover' open={btnStatus} onOpenChange={changeTooltipStatus}>
6578
<Button type="text" disabled={disabled} className={`h-[22px] border-none p-0 flex items-center bg-transparent ${className} `} key={btnType} icon={<Icon icon={TableIconName[btnType as keyof typeof TableIconName]} width="18" height="18" />} onClick={handleClick}>{ }</Button>
6679
</Tooltip>
6780

frontend/packages/common/src/components/aoplatform/TimeRangeSelector.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ type TimeRangeSelectorProps = {
2626
onTimeButtonChange: (time: TimeRangeButton) => void
2727
labelSize?: 'small' | 'default'
2828
bindRef?: any
29+
hideBtns?: TimeRangeButton[]
30+
defaultTimeButton?: TimeRangeButton
2931
}
3032
const TimeRangeSelector = (props: TimeRangeSelectorProps) => {
31-
const { initialTimeButton, initialDatePickerValue, onTimeRangeChange, hideTitle, onTimeButtonChange, labelSize = 'default', bindRef } = props
33+
const { initialTimeButton, initialDatePickerValue, onTimeRangeChange, hideTitle, onTimeButtonChange, labelSize = 'default', bindRef, hideBtns = [], defaultTimeButton = 'hour' } = props
3234
const [timeButton, setTimeButton] = useState(initialTimeButton || '');
3335
const [datePickerValue, setDatePickerValue] = useState<RangeValue>(initialDatePickerValue || [null, null]);
3436
useEffect(() => {
@@ -37,7 +39,7 @@ const TimeRangeSelector = (props: TimeRangeSelectorProps) => {
3739
}
3840
}, [bindRef])
3941
// 根据选择的时间范围计算开始和结束时间
40-
const calculateTimeRange = (curBtn: 'hour' | 'day' | 'threeDays' | 'sevenDays') => {
42+
const calculateTimeRange = (curBtn: TimeRangeButton) => {
4143
const currentSecond = Math.floor(Date.now() / 1000); // 当前秒级时间戳
4244
let startMin = currentSecond - 60 * 60
4345
switch (curBtn) {
@@ -75,15 +77,15 @@ const TimeRangeSelector = (props: TimeRangeSelectorProps) => {
7577
calculateTimeRange(e.target.value);
7678
};
7779
const reset = () => {
78-
setTimeButton('hour')
79-
calculateTimeRange('hour')
80+
setTimeButton(defaultTimeButton)
81+
calculateTimeRange(defaultTimeButton)
8082
setDatePickerValue(null)
8183
}
8284

8385
// 处理日期选择器的变化
8486
const handleDatePickerChange = (dates: RangeValue) => {
85-
setTimeButton(dates ? '' : 'hour')
86-
onTimeButtonChange?.(dates ? '' : 'hour')
87+
setTimeButton(dates ? '' : defaultTimeButton)
88+
onTimeButtonChange?.(dates ? '' : defaultTimeButton)
8789
setDatePickerValue(dates);
8890
if (dates && Array.isArray(dates) && dates.length === 2) {
8991
const [startDate, endDate] = dates;
@@ -94,7 +96,7 @@ const TimeRangeSelector = (props: TimeRangeSelectorProps) => {
9496
}
9597
}
9698
if (!dates) {
97-
calculateTimeRange('hour')
99+
calculateTimeRange(defaultTimeButton)
98100
}
99101
};
100102

@@ -109,10 +111,10 @@ const TimeRangeSelector = (props: TimeRangeSelectorProps) => {
109111
<div className="flex flex-nowrap items-center pt-btnybase mr-btnybase">
110112
{!hideTitle && <label className={`whitespace-nowrap `}>{$t('时间')}</label>}
111113
<Radio.Group className="whitespace-nowrap" value={timeButton} onChange={handleRadioChange} buttonStyle="solid">
112-
<Radio.Button value="hour">{$t('近1小时')}</Radio.Button>
113-
<Radio.Button value="day">{$t('近24小时')}</Radio.Button>
114-
<Radio.Button value="threeDays">{$t('近3天')}</Radio.Button>
115-
<Radio.Button className="rounded-e-none" value="sevenDays">{$t('近7天')}</Radio.Button>
114+
{hideBtns?.length && hideBtns.includes('hour') ? null : <Radio.Button value="hour">{$t('近1小时')}</Radio.Button>}
115+
{hideBtns?.length && hideBtns.includes('day') ? null : <Radio.Button value="day">{$t('近24小时')}</Radio.Button>}
116+
{hideBtns?.length && hideBtns.includes('threeDays') ? null : <Radio.Button value="threeDays">{$t('近3天')}</Radio.Button>}
117+
{hideBtns?.length && hideBtns.includes('sevenDays') ? null : <Radio.Button className="rounded-e-none" value="sevenDays">{$t('近7天')}</Radio.Button>}
116118
</Radio.Group>
117119
<DatePicker.RangePicker
118120
value={datePickerValue}

frontend/packages/core/src/pages/policy/dataMasking/DataMaskingColumn.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const DATA_MASKING_TABLE_COLUMNS: PageProColumns<any>[] = [
2727
filters: true,
2828
onFilter: false ,
2929
ellipsis: true,
30-
width: 140,
30+
width: 110,
3131
valueEnum: new Map(
3232
Object.keys(StrategyStatusEnum).map(key=>
3333
[key,
@@ -40,6 +40,7 @@ export const DATA_MASKING_TABLE_COLUMNS: PageProColumns<any>[] = [
4040
filters: true,
4141
onFilter: false ,
4242
ellipsis: true,
43+
width: 90,
4344
valueEnum: {
4445
false: { text: <span className="text-status_success">{$t('启用')}</span> },
4546
true: { text: <span className="text-status_fail">{$t('禁用')}</span> }
@@ -53,7 +54,8 @@ export const DATA_MASKING_TABLE_COLUMNS: PageProColumns<any>[] = [
5354
{
5455
title: ('处理数'),
5556
dataIndex: 'processedTotal',
56-
ellipsis: true
57+
ellipsis: true,
58+
width: 80,
5759
},
5860
{
5961
title: ('更新者'),

frontend/packages/core/src/pages/policy/dataMasking/DataMaskingLogModal.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DataMaskingLogModal = (props: any) => {
2121
const [datePickerValue, setDatePickerValue] = useState<any>();
2222
const currentSecond = Math.floor(Date.now() / 1000); // 当前秒级时间戳
2323
const [queryData, setQueryData] = useState<SearchBody>({
24-
start: currentSecond - 60 * 60,
24+
start: currentSecond - 24 * 60 * 60,
2525
end: currentSecond
2626
})
2727
/**
@@ -43,7 +43,7 @@ const DataMaskingLogModal = (props: any) => {
4343
/**
4444
* 时间按钮
4545
*/
46-
const [timeButton, setTimeButton] = useState<'' | 'hour' | 'day' | 'threeDays' | 'sevenDays'>('hour');
46+
const [timeButton, setTimeButton] = useState<'' | 'hour' | 'day' | 'threeDays' | 'sevenDays'>('day');
4747
/**
4848
* 绑定时间范围组件
4949
* @param instance
@@ -84,7 +84,7 @@ const DataMaskingLogModal = (props: any) => {
8484
const columns = useMemo(() => {
8585
const res = DATA_MASKING_TABLE_LOG_COLUMNS.map(x => {
8686
if (x.dataIndex === 'url') {
87-
x.render = (text: any, record: any) => <><span className='text-green-500'>{record.method}</span>&nbsp;<span>{text}</span></>
87+
x.render = (text: any, record: any) => <><div className='w-full'><span className='text-green-500'>{record.method}</span>&nbsp;<span className='w-[calc(100%-25px)] text-ellipsis overflow-hidden whitespace-nowrap inline-block align-top'>{text}</span></div></>
8888
}
8989
return {
9090
...x,
@@ -161,6 +161,8 @@ const DataMaskingLogModal = (props: any) => {
161161
<TimeRangeSelector
162162
labelSize="small"
163163
bindRef={bindRef}
164+
hideBtns={['hour']}
165+
defaultTimeButton="day"
164166
initialTimeButton={timeButton}
165167
onTimeButtonChange={setTimeButton}
166168
initialDatePickerValue={datePickerValue}

0 commit comments

Comments
 (0)