Skip to content

Commit f965fce

Browse files
committed
优化无思考过程的UI
1 parent cc0abfa commit f965fce

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

app/components/markdown.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ const ThinkCollapse = styled(
3434
({ title, children, className }: ThinkCollapseProps) => {
3535
// 如果是 Thinking 状态,默认展开,否则折叠
3636
const defaultActive = title === Locale.NewChat.Thinking ? ["1"] : [];
37+
// 如果是 NoThink 状态,禁用
38+
const disabled = title === Locale.NewChat.NoThink;
3739
const [activeKeys, setActiveKeys] = useState(defaultActive);
3840

39-
// 当标题从 Thinking 变为 Think 时自动折叠
41+
// 当标题从 Thinking 变为 Think 或 NoThink 时自动折叠
4042
useEffect(() => {
41-
if (title === Locale.NewChat.Think) {
43+
if (title === Locale.NewChat.Think || title === Locale.NewChat.NoThink) {
4244
setActiveKeys([]);
4345
} else if (title === Locale.NewChat.Thinking) {
4446
setActiveKeys(["1"]);
@@ -47,10 +49,10 @@ const ThinkCollapse = styled(
4749

4850
return (
4951
<Collapse
50-
className={className}
52+
className={`${className} ${disabled ? "disabled" : ""}`}
5153
size="small"
5254
activeKey={activeKeys}
53-
onChange={(keys) => setActiveKeys(keys as string[])}
55+
onChange={(keys) => !disabled && setActiveKeys(keys as string[])}
5456
bordered={false}
5557
>
5658
<Panel header={title} key="1">
@@ -91,6 +93,18 @@ const ThinkCollapse = styled(
9193
opacity: 0.8;
9294
}
9395
}
96+
97+
&.disabled {
98+
opacity: 0.9;
99+
pointer-events: none;
100+
.ant-collapse-item {
101+
border: none !important;
102+
background-color: transparent !important;
103+
}
104+
.ant-collapse-header {
105+
padding: 6px 0px !important;
106+
}
107+
}
94108
`;
95109

96110
function Details(props: { children: React.ReactNode }) {
@@ -435,6 +449,10 @@ function formatThinkText(text: string): string {
435449
const pattern = /^<think>([\s\S]*?)<\/think>/;
436450
return text.replace(pattern, (match, thinkContent) => {
437451
// 渲染为"思考完成"状态
452+
// 如果 thinkContent 为空,则渲染为"没有思考过程"状态
453+
if (thinkContent.trim() === "") {
454+
return `<thinkcollapse title="${Locale.NewChat.NoThink}">\n</thinkcollapse>`;
455+
}
438456
return `<thinkcollapse title="${Locale.NewChat.Think}">\n${thinkContent}\n</thinkcollapse>`;
439457
});
440458
}

app/locales/cn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ const cn = {
608608
Less: "折叠代码",
609609
Thinking: "正在思考中...",
610610
Think: "思考过程",
611+
NoThink: "没有思考过程",
611612
ArtifactsInfo:
612613
"可在设置中开启/关闭“Artifacts 预览”和“代码折叠”,若预览失败请刷新页面",
613614
},

app/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ const en: LocaleType = {
618618
ConfirmNoShow: "Confirm to disable?You can enable it in settings later.",
619619
Thinking: "Thinking...",
620620
Think: "Content of Thought",
621+
NoThink: "No Thought",
621622
ArtifactsInfo:
622623
"You can enable/disable 'Artifacts Preview' and 'Code Fold' in settings. If the preview fails, please refresh the page.",
623624
},

0 commit comments

Comments
 (0)