c039475119
* docs: 添加组件文档注释和类型导入 refactor: 统一使用 SnackbarOptions 类型 style: 优化导入语句顺序和格式 * refactor: 简化假数据生成器中的faker导入和使用 Co-authored-by: Copilot <copilot@github.com> * feat(form-recognizer): 增强表单识别功能并优化UI交互 - 新增字段类型偏好设置功能,支持按域名保存字段类型 - 重构FieldList组件,改进字段选择和类型修改体验 - 添加字段定位闪烁功能,便于在页面上快速找到对应字段 - 优化表单填充逻辑,支持单个字段覆盖默认填充模式 - 移除独立的侧边栏页面,统一使用主页面组件 - 改进useStorageState钩子,增加加载状态管理和防抖处理 * refactor: 移除未使用的组件文件 * refactor(页面头部): 提取通用 PageHeader 组件并替换各页面头部实现 重构各页面头部为统一的 PageHeader 组件,提高代码复用性和维护性 * style(组件): 调整自动刷新开关和存储选项网格的样式 优化自动刷新开关的文本内边距,重构存储选项网格的布局结构,调整间距和边框样式 * style(ui): 调整时间戳页面和结果视图的样式 - 为时区选择器添加圆角 - 优化结果视图的布局和对齐方式 - 调整结果项的内边距和文本样式 * ci(workflow): 移除Firefox测试以简化CI流程 仅保留Chrome浏览器的构建步骤,减少CI运行时间和资源消耗
146 lines
4.3 KiB
TypeScript
146 lines
4.3 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
import { Typography, Box, Fade, Stack, alpha } from '@mui/material';
|
|
import dayjs from '@/utils/dayjs';
|
|
import CopyButton from '@/components/CopyButton';
|
|
import { DATE_FORMAT, timestampPageStyles } from '@/config/pageTheme';
|
|
import type { UnitType } from '@/config/pageTheme';
|
|
import type { SnackbarOptions } from '@/components/GlobalSnackbar';
|
|
|
|
interface ResultViewProps {
|
|
result: string;
|
|
mode: 'ts2dt' | 'dt2ts';
|
|
unit: UnitType;
|
|
zone: string;
|
|
showMessage?: (message: string, options?: SnackbarOptions) => void;
|
|
}
|
|
|
|
const ResultView = React.memo(({ result, mode, unit, zone, showMessage }: ResultViewProps) => {
|
|
const extraInfo = useMemo(() => {
|
|
if (!result) return null;
|
|
const d =
|
|
mode === 'ts2dt'
|
|
? dayjs(result, DATE_FORMAT).tz(zone)
|
|
: unit === 'ms'
|
|
? dayjs(Number(result))
|
|
: dayjs.unix(Number(result));
|
|
|
|
return {
|
|
relative: d.fromNow(),
|
|
iso: d.toISOString(),
|
|
utc: d.utc().format(DATE_FORMAT) + ' UTC',
|
|
};
|
|
}, [result, mode, zone, unit]);
|
|
|
|
if (!result) return null;
|
|
|
|
return (
|
|
<Fade in={!!result}>
|
|
<Box sx={{ mt: 3, pt: 2.5, borderTop: '1px solid', borderColor: 'grey.50' }}>
|
|
<Typography
|
|
variant="caption"
|
|
sx={{
|
|
color: 'text.secondary',
|
|
mb: 1.2,
|
|
display: 'block',
|
|
fontWeight: 800,
|
|
fontSize: '0.7rem',
|
|
}}
|
|
>
|
|
转换结果
|
|
</Typography>
|
|
|
|
<Box
|
|
sx={{
|
|
bgcolor: alpha(timestampPageStyles.primaryColor, 0.05),
|
|
p: 2,
|
|
borderRadius: 4,
|
|
position: 'relative',
|
|
mb: 2.5,
|
|
border: '1px solid',
|
|
borderColor: alpha(timestampPageStyles.primaryColor, 0.1),
|
|
display: 'flex',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
}}
|
|
>
|
|
<Typography
|
|
variant="body1"
|
|
sx={{
|
|
fontFamily: 'monospace',
|
|
fontWeight: 700,
|
|
color: timestampPageStyles.primaryColor,
|
|
wordBreak: 'break-all',
|
|
pr: 4,
|
|
fontSize: '1rem',
|
|
}}
|
|
>
|
|
{result}
|
|
</Typography>
|
|
<CopyButton
|
|
text={result}
|
|
tooltip="复制结果"
|
|
size="small"
|
|
color={timestampPageStyles.primaryColor}
|
|
showMessage={showMessage}
|
|
/>
|
|
</Box>
|
|
|
|
<Stack
|
|
spacing={1.2}
|
|
sx={{
|
|
bgcolor: alpha(timestampPageStyles.primaryColor, 0.05),
|
|
p: 2,
|
|
borderRadius: 4,
|
|
border: '1px solid',
|
|
borderColor: alpha(timestampPageStyles.primaryColor, 0.1),
|
|
}}
|
|
>
|
|
{[
|
|
{ label: '相对时间', value: extraInfo?.relative },
|
|
{ label: 'ISO 8601', value: extraInfo?.iso },
|
|
{ label: 'UTC 时间', value: extraInfo?.utc },
|
|
].map((item) => (
|
|
<Box
|
|
key={item.label}
|
|
sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
|
|
>
|
|
<Typography
|
|
variant="caption"
|
|
sx={{ color: 'text.disabled', fontWeight: 700, fontSize: '0.65rem', pr: 4 }}
|
|
>
|
|
{item.label}
|
|
</Typography>
|
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
<Typography
|
|
variant="caption"
|
|
sx={{
|
|
fontFamily: 'monospace',
|
|
color: timestampPageStyles.primaryColor,
|
|
fontWeight: 600,
|
|
fontSize: '0.65rem',
|
|
}}
|
|
>
|
|
{item.value}
|
|
</Typography>
|
|
{item.value && (
|
|
<CopyButton
|
|
text={item.value}
|
|
tooltip="复制"
|
|
size="small"
|
|
color={timestampPageStyles.primaryColor}
|
|
showMessage={showMessage}
|
|
/>
|
|
)}
|
|
</Box>
|
|
</Box>
|
|
))}
|
|
</Stack>
|
|
</Box>
|
|
</Fade>
|
|
);
|
|
});
|
|
|
|
ResultView.displayName = 'ResultView';
|
|
|
|
export default ResultView;
|