This commit is contained in:
parent
d747ebd892
commit
986176fff9
|
@ -32,7 +32,12 @@
|
|||
<span>医慧咨询</span>
|
||||
</template>
|
||||
<el-menu-item index="/consultation/inquiry">病情询问</el-menu-item>
|
||||
<el-menu-item index="/consultation/record">询问记录</el-menu-item>
|
||||
</el-sub-menu>
|
||||
<el-menu-item index="/chatroom">
|
||||
<el-icon><ChatLineRound /></el-icon>
|
||||
<span>聊天室</span>
|
||||
</el-menu-item>
|
||||
|
||||
<el-sub-menu index="/template">
|
||||
<template #title>
|
||||
|
|
|
@ -72,6 +72,12 @@ const routes = [
|
|||
name: 'ConsultationInquiry',
|
||||
component: () => import('../views/consultation/Inquiry.vue'),
|
||||
meta: { title: '病情询问' }
|
||||
},
|
||||
{
|
||||
path: 'record',
|
||||
name: 'ConsultationRecord',
|
||||
component: () => import('../views/consultation/Record.vue'),
|
||||
meta: { title: '病历记录' }
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -140,4 +146,4 @@ const router = createRouter({
|
|||
|
||||
|
||||
|
||||
export default router
|
||||
export default router
|
||||
|
|
|
@ -3,29 +3,20 @@
|
|||
<h2>病情询问页面</h2>
|
||||
<el-card class="chat-card">
|
||||
<div class="chat-container">
|
||||
<div class="chat-messages" ref="messagesContainer">
|
||||
<div
|
||||
v-for="(message, index) in messages"
|
||||
:key="index"
|
||||
:class="['message', message.type]"
|
||||
>
|
||||
<div class="message-content">
|
||||
{{ message.content }}
|
||||
</div>
|
||||
<div class="message-time">
|
||||
{{ message.time }}
|
||||
</div>
|
||||
<div class="chat-messages">
|
||||
<div v-for="message in messages" :key="message.content" class="message-item" :class="{'user-message': message.sender === 'user', 'ai-message': message.sender === 'ai'}">
|
||||
<strong>{{ message.sender }}:</strong> {{ message.content }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-input">
|
||||
<el-input
|
||||
v-model="newMessage"
|
||||
v-model="inputMessage"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请描述您的症状或问题..."
|
||||
@keyup.enter="sendMessage"
|
||||
@keyup.enter="handleSendMessage"
|
||||
/>
|
||||
<el-button type="primary" @click="sendMessage" :disabled="!newMessage.trim()">
|
||||
<el-button type="primary" @click="handleSendMessage">
|
||||
发送
|
||||
</el-button>
|
||||
</div>
|
||||
|
@ -35,52 +26,59 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, nextTick } from 'vue'
|
||||
import { ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
const messages = ref([
|
||||
{
|
||||
content: '您好!我是您的智能医疗助手,请描述您的症状,我会为您提供专业的建议。',
|
||||
type: 'received',
|
||||
time: new Date().toLocaleTimeString()
|
||||
const inputMessage = ref('');
|
||||
const messages = ref([]);
|
||||
|
||||
const callBackend = async (message) => {
|
||||
try {
|
||||
const response = await axios.post('http://127.0.0.1:8080/talk/main', {
|
||||
"model":"glm4:latest",
|
||||
"prompt": message,
|
||||
"stream": false
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
}
|
||||
});
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.error('Error calling backend:', error);
|
||||
if (error.response) {
|
||||
console.error('Backend responded with status:', error.response.status);
|
||||
console.error('Backend responded with data:', error.response.data);
|
||||
} else if (error.request) {
|
||||
console.error('No response received:', error.request);
|
||||
} else {
|
||||
console.error('Error setting up the request:', error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
])
|
||||
|
||||
const newMessage = ref('')
|
||||
const messagesContainer = ref(null)
|
||||
|
||||
};
|
||||
const handleSendMessage = () => {
|
||||
sendMessage();
|
||||
};
|
||||
const sendMessage = async () => {
|
||||
if (!newMessage.value.trim()) return
|
||||
|
||||
// 添加用户消息
|
||||
messages.value.push({
|
||||
content: newMessage.value,
|
||||
type: 'sent',
|
||||
time: new Date().toLocaleTimeString()
|
||||
})
|
||||
|
||||
// 模拟自动回复
|
||||
setTimeout(() => {
|
||||
messages.value.push({
|
||||
content: '我已经收到您的问题,正在为您分析...',
|
||||
type: 'received',
|
||||
time: new Date().toLocaleTimeString()
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
newMessage.value = ''
|
||||
await nextTick()
|
||||
scrollToBottom()
|
||||
}
|
||||
|
||||
const scrollToBottom = () => {
|
||||
if (messagesContainer.value) {
|
||||
messagesContainer.value.scrollTop = messagesContainer.value.scrollHeight
|
||||
if (inputMessage.value.trim() === '') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
messages.value.push({ sender: '使用者', content: inputMessage.value });
|
||||
let putmessage=inputMessage.value;
|
||||
inputMessage.value = '';
|
||||
|
||||
try {
|
||||
const response = await callBackend(putmessage);
|
||||
|
||||
messages.value.push({ sender: '医小慧', content: response.response });
|
||||
} catch (error) {
|
||||
// 捕获网络错误或其他异常
|
||||
console.error('请求失败:', error); // 打印错误信息
|
||||
messages.value.push({ sender: 'ai', content: '网络错误,请检查连接' });
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
scrollToBottom()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
@ -116,18 +114,6 @@ onMounted(() => {
|
|||
text-align: right;
|
||||
}
|
||||
|
||||
.message.received {
|
||||
margin-right: auto;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
background-color: #f4f4f5;
|
||||
padding: 10px 15px;
|
||||
border-radius: 8px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.message.sent .message-content {
|
||||
background-color: #409eff;
|
||||
color: white;
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<template>
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
<el-table-column prop="talkId" label="问题ID" width="180" />
|
||||
<el-table-column prop="talkPrompt" label="使用者提问" />
|
||||
<el-table-column prop="talkResponse" label="医小慧回复" />
|
||||
<el-table-column prop="talkTime" label="提问时间" width="180" />
|
||||
<el-table-column prop="talkUser" label="使用者身份" width="180" />
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref, onMounted } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'TalkHistory',
|
||||
setup() {
|
||||
const tableData = ref([]);
|
||||
|
||||
const fetchData = () => {
|
||||
axios.get('http://127.0.0.1:8080/talk/record/all')
|
||||
.then(response => {
|
||||
console.log('Talk records fetched successfully:', response.data);
|
||||
tableData.value = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('There was an error fetching the talk records:', error);
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
});
|
||||
|
||||
return {
|
||||
tableData
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue