@@ -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 = () => {
setBatchTab('create')}
- className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${batchTab === 'create' ? 'bg-[#0094f7] text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}
+ className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${batchTab === 'create' ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}
>
批量创建卡密组
setBatchTab('append')}
- className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${batchTab === 'append' ? 'bg-[#0094f7] text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}
+ className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${batchTab === 'append' ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}
>
往单个组充卡密
diff --git a/frontend/components/Chat.tsx b/frontend/components/Chat.tsx
index fd00aaf..bdb574b 100644
--- a/frontend/components/Chat.tsx
+++ b/frontend/components/Chat.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useMemo, useRef, useState } from 'react';
+import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import {
AlertCircle, Check, CheckCheck, ImagePlus, Loader2, MessageCircleMore, RefreshCw,
Search, Send, Smile, UserRound, Wifi, WifiOff,
@@ -53,6 +53,9 @@ const Chat: React.FC = () => {
const activeAccountRef = useRef('');
const activeChatRef = useRef('');
const scrollRef = useRef(null);
+ const scrollContextRef = useRef({ accountID: '', chatID: '' });
+ const shouldScrollToBottomRef = useRef(true);
+ const skipNextMessageScrollRef = useRef(false);
const imageInputRef = useRef(null);
const refreshedAccountsRef = useRef(new Set());
@@ -177,6 +180,7 @@ const Chat: React.FC = () => {
if (!activeAccountID || !activeChatID || olderLoading || !hasOlder) return;
const container = scrollRef.current;
const previousHeight = container?.scrollHeight || 0;
+ skipNextMessageScrollRef.current = true;
setOlderLoading(true);
setError('');
try {
@@ -192,6 +196,7 @@ const Chat: React.FC = () => {
if (container) container.scrollTop += container.scrollHeight - previousHeight;
});
} catch (loadError) {
+ skipNextMessageScrollRef.current = false;
setError(loadError instanceof Error ? loadError.message : '加载历史消息失败');
} finally {
setOlderLoading(false);
@@ -261,10 +266,28 @@ const Chat: React.FC = () => {
};
}, []);
- useEffect(() => {
+ const handleMessageScroll = () => {
const container = scrollRef.current;
- if (container) container.scrollTop = container.scrollHeight;
- }, [activeAccountID, activeChatID, messagesLoading]);
+ if (!container) return;
+ const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight;
+ shouldScrollToBottomRef.current = distanceFromBottom <= 48;
+ };
+
+ useLayoutEffect(() => {
+ const contextChanged = scrollContextRef.current.accountID !== activeAccountID
+ || scrollContextRef.current.chatID !== activeChatID;
+ scrollContextRef.current = { accountID: activeAccountID, chatID: activeChatID };
+ if (contextChanged) shouldScrollToBottomRef.current = true;
+
+ const container = scrollRef.current;
+ if (!container) return;
+
+ if (skipNextMessageScrollRef.current) {
+ skipNextMessageScrollRef.current = false;
+ return;
+ }
+ if (messagesLoading || shouldScrollToBottomRef.current) container.scrollTop = container.scrollHeight;
+ }, [activeAccountID, activeChatID, messages, messagesLoading]);
const activeAccount = accounts.find(account => account.id === activeAccountID);
const activeSessions = sessionsByAccount[activeAccountID] || [];
@@ -343,7 +366,7 @@ const Chat: React.FC = () => {
if (loading) return ;
return (
-
+
@@ -400,7 +423,7 @@ const Chat: React.FC = () => {
{filteredSessions.map(session => (
setActiveChatID(session.chat_id)}
- className={`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${session.chat_id === activeChatID ? 'bg-white shadow-[inset_3px_0_0_#0ea5e9]' : 'hover:bg-white/80'}`}>
+ className={`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${session.chat_id === activeChatID ? 'bg-white shadow-chat-active' : 'hover:bg-white/80'}`}>
{session.buyer_avatar_url ?  : }
@@ -427,7 +450,7 @@ const Chat: React.FC = () => {
-
+
{selectedSession ? (
<>
@@ -439,7 +462,7 @@ const Chat: React.FC = () => {
{activeAccount?.runtime_state === 'online' ? '账号在线' : '账号离线'}
-
+
{messagesLoading ?
: <>
{hasOlder &&
void loadOlderMessages()} disabled={olderLoading}
@@ -490,7 +513,7 @@ const Chat: React.FC = () => {
>}
{error && {error} }
-
+
setEmojiOpen(value => !value)} disabled={sending || activeAccount?.runtime_state !== 'online'} className="rounded-lg p-2 text-slate-500 hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40" title="闲鱼表情">
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"
/>
{
@@ -356,26 +368,26 @@ const Dashboard: React.FC = () => {
dataKey="name"
axisLine={false}
tickLine={false}
- tick={{fill: '#374151', fontSize: 14, fontWeight: 600}}
+ tick={{fill: cssColor('neutral-700'), fontSize: 14, fontWeight: 600}}
dy={10}
/>
`¥${value}`}
/>
{
const num = Number(value);
return [`¥${num.toFixed(2)}`, '营收'];
@@ -383,7 +395,7 @@ const Dashboard: React.FC = () => {
/>
{
{chartData.map((_, index) => (
|
@@ -407,36 +419,36 @@ const Dashboard: React.FC = () => {
-
-
+
+
-
+
-
+
)}
@@ -466,7 +478,7 @@ const Dashboard: React.FC = () => {
@@ -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)'
}}
/>
|