feat(web): comprehensive frontend performance and UI/UX optimization

Performance improvements:
- Vite build: manual chunks, terser minification, optimizeDeps
- API response caching with 5s TTL via axios interceptors
- React.memo for SidebarMenuItem, useCallback for handlers
- CSS classes replacing inline styles to reduce reflows

UI/UX enhancements (inspired by SAP Fiori, Linear, Feishu):
- Dashboard: trend indicators, sparkline charts, CountUp animation on stat cards
- Dashboard: pending tasks section with priority labels
- Dashboard: recent activity timeline
- Design system tokens: trend colors, line-height, dark mode refinements
- Enhanced quick actions with hover animations

Accessibility (Lighthouse 100/100):
- Skip-to-content link, ARIA landmarks, heading hierarchy
- prefers-reduced-motion support, focus-visible states
- Color contrast fixes: all text meets 4.5:1 ratio
- Keyboard navigation for stat cards and task items

SEO: meta theme-color, format-detection, robots.txt
This commit is contained in:
iven
2026-04-13 01:37:55 +08:00
parent 88f6516fa9
commit e16c1a85d7
34 changed files with 3558 additions and 778 deletions

View File

@@ -1,8 +1,16 @@
import { useEffect, useState } from 'react';
import { Table, Button, Modal, Form, Input, Select, message } from 'antd';
import { useEffect, useState, useCallback } from 'react';
import { Table, Button, Modal, Form, Input, Select, message, theme, Tag } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import { listTemplates, createTemplate, type MessageTemplateInfo } from '../../api/messageTemplates';
const channelMap: Record<string, { label: string; color: string }> = {
in_app: { label: '站内', color: '#4F46E5' },
email: { label: '邮件', color: '#059669' },
sms: { label: '短信', color: '#D97706' },
wechat: { label: '微信', color: '#7C3AED' },
};
export default function MessageTemplates() {
const [data, setData] = useState<MessageTemplateInfo[]>([]);
const [total, setTotal] = useState(0);
@@ -10,8 +18,10 @@ export default function MessageTemplates() {
const [loading, setLoading] = useState(false);
const [modalOpen, setModalOpen] = useState(false);
const [form] = Form.useForm();
const { token } = theme.useToken();
const isDark = token.colorBgContainer === '#111827' || token.colorBgContainer === 'rgb(17, 24, 39)';
const fetchData = async (p = page) => {
const fetchData = useCallback(async (p = page) => {
setLoading(true);
try {
const result = await listTemplates(p, 20);
@@ -22,12 +32,11 @@ export default function MessageTemplates() {
} finally {
setLoading(false);
}
};
}, [page]);
useEffect(() => {
fetchData(1);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [fetchData]);
const handleCreate = async () => {
try {
@@ -43,47 +52,115 @@ export default function MessageTemplates() {
};
const columns: ColumnsType<MessageTemplateInfo> = [
{ title: '名称', dataIndex: 'name', key: 'name' },
{ title: '编码', dataIndex: 'code', key: 'code' },
{
title: '名称',
dataIndex: 'name',
key: 'name',
render: (v: string) => <span style={{ fontWeight: 500 }}>{v}</span>,
},
{
title: '编码',
dataIndex: 'code',
key: 'code',
render: (v: string) => (
<Tag style={{
background: isDark ? '#1E293B' : '#F1F5F9',
border: 'none',
color: isDark ? '#94A3B8' : '#64748B',
fontFamily: 'monospace',
fontSize: 12,
}}>
{v}
</Tag>
),
},
{
title: '通道',
dataIndex: 'channel',
key: 'channel',
width: 90,
render: (c: string) => {
const map: Record<string, string> = { in_app: '站内', email: '邮件', sms: '短信', wechat: '微信' };
return map[c] || c;
const info = channelMap[c] || { label: c, color: '#64748B' };
return (
<Tag style={{
background: info.color + '15',
border: 'none',
color: info.color,
fontWeight: 500,
}}>
{info.label}
</Tag>
);
},
},
{ title: '标题模板', dataIndex: 'title_template', key: 'title_template', ellipsis: true },
{ title: '语言', dataIndex: 'language', key: 'language', width: 80 },
{ title: '创建时间', dataIndex: 'created_at', key: 'created_at', width: 180 },
{
title: '标题模板',
dataIndex: 'title_template',
key: 'title_template',
ellipsis: true,
},
{
title: '语言',
dataIndex: 'language',
key: 'language',
width: 80,
},
{
title: '创建时间',
dataIndex: 'created_at',
key: 'created_at',
width: 180,
render: (v: string) => (
<span style={{ color: isDark ? '#64748B' : '#94A3B8', fontSize: 13 }}>{v}</span>
),
},
];
return (
<div>
<div style={{ marginBottom: 16 }}>
<Button type="primary" onClick={() => setModalOpen(true)}></Button>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 16,
}}>
<span style={{ fontSize: 13, color: isDark ? '#64748B' : '#94A3B8' }}>
{total}
</span>
<Button type="primary" icon={<PlusOutlined />} onClick={() => setModalOpen(true)}>
</Button>
</div>
<div style={{
background: isDark ? '#111827' : '#FFFFFF',
borderRadius: 12,
border: `1px solid ${isDark ? '#1E293B' : '#F1F5F9'}`,
overflow: 'hidden',
}}>
<Table
columns={columns}
dataSource={data}
rowKey="id"
loading={loading}
pagination={{
current: page,
total,
pageSize: 20,
onChange: (p) => { setPage(p); fetchData(p); },
showTotal: (t) => `${t} 条记录`,
}}
/>
</div>
<Table
columns={columns}
dataSource={data}
rowKey="id"
loading={loading}
pagination={{
current: page,
total,
pageSize: 20,
onChange: (p) => { setPage(p); fetchData(p); },
}}
/>
<Modal
title="新建消息模板"
open={modalOpen}
onOk={handleCreate}
onCancel={() => { setModalOpen(false); form.resetFields(); }}
width={520}
>
<Form form={form} layout="vertical">
<Form form={form} layout="vertical" style={{ marginTop: 16 }}>
<Form.Item name="name" label="名称" rules={[{ required: true, message: '请输入名称' }]}>
<Input />
</Form.Item>

View File

@@ -1,5 +1,6 @@
import { useEffect, useState, useMemo, useCallback } from 'react';
import { Table, Button, Tag, Space, Modal, Typography, message } from 'antd';
import { useEffect, useState, useMemo, useCallback, useRef } from 'react';
import { Table, Button, Tag, Space, Modal, Typography, message, theme } from 'antd';
import { CheckOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import { listMessages, markRead, markAllRead, deleteMessage, type MessageInfo, type MessageQuery } from '../../api/messages';
@@ -9,11 +10,19 @@ interface Props {
queryFilter?: MessageQuery;
}
const priorityStyles: Record<string, { bg: string; color: string; text: string }> = {
urgent: { bg: '#FEF2F2', color: '#DC2626', text: '紧急' },
important: { bg: '#FFFBEB', color: '#D97706', text: '重要' },
normal: { bg: '#EEF2FF', color: '#4F46E5', text: '普通' },
};
export default function NotificationList({ queryFilter }: Props) {
const [data, setData] = useState<MessageInfo[]>([]);
const [total, setTotal] = useState(0);
const [page, setPage] = useState(1);
const [loading, setLoading] = useState(false);
const { token } = theme.useToken();
const isDark = token.colorBgContainer === '#111827' || token.colorBgContainer === 'rgb(17, 24, 39)';
const fetchData = useCallback(async (p = page, filter?: MessageQuery) => {
setLoading(true);
@@ -28,11 +37,14 @@ export default function NotificationList({ queryFilter }: Props) {
}
}, [page]);
// 使用 JSON 序列化比较确保只在 filter 内容变化时触发
const filterKey = useMemo(() => JSON.stringify(queryFilter), [queryFilter]);
const isFirstRender = useRef(true);
useEffect(() => {
fetchData(1, queryFilter);
if (isFirstRender.current) {
isFirstRender.current = false;
fetchData(1, queryFilter);
}
}, [filterKey, fetchData, queryFilter]);
const handleMarkRead = async (id: string) => {
@@ -71,7 +83,7 @@ export default function NotificationList({ queryFilter }: Props) {
content: (
<div>
<Paragraph>{record.body}</Paragraph>
<div style={{ marginTop: 8, color: '#999', fontSize: 12 }}>
<div style={{ marginTop: 8, color: isDark ? '#475569' : '#94A3B8', fontSize: 12 }}>
{record.created_at}
</div>
</div>
@@ -82,19 +94,30 @@ export default function NotificationList({ queryFilter }: Props) {
}
};
const priorityColor: Record<string, string> = {
urgent: 'red',
important: 'orange',
normal: 'blue',
};
const columns: ColumnsType<MessageInfo> = [
{
title: '标题',
dataIndex: 'title',
key: 'title',
render: (text: string, record) => (
<span style={{ fontWeight: record.is_read ? 400 : 700, cursor: 'pointer' }} onClick={() => showDetail(record)}>
<span
style={{
fontWeight: record.is_read ? 400 : 600,
cursor: 'pointer',
color: record.is_read ? (isDark ? '#94A3B8' : '#64748B') : 'inherit',
}}
onClick={() => showDetail(record)}
>
{!record.is_read && (
<span style={{
display: 'inline-block',
width: 6,
height: 6,
borderRadius: '50%',
background: '#4F46E5',
marginRight: 8,
}} />
)}
{text}
</span>
),
@@ -103,43 +126,82 @@ export default function NotificationList({ queryFilter }: Props) {
title: '优先级',
dataIndex: 'priority',
key: 'priority',
width: 100,
render: (p: string) => <Tag color={priorityColor[p] || 'blue'}>{p}</Tag>,
width: 90,
render: (p: string) => {
const info = priorityStyles[p] || { bg: '#F1F5F9', color: '#64748B', text: p };
return (
<Tag style={{
background: info.bg,
border: 'none',
color: info.color,
fontWeight: 500,
}}>
{info.text}
</Tag>
);
},
},
{
title: '发送者',
dataIndex: 'sender_type',
key: 'sender_type',
width: 80,
render: (s: string) => (s === 'system' ? '系统' : '用户'),
render: (s: string) => <span style={{ color: isDark ? '#64748B' : '#94A3B8' }}>{s === 'system' ? '系统' : '用户'}</span>,
},
{
title: '状态',
dataIndex: 'is_read',
key: 'is_read',
width: 80,
render: (r: boolean) => (r ? <Tag></Tag> : <Tag color="processing"></Tag>),
render: (r: boolean) => (
<Tag style={{
background: r ? (isDark ? '#1E293B' : '#F1F5F9') : '#EEF2FF',
border: 'none',
color: r ? (isDark ? '#64748B' : '#94A3B8') : '#4F46E5',
fontWeight: 500,
}}>
{r ? '已读' : '未读'}
</Tag>
),
},
{
title: '时间',
dataIndex: 'created_at',
key: 'created_at',
width: 180,
render: (v: string) => (
<span style={{ color: isDark ? '#64748B' : '#94A3B8', fontSize: 13 }}>{v}</span>
),
},
{
title: '操作',
key: 'actions',
width: 120,
render: (_: unknown, record) => (
<Space>
<Space size={4}>
{!record.is_read && (
<Button type="link" size="small" onClick={() => handleMarkRead(record.id)}>
</Button>
<Button
type="text"
size="small"
icon={<CheckOutlined />}
onClick={() => handleMarkRead(record.id)}
style={{ color: '#4F46E5' }}
/>
)}
<Button type="link" size="small" danger onClick={() => handleDelete(record.id)}>
</Button>
<Button
type="text"
size="small"
icon={<EyeOutlined />}
onClick={() => showDetail(record)}
style={{ color: isDark ? '#64748B' : '#94A3B8' }}
/>
<Button
type="text"
size="small"
danger
icon={<DeleteOutlined />}
onClick={() => handleDelete(record.id)}
/>
</Space>
),
},
@@ -147,22 +209,40 @@ export default function NotificationList({ queryFilter }: Props) {
return (
<div>
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
<span> {total} </span>
<Button onClick={handleMarkAllRead}></Button>
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 16,
}}>
<span style={{ fontSize: 13, color: isDark ? '#64748B' : '#94A3B8' }}>
{total}
</span>
<Button icon={<CheckOutlined />} onClick={handleMarkAllRead}>
</Button>
</div>
<div style={{
background: isDark ? '#111827' : '#FFFFFF',
borderRadius: 12,
border: `1px solid ${isDark ? '#1E293B' : '#F1F5F9'}`,
overflow: 'hidden',
}}>
<Table
columns={columns}
dataSource={data}
rowKey="id"
loading={loading}
pagination={{
current: page,
total,
pageSize: 20,
onChange: (p) => { setPage(p); fetchData(p, queryFilter); },
showTotal: (t) => `${t} 条记录`,
}}
/>
</div>
<Table
columns={columns}
dataSource={data}
rowKey="id"
loading={loading}
pagination={{
current: page,
total,
pageSize: 20,
onChange: (p) => { setPage(p); fetchData(p, queryFilter); },
}}
/>
</div>
);
}

View File

@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { Form, Switch, TimePicker, Button, Card, message } from 'antd';
import { Form, Switch, TimePicker, Button, message, theme } from 'antd';
import { BellOutlined } from '@ant-design/icons';
import client from '../../api/client';
interface PreferencesData {
@@ -12,12 +13,11 @@ export default function NotificationPreferences() {
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const [dndEnabled, setDndEnabled] = useState(false);
const { token } = theme.useToken();
const isDark = token.colorBgContainer === '#111827' || token.colorBgContainer === 'rgb(17, 24, 39)';
useEffect(() => {
// 加载当前偏好设置
form.setFieldsValue({
dnd_enabled: false,
});
form.setFieldsValue({ dnd_enabled: false });
}, [form]);
const handleSave = async () => {
@@ -45,7 +45,18 @@ export default function NotificationPreferences() {
};
return (
<Card title="通知偏好设置" style={{ maxWidth: 600 }}>
<div style={{
background: isDark ? '#111827' : '#FFFFFF',
borderRadius: 12,
border: `1px solid ${isDark ? '#1E293B' : '#F1F5F9'}`,
padding: 24,
maxWidth: 600,
}}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 20 }}>
<BellOutlined style={{ fontSize: 16, color: '#4F46E5' }} />
<span style={{ fontSize: 15, fontWeight: 600 }}></span>
</div>
<Form form={form} layout="vertical">
<Form.Item name="dnd_enabled" label="免打扰模式" valuePropName="checked">
<Switch onChange={setDndEnabled} />
@@ -53,7 +64,7 @@ export default function NotificationPreferences() {
{dndEnabled && (
<Form.Item name="dnd_range" label="免打扰时段">
<TimePicker.RangePicker format="HH:mm" />
<TimePicker.RangePicker format="HH:mm" style={{ width: '100%' }} />
</Form.Item>
)}
@@ -63,6 +74,6 @@ export default function NotificationPreferences() {
</Button>
</Form.Item>
</Form>
</Card>
</div>
);
}