diff --git a/package.json b/package.json index ba540009..c1b8c358 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "element-plus": "2.8.4", "fast-xml-parser": "^4.3.2", "highlight.js": "^11.9.0", + "idb": "^8.0.0", "jsencrypt": "^3.3.2", "lodash-es": "^4.17.21", "markdown-it": "^14.1.0", diff --git a/src/store/indexedDB.ts b/src/store/indexedDB.ts new file mode 100644 index 00000000..d1427899 --- /dev/null +++ b/src/store/indexedDB.ts @@ -0,0 +1,72 @@ +import { ConversationModelType } from '@/views/chat/types/types' +import { openDB, DBSchema, IDBPDatabase } from 'idb' + +// Define your database schema +interface MyDB extends DBSchema { + Conversations: { + key: string + value: ConversationModelType + } +} + +let dbPromise: Promise> + +export const initDB = () => { + if (!dbPromise) { + try { + dbPromise = openDB('yudao-im-indexeddb', 1, { + upgrade(db) { + db.createObjectStore('Conversations', { keyPath: 'conversationNo' }) + } + }) + } catch (error) { + console.log(error) + } + } + return dbPromise +} + +export const addConversation = async (conversation: ConversationModelType) => { + + try { + const db = await initDB() + await db.put('Conversations', conversation) + } catch (error) { + console.error(conversation) + console.error(error) + } + +} + +export const getConversation = async (conversationNo: string) => { + + try { + const db = await initDB() + return await db.get('Conversations', conversationNo) + } catch (error) { + console.error(error) + } + +} + +export const deleteConversation = async (conversationNo: string) => { + + try { + const db = await initDB() + await db.delete('Conversations', conversationNo) + } catch (error) { + console.error(error) + } + +} + +export const getAllConversations = async () => { + + try { + const db = await initDB() + return await db.getAll('Conversations') + } catch (error) { + console.log(error) + } + +} diff --git a/src/views/chat/ChatPage/Index.vue b/src/views/chat/ChatPage/Index.vue index 3a1a604f..dae35248 100644 --- a/src/views/chat/ChatPage/Index.vue +++ b/src/views/chat/ChatPage/Index.vue @@ -18,17 +18,22 @@ */ import ToolSection from '../components/ToolSection/Index.vue' -import Session from '../components/Session/Index.vue' +import Session from '../components/Conversation/index.vue' import Friends from '../components/Friends/Index.vue' -import ChatHeader from '../components/ChatHeader/Index.vue' // TODO @dylan:为啥这个 index.vue 是大写哈?可以搞成小写哇? -import ChatMessage from '../components/ChatMessage/Index.vue' -import InputSection from '../components/InputSection/Index.vue' +import ChatHeader from '../components/ChatHeader/index.vue' +import ChatMessage from '../components/ChatMessage/index.vue' +import InputSection from '../components/InputSection/index.vue' import FriendDetail from '../components/FriendDetail/Index.vue' -import { MENU_LIST_ENUM } from '../types/index.d.ts' +import { MENU_LIST_ENUM } from '../types/types' +import { useWebSocketStore } from '../store/websocketStore' defineOptions({ name: 'ChatPage' }) const bussinessType = ref(1) +const webSocketStore = useWebSocketStore(); +onMounted(() => { + webSocketStore.connect() +}) const toolMenuSelectChange = (value) => { bussinessType.value = value diff --git a/src/views/chat/api/messageApi.ts b/src/views/chat/api/messageApi.ts index d086b639..5a1290fa 100644 --- a/src/views/chat/api/messageApi.ts +++ b/src/views/chat/api/messageApi.ts @@ -6,7 +6,7 @@ */ import request from '@/config/axios' -import { MessageModelType } from '../types' +import { MessageModelType } from '../types/types' export interface SendMsg { clientMessageId: string diff --git a/src/views/chat/components/ChatMessage/Index.vue b/src/views/chat/components/ChatMessage/Index.vue index 06027f83..b972b03f 100644 --- a/src/views/chat/components/ChatMessage/Index.vue +++ b/src/views/chat/components/ChatMessage/Index.vue @@ -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' }) diff --git a/src/views/chat/components/Session/Index.vue b/src/views/chat/components/Conversation/index.vue similarity index 77% rename from src/views/chat/components/Session/Index.vue rename to src/views/chat/components/Conversation/index.vue index 1db5009f..6aa3e194 100644 --- a/src/views/chat/components/Session/Index.vue +++ b/src/views/chat/components/Conversation/index.vue @@ -3,7 +3,7 @@