|
|
|
@ -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) { |
|
|
|
|