【增加】AI 对话增加 GROUP 分组

pull/449/head^2
cherishsince 2024-05-16 11:28:31 +08:00
parent ad02983098
commit f21991f4fc
1 changed files with 102 additions and 48 deletions

View File

@ -23,10 +23,14 @@
<!-- 左中间对话列表 -->
<div class="conversation-list">
<!-- TODO @fain置顶聊天记录一星期钱30天前前端对数据重新做一下分组或者后端接口改一下 -->
<div>
<el-text class="mx-1" size="small" tag="b">置顶</el-text>
<div v-for="conversationKey in Object.keys(conversationMap)" :key="conversationKey" >
<div v-if="conversationMap[conversationKey].length">
<el-text class="mx-1" size="small" tag="b">{{conversationKey}}</el-text>
</div>
<el-row v-for="conversation in conversationList" :key="conversation.id" @click="handleConversationClick(conversation.id)">
<el-row
v-for="conversation in conversationMap[conversationKey]"
:key="conversation.id"
@click="handleConversationClick(conversation.id)">
<div
:class="conversation.id === conversationId ? 'conversation active' : 'conversation'"
@click="changeConversation(conversation.id)"
@ -48,6 +52,7 @@
</el-row>
</div>
</div>
</div>
<!-- 左底部工具栏 -->
<div class="tool-box">
<div @click="handleRoleRepository">
@ -193,7 +198,7 @@
</template>
<script setup lang="ts">
import { ChatMessageApi, ChatMessageSendVO, ChatMessageVO } from '@/api/ai/chat/message'
import {ChatMessageApi, ChatMessageVO} from '@/api/ai/chat/message'
import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation'
import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue'
import Role from '@/views/ai/chat/role/index.vue'
@ -204,6 +209,7 @@ import { marked } from 'marked'
// https://highlightjs.org/
import 'highlight.js/styles/vs2015.min.css'
import hljs from 'highlight.js'
const route = useRoute() //
const message = useMessage() //
@ -220,6 +226,7 @@ marked.use({
})
const conversationList = ref([] as ChatConversationVO[])
const conversationMap = ref<any>({})
// copy
const {copy} = useClipboard()
@ -286,7 +293,8 @@ const deleteChatConversation = async (conversation: ChatConversationVO) => {
message.success('会话已删除')
//
await getChatConversationList()
} catch {}
} catch {
}
}
const searchConversation = () => {
@ -532,8 +540,54 @@ const getChatConversationList = async () => {
changeConversation(conversationList.value[0].id)
}
}
// map
const groupRes = await conversationTimeGroup(conversationList.value)
conversationMap.value = groupRes
}
const conversationTimeGroup = async (list: ChatConversationVO[]) => {
// (30)
const groupMap = {
'置顶': [],
'今天': [],
'一天前': [],
'三天前': [],
'七天前': [],
'三十天前': []
}
//
const now = Date.now();
//
const oneDay = 24 * 60 * 60 * 1000;
const threeDays = 3 * oneDay;
const sevenDays = 7 * oneDay;
const thirtyDays = 30 * oneDay;
console.log('listlistlist', list)
for (const conversation: ChatConversationVO of list) {
//
if (conversation.pinned) {
groupMap['置顶'].push(conversation)
continue
}
//
const diff = now - conversation.updateTime;
//
if (diff < oneDay) {
groupMap['今天'].push(conversation)
} else if (diff < threeDays) {
groupMap['一天前'].push(conversation)
} else if (diff < sevenDays) {
groupMap['三天前'].push(conversation)
} else if (diff < thirtyDays) {
groupMap['七天前'].push(conversation)
} else {
groupMap['三十天前'].push(conversation)
}
}
return groupMap
}
//
const handleConversationClick = async (id: number) => {
//