feat: Enhance LogsTable component with mobile support and date handling improvements
- Added mobile-specific date pickers for start and end timestamps in the LogsTable component, improving user experience on mobile devices. - Updated the input handling for date values to ensure valid date formats are maintained. - Introduced a new translation key for "时间范围" (Time range) in the English locale file to support localization efforts.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
API,
|
API,
|
||||||
@@ -33,6 +33,7 @@ import {
|
|||||||
} from '../helpers/render';
|
} from '../helpers/render';
|
||||||
import Paragraph from '@douyinfe/semi-ui/lib/es/typography/paragraph';
|
import Paragraph from '@douyinfe/semi-ui/lib/es/typography/paragraph';
|
||||||
import { getLogOther } from '../helpers/other.js';
|
import { getLogOther } from '../helpers/other.js';
|
||||||
|
import { StyleContext } from '../context/Style/index.js';
|
||||||
|
|
||||||
const { Header } = Layout;
|
const { Header } = Layout;
|
||||||
|
|
||||||
@@ -406,6 +407,7 @@ const LogsTable = () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const [styleState, styleDispatch] = useContext(StyleContext);
|
||||||
const [logs, setLogs] = useState([]);
|
const [logs, setLogs] = useState([]);
|
||||||
const [expandData, setExpandData] = useState({});
|
const [expandData, setExpandData] = useState({});
|
||||||
const [showStat, setShowStat] = useState(false);
|
const [showStat, setShowStat] = useState(false);
|
||||||
@@ -443,12 +445,17 @@ const LogsTable = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleInputChange = (value, name) => {
|
const handleInputChange = (value, name) => {
|
||||||
// console.log('name:', name, 'value:', value);
|
if (value && (name === 'start_timestamp' || name === 'end_timestamp')) {
|
||||||
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
// 确保日期值是有效的
|
||||||
|
const dateValue = typeof value === 'string' ? value : timestamp2string(value);
|
||||||
|
setInputs(inputs => ({ ...inputs, [name]: dateValue }));
|
||||||
|
} else {
|
||||||
|
setInputs(inputs => ({ ...inputs, [name]: value }));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLogSelfStat = async () => {
|
const getLogSelfStat = async () => {
|
||||||
let localStartTimestamp = Date.parse(start_timestamp) / 1000;
|
let localStartTimestamp = Date.parse(3) / 1000;
|
||||||
let localEndTimestamp = Date.parse(end_timestamp) / 1000;
|
let localEndTimestamp = Date.parse(end_timestamp) / 1000;
|
||||||
let url = `/api/log/self/stat?type=${logType}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&group=${group}`;
|
let url = `/api/log/self/stat?type=${logType}&token_name=${token_name}&model_name=${model_name}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}&group=${group}`;
|
||||||
url = encodeURI(url);
|
url = encodeURI(url);
|
||||||
@@ -694,19 +701,47 @@ const LogsTable = () => {
|
|||||||
<Form layout='horizontal' style={{ marginTop: 10 }}>
|
<Form layout='horizontal' style={{ marginTop: 10 }}>
|
||||||
<>
|
<>
|
||||||
<Form.Section>
|
<Form.Section>
|
||||||
<div style={{ display: 'flex', marginBottom: 10 }}>
|
<div style={{ marginBottom: 10 }}>
|
||||||
<Form.DatePicker
|
{
|
||||||
field="range_timestamp"
|
styleState.isMobile ? (
|
||||||
label={t('时间范围')}
|
<div>
|
||||||
initValue={[start_timestamp, end_timestamp]}
|
<Form.DatePicker
|
||||||
value={[start_timestamp, end_timestamp]}
|
field='start_timestamp'
|
||||||
type="dateTimeRange"
|
label={t('起始时间')}
|
||||||
name="range_timestamp"
|
style={{ width: 272 }}
|
||||||
onChange={(value) => {
|
initValue={start_timestamp}
|
||||||
handleInputChange(value[0], 'start_timestamp');
|
type='dateTime'
|
||||||
handleInputChange(value[1], 'end_timestamp');
|
onChange={(value) => {
|
||||||
}}
|
console.log(value);
|
||||||
/>
|
handleInputChange(value, 'start_timestamp')
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Form.DatePicker
|
||||||
|
field='end_timestamp'
|
||||||
|
fluid
|
||||||
|
label={t('结束时间')}
|
||||||
|
style={{ width: 272 }}
|
||||||
|
initValue={end_timestamp}
|
||||||
|
type='dateTime'
|
||||||
|
onChange={(value) => handleInputChange(value, 'end_timestamp')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Form.DatePicker
|
||||||
|
field="range_timestamp"
|
||||||
|
label={t('时间范围')}
|
||||||
|
initValue={[start_timestamp, end_timestamp]}
|
||||||
|
type="dateTimeRange"
|
||||||
|
name="range_timestamp"
|
||||||
|
onChange={(value) => {
|
||||||
|
if (Array.isArray(value) && value.length === 2) {
|
||||||
|
handleInputChange(value[0], 'start_timestamp');
|
||||||
|
handleInputChange(value[1], 'end_timestamp');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</Form.Section>
|
</Form.Section>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
|
|||||||
@@ -1234,5 +1234,6 @@
|
|||||||
"应用更改": "Apply changes",
|
"应用更改": "Apply changes",
|
||||||
"更多": "Expand more",
|
"更多": "Expand more",
|
||||||
"个模型": "models",
|
"个模型": "models",
|
||||||
"可用模型": "Available models"
|
"可用模型": "Available models",
|
||||||
|
"时间范围": "Time range"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user