@nokecy/qc-ui 1.0.93 → 1.0.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ag-grid-plus/ag-gridPlus.js +24 -18
- package/dist/cjs/ag-grid-plus/context/gridContext.d.ts +6 -0
- package/dist/cjs/ag-grid-plus/index.d.ts +2 -4
- package/dist/cjs/ag-grid-plus/index.js +18 -79
- package/dist/cjs/ag-grid-plus/querySchemes/components/QuerySchemesManager.js +134 -117
- package/dist/cjs/ag-grid-plus/querySchemes/types.d.ts +2 -0
- package/dist/cjs/ag-grid-plus/schemes/index.d.ts +7 -0
- package/dist/cjs/ag-grid-plus/schemes/index.js +40 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/configMerger.d.ts +10 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/configMerger.js +34 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/localStorageAdapter.d.ts +17 -2
- package/dist/cjs/ag-grid-plus/schemes/storage/localStorageAdapter.js +27 -7
- package/dist/cjs/ag-grid-plus/schemes/storage/priorityStorageAdapter.d.ts +122 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/priorityStorageAdapter.js +476 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/remoteStorageAdapter.d.ts +139 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/remoteStorageAdapter.js +746 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/useRemoteStorage.d.ts +29 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/useRemoteStorage.js +45 -0
- package/dist/cjs/ag-grid-plus/setting/ColumnSetting.js +154 -270
- package/dist/cjs/ag-grid-plus/storage/index.d.ts +10 -5
- package/dist/cjs/ag-grid-plus/storage/index.js +0 -44
- package/dist/cjs/array-table/index.js +5 -3
- package/dist/cjs/draggableModal/index.d.ts +1 -1
- package/dist/cjs/draggableModal/index.js +23 -93
- package/dist/cjs/draggableModal/style.less +0 -73
- package/dist/cjs/index.d.ts +2 -3
- package/dist/cjs/index.js +8 -80
- package/dist/esm/ag-grid-plus/ag-gridPlus.js +24 -18
- package/dist/esm/ag-grid-plus/context/gridContext.d.ts +6 -0
- package/dist/esm/ag-grid-plus/errors/ErrorBoundary.d.ts +1 -1
- package/dist/esm/ag-grid-plus/index.d.ts +2 -4
- package/dist/esm/ag-grid-plus/index.js +5 -3
- package/dist/esm/ag-grid-plus/querySchemes/components/QuerySchemesManager.js +135 -118
- package/dist/esm/ag-grid-plus/querySchemes/types.d.ts +2 -0
- package/dist/esm/ag-grid-plus/schemes/index.d.ts +7 -0
- package/dist/esm/ag-grid-plus/schemes/index.js +5 -0
- package/dist/esm/ag-grid-plus/schemes/storage/configMerger.d.ts +10 -0
- package/dist/esm/ag-grid-plus/schemes/storage/configMerger.js +28 -0
- package/dist/esm/ag-grid-plus/schemes/storage/localStorageAdapter.d.ts +17 -2
- package/dist/esm/ag-grid-plus/schemes/storage/localStorageAdapter.js +29 -7
- package/dist/esm/ag-grid-plus/schemes/storage/priorityStorageAdapter.d.ts +122 -0
- package/dist/esm/ag-grid-plus/schemes/storage/priorityStorageAdapter.js +471 -0
- package/dist/esm/ag-grid-plus/schemes/storage/remoteStorageAdapter.d.ts +139 -0
- package/dist/esm/ag-grid-plus/schemes/storage/remoteStorageAdapter.js +746 -0
- package/dist/esm/ag-grid-plus/schemes/storage/useRemoteStorage.d.ts +29 -0
- package/dist/esm/ag-grid-plus/schemes/storage/useRemoteStorage.js +40 -0
- package/dist/esm/ag-grid-plus/setting/ColumnSetting.js +156 -272
- package/dist/esm/ag-grid-plus/storage/index.d.ts +10 -5
- package/dist/esm/ag-grid-plus/storage/index.js +13 -5
- package/dist/esm/array-table/index.js +6 -2
- package/dist/esm/draggableModal/index.d.ts +1 -1
- package/dist/esm/draggableModal/index.js +24 -93
- package/dist/esm/draggableModal/style.less +0 -73
- package/dist/esm/index.d.ts +2 -3
- package/dist/esm/index.js +10 -7
- package/dist/esm/standardFormDialog/useStandardFormSchema.d.ts +1 -1
- package/dist/umd/qc-ui.min.css +1 -1
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/ag-grid-plus/storage/MemoryStorageAdapter.d.ts +0 -76
- package/dist/cjs/ag-grid-plus/storage/MemoryStorageAdapter.js +0 -276
- package/dist/cjs/ag-grid-plus/storage/SchemeSyncManager.d.ts +0 -141
- package/dist/cjs/ag-grid-plus/storage/SchemeSyncManager.js +0 -902
- package/dist/cjs/ag-grid-plus/storage/globalSyncManager.d.ts +0 -106
- package/dist/cjs/ag-grid-plus/storage/globalSyncManager.js +0 -364
- package/dist/cjs/ag-grid-plus/storage/types.d.ts +0 -150
- package/dist/cjs/ag-grid-plus/storage/types.js +0 -5
- package/dist/esm/ag-grid-plus/storage/MemoryStorageAdapter.d.ts +0 -76
- package/dist/esm/ag-grid-plus/storage/MemoryStorageAdapter.js +0 -273
- package/dist/esm/ag-grid-plus/storage/SchemeSyncManager.d.ts +0 -141
- package/dist/esm/ag-grid-plus/storage/SchemeSyncManager.js +0 -896
- package/dist/esm/ag-grid-plus/storage/globalSyncManager.d.ts +0 -106
- package/dist/esm/ag-grid-plus/storage/globalSyncManager.js +0 -350
- package/dist/esm/ag-grid-plus/storage/types.d.ts +0 -150
- package/dist/esm/ag-grid-plus/storage/types.js +0 -1
|
@@ -1,896 +0,0 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
18
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
-
/**
|
|
20
|
-
* 方案同步管理器
|
|
21
|
-
* 负责所有与后端的数据同步操作
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 默认配置
|
|
26
|
-
*/
|
|
27
|
-
var DEFAULT_CONFIG = {
|
|
28
|
-
getApiPath: '/api/v1/ag-grid-plus/schemes',
|
|
29
|
-
syncApiPath: '/api/v1/ag-grid-plus/schemes',
|
|
30
|
-
autoSaveDelay: 3000,
|
|
31
|
-
backgroundSyncInterval: 300000,
|
|
32
|
-
// 5分钟
|
|
33
|
-
enableAutoSave: true,
|
|
34
|
-
enableBackgroundSync: true,
|
|
35
|
-
conflictResolution: 'client',
|
|
36
|
-
requestTimeout: 30000,
|
|
37
|
-
maxRetries: 3
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 方案同步管理器类
|
|
42
|
-
*/
|
|
43
|
-
export var SchemeSyncManager = /*#__PURE__*/function () {
|
|
44
|
-
function SchemeSyncManager(config) {
|
|
45
|
-
var _this = this;
|
|
46
|
-
var events = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
47
|
-
_classCallCheck(this, SchemeSyncManager);
|
|
48
|
-
_defineProperty(this, "config", void 0);
|
|
49
|
-
_defineProperty(this, "events", void 0);
|
|
50
|
-
// 数据存储
|
|
51
|
-
_defineProperty(this, "allData", void 0);
|
|
52
|
-
// 同步状态
|
|
53
|
-
_defineProperty(this, "lastSyncTime", 0);
|
|
54
|
-
_defineProperty(this, "syncing", false);
|
|
55
|
-
_defineProperty(this, "initialized", false);
|
|
56
|
-
// 脏数据跟踪
|
|
57
|
-
_defineProperty(this, "dirtyGrids", new Map());
|
|
58
|
-
// 定时器
|
|
59
|
-
_defineProperty(this, "autoSaveTimer", void 0);
|
|
60
|
-
_defineProperty(this, "backgroundSyncTimer", void 0);
|
|
61
|
-
// 认证 Token
|
|
62
|
-
_defineProperty(this, "authToken", null);
|
|
63
|
-
/**
|
|
64
|
-
* 页面卸载前同步
|
|
65
|
-
*/
|
|
66
|
-
_defineProperty(this, "handleBeforeUnload", function () {
|
|
67
|
-
if (_this.hasDirtyData()) {
|
|
68
|
-
// 序列化列方案和查询方案
|
|
69
|
-
var serializedColumnSchemes = {};
|
|
70
|
-
Object.entries(_this.allData.columnSchemes).forEach(function (_ref) {
|
|
71
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
72
|
-
gridId = _ref2[0],
|
|
73
|
-
schemes = _ref2[1];
|
|
74
|
-
serializedColumnSchemes[gridId] = schemes.map(function (scheme) {
|
|
75
|
-
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
76
|
-
columnState: JSON.stringify(scheme.columnConfig)
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
var serializedQuerySchemes = {};
|
|
81
|
-
Object.entries(_this.allData.querySchemes).forEach(function (_ref3) {
|
|
82
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
83
|
-
gridId = _ref4[0],
|
|
84
|
-
schemes = _ref4[1];
|
|
85
|
-
serializedQuerySchemes[gridId] = schemes.map(function (scheme) {
|
|
86
|
-
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
87
|
-
itemsOrder: JSON.stringify(scheme.itemsOrder)
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// 使用 Beacon API 发送数据(不阻塞页面卸载)
|
|
93
|
-
var requestData = {
|
|
94
|
-
clientSyncTime: _this.lastSyncTime,
|
|
95
|
-
columnSchemes: serializedColumnSchemes,
|
|
96
|
-
querySchemes: serializedQuerySchemes,
|
|
97
|
-
currentSchemes: _this.allData.currentSchemes
|
|
98
|
-
};
|
|
99
|
-
var blob = new Blob([JSON.stringify(requestData)], {
|
|
100
|
-
type: 'application/json'
|
|
101
|
-
});
|
|
102
|
-
if (navigator.sendBeacon) {
|
|
103
|
-
navigator.sendBeacon(_this.getSyncApiUrl(), blob);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
this.config = _objectSpread(_objectSpread({}, DEFAULT_CONFIG), config);
|
|
108
|
-
this.events = events;
|
|
109
|
-
|
|
110
|
-
// 如果配置中提供了 token,立即设置
|
|
111
|
-
if (config.token) {
|
|
112
|
-
this.authToken = config.token;
|
|
113
|
-
console.log('[SchemeSyncManager] 从配置中设置了初始 Token');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 初始化空数据
|
|
117
|
-
this.allData = {
|
|
118
|
-
columnSchemes: {},
|
|
119
|
-
querySchemes: {},
|
|
120
|
-
currentSchemes: {},
|
|
121
|
-
syncTime: 0,
|
|
122
|
-
version: 1
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// 页面卸载前同步
|
|
126
|
-
if (typeof window !== 'undefined') {
|
|
127
|
-
window.addEventListener('beforeunload', this.handleBeforeUnload);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 获取方案的完整 API URL (GET请求)
|
|
133
|
-
* @private
|
|
134
|
-
*/
|
|
135
|
-
_createClass(SchemeSyncManager, [{
|
|
136
|
-
key: "getGetApiUrl",
|
|
137
|
-
value: function getGetApiUrl() {
|
|
138
|
-
return "".concat(this.config.apiBaseUrl).concat(this.config.getApiPath);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 同步方案的完整 API URL (POST请求)
|
|
143
|
-
* @private
|
|
144
|
-
*/
|
|
145
|
-
}, {
|
|
146
|
-
key: "getSyncApiUrl",
|
|
147
|
-
value: function getSyncApiUrl() {
|
|
148
|
-
return "".concat(this.config.apiBaseUrl).concat(this.config.syncApiPath);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 检查是否有有效的用户数据
|
|
153
|
-
* @private
|
|
154
|
-
*/
|
|
155
|
-
}, {
|
|
156
|
-
key: "hasValidData",
|
|
157
|
-
value: function hasValidData() {
|
|
158
|
-
var hasColumnSchemes = Object.keys(this.allData.columnSchemes).length > 0;
|
|
159
|
-
var hasQuerySchemes = Object.keys(this.allData.querySchemes).length > 0;
|
|
160
|
-
var hasCurrentSchemes = Object.keys(this.allData.currentSchemes).length > 0;
|
|
161
|
-
return hasColumnSchemes || hasQuerySchemes || hasCurrentSchemes;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 重新加载数据(从服务器获取最新方案数据)
|
|
166
|
-
*/
|
|
167
|
-
}, {
|
|
168
|
-
key: "reloadData",
|
|
169
|
-
value: (function () {
|
|
170
|
-
var _reloadData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
171
|
-
var response, responseData, allSchemesData;
|
|
172
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
173
|
-
while (1) switch (_context.prev = _context.next) {
|
|
174
|
-
case 0:
|
|
175
|
-
console.log('[SchemeSyncManager] 重新加载数据...');
|
|
176
|
-
_context.prev = 1;
|
|
177
|
-
_context.next = 4;
|
|
178
|
-
return this.fetchWithRetry(this.getGetApiUrl(), {
|
|
179
|
-
method: 'GET',
|
|
180
|
-
headers: this.getHeaders()
|
|
181
|
-
});
|
|
182
|
-
case 4:
|
|
183
|
-
response = _context.sent;
|
|
184
|
-
_context.next = 7;
|
|
185
|
-
return response.json();
|
|
186
|
-
case 7:
|
|
187
|
-
responseData = _context.sent;
|
|
188
|
-
if (!(responseData.success !== undefined)) {
|
|
189
|
-
_context.next = 14;
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
if (responseData.success) {
|
|
193
|
-
_context.next = 11;
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
throw new Error('重新加载失败:服务器返回错误');
|
|
197
|
-
case 11:
|
|
198
|
-
allSchemesData = responseData.data;
|
|
199
|
-
_context.next = 19;
|
|
200
|
-
break;
|
|
201
|
-
case 14:
|
|
202
|
-
if (!(responseData.columnSchemes !== undefined)) {
|
|
203
|
-
_context.next = 18;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
allSchemesData = responseData;
|
|
207
|
-
_context.next = 19;
|
|
208
|
-
break;
|
|
209
|
-
case 18:
|
|
210
|
-
throw new Error('重新加载失败:服务器返回的数据格式不正确');
|
|
211
|
-
case 19:
|
|
212
|
-
// 反序列化并更新数据
|
|
213
|
-
this.allData = this.deserializeSchemesData(allSchemesData);
|
|
214
|
-
this.lastSyncTime = allSchemesData.syncTime || Date.now();
|
|
215
|
-
console.log('[SchemeSyncManager] 数据重新加载成功:', {
|
|
216
|
-
columnSchemes: Object.keys(this.allData.columnSchemes).length,
|
|
217
|
-
querySchemes: Object.keys(this.allData.querySchemes).length,
|
|
218
|
-
syncTime: new Date(this.lastSyncTime).toISOString()
|
|
219
|
-
});
|
|
220
|
-
_context.next = 28;
|
|
221
|
-
break;
|
|
222
|
-
case 24:
|
|
223
|
-
_context.prev = 24;
|
|
224
|
-
_context.t0 = _context["catch"](1);
|
|
225
|
-
console.error('[SchemeSyncManager] 重新加载数据失败:', _context.t0);
|
|
226
|
-
throw _context.t0;
|
|
227
|
-
case 28:
|
|
228
|
-
case "end":
|
|
229
|
-
return _context.stop();
|
|
230
|
-
}
|
|
231
|
-
}, _callee, this, [[1, 24]]);
|
|
232
|
-
}));
|
|
233
|
-
function reloadData() {
|
|
234
|
-
return _reloadData.apply(this, arguments);
|
|
235
|
-
}
|
|
236
|
-
return reloadData;
|
|
237
|
-
}()
|
|
238
|
-
/**
|
|
239
|
-
* 设置认证 Token
|
|
240
|
-
* @param token 认证令牌 (通常是 Bearer Token)
|
|
241
|
-
* @param autoReload 是否在设置 token 后自动重新加载数据(默认 true)
|
|
242
|
-
*/
|
|
243
|
-
)
|
|
244
|
-
}, {
|
|
245
|
-
key: "setToken",
|
|
246
|
-
value: (function () {
|
|
247
|
-
var _setToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
|
|
248
|
-
var autoReload,
|
|
249
|
-
previousToken,
|
|
250
|
-
_args2 = arguments;
|
|
251
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
252
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
253
|
-
case 0:
|
|
254
|
-
autoReload = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : true;
|
|
255
|
-
previousToken = this.authToken;
|
|
256
|
-
this.authToken = token;
|
|
257
|
-
console.log('[SchemeSyncManager] Token 已更新');
|
|
258
|
-
|
|
259
|
-
// 如果已经初始化,且之前没有 token,现在有了 token,且数据为空,自动重新加载
|
|
260
|
-
if (!(autoReload && this.initialized && !previousToken && token && !this.hasValidData())) {
|
|
261
|
-
_context2.next = 14;
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
console.log('[SchemeSyncManager] 检测到首次设置 Token 且无数据,自动重新加载...');
|
|
265
|
-
_context2.prev = 6;
|
|
266
|
-
_context2.next = 9;
|
|
267
|
-
return this.reloadData();
|
|
268
|
-
case 9:
|
|
269
|
-
_context2.next = 14;
|
|
270
|
-
break;
|
|
271
|
-
case 11:
|
|
272
|
-
_context2.prev = 11;
|
|
273
|
-
_context2.t0 = _context2["catch"](6);
|
|
274
|
-
console.error('[SchemeSyncManager] Token 设置后自动重新加载失败:', _context2.t0);
|
|
275
|
-
// 不抛出错误,允许继续使用
|
|
276
|
-
case 14:
|
|
277
|
-
case "end":
|
|
278
|
-
return _context2.stop();
|
|
279
|
-
}
|
|
280
|
-
}, _callee2, this, [[6, 11]]);
|
|
281
|
-
}));
|
|
282
|
-
function setToken(_x) {
|
|
283
|
-
return _setToken.apply(this, arguments);
|
|
284
|
-
}
|
|
285
|
-
return setToken;
|
|
286
|
-
}()
|
|
287
|
-
/**
|
|
288
|
-
* 获取请求头(包含认证信息)
|
|
289
|
-
* @private
|
|
290
|
-
*/
|
|
291
|
-
)
|
|
292
|
-
}, {
|
|
293
|
-
key: "getHeaders",
|
|
294
|
-
value: function getHeaders() {
|
|
295
|
-
var headers = {
|
|
296
|
-
'Content-Type': 'application/json'
|
|
297
|
-
};
|
|
298
|
-
if (this.authToken) {
|
|
299
|
-
headers['Authorization'] = "Bearer ".concat(this.authToken);
|
|
300
|
-
}
|
|
301
|
-
return headers;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* 初始化:从服务器加载所有数据
|
|
306
|
-
*/
|
|
307
|
-
}, {
|
|
308
|
-
key: "initialize",
|
|
309
|
-
value: (function () {
|
|
310
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
311
|
-
var response, responseData, allSchemesData;
|
|
312
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
313
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
314
|
-
case 0:
|
|
315
|
-
if (!this.initialized) {
|
|
316
|
-
_context3.next = 3;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
console.warn('[SchemeSyncManager] 已经初始化,跳过重复初始化');
|
|
320
|
-
return _context3.abrupt("return");
|
|
321
|
-
case 3:
|
|
322
|
-
_context3.prev = 3;
|
|
323
|
-
_context3.next = 6;
|
|
324
|
-
return this.fetchWithRetry(this.getGetApiUrl(), {
|
|
325
|
-
method: 'GET',
|
|
326
|
-
headers: this.getHeaders()
|
|
327
|
-
});
|
|
328
|
-
case 6:
|
|
329
|
-
response = _context3.sent;
|
|
330
|
-
_context3.next = 9;
|
|
331
|
-
return response.json();
|
|
332
|
-
case 9:
|
|
333
|
-
responseData = _context3.sent;
|
|
334
|
-
if (!(responseData.success !== undefined)) {
|
|
335
|
-
_context3.next = 16;
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
if (responseData.success) {
|
|
339
|
-
_context3.next = 13;
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
|
-
throw new Error('初始化失败:服务器返回错误');
|
|
343
|
-
case 13:
|
|
344
|
-
allSchemesData = responseData.data;
|
|
345
|
-
_context3.next = 21;
|
|
346
|
-
break;
|
|
347
|
-
case 16:
|
|
348
|
-
if (!(responseData.columnSchemes !== undefined)) {
|
|
349
|
-
_context3.next = 20;
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
// 格式2: 直接返回 AllSchemesData
|
|
353
|
-
allSchemesData = responseData;
|
|
354
|
-
_context3.next = 21;
|
|
355
|
-
break;
|
|
356
|
-
case 20:
|
|
357
|
-
throw new Error('初始化失败:服务器返回的数据格式不正确');
|
|
358
|
-
case 21:
|
|
359
|
-
// 反序列化从后端接收的数据
|
|
360
|
-
this.allData = this.deserializeSchemesData(allSchemesData);
|
|
361
|
-
this.lastSyncTime = allSchemesData.syncTime || 0;
|
|
362
|
-
this.initialized = true;
|
|
363
|
-
|
|
364
|
-
// 启动后台同步
|
|
365
|
-
if (this.config.enableBackgroundSync) {
|
|
366
|
-
this.startBackgroundSync();
|
|
367
|
-
}
|
|
368
|
-
console.log('[SchemeSyncManager] 初始化成功,加载数据:', {
|
|
369
|
-
columnSchemes: Object.keys(this.allData.columnSchemes).length,
|
|
370
|
-
querySchemes: Object.keys(this.allData.querySchemes).length,
|
|
371
|
-
syncTime: new Date(this.lastSyncTime).toISOString()
|
|
372
|
-
});
|
|
373
|
-
_context3.next = 32;
|
|
374
|
-
break;
|
|
375
|
-
case 28:
|
|
376
|
-
_context3.prev = 28;
|
|
377
|
-
_context3.t0 = _context3["catch"](3);
|
|
378
|
-
console.error('[SchemeSyncManager] 初始化失败:', _context3.t0);
|
|
379
|
-
throw _context3.t0;
|
|
380
|
-
case 32:
|
|
381
|
-
case "end":
|
|
382
|
-
return _context3.stop();
|
|
383
|
-
}
|
|
384
|
-
}, _callee3, this, [[3, 28]]);
|
|
385
|
-
}));
|
|
386
|
-
function initialize() {
|
|
387
|
-
return _initialize.apply(this, arguments);
|
|
388
|
-
}
|
|
389
|
-
return initialize;
|
|
390
|
-
}()
|
|
391
|
-
/**
|
|
392
|
-
* 销毁管理器
|
|
393
|
-
*/
|
|
394
|
-
)
|
|
395
|
-
}, {
|
|
396
|
-
key: "destroy",
|
|
397
|
-
value: function destroy() {
|
|
398
|
-
// 停止所有定时器
|
|
399
|
-
if (this.autoSaveTimer) {
|
|
400
|
-
clearTimeout(this.autoSaveTimer);
|
|
401
|
-
}
|
|
402
|
-
if (this.backgroundSyncTimer) {
|
|
403
|
-
clearInterval(this.backgroundSyncTimer);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// 移除事件监听
|
|
407
|
-
if (typeof window !== 'undefined') {
|
|
408
|
-
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
|
409
|
-
}
|
|
410
|
-
this.initialized = false;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* 获取列方案数据
|
|
415
|
-
*/
|
|
416
|
-
}, {
|
|
417
|
-
key: "getColumnSchemes",
|
|
418
|
-
value: function getColumnSchemes(gridId) {
|
|
419
|
-
return this.allData.columnSchemes[gridId] || [];
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* 保存列方案数据
|
|
424
|
-
*/
|
|
425
|
-
}, {
|
|
426
|
-
key: "saveColumnSchemes",
|
|
427
|
-
value: function saveColumnSchemes(gridId, schemes) {
|
|
428
|
-
this.allData.columnSchemes[gridId] = schemes;
|
|
429
|
-
this.markDirty(gridId, 'column');
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* 获取查询方案数据
|
|
434
|
-
*/
|
|
435
|
-
}, {
|
|
436
|
-
key: "getQuerySchemes",
|
|
437
|
-
value: function getQuerySchemes(gridId) {
|
|
438
|
-
return this.allData.querySchemes[gridId] || [];
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* 保存查询方案数据
|
|
443
|
-
*/
|
|
444
|
-
}, {
|
|
445
|
-
key: "saveQuerySchemes",
|
|
446
|
-
value: function saveQuerySchemes(gridId, schemes) {
|
|
447
|
-
this.allData.querySchemes[gridId] = schemes;
|
|
448
|
-
this.markDirty(gridId, 'query');
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* 获取当前方案ID
|
|
453
|
-
*/
|
|
454
|
-
}, {
|
|
455
|
-
key: "getCurrentSchemeId",
|
|
456
|
-
value: function getCurrentSchemeId(gridId, type) {
|
|
457
|
-
var current = this.allData.currentSchemes[gridId];
|
|
458
|
-
if (!current) return null;
|
|
459
|
-
return type === 'column' ? current.columnSchemeId || null : current.querySchemeId || null;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* 保存当前方案ID
|
|
464
|
-
*/
|
|
465
|
-
}, {
|
|
466
|
-
key: "saveCurrentSchemeId",
|
|
467
|
-
value: function saveCurrentSchemeId(gridId, type, schemeId) {
|
|
468
|
-
if (!this.allData.currentSchemes[gridId]) {
|
|
469
|
-
this.allData.currentSchemes[gridId] = {};
|
|
470
|
-
}
|
|
471
|
-
if (type === 'column') {
|
|
472
|
-
this.allData.currentSchemes[gridId].columnSchemeId = schemeId;
|
|
473
|
-
} else {
|
|
474
|
-
this.allData.currentSchemes[gridId].querySchemeId = schemeId;
|
|
475
|
-
}
|
|
476
|
-
this.markDirty(gridId, 'current');
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* 标记数据为脏数据
|
|
481
|
-
*/
|
|
482
|
-
}, {
|
|
483
|
-
key: "markDirty",
|
|
484
|
-
value: function markDirty(gridId, type) {
|
|
485
|
-
if (!this.dirtyGrids.has(gridId)) {
|
|
486
|
-
this.dirtyGrids.set(gridId, new Set());
|
|
487
|
-
}
|
|
488
|
-
this.dirtyGrids.get(gridId).add(type);
|
|
489
|
-
|
|
490
|
-
// 触发自动保存
|
|
491
|
-
if (this.config.enableAutoSave) {
|
|
492
|
-
this.scheduleAutoSave();
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* 检查是否有未同步的数据
|
|
498
|
-
*/
|
|
499
|
-
}, {
|
|
500
|
-
key: "hasDirtyData",
|
|
501
|
-
value: function hasDirtyData() {
|
|
502
|
-
return this.dirtyGrids.size > 0;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* 获取所有脏数据的 gridId 列表
|
|
507
|
-
*/
|
|
508
|
-
}, {
|
|
509
|
-
key: "getDirtyGridIds",
|
|
510
|
-
value: function getDirtyGridIds() {
|
|
511
|
-
return Array.from(this.dirtyGrids.keys());
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* 调度自动保存
|
|
516
|
-
*/
|
|
517
|
-
}, {
|
|
518
|
-
key: "scheduleAutoSave",
|
|
519
|
-
value: function scheduleAutoSave() {
|
|
520
|
-
var _this2 = this;
|
|
521
|
-
if (this.autoSaveTimer) {
|
|
522
|
-
clearTimeout(this.autoSaveTimer);
|
|
523
|
-
}
|
|
524
|
-
this.autoSaveTimer = setTimeout(function () {
|
|
525
|
-
var _this2$events$onAutoS, _this2$events;
|
|
526
|
-
(_this2$events$onAutoS = (_this2$events = _this2.events).onAutoSave) === null || _this2$events$onAutoS === void 0 || _this2$events$onAutoS.call(_this2$events);
|
|
527
|
-
_this2.syncNow().catch(function (error) {
|
|
528
|
-
console.error('[SchemeSyncManager] 自动保存失败:', error);
|
|
529
|
-
});
|
|
530
|
-
}, this.config.autoSaveDelay);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* 启动后台同步
|
|
535
|
-
*/
|
|
536
|
-
}, {
|
|
537
|
-
key: "startBackgroundSync",
|
|
538
|
-
value: function startBackgroundSync() {
|
|
539
|
-
var _this3 = this;
|
|
540
|
-
if (this.backgroundSyncTimer) {
|
|
541
|
-
clearInterval(this.backgroundSyncTimer);
|
|
542
|
-
}
|
|
543
|
-
this.backgroundSyncTimer = setInterval(function () {
|
|
544
|
-
if (_this3.hasDirtyData()) {
|
|
545
|
-
_this3.syncNow().catch(function (error) {
|
|
546
|
-
console.error('[SchemeSyncManager] 后台同步失败:', error);
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
}, this.config.backgroundSyncInterval);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* 立即同步数据到服务器
|
|
554
|
-
*/
|
|
555
|
-
}, {
|
|
556
|
-
key: "syncNow",
|
|
557
|
-
value: (function () {
|
|
558
|
-
var _syncNow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
559
|
-
var _this$events$onSyncSt,
|
|
560
|
-
_this$events,
|
|
561
|
-
_this4 = this;
|
|
562
|
-
var _this$events$onSyncSu, _this$events3, _syncResult$conflicts, requestData, dirtyColumnGrids, dirtyQueryGrids, dirtyCurrentGrids, response, responseData, syncResult, _this$events$onConfli, _this$events2, _this$events$onSyncEr, _this$events4;
|
|
563
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
564
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
565
|
-
case 0:
|
|
566
|
-
if (!this.syncing) {
|
|
567
|
-
_context4.next = 3;
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
console.log('[SchemeSyncManager] 正在同步中,跳过重复请求');
|
|
571
|
-
return _context4.abrupt("return");
|
|
572
|
-
case 3:
|
|
573
|
-
if (this.hasDirtyData()) {
|
|
574
|
-
_context4.next = 6;
|
|
575
|
-
break;
|
|
576
|
-
}
|
|
577
|
-
console.log('[SchemeSyncManager] 没有需要同步的数据');
|
|
578
|
-
return _context4.abrupt("return");
|
|
579
|
-
case 6:
|
|
580
|
-
this.syncing = true;
|
|
581
|
-
(_this$events$onSyncSt = (_this$events = this.events).onSyncStart) === null || _this$events$onSyncSt === void 0 || _this$events$onSyncSt.call(_this$events);
|
|
582
|
-
_context4.prev = 8;
|
|
583
|
-
// 构建同步请求数据
|
|
584
|
-
requestData = {
|
|
585
|
-
clientSyncTime: this.lastSyncTime
|
|
586
|
-
};
|
|
587
|
-
dirtyColumnGrids = new Set();
|
|
588
|
-
dirtyQueryGrids = new Set();
|
|
589
|
-
dirtyCurrentGrids = new Set();
|
|
590
|
-
this.dirtyGrids.forEach(function (types, gridId) {
|
|
591
|
-
if (types.has('column')) dirtyColumnGrids.add(gridId);
|
|
592
|
-
if (types.has('query')) dirtyQueryGrids.add(gridId);
|
|
593
|
-
if (types.has('current')) dirtyCurrentGrids.add(gridId);
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
// 添加列方案数据(将 columnConfig 序列化为 JSON 字符串并映射到 columnState 字段)
|
|
597
|
-
if (dirtyColumnGrids.size > 0) {
|
|
598
|
-
requestData.columnSchemes = {};
|
|
599
|
-
dirtyColumnGrids.forEach(function (gridId) {
|
|
600
|
-
var schemes = _this4.allData.columnSchemes[gridId] || [];
|
|
601
|
-
// 将每个方案的 columnConfig 从数组转换为 JSON 字符串,并映射到 columnState 字段
|
|
602
|
-
requestData.columnSchemes[gridId] = schemes.map(function (scheme) {
|
|
603
|
-
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
604
|
-
columnState: JSON.stringify(scheme.columnConfig)
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// 添加查询方案数据(将 itemsOrder 序列化为 JSON 字符串)
|
|
611
|
-
if (dirtyQueryGrids.size > 0) {
|
|
612
|
-
requestData.querySchemes = {};
|
|
613
|
-
dirtyQueryGrids.forEach(function (gridId) {
|
|
614
|
-
var schemes = _this4.allData.querySchemes[gridId] || [];
|
|
615
|
-
// 将每个方案的 itemsOrder 从数组转换为 JSON 字符串
|
|
616
|
-
requestData.querySchemes[gridId] = schemes.map(function (scheme) {
|
|
617
|
-
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
618
|
-
itemsOrder: JSON.stringify(scheme.itemsOrder)
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// 添加当前方案数据
|
|
625
|
-
if (dirtyCurrentGrids.size > 0) {
|
|
626
|
-
requestData.currentSchemes = {};
|
|
627
|
-
dirtyCurrentGrids.forEach(function (gridId) {
|
|
628
|
-
requestData.currentSchemes[gridId] = _this4.allData.currentSchemes[gridId] || {};
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// 发送同步请求
|
|
633
|
-
_context4.next = 19;
|
|
634
|
-
return this.fetchWithRetry(this.getSyncApiUrl(), {
|
|
635
|
-
method: 'POST',
|
|
636
|
-
headers: this.getHeaders(),
|
|
637
|
-
body: JSON.stringify(requestData)
|
|
638
|
-
});
|
|
639
|
-
case 19:
|
|
640
|
-
response = _context4.sent;
|
|
641
|
-
_context4.next = 22;
|
|
642
|
-
return response.json();
|
|
643
|
-
case 22:
|
|
644
|
-
responseData = _context4.sent;
|
|
645
|
-
if (!(responseData.success !== undefined)) {
|
|
646
|
-
_context4.next = 29;
|
|
647
|
-
break;
|
|
648
|
-
}
|
|
649
|
-
if (responseData.success) {
|
|
650
|
-
_context4.next = 26;
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
throw new Error(responseData.error || '同步失败');
|
|
654
|
-
case 26:
|
|
655
|
-
syncResult = responseData;
|
|
656
|
-
_context4.next = 34;
|
|
657
|
-
break;
|
|
658
|
-
case 29:
|
|
659
|
-
if (!(responseData.syncTime !== undefined)) {
|
|
660
|
-
_context4.next = 33;
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
// 格式2: 直接返回数据格式,构造一个兼容的结果对象
|
|
664
|
-
syncResult = {
|
|
665
|
-
success: true,
|
|
666
|
-
syncTime: responseData.syncTime,
|
|
667
|
-
conflicts: responseData.conflicts
|
|
668
|
-
};
|
|
669
|
-
_context4.next = 34;
|
|
670
|
-
break;
|
|
671
|
-
case 33:
|
|
672
|
-
throw new Error('同步失败:服务器返回的数据格式不正确');
|
|
673
|
-
case 34:
|
|
674
|
-
// 处理冲突
|
|
675
|
-
if (syncResult.conflicts && syncResult.conflicts.length > 0) {
|
|
676
|
-
this.handleConflicts(syncResult.conflicts);
|
|
677
|
-
(_this$events$onConfli = (_this$events2 = this.events).onConflict) === null || _this$events$onConfli === void 0 || _this$events$onConfli.call(_this$events2, syncResult.conflicts);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// 更新同步时间
|
|
681
|
-
if (syncResult.syncTime) {
|
|
682
|
-
this.lastSyncTime = syncResult.syncTime;
|
|
683
|
-
this.allData.syncTime = syncResult.syncTime;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// 清除脏数据标记
|
|
687
|
-
this.dirtyGrids.clear();
|
|
688
|
-
(_this$events$onSyncSu = (_this$events3 = this.events).onSyncSuccess) === null || _this$events$onSyncSu === void 0 || _this$events$onSyncSu.call(_this$events3, this.lastSyncTime);
|
|
689
|
-
console.log('[SchemeSyncManager] 同步成功:', {
|
|
690
|
-
syncTime: new Date(this.lastSyncTime).toISOString(),
|
|
691
|
-
conflicts: ((_syncResult$conflicts = syncResult.conflicts) === null || _syncResult$conflicts === void 0 ? void 0 : _syncResult$conflicts.length) || 0
|
|
692
|
-
});
|
|
693
|
-
_context4.next = 46;
|
|
694
|
-
break;
|
|
695
|
-
case 41:
|
|
696
|
-
_context4.prev = 41;
|
|
697
|
-
_context4.t0 = _context4["catch"](8);
|
|
698
|
-
console.error('[SchemeSyncManager] 同步失败:', _context4.t0);
|
|
699
|
-
(_this$events$onSyncEr = (_this$events4 = this.events).onSyncError) === null || _this$events$onSyncEr === void 0 || _this$events$onSyncEr.call(_this$events4, _context4.t0);
|
|
700
|
-
throw _context4.t0;
|
|
701
|
-
case 46:
|
|
702
|
-
_context4.prev = 46;
|
|
703
|
-
this.syncing = false;
|
|
704
|
-
return _context4.finish(46);
|
|
705
|
-
case 49:
|
|
706
|
-
case "end":
|
|
707
|
-
return _context4.stop();
|
|
708
|
-
}
|
|
709
|
-
}, _callee4, this, [[8, 41, 46, 49]]);
|
|
710
|
-
}));
|
|
711
|
-
function syncNow() {
|
|
712
|
-
return _syncNow.apply(this, arguments);
|
|
713
|
-
}
|
|
714
|
-
return syncNow;
|
|
715
|
-
}()
|
|
716
|
-
/**
|
|
717
|
-
* 处理冲突
|
|
718
|
-
*/
|
|
719
|
-
)
|
|
720
|
-
}, {
|
|
721
|
-
key: "handleConflicts",
|
|
722
|
-
value: function handleConflicts(conflicts) {
|
|
723
|
-
var _this5 = this;
|
|
724
|
-
conflicts.forEach(function (conflict) {
|
|
725
|
-
switch (_this5.config.conflictResolution) {
|
|
726
|
-
case 'server':
|
|
727
|
-
// 使用服务器版本
|
|
728
|
-
_this5.applyServerVersion(conflict);
|
|
729
|
-
break;
|
|
730
|
-
case 'client':
|
|
731
|
-
// 保持客户端版本(默认行为)
|
|
732
|
-
console.warn('[SchemeSyncManager] 冲突检测到,保持客户端版本:', conflict);
|
|
733
|
-
break;
|
|
734
|
-
case 'manual':
|
|
735
|
-
// 需要用户手动解决
|
|
736
|
-
console.warn('[SchemeSyncManager] 冲突需要手动解决:', conflict);
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* 应用服务器版本
|
|
744
|
-
*/
|
|
745
|
-
}, {
|
|
746
|
-
key: "applyServerVersion",
|
|
747
|
-
value: function applyServerVersion(conflict) {
|
|
748
|
-
var gridId = conflict.gridId,
|
|
749
|
-
type = conflict.type,
|
|
750
|
-
serverVersion = conflict.serverVersion;
|
|
751
|
-
switch (type) {
|
|
752
|
-
case 'column':
|
|
753
|
-
if (Array.isArray(serverVersion)) {
|
|
754
|
-
this.allData.columnSchemes[gridId] = serverVersion;
|
|
755
|
-
}
|
|
756
|
-
break;
|
|
757
|
-
case 'query':
|
|
758
|
-
if (Array.isArray(serverVersion)) {
|
|
759
|
-
this.allData.querySchemes[gridId] = serverVersion;
|
|
760
|
-
}
|
|
761
|
-
break;
|
|
762
|
-
case 'current':
|
|
763
|
-
this.allData.currentSchemes[gridId] = serverVersion;
|
|
764
|
-
break;
|
|
765
|
-
}
|
|
766
|
-
console.log('[SchemeSyncManager] 已应用服务器版本:', {
|
|
767
|
-
gridId: gridId,
|
|
768
|
-
type: type
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
/**
|
|
773
|
-
* 反序列化从后端接收的方案数据
|
|
774
|
-
* 将 columnState(后端字段) 映射为 columnConfig 并从 JSON 字符串转换为数组
|
|
775
|
-
* 将 itemsOrder 从 JSON 字符串转换为数组
|
|
776
|
-
*/
|
|
777
|
-
}, {
|
|
778
|
-
key: "deserializeSchemesData",
|
|
779
|
-
value: function deserializeSchemesData(data) {
|
|
780
|
-
var result = _objectSpread(_objectSpread({}, data), {}, {
|
|
781
|
-
columnSchemes: {},
|
|
782
|
-
querySchemes: {}
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
// 反序列化列方案
|
|
786
|
-
Object.entries(data.columnSchemes || {}).forEach(function (_ref5) {
|
|
787
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
788
|
-
gridId = _ref6[0],
|
|
789
|
-
schemes = _ref6[1];
|
|
790
|
-
result.columnSchemes[gridId] = schemes.map(function (scheme) {
|
|
791
|
-
// 后端返回的数据中,columnState 字段存储的是 columnConfig 的 JSON 字符串
|
|
792
|
-
// 需要将其解析为数组并映射到 columnConfig 字段
|
|
793
|
-
var schemeWithState = scheme; // 类型断言处理后端数据
|
|
794
|
-
var columnConfig = typeof schemeWithState.columnState === 'string' ? JSON.parse(schemeWithState.columnState) : schemeWithState.columnState;
|
|
795
|
-
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
796
|
-
columnConfig: columnConfig
|
|
797
|
-
});
|
|
798
|
-
});
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
// 反序列化查询方案
|
|
802
|
-
Object.entries(data.querySchemes || {}).forEach(function (_ref7) {
|
|
803
|
-
var _ref8 = _slicedToArray(_ref7, 2),
|
|
804
|
-
gridId = _ref8[0],
|
|
805
|
-
schemes = _ref8[1];
|
|
806
|
-
result.querySchemes[gridId] = schemes.map(function (scheme) {
|
|
807
|
-
// 如果 itemsOrder 是字符串,则解析为数组
|
|
808
|
-
var itemsOrder = typeof scheme.itemsOrder === 'string' ? JSON.parse(scheme.itemsOrder) : scheme.itemsOrder;
|
|
809
|
-
return _objectSpread(_objectSpread({}, scheme), {}, {
|
|
810
|
-
itemsOrder: itemsOrder
|
|
811
|
-
});
|
|
812
|
-
});
|
|
813
|
-
});
|
|
814
|
-
return result;
|
|
815
|
-
}
|
|
816
|
-
}, {
|
|
817
|
-
key: "fetchWithRetry",
|
|
818
|
-
value: (
|
|
819
|
-
/**
|
|
820
|
-
* 带重试的 fetch 请求
|
|
821
|
-
*/
|
|
822
|
-
function () {
|
|
823
|
-
var _fetchWithRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(url, options) {
|
|
824
|
-
var retries,
|
|
825
|
-
controller,
|
|
826
|
-
timeoutId,
|
|
827
|
-
response,
|
|
828
|
-
_args5 = arguments;
|
|
829
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
830
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
831
|
-
case 0:
|
|
832
|
-
retries = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : this.config.maxRetries;
|
|
833
|
-
_context5.prev = 1;
|
|
834
|
-
controller = new AbortController();
|
|
835
|
-
timeoutId = setTimeout(function () {
|
|
836
|
-
return controller.abort();
|
|
837
|
-
}, this.config.requestTimeout);
|
|
838
|
-
_context5.next = 6;
|
|
839
|
-
return fetch(url, _objectSpread(_objectSpread({}, options), {}, {
|
|
840
|
-
signal: controller.signal
|
|
841
|
-
}));
|
|
842
|
-
case 6:
|
|
843
|
-
response = _context5.sent;
|
|
844
|
-
clearTimeout(timeoutId);
|
|
845
|
-
if (response.ok) {
|
|
846
|
-
_context5.next = 10;
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
throw new Error("HTTP ".concat(response.status, ": ").concat(response.statusText));
|
|
850
|
-
case 10:
|
|
851
|
-
return _context5.abrupt("return", response);
|
|
852
|
-
case 13:
|
|
853
|
-
_context5.prev = 13;
|
|
854
|
-
_context5.t0 = _context5["catch"](1);
|
|
855
|
-
if (!(retries > 0)) {
|
|
856
|
-
_context5.next = 20;
|
|
857
|
-
break;
|
|
858
|
-
}
|
|
859
|
-
console.warn("[SchemeSyncManager] \u8BF7\u6C42\u5931\u8D25\uFF0C\u91CD\u8BD5\u4E2D... (\u5269\u4F59 ".concat(retries, " \u6B21)"), _context5.t0);
|
|
860
|
-
_context5.next = 19;
|
|
861
|
-
return new Promise(function (resolve) {
|
|
862
|
-
return setTimeout(resolve, 1000);
|
|
863
|
-
});
|
|
864
|
-
case 19:
|
|
865
|
-
return _context5.abrupt("return", this.fetchWithRetry(url, options, retries - 1));
|
|
866
|
-
case 20:
|
|
867
|
-
throw _context5.t0;
|
|
868
|
-
case 21:
|
|
869
|
-
case "end":
|
|
870
|
-
return _context5.stop();
|
|
871
|
-
}
|
|
872
|
-
}, _callee5, this, [[1, 13]]);
|
|
873
|
-
}));
|
|
874
|
-
function fetchWithRetry(_x2, _x3) {
|
|
875
|
-
return _fetchWithRetry.apply(this, arguments);
|
|
876
|
-
}
|
|
877
|
-
return fetchWithRetry;
|
|
878
|
-
}()
|
|
879
|
-
/**
|
|
880
|
-
* 获取同步状态信息
|
|
881
|
-
*/
|
|
882
|
-
)
|
|
883
|
-
}, {
|
|
884
|
-
key: "getSyncStatus",
|
|
885
|
-
value: function getSyncStatus() {
|
|
886
|
-
return {
|
|
887
|
-
initialized: this.initialized,
|
|
888
|
-
syncing: this.syncing,
|
|
889
|
-
lastSyncTime: this.lastSyncTime,
|
|
890
|
-
hasDirtyData: this.hasDirtyData(),
|
|
891
|
-
dirtyGrids: this.getDirtyGridIds()
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
}]);
|
|
895
|
-
return SchemeSyncManager;
|
|
896
|
-
}();
|