数据持久化
This commit is contained in:
@ -24,7 +24,7 @@
|
||||
import { useChatStore } from '../../store/chatstore'
|
||||
import TextMsg from '@/views/chat/components/Message/TextMsg.vue'
|
||||
import ImageMsg from '@/views/chat/components/Message/ImageMsg.vue'
|
||||
import { ContentType } from '../../types/index.d.ts'
|
||||
import { ContentType } from '../../types/types'
|
||||
|
||||
defineOptions({ name: 'ChatMessage' })
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<view class="flex flex-col w-full">
|
||||
<SessionItem
|
||||
v-for="(item, index) in chatStore.sessionList"
|
||||
:key="item.id"
|
||||
:key="item.id"
|
||||
:index="index"
|
||||
:conversation="item"
|
||||
@click="() => onSessionItemClick(index)"
|
||||
@ -13,17 +13,17 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import SessionItem from '../SessionItem/Index.vue'
|
||||
import SessionItem from '@/views/chat/components/ConversationItem/index.vue'
|
||||
import { useChatStoreWithOut } from '../../store/chatstore'
|
||||
import { onMounted } from 'vue'
|
||||
|
||||
defineOptions({ name: 'Session' })
|
||||
|
||||
const chatStore = useChatStoreWithOut()
|
||||
const { setCurrentConversation, setCurrentSessionIndex, getSession } = useChatStoreWithOut()
|
||||
const { setCurrentConversation, setCurrentSessionIndex, getConversationList } = useChatStoreWithOut()
|
||||
|
||||
onMounted(() => {
|
||||
getSession()
|
||||
getConversationList()
|
||||
// set default conversation
|
||||
nextTick(() => {
|
||||
setCurrentConversation()
|
||||
@ -18,10 +18,11 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { PropType } from 'vue'
|
||||
import { ContentType, ConversationModelType } from '../../types/index.d.ts'
|
||||
import { ContentType, ConversationModelType } from '../../types/types'
|
||||
|
||||
import { formatPast } from '@/utils/formatTime'
|
||||
import { useChatStore } from '../../store/chatstore'
|
||||
import TextMessage from '../../model/TextMessage';
|
||||
import { useChatStore } from '../../store/chatstore.js'
|
||||
import TextMessage from '../../model/TextMessage.js';
|
||||
|
||||
defineOptions({ name: 'SessionItem' })
|
||||
|
||||
@ -24,18 +24,27 @@
|
||||
<script lang="ts" setup>
|
||||
import TextMessage from '../../model/TextMessage'
|
||||
import { useChatStoreWithOut } from '../../store/chatstore'
|
||||
import { CONVERSATION_TYPE } from '../../types/index.d.ts'
|
||||
import { SendStatus, MessageRole, ContentType } from '../../types/index.d.ts'
|
||||
import { CONVERSATION_TYPE } from '../../types/types'
|
||||
import { SendStatus, MessageRole, ContentType } from '../../types/types'
|
||||
import { useUserStoreWithOut } from '../../../../store/modules/user';
|
||||
import { ElNotification } from 'element-plus';
|
||||
|
||||
defineOptions({ name: 'InputSection' })
|
||||
|
||||
const chatStore = useChatStoreWithOut()
|
||||
const onEnter = () => {
|
||||
console.log('enter pressed')
|
||||
const msg = createTextMessage(chatStore.inputText)
|
||||
|
||||
if (!chatStore.inputText.trim()) {
|
||||
ElNotification({
|
||||
title: '温馨提示',
|
||||
message: '请输入内容',
|
||||
type: 'warning'
|
||||
})
|
||||
return
|
||||
}
|
||||
const msg = createTextMessage(chatStore.inputText.trim())
|
||||
chatStore.addMessageToCurrentSession(msg)
|
||||
chatStore.setInputText('')
|
||||
}
|
||||
|
||||
const createTextMessage = (content: string): TextMessage => {
|
||||
@ -53,6 +62,7 @@ const createTextMessage = (content: string): TextMessage => {
|
||||
MessageRole.SELF,
|
||||
SendStatus.SENDING,
|
||||
chatStore.currentSession?.id || '',
|
||||
userStore.user.id,
|
||||
chatStore.currentSession ? chatStore.currentSession.targetId : 0,
|
||||
chatStore.currentSession?.type || CONVERSATION_TYPE.SINGLE,
|
||||
chatStore.currentSession?.senderId || ''
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { PropType } from 'vue'
|
||||
import { Loading } from '@element-plus/icons-vue'
|
||||
import { MessageModelType, MessageRole, SendStatus } from '../../types/index.d.ts'
|
||||
import { MessageModelType, MessageRole, SendStatus } from '../../types/types'
|
||||
|
||||
defineOptions({ name: 'BaseMessage' })
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
import { PropType } from 'vue'
|
||||
import { useChatStore } from '../../store/chatstore'
|
||||
import { onMounted } from 'vue'
|
||||
import { MessageModelType } from '../../types'
|
||||
import { MessageModelType } from '../../types/types'
|
||||
import BaseMesageLayout from './BaseMsg.vue'
|
||||
|
||||
defineOptions({ name: 'ImageMessage' })
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { MENU_LIST_ENUM } from '../../types/index.d.ts'
|
||||
import { MENU_LIST_ENUM } from '../../types/types'
|
||||
|
||||
defineOptions({ name: 'ToolSection' })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user