feat: 优化侧边会话
This commit is contained in:
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 class="flex flex-col gap-2 text-sm">
|
||||||
<div v-for="(item, index) of dataSources" :key="index">
|
<div v-for="(item, index) of dataSources" :key="index">
|
||||||
<a
|
<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)"
|
@click="handleSelect(index)"
|
||||||
>
|
>
|
||||||
<span :class="[{ 'text-[#4b9e5f]': historyStore.active === index }]">
|
<span>
|
||||||
<SvgIcon icon="ri:message-3-line" />
|
<SvgIcon icon="ri:message-3-line" />
|
||||||
</span>
|
</span>
|
||||||
<div class="relative flex-1 overflow-hidden break-all text-ellipsis whitespace-nowrap">
|
<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() {
|
function handleAdd() {
|
||||||
historyStore.addHistory({
|
historyStore.addHistory({
|
||||||
title: '',
|
title: 'New Chat',
|
||||||
isEdit: false,
|
isEdit: false,
|
||||||
data: [],
|
data: [],
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,14 +5,17 @@ import { getLocalHistory, setLocalHistory } from './helper'
|
||||||
export const useHistoryStore = defineStore('history-store', {
|
export const useHistoryStore = defineStore('history-store', {
|
||||||
state: (): HistoryState => getLocalHistory(),
|
state: (): HistoryState => getLocalHistory(),
|
||||||
getters: {
|
getters: {
|
||||||
getCurrentChat(state): Chat.Chat[] {
|
getCurrentHistory(state): Chat.HistoryChat {
|
||||||
if (state.historyChat.length) {
|
if (state.historyChat.length) {
|
||||||
if (state.active === null || state.active >= state.historyChat.length || state.active < 0)
|
if (state.active === null || state.active >= state.historyChat.length || state.active < 0)
|
||||||
state.active = 0
|
state.active = 0
|
||||||
return state.historyChat[state.active].data ?? []
|
return state.historyChat[state.active] ?? { title: '', isEdit: false, data: [] }
|
||||||
}
|
}
|
||||||
state.active = null
|
state.active = null
|
||||||
return []
|
return { title: '', isEdit: false, data: [] }
|
||||||
|
},
|
||||||
|
getCurrentChat(): Chat.Chat[] {
|
||||||
|
return this.getCurrentHistory.data ?? []
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -23,7 +26,7 @@ export const useHistoryStore = defineStore('history-store', {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const active = uuid !== null ? uuid : this.active
|
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].title = data.message
|
||||||
this.historyChat[active].data.push(data)
|
this.historyChat[active].data.push(data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue