From 687fb37beb0ec31239fc1b519c667b4ae4907f53 Mon Sep 17 00:00:00 2001 From: wx <645899409@qq.com> Date: Thu, 12 Mar 2026 16:10:15 +0800 Subject: [PATCH] =?UTF-8?q?update=201.=E6=9B=B4=E6=8D=A2=E5=8F=98=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=A4=96=E9=93=BE=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- .env.production | 2 +- .env.test | 2 +- Dockerfile | 2 +- entrypoint.sh | 2 +- iweb/src/components/db/conversationDB.ts | 236 +++++++++++++++++++++++ src/components/Menu/src/BasicMenu.vue | 2 + src/hooks/setting/index.ts | 4 +- src/utils/env.ts | 4 +- types/config.d.ts | 2 +- 10 files changed, 248 insertions(+), 10 deletions(-) create mode 100644 iweb/src/components/db/conversationDB.ts diff --git a/.env.development b/.env.development index 76fa791..3055dfb 100644 --- a/.env.development +++ b/.env.development @@ -32,4 +32,4 @@ VITE_EMERGENCY_SCREEN=http://emer.dev.yg.dt.io/ VITE_PLATFORM = 'YT' # 跳转外部链接 -VITE_OUT_URL=https://console-jkglpt.iosp.ydpt.tech/hb/healthadmin/index.html?param= +VITE_GLOB_OUT_URL=https://console-jkglpt.iosp.ydpt.tech/hb/healthadmin/index.html?param= diff --git a/.env.production b/.env.production index a05624c..249f839 100644 --- a/.env.production +++ b/.env.production @@ -41,4 +41,4 @@ VITE_LEGACY = false VITE_PLATFORM = 'YT' # 跳转外部链接 -VITE_OUT_URL=https://console-jkglpt.iosp.ydpt.tech/hb/healthadmin/index.html?param= +VITE_GLOB_OUT_URL=https://console-jkglpt.iosp.ydpt.tech/hb/healthadmin/index.html?param= diff --git a/.env.test b/.env.test index 0c641ad..eac5622 100644 --- a/.env.test +++ b/.env.test @@ -39,4 +39,4 @@ VITE_LEGACY = false VITE_PLATFORM = 'YT' # 跳转外部链接 -VITE_OUT_URL=https://gstest.superwx.cn/healthapiadmin/index.html?param= +VITE_GLOB_OUT_URL=https://gstest.superwx.cn/healthapiadmin/index.html?param= diff --git a/Dockerfile b/Dockerfile index 3d077ae..98624d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ENV LANG en_US.UTF-8 ENV VITE_GLOB_API_URL https://xj-api.mcrm.vip:8888 ENV VITE_GLOB_DOMAIN_URL https://xj-api.mcrm.vip:8888 -ENV VITE_OUT_URL https://gstest.superwx.cn/healthapiadmin/index.html?param= +ENV VITE_GLOB_OUT_URL https://gstest.superwx.cn/healthapiadmin/index.html?param= RUN echo "server { \ #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 \ diff --git a/entrypoint.sh b/entrypoint.sh index 3956e8a..2c9398a 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,7 +20,7 @@ window['$CONFIG_VAR'] = { "VITE_GLOB_DOMAIN_URL": "${VITE_GLOB_DOMAIN_URL:-http://default-domain.com}", "VITE_GLOB_ST_DOMAIN_URL": "${VITE_GLOB_ST_DOMAIN_URL:-http://default-domain.com}", "VITE_GLOB_API_URL_PREFIX": "${VITE_GLOB_API_URL_PREFIX:-}", - "VITE_OUT_URL": "${VITE_OUT_URL:-}" + "VITE_GLOB_OUT_URL": "${VITE_GLOB_OUT_URL:-}" }; // 冻结对象(可选,模拟生产行为) diff --git a/iweb/src/components/db/conversationDB.ts b/iweb/src/components/db/conversationDB.ts new file mode 100644 index 0000000..1aa95e4 --- /dev/null +++ b/iweb/src/components/db/conversationDB.ts @@ -0,0 +1,236 @@ +// 数据库管理类 +class ConversationDB { + constructor() { + this.dbName = 'TIMConversationDB'; + this.version = 1; + this.db = null; + } + + // 打开数据库 + async openDB() { + return new Promise((resolve, reject) => { + const request = indexedDB.open(this.dbName, this.version); + + request.onerror = () => reject(request.error); + request.onsuccess = () => { + this.db = request.result; + resolve(this.db); + }; + + request.onupgradeneeded = (event) => { + const db = event.target.result; + + // 创建会话存储空间 + if (!db.objectStoreNames.contains('conversations')) { + const store = db.createObjectStore('conversations', { + keyPath: 'conversationID', + }); + + // 创建索引 + store.createIndex('lastMessageTime', 'lastMessageTime', { unique: false }); + store.createIndex('isTop', 'isTop', { unique: false }); + store.createIndex('status', 'status', { unique: false }); + store.createIndex('type', 'type', { unique: false }); + } + + // 创建消息存储空间(可选) + if (!db.objectStoreNames.contains('messages')) { + const messageStore = db.createObjectStore('messages', { + keyPath: 'ID', + }); + messageStore.createIndex('conversationID', 'conversationID', { unique: false }); + messageStore.createIndex('time', 'time', { unique: false }); + } + }; + }); + } + + // 保存或更新会话 + async saveConversation(conversation) { + if (!this.db) await this.openDB(); + + return new Promise((resolve, reject) => { + const transaction = this.db.transaction(['conversations'], 'readwrite'); + const store = transaction.objectStore('conversations'); + + // 添加更新时间 + conversation.updatedTime = Date.now(); + + const request = store.put(conversation); + + request.onerror = () => reject(request.error); + request.onsuccess = () => resolve(request.result); + }); + } + + // 批量保存会话 + async saveConversations(conversations) { + if (!this.db) await this.openDB(); + + return new Promise((resolve, reject) => { + const transaction = this.db.transaction(['conversations'], 'readwrite'); + const store = transaction.objectStore('conversations'); + + conversations.forEach((conversation) => { + conversation.updatedTime = Date.now(); + store.put(conversation); + }); + + transaction.oncomplete = () => resolve(); + transaction.onerror = () => reject(transaction.error); + }); + } + + // 获取会话列表(支持排序和分页) + async getConversationList(options = {}) { + if (!this.db) await this.openDB(); + + const { + page = 1, + pageSize = 50, + status = 0, // 0:活跃 1:已结束 + sortBy = 'lastMessageTime', + sortOrder = 'desc', + } = options; + + return new Promise((resolve, reject) => { + const transaction = this.db.transaction(['conversations'], 'readonly'); + const store = transaction.objectStore('conversations'); + const index = store.index(sortBy); + + let conversations = []; + let count = 0; + let cursor = index.openCursor(null, sortOrder === 'desc' ? 'prev' : 'next'); + + cursor.onsuccess = (event) => { + const cursor = event.target.result; + if (cursor) { + const conversation = cursor.value; + + // 过滤条件 + if (conversation.status === status) { + count++; + + // 分页计算 + const startIndex = (page - 1) * pageSize; + const endIndex = page * pageSize; + + if (count > startIndex && count <= endIndex) { + conversations.push(conversation); + } + } + + if (count < endIndex) { + cursor.continue(); + } else { + resolve({ + conversations, + total: count, + page, + pageSize, + }); + } + } else { + resolve({ + conversations, + total: count, + page, + pageSize, + }); + } + }; + + cursor.onerror = () => reject(cursor.error); + }); + } + + // 根据会话ID获取会话 + async getConversation(conversationID) { + if (!this.db) await this.openDB(); + + return new Promise((resolve, reject) => { + const transaction = this.db.transaction(['conversations'], 'readonly'); + const store = transaction.objectStore('conversations'); + const request = store.get(conversationID); + + request.onerror = () => reject(request.error); + request.onsuccess = () => resolve(request.result); + }); + } + + // 删除会话 + async deleteConversation(conversationID) { + if (!this.db) await this.openDB(); + + return new Promise((resolve, reject) => { + const transaction = this.db.transaction(['conversations'], 'readwrite'); + const store = transaction.objectStore('conversations'); + const request = store.delete(conversationID); + + request.onerror = () => reject(request.error); + request.onsuccess = () => resolve(); + }); + } + + // 标记会话为已结束 + async markConversationEnded(conversationID, reason = '') { + const conversation = await this.getConversation(conversationID); + if (conversation) { + conversation.status = 1; + conversation.endReason = reason; + conversation.endTime = Date.now(); + await this.saveConversation(conversation); + } + } + + // 更新会话最后消息 + async updateLastMessage(conversationID, message) { + const conversation = await this.getConversation(conversationID); + if (conversation) { + conversation.lastMessage = this.getMessageSummary(message); + conversation.lastMessageType = message.type; + conversation.lastMessageTime = message.time || Date.now(); + + // 如果会话已结束但收到新消息,重新激活 + if (conversation.status === 1) { + conversation.status = 0; + conversation.endReason = ''; + conversation.endTime = 0; + } + + await this.saveConversation(conversation); + } + } + + // 获取消息摘要 + getMessageSummary(message) { + switch (message.type) { + case 'TIMTextElem': + return message.payload.text; + case 'TIMImageElem': + return '[图片]'; + case 'TIMSoundElem': + return '[语音]'; + case 'TIMCustomElem': + return this.parseCustomMessage(message); + default: + return '[未知消息]'; + } + } + + // 解析自定义消息 + parseCustomMessage(message) { + try { + const data = JSON.parse(message.payload.data); + if (data.type === 'END_CONVERSATION') { + return `[会话结束: ${data.reason}]`; + } + return '[自定义消息]'; + } catch { + return '[自定义消息]'; + } + } +} + +// 单例模式 +export const conversationDB = new ConversationDB(); diff --git a/src/components/Menu/src/BasicMenu.vue b/src/components/Menu/src/BasicMenu.vue index 0d40e93..d9f2e14 100644 --- a/src/components/Menu/src/BasicMenu.vue +++ b/src/components/Menu/src/BasicMenu.vue @@ -131,6 +131,8 @@ if (item.title === '健康银行') { open(); const url = viteOutUrl; + console.log(url); + console.log(useGlobSetting()); await defHttp .get({ url: '/health-system/api/sys/encryptInfo', diff --git a/src/hooks/setting/index.ts b/src/hooks/setting/index.ts index 2f6c925..f6f8385 100644 --- a/src/hooks/setting/index.ts +++ b/src/hooks/setting/index.ts @@ -17,7 +17,7 @@ export const useGlobSetting = (): Readonly => { VITE_GLOB_ONLINE_VIEW_URL, VITE_GLOB_ST_DOMAIN_URL, VITE_PLATFORM, - VITE_OUT_URL, + VITE_GLOB_OUT_URL, } = getAppEnvConfig(); if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) { @@ -41,7 +41,7 @@ export const useGlobSetting = (): Readonly => { viewUrl: VITE_GLOB_ONLINE_VIEW_URL, stDomainUrl: VITE_GLOB_ST_DOMAIN_URL, vitePlatform: VITE_PLATFORM, - viteOutUrl: VITE_OUT_URL, + viteOutUrl: VITE_GLOB_OUT_URL, }; window._CONFIG['domianURL'] = VITE_GLOB_DOMAIN_URL; return glob as Readonly; diff --git a/src/utils/env.ts b/src/utils/env.ts index a9515fb..144ec20 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -34,7 +34,7 @@ export function getAppEnvConfig() { VITE_GLOB_ONLINE_VIEW_URL, VITE_GLOB_ST_DOMAIN_URL, VITE_PLATFORM, - VITE_OUT_URL, + VITE_GLOB_OUT_URL, } = ENV; if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) { // warn( @@ -56,7 +56,7 @@ export function getAppEnvConfig() { VITE_GLOB_ONLINE_VIEW_URL, VITE_GLOB_ST_DOMAIN_URL, VITE_PLATFORM, - VITE_OUT_URL, + VITE_GLOB_OUT_URL, }; } diff --git a/types/config.d.ts b/types/config.d.ts index 394b758..53b2b72 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -181,5 +181,5 @@ export interface GlobEnvConfig { VITE_GLOB_ONLINE_VIEW_URL?: string; VITE_GLOB_ST_DOMAIN_URL?: string; VITE_PLATFORM?: string; - VITE_OUT_URL?: string; + VITE_GLOB_OUT_URL?: string; }