|
|
|
@ -12,30 +12,30 @@ |
|
|
|
:key="index" |
|
|
|
:class="['message', msg.role]" |
|
|
|
> |
|
|
|
<div>2025</div> |
|
|
|
<div class="time">{{ msg.time }}</div> |
|
|
|
<div v-if="msg.role === 'user'" class="bubble"> |
|
|
|
{{ msg.content }} |
|
|
|
</div> |
|
|
|
<div v-else-if="msg.role === 'assistant'"> |
|
|
|
<div v-if="msg.isKG" class="kg-card"> |
|
|
|
<div v-if="msg.content.entities?.length" class="kg-section"> |
|
|
|
<div v-if="msg.entities?.length" class="kg-section"> |
|
|
|
<h5 style="text-align: left">识别出的实体</h5> |
|
|
|
<div class="entity-list"> |
|
|
|
<span |
|
|
|
v-for="(ent, i) in msg.content.entities" |
|
|
|
:key="i" |
|
|
|
class="entity-tag" |
|
|
|
:class="'tag-' + ent.t" |
|
|
|
> |
|
|
|
v-for="(ent, i) in msg.entities" |
|
|
|
:key="i" |
|
|
|
class="entity-tag" |
|
|
|
:class="'tag-' + ent.t" |
|
|
|
> |
|
|
|
{{ ent.n }}<small>({{ ent.t }})</small> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div v-if="msg.content.relations?.length" class="kg-section"> |
|
|
|
<div v-if="msg.relations?.length" class="kg-section"> |
|
|
|
<h5 style="text-align: left">识别出的关系</h5> |
|
|
|
<ul class="relation-list"> |
|
|
|
<li v-for="(rel, i) in msg.content.relations" :key="i"> |
|
|
|
<li v-for="(rel, i) in msg.relations" :key="i"> |
|
|
|
<span class="rel-subject">{{ rel.e1 }}</span> |
|
|
|
<span class="rel-predicate">— {{ rel.r }} →</span> |
|
|
|
<span class="rel-object">{{ rel.e2 }}</span> |
|
|
|
@ -43,24 +43,40 @@ |
|
|
|
</ul> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div v-if="!msg.content.entities?.length && !msg.content.relations?.length" class="empty-state"> |
|
|
|
未提取到有效医学实体或关系。 |
|
|
|
</div> |
|
|
|
<div v-if="!msg.entities?.length && !msg.relations?.length" style="font-size: 12px; |
|
|
|
text-align: left;" > |
|
|
|
未提取到有效医学实体或关系。</div> |
|
|
|
</div> |
|
|
|
<div v-else class="bubble assistant-text"> |
|
|
|
{{ msg.content }} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<!-- 输入区域(Qwen 风格) --> |
|
|
|
<div class="input-area"> |
|
|
|
<div class="word" v-if="showFile"> |
|
|
|
<img src="../assets/word.svg" style="width: 28px;margin-right: 5px; flex-shrink: 0; flex-grow: 0;"> |
|
|
|
<div style="flex: 1; overflow: auto;"> |
|
|
|
<div class="wordName" style="text-align: left;margin-bottom: 1px;font-size: 11px;line-height: 14px;">{{file.fileName}}</div> |
|
|
|
<div style=" align-items: center;height: 18px;font-size: 10px; line-height: 12px;display: flex;">{{file.size}}</div> |
|
|
|
</div> |
|
|
|
<img |
|
|
|
src="../assets/close.svg" |
|
|
|
alt="close" |
|
|
|
class="close-btn" |
|
|
|
@click="removeFile" |
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<textarea |
|
|
|
v-model="inputText" |
|
|
|
placeholder="有什么可以帮助您?" |
|
|
|
class="input-box" |
|
|
|
@keyup.enter.exact.prevent="sendMessage" |
|
|
|
rows="1" |
|
|
|
:rows="rows" |
|
|
|
></textarea> |
|
|
|
|
|
|
|
|
|
|
|
@ -71,19 +87,35 @@ |
|
|
|
src="../assets/upload.png" |
|
|
|
alt="用户头像" |
|
|
|
class="avatar" |
|
|
|
@click="upload" |
|
|
|
style="margin-left: 10px;cursor:pointer;border-radius: 50%;width: 30px;box-shadow: rgb(0 0 0 / 18%) 0px 2px 8px; " |
|
|
|
> |
|
|
|
<div style="display: flex;align-items: center;"> |
|
|
|
<img |
|
|
|
<img v-if="inputStatus" |
|
|
|
|
|
|
|
src="../assets/放大.png" |
|
|
|
alt="用户头像" |
|
|
|
class="avatar" |
|
|
|
style="margin-left: 10px;cursor:pointer;width: 15px;margin-right: 26px " |
|
|
|
@click="adjustHeight(false)" |
|
|
|
> |
|
|
|
<img v-if="!inputStatus" |
|
|
|
|
|
|
|
src="../assets/缩小.png" |
|
|
|
alt="用户头像" |
|
|
|
class="avatar" |
|
|
|
style="margin-left: 10px;cursor:pointer;width: 15px;margin-right: 26px " |
|
|
|
@click="adjustHeight(true)" |
|
|
|
> |
|
|
|
<button class="send-btn" @click="sendMessage" title="发送"> |
|
|
|
发送 |
|
|
|
</button> |
|
|
|
<input |
|
|
|
ref="fileInput" |
|
|
|
type="file" |
|
|
|
style="display: none;" |
|
|
|
@change="handleFileChange" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
@ -108,10 +140,58 @@ export default { |
|
|
|
messages: [ |
|
|
|
{ role: 'assistant', content: '你好!我是图谱构建助手,有什么可以帮你的吗?',isKG:false } |
|
|
|
], |
|
|
|
status:"wait" |
|
|
|
status:"wait", |
|
|
|
rows:3, |
|
|
|
inputStatus:true, |
|
|
|
fileName:"", |
|
|
|
file:{}, |
|
|
|
showFile:false |
|
|
|
}; |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
removeFile(){ |
|
|
|
this.file={} |
|
|
|
this.showFile=false |
|
|
|
}, |
|
|
|
upload(){ |
|
|
|
this.$refs.fileInput.click(); // 点击按钮时打开文件选择框 |
|
|
|
}, |
|
|
|
handleFileChange(event) { |
|
|
|
const file = event.target.files[0]; // 获取第一个选择的文件 |
|
|
|
if (file) { |
|
|
|
this.fileName = file.name; // 存储文件名 |
|
|
|
|
|
|
|
const sizeInBytes = file.size; // 获取文件的字节数 |
|
|
|
let fileSize; |
|
|
|
|
|
|
|
if (sizeInBytes < 1024 * 1024) { |
|
|
|
// 文件小于 1MB,显示为 KB |
|
|
|
const sizeInKB = sizeInBytes / 1024; // 将字节转换为 KB |
|
|
|
fileSize = `${sizeInKB.toFixed(2)} KB`; |
|
|
|
} else { |
|
|
|
// 文件大于等于 1MB,显示为 MB |
|
|
|
const sizeInMB = sizeInBytes / (1024 * 1024); // 将字节转换为 MB |
|
|
|
fileSize = `${sizeInMB.toFixed(2)} MB`; |
|
|
|
} |
|
|
|
|
|
|
|
this.file = { |
|
|
|
fileName: file.name, |
|
|
|
size: fileSize // 自动加上单位 KB 或 MB |
|
|
|
}; |
|
|
|
this.showFile = true; |
|
|
|
console.log("文件信息:", this.file); // 打印文件信息 |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
adjustHeight(status){ |
|
|
|
if(status){ |
|
|
|
this.rows=3 |
|
|
|
this.inputStatus=true |
|
|
|
}else{ |
|
|
|
this.rows=10 |
|
|
|
this.inputStatus=false |
|
|
|
} |
|
|
|
}, |
|
|
|
pollAIStatus() { |
|
|
|
if (this.status !== "wait") return; // 如果已结束,不再继续 |
|
|
|
try { |
|
|
|
@ -129,6 +209,21 @@ export default { |
|
|
|
alert("查询状态失败,请重试"); |
|
|
|
} |
|
|
|
}, |
|
|
|
getNowDate(){ |
|
|
|
const currentDate = new Date(); |
|
|
|
|
|
|
|
// 获取年份、月份、日期、小时、分钟和秒 |
|
|
|
const year = currentDate.getFullYear(); |
|
|
|
const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1 |
|
|
|
const day = String(currentDate.getDate()).padStart(2, '0'); |
|
|
|
const hours = String(currentDate.getHours()).padStart(2, '0'); |
|
|
|
const minutes = String(currentDate.getMinutes()).padStart(2, '0'); |
|
|
|
const seconds = String(currentDate.getSeconds()).padStart(2, '0'); |
|
|
|
|
|
|
|
// 格式化时间为 YYYY-MM-DD HH:mm:ss |
|
|
|
const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
|
|
|
return formattedTime; |
|
|
|
}, |
|
|
|
sendMessage() { |
|
|
|
const text = this.inputText.trim(); |
|
|
|
if (!text) return; |
|
|
|
@ -137,15 +232,18 @@ export default { |
|
|
|
} |
|
|
|
// this.pollAIStatus() |
|
|
|
// 添加用户消息 |
|
|
|
let message={ role: 'user', content: text } |
|
|
|
|
|
|
|
let message={ role: 'user', content: text,time:this.getNowDate() } |
|
|
|
this.messages.push(message); |
|
|
|
this.inputText = ''; |
|
|
|
analyze(data).then(res=>{ |
|
|
|
console.log(res) |
|
|
|
let message={ role: 'assistant', |
|
|
|
content: res,entities:res.entities,relations:res.relations,isKG:true } |
|
|
|
content: res,entities:res.entities,relations:res.relations,isKG:true,time:this.getNowDate() } |
|
|
|
this.messages.push(message); |
|
|
|
this.scrollToBottom() |
|
|
|
}) |
|
|
|
this.scrollToBottom() |
|
|
|
// qaAnalyze(data).then(res=>{ |
|
|
|
// |
|
|
|
// }) |
|
|
|
@ -161,11 +259,18 @@ export default { |
|
|
|
scrollToBottom() { |
|
|
|
this.$nextTick(() => { |
|
|
|
const container = this.$refs.messagesContainer; |
|
|
|
console.log(container) |
|
|
|
if (container) { |
|
|
|
container.scrollTop = container.scrollHeight; |
|
|
|
// 使用 setTimeout 确保所有 DOM 更新完成后再执行滚动 |
|
|
|
setTimeout(() => { |
|
|
|
container.scrollTop = container.scrollHeight; |
|
|
|
console.log(container.scrollTop) |
|
|
|
console.log(container.scrollHeight) |
|
|
|
}, 100); // 延迟 100ms |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
saveMessage(message) { |
|
|
|
const messages = JSON.parse(localStorage.getItem('messages')) || []; |
|
|
|
messages.push(message); // 将新消息添加到消息数组中 |
|
|
|
@ -224,14 +329,16 @@ export default { |
|
|
|
.message { |
|
|
|
display: flex; |
|
|
|
margin-bottom: 12px; |
|
|
|
align-items: flex-start; |
|
|
|
flex-direction: column; /* 垂直排列时间和内容 */ |
|
|
|
} |
|
|
|
|
|
|
|
.message.user { |
|
|
|
justify-content: flex-end; |
|
|
|
align-items: flex-end; |
|
|
|
} |
|
|
|
|
|
|
|
.message.assistant { |
|
|
|
justify-content: flex-start; |
|
|
|
align-items: flex-start; |
|
|
|
} |
|
|
|
|
|
|
|
.bubble { |
|
|
|
@ -267,7 +374,6 @@ export default { |
|
|
|
font-weight: 500; |
|
|
|
} |
|
|
|
.input-box { |
|
|
|
height: 75px; |
|
|
|
width: 100%; |
|
|
|
padding: 12px 16px; |
|
|
|
border: none; |
|
|
|
@ -454,4 +560,54 @@ export default { |
|
|
|
background-color: #e9ecef; |
|
|
|
color: #333; |
|
|
|
} |
|
|
|
.message.assistant .time{ |
|
|
|
text-align: left; |
|
|
|
color: #A5A5A5; |
|
|
|
margin-bottom: 5px; |
|
|
|
font-size: 12px; |
|
|
|
} |
|
|
|
.message.user .time{ |
|
|
|
text-align: right; |
|
|
|
color: #A5A5A5; |
|
|
|
margin-bottom: 5px; |
|
|
|
font-size: 12px; |
|
|
|
} |
|
|
|
.word{ |
|
|
|
border: 1px solid rgba(17,17,51,.1); |
|
|
|
border-radius: 8px; |
|
|
|
justify-content: flex-start; |
|
|
|
align-items: center; |
|
|
|
width: 24%; |
|
|
|
min-width: 149px; |
|
|
|
max-width: 206px; |
|
|
|
padding: 9px 6px; |
|
|
|
display: flex; |
|
|
|
margin-left: 10px; |
|
|
|
position: relative; |
|
|
|
} |
|
|
|
.wordName{ |
|
|
|
overflow: hidden; /* 隐藏超出部分 */ |
|
|
|
display: -webkit-box; /* 使用 webkit 的盒子模型 */ |
|
|
|
-webkit-box-orient: vertical; /* 设置为垂直方向 */ |
|
|
|
-webkit-line-clamp: 1; /* 限制为两行 */ |
|
|
|
text-overflow: ellipsis; /* 显示省略号 */ |
|
|
|
} |
|
|
|
.word:hover .close-btn { |
|
|
|
display: block; /* 悬浮时显示X按钮 */ |
|
|
|
} |
|
|
|
.close-btn{ |
|
|
|
position: absolute; |
|
|
|
|
|
|
|
width: 20px; /* 设置适合的图片大小 */ |
|
|
|
height: 20px; |
|
|
|
cursor: pointer; |
|
|
|
padding: 5px; |
|
|
|
box-sizing: border-box; |
|
|
|
top: -8px; |
|
|
|
right: -7px; |
|
|
|
border: 1px solid rgba(17,17,51,.1); |
|
|
|
border-radius: 50%; |
|
|
|
background-color: #fff; |
|
|
|
display: none; |
|
|
|
} |
|
|
|
</style> |