@pisell/pisellos 3.0.57 → 3.0.58

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.
Files changed (256) hide show
  1. package/dist/core/index.js +1 -2
  2. package/dist/effects/index.d.ts +3 -4
  3. package/dist/effects/index.js +6 -15
  4. package/dist/modules/AccountList/index.d.ts +1 -7
  5. package/dist/modules/AccountList/index.js +14 -81
  6. package/dist/modules/AccountList/types.d.ts +0 -28
  7. package/dist/modules/AccountList/types.js +0 -8
  8. package/dist/modules/Cart/index.js +1 -1
  9. package/dist/modules/Payment/index.d.ts +9 -273
  10. package/dist/modules/Payment/index.js +109 -2525
  11. package/dist/modules/Payment/types.d.ts +30 -382
  12. package/dist/modules/Payment/types.js +14 -116
  13. package/dist/modules/ProductList/index.d.ts +1 -12
  14. package/dist/modules/ProductList/index.js +3 -27
  15. package/dist/modules/Rules/index.js +14 -27
  16. package/dist/modules/Rules/types.d.ts +0 -1
  17. package/dist/modules/index.d.ts +0 -1
  18. package/dist/modules/index.js +0 -1
  19. package/dist/plugins/window.d.ts +0 -1
  20. package/dist/solution/BookingByStep/index.js +1 -9
  21. package/dist/solution/ShopDiscount/index.js +2 -4
  22. package/dist/solution/index.d.ts +0 -2
  23. package/dist/solution/index.js +1 -3
  24. package/dist/types/index.d.ts +1 -3
  25. package/lib/core/index.js +1 -1
  26. package/lib/effects/index.d.ts +3 -4
  27. package/lib/effects/index.js +1 -4
  28. package/lib/modules/AccountList/index.d.ts +1 -7
  29. package/lib/modules/AccountList/index.js +0 -27
  30. package/lib/modules/AccountList/types.d.ts +0 -28
  31. package/lib/modules/Cart/index.js +1 -1
  32. package/lib/modules/Payment/index.d.ts +9 -273
  33. package/lib/modules/Payment/index.js +50 -1285
  34. package/lib/modules/Payment/types.d.ts +30 -382
  35. package/lib/modules/Payment/types.js +6 -41
  36. package/lib/modules/ProductList/index.d.ts +1 -12
  37. package/lib/modules/ProductList/index.js +2 -29
  38. package/lib/modules/Rules/index.js +12 -20
  39. package/lib/modules/Rules/types.d.ts +0 -1
  40. package/lib/modules/index.d.ts +0 -1
  41. package/lib/modules/index.js +0 -2
  42. package/lib/plugins/window.d.ts +0 -1
  43. package/lib/solution/BookingByStep/index.js +2 -1
  44. package/lib/solution/ShopDiscount/index.js +1 -2
  45. package/lib/solution/index.d.ts +0 -2
  46. package/lib/solution/index.js +1 -5
  47. package/lib/types/index.d.ts +1 -3
  48. package/package.json +2 -4
  49. package/dist/modules/Customer/constants.d.ts +0 -7
  50. package/dist/modules/Customer/constants.js +0 -12
  51. package/dist/modules/Customer/index.d.ts +0 -122
  52. package/dist/modules/Customer/index.js +0 -697
  53. package/dist/modules/Customer/types.d.ts +0 -146
  54. package/dist/modules/Customer/types.js +0 -41
  55. package/dist/modules/Payment/cash.d.ts +0 -11
  56. package/dist/modules/Payment/cash.js +0 -78
  57. package/dist/modules/Payment/eftpos.d.ts +0 -11
  58. package/dist/modules/Payment/eftpos.js +0 -80
  59. package/dist/modules/Payment/wallet.d.ts +0 -11
  60. package/dist/modules/Payment/wallet.js +0 -78
  61. package/dist/modules/Payment/walletpass.d.ts +0 -0
  62. package/dist/modules/Payment/walletpass.js +0 -0
  63. package/dist/plugins/app-types/app/app.d.ts +0 -83
  64. package/dist/plugins/app-types/app/const.d.ts +0 -4
  65. package/dist/plugins/app-types/app/index.d.ts +0 -14
  66. package/dist/plugins/app-types/applicationManager/application.d.ts +0 -50
  67. package/dist/plugins/app-types/applicationManager/index.d.ts +0 -13
  68. package/dist/plugins/app-types/config.d.ts +0 -3
  69. package/dist/plugins/app-types/cookie/index.d.ts +0 -13
  70. package/dist/plugins/app-types/data/index.d.ts +0 -8
  71. package/dist/plugins/app-types/history/config.d.ts +0 -24
  72. package/dist/plugins/app-types/history/index.d.ts +0 -20
  73. package/dist/plugins/app-types/history/type.d.ts +0 -2
  74. package/dist/plugins/app-types/hooks/index.d.ts +0 -12
  75. package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +0 -2
  76. package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +0 -2
  77. package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +0 -13
  78. package/dist/plugins/app-types/hooks/useStore/index.d.ts +0 -6
  79. package/dist/plugins/app-types/index.d.ts +0 -6
  80. package/dist/plugins/app-types/indexDB/index.d.ts +0 -178
  81. package/dist/plugins/app-types/locales/en.d.ts +0 -3
  82. package/dist/plugins/app-types/locales/index.d.ts +0 -37
  83. package/dist/plugins/app-types/locales/original.d.ts +0 -3
  84. package/dist/plugins/app-types/locales/type.d.ts +0 -19
  85. package/dist/plugins/app-types/locales/zh-CN.d.ts +0 -3
  86. package/dist/plugins/app-types/locales/zh-HK.d.ts +0 -3
  87. package/dist/plugins/app-types/logger/feishu.d.ts +0 -11
  88. package/dist/plugins/app-types/logger/index.d.ts +0 -122
  89. package/dist/plugins/app-types/menuManager/hooks.d.ts +0 -17
  90. package/dist/plugins/app-types/menuManager/index.d.ts +0 -28
  91. package/dist/plugins/app-types/models/global.d.ts +0 -32
  92. package/dist/plugins/app-types/models/index.d.ts +0 -45
  93. package/dist/plugins/app-types/models/type.d.ts +0 -2
  94. package/dist/plugins/app-types/package.json +0 -15
  95. package/dist/plugins/app-types/plugin/index.d.ts +0 -0
  96. package/dist/plugins/app-types/pubsub/example.d.ts +0 -5
  97. package/dist/plugins/app-types/pubsub/index.d.ts +0 -63
  98. package/dist/plugins/app-types/request/cache.d.ts +0 -46
  99. package/dist/plugins/app-types/request/cancelToken.d.ts +0 -38
  100. package/dist/plugins/app-types/request/config.d.ts +0 -3
  101. package/dist/plugins/app-types/request/constants.d.ts +0 -2
  102. package/dist/plugins/app-types/request/index.d.ts +0 -24
  103. package/dist/plugins/app-types/request/pisell2Request.d.ts +0 -6
  104. package/dist/plugins/app-types/request/type.d.ts +0 -41
  105. package/dist/plugins/app-types/request/utils.d.ts +0 -46
  106. package/dist/plugins/app-types/routes/config.d.ts +0 -7
  107. package/dist/plugins/app-types/routes/index.d.ts +0 -28
  108. package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +0 -6
  109. package/dist/plugins/app-types/socket/components/index.d.ts +0 -2
  110. package/dist/plugins/app-types/socket/constants.d.ts +0 -33
  111. package/dist/plugins/app-types/socket/events.d.ts +0 -31
  112. package/dist/plugins/app-types/socket/heartbeat.d.ts +0 -66
  113. package/dist/plugins/app-types/socket/index.d.ts +0 -61
  114. package/dist/plugins/app-types/socket/monitor.d.ts +0 -169
  115. package/dist/plugins/app-types/socket/reconnect.d.ts +0 -61
  116. package/dist/plugins/app-types/socket/socket.d.ts +0 -129
  117. package/dist/plugins/app-types/socket/types.d.ts +0 -85
  118. package/dist/plugins/app-types/storage/index.d.ts +0 -17
  119. package/dist/plugins/app-types/tasks/index.d.ts +0 -77
  120. package/dist/plugins/app-types/tasks/type.d.ts +0 -62
  121. package/dist/plugins/app-types/tasks/useTasks.d.ts +0 -5
  122. package/dist/plugins/app-types/type.d.ts +0 -2
  123. package/dist/plugins/app-types/variables/VariablesProvider.d.ts +0 -7
  124. package/dist/plugins/app-types/variables/config.d.ts +0 -3
  125. package/dist/plugins/app-types/variables/index.d.ts +0 -6
  126. package/dist/plugins/app-types/variables/type.d.ts +0 -2
  127. package/dist/plugins/app-types/website/index.d.ts +0 -6
  128. package/dist/plugins/app.d.ts +0 -8
  129. package/dist/plugins/app.js +0 -1
  130. package/dist/solution/BookingTicket/index.d.ts +0 -172
  131. package/dist/solution/BookingTicket/index.js +0 -665
  132. package/dist/solution/BookingTicket/types.d.ts +0 -68
  133. package/dist/solution/BookingTicket/types.js +0 -43
  134. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +0 -22
  135. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +0 -159
  136. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +0 -16
  137. package/dist/solution/BookingTicket/utils/scan/handleScan.js +0 -174
  138. package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -81
  139. package/dist/solution/BookingTicket/utils/scan/index.js +0 -285
  140. package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +0 -78
  141. package/dist/solution/BookingTicket/utils/scan/scanCache.js +0 -305
  142. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  143. package/dist/solution/Checkout/index.d.ts +0 -181
  144. package/dist/solution/Checkout/index.js +0 -1596
  145. package/dist/solution/Checkout/types.d.ts +0 -550
  146. package/dist/solution/Checkout/types.js +0 -132
  147. package/dist/solution/Checkout/utils/index.d.ts +0 -73
  148. package/dist/solution/Checkout/utils/index.js +0 -371
  149. package/dist/utils/task.d.ts +0 -40
  150. package/dist/utils/task.js +0 -171
  151. package/dist/utils/watch.d.ts +0 -102
  152. package/dist/utils/watch.js +0 -294
  153. package/lib/modules/Customer/constants.d.ts +0 -7
  154. package/lib/modules/Customer/constants.js +0 -39
  155. package/lib/modules/Customer/index.d.ts +0 -122
  156. package/lib/modules/Customer/index.js +0 -440
  157. package/lib/modules/Customer/types.d.ts +0 -146
  158. package/lib/modules/Customer/types.js +0 -37
  159. package/lib/modules/Payment/cash.d.ts +0 -11
  160. package/lib/modules/Payment/cash.js +0 -51
  161. package/lib/modules/Payment/eftpos.d.ts +0 -11
  162. package/lib/modules/Payment/eftpos.js +0 -51
  163. package/lib/modules/Payment/wallet.d.ts +0 -11
  164. package/lib/modules/Payment/wallet.js +0 -51
  165. package/lib/modules/Payment/walletpass.d.ts +0 -0
  166. package/lib/modules/Payment/walletpass.js +0 -0
  167. package/lib/plugins/app-types/app/app.d.ts +0 -83
  168. package/lib/plugins/app-types/app/const.d.ts +0 -4
  169. package/lib/plugins/app-types/app/index.d.ts +0 -14
  170. package/lib/plugins/app-types/applicationManager/application.d.ts +0 -50
  171. package/lib/plugins/app-types/applicationManager/index.d.ts +0 -13
  172. package/lib/plugins/app-types/config.d.ts +0 -3
  173. package/lib/plugins/app-types/cookie/index.d.ts +0 -13
  174. package/lib/plugins/app-types/data/index.d.ts +0 -8
  175. package/lib/plugins/app-types/history/config.d.ts +0 -24
  176. package/lib/plugins/app-types/history/index.d.ts +0 -20
  177. package/lib/plugins/app-types/history/type.d.ts +0 -2
  178. package/lib/plugins/app-types/hooks/index.d.ts +0 -12
  179. package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +0 -2
  180. package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +0 -2
  181. package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +0 -13
  182. package/lib/plugins/app-types/hooks/useStore/index.d.ts +0 -6
  183. package/lib/plugins/app-types/index.d.ts +0 -6
  184. package/lib/plugins/app-types/indexDB/index.d.ts +0 -178
  185. package/lib/plugins/app-types/locales/en.d.ts +0 -3
  186. package/lib/plugins/app-types/locales/index.d.ts +0 -37
  187. package/lib/plugins/app-types/locales/original.d.ts +0 -3
  188. package/lib/plugins/app-types/locales/type.d.ts +0 -19
  189. package/lib/plugins/app-types/locales/zh-CN.d.ts +0 -3
  190. package/lib/plugins/app-types/locales/zh-HK.d.ts +0 -3
  191. package/lib/plugins/app-types/logger/feishu.d.ts +0 -11
  192. package/lib/plugins/app-types/logger/index.d.ts +0 -122
  193. package/lib/plugins/app-types/menuManager/hooks.d.ts +0 -17
  194. package/lib/plugins/app-types/menuManager/index.d.ts +0 -28
  195. package/lib/plugins/app-types/models/global.d.ts +0 -32
  196. package/lib/plugins/app-types/models/index.d.ts +0 -45
  197. package/lib/plugins/app-types/models/type.d.ts +0 -2
  198. package/lib/plugins/app-types/package.json +0 -15
  199. package/lib/plugins/app-types/plugin/index.d.ts +0 -0
  200. package/lib/plugins/app-types/pubsub/example.d.ts +0 -5
  201. package/lib/plugins/app-types/pubsub/index.d.ts +0 -63
  202. package/lib/plugins/app-types/request/cache.d.ts +0 -46
  203. package/lib/plugins/app-types/request/cancelToken.d.ts +0 -38
  204. package/lib/plugins/app-types/request/config.d.ts +0 -3
  205. package/lib/plugins/app-types/request/constants.d.ts +0 -2
  206. package/lib/plugins/app-types/request/index.d.ts +0 -24
  207. package/lib/plugins/app-types/request/pisell2Request.d.ts +0 -6
  208. package/lib/plugins/app-types/request/type.d.ts +0 -41
  209. package/lib/plugins/app-types/request/utils.d.ts +0 -46
  210. package/lib/plugins/app-types/routes/config.d.ts +0 -7
  211. package/lib/plugins/app-types/routes/index.d.ts +0 -28
  212. package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +0 -6
  213. package/lib/plugins/app-types/socket/components/index.d.ts +0 -2
  214. package/lib/plugins/app-types/socket/constants.d.ts +0 -33
  215. package/lib/plugins/app-types/socket/events.d.ts +0 -31
  216. package/lib/plugins/app-types/socket/heartbeat.d.ts +0 -66
  217. package/lib/plugins/app-types/socket/index.d.ts +0 -61
  218. package/lib/plugins/app-types/socket/monitor.d.ts +0 -169
  219. package/lib/plugins/app-types/socket/reconnect.d.ts +0 -61
  220. package/lib/plugins/app-types/socket/socket.d.ts +0 -129
  221. package/lib/plugins/app-types/socket/types.d.ts +0 -85
  222. package/lib/plugins/app-types/storage/index.d.ts +0 -17
  223. package/lib/plugins/app-types/tasks/index.d.ts +0 -77
  224. package/lib/plugins/app-types/tasks/type.d.ts +0 -62
  225. package/lib/plugins/app-types/tasks/useTasks.d.ts +0 -5
  226. package/lib/plugins/app-types/type.d.ts +0 -2
  227. package/lib/plugins/app-types/variables/VariablesProvider.d.ts +0 -7
  228. package/lib/plugins/app-types/variables/config.d.ts +0 -3
  229. package/lib/plugins/app-types/variables/index.d.ts +0 -6
  230. package/lib/plugins/app-types/variables/type.d.ts +0 -2
  231. package/lib/plugins/app-types/website/index.d.ts +0 -6
  232. package/lib/plugins/app.d.ts +0 -8
  233. package/lib/plugins/app.js +0 -17
  234. package/lib/solution/BookingTicket/index.d.ts +0 -172
  235. package/lib/solution/BookingTicket/index.js +0 -399
  236. package/lib/solution/BookingTicket/types.d.ts +0 -68
  237. package/lib/solution/BookingTicket/types.js +0 -72
  238. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +0 -22
  239. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +0 -117
  240. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +0 -16
  241. package/lib/solution/BookingTicket/utils/scan/handleScan.js +0 -125
  242. package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -81
  243. package/lib/solution/BookingTicket/utils/scan/index.js +0 -210
  244. package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +0 -78
  245. package/lib/solution/BookingTicket/utils/scan/scanCache.js +0 -231
  246. package/lib/solution/Checkout/appointmentDemo.json +0 -1
  247. package/lib/solution/Checkout/index.d.ts +0 -181
  248. package/lib/solution/Checkout/index.js +0 -864
  249. package/lib/solution/Checkout/types.d.ts +0 -550
  250. package/lib/solution/Checkout/types.js +0 -75
  251. package/lib/solution/Checkout/utils/index.d.ts +0 -73
  252. package/lib/solution/Checkout/utils/index.js +0 -266
  253. package/lib/utils/task.d.ts +0 -40
  254. package/lib/utils/task.js +0 -109
  255. package/lib/utils/watch.d.ts +0 -102
  256. package/lib/utils/watch.js +0 -217
