"use strict";
|
const common_vendor = require("../../common/vendor.js");
|
const common_assets = require("../../common/assets.js");
|
if (!Array) {
|
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
|
_easycom_uni_popup2();
|
}
|
const _easycom_uni_popup = () => "../../node-modules/@dcloudio/uni-ui/lib/uni-popup/uni-popup.js";
|
if (!Math) {
|
_easycom_uni_popup();
|
}
|
const _sfc_main = {
|
__name: "ai",
|
setup(__props) {
|
var _a;
|
const userAvatar = common_vendor.ref(((_a = common_vendor.index.getStorageSync("userInfo")) == null ? void 0 : _a.avatar) || "/static/avatar/default.png");
|
const inputContent = common_vendor.ref("");
|
const messages = common_vendor.ref([]);
|
const scrollTop = common_vendor.ref(0);
|
const record = common_vendor.ref(null);
|
const loadMoreHistory = () => {
|
common_vendor.index.showLoading({
|
title: "加载中..."
|
});
|
setTimeout(() => {
|
const historicalMessages = [
|
{
|
type: "user",
|
content: "之前的咨询记录1"
|
},
|
{
|
type: "ai",
|
content: "历史回复1",
|
quickReplies: ["追问1", "追问2"]
|
}
|
];
|
messages.value = [...historicalMessages, ...messages.value];
|
common_vendor.index.hideLoading();
|
}, 1e3);
|
};
|
const quickQuestions = common_vendor.ref([
|
"最近感冒了,该怎么办?",
|
"头痛是什么原因?",
|
"如何缓解失眠?"
|
]);
|
const analyzeTemplates = {
|
// 病历分析模板
|
record: {
|
content: (data) => `
|
根据您的病历,我的分析如下:
|
|
1. 基本情况
|
医院:${data.hospital}
|
科室:${data.department}
|
诊断:${data.diagnosis}
|
|
2. 病情分析
|
- 这是一个${data.diagnosis}的诊断
|
- 这类疾病通常属于${data.department}常见病症
|
- 需要重点关注的症状包括...
|
|
3. 建议
|
- 建议按医嘱完成治疗疗程
|
- 注意观察以下症状...
|
- 如有以下情况需及时就医...
|
|
4. 预防措施
|
- 保持良好的生活习惯
|
- 避免接触可能的诱发因素
|
- 定期进行相关检查
|
|
需要了解更多详细信息吗?
|
`,
|
quickReplies: [
|
"这个病严重吗?",
|
"需要注意什么?",
|
"多久能康复?",
|
"是否需要复查?"
|
]
|
},
|
// 检查报告分析模板
|
report: {
|
content: (data) => `
|
根据您的检查报告,我的分析如下:
|
|
1. 检查概况
|
项目:${data.name}
|
时间:${data.time}
|
结果:${data.status === "normal" ? "正常" : "异常"}
|
|
2. 详细分析
|
${data.status === "normal" ? `
|
• 您的检查结果在正常范围内
|
• 各项指标符合健康标准
|
• 建议继续保持良好的生活习惯
|
` : `
|
• 检测到部分指标异常
|
• 建议及时就医进行进一步检查
|
• 需要注意观察相关症状变化
|
`}
|
|
3. 建议
|
- ${data.status === "normal" ? "定期进行健康检查,保持健康的生活方式。" : "建议您尽快预约相关科室进行就医。"}
|
- 保持良好的作息和饮食习惯
|
- 适量运动,增强体质
|
|
4. 后续跟进
|
${data.status === "normal" ? "建议您按照常规体检周期进行复查。" : "建议您在就医后根据医生建议安排复查时间。"}
|
|
需要了解更多信息或预约就医吗?`,
|
quickReplies: [
|
"如何预约复查?",
|
"需要挂什么科室?",
|
"这个结果代表什么?",
|
"建议就医吗?"
|
]
|
}
|
};
|
const askQuestion = (question) => {
|
inputContent.value = question;
|
sendMessage();
|
};
|
const aiResponses = {
|
common: [
|
{
|
keywords: ["头痛", "头晕"],
|
content: "根据您描述的症状,可能的原因包括:\n1. 紧张性头痛\n2. 偏头痛\n3. 颈椎问题\n4. 眼疲劳\n\n建议:\n1. 保持良好的作息习惯\n2. 避免长时间用眼\n3. 适当运动放松\n4. 如果症状持续,建议到神经内科就诊",
|
medicines: ["布洛芬缓释胶囊", "头痛宁片"],
|
quickReplies: ["症状多久需要就医?", "如何预防头痛?", "需要做什么检查?"]
|
},
|
{
|
keywords: ["感冒", "发烧", "咳嗽"],
|
content: "您的症状疑似上呼吸道感染,建议:\n1. 多休息,保持充足睡眠\n2. 多饮温水\n3. 可以服用一些退烧止咳药物\n4. 如果发烧超过38.5℃或持续3天以上,建议及时就医",
|
medicines: ["布洛芬缓释胶囊", "感冒灵颗粒", "止咳糖浆"],
|
quickReplies: ["需要吃什么药?", "多久能好?", "如何预防传染?"]
|
}
|
]
|
};
|
const medicineDatabase = {
|
"布洛芬缓释胶囊": {
|
id: 1,
|
name: "布洛芬缓释胶囊",
|
image: "/static/medicines/buluofen.jpg",
|
price: "39.8",
|
desc: "用于缓解轻至中度疼痛,如头痛、关节痛、发热等",
|
usage: "口服,一次1片,必要时每4-6小时重复一次",
|
spec: "0.3g*12片/盒"
|
},
|
"感冒灵颗粒": {
|
id: 2,
|
name: "感冒灵颗粒",
|
image: "/static/medicines/ganmaoling.jpg",
|
price: "28.5",
|
desc: "用于感冒引起的头痛、发热、鼻塞、流涕、咽痛等",
|
usage: "口服,一次1袋,一日3次",
|
spec: "10g*10袋/盒"
|
},
|
"止咳糖浆": {
|
id: 3,
|
name: "止咳糖浆",
|
image: "/static/medicines/zhike.jpg",
|
price: "35.6",
|
desc: "用于各种原因引起的咳嗽症状",
|
usage: "口服,一次10ml,一日3次",
|
spec: "100ml/瓶"
|
}
|
};
|
const sendMessage = async () => {
|
if (!inputContent.value || !inputContent.value.trim())
|
return;
|
const userMessage = inputContent.value.trim();
|
messages.value.push({
|
type: "user",
|
content: userMessage,
|
avatar: userAvatar.value
|
});
|
inputContent.value = "";
|
await common_vendor.nextTick$1();
|
scrollToBottom();
|
let aiResponse = null;
|
for (const response of aiResponses.common) {
|
if (response.keywords.some((keyword) => userMessage.includes(keyword))) {
|
aiResponse = response;
|
break;
|
}
|
}
|
if (!aiResponse) {
|
aiResponse = {
|
content: "我理解您的问题。建议您:\n1. 注意观察症状变化\n2. 保持良好的作息习惯\n3. 如果症状持续,建议及时就医",
|
medicines: [],
|
quickReplies: ["需要挂什么科?", "如何预约就医?", "还有其他建议吗?"]
|
};
|
}
|
const recommendedMedicines = aiResponse.medicines.map((name) => medicineDatabase[name]).filter(Boolean);
|
setTimeout(() => {
|
messages.value.push({
|
type: "ai",
|
content: aiResponse.content + (recommendedMedicines.length ? "\n\n推荐药品:" + recommendedMedicines.map((med) => `
|
• ${med.name}
|
${med.desc}
|
规格:${med.spec}
|
用法:${med.usage}`).join("\n") : ""),
|
medicines: recommendedMedicines,
|
quickReplies: aiResponse.quickReplies
|
});
|
scrollToBottom();
|
}, 1e3);
|
};
|
const scrollToBottom = () => {
|
common_vendor.nextTick$1(() => {
|
const query = common_vendor.index.createSelectorQuery();
|
query.select(".chat-content").boundingClientRect();
|
query.exec((res) => {
|
if (res[0]) {
|
scrollTop.value = res[0].height;
|
}
|
});
|
});
|
};
|
common_vendor.onMounted(() => {
|
var _a2;
|
const pages = getCurrentPages();
|
const currentPage = pages[pages.length - 1];
|
const eventChannel = (_a2 = currentPage.$getOpenerEventChannel) == null ? void 0 : _a2.call(currentPage);
|
eventChannel == null ? void 0 : eventChannel.on("initMessage", (data) => {
|
if (data.message) {
|
messages.value.push({
|
type: "user",
|
content: data.message
|
});
|
setTimeout(() => {
|
const isRecord = data.message.includes("病历");
|
const template = isRecord ? analyzeTemplates.record : analyzeTemplates.report;
|
const dataMatch = data.message.match(/医院: (.+)\n科室: (.+)\n诊断: (.+)/) || data.message.match(/检查项目: (.+)\n检查时间: (.+)\n检查结果: (.+)/);
|
if (dataMatch) {
|
const templateData = isRecord ? {
|
hospital: dataMatch[1],
|
department: dataMatch[2],
|
diagnosis: dataMatch[3]
|
} : {
|
name: dataMatch[1],
|
time: dataMatch[2],
|
status: dataMatch[3]
|
};
|
messages.value.push({
|
type: "ai",
|
content: template.content(templateData),
|
quickReplies: template.quickReplies
|
});
|
} else {
|
messages.value.push({
|
type: "ai",
|
content: "抱歉,我无法解析这些信息。请提供更多详细信息。",
|
quickReplies: ["重新描述", "人工咨询"]
|
});
|
}
|
scrollToBottom();
|
}, 1e3);
|
}
|
});
|
const recordId = common_vendor.index.getStorageSync("selectedRecordId");
|
if (recordId) {
|
getRecordDetail(recordId).then((res) => {
|
record.value = res;
|
analyzeRecord();
|
});
|
}
|
});
|
const analyzeRecord = () => {
|
if (!record.value)
|
return;
|
messages.value.push({
|
type: "ai",
|
content: "我已收到您的病历,正在为您分析...",
|
avatar: "/static/avatar/ai.png"
|
});
|
setTimeout(() => {
|
messages.value.push({
|
type: "ai",
|
content: `根据您的病历显示:
|
1. 主要症状: ${record.value.symptoms}
|
2. 初步诊断: ${record.value.diagnosis}
|
3. 建议治疗方案: ${record.value.treatment}
|
|
请问您还有什么想要了解的吗?`,
|
avatar: "/static/avatar/ai.png"
|
});
|
}, 1e3);
|
};
|
const medicalRecords = common_vendor.ref([
|
{
|
id: 1,
|
hospital: "青岛中央医院",
|
department: "呼吸内科",
|
diagnosis: "上呼吸道感染",
|
date: "2024-03-15",
|
details: "发热38.5℃,咽痛,咳嗽..."
|
},
|
{
|
id: 2,
|
hospital: "青岛仁伯爵综合医院",
|
department: "消化内科",
|
diagnosis: "慢性胃炎",
|
date: "2024-02-20",
|
details: "上腹部不适,嗳气..."
|
}
|
]);
|
const recommendMedicines = {
|
"上呼吸道感染": [
|
{
|
id: 1,
|
name: "布洛芬缓释胶囊",
|
image: "/static/medicines/buluofen.jpg",
|
price: "39.8",
|
desc: "用于缓解感冒发热、咽喉疼痛"
|
},
|
{
|
id: 2,
|
name: "板蓝根颗粒",
|
image: "/static/medicines/banlangen.jpg",
|
price: "28.5",
|
desc: "清热解毒,凉血利咽"
|
}
|
],
|
"慢性胃炎": [
|
{
|
id: 3,
|
name: "奥美拉唑肠溶胶囊",
|
image: "/static/medicines/amzl.jpg",
|
price: "45.6",
|
desc: "用于胃酸过多、胃痛"
|
}
|
]
|
};
|
const recordSelector = common_vendor.ref(null);
|
const showRecordSelector = () => {
|
recordSelector.value.open();
|
};
|
const closeRecordSelector = () => {
|
recordSelector.value.close();
|
};
|
const analyzeFromRecord = (record2) => {
|
messages.value.push({
|
type: "user",
|
content: `请分析我的病历:
|
医院:${record2.hospital}
|
科室:${record2.department}
|
诊断:${record2.diagnosis}`,
|
avatar: userAvatar.value
|
});
|
setTimeout(() => {
|
const analysis = analyzeTemplates.record.content({
|
hospital: record2.hospital,
|
department: record2.department,
|
diagnosis: record2.diagnosis,
|
details: record2.details
|
});
|
const medicines = recommendMedicines[record2.diagnosis] || [];
|
messages.value.push({
|
type: "ai",
|
content: analysis,
|
medicines,
|
quickReplies: [
|
"需要复查吗?",
|
"如何预防复发?",
|
"建议就医吗?",
|
"查看其他病历"
|
]
|
});
|
scrollToBottom();
|
}, 1e3);
|
};
|
const selectRecord = (record2) => {
|
closeRecordSelector();
|
analyzeFromRecord(record2);
|
};
|
common_vendor.onLoad((options) => {
|
if (options.type === "record") {
|
if (medicalRecords.value.length > 1) {
|
showRecordSelector();
|
} else if (medicalRecords.value.length === 1) {
|
analyzeFromRecord(medicalRecords.value[0]);
|
}
|
}
|
});
|
return (_ctx, _cache) => {
|
return {
|
a: common_vendor.f(quickQuestions.value, (q, index, i0) => {
|
return {
|
a: common_vendor.t(q),
|
b: index,
|
c: common_vendor.o(($event) => askQuestion(q), index)
|
};
|
}),
|
b: common_vendor.f(messages.value, (msg, index, i0) => {
|
return common_vendor.e({
|
a: msg.type === "user"
|
}, msg.type === "user" ? {
|
b: common_vendor.t(msg.content),
|
c: userAvatar.value
|
} : common_vendor.e({
|
d: common_assets._imports_0$15,
|
e: common_vendor.t(msg.content),
|
f: msg.quickReplies
|
}, msg.quickReplies ? {
|
g: common_vendor.f(msg.quickReplies, (reply, idx, i1) => {
|
return {
|
a: common_vendor.t(reply),
|
b: idx,
|
c: common_vendor.o(($event) => askQuestion(reply), idx)
|
};
|
})
|
} : {}), {
|
h: index,
|
i: common_vendor.n(msg.type)
|
});
|
}),
|
c: scrollTop.value,
|
d: common_vendor.o(loadMoreHistory),
|
e: -1,
|
f: common_vendor.o(sendMessage),
|
g: inputContent.value,
|
h: common_vendor.o(($event) => inputContent.value = $event.detail.value),
|
i: inputContent.value && inputContent.value.trim() ? 1 : "",
|
j: common_vendor.o(sendMessage),
|
k: common_vendor.o(closeRecordSelector),
|
l: common_vendor.f(medicalRecords.value, (record2, index, i0) => {
|
return {
|
a: common_vendor.t(record2.hospital),
|
b: common_vendor.t(record2.department),
|
c: common_vendor.t(record2.date),
|
d: common_vendor.t(record2.diagnosis),
|
e: index,
|
f: common_vendor.o(($event) => selectRecord(record2), index)
|
};
|
}),
|
m: common_vendor.sr(recordSelector, "67c33e29-0", {
|
"k": "recordSelector"
|
}),
|
n: common_vendor.p({
|
type: "bottom"
|
}),
|
o: common_vendor.gei(_ctx, "")
|
};
|
};
|
}
|
};
|
wx.createPage(_sfc_main);
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/consultation/ai.js.map
|