diff --git a/src/api/path/project.api.ts b/src/api/path/project.api.ts index 6d9029d..435c297 100644 --- a/src/api/path/project.api.ts +++ b/src/api/path/project.api.ts @@ -3,6 +3,7 @@ import { httpErrorHandle } from '@/utils' import { ContentTypeEnum, RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum' import { ProjectItem, ProjectDetail } from './project' + // * 项目列表 export const projectListApi = async (data?: object) => { try { @@ -13,6 +14,43 @@ export const projectListApi = async (data?: object) => { } } + +// 新增聊天室历史记录 + +export const historyMessageRoom = async(data: object)=>{ + try{ + const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.MESSAGE}`, data) + return res + }catch{ + httpErrorHandle() + } +} + +export const historyMessageRoomList = async(data?: object)=>{ + try{ + const res = await http(RequestHttpEnum.GET)(`${ModuleTypeEnum.MESSAGE}`, data) + return res + }catch{ + httpErrorHandle() + } +} + +export const historyMessageRoomById = async(id:any)=>{ + try{ + const res = await http(RequestHttpEnum.GET)(`${ModuleTypeEnum.MESSAGE}/${id}`, ) + return res + }catch{ + httpErrorHandle() + } +} +export const historyMessageRoomDel= async(id:any)=>{ + try{ + const res = await http(RequestHttpEnum.DELETE)(`${ModuleTypeEnum.MESSAGE}/${id}`, ) + return res + }catch{ + httpErrorHandle() + } +} // * 新增项目 export const createProjectApi = async (data: object) => { try { diff --git a/src/enums/httpEnum.ts b/src/enums/httpEnum.ts index fb21205..1bbe91e 100644 --- a/src/enums/httpEnum.ts +++ b/src/enums/httpEnum.ts @@ -2,6 +2,7 @@ export enum ModuleTypeEnum { SYSTEM = 'sys', PROJECT = 'project', + MESSAGE = 'tHistoricalReply' } // 请求结果集 diff --git a/src/store/modules/messageRoom/index.js b/src/store/modules/messageRoom/index.js new file mode 100644 index 0000000..3cce59f --- /dev/null +++ b/src/store/modules/messageRoom/index.js @@ -0,0 +1,22 @@ +import { defineStore } from 'pinia' +const useMessageRoomStore = defineStore('useMessageRoomStore', { + state: () => ({ + messageRoom: { + fristIssue:undefined, + list:[] + } + }), + actions: { + setMessage(fristIssue,item) { + if (this.messageRoom.list.length >= 35) return + if(!this.messageRoom.fristIssue) this.messageRoom.fristIssue = fristIssue + this.messageRoom.list.push(item) + }, + resetList(obj){ + this.messageRoom = obj + } + } +}) + + +export default useMessageRoomStore \ No newline at end of file diff --git a/src/views/AI/chat/index.vue b/src/views/AI/chat/index.vue index 87a3fed..f078bf0 100644 --- a/src/views/AI/chat/index.vue +++ b/src/views/AI/chat/index.vue @@ -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(null) // const chartContainer = ref(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( diff --git a/src/views/AI/components/history/index.vue b/src/views/AI/components/history/index.vue index 5dce0ac..3efdc42 100644 --- a/src/views/AI/components/history/index.vue +++ b/src/views/AI/components/history/index.vue @@ -2,35 +2,9 @@
聊天历史记录
-
-
根据2024年度业务根据2024年度业务根据2024年度业务
-
- - - - - - - - -
-
-
-
根据2024年度业务根据2024年度业务根据2024年度业务
-
- - - - - - - - -
-
-
-
根据2024年度业务根据2024年度业务根据2024年度业务
-
+
+
{{ formatFristIssue(item) }}
+
@@ -50,20 +24,56 @@
-