【增加】AI 对话增加 GROUP 分组
parent
ad02983098
commit
f21991f4fc
|
@ -23,10 +23,14 @@
|
||||||
<!-- 左中间:对话列表 -->
|
<!-- 左中间:对话列表 -->
|
||||||
<div class="conversation-list">
|
<div class="conversation-list">
|
||||||
<!-- TODO @fain:置顶、聊天记录、一星期钱、30天前,前端对数据重新做一下分组,或者后端接口改一下 -->
|
<!-- TODO @fain:置顶、聊天记录、一星期钱、30天前,前端对数据重新做一下分组,或者后端接口改一下 -->
|
||||||
<div>
|
<div v-for="conversationKey in Object.keys(conversationMap)" :key="conversationKey" >
|
||||||
<el-text class="mx-1" size="small" tag="b">置顶</el-text>
|
<div v-if="conversationMap[conversationKey].length">
|
||||||
|
<el-text class="mx-1" size="small" tag="b">{{conversationKey}}</el-text>
|
||||||
</div>
|
</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
|
<div
|
||||||
:class="conversation.id === conversationId ? 'conversation active' : 'conversation'"
|
:class="conversation.id === conversationId ? 'conversation active' : 'conversation'"
|
||||||
@click="changeConversation(conversation.id)"
|
@click="changeConversation(conversation.id)"
|
||||||
|
@ -48,6 +52,7 @@
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- 左底部:工具栏 -->
|
<!-- 左底部:工具栏 -->
|
||||||
<div class="tool-box">
|
<div class="tool-box">
|
||||||
<div @click="handleRoleRepository">
|
<div @click="handleRoleRepository">
|
||||||
|
@ -193,7 +198,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation'
|
||||||
import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue'
|
import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue'
|
||||||
import Role from '@/views/ai/chat/role/index.vue'
|
import Role from '@/views/ai/chat/role/index.vue'
|
||||||
|
@ -204,6 +209,7 @@ import { marked } from 'marked'
|
||||||
// 代码高亮 https://highlightjs.org/
|
// 代码高亮 https://highlightjs.org/
|
||||||
import 'highlight.js/styles/vs2015.min.css'
|
import 'highlight.js/styles/vs2015.min.css'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
|
|
||||||
const route = useRoute() // 路由
|
const route = useRoute() // 路由
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
@ -220,6 +226,7 @@ marked.use({
|
||||||
})
|
})
|
||||||
|
|
||||||
const conversationList = ref([] as ChatConversationVO[])
|
const conversationList = ref([] as ChatConversationVO[])
|
||||||
|
const conversationMap = ref<any>({})
|
||||||
// 初始化 copy 到粘贴板
|
// 初始化 copy 到粘贴板
|
||||||
const {copy} = useClipboard()
|
const {copy} = useClipboard()
|
||||||
|
|
||||||
|
@ -286,7 +293,8 @@ const deleteChatConversation = async (conversation: ChatConversationVO) => {
|
||||||
message.success('会话已删除')
|
message.success('会话已删除')
|
||||||
// 刷新列表
|
// 刷新列表
|
||||||
await getChatConversationList()
|
await getChatConversationList()
|
||||||
} catch {}
|
} catch {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchConversation = () => {
|
const searchConversation = () => {
|
||||||
|
@ -532,8 +540,54 @@ const getChatConversationList = async () => {
|
||||||
changeConversation(conversationList.value[0].id)
|
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) => {
|
const handleConversationClick = async (id: number) => {
|
||||||
// 切换对话
|
// 切换对话
|
||||||
|
|
Loading…
Reference in New Issue