|
|
|
@ -78,18 +78,23 @@ import { LineChart } from './class/LineChart.ts'
|
|
|
|
|
import { BarChart } from './class/BarChart.ts'
|
|
|
|
|
|
|
|
|
|
import { ref, reactive, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
|
|
|
|
import { historyMessageRoomById } from '@/api/path'
|
|
|
|
|
import userIcon from '@/assets/images/ai/user-icon.png'
|
|
|
|
|
import aiIcon from '@/assets/images/ai/ai-icon.png'
|
|
|
|
|
import { useMessage } from 'naive-ui'
|
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
import useMessageRoomStore from '@/store/modules/messageRoom'
|
|
|
|
|
|
|
|
|
|
const useMessageRoom = useMessageRoomStore()
|
|
|
|
|
|
|
|
|
|
let infoData = ref({})
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
const messageDialog = useMessage()
|
|
|
|
|
const scrollContainer = ref<HTMLDivElement | null>(null)
|
|
|
|
|
// const chartContainer = ref<HTMLDivElement | null>(null)
|
|
|
|
|
let loading = ref(false)
|
|
|
|
|
let keyWord = ref('')
|
|
|
|
|
let messages: AiChatroomType[] = reactive([])
|
|
|
|
|
let messages= reactive([])
|
|
|
|
|
let chartInstance: LineChart | null = null
|
|
|
|
|
|
|
|
|
|
// 单系列数值数组示例
|
|
|
|
@ -107,11 +112,10 @@ const handleSend = async () => {
|
|
|
|
|
messageDialog.warning('请先输入需要统计的数据!')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*保存用户提问信息
|
|
|
|
|
*/
|
|
|
|
|
messages.push({
|
|
|
|
|
setMessageStore({
|
|
|
|
|
from: 'user',
|
|
|
|
|
text: keyWord.value,
|
|
|
|
|
time: moment().format('YYYY/MM/DD HH:mm:ss')
|
|
|
|
@ -119,10 +123,10 @@ const handleSend = async () => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
const res = await getAiMsg({ prompt: keyWord.value })
|
|
|
|
|
console.log('回答',res)
|
|
|
|
|
console.log('回答', res)
|
|
|
|
|
//保存AI回答
|
|
|
|
|
if (res.type) {
|
|
|
|
|
messages.push({
|
|
|
|
|
setMessageStore({
|
|
|
|
|
from: 'ai',
|
|
|
|
|
text: '以图表形式展示',
|
|
|
|
|
chartType: res.chartType,
|
|
|
|
@ -148,7 +152,7 @@ const handleSend = async () => {
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
//纯文本信息
|
|
|
|
|
messages.push({
|
|
|
|
|
setMessageStore({
|
|
|
|
|
from: 'ai',
|
|
|
|
|
text: res,
|
|
|
|
|
time: moment().format('YYYY/MM/DD HH:mm:ss')
|
|
|
|
@ -158,7 +162,7 @@ const handleSend = async () => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
} catch (error) {
|
|
|
|
|
//报错纯文本信息
|
|
|
|
|
messages.push({
|
|
|
|
|
setMessageStore({
|
|
|
|
|
from: 'ai',
|
|
|
|
|
text: '服务器繁忙,请稍后再试。',
|
|
|
|
|
time: moment().format('YYYY/MM/DD HH:mm:ss')
|
|
|
|
@ -167,6 +171,22 @@ const handleSend = async () => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const setMessageStore = (messageItem: any) => {
|
|
|
|
|
messages.push(messageItem)
|
|
|
|
|
|
|
|
|
|
useMessageRoom.setMessage(messages[0].text, {
|
|
|
|
|
from: messageItem.from,
|
|
|
|
|
text: messageItem.text,
|
|
|
|
|
chartType: messageItem.chartType,
|
|
|
|
|
time: messageItem.time,
|
|
|
|
|
chartInstanceItem: null,
|
|
|
|
|
chartInstanceActiveIndex: 0,
|
|
|
|
|
xData: messageItem.xData,
|
|
|
|
|
yData: messageItem.yData
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const hanlderStyleColor = (type: string, fatherIndex: number, childIndex: number) => {
|
|
|
|
|
const messagesItem = messages[fatherIndex]
|
|
|
|
|
if (messagesItem.chartInstanceActiveIndex == childIndex) return
|
|
|
|
@ -174,34 +194,35 @@ const hanlderStyleColor = (type: string, fatherIndex: number, childIndex: number
|
|
|
|
|
messagesItem.chartInstanceItem?.changeColorStyle(childIndex)
|
|
|
|
|
}
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
// route.path
|
|
|
|
|
// const result = checkLastPartIsTimestamp(route.path);
|
|
|
|
|
// if(result){
|
|
|
|
|
// //时间戳
|
|
|
|
|
// }else{
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// console.log(result )
|
|
|
|
|
|
|
|
|
|
getInfo()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const checkLastPartIsTimestamp = (str:string)=> {
|
|
|
|
|
// 找到最后一个 / 的位置
|
|
|
|
|
const lastSlashIndex = str.lastIndexOf('/');
|
|
|
|
|
if (lastSlashIndex === -1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 截取最后一个 / 后面的值
|
|
|
|
|
const lastPart = str.slice(lastSlashIndex + 1);
|
|
|
|
|
// 尝试将其转换为数字
|
|
|
|
|
const num = Number(lastPart);
|
|
|
|
|
// 检查是否为有效数字
|
|
|
|
|
if (isNaN(num)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 检查是否在合理的时间戳范围内(这里简单假设从 2000 年到 2100 年)
|
|
|
|
|
const minTimestamp = new Date('2024-01-01').getTime();
|
|
|
|
|
const maxTimestamp = new Date('2124-01-01').getTime();
|
|
|
|
|
return num >= minTimestamp && num <= maxTimestamp;
|
|
|
|
|
const getInfo = async () => {
|
|
|
|
|
const id = checkLastPartIsTimestamp(route.path)
|
|
|
|
|
const res = await historyMessageRoomById(id)
|
|
|
|
|
if (res?.data) {
|
|
|
|
|
res.data.content = JSON.parse(res.data.content)
|
|
|
|
|
infoData.value = res.data
|
|
|
|
|
// messages = infoData.value.content.list
|
|
|
|
|
infoData.value.content.list.forEach(item => {
|
|
|
|
|
messages.push(item);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// console.log(infoData.value.content.list)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const checkLastPartIsTimestamp = (str: string) => {
|
|
|
|
|
// 找到最后一个 / 的位置
|
|
|
|
|
const lastSlashIndex = str.lastIndexOf('/')
|
|
|
|
|
if (lastSlashIndex === -1) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
// 截取最后一个 / 后面的值
|
|
|
|
|
const lastPart = str.slice(lastSlashIndex + 1)
|
|
|
|
|
return lastPart
|
|
|
|
|
}
|
|
|
|
|
// 监听messages变化,自动滚动到底部
|
|
|
|
|
watch(
|
|
|
|
|