This commit is contained in:
liuyuan
2025-05-23 17:23:44 +08:00
parent 060344610a
commit 56ee2fee9e
16 changed files with 257 additions and 118 deletions

View File

@@ -60,7 +60,7 @@
</button>
</view>
<view class="message_wrap" :style="{ top: 82 + 'px' }" v-if="showMessages">
<view class="message_wrap" :style="{ top: 80 + 'px' }" v-if="showMessages">
<text class="message_title" v-if="tishi">好的结合您的情况下面是分析结果</text>
<!-- 显示聊天记录 -->
<view class="message-container-block" ref="messageContainerBlock">
@@ -102,6 +102,7 @@
<script>
import $http from "@/config/requestConfig.js";
import { mapState, mapMutations } from "vuex";
import qs from 'qs'
export default {
data() {
return {
@@ -135,9 +136,6 @@ export default {
},
computed: {
...mapState(["userInfo"]),
},
mounted() {
},
onLoad() {
uni.hideTabBar();
@@ -146,9 +144,13 @@ export default {
const systemInfo = uni.getSystemInfoSync();
this.containerHeight = systemInfo.windowHeight; //获取设备的窗口高度
this.getChatAssistants();
//重置
this.$nextTick(() => {
this.showMode();
});
},
onShow(){
this.showMessages = false;
console.log('进入到onShow方法')
this.activeRecord = null;
this.getRecordsData();
@@ -157,6 +159,11 @@ export default {
let index = uni.getStorageSync('homeParams').index;
if(data){
this.clickRecord(data, index);
}else{
uni.removeStorageSync('homeParams');
this.$nextTick(() => {
this.showMessages = false;
});
}
},
methods: {
@@ -174,8 +181,8 @@ export default {
},
})
.then(res=> {
uni.hideLoading();
if (res.list&&res.list.length>0) {
uni.hideLoading();
res.list = res.list.filter(item => {
return !item.name.includes('心理助手') && !item.name.includes('太湖云翳');
});
@@ -204,11 +211,13 @@ export default {
}
})
.catch(e=>{
uni.hideLoading();
uni.setStorageSync("guidePages", 2);
});
},
//获取对话记录数据
getRecordsData() {
this.record_list = [];
this.$http.request({
url: 'common/ragFlowApi/getChats',
method: "POST",
@@ -224,6 +233,7 @@ export default {
})
.then(res=> {
if(res.code==0){
console.log('请求最新列表')
if(res.list&&res.list.length>0){
this.record_list = res.list;
}else{
@@ -247,6 +257,8 @@ export default {
this.activeRecord = index;
this.messages = [];
this.showMessages = true;
//如果正在回答的时候切换需要中断回答
this.closeWebSocket();
uni.showLoading({
title: '加载中'
})
@@ -321,7 +333,7 @@ export default {
if(this.formData.diagnosis){
question += '诊断:'+this.formData.diagnosis+'';
}
question += '病情为:'+this.formData.illness+''+this.formData.symptoms+',请根据这位患者的情况出一个中医治疗方案';
question += '病情为:'+this.formData.illness+''+this.formData.symptoms;
this.question = question;
//创建对话 获取sessionId
@@ -345,6 +357,7 @@ export default {
if (res.code==0) {
this.sessionId = res.id;
//获取回答
console.log('sessionId', this.sessionId)
this.sendQuestion();
}
});
@@ -372,23 +385,46 @@ export default {
},
//开始监听 SSE 数据
startSSE(params){
// 拼接查询字符串
const query = new URLSearchParams({
...params,
token: uni.getStorageSync('token')
}).toString();
const queryString = qs.stringify(params);
var data = {};
this.eventSource = uni.connectSocket({
url: this.$baseUrl + `websocket`,
success: () => {
console.log('WebSocket连接中...');
$http.request({
url: `common/ragFlowApi/chatToAssistantStream?${queryString}`,
method: "GET",
data,
header: {
"Content-Type": "application/json",
},
})
.then(res=> {
console.log('请求成功')
})
.catch(e=>{
console.log('失败')
});
},
fail: (err) => {
console.error('连接失败', err);
uni.showToast({ title: '连接失败', icon: 'error' });
}
});
// 创建 SSE 连接
this.eventSource = new EventSource(this.$baseUrl+`common/ragFlowApi/chatToAssistantStream?${query}`);
// 监听服务器发送的消息
this.eventSource.onmessage = (event) => {
uni.onSocketMessage((event) => {
try {
const message = JSON.parse(event.data);
if (message.data === true) {
console.log("回答已结束");
console.log("回答已结束1111");
this.pauseStatus = false;
this.eventSource.close();
this.loading = false;
//获取最近的会话记录数据
this.getRecordsData();
setTimeout(() => {
this.closeWebSocket();
}, 200);
return;
}
@@ -415,50 +451,53 @@ export default {
this.previousAnswer = answer;
}
} catch (error) {
this.$commonJS.showToast("处理消息时发生错误");
this.loading = false;
this.closeWebSocket();
}
};
//监听 SSE 连接关闭
this.eventSource.onclose = () => {
console.log("SSE 连接已关闭");
this.loading = false;
};
//监听 SSE 错误
this.eventSource.onerror = (error) => {
console.error("SSE 连接发生错误", error);
this.loading = false;
};
//获取最近的会话记录数据
this.getRecordsData();
});
//监听WebSocket连接打开
uni.onSocketOpen(() => {
console.log('WebSocket已连接');
});
//监听WebSocket错误
uni.onSocketError((err) => {
console.error('WebSocket连接错误', err);
});
//监听WebSocket关闭
uni.onSocketClose((res) => {
console.log('WebSocket 已关闭', res);
});
},
//回答界面的提交
sendAgain(){
console.log('这是再一次提问')
if(!this.question_send){
this.$commonJS.showToast("请输入发送内容");
return
if(!this.pauseStatus){
if(!this.question_send){
this.$commonJS.showToast("请输入发送内容");
return
}
const params = {
chatId: this.chatId,
chatName: this.chatName,
question: this.question_send,
sessionId: this.sessionId,
sessionName: this.question_send.slice(0, 15),
patientName: this.formData.name
};
this.messages.push({
content: `${this.question_send}`,
type: 'question',
});
this.loading = true;
this.question_send = '';
this.pauseStatus = true;
this.previousAnswer = null;
//调用后端 SSE 接口,发送问题并接收实时回答
this.startSSE(params);
}else{
console.log('不能点击了')
}
const params = {
chatId: this.chatId,
chatName: this.chatName,
question: this.question_send,
sessionId: this.sessionId,
sessionName: this.question_send.slice(0, 15),
patientName: this.formData.name
};
this.messages.push({
content: `${this.question_send}`,
type: 'question',
});
this.loading = true;
this.question_send = '';
this.pauseStatus = true;
this.previousAnswer = null;
//调用后端 SSE 接口,发送问题并接收实时回答
this.startSSE(params);
},
//点击左侧弹窗
openDrawer() {
@@ -478,15 +517,34 @@ export default {
this.chatId = null;
this.activeIndex = null;
this.activeRecord = null;
if(this.eventSource){
this.eventSource.close();
}
//中断
this.closeWebSocket();
this.previousAnswer = null;
this.pauseStatus = false;
//把缓存清除
uni.removeStorageSync('homeParams');
},
//关闭进程和监听
closeWebSocket() {
if (this.eventSource) {
// 关闭连接并移除监听
this.eventSource.close({
success: () => {
console.log('WebSocket 已关闭-closeWebSocket');
uni.offSocketMessage(); //移除消息监听
}
});
this.eventSource = null;
this.loading = false;
this.pauseStatus = false;
}
}
},
beforeDestroy() {
onHide() {
this.closeWebSocket();
},
onUnload() {
this.closeWebSocket();
}
}
</script>
@@ -711,6 +769,7 @@ export default {
}
.message-container {
display: inline;
line-height: 48rpx;
}
.message-item {
@@ -757,7 +816,7 @@ h3{
text{
display: inline-block;
padding: 20rpx;
line-height: 34rpx;
line-height: 38rpx;
background-color: rgba(81, 136, 229, 0.2);
border-radius: 15rpx;
color: #333;
@@ -772,11 +831,11 @@ h3{
flex-direction: column;
}
.list_content{
padding: 30rpx 20rpx;
padding: 60rpx 20rpx 30rpx;
overflow-y: auto;
}
.list_item{
padding: 20rpx 10rpx;
padding: 15rpx 10rpx;
}
.text_item{
display: block;

View File

@@ -71,13 +71,13 @@ export default {
]
};
},
computed: {
...mapState(["userInfo"]),
},
//第一次加载
onLoad(e) {
uni.hideTabBar();
},
computed: {
...mapState(["userInfo"]),
},
//页面显示
onShow() {
uni.removeStorageSync('homeParams');

View File

@@ -0,0 +1,65 @@
<template>
<view class="content">
<z-nav-bar title="医生证书" bgColor="#5188e5" fontColor="#fff"></z-nav-bar>
<view class="url_block">
<view v-for="item in urlArr" :key="item" class="item_url">
<image mode="aspectFit"
:src="item"
@click="showImg(item)"
></image>
</view>
</view>
</view>
</template>
<script>
import $http from "@/config/requestConfig.js";
export default {
data() {
return {
urlArr: []
}
},
onLoad(e) {
let data = JSON.parse(e.data);
let arr = data.flatMap(item =>
item.certificateUrl.split(',').map(v => v)
);
this.urlArr = arr;
},
methods: {
//展示图片
showImg(item){
uni.previewImage({
urls: [item],
current: 0
});
}
},
}
</script>
<style lang="scss" scoped>
@import '@/static/mixin.scss';
.url_block{
padding: 30rpx 30rpx 10rpx;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.item_url{
width: 48%;
background: rgba(216, 230, 255, 0.8);
border: 1rpx solid #d8e6ff;
margin-bottom: 20rpx;
margin-right: 20rpx;
image{
width: 100%;
height: 280rpx;
}
}
.item_url:nth-child(2n){
margin-right: 0;
}
</style>

View File

@@ -33,7 +33,7 @@
<view class="taihu_common">
<text>太湖证书</text>
<view class="certificate-list" v-if="certificates.length>0">
<view class="list_block" v-for="(item,index) in displayedCertificates" :key="index" @click="showImg(item.certificateUrl)">
<view class="list_block" v-for="(item,index) in displayedCertificates" :key="index" @click="goToUrl(item.userCertificates)">
{{item.title}}
</view>
@@ -58,7 +58,7 @@ export default {
certificates: [], //证书
status: false,
showAll: false, //是否显示全部
defaultShowCount: 5 //默认显示条数
defaultShowCount: 6 //默认显示条数
}
},
computed: {
@@ -108,18 +108,15 @@ export default {
this.showAll = !this.showAll
},
//展示图片
showImg(data){
let url = '';
if(data){
url = data.split(',')[0];
uni.previewImage({
urls: [url],
current: 0
goToUrl(urlArr){
if(urlArr&&urlArr.length>0){
uni.navigateTo({
url: '/pages/talents/certificateUrl?data='+JSON.stringify(urlArr),
});
}else{
this.$commonJS.showToast("暂无证书图片");
}
}
},
},
}
</script>

View File

@@ -29,10 +29,10 @@ export default {
},
onLoad() {
uni.hideTabBar();
this.getData();
},
onShow() {
uni.removeStorageSync('homeParams');
this.getData();
},
methods: {
//获取数据

View File

@@ -230,7 +230,6 @@ export default {
},
})
.then((res) => {
console.log(1111)
if (res.code == 0 && res.baseAreas.length > 0) {
this.quCodeList = res.baseAreas.map((item) => {
let obj = {
@@ -239,7 +238,6 @@ export default {
};
return obj;
});
console.log(2222)
this.loginForm.quCode = this.quCodeList[0].value;
this.$forceUpdate();
} else {
@@ -393,7 +391,7 @@ export default {
duration: 1000,
});
setTimeout(() => {
uni.switchTab({
uni.reLaunch({
url: "/pages/home/index",
});
}, 1000);
@@ -464,7 +462,7 @@ export default {
setTimeout(() => {
uni.setStorageSync("isJump", "false");
uni.switchTab({
uni.reLaunch({
url: "/pages/home/index"
});
}, 100);
@@ -503,7 +501,7 @@ export default {
title: "登录成功",
});
setTimeout(() => {
uni.switchTab({
uni.reLaunch({
url: "/pages/home/index"
});
}, 500);
@@ -542,7 +540,7 @@ export default {
title: "登录成功",
});
setTimeout(() => {
uni.switchTab({
uni.reLaunch({
url: "/pages/home/index"
});
}, 500);
@@ -598,7 +596,7 @@ export default {
title: "登录成功",
});
setTimeout(() => {
uni.switchTab({
uni.reLaunch({
url: "/pages/home/index"
});
}, 500);
@@ -657,7 +655,7 @@ export default {
duration: 2000,
});
setTimeout(() => {
uni.switchTab({
uni.reLaunch({
url: "/pages/home/index"
});
}, 500);