From 70e6a3c2263128cb5697d5df7e5762ad947688ac Mon Sep 17 00:00:00 2001 From: "15881625488@163.com" <15881625488@163.com> Date: Wed, 7 Jan 2026 13:31:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=90=BD=E7=AC=94=E7=95=99?= =?UTF-8?q?=E7=97=95demo=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/lblh/components/AutoSaveManager.js | 2 +- src/views/lblh/components/storage/ServerStorage.js | 9 ++++++--- src/views/lblh/index.vue | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/views/lblh/components/AutoSaveManager.js b/src/views/lblh/components/AutoSaveManager.js index f5fc5d5..90fff6b 100644 --- a/src/views/lblh/components/AutoSaveManager.js +++ b/src/views/lblh/components/AutoSaveManager.js @@ -15,7 +15,7 @@ class AutoSaveManager { try { this.storages = { // memory: new MemoryStorage(key), - localStorage: new LocalStorage(key), + // localStorage: new LocalStorage(key), // sessionStorage: new SessionStorage(key), indexedDB: new IndexedDBStorage(key), server: new ServerStorage(key, serverOptions) diff --git a/src/views/lblh/components/storage/ServerStorage.js b/src/views/lblh/components/storage/ServerStorage.js index 9425886..0756bf1 100644 --- a/src/views/lblh/components/storage/ServerStorage.js +++ b/src/views/lblh/components/storage/ServerStorage.js @@ -1,3 +1,5 @@ +import { getToken } from '@/utils/auth' + /** * 服务器存储策略 * 支持离线队列,网络恢复后自动重传 @@ -6,9 +8,9 @@ class ServerStorage { constructor(key, options = {}) { this.key = key; this.options = { - endpoint: options.endpoint || '/api/save-text', - syncEndpoint: options.syncEndpoint || '/api/sync-text', - historyEndpoint: options.historyEndpoint || '/api/text-history', + endpoint: options.endpoint || '/system/business/test/testLblh', + syncEndpoint: options.syncEndpoint || '/system/business/test/testLblhHistory', + historyEndpoint: options.historyEndpoint || '/system/business/test/testLblhHistory', retryCount: options.retryCount || 3, //最多重试次数 retryDelay: options.retryDelay || 1000,//重试等待 毫秒 ...options @@ -102,6 +104,7 @@ class ServerStorage { const xhr = new XMLHttpRequest(); xhr.open('POST', this.options.endpoint); xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.setRequestHeader('Authorization', 'Bearer ' + getToken()); // 让每个请求携带自定义token 请根据实际情况自行修改 xhr.onload = () => { if (xhr.status === 200 || xhr.status === 201) { diff --git a/src/views/lblh/index.vue b/src/views/lblh/index.vue index a5a6c50..88160a3 100644 --- a/src/views/lblh/index.vue +++ b/src/views/lblh/index.vue @@ -36,7 +36,7 @@

分层存储(数据流向:用户输入 → 本地持久化 → 云端)

1.服务器存储:云端同步,跨设备访问

2.IndexedDB存储:浏览器内置 NoSQL 数据库,所有pc浏览器都支持,移动端浏览器也支持(存储数据可达50%的磁盘容量,并且支持事务,索引)(关闭标签页/窗口 → 数据保留;刷新页面 → 数据保留)

-

3.LocalStorage:本地存储, 持久化,跨会话保存(关闭标签页/窗口 → 数据保留;刷新页面 → 数据保留)

+

3.LocalStorage:本地存储, 持久化,跨会话保存(关闭标签页/窗口 → 数据保留;刷新页面 → 数据保留)如果IndexedDB初始化失败则启用

实时保存

3.输入结束,失去焦点后触发多存储并行保存

4.页面关闭前强制同步保存