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运行时间和资源消耗
154 lines
4.6 KiB
TypeScript
154 lines
4.6 KiB
TypeScript
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
import { Stack, Typography, Box, IconButton, Tooltip, Divider, alpha } from '@mui/material';
|
|
import AccessTimeIcon from '@mui/icons-material/AccessTime';
|
|
import CopyButton from '@/components/CopyButton';
|
|
import { timestampPageStyles } from '@/config/pageTheme';
|
|
import type { UnitType } from '@/config/pageTheme';
|
|
import type { SnackbarOptions } from '@/components/GlobalSnackbar';
|
|
|
|
interface LiveClockProps {
|
|
unit: UnitType;
|
|
onUseNow: (val: number) => void;
|
|
onUnitChange: (u: UnitType) => void;
|
|
showMessage?: (message: string, options?: SnackbarOptions) => void;
|
|
}
|
|
|
|
const LiveClock = React.memo(({ unit, onUseNow, onUnitChange, showMessage }: LiveClockProps) => {
|
|
const [now, setNow] = useState(() => Date.now());
|
|
const onUseNowRef = useRef(onUseNow);
|
|
const showMessageRef = useRef(showMessage);
|
|
|
|
useEffect(() => {
|
|
onUseNowRef.current = onUseNow;
|
|
showMessageRef.current = showMessage;
|
|
}, [onUseNow, showMessage]);
|
|
|
|
useEffect(() => {
|
|
const t = setInterval(() => setNow(Date.now()), 1000);
|
|
return () => clearInterval(t);
|
|
}, []);
|
|
|
|
const displayVal = useMemo(
|
|
() => String(Math.floor(now / (unit === 'ms' ? 1 : 1000))),
|
|
[now, unit],
|
|
);
|
|
|
|
const handleUseNow = useCallback(() => {
|
|
onUseNowRef.current(now);
|
|
showMessageRef.current?.('已使用当前时间戳', { severity: 'success' });
|
|
}, [now, showMessageRef]);
|
|
|
|
return (
|
|
<Box
|
|
sx={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
p: 1.8,
|
|
mb: 2.5,
|
|
bgcolor: alpha(timestampPageStyles.primaryColor, 0.04),
|
|
borderRadius: 4,
|
|
border: '1px solid',
|
|
borderColor: alpha(timestampPageStyles.primaryColor, 0.1),
|
|
}}
|
|
>
|
|
<Stack spacing={0.5}>
|
|
<Typography
|
|
variant="caption"
|
|
sx={{
|
|
color: timestampPageStyles.primaryColor,
|
|
fontWeight: 800,
|
|
fontSize: '0.6rem',
|
|
textTransform: 'uppercase',
|
|
letterSpacing: 1,
|
|
}}
|
|
>
|
|
当前时间戳
|
|
</Typography>
|
|
<Typography
|
|
variant="subtitle2"
|
|
sx={{
|
|
fontWeight: 800,
|
|
color: timestampPageStyles.primaryColor,
|
|
fontFamily: 'monospace',
|
|
fontSize: '1.2rem',
|
|
letterSpacing: '-0.5px',
|
|
lineHeight: 1.2,
|
|
}}
|
|
>
|
|
{displayVal}
|
|
</Typography>
|
|
</Stack>
|
|
|
|
<Stack direction="row" spacing={1} alignItems="center">
|
|
{/* 胶囊式单位切换器 */}
|
|
<Box
|
|
sx={{
|
|
display: 'flex',
|
|
p: 0.4,
|
|
bgcolor: alpha(timestampPageStyles.primaryColor, 0.08),
|
|
borderRadius: 2.5,
|
|
border: '1px solid',
|
|
borderColor: alpha(timestampPageStyles.primaryColor, 0.1),
|
|
}}
|
|
>
|
|
{(['ms', 's'] as const).map((u) => (
|
|
<Box
|
|
key={u}
|
|
onClick={() => onUnitChange(u)}
|
|
sx={{
|
|
px: 1.2,
|
|
py: 0.35,
|
|
borderRadius: 2,
|
|
cursor: 'pointer',
|
|
fontSize: '0.65rem',
|
|
fontWeight: 900,
|
|
transition: 'all 0.2s',
|
|
bgcolor: unit === u ? '#fff' : 'transparent',
|
|
color: unit === u ? 'primary.main' : alpha(timestampPageStyles.primaryColor, 0.4),
|
|
boxShadow: unit === u ? '0 2px 6px rgba(33, 150, 243, 0.2)' : 'none',
|
|
}}
|
|
>
|
|
{u.toUpperCase()}
|
|
</Box>
|
|
))}
|
|
</Box>
|
|
|
|
<Divider
|
|
orientation="vertical"
|
|
flexItem
|
|
sx={{ mx: 0.5, my: 1, borderColor: alpha(timestampPageStyles.primaryColor, 0.1) }}
|
|
/>
|
|
|
|
<Stack direction="row" spacing={0.5}>
|
|
<Tooltip title="填充到下方">
|
|
<IconButton
|
|
size="small"
|
|
onClick={handleUseNow}
|
|
sx={{
|
|
color: timestampPageStyles.primaryColor,
|
|
bgcolor: '#fff',
|
|
boxShadow: '0 2px 4px rgba(0,0,0,0.05)',
|
|
'&:hover': { bgcolor: timestampPageStyles.primaryColor, color: '#fff' },
|
|
}}
|
|
>
|
|
<AccessTimeIcon fontSize="small" />
|
|
</IconButton>
|
|
</Tooltip>
|
|
<CopyButton
|
|
text={displayVal}
|
|
tooltip="复制时间戳"
|
|
size="small"
|
|
color={timestampPageStyles.primaryColor}
|
|
showMessage={showMessage}
|
|
/>
|
|
</Stack>
|
|
</Stack>
|
|
</Box>
|
|
);
|
|
});
|
|
|
|
LiveClock.displayName = 'LiveClock';
|
|
|
|
export default LiveClock;
|