feat: 历史记录

main
许宏杰 2 months ago
parent aed250da13
commit e011329313

@ -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 {

@ -2,6 +2,7 @@
export enum ModuleTypeEnum {
SYSTEM = 'sys',
PROJECT = 'project',
MESSAGE = 'tHistoricalReply'
}
// 请求结果集

@ -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

@ -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(

@ -2,35 +2,9 @@
<div class="history-box">
<div class="history-title">聊天历史记录</div>
<div class="history-list">
<div class="history-item">
<div class="history-row-title">根据2024年度业务根据2024年度业务根据2024年度业务</div>
<div class="history-row-icon">
<n-icon size="14" color="#F25D44" class="del-icon">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32">
<path d="M12 12h2v12h-2z" fill="currentColor"></path>
<path d="M18 12h2v12h-2z" fill="currentColor"></path>
<path d="M4 6v2h2v20a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8h2V6zm4 22V8h16v20z" fill="currentColor"></path>
<path d="M12 2h8v2h-8z" fill="currentColor"></path>
</svg>
</n-icon>
</div>
</div>
<div class="history-item">
<div class="history-row-title">根据2024年度业务根据2024年度业务根据2024年度业务</div>
<div class="history-row-icon">
<n-icon size="14" color="#F25D44" class="del-icon">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32">
<path d="M12 12h2v12h-2z" fill="currentColor"></path>
<path d="M18 12h2v12h-2z" fill="currentColor"></path>
<path d="M4 6v2h2v20a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8h2V6zm4 22V8h16v20z" fill="currentColor"></path>
<path d="M12 2h8v2h-8z" fill="currentColor"></path>
</svg>
</n-icon>
</div>
</div>
<div class="history-item">
<div class="history-row-title">根据2024年度业务根据2024年度业务根据2024年度业务</div>
<div class="history-row-icon">
<div class="history-item" v-for="item in list" :key="item.id" @click="getMessageInfo(item.id)">
<div class="history-row-title">{{ formatFristIssue(item) }}</div>
<div class="history-row-icon" @click.stop="delMessageItem(item.id)">
<n-icon size="14" color="#F25D44" class="del-icon">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32">
<path d="M12 12h2v12h-2z" fill="currentColor"></path>
@ -50,20 +24,56 @@
</div>
</template>
<script setup lang="ts">
import { projectListApi } from '@/api/path'
import { onMounted } from 'vue'
<script setup>
import { onMounted, ref } from 'vue'
import { projectListApi, deleteProjectApi, historyMessageRoomList,historyMessageRoomDel } from '@/api/path'
import { useRouter } from 'vue-router'
let list = ref([])
const router = useRouter()
//List
const fetchList = async () => {
const res = await projectListApi()
console.log(res)
}
onMounted(()=>{
fetchList()
//
const delProjectItem = async id => {
const res = await deleteProjectApi({ ids: id })
}
const formatFristIssue = value => {
const data = JSON.parse(value.content)
return data.fristIssue
}
//list
const messageList = async () => {
const res = await historyMessageRoomList()
list.value = res.data.records
}
//
const delMessageItem = async (id) => {
const res = await historyMessageRoomDel(id)
if(res){
messageList()
}
}
const getMessageInfo = id => {
router.push('/chat/' + id)
}
onMounted(() => {
// fetchList()
// messageList()
})
defineExpose({
fetchList
});
fetchList,
messageList
})
</script>
<style lang="scss" scoped>

@ -30,13 +30,17 @@
<script setup>
import { useRoute, useRouter } from 'vue-router'
import { createProjectApi } from '@/api/path'
import { getUUID } from '@/utils'
import { createProjectApi, historyMessageRoom } from '@/api/path'
import { getUUID } from '@/utils'
import { ResultEnum } from '@/enums/httpEnum'
import AiLogo from '../AI/components/logo/index.vue'
import AiHistory from '../AI/components/history/index.vue'
import { ref } from 'vue'
import useMessageRoomStore from '@/store/modules/messageRoom'
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
const systemStore = useSystemStore()
const useMessageRoom = useMessageRoomStore()
const router = useRouter()
const route = useRoute()
const history = ref(null)
@ -50,31 +54,44 @@ const getCurrentRoute = path => {
return route.path.includes(path)
}
const handlerPath = async (path, index) => {
if (index == 1) {
if(history.value){
// history.value.fetchList()
}
try {
//
const res = await createProjectApi({
//
projectName: getUUID(),
// remarks
remarks: null,
//
indexImage: null
})
if (res && res.code === ResultEnum.SUCCESS) {
const { id } = res.data
router.push(path + '/' + id)
}
} catch (error) {
window['$message'].error(window['$t']('project.create_failure'))
}
}else{
router.push(path + '/' + Date.now()).catch(() => {})
}
router.push(path + '/' + Date.now())
// if (index == 1) {
// if (history.value) {
// // history.value.fetchList()
// }
// try {
// //
// const res = await createProjectApi({
// //
// projectName: getUUID(),
// // remarks
// remarks: null,
// //
// indexImage: null
// })
// if (res && res.code === ResultEnum.SUCCESS) {
// const { id } = res.data
// router.push(path + '/' + id)
// }
// } catch (error) {
// window['$message'].error(window['$t']('project.create_failure'))
// }
// } else {
// if (useMessageRoom.messageRoom.list.length > 0) {
// //
// const jsonData = JSON.stringify(useMessageRoom.messageRoom)
// await historyMessageRoom({ content: jsonData, createUserId: systemStore.userInfo.userId || 1 })
// history.value.messageList()
// useMessageRoom.resetList({
// fristIssue:undefined,
// list:[]
// })//
// router.push(path + '/' + Date.now())
// } else {
// history.value.messageList()
// router.push(path + '/' + Date.now())
// }
// }
}
</script>

Loading…
Cancel
Save