Compare commits
11 Commits
c6271e9f4b
...
5292ede3c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5292ede3c5 | ||
|
|
af9c3c7c28 | ||
|
|
fe0a36e446 | ||
|
|
6f9f129883 | ||
|
|
65653525a0 | ||
| 6e658c9967 | |||
|
|
c46392b478 | ||
| aedc71903d | |||
| 680ac8fd38 | |||
| 6ea7cf495c | |||
| e539c7d35d |
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@ -0,0 +1,17 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
insert_final_newline = false
|
||||
@ -3,3 +3,6 @@ export const SCROLL_TO_BOTTOM = 'SCROLL_TO_BOTTOM'
|
||||
|
||||
// 推荐帖子
|
||||
export const RECOMMEND_POSTS_TITLE = 'RECOMMEND_POSTS_TITLE'
|
||||
|
||||
// 发送命令
|
||||
export const SEND_COMMAND_TEXT = 'SEND_COMMAND_TEXT'
|
||||
11
pages.json
11
pages.json
@ -13,6 +13,17 @@
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/chat/ChatMainList",
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"app-plus": {
|
||||
"softinputMode": "adjustPan",
|
||||
"bounce": "none",
|
||||
"titleNView": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/chat/ChatQuickAccess",
|
||||
"style": {
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
<template>
|
||||
<view class="area-input">
|
||||
<!-- 发送语音 -->
|
||||
<view class="input-container-voice">
|
||||
<image src='/static/input_voice_icon.png'></image>
|
||||
<!-- 语音/键盘切换 -->
|
||||
<view class="input-container-voice" @click="toggleVoiceMode">
|
||||
<image v-if="!isVoiceMode" src='/static/input_voice_icon.png'></image>
|
||||
<image v-else src='/static/input_keyboard_icon.png'></image>
|
||||
</view>
|
||||
<!-- 输入框 -->
|
||||
|
||||
<!-- 输入框/语音按钮容器 -->
|
||||
<view class="input-button-container">
|
||||
<textarea
|
||||
ref="textareaRef"
|
||||
class="textarea"
|
||||
type="text"
|
||||
:placeholder="placeholder"
|
||||
@ -13,47 +17,251 @@
|
||||
confirm-type='done'
|
||||
v-model="inputMessage"
|
||||
@confirm="sendMessage"
|
||||
@touchend="handleNoHideKeyboard"
|
||||
@focus="handleFocus"
|
||||
@blur="handleBlur"
|
||||
@touchstart="handleTouchStart"
|
||||
@touchend="handleTouchEnd"
|
||||
:confirm-hold="true"
|
||||
auto-height
|
||||
:show-confirm-bar='false'
|
||||
:hold-keyboard="holdKeyboard"
|
||||
:adjust-position="true"
|
||||
maxlength="300"
|
||||
/>
|
||||
<view class="input-container-send" @click="sendMessage">
|
||||
<image src='/static/input_send_icon.png'></image>
|
||||
|
||||
<view
|
||||
v-if="isVoiceMode"
|
||||
class="hold-to-talk-button"
|
||||
@touchstart.stop="startRecording"
|
||||
@touchend.stop="stopRecording"
|
||||
@touchmove.stop="handleTouchMove"
|
||||
>
|
||||
按住说话
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="input-container-send">
|
||||
<view v-if="!isVoiceMode" class="input-container-send-btn" @click="sendMessage">
|
||||
<image v-if="props.isSessionActive" src='/static/input_stop_icon.png'></image>
|
||||
<image v-else src='/static/input_send_icon.png'></image>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
||||
<!-- 录音界面 -->
|
||||
<uni-popup v-model:show="isRecording" position="center" :mask-click-able="false">
|
||||
<view class="recording-popup">
|
||||
<view class="recording-wave">
|
||||
<!-- 波形动画 -->
|
||||
<view class="wave-animation"></view>
|
||||
</view>
|
||||
<view class="recording-text">
|
||||
{{ isSlideToText ? '松开发送 转文字' : '松开发送' }}
|
||||
</view>
|
||||
<view class="recording-cancel">
|
||||
取消
|
||||
</view>
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
|
||||
<!-- 语音结果界面 -->
|
||||
<uni-popup v-model:show="showVoiceResult" position="center" :mask-click-able="false">
|
||||
<view class="voice-result-popup">
|
||||
<view class="voice-result-bubble">
|
||||
{{ voiceText }}
|
||||
</view>
|
||||
<view class="voice-result-actions">
|
||||
<view class="action-button cancel" @click="cancelVoice">取消</view>
|
||||
<view class="action-button voice">发送原语音</view>
|
||||
<view class="action-button send" @click="sendVoiceMessage">发送</view>
|
||||
</view>
|
||||
</view>
|
||||
</uni-popup>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref, watch, nextTick, onMounted, onUnmounted } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
inputMessage: String,
|
||||
holdKeyboard: Boolean
|
||||
holdKeyboard: Boolean,
|
||||
isSessionActive: Boolean,
|
||||
stopRequest: Function
|
||||
})
|
||||
const emit = defineEmits(['update:inputMessage', 'send', 'noHideKeyboard'])
|
||||
const emit = defineEmits(['update:inputMessage', 'send', 'noHideKeyboard', 'keyboardShow', 'keyboardHide', 'sendVoice'])
|
||||
|
||||
const textareaRef = ref(null)
|
||||
const placeholder = ref('快告诉朵朵您在想什么~')
|
||||
const inputMessage = ref(props.inputMessage || '')
|
||||
const isFocused = ref(false)
|
||||
const keyboardHeight = ref(0)
|
||||
const isVoiceMode = ref(false)
|
||||
const isRecording = ref(false)
|
||||
const recordingTime = ref(0)
|
||||
const recordingTimer = ref(null)
|
||||
const voiceText = ref('')
|
||||
const showVoiceResult = ref(false)
|
||||
const isSlideToText = ref(false)
|
||||
|
||||
|
||||
// 保持和父组件同步
|
||||
watch(() => props.inputMessage, (val) => {
|
||||
inputMessage.value = val
|
||||
})
|
||||
|
||||
const sendMessage = () => {
|
||||
if (!inputMessage.value.trim()) return;
|
||||
emit('send', inputMessage.value)
|
||||
inputMessage.value = ''
|
||||
emit('update:inputMessage', inputMessage.value)
|
||||
// 切换语音/文本模式
|
||||
const toggleVoiceMode = () => {
|
||||
isVoiceMode.value = !isVoiceMode.value
|
||||
}
|
||||
|
||||
const handleNoHideKeyboard = () => {
|
||||
// 开始录音
|
||||
const startRecording = () => {
|
||||
isRecording.value = true
|
||||
|
||||
return
|
||||
recordingTime.value = 0
|
||||
// 启动录音计时器
|
||||
recordingTimer.value = setInterval(() => {
|
||||
recordingTime.value += 1
|
||||
}, 1000)
|
||||
|
||||
// 调用uni-app录音API
|
||||
uni.startRecord({
|
||||
success: (res) => {
|
||||
// 录音成功,处理录音文件
|
||||
const tempFilePath = res.tempFilePath
|
||||
// 这里可以添加语音转文字的逻辑
|
||||
// 模拟语音转文字
|
||||
setTimeout(() => {
|
||||
voiceText.value = '这是语音转文字的结果'
|
||||
showVoiceResult.value = true
|
||||
}, 1000)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('录音失败:', err)
|
||||
isRecording.value = false
|
||||
clearInterval(recordingTimer.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 结束录音
|
||||
const stopRecording = () => {
|
||||
isRecording.value = false
|
||||
|
||||
return
|
||||
clearInterval(recordingTimer.value)
|
||||
|
||||
// 如果录音时间小于1秒,取消录音
|
||||
if (recordingTime.value < 1) {
|
||||
uni.stopRecord()
|
||||
return
|
||||
}
|
||||
|
||||
// 停止录音
|
||||
uni.stopRecord()
|
||||
}
|
||||
|
||||
// 处理滑动事件
|
||||
const handleTouchMove = (e) => {
|
||||
// 检测滑动位置,判断是否需要转文字
|
||||
// 这里只是示例逻辑,需要根据实际UI调整
|
||||
const touchY = e.touches[0].clientY
|
||||
// 假设滑动到某个位置以下转为文字
|
||||
isSlideToText.value = touchY < 200
|
||||
}
|
||||
|
||||
// 发送语音
|
||||
const sendVoiceMessage = () => {
|
||||
// 发送语音逻辑
|
||||
emit('sendVoice', {
|
||||
text: voiceText.value,
|
||||
// 可以添加语音文件路径等信息
|
||||
})
|
||||
showVoiceResult.value = false
|
||||
isVoiceMode.value = false
|
||||
}
|
||||
|
||||
// 取消语音
|
||||
const cancelVoice = () => {
|
||||
showVoiceResult.value = false
|
||||
isVoiceMode.value = false
|
||||
}
|
||||
|
||||
// 监听键盘高度变化
|
||||
onMounted(() => {
|
||||
// 监听键盘弹起
|
||||
uni.onKeyboardHeightChange((res) => {
|
||||
keyboardHeight.value = res.height
|
||||
if (res.height > 0) {
|
||||
emit('keyboardShow', res.height)
|
||||
} else {
|
||||
emit('keyboardHide')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const sendMessage = () => {
|
||||
if (props.isSessionActive) {
|
||||
// 如果会话进行中,调用停止请求函数
|
||||
if (props.stopRequest) {
|
||||
props.stopRequest();
|
||||
}
|
||||
} else {
|
||||
// 否则发送新消息
|
||||
if (!inputMessage.value.trim()) return;
|
||||
emit('send', inputMessage.value)
|
||||
|
||||
// 发送后保持焦点(可选)
|
||||
if (props.holdKeyboard && textareaRef.value) {
|
||||
nextTick(() => {
|
||||
textareaRef.value.focus()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleFocus = () => {
|
||||
isFocused.value = true
|
||||
emit('noHideKeyboard')
|
||||
}
|
||||
|
||||
const handleBlur = () => {
|
||||
isFocused.value = false
|
||||
}
|
||||
|
||||
const handleTouchStart = () => {
|
||||
emit('noHideKeyboard')
|
||||
}
|
||||
|
||||
const handleTouchEnd = () => {
|
||||
emit('noHideKeyboard')
|
||||
}
|
||||
|
||||
// 手动聚焦输入框
|
||||
const focusInput = () => {
|
||||
if (textareaRef.value) {
|
||||
textareaRef.value.focus()
|
||||
}
|
||||
}
|
||||
|
||||
// 手动失焦输入框
|
||||
const blurInput = () => {
|
||||
if (textareaRef.value) {
|
||||
textareaRef.value.blur()
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
focusInput,
|
||||
blurInput,
|
||||
isFocused,
|
||||
toggleVoiceMode
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@ -64,6 +272,8 @@ const handleNoHideKeyboard = () => {
|
||||
background-color: #FFFFFF;
|
||||
box-shadow: 0px 0px 20px 0px rgba(52,25,204,0.05);
|
||||
margin: 0 12px;
|
||||
/* 确保输入框在安全区域内 */
|
||||
margin-bottom: 8px;
|
||||
|
||||
.input-container-voice {
|
||||
display: flex;
|
||||
@ -73,6 +283,7 @@ const handleNoHideKeyboard = () => {
|
||||
height: 44px;
|
||||
flex-shrink: 0;
|
||||
align-self: flex-end;
|
||||
cursor: pointer;
|
||||
|
||||
image {
|
||||
width: 22px;
|
||||
@ -80,6 +291,26 @@ const handleNoHideKeyboard = () => {
|
||||
}
|
||||
}
|
||||
|
||||
.input-button-container {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
height: 44px;
|
||||
}
|
||||
|
||||
.hold-to-talk-button {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #333333;
|
||||
font-size: 16px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.input-container-send {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@ -89,6 +320,14 @@ const handleNoHideKeyboard = () => {
|
||||
flex-shrink: 0;
|
||||
align-self: flex-end;
|
||||
|
||||
.input-container-send-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
image {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
@ -97,12 +336,115 @@ const handleNoHideKeyboard = () => {
|
||||
|
||||
.textarea {
|
||||
flex: 1;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
max-height: 92px;
|
||||
min-height: 22px;
|
||||
min-height: 44px;
|
||||
font-size: 16px;
|
||||
line-height: 22px;
|
||||
margin-bottom: 2px;
|
||||
padding: 3px 0 0;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* 确保textarea在iOS上的样式正常 */
|
||||
.textarea::-webkit-input-placeholder {
|
||||
color: #CCCCCC;
|
||||
}
|
||||
.textarea:focus {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* 录音弹窗样式 */
|
||||
.recording-popup {
|
||||
width: 280px;
|
||||
height: 280px;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
border-radius: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.recording-wave {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
border-radius: 50%;
|
||||
background-color: rgba(76, 217, 100, 0.3);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.wave-animation {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
/* 这里可以添加波形动画 */
|
||||
background-image: url('/static/wave_icon.png');
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.recording-text {
|
||||
font-size: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.recording-cancel {
|
||||
font-size: 14px;
|
||||
color: #CCCCCC;
|
||||
}
|
||||
|
||||
/* 语音结果弹窗样式 */
|
||||
.voice-result-popup {
|
||||
width: 300px;
|
||||
background-color: white;
|
||||
border-radius: 16px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.voice-result-bubble {
|
||||
background-color: #4CD964;
|
||||
color: white;
|
||||
padding: 15px;
|
||||
border-radius: 18px;
|
||||
border-top-left-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
min-height: 60px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.voice-result-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.cancel {
|
||||
color: #666666;
|
||||
background-color: #F5F5F5;
|
||||
}
|
||||
|
||||
.voice {
|
||||
color: #007AFF;
|
||||
background-color: #E8F0FE;
|
||||
}
|
||||
|
||||
.send {
|
||||
color: white;
|
||||
background-color: #007AFF;
|
||||
}
|
||||
</style>
|
||||
@ -61,10 +61,15 @@
|
||||
<view class="footer-area">
|
||||
<ChatQuickAccess @replySent="handleReplyInstruct"/>
|
||||
<ChatInputArea
|
||||
ref="inputAreaRef"
|
||||
v-model="inputMessage"
|
||||
:holdKeyboard="holdKeyboard"
|
||||
:is-session-active="isSessionActive"
|
||||
:stop-request="stopRequest"
|
||||
@send="sendMessageAction"
|
||||
@noHideKeyboard="handleNoHideKeyboard"
|
||||
@keyboardShow="handleKeyboardShow"
|
||||
@keyboardHide="handleKeyboardHide"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
@ -72,11 +77,11 @@
|
||||
</template>
|
||||
|
||||
<script setup >
|
||||
import { onMounted, nextTick } from 'vue'
|
||||
import { onMounted, nextTick, computed } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { defineEmits } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { SCROLL_TO_BOTTOM, RECOMMEND_POSTS_TITLE } from '@/constant/constant'
|
||||
import { SCROLL_TO_BOTTOM, RECOMMEND_POSTS_TITLE, SEND_COMMAND_TEXT } from '@/constant/constant'
|
||||
import { MessageRole, MessageType, CompName } from '../../model/ChatModel';
|
||||
|
||||
import ChatTopWelcome from './ChatTopWelcome.vue';
|
||||
@ -106,12 +111,18 @@
|
||||
|
||||
/// 导航栏相关
|
||||
const statusBarHeight = ref(20);
|
||||
/// 输入框组件引用
|
||||
const inputAreaRef = ref(null);
|
||||
|
||||
const timer = ref(null)
|
||||
/// focus时,点击页面的时候不收起键盘
|
||||
const holdKeyboard = ref(false)
|
||||
/// 是否在键盘弹出,点击界面时关闭键盘
|
||||
const holdKeyboardFlag = ref(true)
|
||||
/// 键盘高度
|
||||
const keyboardHeight = ref(0)
|
||||
/// 是否显示键盘
|
||||
const isKeyboardShow = ref(false)
|
||||
|
||||
///(控制滚动位置)
|
||||
const scrollTop = ref(99999);
|
||||
@ -120,6 +131,8 @@
|
||||
const chatMsgList = ref([])
|
||||
/// 输入口的输入消息
|
||||
const inputMessage = ref('')
|
||||
/// 加载中
|
||||
let currentAIMsgIndex = 0
|
||||
|
||||
/// 从个渠道获取如二维,没有的时候就返回首页的数据
|
||||
const sceneId = ref('')
|
||||
@ -131,11 +144,15 @@
|
||||
const mainPageDataModel = ref({})
|
||||
|
||||
// 会话进行中标志
|
||||
let isSessionActive = false;
|
||||
const isSessionActive = ref(false);
|
||||
// 请求任务引用
|
||||
const requestTaskRef = ref(null);
|
||||
/// 指令
|
||||
let commonType = ''
|
||||
|
||||
|
||||
|
||||
|
||||
// 打开抽屉
|
||||
const emits = defineEmits(['openDrawer'])
|
||||
const openDrawer = () => {
|
||||
@ -144,23 +161,37 @@
|
||||
}
|
||||
|
||||
const handleTouchEnd = () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
clearTimeout(timer.value)
|
||||
timer.value = setTimeout(() => {
|
||||
// 键盘弹出时点击界面则关闭键盘
|
||||
if (handleNoHideKeyboard) {
|
||||
if (holdKeyboardFlag.value && isKeyboardShow.value) {
|
||||
uni.hideKeyboard()
|
||||
}
|
||||
holdKeyboardFlag.value = true
|
||||
}, 50)
|
||||
// #endif
|
||||
}, 100)
|
||||
}
|
||||
|
||||
// 点击输入框、发送按钮时,不收键盘
|
||||
const handleNoHideKeyboard = () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
holdKeyboardFlag.value = false
|
||||
// #endif
|
||||
}
|
||||
|
||||
// 键盘弹起事件
|
||||
const handleKeyboardShow = (height) => {
|
||||
keyboardHeight.value = height
|
||||
isKeyboardShow.value = true
|
||||
holdKeyboard.value = true
|
||||
// 键盘弹起时调整聊天内容的底部边距并滚动到底部
|
||||
setTimeout(() => {
|
||||
scrollToBottom()
|
||||
}, 150)
|
||||
}
|
||||
|
||||
// 键盘收起事件
|
||||
const handleKeyboardHide = () => {
|
||||
keyboardHeight.value = 0
|
||||
isKeyboardShow.value = false
|
||||
holdKeyboard.value = false
|
||||
}
|
||||
|
||||
/// 滚动到底部
|
||||
@ -204,8 +235,11 @@
|
||||
if (!inputText.trim()) return;
|
||||
handleNoHideKeyboard()
|
||||
sendMessage(inputText)
|
||||
if(!isSessionActive) {
|
||||
inputMessage.value = ''
|
||||
// 发送消息后保持键盘状态
|
||||
if (holdKeyboard.value && inputAreaRef.value) {
|
||||
setTimeout(() => {
|
||||
inputAreaRef.value.focusInput()
|
||||
}, 100)
|
||||
}
|
||||
setTimeoutScrollToBottom()
|
||||
}
|
||||
@ -238,6 +272,15 @@
|
||||
handleReply(value)
|
||||
}
|
||||
})
|
||||
|
||||
uni.$on(SEND_COMMAND_TEXT, (value) => {
|
||||
console.log('SEND_COMMAND_TEXT:', value)
|
||||
if(value && value.length > 0) {
|
||||
commonType = 'Command.quickBooking'
|
||||
sendMessage(value, true)
|
||||
setTimeoutScrollToBottom()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// 获取最近一次的会话id
|
||||
@ -279,14 +322,14 @@
|
||||
|
||||
/// 发送消息的参数拼接
|
||||
const sendMessage = (message, isInstruct = false) => {
|
||||
if (isSessionActive) {
|
||||
if (isSessionActive.value) {
|
||||
uni.showToast({
|
||||
title: '请等待当前回复完成',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
isSessionActive = true;
|
||||
isSessionActive.value = true;
|
||||
const newMsg = {
|
||||
msgId: `msg_${chatMsgList.value.length}`,
|
||||
msgType: MessageRole.ME,
|
||||
@ -297,6 +340,7 @@
|
||||
}
|
||||
}
|
||||
chatMsgList.value.push(newMsg)
|
||||
inputMessage.value = '';
|
||||
sendChat(message, isInstruct)
|
||||
console.log("发送的新消息:",JSON.stringify(newMsg))
|
||||
}
|
||||
@ -328,6 +372,7 @@
|
||||
}
|
||||
chatMsgList.value.push(aiMsg)
|
||||
const aiMsgIndex = chatMsgList.value.length - 1
|
||||
currentAIMsgIndex = aiMsgIndex
|
||||
|
||||
// 动态加载中动画
|
||||
let dotCount = 1;
|
||||
@ -345,7 +390,7 @@
|
||||
}
|
||||
|
||||
// 流式接收内容
|
||||
agentChatStream(args, (chunk) => {
|
||||
const { promise, requestTask } = agentChatStream(args, (chunk) => {
|
||||
console.log('分段内容:', chunk)
|
||||
if (chunk && chunk.error) {
|
||||
chatMsgList.value[aiMsgIndex].msg = '请求错误,请重试';
|
||||
@ -353,7 +398,7 @@
|
||||
loadingTimer = null;
|
||||
isTyping = false;
|
||||
typeWriterTimer = null;
|
||||
isSessionActive = false; // 出错也允许再次发送
|
||||
isSessionActive.value = false; // 出错也允许再次发送
|
||||
console.error('流式错误:', chunk.message, chunk.detail);
|
||||
return;
|
||||
}
|
||||
@ -404,14 +449,22 @@
|
||||
chatMsgList.value[aiMsgIndex].question = chunk.question
|
||||
}
|
||||
|
||||
isSessionActive = false;
|
||||
isSessionActive.value = false;
|
||||
scrollToBottom();
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}).catch(e => {
|
||||
isSessionActive = false; // 出错也允许再次发送
|
||||
console.log('error:', e)
|
||||
})
|
||||
|
||||
// 存储请求任务
|
||||
requestTaskRef.value = requestTask;
|
||||
|
||||
// 可选:处理Promise完成/失败, 已经在回调中处理数据,此处无需再处理
|
||||
promise.then(data => {
|
||||
console.log('请求完成');
|
||||
}).catch(err => {
|
||||
isSessionActive.value = false; // 出错也允许再次发送
|
||||
console.log('error:', err);
|
||||
});
|
||||
|
||||
// 打字机函数
|
||||
@ -432,6 +485,34 @@
|
||||
}
|
||||
|
||||
|
||||
// 停止请求函数
|
||||
const stopRequest = () => {
|
||||
if (requestTaskRef.value && requestTaskRef.value.abort) {
|
||||
// 标记请求已中止,用于过滤后续可能到达的数据
|
||||
requestTaskRef.value.isAborted = true;
|
||||
// 中止请求
|
||||
requestTaskRef.value.abort();
|
||||
// 重置状态
|
||||
isSessionActive.value = false;
|
||||
const msg = chatMsgList.value[currentAIMsgIndex].msg;
|
||||
if (!msg || msg === '加载中.' || msg.startsWith('加载中')) {
|
||||
chatMsgList.value[currentAIMsgIndex].msg = '已终止请求,请重试';
|
||||
}
|
||||
// 清除计时器
|
||||
if (loadingTimer) {
|
||||
clearInterval(loadingTimer);
|
||||
loadingTimer = null;
|
||||
}
|
||||
if (typeWriterTimer) {
|
||||
clearTimeout(typeWriterTimer);
|
||||
typeWriterTimer = null;
|
||||
}
|
||||
setTimeoutScrollToBottom()
|
||||
// 清空请求引用
|
||||
requestTaskRef.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
flex-direction: column;
|
||||
overflow: hidden !important;
|
||||
position: relative;
|
||||
/* 确保在键盘弹起时布局正确 */
|
||||
box-sizing: border-box;
|
||||
|
||||
.chat-container-bg {
|
||||
position: fixed;
|
||||
@ -20,12 +22,10 @@
|
||||
|
||||
.chat-content {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
@ -77,13 +77,19 @@
|
||||
.footer-area {
|
||||
width: 100vw;
|
||||
flex-shrink: 0;
|
||||
padding: 4px 0 24px 0;
|
||||
padding: 4px 0 20px 0; /* 直接设置20px底部安全距离 */
|
||||
background-color: #E9F3F7;
|
||||
touch-action: pan-x; /* 仅允许横向触摸滚动 */
|
||||
overflow-x: auto; /* 允许横向滚动 */
|
||||
overflow-y: hidden; /* 禁止垂直滚动 */
|
||||
/* 确保高度能够正确计算 */
|
||||
touch-action: pan-x;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
min-height: fit-content;
|
||||
/* 安卓键盘适配 - 使用相对定位配合adjustPan */
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
transition: padding-bottom 0.3s ease;
|
||||
/* 确保输入区域始终可见 */
|
||||
transform: translateZ(0);
|
||||
-webkit-transform: translateZ(0);
|
||||
}
|
||||
|
||||
.area-input {
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 底部退出按钮 -->
|
||||
<button class="logout-btn" @click="handleLogout">退出登录</button>
|
||||
<text class="logout-btn" @click="handleLogout">退出登录</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -140,8 +140,11 @@ const handleLogout = () => {
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 90%;
|
||||
margin: 80rpx auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 42px;
|
||||
margin-top: 40px;
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
border-radius: 8rpx;
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
:interval="interval"
|
||||
:duration="duration">
|
||||
<swiper-item v-for="item in activityList" :key="item.id">
|
||||
<view class="swiper-item">
|
||||
<view class="swiper-item" @click="handleClick(item)">
|
||||
<image :src="item.activityCover" mode="aspectFill"></image>
|
||||
<view class="corner-btn">快速预定</view>
|
||||
</view>
|
||||
@ -20,6 +20,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { SEND_COMMAND_TEXT } from '@/constant/constant'
|
||||
|
||||
const autoplay = ref(true)
|
||||
const interval = ref(3000)
|
||||
@ -32,6 +33,10 @@
|
||||
}
|
||||
})
|
||||
|
||||
const handleClick = (item) => {
|
||||
uni.$emit(SEND_COMMAND_TEXT, '快速预定')
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@ -3,18 +3,18 @@
|
||||
<ModuleTitle :title="commodityDTO.title" />
|
||||
<view class="container-scroll">
|
||||
<view class="mk-card-item" v-for="(item) in commodityDTO.commodityList" :key="item.commodityName">
|
||||
<view class="card-badge">超值推荐</view>
|
||||
<image class="card-img" :src="item.commodityIcon" mode="widthFix" />
|
||||
<!-- <view class="card-badge">超值推荐</view> -->
|
||||
<image class="card-img" :src="item.commodityIcon" mode="aspectFill" />
|
||||
<view class="card-content">
|
||||
<view class="card-title-column">
|
||||
<text class="card-title">{{ item.commodityName }}</text>
|
||||
<view class="card-tags">
|
||||
<text class="card-tag">随时可退</text>
|
||||
<text class="card-tag">民俗表演</text>
|
||||
<view class="card-tags" v-for="(tag) in item.commodityTradeRuleList" :key="tag">
|
||||
<text class="card-tag">{{ tag }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="card-desc">· 往返观光车票</view>
|
||||
<view class="card-desc">· 营业时间:9:00-22:00</view>
|
||||
<template v-for="(serviceItem, index) in item.commodityServices" :key="serviceItem.serviceTitle">
|
||||
<view v-if="index < 3" class="card-desc">· {{ serviceItem.serviceTitle }}</view>
|
||||
</template>
|
||||
<view class="card-bottom-row">
|
||||
<view class="card-price-row">
|
||||
<text class="card-price-fu">¥</text>
|
||||
@ -72,7 +72,7 @@
|
||||
flex-direction: column;
|
||||
align-items: start;
|
||||
width: 188px;
|
||||
height: 244px;
|
||||
// height: 244px;
|
||||
background-color: #ffffff;
|
||||
border-radius: 10px;
|
||||
margin-right: 8px;
|
||||
@ -94,6 +94,8 @@
|
||||
width: 188px;
|
||||
height: 114px;
|
||||
border-radius: 10px;
|
||||
object-fit: cover; /* 确保图片不变形,保持比例裁剪 */
|
||||
flex-shrink: 0; /* 防止图片被压缩 */
|
||||
}
|
||||
|
||||
.card-content {
|
||||
@ -101,20 +103,33 @@
|
||||
padding: 10px 12px 0 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
align-items: start;
|
||||
width: 100%;
|
||||
flex: 1; /* 让内容区域占据剩余空间 */
|
||||
overflow: hidden; /* 防止内容溢出 */
|
||||
}
|
||||
|
||||
.card-title-column {
|
||||
display: flex;
|
||||
align-items: start;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #222;
|
||||
width: 100%;
|
||||
/* 限制标题最多显示两行 */
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1.4;
|
||||
max-height: 2.8em; /* 2行的高度 */
|
||||
}
|
||||
|
||||
.card-tags {
|
||||
|
||||
@ -7,16 +7,17 @@ const API = '/agent/assistant/chat';
|
||||
* 获取AI聊天流式信息(仅微信小程序支持)
|
||||
* @param {Object} params 请求参数
|
||||
* @param {Function} onChunk 回调,每收到一段数据触发
|
||||
* @returns {Promise}
|
||||
* @returns {Object} 包含Promise和requestTask的对象
|
||||
*/
|
||||
function agentChatStream(params, onChunk) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let requestTask;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const token = uni.getStorageSync('token');
|
||||
let hasError = false;
|
||||
|
||||
console.log("发送请求内容: ", params)
|
||||
// #ifdef MP-WEIXIN
|
||||
const requestTask = uni.request({
|
||||
requestTask = uni.request({
|
||||
url: BASE_URL + API, // 替换为你的接口地址
|
||||
method: 'POST',
|
||||
data: params,
|
||||
@ -37,7 +38,6 @@ function agentChatStream(params, onChunk) {
|
||||
complete(res) {
|
||||
if(res.statusCode !== 200) {
|
||||
console.log("====> ", JSON.stringify(res))
|
||||
|
||||
if (onChunk) {
|
||||
onChunk({ error: true, message: '服务器错误', detail: res });
|
||||
}
|
||||
@ -59,11 +59,12 @@ function agentChatStream(params, onChunk) {
|
||||
});
|
||||
|
||||
requestTask.onChunkReceived(res => {
|
||||
if (hasError) return;
|
||||
// 检查请求是否已被中止
|
||||
if (hasError || requestTask.isAborted) return;
|
||||
const base64 = uni.arrayBufferToBase64(res.data);
|
||||
let data = '';
|
||||
try {
|
||||
data = decodeURIComponent(escape(atob(base64)));
|
||||
data = decodeURIComponent(escape(weAtob(base64)));
|
||||
} catch (e) {
|
||||
// 某些平台可能不支持 atob,可以直接用 base64
|
||||
data = base64;
|
||||
@ -75,8 +76,62 @@ function agentChatStream(params, onChunk) {
|
||||
});
|
||||
// #endif
|
||||
});
|
||||
|
||||
return {
|
||||
promise,
|
||||
requestTask
|
||||
};
|
||||
}
|
||||
|
||||
// window.atob兼容性处理
|
||||
const weAtob = (string) => {
|
||||
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
|
||||
const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
// 去除空白字符
|
||||
string = String(string).replace(/[\t\n\f\r ]+/g, '');
|
||||
// 验证 Base64 编码
|
||||
if (!b64re.test(string)) {
|
||||
throw new TypeError(
|
||||
// eslint-disable-next-line quotes
|
||||
"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."
|
||||
);
|
||||
}
|
||||
|
||||
// 填充字符
|
||||
string += '=='.slice(2 - (string.length & 3));
|
||||
|
||||
let bitmap,
|
||||
result = '',
|
||||
r1,
|
||||
r2,
|
||||
i = 0;
|
||||
|
||||
for (; i < string.length;) {
|
||||
bitmap =
|
||||
(b64.indexOf(string.charAt(i++)) << 18) |
|
||||
(b64.indexOf(string.charAt(i++)) << 12) |
|
||||
((r1 = b64.indexOf(string.charAt(i++))) << 6) |
|
||||
(r2 = b64.indexOf(string.charAt(i++)));
|
||||
|
||||
if (r1 === 64) {
|
||||
result += String.fromCharCode((bitmap >> 16) & 255);
|
||||
} else if (r2 === 64) {
|
||||
result += String.fromCharCode(
|
||||
(bitmap >> 16) & 255,
|
||||
(bitmap >> 8) & 255
|
||||
);
|
||||
} else {
|
||||
result += String.fromCharCode(
|
||||
(bitmap >> 16) & 255,
|
||||
(bitmap >> 8) & 255,
|
||||
bitmap & 255
|
||||
);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// 解析SSE分段数据
|
||||
function parseSSEChunk(raw) {
|
||||
// 拆分为多段
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { BASE_URL } from "../../constant/base";
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
|
||||
const defaultConfig = {
|
||||
header: {
|
||||
@ -49,6 +50,10 @@ function request(url, args = {}, method = 'POST', customConfig = {}) {
|
||||
success: (res) => {
|
||||
console.log("请求响应:" + JSON.stringify(res))
|
||||
resolve(res.data)
|
||||
if(res.statusCode && res.statusCode === 424) {
|
||||
uni.setStorageSync('token', '')
|
||||
goLogin();
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("请求失败:", err);
|
||||
|
||||
BIN
static/input_keyboard_icon.png
Normal file
BIN
static/input_keyboard_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
static/input_stop_icon.png
Normal file
BIN
static/input_stop_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user