You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
299 lines
7.6 KiB
299 lines
7.6 KiB
Page({
|
|
data: {
|
|
// 当前时间
|
|
currentTime: '',
|
|
|
|
// 聊天消息
|
|
messages: [],
|
|
|
|
// 输入框相关
|
|
inputValue: '',
|
|
autoFocus: false,
|
|
|
|
// 症状选择
|
|
quickSymptoms: [
|
|
'发热', '咳嗽', '腹泻', '食欲不振',
|
|
'精神萎靡', '呼吸困难', '体重下降', '皮肤问题'
|
|
],
|
|
selectedSymptoms: [],
|
|
showSymptomSelector: false,
|
|
|
|
// 症状数据
|
|
symptoms: [
|
|
{ id: 1, name: '发热', category: '全身症状' },
|
|
{ id: 2, name: '咳嗽', category: '呼吸系统' },
|
|
{ id: 3, name: '腹泻', category: '消化系统' },
|
|
{ id: 4, name: '呕吐', category: '消化系统' },
|
|
{ id: 5, name: '食欲不振', category: '消化系统' },
|
|
{ id: 6, name: '呼吸困难', category: '呼吸系统' },
|
|
{ id: 7, name: '精神萎靡', category: '神经系统' },
|
|
{ id: 8, name: '体重下降', category: '全身症状' },
|
|
{ id: 9, name: '皮肤问题', category: '皮肤系统' },
|
|
{ id: 10, name: '跛行', category: '运动系统' },
|
|
{ id: 11, name: '眼部分泌物', category: '五官' },
|
|
{ id: 12, name: '流鼻涕', category: '呼吸系统' }
|
|
],
|
|
|
|
// 状态控制
|
|
isAIThinking: false,
|
|
isLoading: false,
|
|
loadingText: '',
|
|
showMoreMenu: false
|
|
},
|
|
|
|
onLoad() {
|
|
this.initData();
|
|
},
|
|
|
|
onShow() {
|
|
this.updateCurrentTime();
|
|
this.setData({ autoFocus: true });
|
|
},
|
|
|
|
// 初始化数据
|
|
initData() {
|
|
// 设置当前时间
|
|
this.updateCurrentTime();
|
|
|
|
// 定时更新当前时间
|
|
setInterval(() => {
|
|
this.updateCurrentTime();
|
|
}, 60000);
|
|
|
|
},
|
|
|
|
// 更新当前时间
|
|
updateCurrentTime() {
|
|
const now = new Date();
|
|
const timeString = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
|
|
this.setData({ currentTime: timeString });
|
|
},
|
|
|
|
// 输入框变化
|
|
onInput(e) {
|
|
this.setData({ inputValue: e.detail.value });
|
|
},
|
|
|
|
// 发送消息
|
|
sendMessage() {
|
|
const message = this.data.inputValue.trim();
|
|
if (!message) return;
|
|
|
|
// 添加用户消息
|
|
const userMessage = {
|
|
id: Date.now(),
|
|
type: 'user',
|
|
content: message,
|
|
time: this.getCurrentTime()
|
|
};
|
|
|
|
this.setData({
|
|
messages: [...this.data.messages, userMessage],
|
|
inputValue: '',
|
|
autoFocus: true
|
|
});
|
|
|
|
// 模拟AI思考
|
|
this.simulateAIResponse(message);
|
|
},
|
|
|
|
// 获取当前时间
|
|
getCurrentTime() {
|
|
const now = new Date();
|
|
return `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
|
|
},
|
|
|
|
// 模拟AI响应
|
|
simulateAIResponse(userMessage) {
|
|
this.setData({ isAIThinking: true });
|
|
|
|
// 模拟AI思考时间
|
|
setTimeout(() => {
|
|
const aiMessage = this.generateAIResponse(userMessage);
|
|
console.log(333,aiMessage);
|
|
this.setData({
|
|
messages: [...this.data.messages, aiMessage],
|
|
isAIThinking: false
|
|
});
|
|
}, 1500 + Math.random() * 1000);
|
|
|
|
|
|
},
|
|
|
|
// 生成AI响应
|
|
generateAIResponse(userMessage) {
|
|
console.log(444,userMessage);
|
|
const responses = {
|
|
'发热': {
|
|
content: '根据您的描述,牲畜出现发热症状。',
|
|
diagnosis: {
|
|
disease: '可能为感染性疾病或中暑',
|
|
severity: 'moderate',
|
|
severityText: '中度',
|
|
suggestion: '建议:1. 隔离观察 2. 监测体温 3. 提供充足饮水 4. 如持续发热,及时联系兽医'
|
|
}
|
|
},
|
|
'咳嗽': {
|
|
content: '咳嗽症状提示可能存在呼吸系统问题。',
|
|
diagnosis: {
|
|
disease: '可能为呼吸道感染或肺炎',
|
|
severity: 'low',
|
|
severityText: '轻度',
|
|
suggestion: '建议:1. 保持圈舍通风 2. 避免粉尘 3. 观察呼吸频率 4. 如有加重及时就医'
|
|
}
|
|
},
|
|
'腹泻': {
|
|
content: '腹泻症状需要关注,可能由多种原因引起。',
|
|
diagnosis: {
|
|
disease: '可能为消化不良或肠胃感染',
|
|
severity: 'moderate',
|
|
severityText: '中度',
|
|
suggestion: '建议:1. 调整饲料 2. 补充电解质 3. 观察粪便性状 4. 如持续腹泻需兽医检查'
|
|
}
|
|
}
|
|
};
|
|
|
|
// 匹配症状关键词
|
|
let response = responses['发热']; // 默认响应
|
|
for (const [symptom, data] of Object.entries(responses)) {
|
|
if (userMessage.includes(symptom)) {
|
|
response = data;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return {
|
|
id: Date.now() + 1,
|
|
type: 'assistant',
|
|
content: response.content,
|
|
diagnosis: response.diagnosis,
|
|
time: this.getCurrentTime()
|
|
};
|
|
},
|
|
|
|
// 选择快捷症状
|
|
selectQuickSymptom(e) {
|
|
console.log(1111,e);
|
|
const symptom = e.currentTarget.dataset.symptom;
|
|
this.setData({ inputValue: symptom });
|
|
this.sendMessage();
|
|
},
|
|
|
|
// 切换症状选择器
|
|
toggleSymptomSelector() {
|
|
this.setData({ showSymptomSelector: !this.data.showSymptomSelector });
|
|
},
|
|
|
|
// 关闭症状选择器
|
|
closeSymptomSelector() {
|
|
this.setData({ showSymptomSelector: false });
|
|
},
|
|
|
|
// 症状选择
|
|
onSymptomSelect(e) {
|
|
const { symptom } = e.detail;
|
|
const selectedSymptoms = [...this.data.selectedSymptoms];
|
|
|
|
const index = selectedSymptoms.findIndex(s => s.id === symptom.id);
|
|
if (index > -1) {
|
|
selectedSymptoms.splice(index, 1);
|
|
} else {
|
|
selectedSymptoms.push(symptom);
|
|
}
|
|
|
|
this.setData({ selectedSymptoms });
|
|
},
|
|
|
|
// 确认症状选择
|
|
confirmSymptoms() {
|
|
if (this.data.selectedSymptoms.length === 0) {
|
|
wx.showToast({
|
|
title: '请选择至少一个症状',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
|
|
const symptomNames = this.data.selectedSymptoms.map(s => s.name).join('、');
|
|
this.setData({
|
|
inputValue: `我的牲畜出现以下症状:${symptomNames}`,
|
|
showSymptomSelector: false
|
|
});
|
|
},
|
|
|
|
|
|
// 返回
|
|
goBack() {
|
|
wx.navigateBack();
|
|
},
|
|
|
|
// 显示更多菜单
|
|
showMoreMenu() {
|
|
this.setData({ showMoreMenu: true });
|
|
},
|
|
|
|
// 关闭更多菜单
|
|
closeMoreMenu() {
|
|
this.setData({ showMoreMenu: false });
|
|
},
|
|
|
|
// 阻止事件冒泡
|
|
stopPropagation() {},
|
|
|
|
// 清空记录
|
|
clearHistory() {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '确定要清空所有聊天记录吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
this.setData({
|
|
messages: [{
|
|
id: 1,
|
|
type: 'assistant',
|
|
content: '您好!我是AI健康助手,有什么可以帮您?\n\n请描述您或牲畜的健康状况,我会为您提供专业的分析和建议。',
|
|
time: this.getCurrentTime()
|
|
}],
|
|
selectedSymptoms: []
|
|
});
|
|
this.closeMoreMenu();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
// 导出记录
|
|
exportChat() {
|
|
wx.showToast({
|
|
title: '记录已保存到本地',
|
|
icon: 'success'
|
|
});
|
|
this.closeMoreMenu();
|
|
},
|
|
|
|
// 联系兽医
|
|
contactDoctor() {
|
|
wx.showModal({
|
|
title: '联系兽医',
|
|
content: '确定要拨打兽医热线吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
wx.makePhoneCall({
|
|
phoneNumber: '400-123-4567'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
this.closeMoreMenu();
|
|
},
|
|
|
|
// 显示使用说明
|
|
showInstructions() {
|
|
wx.showModal({
|
|
title: '使用说明',
|
|
content: '1. 描述您或牲畜的症状\n2. AI助手会分析并提供建议\n3. 可使用快捷症状选择\n4. 诊断结果仅供参考,请及时咨询专业兽医',
|
|
showCancel: false
|
|
});
|
|
this.closeMoreMenu();
|
|
}
|
|
});
|