Skip to content

Commit a29f718

Browse files
committed
perf: 优化Webui细节
1 parent d9f7884 commit a29f718

3 files changed

Lines changed: 156 additions & 12 deletions

File tree

dashboard/src/index.css

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,84 @@
654654
font-weight: 700;
655655
}
656656

657+
:root[data-dashboard-style='future-retro'] [data-dashboard-status-dot='true'] {
658+
border: 1px solid var(--retro-line) !important;
659+
border-radius: 1px !important;
660+
background: var(--retro-recessed-strong) !important;
661+
box-shadow: none !important;
662+
animation: none !important;
663+
}
664+
665+
:root[data-dashboard-style='future-retro']
666+
[data-dashboard-status-dot='true'][data-state='running'] {
667+
background: var(--retro-rust) !important;
668+
}
669+
670+
:root[data-dashboard-style='future-retro']
671+
[data-dashboard-status-dot='true'][data-state='loading'] {
672+
background: var(--retro-gold) !important;
673+
}
674+
675+
:root[data-dashboard-style='future-retro']
676+
[data-dashboard-status-dot='true'][data-state='stopped'] {
677+
background: var(--retro-ink-soft) !important;
678+
}
679+
680+
:root[data-dashboard-style='future-retro'] [data-dashboard-status-badge='true'] {
681+
min-height: 1.7rem;
682+
border: var(--retro-stroke) solid var(--retro-line) !important;
683+
border-radius: 2px !important;
684+
background: var(--retro-recessed) !important;
685+
color: var(--retro-ink) !important;
686+
box-shadow: none !important;
687+
font-weight: 800;
688+
}
689+
690+
:root[data-dashboard-style='future-retro']
691+
[data-dashboard-status-badge='true'][data-state='running'] {
692+
background: var(--retro-gold) !important;
693+
color: var(--retro-ink) !important;
694+
}
695+
696+
:root[data-dashboard-style='future-retro']
697+
[data-dashboard-status-badge='true'][data-state='stopped'] {
698+
background: var(--retro-rust) !important;
699+
color: var(--retro-paper) !important;
700+
}
701+
702+
:root[data-dashboard-style='future-retro'] [data-dashboard-status-badge='true'] svg {
703+
color: currentColor !important;
704+
stroke-width: 2.35;
705+
}
706+
707+
:root[data-dashboard-style='future-retro'] [data-dashboard-feature-status='true'] {
708+
min-height: 2rem;
709+
border: var(--retro-stroke) solid var(--retro-line) !important;
710+
border-radius: 2px !important;
711+
background: transparent !important;
712+
color: var(--retro-ink) !important;
713+
font-weight: 700;
714+
box-shadow: none !important;
715+
}
716+
717+
:root[data-dashboard-style='future-retro']
718+
[data-dashboard-feature-status='true'][data-enabled='true'] {
719+
background: var(--retro-recessed) !important;
720+
}
721+
722+
:root[data-dashboard-style='future-retro'] [data-dashboard-feature-status-light='true'] {
723+
border: 1px solid var(--retro-line) !important;
724+
border-radius: 1px !important;
725+
background: transparent !important;
726+
box-shadow: none !important;
727+
}
728+
729+
:root[data-dashboard-style='future-retro']
730+
[data-dashboard-feature-status='true'][data-enabled='true']
731+
[data-dashboard-feature-status-light='true'] {
732+
background: var(--retro-gold) !important;
733+
}
734+
657735
:root[data-dashboard-style='future-retro'] [data-dashboard-switch='true'] {
658736
border: var(--retro-stroke) solid var(--retro-line) !important;
659737
border-radius: 2px !important;

dashboard/src/routes/chat/MessageList.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,42 @@ export function MessageList({
8585
language,
8686
}: MessageListProps) {
8787
const { t } = useTranslation()
88+
const viewportRef = useRef<HTMLDivElement>(null)
8889
const endRef = useRef<HTMLDivElement>(null)
8990
const messageRefs = useRef<Map<string, HTMLDivElement>>(new Map())
9091

9192
useEffect(() => {
92-
endRef.current?.scrollIntoView({ behavior: 'smooth' })
93+
const viewport = viewportRef.current
94+
if (!viewport) {
95+
return
96+
}
97+
98+
viewport.scrollTo({
99+
top: viewport.scrollHeight,
100+
behavior: 'smooth',
101+
})
93102
}, [messages])
94103

95104
const scrollToMessage = useCallback((messageId: string) => {
105+
const viewport = viewportRef.current
96106
const target = messageRefs.current.get(messageId)
97-
if (!target) {
107+
if (!target || !viewport) {
98108
return false
99109
}
100-
target.scrollIntoView({ behavior: 'smooth', block: 'center' })
110+
111+
const viewportRect = viewport.getBoundingClientRect()
112+
const targetRect = target.getBoundingClientRect()
113+
const targetTop =
114+
viewport.scrollTop +
115+
targetRect.top -
116+
viewportRect.top -
117+
viewport.clientHeight / 2 +
118+
targetRect.height / 2
119+
120+
viewport.scrollTo({
121+
top: Math.max(0, targetTop),
122+
behavior: 'smooth',
123+
})
101124
target.classList.add('chat-message-flash')
102125
window.setTimeout(() => {
103126
target.classList.remove('chat-message-flash')
@@ -130,6 +153,7 @@ export function MessageList({
130153
className="h-full w-full"
131154
contentClassName="!block w-full min-w-0"
132155
scrollbars="vertical"
156+
viewportRef={viewportRef}
133157
viewportClassName="[&>div]:!block [&>div]:!min-w-0 [&>div]:w-full"
134158
>
135159
<EmptyState botName={botDisplayName} />
@@ -144,6 +168,7 @@ export function MessageList({
144168
className="h-full w-full"
145169
contentClassName="!block w-full min-w-0"
146170
scrollbars="vertical"
171+
viewportRef={viewportRef}
147172
viewportClassName="[&>div]:!block [&>div]:!min-w-0 [&>div]:w-full"
148173
>
149174
<ChatScrollContext.Provider value={scrollContextValue}>

dashboard/src/routes/index.tsx

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,13 @@ const generatePieColors = (count: number): string[] => {
181181
// 内部实现组件
182182
function FeatureStatusLight({ enabled, label }: { enabled: boolean; label: string }) {
183183
return (
184-
<div className="inline-flex items-center gap-1.5 rounded-md border bg-background px-2 py-1 text-xs text-muted-foreground">
184+
<div
185+
data-dashboard-feature-status="true"
186+
data-enabled={enabled ? 'true' : 'false'}
187+
className="inline-flex items-center gap-1.5 rounded-md border bg-background px-2 py-1 text-xs text-muted-foreground"
188+
>
185189
<span
190+
data-dashboard-feature-status-light="true"
186191
className={`h-2.5 w-2.5 rounded-full ${
187192
enabled ? 'bg-green-500 shadow-[0_0_0_3px_rgba(34,197,94,0.18)]' : 'bg-muted-foreground/30'
188193
}`}
@@ -788,32 +793,68 @@ function IndexPageContent() {
788793
<div className="flex items-center gap-2">
789794
{isBotStatusLoading && !botStatus ? (
790795
<>
791-
<div className="h-3 w-3 rounded-full bg-muted-foreground/40 animate-pulse" />
792-
<Badge variant="outline" className="whitespace-nowrap text-muted-foreground">
796+
<div
797+
data-dashboard-status-dot="true"
798+
data-state="loading"
799+
className="h-3 w-3 rounded-full bg-muted-foreground/40 animate-pulse"
800+
/>
801+
<Badge
802+
data-dashboard-status-badge="true"
803+
data-state="loading"
804+
variant="outline"
805+
className="whitespace-nowrap text-muted-foreground"
806+
>
793807
<RefreshCw className="h-3 w-3 mr-1 animate-spin" />
794808
读取中
795809
</Badge>
796810
</>
797811
) : botStatus?.running ? (
798812
<>
799-
<div className="h-3 w-3 rounded-full bg-green-500 animate-pulse" />
800-
<Badge variant="outline" className="whitespace-nowrap text-green-600 border-green-300 bg-green-50">
813+
<div
814+
data-dashboard-status-dot="true"
815+
data-state="running"
816+
className="h-3 w-3 rounded-full bg-green-500 animate-pulse"
817+
/>
818+
<Badge
819+
data-dashboard-status-badge="true"
820+
data-state="running"
821+
variant="outline"
822+
className="whitespace-nowrap text-green-600 border-green-300 bg-green-50"
823+
>
801824
<CheckCircle2 className="h-3 w-3 mr-1" />
802825
{t('home.botStatus.running')}
803826
</Badge>
804827
</>
805828
) : botStatus ? (
806829
<>
807-
<div className="h-3 w-3 rounded-full bg-red-500" />
808-
<Badge variant="outline" className="whitespace-nowrap text-red-600 border-red-300 bg-red-50">
830+
<div
831+
data-dashboard-status-dot="true"
832+
data-state="stopped"
833+
className="h-3 w-3 rounded-full bg-red-500"
834+
/>
835+
<Badge
836+
data-dashboard-status-badge="true"
837+
data-state="stopped"
838+
variant="outline"
839+
className="whitespace-nowrap text-red-600 border-red-300 bg-red-50"
840+
>
809841
<AlertCircle className="h-3 w-3 mr-1" />
810842
{t('home.botStatus.stopped')}
811843
</Badge>
812844
</>
813845
) : (
814846
<>
815-
<div className="h-3 w-3 rounded-full bg-muted-foreground/40" />
816-
<Badge variant="outline" className="whitespace-nowrap text-muted-foreground">
847+
<div
848+
data-dashboard-status-dot="true"
849+
data-state="unknown"
850+
className="h-3 w-3 rounded-full bg-muted-foreground/40"
851+
/>
852+
<Badge
853+
data-dashboard-status-badge="true"
854+
data-state="unknown"
855+
variant="outline"
856+
className="whitespace-nowrap text-muted-foreground"
857+
>
817858
<AlertCircle className="h-3 w-3 mr-1" />
818859
未知
819860
</Badge>

0 commit comments

Comments
 (0)