From eb2473df6f021fb8c14fe12500d316448eb33a0e Mon Sep 17 00:00:00 2001 From: wangyifeng <812766448@qq.com> Date: Mon, 28 Apr 2025 19:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=97=A0=E6=84=9F=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E5=B9=B6=E5=8E=BB=E6=8E=89=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/dialogueList.js | 2 +- src/store/modules/sqlite.js | 100 ------------------------------ 2 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 src/store/modules/sqlite.js diff --git a/src/store/modules/dialogueList.js b/src/store/modules/dialogueList.js index 9b51e34..415f5e3 100644 --- a/src/store/modules/dialogueList.js +++ b/src/store/modules/dialogueList.js @@ -103,7 +103,7 @@ export const useDialogueListStore = createGlobalState(() => { }) }) } - testDatabase() + // testDatabase() const dialogueList = useStorage('dialogueList', [], uniStorage) // const dialogueList = ref([]) diff --git a/src/store/modules/sqlite.js b/src/store/modules/sqlite.js deleted file mode 100644 index 2747ff9..0000000 --- a/src/store/modules/sqlite.js +++ /dev/null @@ -1,100 +0,0 @@ -// 初始化数据库 -export const initDatabase = async () => { - try { - const isOpen = await plus.sqlite.isOpenDatabase({ - name: 'chat', - path: '_doc/chat.db' - }) - - if (!isOpen) { - await plus.sqlite.openDatabase({ - name: 'chat', - path: '_doc/chat.db' - }) - - await plus.sqlite.executeSql({ - name: 'chat', - sql: ` - CREATE TABLE IF NOT EXISTS talk_records ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - msg_id TEXT NOT NULL, - sequence INTEGER NOT NULL, - talk_type INTEGER NOT NULL DEFAULT 1, - msg_type INTEGER NOT NULL DEFAULT 1, - user_id INTEGER NOT NULL DEFAULT 0, - receiver_id INTEGER NOT NULL DEFAULT 0, - is_revoke INTEGER NOT NULL DEFAULT 0, - is_mark INTEGER NOT NULL DEFAULT 0, - quote_id TEXT NOT NULL, - extra TEXT NOT NULL, - created_at TEXT NOT NULL, - updated_at TEXT NOT NULL, - biz_date TEXT - ); - - CREATE UNIQUE INDEX IF NOT EXISTS uk_msgid ON talk_records(msg_id); - CREATE UNIQUE INDEX IF NOT EXISTS idx_user_id_receiver_id_sequence ON talk_records(user_id, receiver_id, sequence); - CREATE INDEX IF NOT EXISTS idx_receiver_id ON talk_records(receiver_id); - CREATE INDEX IF NOT EXISTS idx_created_at ON talk_records(created_at); - CREATE INDEX IF NOT EXISTS idx_updated_at ON talk_records(updated_at); - CREATE INDEX IF NOT EXISTS idx_biz_date ON talk_records(biz_date); - ` - }) - } - - return true - } catch (error) { - console.error('数据库初始化失败:', error) - return false - } -} - -// 添加消息记录 -export const sqlAddRecord = async (message) => { - try { - await plus.sqlite.executeSql({ - name: 'chat', - sql: `INSERT INTO talk_records ( - msg_id, sequence, talk_type, msg_type, user_id, receiver_id, - is_revoke, is_mark, quote_id, extra, created_at, updated_at, biz_date - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, - args: [ - message.msg_id, - message.sequence, - message.talk_type, - message.msg_type, - message.user_id, - message.receiver_id, - message.is_revoke || 0, - message.is_mark || 0, - message.quote_id || '', - JSON.stringify(message.extra), - message.created_at, - message.updated_at, - message.biz_date - ] - }) - return true - } catch (error) { - console.error('添加消息失败:', error) - return false - } -} - -// 查询消息记录 -export const sqlGetRecord = async (receiverId, page = 1, pageSize = 20) => { - try { - const result = await plus.sqlite.selectSql({ - name: 'chat', - sql: `SELECT * FROM talk_records - WHERE receiver_id = ? - ORDER BY sequence DESC - LIMIT ? OFFSET ?`, - args: [receiverId, pageSize, (page - 1) * pageSize] - }) - return result - } catch (error) { - console.error('查询消息失败:', error) - return [] - } -} \ No newline at end of file