Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
091c7fb9
Commit
091c7fb9
authored
Dec 15, 2025
by
水玉婷
Browse files
feat:思考添加标识及时间
parent
0d0faeb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/views/components/AiChat.vue
View file @
091c7fb9
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<div
class=
"intro-content"
>
<div
class=
"intro-content"
>
<img
:src=
"defaultAvatar"
alt=
"avatar"
class=
"avatar-image"
/>
<img
:src=
"defaultAvatar"
alt=
"avatar"
class=
"avatar-image"
/>
<h3>
嗨,我是国械小智
</h3>
<h3>
嗨,我是国械小智
</h3>
<p>
可以
问我公司经营情况、制度等相关问题,
<br>
我还在成长中,会不断强大
</p>
<p>
我
可以
帮您搜索数据、查找流程制度,
<br/>
请把问题交给我吧
</p>
</div>
</div>
</div>
</div>
...
...
src/views/components/style.less
View file @
091c7fb9
...
@@ -306,6 +306,11 @@ li {
...
@@ -306,6 +306,11 @@ li {
font-size: 14px;
font-size: 14px;
}
}
// 思考消息样式
:deep(.think-message) {
color: @gray-5;
}
// 思考框样式
// 思考框样式
.think-box-wrapper {
.think-box-wrapper {
margin: 12px 0;
margin: 12px 0;
...
...
src/views/components/utils/contentTemplateService.ts
View file @
091c7fb9
...
@@ -62,9 +62,11 @@ export interface TemplateProcessResult {
...
@@ -62,9 +62,11 @@ export interface TemplateProcessResult {
// 内容模板服务类
// 内容模板服务类
export
class
ContentTemplateService
{
export
class
ContentTemplateService
{
private
templates
:
ContentTemplates
;
private
templates
:
ContentTemplates
;
private
thinkingStartTime
:
number
|
null
;
// 新增:思考开始时间
constructor
()
{
constructor
()
{
this
.
templates
=
this
.
createTemplates
();
this
.
templates
=
this
.
createTemplates
();
this
.
thinkingStartTime
=
null
;
// 初始化思考开始时间
}
}
// 创建内容模板生成器
// 创建内容模板生成器
...
@@ -209,6 +211,51 @@ export class ContentTemplateService {
...
@@ -209,6 +211,51 @@ export class ContentTemplateService {
// 根据是否为历史数据设置默认展开状态
// 根据是否为历史数据设置默认展开状态
const
defaultThinkBoxExpanded
=
!
isHistoryData
;
const
defaultThinkBoxExpanded
=
!
isHistoryData
;
// 检查是否是"正在思考中....."消息(仅当状态为0且类型为0时)
const
isThinkingMessage
=
contentStatus
===
0
&&
contentType
===
0
&&
typeof
messageContent
===
'
string
'
&&
messageContent
.
includes
(
'
正在思考中.....
'
);
// 跟踪思考状态的变量
let
isCurrentlyThinking
=
updatedResponse
&&
updatedResponse
.
contentBlocks
.
length
>
0
&&
updatedResponse
.
contentBlocks
.
some
(
block
=>
block
.
content
.
includes
(
'
think-message
'
));
// 处理思考开始时间(基于"正在思考中....."文本的出现)
if
(
isThinkingMessage
&&
!
this
.
thinkingStartTime
)
{
// 思考开始,记录开始时间
this
.
thinkingStartTime
=
Date
.
now
();
}
// 检查是否是思考完成的消息("正在思考中....."文本消失)
const
isThinkingComplete
=
contentStatus
===
0
&&
contentType
===
0
&&
!
isThinkingMessage
&&
this
.
thinkingStartTime
;
// 处理思考完成状态(在所有状态分支之前处理)
if
(
isThinkingComplete
)
{
// 如果思考完成,更新所有包含"正在思考中....."的消息
if
(
updatedResponse
&&
updatedResponse
.
contentBlocks
.
length
>
0
)
{
let
thinkingTimeText
=
''
;
// 计算思考用时
if
(
this
.
thinkingStartTime
)
{
const
thinkingEndTime
=
Date
.
now
();
const
thinkingTimeSeconds
=
Math
.
round
((
thinkingEndTime
-
this
.
thinkingStartTime
)
/
1000
);
thinkingTimeText
=
`(用时:
${
thinkingTimeSeconds
}
s)`
;
// 重置思考开始时间
this
.
thinkingStartTime
=
null
;
}
updatedResponse
.
contentBlocks
.
forEach
(
block
=>
{
// 只在包含"正在思考中....."文本的块中添加用时信息
if
(
block
.
content
&&
block
.
content
.
includes
(
'
正在思考中.....
'
))
{
block
.
content
=
block
.
content
.
replace
(
'
正在思考中.....
'
,
`已完成思考
${
thinkingTimeText
}
`
);
}
if
(
block
.
thinkContent
&&
block
.
thinkContent
.
includes
(
'
正在思考中.....
'
))
{
block
.
thinkContent
=
block
.
thinkContent
.
replace
(
'
正在思考中.....
'
,
`已完成思考
${
thinkingTimeText
}
`
);
}
});
}
}
switch
(
contentStatus
)
{
switch
(
contentStatus
)
{
case
-
1
:
// 错误信息
case
-
1
:
// 错误信息
if
(
updatedResponse
)
{
if
(
updatedResponse
)
{
...
@@ -349,6 +396,34 @@ export class ContentTemplateService {
...
@@ -349,6 +396,34 @@ export class ContentTemplateService {
updatedIsThinking
=
false
;
updatedIsThinking
=
false
;
break
;
break
;
case
0
:
// 普通内容状态
if
(
isThinkingMessage
||
isCurrentlyThinking
)
{
// 如果是思考中消息或当前处于思考状态,添加think类别
if
(
updatedResponse
)
{
updatedResponse
.
contentBlocks
.
push
({
content
:
`<div class="message-text think-message">
${
messageContent
}
</div>`
,
hasThinkBox
:
false
,
thinkContent
:
''
,
thinkBoxExpanded
:
false
,
});
// 标记为当前处于思考状态
isCurrentlyThinking
=
true
;
}
}
else
{
// 普通消息处理
if
(
updatedResponse
)
{
updatedResponse
.
contentBlocks
.
push
({
content
:
this
.
templates
.
text
(
messageContent
),
hasThinkBox
:
false
,
thinkContent
:
''
,
thinkBoxExpanded
:
false
,
});
// 普通消息结束思考状态
isCurrentlyThinking
=
false
;
}
}
break
;
case
20
:
// 初始连接回传信息
case
20
:
// 初始连接回传信息
if
(
updatedResponse
)
{
if
(
updatedResponse
)
{
updatedResponse
.
contentBlocks
.
push
({
updatedResponse
.
contentBlocks
.
push
({
...
@@ -380,6 +455,9 @@ export class ContentTemplateService {
...
@@ -380,6 +455,9 @@ export class ContentTemplateService {
}
}
updatedIsThinking
=
false
;
updatedIsThinking
=
false
;
updatedBlockIndex
=
-
1
;
updatedBlockIndex
=
-
1
;
// 会话结束时重置思考开始时间
this
.
thinkingStartTime
=
null
;
break
;
break
;
default
:
// 普通内容
default
:
// 普通内容
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment