<template>
|
<div class="chat-box">
|
<div class="chat-box-left">
|
<div class="new-chat">
|
<el-icon>
|
<Plus />
|
</el-icon>
|
<div>New conversation</div>
|
</div>
|
<div class="chat-list" v-for="(item, index) in pageData.historylist">
|
<div :title="item.content" @click="goAi(item)">{{ item.content }}</div>
|
</div>
|
</div>
|
<div class="chat-box-right">
|
<Header class="header"></Header>
|
<!-- 聊天框内容容器 -->
|
<div class="chat-box-content" ref="messagesContainer">
|
<!-- 当前时间显示 -->
|
<div class="chat-date">{{ currentTime }}</div>
|
<!-- 底部信息展示 -->
|
<div class="chat-back-info">
|
<!-- 头像 -->
|
<div class="back-avator">
|
<img src="../../assets/images/home/AI_logo.png" alt="" />
|
</div>
|
<!-- 基础图书信息 -->
|
<div class="base-book-box">
|
您好!我是您的AI智能助手,专注于小分子结构领域!我可以帮助您轻松获取与小分子结构相关的信息。您可以这样问我:“Aspirin是什么?”“xx的物理化学属性都是什么?”让小分子结构知识触手可及!
|
</div>
|
</div>
|
<!-- 消息列表 -->
|
<div v-for="(item, index) in message" :key="index" class="chat-box-content-item">
|
<div v-if="item.type === 'user'" class="chat-date">{{ item.time }}</div>
|
<div :class="['message', item.type === 'user' ? 'user-message' : 'assistant-message']">
|
<!-- 助手头像 -->
|
<el-avatar class="assistant-avatar" :size="screenWidth > 375 ? 60 : 30"
|
:src="[item.type === 'user' ? userProfilePicture : assistantAvatar]" />
|
<!-- 消息内容 -->
|
<div :class="['message-content', item.type === 'user' ? 'user-message-content' : '']">
|
<!-- 用户消息 -->
|
<div class="user-message-text" v-if="item.type === 'user'" v-html="item.content"></div>
|
<!-- AI 图片消息 -->
|
<div :class="['message-text', 'requestText' + index].join(' ')"
|
v-if="item.type != 'user' && item.txtType == 'txt'">
|
<p class="message-text-title">
|
AI智能助手为您找到以下的信息内容如下:
|
</p>
|
<iframe class="message-text-iframe" ref="iframeRef" v-if="item.iframeSrc != ''"
|
:src="item.iframeSrc" frameborder="0"></iframe>
|
<div v-html="item.content"></div>
|
<p class="message-text-titleOne">以上内容由AI生成,仅供参考。</p>
|
</div>
|
<!-- 消息底部时间 -->
|
<div class="message-footer" v-if="item.type != 'user'">
|
<span class="message-time">{{ item.time }}</span>
|
</div>
|
</div>
|
</div>
|
<!-- 加载中状态 -->
|
<div v-if="loading && index == message.length - 1"
|
class="message assistant-message loading-message">
|
<el-avatar class="assistant-avatar" :size="screenWidth > 375 ? 60 : 30"
|
:src="assistantAvatar" />
|
<div :class="['message-content', item.type === 'user' ? 'user-message-content' : '']">
|
<div class="message-text-loading">
|
<span class="dot-loading">思考中...</span>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
<!-- 输入框 -->
|
<div class="chat-footer">
|
<!-- 输入框 -->
|
<div class="chat-text">
|
<el-input type="textarea" :autosize="{ minRows: 3, maxRows: 3 }" placeholder="" v-model="inputValue"
|
@keyup.enter="handleEnter($event)" />
|
</div>
|
<!-- 功能选择区域 -->
|
<div class="select">
|
<div class="select-right">
|
<div class="select-item">
|
<img @click="sendMsg()" :src="currentImage" alt="" />
|
</div>
|
</div>
|
</div>
|
</div>
|
<div class="main-footer">
|
Information displayed here is AI model generated and should not be considered as legal, finance or
|
investment advice. You should always seek advice from a qualified <br />professional. Request
|
consultation.
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script lang="ts" setup>
|
import { ref, reactive, nextTick, computed, onMounted } from 'vue'
|
import type { aiDetails } from '@/types/aiDetails'
|
import current from '@/assets/images/ai/current.png'
|
import noCurrent from '@/assets/images/ai/noCurrent.png'
|
import dayjs from 'dayjs'
|
import Header from '@/layout/components/headerPage.vue'
|
import defaultImg from '../../assets/images/home/AI_logo.png'
|
import userIcon from '../../assets/images/ai/userImg.png'
|
import request from '@/plugin/axios/index'
|
const screenWidth = ref(window.innerWidth)
|
const assistantAvatar = defaultImg
|
const userProfilePicture = userIcon
|
const pageData = reactive<aiDetails>({
|
historylist: [
|
{
|
content: "What is the quarterly water bill?",
|
},
|
{
|
content: "How much are the council rates per quarter?",
|
},
|
{
|
content: "What are the quarterly strata fees?",
|
},
|
{
|
content: "What are the quarterly strata fees?",
|
},
|
],
|
})
|
const inputValue = ref('')
|
const message = ref<any>([])
|
const loading = ref(false)
|
const autoScroll = ref(true)
|
const messagesContainer = ref<HTMLElement | null>(null)
|
const currentTime = ref(dayjs(new Date()).format('MM/DD HH:mm:ss'))
|
const currentImage = computed(() => {
|
return inputValue.value.trim() === '' ? noCurrent : current;
|
});
|
// 从本地存储加载消息
|
onMounted(() => {
|
// getCommonQyestuion()
|
// 删除本地缓存
|
localStorage.removeItem('chatMessages')
|
const savedMessages = localStorage.getItem('chatMessages')
|
if (savedMessages) {
|
message.value = JSON.parse(savedMessages)
|
}
|
scrollToBottom()
|
screenWidth.value = window.innerWidth
|
|
window.addEventListener('message', function (event) {
|
console.log(event, "event");
|
if (event.data.type == 'toggleFullScreen') {
|
window.open(event.data.data)
|
} else if (event.data.type == 'download') {
|
const link = document.createElement('a')
|
link.href = event.data.data
|
link.download = event.data.data
|
document.body.appendChild(link)
|
link.click()
|
document.body.removeChild(link)
|
}
|
})
|
})
|
|
const scrollToBottom = async () => {
|
if (!autoScroll.value) return
|
await nextTick()
|
if (messagesContainer.value) {
|
const dom1 = document.querySelector('.dot-loading')
|
const dom = document.querySelector('.requestText' + (message.value.length - 1))
|
dom1?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
dom?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
}
|
}
|
|
|
|
interface ChatMessage {
|
content: string
|
type: 'user' | 'assistant'
|
time: string
|
txtType: 'txt' | 'List'
|
currentContentIndex: 0
|
isEnd: boolean
|
iframeSrc: string
|
}
|
|
const handleEnter = (event: any) => {
|
event.preventDefault()
|
inputValue.value = inputValue.value.replace(/\n/g, '')
|
// 调用发送消息的方法
|
sendMsg()
|
}
|
const sendMsg = async () => {
|
if (!inputValue.value.trim() || loading.value) return
|
const userMessage: ChatMessage = {
|
content: inputValue.value,
|
type: 'user',
|
time: new Date().toLocaleTimeString(),
|
txtType: 'txt',
|
currentContentIndex: 0,
|
isEnd: false,
|
iframeSrc: '',
|
}
|
|
message.value.push(userMessage)
|
const messageToSend = inputValue.value
|
inputValue.value = ''
|
try {
|
await getData(messageToSend) // 使用 await 等待 getData 完成
|
console.log(message, "message");
|
|
} catch (error) {
|
console.error('发送消息失败', error)
|
}
|
}
|
|
|
// 获取数据
|
const getData = async (messageToSend: any) => {
|
loading.value = true
|
try {
|
const response = await request({
|
url: '/v1/workflows/run',
|
method: 'post',
|
data: {
|
inputs: {
|
question: messageToSend,
|
},
|
parent_message_id: null,
|
response_mode: 'blocking',
|
conversation_id: '',
|
user: 'abc-123',
|
files: [],
|
},
|
})
|
try {
|
const answerAgain = JSON.parse((response as any).data.outputs.text)
|
answerAgain.msg = answerAgain.msg.replace(/\n/g, '<br>')
|
console.log(answerAgain, 'answerAgain');
|
answerAgain.iframeSrc = '';
|
if (answerAgain.model && answerAgain.model[0].name == 'Conformer3D_COMPOUND_CID_2244') {
|
answerAgain.iframeSrc = 'http://182.92.203.7:3007/showModel/?name=' + answerAgain.model[0].name;
|
}
|
if (answerAgain.code == 1) {
|
const assistantMessage: ChatMessage = {
|
content: answerAgain.data,
|
type: 'assistant',
|
time: new Date().toLocaleTimeString(),
|
txtType: 'List',
|
currentContentIndex: 0,
|
isEnd: false,
|
iframeSrc: answerAgain.iframeSrc,
|
}
|
message.value.push(assistantMessage)
|
} else if (answerAgain.code == 2 || answerAgain.code == 3) {
|
const assistantMessage: ChatMessage = {
|
content: answerAgain.msg,
|
type: 'assistant',
|
time: new Date().toLocaleTimeString(),
|
txtType: 'txt',
|
currentContentIndex: 0,
|
isEnd: false,
|
iframeSrc: answerAgain.iframeSrc,
|
}
|
console.log(assistantMessage);
|
message.value.push(assistantMessage)
|
loading.value = false
|
// 保存消息到本地存储
|
localStorage.setItem('chatMessages', JSON.stringify(message.value))
|
}
|
console.log(message, "message");
|
} catch (error) {
|
console.log(error)
|
}
|
} catch (error) {
|
const assistantMessage: ChatMessage = {
|
content: '当前操作遇到一些问题,请稍后再试。',
|
type: 'assistant',
|
time: new Date().toLocaleTimeString(),
|
txtType: 'txt',
|
currentContentIndex: 0,
|
isEnd: false,
|
iframeSrc: "",
|
}
|
message.value.push(assistantMessage)
|
console.error('发送消息失败', error)
|
} finally {
|
loading.value = false
|
}
|
}
|
|
|
|
|
</script>
|
|
<style lang="less" scoped>
|
.chat-box {
|
display: flex;
|
height: 100%;
|
width: 100%;
|
|
}
|
|
.chat-box-left {
|
width: 14%;
|
border-right: 1px solid #F0F0F0;
|
padding: 13px 17px;
|
|
.new-chat {
|
height: 34px;
|
background: linear-gradient(90deg, #006CB6 0%, #01644C 100%);
|
border-radius: 30px 30px 30px 30px;
|
margin-top: 45px;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
color: #fff;
|
cursor: pointer;
|
|
div {
|
margin-left: 5px;
|
font-weight: 400;
|
font-size: 12px;
|
}
|
}
|
|
.chat-list {
|
width: 100%;
|
margin-top: 28px;
|
|
div {
|
line-height: 1.5em;
|
cursor: pointer;
|
width: 100%;
|
margin-top: 20px;
|
overflow: hidden;
|
text-wrap: nowrap;
|
}
|
}
|
}
|
|
.message {
|
display: flex;
|
margin-bottom: 24px;
|
align-items: flex-start;
|
animation: slideIn 0.3s ease;
|
animation-fill-mode: forwards;
|
max-width: 85%;
|
border-radius: 12px;
|
// box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
padding: 16px;
|
}
|
|
.assistant-avatar {
|
width: 32px;
|
height: auto;
|
}
|
|
.user-message {
|
flex-direction: row-reverse;
|
margin-left: auto;
|
}
|
|
.assistant-message {
|
background-color: #f7fffc;
|
}
|
|
|
|
|
.chat-box-right {
|
width: 86%;
|
margin: 0 auto;
|
display: flex;
|
flex-direction: column;
|
justify-content: center;
|
align-items: center;
|
|
|
|
.chat-box-content {
|
width: 62%;
|
margin: 0 auto;
|
height: calc(100vh - 150px);
|
display: flex;
|
flex-direction: column;
|
justify-content: flex-start;
|
overflow: auto;
|
align-items: flex-start;
|
|
.chat-send {
|
width: 100%;
|
display: flex;
|
flex-direction: column;
|
justify-content: space-between;
|
align-items: flex-end;
|
margin-bottom: 20px;
|
|
.chat-send-info {
|
width: 263px;
|
height: 40px;
|
background: #af8b56;
|
border-radius: 20px;
|
line-height: 40px;
|
padding: 0 20px;
|
color: #fff;
|
}
|
|
.chat-message {
|
width: 263px;
|
height: 40px;
|
background: #fff;
|
border-radius: 20px;
|
line-height: 40px;
|
padding: 0 20px;
|
color: #000;
|
}
|
}
|
|
.chat-date {
|
color: #999;
|
width: 100%;
|
text-align: center;
|
margin-bottom: 30px;
|
margin-top: 30px;
|
}
|
|
.chat-send {
|
width: 100%;
|
display: flex;
|
justify-content: flex-end;
|
margin-bottom: 20px;
|
|
.chat-send-info {
|
width: 263px;
|
height: 40px;
|
background: #af8b56;
|
border-radius: 20px;
|
line-height: 40px;
|
padding: 0 20px;
|
color: #fff;
|
}
|
}
|
|
.chat-back-info {
|
margin-bottom: 20px;
|
display: flex;
|
justify-content: flex-start;
|
// min-height: 90px;
|
padding: 16px;
|
|
.back-avator {
|
margin-right: 10px;
|
|
img {
|
width: 32px;
|
}
|
}
|
|
.base-book-box {
|
display: flex;
|
width: 800px;
|
padding: 20px 47px;
|
box-sizing: border-box;
|
background-color: #f7fffc;
|
border-radius: 20px;
|
line-height: 1.5em;
|
}
|
}
|
|
.back-item {
|
width: 349px;
|
height: auto;
|
background: #ffffff;
|
border-radius: 20px;
|
margin-left: 100px;
|
margin-bottom: 20px;
|
|
.back-item-title {
|
width: 80%;
|
height: 60px;
|
display: flex;
|
align-items: center;
|
padding: 0 10px;
|
margin: auto;
|
border-bottom: 1px solid #e9d8bf;
|
}
|
|
.hot-question {
|
cursor: pointer;
|
|
&:hover {
|
color: #d2a25b;
|
}
|
}
|
|
img {
|
margin-right: 10px;
|
}
|
|
ul li {
|
list-style: none;
|
margin: 20px 0 20px 0;
|
display: flex;
|
justify-content: flex-start;
|
align-items: center;
|
}
|
|
.chat-change {
|
display: flex;
|
justify-content: flex-end;
|
align-items: center;
|
padding: 0 20px;
|
color: #d2a25b;
|
margin-bottom: 10px;
|
cursor: pointer;
|
|
img {
|
cursor: pointer;
|
}
|
}
|
}
|
|
.chat-box-content-item {
|
width: 100%;
|
}
|
}
|
|
.chat-box-content::-webkit-scrollbar {
|
width: 1px;
|
}
|
|
/* 隐藏水平滚动条 */
|
.chat-box-content::-webkit-scrollbar {
|
height: 0;
|
}
|
|
|
.message-content {
|
display: inline-block;
|
max-width: 80%;
|
background: #DEDEDE;
|
margin-left: 10px;
|
border-radius: 10px 0px 10px 10px;
|
padding: 14px 12px;
|
margin-top: 5px;
|
margin-right: 10px;
|
}
|
|
.user-message-text {
|
font-weight: 400;
|
font-size: 14px;
|
color: #000000;
|
line-height: 1.5em;
|
}
|
|
.message-text {
|
min-width: 600px;
|
padding: 0px 40px;
|
border-radius: 12px;
|
word-wrap: break-word;
|
line-height: 1.6;
|
font-size: 0.95rem;
|
transition: all 0.3s ease;
|
white-space: pre-wrap;
|
color: #333;
|
|
.message-text-title {
|
font-size: 16px;
|
color: #999;
|
line-height: 35px;
|
padding: 0px 0 10px 0;
|
}
|
|
.message-text-iframe {
|
width: 100%;
|
height: 400px;
|
margin-bottom: 10px;
|
}
|
|
.message-text-titleOne {
|
text-align: right;
|
color: #fe7313;
|
font-size: 10px;
|
padding-bottom: 5px;
|
border-bottom: 1px solid #e9d8bf;
|
}
|
|
.message-text-changeOne {
|
display: flex;
|
align-items: center;
|
justify-content: flex-end;
|
padding: 10px 0 0 0;
|
|
span {
|
font-size: 14px;
|
font-family:
|
Microsoft YaHei,
|
Microsoft YaHei-Regular;
|
font-weight: 400;
|
text-align: left;
|
color: #d2a25b;
|
line-height: 35px;
|
}
|
}
|
}
|
|
.chat-footer {
|
width: 62%;
|
min-width: 800px;
|
border-radius: 8px 8px 8px 8px;
|
border: 1px solid #E8E8E8;
|
padding: 9px 13px;
|
box-sizing: border-box;
|
margin-bottom: 10px;
|
margin-top: 14px;
|
}
|
|
::v-deep(.chat-text) {
|
// height: 100%;
|
display: flex;
|
align-items: center;
|
margin-bottom: 10px;
|
|
.el-textarea__inner {
|
overflow: auto;
|
height: 100% !important;
|
border: none !important;
|
outline: none !important;
|
box-shadow: none !important;
|
background-color: transparent !important;
|
resize: none !important;
|
}
|
|
img {
|
cursor: pointer;
|
min-height: 25px;
|
}
|
}
|
|
.select {
|
width: 100%;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
|
.select-left,
|
.select-right {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
justify-content: flex-start;
|
|
.upload-demo {
|
height: 24px;
|
}
|
|
svg {
|
cursor: pointer;
|
}
|
|
.select-item {
|
display: flex;
|
align-items: center;
|
padding: 2px 10px;
|
box-sizing: border-box;
|
border: 1px solid #e9d8bf;
|
border-radius: 15px;
|
|
font-size: 14px;
|
font-family:
|
Microsoft YaHei,
|
Microsoft YaHei-Regular;
|
font-weight: 400;
|
color: #e1c49a;
|
|
img {
|
height: 34px;
|
cursor: pointer;
|
}
|
}
|
}
|
|
.select-right {
|
display: flex;
|
align-items: center;
|
justify-content: flex-end;
|
|
.select-item {
|
border: 0;
|
}
|
}
|
}
|
|
.main-footer {
|
text-align: center;
|
font-weight: 400;
|
font-size: 12px;
|
color: #BABABA;
|
line-height: 1.4em;
|
}
|
|
}
|
</style>
|