@@ -1,285 +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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
- 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); } }
7
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
- 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; }
9
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
- 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); }
11
- import watch from "../../../../utils/watch";
12
- import Tasks from "../../../../utils/task";
13
- var ScanResultType = /*#__PURE__*/function (ScanResultType) {
14
- ScanResultType["Scanner"] = "scanner";
15
- ScanResultType["NFC"] = "nfc";
16
- ScanResultType["NativeScanner"] = "nativeScanner";
17
- return ScanResultType;
18
- }(ScanResultType || {});
19
- var Scan = /*#__PURE__*/function () {
20
- function Scan(solution, watchKey) {
21
- var _this$solution,
22
- _this$solution$mountF,
23
- _this = this;
24
- _classCallCheck(this, Scan);
25
- _defineProperty(this, "solution", void 0);
26
- _defineProperty(this, "watchKey", void 0);
27
- _defineProperty(this, "listenerConfig", new Map());
28
- this.solution = solution;
29
- this.watchKey = watchKey;
30
-
31
- // 监听扫码结果
32
- (_this$solution = this.solution) === null || _this$solution === void 0 || (_this$solution = _this$solution.window) === null || _this$solution === void 0 || (_this$solution = _this$solution.interaction) === null || _this$solution === void 0 || (_this$solution = _this$solution.utils) === null || _this$solution === void 0 || (_this$solution$mountF = _this$solution.mountFunction) === null || _this$solution$mountF === void 0 || _this$solution$mountF.call(_this$solution, 'global', 'peripheralsResult', function (strVal) {
33
- try {
34
- var _result = JSON.parse(strVal);
35
- console.log('nativeScannerResult>>>>>>>', _result);
36
- _this.handleScan(_result);
37
- } catch (err) {
38
- console.error(err);
39
- }
40
- });
41
- }
42
-
43
- /**
44
- * 处理扫码事件
45
- * @param eventKey 事件key
46
- * @param value 扫码结果
47
- */
48
- _createClass(Scan, [{
49
- key: "handleScan",
50
- value: function handleScan(result) {
51
- var lastEnableEventKey = watch.getLastEnableEventKey(this.watchKey);
52
- if (lastEnableEventKey) {
53
- var listenerConfig = this.listenerConfig.get(lastEnableEventKey);
54
- if (listenerConfig) {
55
- listenerConfig.task.addTask({
56
- uuid: this.generateUuid(),
57
- type: lastEnableEventKey,
58
- actionParams: {
59
- scanResult: result
60
- }
61
- });
62
- }
63
- }
64
- }
65
-
66
- /**
67
- * 生成uuid
68
- * @returns uuid
69
- */
70
- }, {
71
- key: "generateUuid",
72
- value: function generateUuid() {
73
- // 需要加入时间戳,避免重复
74
- return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
75
- }
76
-
77
- /**
78
- * 添加扫码信息监听
79
- * @param watchKey 监听的key
80
- * @param event 事件
81
- */
82
- }, {
83
- key: "addListener",
84
- value: function addListener(event, scanCallback) {
85
- var _this2 = this;
86
- // 订阅事件
87
- watch.subscribe(this.watchKey, event);
88
- // 创建任务
89
- var task = new Tasks();
90
- task.addAction(event.key, function () {
91
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
92
- args[_key] = arguments[_key];
93
- }
94
- return _this2.scanTaskAction.apply(_this2, [event.key].concat(args));
95
- });
96
-
97
- // 创建监听配置
98
- this.listenerConfig.set(event.key, {
99
- scanCallback: scanCallback,
100
- task: task
101
- });
102
- return {
103
- remove: function remove() {
104
- _this2.removeListener(event);
105
- }
106
- };
107
- }
108
-
109
- /**
110
- * 移除扫码信息监听
111
- * @param watchKey 监听的key
112
- * @param event 事件
113
- */
114
- }, {
115
- key: "removeListener",
116
- value: function removeListener(event) {
117
- var _this$listenerConfig$;
118
- watch.unsubscribe(this.watchKey, event);
119
- (_this$listenerConfig$ = this.listenerConfig.get(event.key)) === null || _this$listenerConfig$ === void 0 || (_this$listenerConfig$ = _this$listenerConfig$.task) === null || _this$listenerConfig$ === void 0 || _this$listenerConfig$.clear();
120
- this.listenerConfig.delete(event.key);
121
- }
122
-
123
- /**
124
- * 移除所有监听
125
- */
126
- }, {
127
- key: "removeAllListeners",
128
- value: function removeAllListeners() {
129
- var _this$listenerConfig, _this$listenerConfig$2, _this$listenerConfig2, _this$listenerConfig3;
130
- watch.clearEvent(this.watchKey);
131
- (_this$listenerConfig = this.listenerConfig) === null || _this$listenerConfig === void 0 || (_this$listenerConfig$2 = _this$listenerConfig.forEach) === null || _this$listenerConfig$2 === void 0 || _this$listenerConfig$2.call(_this$listenerConfig, function (item) {
132
- var _item$task;
133
- item === null || item === void 0 || (_item$task = item.task) === null || _item$task === void 0 || _item$task.clear();
134
- });
135
- (_this$listenerConfig2 = this.listenerConfig) === null || _this$listenerConfig2 === void 0 || (_this$listenerConfig3 = _this$listenerConfig2.clear) === null || _this$listenerConfig3 === void 0 || _this$listenerConfig3.call(_this$listenerConfig2);
136
- }
137
-
138
- /**
139
- * 启用所有监听
140
- */
141
- }, {
142
- key: "enableAllListeners",
143
- value: function enableAllListeners() {
144
- watch.enableAllEventByWatchKey(this.watchKey);
145
- }
146
-
147
- /**
148
- * 禁用所有监听,并清空任务执行队列
149
- */
150
- }, {
151
- key: "disableAllListeners",
152
- value: function disableAllListeners() {
153
- var _this$listenerConfig4, _this$listenerConfig5;
154
- watch.disabledAllEventByWatchKey(this.watchKey);
155
- // 清空任务
156
- (_this$listenerConfig4 = this.listenerConfig) === null || _this$listenerConfig4 === void 0 || (_this$listenerConfig5 = _this$listenerConfig4.forEach) === null || _this$listenerConfig5 === void 0 || _this$listenerConfig5.call(_this$listenerConfig4, function (item) {
157
- var _item$task2;
158
- item === null || item === void 0 || (_item$task2 = item.task) === null || _item$task2 === void 0 || _item$task2.clearTaskQueue();
159
- });
160
- }
161
-
162
- /**
163
- * 清空监听对应的任务执行队列,不传入eventKey则清空所有监听对应的任务执行队列
164
- * @param eventKey 事件key
165
- */
166
- }, {
167
- key: "clearTaskQueue",
168
- value: function clearTaskQueue(eventKey) {
169
- console.log('clearTaskQueue>>>>>>>', eventKey);
170
- if (eventKey) {
171
- var _this$listenerConfig$3;
172
- (_this$listenerConfig$3 = this.listenerConfig.get(eventKey)) === null || _this$listenerConfig$3 === void 0 || _this$listenerConfig$3.task.clearTaskQueue();
173
- } else {
174
- var _this$listenerConfig6, _this$listenerConfig7;
175
- (_this$listenerConfig6 = this.listenerConfig) === null || _this$listenerConfig6 === void 0 || (_this$listenerConfig7 = _this$listenerConfig6.forEach) === null || _this$listenerConfig7 === void 0 || _this$listenerConfig7.call(_this$listenerConfig6, function (item) {
176
- var _item$task3;
177
- item === null || item === void 0 || (_item$task3 = item.task) === null || _item$task3 === void 0 || _item$task3.clearTaskQueue();
178
- });
179
- }
180
- }
181
-
182
- /**
183
- * 获取监听配置
184
- * @param eventKey 事件key
185
- * @returns 监听配置
186
- */
187
- }, {
188
- key: "getListenerConfig",
189
- value: function getListenerConfig(eventKey) {
190
- var _this$listenerConfig8;
191
- return (_this$listenerConfig8 = this.listenerConfig) === null || _this$listenerConfig8 === void 0 ? void 0 : _this$listenerConfig8.get(eventKey);
192
- }
193
-
194
- /**
195
- * 扫码任务执行函数
196
- * @param args 参数
197
- */
198
- }, {
199
- key: "scanTaskAction",
200
- value: (function () {
201
- var _scanTaskAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
202
- var _len2,
203
- args,
204
- _key2,
205
- eventKey,
206
- other,
207
- _ref,
208
- type,
209
- value,
210
- data,
211
- taskItemUuid,
212
- _ref2,
213
- scanCallback,
214
- task,
215
- _result2,
216
- _args = arguments;
217
- return _regeneratorRuntime().wrap(function _callee$(_context) {
218
- while (1) switch (_context.prev = _context.next) {
219
- case 0:
220
- for (_len2 = _args.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
221
- args[_key2] = _args[_key2];
222
- }
223
- eventKey = args[0], other = args[1];
224
- _ref = (other === null || other === void 0 ? void 0 : other.scanResult) || {}, type = _ref.type, value = _ref.value, data = _ref.data;
225
- taskItemUuid = other === null || other === void 0 ? void 0 : other.uuid;
226
- _ref2 = this.getListenerConfig(eventKey) || {}, scanCallback = _ref2.scanCallback, task = _ref2.task;
227
- if (!scanCallback) {
228
- _context.next = 18;
229
- break;
230
- }
231
- _context.prev = 6;
232
- _context.next = 9;
233
- return scanCallback({
234
- type: type,
235
- value: value
236
- });
237
- case 9:
238
- _result2 = _context.sent;
239
- console.log("".concat(eventKey, "_result>>>>>>>"), _result2);
240
- // 如果任务存在,则发布结果
241
- if (taskItemUuid && task !== null && task !== void 0 && task.isTaskExist(taskItemUuid)) {
242
- watch.publishByEventKey(this.watchKey, eventKey, {
243
- type: eventKey,
244
- status: 'success',
245
- scanType: type,
246
- scanCode: value,
247
- scanData: data,
248
- result: _result2
249
- });
250
- } else {
251
- console.warn("".concat(eventKey, "_result_task_not_exist>>>>>>>"), task);
252
- }
253
- _context.next = 18;
254
- break;
255
- case 14:
256
- _context.prev = 14;
257
- _context.t0 = _context["catch"](6);
258
- console.log("".concat(eventKey, "_result_error>>>>>>>"), _context.t0);
259
- // 如果任务存在,则发布结果
260
- if (taskItemUuid && task !== null && task !== void 0 && task.isTaskExist(taskItemUuid)) {
261
- watch.publishByEventKey(this.watchKey, eventKey, {
262
- type: eventKey,
263
- status: 'failed',
264
- scanType: type,
265
- scanCode: value,
266
- scanData: data
267
- });
268
- } else {
269
- console.warn("".concat(eventKey, "_result_error_task_not_exist>>>>>>>"), task);
270
- }
271
- case 18:
272
- case "end":
273
- return _context.stop();
274
- }
275
- }, _callee, this, [[6, 14]]);
276
- }));
277
- function scanTaskAction() {
278
- return _scanTaskAction.apply(this, arguments);
279
- }
280
- return scanTaskAction;
281
- }())
282
- }]);
283
- return Scan;
284
- }();
285
- export { Scan as default };
@@ -1,78 +0,0 @@
1
- /**
2
- * LRU缓存类,用于缓存接口数据
3
- * 限制最多存储100条数据,超过时移除最久未使用的数据
4
- * 支持数据压缩以减小缓存压力
5
- * 尾部优先策略:新节点插入尾部,最近使用的节点移动到尾部,删除头部节点
6
- */
7
- declare class LRUCache<T> {
8
- private head;
9
- private tail;
10
- private keyMap;
11
- private readonly maxSize;
12
- constructor(maxSize?: number);
13
- /**
14
- * 将节点移动到链表尾部(最近使用)
15
- * @param node 要移动的节点
16
- */
17
- private moveToTail;
18
- /**
19
- * 添加新节点到链表尾部
20
- * @param key 缓存键
21
- * @param compressedData 压缩后的数据
22
- * @param timestamp 时间戳
23
- */
24
- private addToTail;
25
- /**
26
- * 从链表中移除节点
27
- * @param node 要移除的节点
28
- */
29
- private removeNode;
30
- /**
31
- * 移除最久未使用的节点(链表头部)
32
- */
33
- private removeOldest;
34
- /**
35
- * 设置缓存
36
- * @param key 缓存键
37
- * @param data 缓存数据
38
- */
39
- set(key: string, data: T): void;
40
- /**
41
- * 获取缓存
42
- * @param key 缓存键
43
- * @returns 缓存数据或undefined
44
- */
45
- get(key: string): T | undefined;
46
- /**
47
- * 检查是否存在缓存
48
- * @param key 缓存键
49
- * @returns 是否存在
50
- */
51
- has(key: string): boolean;
52
- /**
53
- * 清除所有缓存
54
- */
55
- clear(): void;
56
- /**
57
- * 获取缓存大小
58
- * @returns 当前缓存数量
59
- */
60
- size(): number;
61
- /**
62
- * 获取缓存统计信息
63
- * @returns 缓存统计信息
64
- */
65
- getStats(): {
66
- size: number;
67
- maxSize: number;
68
- usage: number;
69
- };
70
- /**
71
- * 删除指定的缓存项
72
- * @param key 要删除的缓存键
73
- * @returns 是否删除成功
74
- */
75
- delete(key: string): boolean;
76
- }
77
- declare const scanCache: LRUCache<any>;
78
- export default scanCache;
@@ -1,305 +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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
- 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); } }
4
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
- 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; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
- 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); }
8
- /**
9
- * 简单的数据压缩函数
10
- * @param data 要压缩的数据
11
- * @returns 压缩后的字符串
12
- */
13
- var compressData = function compressData(data) {
14
- try {
15
- // 处理undefined值
16
- if (data === undefined) {
17
- return 'undefined';
18
- }
19
- return JSON.stringify(data);
20
- } catch (error) {
21
- console.warn('数据压缩失败:', error);
22
- return JSON.stringify(data);
23
- }
24
- };
25
-
26
- /**
27
- * 数据解压缩函数
28
- * @param compressedData 压缩后的数据
29
- * @returns 解压缩后的数据
30
- */
31
- var decompressData = function decompressData(compressedData) {
32
- try {
33
- // 处理undefined值
34
- if (compressedData === 'undefined') {
35
- return undefined;
36
- }
37
- return JSON.parse(compressedData);
38
- } catch (error) {
39
- console.warn('数据解压缩失败:', error);
40
- return null;
41
- }
42
- };
43
-
44
- /**
45
- * 双向链表节点
46
- */
47
- /**
48
- * LRU缓存类,用于缓存接口数据
49
- * 限制最多存储100条数据,超过时移除最久未使用的数据
50
- * 支持数据压缩以减小缓存压力
51
- * 尾部优先策略:新节点插入尾部,最近使用的节点移动到尾部,删除头部节点
52
- */
53
- var LRUCache = /*#__PURE__*/function () {
54
- function LRUCache() {
55
- var maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
56
- _classCallCheck(this, LRUCache);
57
- _defineProperty(this, "head", null);
58
- // 最久未使用的节点
59
- _defineProperty(this, "tail", null);
60
- // 最近使用的节点
61
- _defineProperty(this, "keyMap", new Map());
62
- // key到节点的映射(只存储引用)
63
- _defineProperty(this, "maxSize", void 0);
64
- this.maxSize = maxSize;
65
- }
66
-
67
- /**
68
- * 将节点移动到链表尾部(最近使用)
69
- * @param node 要移动的节点
70
- */
71
- _createClass(LRUCache, [{
72
- key: "moveToTail",
73
- value: function moveToTail(node) {
74
- if (this.tail === node) return; // 已经是尾部
75
-
76
- // 从当前位置移除
77
- if (node.prev) {
78
- node.prev.next = node.next;
79
- }
80
- if (node.next) {
81
- node.next.prev = node.prev;
82
- }
83
-
84
- // 如果是头部,更新头部
85
- if (this.head === node) {
86
- this.head = node.next;
87
- }
88
-
89
- // 移动到尾部
90
- if (this.tail) {
91
- this.tail.next = node;
92
- }
93
- node.prev = this.tail;
94
- node.next = null;
95
- this.tail = node;
96
-
97
- // 如果链表为空,设置头部
98
- if (!this.head) {
99
- this.head = node;
100
- }
101
- }
102
-
103
- /**
104
- * 添加新节点到链表尾部
105
- * @param key 缓存键
106
- * @param compressedData 压缩后的数据
107
- * @param timestamp 时间戳
108
- */
109
- }, {
110
- key: "addToTail",
111
- value: function addToTail(key, compressedData, timestamp) {
112
- // 先保存当前的tail引用
113
- var oldTail = this.tail;
114
- var node = {
115
- key: key,
116
- compressedData: compressedData,
117
- timestamp: timestamp,
118
- prev: oldTail,
119
- // 使用保存的引用,避免循环引用
120
- next: null
121
- };
122
-
123
- // 存储节点引用
124
- this.keyMap.set(key, node);
125
-
126
- // 更新链表关系
127
- if (oldTail) {
128
- oldTail.next = node;
129
- }
130
- this.tail = node;
131
-
132
- // 如果是第一个节点,设置head
133
- if (!this.head) {
134
- this.head = node;
135
- }
136
- return node;
137
- }
138
-
139
- /**
140
- * 从链表中移除节点
141
- * @param node 要移除的节点
142
- */
143
- }, {
144
- key: "removeNode",
145
- value: function removeNode(node) {
146
- if (node.prev) {
147
- node.prev.next = node.next;
148
- }
149
- if (node.next) {
150
- node.next.prev = node.prev;
151
- }
152
- if (this.head === node) {
153
- this.head = node.next;
154
- }
155
- if (this.tail === node) {
156
- this.tail = node.prev;
157
- }
158
-
159
- // 从Map中移除引用
160
- this.keyMap.delete(node.key);
161
- }
162
-
163
- /**
164
- * 移除最久未使用的节点(链表头部)
165
- */
166
- }, {
167
- key: "removeOldest",
168
- value: function removeOldest() {
169
- if (this.head) {
170
- this.removeNode(this.head);
171
- }
172
- }
173
-
174
- /**
175
- * 设置缓存
176
- * @param key 缓存键
177
- * @param data 缓存数据
178
- */
179
- }, {
180
- key: "set",
181
- value: function set(key, data) {
182
- // 压缩数据
183
- var compressedData = compressData(data);
184
- var timestamp = Date.now();
185
-
186
- // 检查是否已存在该key
187
- var existingNode = this.keyMap.get(key);
188
- if (existingNode) {
189
- // 如果已存在,更新数据并移动到链表尾部
190
- existingNode.compressedData = compressedData;
191
- existingNode.timestamp = timestamp;
192
- this.moveToTail(existingNode);
193
- } else {
194
- // 如果是新数据且缓存已满,移除最久未使用的数据(头部)
195
- if (this.keyMap.size >= this.maxSize) {
196
- this.removeOldest();
197
- }
198
-
199
- // 添加新数据到尾部
200
- this.addToTail(key, compressedData, timestamp);
201
- }
202
- }
203
-
204
- /**
205
- * 获取缓存
206
- * @param key 缓存键
207
- * @returns 缓存数据或undefined
208
- */
209
- }, {
210
- key: "get",
211
- value: function get(key) {
212
- var node = this.keyMap.get(key);
213
- if (node) {
214
- // 解压缩数据
215
- var decompressedData = decompressData(node.compressedData);
216
- if (decompressedData !== null) {
217
- // 更新访问时间戳并移动到链表尾部
218
- node.timestamp = Date.now();
219
- this.moveToTail(node);
220
- return decompressedData;
221
- } else {
222
- // 如果解压缩失败,删除该缓存项
223
- this.removeNode(node);
224
- return undefined;
225
- }
226
- }
227
- return undefined;
228
- }
229
-
230
- /**
231
- * 检查是否存在缓存
232
- * @param key 缓存键
233
- * @returns 是否存在
234
- */
235
- }, {
236
- key: "has",
237
- value: function has(key) {
238
- return this.keyMap.has(key);
239
- }
240
-
241
- /**
242
- * 清除所有缓存
243
- */
244
- }, {
245
- key: "clear",
246
- value: function clear() {
247
- // 清除所有节点的引用关系,帮助垃圾回收
248
- var current = this.head;
249
- while (current) {
250
- var next = current.next;
251
- current.prev = null;
252
- current.next = null;
253
- current = next;
254
- }
255
-
256
- // 清除Map和头尾指针
257
- this.keyMap.clear();
258
- this.head = null;
259
- this.tail = null;
260
- }
261
-
262
- /**
263
- * 获取缓存大小
264
- * @returns 当前缓存数量
265
- */
266
- }, {
267
- key: "size",
268
- value: function size() {
269
- return this.keyMap.size;
270
- }
271
-
272
- /**
273
- * 获取缓存统计信息
274
- * @returns 缓存统计信息
275
- */
276
- }, {
277
- key: "getStats",
278
- value: function getStats() {
279
- return {
280
- size: this.keyMap.size,
281
- maxSize: this.maxSize,
282
- usage: Math.round(this.keyMap.size / this.maxSize * 100)
283
- };
284
- }
285
-
286
- /**
287
- * 删除指定的缓存项
288
- * @param key 要删除的缓存键
289
- * @returns 是否删除成功
290
- */
291
- }, {
292
- key: "delete",
293
- value: function _delete(key) {
294
- var node = this.keyMap.get(key);
295
- if (node) {
296
- this.removeNode(node);
297
- return true;
298
- }
299
- return false;
300
- }
301
- }]);
302
- return LRUCache;
303
- }(); // 创建全局缓存实例
304
- var scanCache = new LRUCache();
305
- export default scanCache;