Compare commits
1
Commits
cd350ef526
...
747a6405d0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
747a6405d0 |
+22
-15
@@ -42,9 +42,11 @@ Page({
|
|||||||
scrollToMessage: '',
|
scrollToMessage: '',
|
||||||
// 语音识别:点麦克风开录、图标转为录音态,识别文本实时回填输入框;
|
// 语音识别:点麦克风开录、图标转为录音态,识别文本实时回填输入框;
|
||||||
// 再点一次结束,定稿后直接发送(语音场景不需要用户再点一次发送键)。
|
// 再点一次结束,定稿后直接发送(语音场景不需要用户再点一次发送键)。
|
||||||
// 图片走另一条路:选完即上屏,识别结果直接作为 AI 回复
|
// 图片走另一条路:选完即上屏,OCR 后自动让 agent 整理成 markdown 再展示。
|
||||||
|
// 图片与语音的识别/等待阶段都用 isTyping 在 AI 回复区给出等待气泡。
|
||||||
recording: false,
|
recording: false,
|
||||||
recordTime: '00:00',
|
recordTime: '00:00',
|
||||||
|
// 语音定稿期间的互斥状态:阻止再次录音/发送,底部状态条只在 recording 时显示
|
||||||
isRecognizing: false,
|
isRecognizing: false,
|
||||||
// 实时链路不可用(供应商失败 / 分片格式无法解码)时置 true:
|
// 实时链路不可用(供应商失败 / 分片格式无法解码)时置 true:
|
||||||
// 状态条补一句「结束后整段转写」,避免用户以为没有识别
|
// 状态条补一句「结束后整段转写」,避免用户以为没有识别
|
||||||
@@ -714,12 +716,14 @@ Page({
|
|||||||
}).catch(() => this.failVoiceStream('语音识别连接中断,请重试'))
|
}).catch(() => this.failVoiceStream('语音识别连接中断,请重试'))
|
||||||
},
|
},
|
||||||
|
|
||||||
// 再次点麦克风 = 结束录音:停止采集并让服务端定稿,定稿后直接发出
|
// 再次点麦克风 = 结束录音:停止采集并让服务端定稿,定稿后直接发出。
|
||||||
|
// 识别期间不再显示底部状态条,改用 AI 回复区的等待气泡(isTyping)
|
||||||
stopVoiceInput() {
|
stopVoiceInput() {
|
||||||
if (!this.data.recording) return
|
if (!this.data.recording) return
|
||||||
|
|
||||||
this.clearRecordTimer()
|
this.clearRecordTimer()
|
||||||
this.setData({ recording: false, recordTime: '00:00', isRecognizing: true })
|
this.setData({ recording: false, recordTime: '00:00', isRecognizing: true, isTyping: true })
|
||||||
|
this.scrollToBottom()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.recorderManager.stop()
|
this.recorderManager.stop()
|
||||||
@@ -822,7 +826,8 @@ Page({
|
|||||||
stream.stopSent = true
|
stream.stopSent = true
|
||||||
stream.socket.send({ type: 'asr_cancel', id: stream.id }).catch(() => {})
|
stream.socket.send({ type: 'asr_cancel', id: stream.id }).catch(() => {})
|
||||||
|
|
||||||
this.setData({ recording: false, recordTime: '00:00', isRecognizing: true })
|
this.setData({ recording: false, recordTime: '00:00', isRecognizing: true, isTyping: true })
|
||||||
|
this.scrollToBottom()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const filePath = await this.waitRecordFile(2500)
|
const filePath = await this.waitRecordFile(2500)
|
||||||
@@ -1004,6 +1009,9 @@ Page({
|
|||||||
recording: false,
|
recording: false,
|
||||||
recordTime: '00:00',
|
recordTime: '00:00',
|
||||||
isRecognizing: false,
|
isRecognizing: false,
|
||||||
|
// 识别失败/取消时收起 AI 回复区的等待气泡;
|
||||||
|
// 正常定稿会紧接着走 dispatchMessage,那里会重新置为 true
|
||||||
|
isTyping: false,
|
||||||
voiceRealtimeOff: false,
|
voiceRealtimeOff: false,
|
||||||
...(keepText ? {} : { inputValue: base })
|
...(keepText ? {} : { inputValue: base })
|
||||||
})
|
})
|
||||||
@@ -1062,8 +1070,8 @@ Page({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 先上屏再识别:识别期间用户看到的是自己发的那张图和 AI 等待动画,
|
// 先上屏再识别:识别期间只保留 AI 回复区的等待动画(isTyping),
|
||||||
// 而不是一层盖住会话的 loading
|
// 不再额外弹「正在识别并发送…」的状态条,避免同一件事出现两个提示
|
||||||
sendImageMessage(file) {
|
sendImageMessage(file) {
|
||||||
const userMessage = {
|
const userMessage = {
|
||||||
id: this.createMessageId(),
|
id: this.createMessageId(),
|
||||||
@@ -1079,8 +1087,7 @@ Page({
|
|||||||
this.beginRequest(requestId, userMessage.id, 'image')
|
this.beginRequest(requestId, userMessage.id, 'image')
|
||||||
this.setData({
|
this.setData({
|
||||||
messages,
|
messages,
|
||||||
isTyping: true,
|
isTyping: true
|
||||||
isRecognizing: true
|
|
||||||
})
|
})
|
||||||
this.saveChatHistory(messages)
|
this.saveChatHistory(messages)
|
||||||
this.scrollToBottom()
|
this.scrollToBottom()
|
||||||
@@ -1130,7 +1137,7 @@ Page({
|
|||||||
// request 层已尝试静默重登,仍回 401 说明本地 token 确实失效:
|
// request 层已尝试静默重登,仍回 401 说明本地 token 确实失效:
|
||||||
// 走登录提示(图片消息置为 blocked,不挂重试,避免反复失败)
|
// 走登录提示(图片消息置为 blocked,不挂重试,避免反复失败)
|
||||||
if (reply && reply.code === 401) {
|
if (reply && reply.code === 401) {
|
||||||
this.setData({ isLoggedIn: false, isRecognizing: false })
|
this.setData({ isLoggedIn: false })
|
||||||
this.handleLoginRequired('登录状态已失效,请重新登录后再试', false)
|
this.handleLoginRequired('登录状态已失效,请重新登录后再试', false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1149,7 +1156,7 @@ Page({
|
|||||||
const imageMessageId = this.activeUserMessageId
|
const imageMessageId = this.activeUserMessageId
|
||||||
const requestId = this.createMessageId('req')
|
const requestId = this.createMessageId('req')
|
||||||
this.beginRequest(requestId, imageMessageId, 'chat')
|
this.beginRequest(requestId, imageMessageId, 'chat')
|
||||||
this.setData({ isRecognizing: false, isTyping: true })
|
this.setData({ isTyping: true })
|
||||||
this.scrollToBottom()
|
this.scrollToBottom()
|
||||||
this.sendToAI(`${OCR_FORMAT_PROMPT}${text}`, 'chat', requestId)
|
this.sendToAI(`${OCR_FORMAT_PROMPT}${text}`, 'chat', requestId)
|
||||||
},
|
},
|
||||||
@@ -1161,7 +1168,7 @@ Page({
|
|||||||
? '图片识别失败,请检查网络后重试'
|
? '图片识别失败,请检查网络后重试'
|
||||||
: (raw || '图片识别失败,请稍后重试')
|
: (raw || '图片识别失败,请稍后重试')
|
||||||
|
|
||||||
this.setData({ isRecognizing: false, isTyping: false })
|
this.setData({ isTyping: false })
|
||||||
this.handleAIError(friendly)
|
this.handleAIError(friendly)
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1320,7 +1327,7 @@ Page({
|
|||||||
item.id === message.id ? { ...item, status: '' } : item
|
item.id === message.id ? { ...item, status: '' } : item
|
||||||
))
|
))
|
||||||
this.beginRequest(requestId, message.id, 'image')
|
this.beginRequest(requestId, message.id, 'image')
|
||||||
this.setData({ messages, isTyping: true, isRecognizing: true })
|
this.setData({ messages, isTyping: true })
|
||||||
this.saveChatHistory(messages)
|
this.saveChatHistory(messages)
|
||||||
this.scrollToBottom()
|
this.scrollToBottom()
|
||||||
|
|
||||||
@@ -1419,11 +1426,11 @@ Page({
|
|||||||
scrollToBottom() {
|
scrollToBottom() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const lastMessage = this.data.messages[this.data.messages.length - 1]
|
const lastMessage = this.data.messages[this.data.messages.length - 1]
|
||||||
if (lastMessage) {
|
if (!lastMessage) return
|
||||||
this.setData({
|
this.setData({
|
||||||
scrollToMessage: `msg-${lastMessage.id}`
|
// 等待动画在消息列表之后,正在等待时直接滚到它,避免长会话里看不到反馈
|
||||||
|
scrollToMessage: this.data.isTyping ? 'msg-typing' : `msg-${lastMessage.id}`
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}, 100)
|
}, 100)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -115,8 +115,8 @@
|
|||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- AI 正在输入 -->
|
<!-- AI 正在输入:图片/语音识别期间也用它作为 AI 回复区的默认等待态 -->
|
||||||
<view class="message-item ai" wx:if="{{isTyping}}">
|
<view class="message-item ai" wx:if="{{isTyping}}" id="msg-typing">
|
||||||
<view class="message-head">
|
<view class="message-head">
|
||||||
<view class="avatar">
|
<view class="avatar">
|
||||||
<image class="avatar-img" src="/images/home-ink.png" mode="aspectFit" />
|
<image class="avatar-img" src="/images/home-ink.png" mode="aspectFit" />
|
||||||
@@ -137,13 +137,13 @@
|
|||||||
<view style="height: 40rpx;"></view>
|
<view style="height: 40rpx;"></view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
|
|
||||||
<!-- 语音状态:录音 / 识别状态紧贴输入区上方一行。
|
<!-- 语音状态:只在录音阶段显示,紧贴输入区上方一行。
|
||||||
只占一行内联提示,不做浮层、不替换输入区,输入框全程可见可读 -->
|
识别/定稿阶段不再出现底部提示条,统一由 AI 回复区的等待气泡承载,
|
||||||
<view class="voice-status" wx:if="{{recording || isRecognizing}}">
|
与图片识别保持同一种反馈 -->
|
||||||
<view class="voice-dot {{recording ? 'recording' : 'recognizing'}}"></view>
|
<view class="voice-status" wx:if="{{recording}}">
|
||||||
<text class="voice-status-text" wx:if="{{recording}}">正在录音 {{recordTime}},再次点击麦克风结束并发送</text>
|
<view class="voice-dot recording"></view>
|
||||||
<text class="voice-status-text" wx:else>正在识别并发送…</text>
|
<text class="voice-status-text">正在录音 {{recordTime}},再次点击麦克风结束并发送</text>
|
||||||
<text class="voice-status-sub" wx:if="{{recording && voiceRealtimeOff}}">结束后整段转写</text>
|
<text class="voice-status-sub" wx:if="{{voiceRealtimeOff}}">结束后整段转写</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 输入区:整行让给文字输入 + 右侧发送。
|
<!-- 输入区:整行让给文字输入 + 右侧发送。
|
||||||
|
|||||||
+2
-16
@@ -545,8 +545,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ===== 语音 / 识别状态条 ===== */
|
/* ===== 语音 / 识别状态条 ===== */
|
||||||
/* 一行内联提示,贴在输入区上沿:不盖住输入框、不替换输入框,
|
/* 一行内联提示,贴在输入区上沿:不盖住输入框、不替换输入框。
|
||||||
录音与识别阶段都在这里说明"现在处于什么状态、下一步做什么" */
|
只在录音阶段说明"现在在录音、下一步怎么结束";识别阶段改用 AI 回复区等待气泡 */
|
||||||
.voice-status {
|
.voice-status {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -571,11 +571,6 @@
|
|||||||
animation: record-pulse 1.2s infinite ease-in-out;
|
animation: record-pulse 1.2s infinite ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 识别阶段不是采集,用慢速呼吸代替录音的脉冲,避免误以为还在录 */
|
|
||||||
.voice-dot.recognizing {
|
|
||||||
animation: voice-dot-soft 1.6s infinite ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voice-status-text {
|
.voice-status-text {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
@@ -601,15 +596,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes voice-dot-soft {
|
|
||||||
0%, 100% {
|
|
||||||
opacity: 0.35;
|
|
||||||
}
|
|
||||||
50% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 发送按钮:默认浅橙底 + 描边,有内容时转实心暖橙(全页唯一的实心橙块)。
|
/* 发送按钮:默认浅橙底 + 描边,有内容时转实心暖橙(全页唯一的实心橙块)。
|
||||||
默认态落在白面输入区上,浅橙底同样靠 --brand-line 描边托形。
|
默认态落在白面输入区上,浅橙底同样靠 --brand-line 描边托形。
|
||||||
圆角由正圆(50%)改为 20rpx,与左侧输入框、上方气泡同档,成对出现 */
|
圆角由正圆(50%)改为 20rpx,与左侧输入框、上方气泡同档,成对出现 */
|
||||||
|
|||||||
Reference in New Issue
Block a user