feat: 优化侧边会话

main
ChenZhaoYu 2 years ago
parent cf8e2dd7b6
commit d2ae2c4f54

@ -31,10 +31,11 @@ function handleEnter(index: number, isEdit: boolean, event: KeyboardEvent) {
<div class="flex flex-col gap-2 text-sm">
<div v-for="(item, index) of dataSources" :key="index">
<a
class="relative flex items-center gap-3 px-3 py-3 break-all rounded-md cursor-pointer bg-neutral-50 pr-14 hover:bg-neutral-100 group"
class="relative flex items-center gap-3 px-3 py-3 break-all border rounded-md cursor-pointer pr-14 hover:bg-neutral-100 group"
:class="historyStore.active === index && ['border-[#4b9e5f]', 'bg-neutral-100', 'text-[#4b9e5f]']"
@click="handleSelect(index)"
>
<span :class="[{ 'text-[#4b9e5f]': historyStore.active === index }]">
<span>
<SvgIcon icon="ri:message-3-line" />
</span>
<div class="relative flex-1 overflow-hidden break-all text-ellipsis whitespace-nowrap">

@ -12,7 +12,7 @@ const collapsed = ref(appStore.siderCollapsed ?? false)
function handleAdd() {
historyStore.addHistory({
title: '',
title: 'New Chat',
isEdit: false,
data: [],
})

@ -5,14 +5,17 @@ import { getLocalHistory, setLocalHistory } from './helper'
export const useHistoryStore = defineStore('history-store', {
state: (): HistoryState => getLocalHistory(),
getters: {
getCurrentChat(state): Chat.Chat[] {
getCurrentHistory(state): Chat.HistoryChat {
if (state.historyChat.length) {
if (state.active === null || state.active >= state.historyChat.length || state.active < 0)
state.active = 0
return state.historyChat[state.active].data ?? []
return state.historyChat[state.active] ?? { title: '', isEdit: false, data: [] }
}
state.active = null
return []
return { title: '', isEdit: false, data: [] }
},
getCurrentChat(): Chat.Chat[] {
return this.getCurrentHistory.data ?? []
},
},
actions: {
@ -23,7 +26,7 @@ export const useHistoryStore = defineStore('history-store', {
}
else {
const active = uuid !== null ? uuid : this.active
if (this.historyChat[active].title === '')
if (this.historyChat[active].title === 'New Chat')
this.historyChat[active].title = data.message
this.historyChat[active].data.push(data)
}

Loading…
Cancel
Save