diff --git a/frontend/App.tsx b/frontend/App.tsx index 4c0c31f..5d6a464 100644 --- a/frontend/App.tsx +++ b/frontend/App.tsx @@ -147,8 +147,8 @@ const App: React.FC = () => { if (checkingAuth) { return ( -
- +
+
); } @@ -156,11 +156,11 @@ const App: React.FC = () => { // Init Screen (system not initialized) if (needsInit) { return ( -
+
-
+
@@ -198,12 +198,12 @@ const App: React.FC = () => { // Login Screen Component if (!isLoggedIn) { return ( -
+
{/* Animated Background Blobs */}
-
+
{/* Header with Logo */}
@@ -288,7 +288,7 @@ const App: React.FC = () => { }; return ( -
+
{ expect(chat).toContain('justify-center py-1'); }); + test('keeps the active chat at the bottom when new messages arrive', () => { + const chat = source('components/Chat.tsx'); + expect(chat).toContain('shouldScrollToBottomRef'); + expect(chat).toContain('skipNextMessageScrollRef'); + expect(chat).toContain('onScroll={handleMessageScroll}'); + expect(chat).toContain('container.scrollHeight - container.scrollTop - container.clientHeight'); + expect(chat).toContain('[activeAccountID, activeChatID, messages, messagesLoading]'); + }); + test('sidebar exposes collapse control and chat primary navigation', () => { const sidebar = source('components/Sidebar.tsx'); expect(sidebar).toContain("id: 'chat'"); diff --git a/frontend/colorTokens.test.ts b/frontend/colorTokens.test.ts new file mode 100644 index 0000000..92e6963 --- /dev/null +++ b/frontend/colorTokens.test.ts @@ -0,0 +1,36 @@ +import { readdirSync, readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; +import { describe, expect, test } from 'vitest'; + +const componentsDir = resolve(__dirname, 'components'); +const pageSources = [ + resolve(__dirname, 'App.tsx'), + ...readdirSync(componentsDir) + .filter((fileName) => fileName.endsWith('.tsx') && !fileName.endsWith('.test.tsx')) + .map((fileName) => resolve(componentsDir, fileName)), +]; + +// rgb(var(--color-*)), CSS classes and the central index.css are references. +// Literal colors in page code would bypass the design-token system. +const hardCodedColorPattern = /#[0-9a-f]{3,8}\b|rgba?\((?!var\(--color-)/gi; + +describe('global color token contract', () => { + test('page components do not contain hard-coded color values', () => { + const violations = pageSources.flatMap((filePath) => { + const source = readFileSync(filePath, 'utf8'); + return [...source.matchAll(hardCodedColorPattern)].map((match) => `${filePath}:${match[0]}`); + }); + + expect(violations).toEqual([]); + }); + + test('the primary brand and highlight colors are defined in the central stylesheet', () => { + const globalStyles = readFileSync(resolve(__dirname, 'index.css'), 'utf8'); + + expect(globalStyles).toContain('--color-brand: 0 148 247;'); + expect(globalStyles).toContain('--color-brand-highlight: 0 113 227;'); + expect(globalStyles).toContain('--color-success-500:'); + expect(globalStyles).toContain('--color-warning-500:'); + expect(globalStyles).toContain('--color-danger-500:'); + }); +}); diff --git a/frontend/components/AccountList.tsx b/frontend/components/AccountList.tsx index eb28eed..81b435f 100644 --- a/frontend/components/AccountList.tsx +++ b/frontend/components/AccountList.tsx @@ -678,7 +678,7 @@ const AccountList: React.FC = () => { } }; - if (loading) return
; + if (loading) return
; const filteredAccounts = accounts.filter(account => { const keyword = accountSearch.trim().toLowerCase(); @@ -728,7 +728,7 @@ const AccountList: React.FC = () => { const runtime = runtimePresentation(account); const requiresLogin = account.runtime_state === 'auth_expired' || account.runtime_state === 'verification_required'; return ( -
+
{account.avatar_url ? ( @@ -898,7 +898,7 @@ const AccountList: React.FC = () => { {deleteDialogAccount && createPortal(
{ role="progressbar" aria-label="正在删除账号" > - +
正在删除账号
正在清理关联数据,请保持页面打开…
@@ -1015,8 +1015,8 @@ const AccountList: React.FC = () => { : '请打开闲鱼APP扫描下方二维码'}

-
- {qrStatus === 'loading' && } +
+ {qrStatus === 'loading' && } {qrStatus === 'waiting' && } {qrStatus === 'success' && (
@@ -1111,7 +1111,7 @@ const AccountList: React.FC = () => { type="button" onClick={() => setEditForm({ ...editForm, auto_confirm: !editForm.auto_confirm })} className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${ - editForm.auto_confirm ? 'bg-[#0094f7]' : 'bg-gray-300' + editForm.auto_confirm ? 'bg-brand' : 'bg-gray-300' }`} > { aria-label="保存登录信息" disabled={longLogin.loading || longLogin.saving || !longLogin.canOpen} onClick={() => void handleLongLoginToggle()} - className={`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${longLogin.enabled ? 'bg-[#0094f7]' : 'bg-gray-300'} disabled:cursor-not-allowed disabled:opacity-50`} + className={`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${longLogin.enabled ? 'bg-brand' : 'bg-gray-300'} disabled:cursor-not-allowed disabled:opacity-50`} > @@ -1206,7 +1206,7 @@ const AccountList: React.FC = () => { type="checkbox" checked={editForm.clear_password} onChange={(e) => setEditForm({ ...editForm, clear_password: e.target.checked, login_password: e.target.checked ? '' : editForm.login_password })} - className="w-4 h-4 accent-[#0094f7]" + className="w-4 h-4 accent-brand" /> 清空已保存密码 @@ -1220,7 +1220,7 @@ const AccountList: React.FC = () => { type="button" onClick={() => setEditForm({ ...editForm, show_browser: !editForm.show_browser })} className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${ - editForm.show_browser ? 'bg-[#0094f7]' : 'bg-gray-300' + editForm.show_browser ? 'bg-brand' : 'bg-gray-300' }`} > { }} disabled={!bindingsLoaded} className={`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${ - checked ? 'bg-[#0094f7] border-[#0094f7]' : 'bg-white border-gray-300' + checked ? 'bg-brand border-brand' : 'bg-white border-gray-300' }`} > {checked && } @@ -1377,7 +1377,7 @@ const AccountList: React.FC = () => { type="button" onClick={() => setAiSettings({ ...aiSettings, ai_enabled: !aiSettings.ai_enabled })} className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${ - aiSettings.ai_enabled ? 'bg-[#0094f7]' : 'bg-gray-300' + aiSettings.ai_enabled ? 'bg-brand' : 'bg-gray-300' }`} > {
-
+
@@ -375,7 +375,7 @@ const CardList: React.FC = () => { } return ( - +
@@ -667,7 +667,7 @@ const CardList: React.FC = () => { type="button" onClick={() => setEditForm({ ...editForm, enabled: !editForm.enabled })} className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${ - editForm.enabled ? 'bg-[#0094f7]' : 'bg-gray-300' + editForm.enabled ? 'bg-brand' : 'bg-gray-300' }`} > {
@@ -879,14 +879,14 @@ const CardList: React.FC = () => {
-
+
{selectedSession ? ( <>
@@ -439,7 +462,7 @@ const Chat: React.FC = () => { {activeAccount?.runtime_state === 'online' ? '账号在线' : '账号离线'}
-
+
{messagesLoading ?
: <> {hasOlder &&
{error &&
{error}
} -
+
diff --git a/frontend/components/Dashboard.test.tsx b/frontend/components/Dashboard.test.tsx index dd157b8..ec590d1 100644 --- a/frontend/components/Dashboard.test.tsx +++ b/frontend/components/Dashboard.test.tsx @@ -33,9 +33,8 @@ describe('Dashboard presentation safeguards', () => { expect(globalStyles).toContain('.dashboard-pie-chart .recharts-sector:focus'); expect(dashboardSource).toContain('dashboard-revenue-chart h-[350px] w-full'); expect(dashboardSource).toContain('activeBar={false}'); - expect(dashboardSource).not.toContain('stroke="#000000"'); - expect(dashboardSource).not.toContain("['#0094f7', '#FCD34D', '#0071e3']"); - expect(dashboardSource).toContain('fill="#0094f7"'); + expect(dashboardSource).not.toMatch(/#[0-9A-Fa-f]{3,8}/); + expect(dashboardSource).toContain("fill={cssColor('brand')}"); expect(globalStyles).toContain('.dashboard-revenue-chart .recharts-rectangle:focus'); expect(globalStyles).toContain('.dashboard-revenue-chart .recharts-curve:focus'); expect(globalStyles).toContain('.dashboard-revenue-chart [class*="recharts-zIndex-layer_"]:focus'); diff --git a/frontend/components/Dashboard.tsx b/frontend/components/Dashboard.tsx index 965d79e..c9bd5c4 100644 --- a/frontend/components/Dashboard.tsx +++ b/frontend/components/Dashboard.tsx @@ -6,11 +6,17 @@ import { formatLocalDateTime } from '../dateTime'; import { TrendingUp, Users, ShoppingCart, AlertCircle, DollarSign, Activity, Package, ArrowUpRight, Calendar, X, BarChart3, PackageCheck, ExternalLink, Eye, Edit } from 'lucide-react'; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, BarChart, Bar, PieChart, Pie, Cell, Legend } from 'recharts'; +const cssColor = (token: string, alpha?: number) => ( + alpha === undefined + ? `rgb(var(--color-${token}))` + : `rgb(var(--color-${token}) / ${alpha})` +); + // 状态徽章组件 export const StatusBadge: React.FC<{ status: OrderStatus }> = ({ status }) => { const styles = { processing: 'bg-blue-100 text-blue-800', - pending_ship: 'bg-[#0094f7] text-white', + pending_ship: 'bg-brand text-white', shipped: 'bg-blue-100 text-blue-700', completed: 'bg-green-100 text-green-700', cancelled: 'bg-gray-100 text-gray-500', @@ -42,7 +48,7 @@ const StatCard: React.FC<{ title: string; value: string | number; icon: React.El
- {trend && + {trend && {trend} }
@@ -75,7 +81,13 @@ const Dashboard: React.FC = () => { const rangeRequestSequence = useRef(0); // 颜色配置 - const COLORS = ['#0094f7', '#3B82F6', '#10B981', '#F59E0B', '#8B5CF6']; + const COLORS = [ + cssColor('brand'), + cssColor('brand-highlight'), + cssColor('success-500'), + cssColor('warning-500'), + cssColor('accent-500'), + ]; const formatCurrency = (value: number) => `¥${Number(value || 0).toLocaleString('zh-CN', { maximumFractionDigits: 2 })}`; const loadRange = async (range: TimeRange) => { let currentRange; @@ -159,7 +171,7 @@ const Dashboard: React.FC = () => {
); } - if (!stats || !analytics) return
; + if (!stats || !analytics) return
; const chartData = analytics.daily_stats?.map(d => ({ name: d.date.slice(5), // MM-DD @@ -267,7 +279,7 @@ const Dashboard: React.FC = () => { onClick={() => setTimeRange(option.key)} className={`px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${ timeRange === option.key - ? 'bg-[#0094f7] text-white shadow-md' + ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:text-black hover:bg-gray-50' }`} > @@ -280,14 +292,14 @@ const Dashboard: React.FC = () => { type="date" value={customStartDate} onChange={(e) => setCustomStartDate(e.target.value)} - className="px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-[#0094f7]" + className="px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand" /> - setCustomEndDate(e.target.value)} - className="px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-[#0094f7]" + className="px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand" />
@@ -516,17 +528,17 @@ const Dashboard: React.FC = () => { formatter={(value) => `${Number(value || 0)} 单`} wrapperStyle={{ zIndex: 30, outline: 'none' }} contentStyle={{ - backgroundColor: '#fff', - border: '1px solid #e5e7eb', + backgroundColor: cssColor('white'), + border: `1px solid ${cssColor('neutral-200')}`, borderRadius: '10px', - boxShadow: '0 8px 20px rgba(15, 23, 42, 0.08)' + boxShadow: 'var(--shadow-md)' }} /> {value}} + formatter={(value) => {value}} /> @@ -544,7 +556,7 @@ const Dashboard: React.FC = () => {
{/* 参与统计的订单列表 */}
-
+

参与统计的订单

{validOrdersTruncated && ( @@ -603,7 +615,7 @@ const Dashboard: React.FC = () => { {filteredValidOrders.map((order) => ( - +
@@ -687,10 +699,10 @@ const Dashboard: React.FC = () => { `¥${Number(value || 0).toLocaleString()}`} /> diff --git a/frontend/components/ItemList.tsx b/frontend/components/ItemList.tsx index 606e11a..755bdb9 100644 --- a/frontend/components/ItemList.tsx +++ b/frontend/components/ItemList.tsx @@ -638,14 +638,14 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => {
- diff --git a/frontend/components/Notifications.tsx b/frontend/components/Notifications.tsx index 608f992..ea7a40a 100644 --- a/frontend/components/Notifications.tsx +++ b/frontend/components/Notifications.tsx @@ -394,7 +394,7 @@ const Notifications: React.FC = ({ isAdmin = false }) => { {/* 说明 */}
- +
配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:
    @@ -409,7 +409,7 @@ const Notifications: React.FC = ({ isAdmin = false }) => { {/* 渠道列表 */} {loading ? (
    - +
    ) : channels.length === 0 ? (
    @@ -454,7 +454,7 @@ const Notifications: React.FC = ({ isAdmin = false }) => { ); })} @@ -712,7 +712,7 @@ const Notifications: React.FC = ({ isAdmin = false }) => { : enableCustomSMTP(form.config, smtp), }); }} - className={`relative h-7 w-12 shrink-0 rounded-full transition-colors ${form.config.use_custom_smtp === true ? 'bg-[#0094f7]' : 'bg-gray-300'}`} + className={`relative h-7 w-12 shrink-0 rounded-full transition-colors ${form.config.use_custom_smtp === true ? 'bg-brand' : 'bg-gray-300'}`} aria-label="使用独立 SMTP" > @@ -839,13 +839,13 @@ const Notifications: React.FC = ({ isAdmin = false }) => { : [...form.event_types, event.value]; setForm({ ...form, event_types: next }); }} - className={`text-left rounded-xl border px-3 py-2.5 transition-colors ${checked ? 'border-[#0094f7] bg-blue-50' : 'border-gray-100 hover:border-gray-300'}`} + className={`text-left rounded-xl border px-3 py-2.5 transition-colors ${checked ? 'border-brand bg-blue-50' : 'border-gray-100 hover:border-gray-300'}`} >
    - + {checked && } - {event.label} + {event.label}

    {event.description}

    @@ -858,7 +858,7 @@ const Notifications: React.FC = ({ isAdmin = false }) => { @@ -889,8 +889,7 @@ const Notifications: React.FC = ({ isAdmin = false }) => { {/* Toast */} {toast && ( -
    +
    {toast.type === 'success' ? : } {toast.text}
    diff --git a/frontend/components/OrderList.tsx b/frontend/components/OrderList.tsx index 34700e7..f49d709 100644 --- a/frontend/components/OrderList.tsx +++ b/frontend/components/OrderList.tsx @@ -9,7 +9,7 @@ import { formatLocalDateTime } from '../dateTime'; const StatusBadge: React.FC<{ status: OrderStatus }> = ({ status }) => { const styles = { processing: 'bg-blue-100 text-blue-800', - pending_ship: 'bg-[#0094f7] text-white', + pending_ship: 'bg-brand text-white', shipped: 'bg-blue-100 text-blue-700', completed: 'bg-green-100 text-green-700', cancelled: 'bg-gray-100 text-gray-500', @@ -356,7 +356,7 @@ const OrderList: React.FC = () => {
    {/* Toolbar */} -
    +
    {[ {k:'all', v:'全部'}, @@ -392,7 +392,7 @@ const OrderList: React.FC = () => {
    - + { {orders.map((order) => ( - +
    @@ -800,7 +800,7 @@ const OrderList: React.FC = () => { diff --git a/frontend/components/Settings.tsx b/frontend/components/Settings.tsx index d163196..43c80c2 100644 --- a/frontend/components/Settings.tsx +++ b/frontend/components/Settings.tsx @@ -269,7 +269,7 @@ const Settings: React.FC = () => { {/* AI Configuration */}

    -
    +
    AI 智能回复配置 @@ -346,10 +346,10 @@ const Settings: React.FC = () => { setSettings({...settings, ai_model: model}); setModelDropdownOpen(false); }} - className="w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-[#0094f7] flex items-center justify-between gap-3" + className="w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-brand flex items-center justify-between gap-3" > {model} - {model === currentModel && } + {model === currentModel && } )) ) : ( diff --git a/frontend/components/Sidebar.tsx b/frontend/components/Sidebar.tsx index f30afcf..71319d3 100644 --- a/frontend/components/Sidebar.tsx +++ b/frontend/components/Sidebar.tsx @@ -30,7 +30,7 @@ const Sidebar: React.FC = ({ ]; return ( -