@pisell/pisellos 2.1.38 → 2.2.1
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/core/index.d.ts +8 -1
- package/dist/core/index.js +116 -42
- package/dist/effects/index.d.ts +1 -0
- package/dist/effects/index.js +29 -6
- package/dist/modules/Account/index.js +2 -3
- package/dist/modules/BaseModule.d.ts +3 -0
- package/dist/modules/BaseModule.js +15 -0
- package/dist/modules/Customer/index.js +9 -10
- package/dist/modules/Customer/types.d.ts +2 -2
- package/dist/modules/Customer/types.js +2 -2
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Guests/index.js +9 -9
- package/dist/modules/Order/index.js +1 -1
- package/dist/modules/Payment/index.js +63 -73
- package/dist/modules/Payment/walletpass.js +4 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +19 -0
- package/dist/modules/ProductList/index.js +5 -14
- package/dist/modules/Resource/index.js +1 -1
- package/dist/modules/Rules/index.js +2 -3
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/plugins/request.d.ts +1 -0
- package/dist/server/index.d.ts +152 -0
- package/dist/server/index.js +946 -0
- package/dist/server/modules/index.d.ts +16 -0
- package/dist/server/modules/index.js +21 -0
- package/dist/server/modules/menu/index.d.ts +63 -0
- package/dist/server/modules/menu/index.js +476 -0
- package/dist/server/modules/menu/types.d.ts +68 -0
- package/dist/server/modules/menu/types.js +16 -0
- package/dist/server/modules/products/index.d.ts +141 -0
- package/dist/server/modules/products/index.js +768 -0
- package/dist/server/modules/products/types.d.ts +94 -0
- package/dist/server/modules/products/types.js +43 -0
- package/dist/server/modules/quotation/index.d.ts +47 -0
- package/dist/server/modules/quotation/index.js +367 -0
- package/dist/server/modules/quotation/types.d.ts +50 -0
- package/dist/server/modules/quotation/types.js +20 -0
- package/dist/server/modules/schedule/index.d.ts +62 -0
- package/dist/server/modules/schedule/index.js +431 -0
- package/dist/server/modules/schedule/types.d.ts +1 -0
- package/dist/server/modules/schedule/types.js +2 -0
- package/dist/server/modules/schedule/utils.d.ts +32 -0
- package/dist/server/modules/schedule/utils.js +747 -0
- package/dist/server/types.d.ts +64 -0
- package/dist/server/types.js +1 -0
- package/dist/server/utils/index.d.ts +5 -0
- package/dist/server/utils/index.js +6 -0
- package/dist/server/utils/product.d.ts +18 -0
- package/dist/server/utils/product.js +339 -0
- package/dist/server/utils/schedule.d.ts +14 -0
- package/dist/server/utils/schedule.js +108 -0
- package/dist/server/utils/time.d.ts +18 -0
- package/dist/server/utils/time.js +53 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -17
- package/dist/solution/BookingByStep/index.js +23 -468
- package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
- package/dist/solution/BookingByStep/utils/capacity.js +8 -24
- package/dist/solution/BookingTicket/index.d.ts +12 -0
- package/dist/solution/BookingTicket/index.js +122 -79
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
- package/dist/solution/BuyTickets/index.js +7 -8
- package/dist/solution/Checkout/index.d.ts +1 -46
- package/dist/solution/Checkout/index.js +530 -850
- package/dist/solution/ShopDiscount/index.js +9 -10
- package/dist/types/index.d.ts +27 -0
- package/lib/core/index.d.ts +8 -1
- package/lib/core/index.js +48 -1
- package/lib/effects/index.d.ts +1 -0
- package/lib/effects/index.js +13 -0
- package/lib/modules/Account/index.js +2 -3
- package/lib/modules/BaseModule.d.ts +3 -0
- package/lib/modules/BaseModule.js +9 -0
- package/lib/modules/Customer/index.js +9 -10
- package/lib/modules/Customer/types.d.ts +2 -2
- package/lib/modules/Customer/types.js +2 -2
- package/lib/modules/Discount/index.js +1 -1
- package/lib/modules/Guests/index.js +9 -9
- package/lib/modules/Order/index.js +1 -1
- package/lib/modules/Payment/index.js +56 -43
- package/lib/modules/Payment/walletpass.js +3 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +19 -0
- package/lib/modules/ProductList/index.js +4 -13
- package/lib/modules/Resource/index.js +1 -1
- package/lib/modules/Rules/index.js +2 -3
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/plugins/request.d.ts +1 -0
- package/lib/server/index.d.ts +152 -0
- package/lib/server/index.js +555 -0
- package/lib/server/modules/index.d.ts +16 -0
- package/lib/server/modules/index.js +47 -0
- package/lib/server/modules/menu/index.d.ts +63 -0
- package/lib/server/modules/menu/index.js +234 -0
- package/lib/server/modules/menu/types.d.ts +68 -0
- package/lib/server/modules/menu/types.js +33 -0
- package/lib/server/modules/products/index.d.ts +141 -0
- package/lib/server/modules/products/index.js +434 -0
- package/lib/server/modules/products/types.d.ts +94 -0
- package/lib/server/modules/products/types.js +35 -0
- package/lib/server/modules/quotation/index.d.ts +47 -0
- package/lib/server/modules/quotation/index.js +177 -0
- package/lib/server/modules/quotation/types.d.ts +50 -0
- package/lib/server/modules/quotation/types.js +33 -0
- package/lib/server/modules/schedule/index.d.ts +62 -0
- package/lib/server/modules/schedule/index.js +231 -0
- package/lib/server/modules/schedule/types.d.ts +1 -0
- package/lib/server/modules/schedule/types.js +23 -0
- package/lib/server/modules/schedule/utils.d.ts +32 -0
- package/lib/server/modules/schedule/utils.js +451 -0
- package/lib/server/types.d.ts +64 -0
- package/lib/server/types.js +17 -0
- package/lib/server/utils/index.d.ts +5 -0
- package/lib/server/utils/index.js +25 -0
- package/lib/server/utils/product.d.ts +18 -0
- package/lib/server/utils/product.js +262 -0
- package/lib/server/utils/schedule.d.ts +14 -0
- package/lib/server/utils/schedule.js +88 -0
- package/lib/server/utils/time.d.ts +18 -0
- package/lib/server/utils/time.js +70 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -17
- package/lib/solution/BookingByStep/index.js +40 -312
- package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
- package/lib/solution/BookingByStep/utils/capacity.js +8 -21
- package/lib/solution/BookingTicket/index.d.ts +12 -0
- package/lib/solution/BookingTicket/index.js +25 -6
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
- package/lib/solution/BuyTickets/index.js +7 -8
- package/lib/solution/Checkout/index.d.ts +1 -46
- package/lib/solution/Checkout/index.js +92 -289
- package/lib/solution/ShopDiscount/index.js +10 -11
- package/lib/types/index.d.ts +27 -0
- package/package.json +2 -2
|
@@ -0,0 +1,768 @@
|
|
|
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
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 _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; }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
14
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
17
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
18
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
19
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
20
|
+
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; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
+
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); }
|
|
23
|
+
import { BaseModule } from "../../../modules/BaseModule";
|
|
24
|
+
import { cloneDeep } from 'lodash-es';
|
|
25
|
+
import { ProductsHooks } from "./types";
|
|
26
|
+
import { applyDetailValueToProducts, applyPriceDataToProducts } from "../../utils/product";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* IndexDB 存储名称
|
|
30
|
+
*/
|
|
31
|
+
var INDEXDB_STORE_NAME = 'products';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Products 模块 - 用于获取和管理完整的商品详细数据
|
|
35
|
+
* 相比 ProductList 模块,Products 会获取所有详细信息并缓存
|
|
36
|
+
*/
|
|
37
|
+
export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
38
|
+
_inherits(ProductsModule, _BaseModule);
|
|
39
|
+
var _super = _createSuper(ProductsModule);
|
|
40
|
+
function ProductsModule(name, version) {
|
|
41
|
+
var _this;
|
|
42
|
+
_classCallCheck(this, ProductsModule);
|
|
43
|
+
_this = _super.call(this, name, version);
|
|
44
|
+
_defineProperty(_assertThisInitialized(_this), "defaultName", 'products');
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
48
|
+
_defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
|
|
49
|
+
// IndexDBManager 实例
|
|
50
|
+
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
51
|
+
// 商品价格缓存:Map<日期, 应用了价格的商品列表>
|
|
52
|
+
_defineProperty(_assertThisInitialized(_this), "productsPriceCache", new Map());
|
|
53
|
+
// 缓存配置
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "CACHE_MAX_DAYS", 7);
|
|
55
|
+
// 最多缓存7天
|
|
56
|
+
// 商品格式化器列表
|
|
57
|
+
_defineProperty(_assertThisInitialized(_this), "formatters", []);
|
|
58
|
+
// 是否已注册内置价格格式化器
|
|
59
|
+
_defineProperty(_assertThisInitialized(_this), "isPriceFormatterRegistered", false);
|
|
60
|
+
return _this;
|
|
61
|
+
}
|
|
62
|
+
_createClass(ProductsModule, [{
|
|
63
|
+
key: "initialize",
|
|
64
|
+
value: function () {
|
|
65
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
66
|
+
var _options$initialState;
|
|
67
|
+
var appPlugin, app;
|
|
68
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
69
|
+
while (1) switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
this.core = core;
|
|
72
|
+
this.store = options.store;
|
|
73
|
+
this.otherParams = options.otherParams || {};
|
|
74
|
+
if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
75
|
+
this.store.list = options.initialState.list;
|
|
76
|
+
// 同步更新 Map 缓存
|
|
77
|
+
this.syncProductsMap();
|
|
78
|
+
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
79
|
+
} else {
|
|
80
|
+
this.store.list = [];
|
|
81
|
+
this.store.map = new Map();
|
|
82
|
+
}
|
|
83
|
+
this.request = core.getPlugin('request');
|
|
84
|
+
|
|
85
|
+
// 获取并存储 dbManager
|
|
86
|
+
appPlugin = core.getPlugin('app');
|
|
87
|
+
if (appPlugin) {
|
|
88
|
+
app = appPlugin.getApp();
|
|
89
|
+
this.dbManager = app.dbManager;
|
|
90
|
+
if (this.dbManager) {
|
|
91
|
+
console.log('[Products] IndexDB Manager 已初始化');
|
|
92
|
+
} else {
|
|
93
|
+
console.warn('[Products] IndexDB Manager 未找到');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 注册内置的价格格式化器(作为第一个格式化器)
|
|
98
|
+
this.registerBuiltinPriceFormatter();
|
|
99
|
+
case 8:
|
|
100
|
+
case "end":
|
|
101
|
+
return _context.stop();
|
|
102
|
+
}
|
|
103
|
+
}, _callee, this);
|
|
104
|
+
}));
|
|
105
|
+
function initialize(_x, _x2) {
|
|
106
|
+
return _initialize.apply(this, arguments);
|
|
107
|
+
}
|
|
108
|
+
return initialize;
|
|
109
|
+
}()
|
|
110
|
+
/**
|
|
111
|
+
* 加载商品价格(原始方法,不带缓存)
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
}, {
|
|
115
|
+
key: "loadProductsPrice",
|
|
116
|
+
value: (function () {
|
|
117
|
+
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
118
|
+
var _ref$ids, ids, customer_id, schedule_date, productsData;
|
|
119
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
120
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
121
|
+
case 0:
|
|
122
|
+
_ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date;
|
|
123
|
+
_context2.next = 3;
|
|
124
|
+
return this.request.post("/product/query/price", {
|
|
125
|
+
ids: ids,
|
|
126
|
+
customer_id: customer_id,
|
|
127
|
+
schedule_date: schedule_date
|
|
128
|
+
}, {
|
|
129
|
+
useCache: true
|
|
130
|
+
});
|
|
131
|
+
case 3:
|
|
132
|
+
productsData = _context2.sent;
|
|
133
|
+
return _context2.abrupt("return", productsData.data);
|
|
134
|
+
case 5:
|
|
135
|
+
case "end":
|
|
136
|
+
return _context2.stop();
|
|
137
|
+
}
|
|
138
|
+
}, _callee2, this);
|
|
139
|
+
}));
|
|
140
|
+
function loadProductsPrice(_x3) {
|
|
141
|
+
return _loadProductsPrice.apply(this, arguments);
|
|
142
|
+
}
|
|
143
|
+
return loadProductsPrice;
|
|
144
|
+
}()
|
|
145
|
+
/**
|
|
146
|
+
* 获取应用了价格的商品列表(带缓存)
|
|
147
|
+
* 使用日期作为缓存 key,同一天的商品价格会被缓存
|
|
148
|
+
* 缓存的是已经应用了价格的完整商品列表,避免重复转换
|
|
149
|
+
* @param schedule_date 日期
|
|
150
|
+
* @param extraContext 额外的上下文数据(可选,由 Server 层传入)
|
|
151
|
+
* @returns 应用了价格的商品列表
|
|
152
|
+
*/
|
|
153
|
+
)
|
|
154
|
+
}, {
|
|
155
|
+
key: "getProductsWithPrice",
|
|
156
|
+
value: (function () {
|
|
157
|
+
var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext) {
|
|
158
|
+
var cacheKey, result;
|
|
159
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
160
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
161
|
+
case 0:
|
|
162
|
+
cacheKey = schedule_date; // 检查缓存
|
|
163
|
+
if (!this.productsPriceCache.has(cacheKey)) {
|
|
164
|
+
_context3.next = 4;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
console.log("[ProductsModule] \uD83D\uDCB0 \u5546\u54C1\u4EF7\u683C\u7F13\u5B58\u547D\u4E2D: ".concat(cacheKey));
|
|
168
|
+
return _context3.abrupt("return", this.productsPriceCache.get(cacheKey));
|
|
169
|
+
case 4:
|
|
170
|
+
// 发起新请求并应用价格
|
|
171
|
+
console.log("[ProductsModule] \uD83C\uDF10 \u83B7\u53D6\u5546\u54C1\u5E76\u5E94\u7528\u4EF7\u683C: ".concat(cacheKey));
|
|
172
|
+
_context3.next = 7;
|
|
173
|
+
return this.prepareProductsWithPrice(schedule_date, extraContext);
|
|
174
|
+
case 7:
|
|
175
|
+
result = _context3.sent;
|
|
176
|
+
// 存入缓存
|
|
177
|
+
this.productsPriceCache.set(cacheKey, result);
|
|
178
|
+
console.log("[ProductsModule] \u2705 \u5546\u54C1\u4EF7\u683C\u5DF2\u7F13\u5B58: ".concat(cacheKey, ", \u5171 ").concat(result.length, " \u4E2A\u5546\u54C1"));
|
|
179
|
+
|
|
180
|
+
// 清理过期缓存
|
|
181
|
+
this.cleanExpiredPriceCache();
|
|
182
|
+
return _context3.abrupt("return", result);
|
|
183
|
+
case 12:
|
|
184
|
+
case "end":
|
|
185
|
+
return _context3.stop();
|
|
186
|
+
}
|
|
187
|
+
}, _callee3, this);
|
|
188
|
+
}));
|
|
189
|
+
function getProductsWithPrice(_x4, _x5) {
|
|
190
|
+
return _getProductsWithPrice.apply(this, arguments);
|
|
191
|
+
}
|
|
192
|
+
return getProductsWithPrice;
|
|
193
|
+
}()
|
|
194
|
+
/**
|
|
195
|
+
* 准备带价格的商品数据(通过格式化器流程处理)
|
|
196
|
+
* @param schedule_date 日期
|
|
197
|
+
* @param extraContext 额外的上下文数据(可选)
|
|
198
|
+
* @returns 完整处理后的商品列表
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
)
|
|
202
|
+
}, {
|
|
203
|
+
key: "prepareProductsWithPrice",
|
|
204
|
+
value: (function () {
|
|
205
|
+
var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext) {
|
|
206
|
+
var allProducts, priceData, context, processedProducts;
|
|
207
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
208
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
209
|
+
case 0:
|
|
210
|
+
_context4.next = 2;
|
|
211
|
+
return this.getProducts();
|
|
212
|
+
case 2:
|
|
213
|
+
allProducts = _context4.sent;
|
|
214
|
+
_context4.next = 5;
|
|
215
|
+
return this.loadProductsPrice({
|
|
216
|
+
ids: allProducts.map(function (product) {
|
|
217
|
+
return product.id;
|
|
218
|
+
}),
|
|
219
|
+
schedule_date: schedule_date
|
|
220
|
+
});
|
|
221
|
+
case 5:
|
|
222
|
+
priceData = _context4.sent;
|
|
223
|
+
// 3. 构建上下文(包含价格数据,合并外部传入的额外上下文)
|
|
224
|
+
context = _objectSpread({
|
|
225
|
+
schedule_date: schedule_date,
|
|
226
|
+
priceData: priceData
|
|
227
|
+
}, extraContext); // 4. 通过格式化器流程处理商品(包括价格应用、字段扩展等)
|
|
228
|
+
_context4.next = 9;
|
|
229
|
+
return this.applyFormatters(allProducts, context);
|
|
230
|
+
case 9:
|
|
231
|
+
processedProducts = _context4.sent;
|
|
232
|
+
_context4.next = 12;
|
|
233
|
+
return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
|
|
234
|
+
case 12:
|
|
235
|
+
return _context4.abrupt("return", processedProducts);
|
|
236
|
+
case 13:
|
|
237
|
+
case "end":
|
|
238
|
+
return _context4.stop();
|
|
239
|
+
}
|
|
240
|
+
}, _callee4, this);
|
|
241
|
+
}));
|
|
242
|
+
function prepareProductsWithPrice(_x6, _x7) {
|
|
243
|
+
return _prepareProductsWithPrice.apply(this, arguments);
|
|
244
|
+
}
|
|
245
|
+
return prepareProductsWithPrice;
|
|
246
|
+
}()
|
|
247
|
+
/**
|
|
248
|
+
* 应用所有已注册的格式化器
|
|
249
|
+
* @param products 商品列表
|
|
250
|
+
* @param context 上下文信息
|
|
251
|
+
* @returns 格式化后的商品列表
|
|
252
|
+
* @private
|
|
253
|
+
*/
|
|
254
|
+
)
|
|
255
|
+
}, {
|
|
256
|
+
key: "applyFormatters",
|
|
257
|
+
value: (function () {
|
|
258
|
+
var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products, context) {
|
|
259
|
+
var result, i, formatter;
|
|
260
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
261
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
262
|
+
case 0:
|
|
263
|
+
result = products;
|
|
264
|
+
if (!(this.formatters.length === 0)) {
|
|
265
|
+
_context5.next = 4;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
|
|
269
|
+
return _context5.abrupt("return", result);
|
|
270
|
+
case 4:
|
|
271
|
+
i = 0;
|
|
272
|
+
case 5:
|
|
273
|
+
if (!(i < this.formatters.length)) {
|
|
274
|
+
_context5.next = 20;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
formatter = this.formatters[i];
|
|
278
|
+
_context5.prev = 7;
|
|
279
|
+
console.log("[ProductsModule] \uD83D\uDCDD \u5E94\u7528\u683C\u5F0F\u5316\u5668 ".concat(i + 1, "/").concat(this.formatters.length));
|
|
280
|
+
_context5.next = 11;
|
|
281
|
+
return formatter(result, context);
|
|
282
|
+
case 11:
|
|
283
|
+
result = _context5.sent;
|
|
284
|
+
_context5.next = 17;
|
|
285
|
+
break;
|
|
286
|
+
case 14:
|
|
287
|
+
_context5.prev = 14;
|
|
288
|
+
_context5.t0 = _context5["catch"](7);
|
|
289
|
+
console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context5.t0);
|
|
290
|
+
// 继续执行后续格式化器,不中断流程
|
|
291
|
+
case 17:
|
|
292
|
+
i++;
|
|
293
|
+
_context5.next = 5;
|
|
294
|
+
break;
|
|
295
|
+
case 20:
|
|
296
|
+
console.log("[ProductsModule] \u2705 \u6240\u6709\u683C\u5F0F\u5316\u5668\u5DF2\u5E94\u7528\uFF0C\u5171 ".concat(this.formatters.length, " \u4E2A"));
|
|
297
|
+
return _context5.abrupt("return", result);
|
|
298
|
+
case 22:
|
|
299
|
+
case "end":
|
|
300
|
+
return _context5.stop();
|
|
301
|
+
}
|
|
302
|
+
}, _callee5, this, [[7, 14]]);
|
|
303
|
+
}));
|
|
304
|
+
function applyFormatters(_x8, _x9) {
|
|
305
|
+
return _applyFormatters.apply(this, arguments);
|
|
306
|
+
}
|
|
307
|
+
return applyFormatters;
|
|
308
|
+
}()
|
|
309
|
+
/**
|
|
310
|
+
* 注册内置的价格格式化器
|
|
311
|
+
* 这个格式化器负责将价格数据应用到商品上
|
|
312
|
+
* @private
|
|
313
|
+
*/
|
|
314
|
+
)
|
|
315
|
+
}, {
|
|
316
|
+
key: "registerBuiltinPriceFormatter",
|
|
317
|
+
value: function registerBuiltinPriceFormatter() {
|
|
318
|
+
if (this.isPriceFormatterRegistered) {
|
|
319
|
+
console.warn('[ProductsModule] 内置价格格式化器已注册,跳过');
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 创建价格格式化器
|
|
324
|
+
var priceFormatter = function priceFormatter(products, context) {
|
|
325
|
+
if (!context.priceData || context.priceData.length === 0) {
|
|
326
|
+
console.log('[ProductsModule] 💰 没有价格数据,跳过价格应用');
|
|
327
|
+
return products;
|
|
328
|
+
}
|
|
329
|
+
console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528\u4EF7\u683C\u6570\u636E\u5230 ".concat(products.length, " \u4E2A\u5546\u54C1"));
|
|
330
|
+
return applyPriceDataToProducts(products, context.priceData);
|
|
331
|
+
};
|
|
332
|
+
var detailValueFormatter = function detailValueFormatter(products, context) {
|
|
333
|
+
return applyDetailValueToProducts(products, context);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// 将价格格式化器注册为第一个格式化器
|
|
337
|
+
this.formatters.unshift(priceFormatter);
|
|
338
|
+
this.formatters.push(detailValueFormatter);
|
|
339
|
+
this.isPriceFormatterRegistered = true;
|
|
340
|
+
console.log('[ProductsModule] ✅ 内置价格格式化器已注册(第 1 个)');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 注册商品格式化器
|
|
345
|
+
* 格式化器会按注册顺序依次执行(内置价格格式化器始终是第一个)
|
|
346
|
+
* @param formatter 格式化函数
|
|
347
|
+
* @param prepend 是否插入到队列开头(默认 false,追加到末尾)
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* productsModule.registerFormatter((products, context) => {
|
|
351
|
+
* return products.map(p => ({
|
|
352
|
+
* ...p,
|
|
353
|
+
* custom_field: 'custom_value'
|
|
354
|
+
* }));
|
|
355
|
+
* });
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
}, {
|
|
359
|
+
key: "registerFormatter",
|
|
360
|
+
value: function registerFormatter(formatter) {
|
|
361
|
+
var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
362
|
+
if (prepend) {
|
|
363
|
+
// 插入到价格格式化器之后(索引 1 的位置)
|
|
364
|
+
var insertIndex = this.isPriceFormatterRegistered ? 1 : 0;
|
|
365
|
+
this.formatters.splice(insertIndex, 0, formatter);
|
|
366
|
+
console.log("[ProductsModule] \uD83D\uDCCC \u5DF2\u5728\u4F4D\u7F6E ".concat(insertIndex + 1, " \u63D2\u5165\u683C\u5F0F\u5316\u5668\uFF0C\u5F53\u524D\u5171 ").concat(this.formatters.length, " \u4E2A"));
|
|
367
|
+
} else {
|
|
368
|
+
// 追加到末尾
|
|
369
|
+
this.formatters.push(formatter);
|
|
370
|
+
console.log("[ProductsModule] \uD83D\uDCCC \u5DF2\u6CE8\u518C\u683C\u5F0F\u5316\u5668\uFF0C\u5F53\u524D\u5171 ".concat(this.formatters.length, " \u4E2A"));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* 清空所有格式化器(包括内置价格格式化器)
|
|
376
|
+
* @param keepBuiltin 是否保留内置价格格式化器(默认 true)
|
|
377
|
+
*/
|
|
378
|
+
}, {
|
|
379
|
+
key: "clearFormatters",
|
|
380
|
+
value: function clearFormatters() {
|
|
381
|
+
var keepBuiltin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
382
|
+
if (keepBuiltin && this.isPriceFormatterRegistered) {
|
|
383
|
+
// 只保留第一个格式化器(内置价格格式化器)
|
|
384
|
+
this.formatters = [this.formatters[0]];
|
|
385
|
+
console.log('[ProductsModule] 🧹 已清空自定义格式化器,保留内置价格格式化器');
|
|
386
|
+
} else {
|
|
387
|
+
this.formatters = [];
|
|
388
|
+
this.isPriceFormatterRegistered = false;
|
|
389
|
+
console.log('[ProductsModule] 🧹 已清空所有格式化器');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* 清理过期的价格缓存
|
|
395
|
+
* 当缓存数量超过限制时,删除最老的缓存
|
|
396
|
+
* @private
|
|
397
|
+
*/
|
|
398
|
+
}, {
|
|
399
|
+
key: "cleanExpiredPriceCache",
|
|
400
|
+
value: function cleanExpiredPriceCache() {
|
|
401
|
+
if (this.productsPriceCache.size > this.CACHE_MAX_DAYS) {
|
|
402
|
+
var keys = Array.from(this.productsPriceCache.keys());
|
|
403
|
+
var oldestKey = keys[0];
|
|
404
|
+
this.productsPriceCache.delete(oldestKey);
|
|
405
|
+
console.log("[ProductsModule] \uD83E\uDDF9 \u6E05\u7406\u8FC7\u671F\u5546\u54C1\u4EF7\u683C\u7F13\u5B58: ".concat(oldestKey));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 清空商品价格缓存
|
|
411
|
+
* 可用于手动刷新价格数据
|
|
412
|
+
*/
|
|
413
|
+
}, {
|
|
414
|
+
key: "clearPriceCache",
|
|
415
|
+
value: function clearPriceCache() {
|
|
416
|
+
this.productsPriceCache.clear();
|
|
417
|
+
console.log('[ProductsModule] 🗑️ 商品价格缓存已清空');
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 加载完整商品列表通过接口(包含所有详细数据)
|
|
422
|
+
* @param params 查询参数
|
|
423
|
+
*/
|
|
424
|
+
}, {
|
|
425
|
+
key: "loadProductsByServer",
|
|
426
|
+
value: (function () {
|
|
427
|
+
var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
428
|
+
var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, _this$otherParams, _productsData$data, productsData;
|
|
429
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
430
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
431
|
+
case 0:
|
|
432
|
+
_ref2 = params || {}, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids, _ref2$product_ids = _ref2.product_ids, product_ids = _ref2$product_ids === void 0 ? [] : _ref2$product_ids, _ref2$collection = _ref2.collection, collection = _ref2$collection === void 0 ? [] : _ref2$collection, customer_id = _ref2.customer_id, cacheId = _ref2.cacheId;
|
|
433
|
+
_context6.prev = 1;
|
|
434
|
+
_context6.next = 4;
|
|
435
|
+
return this.request.post("/product/query", {
|
|
436
|
+
open_bundle: 1,
|
|
437
|
+
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
438
|
+
force_ignore_cache_flag: 1,
|
|
439
|
+
// 获取所有详细信息
|
|
440
|
+
with: ['category', 'collection', 'resourceRelation',
|
|
441
|
+
// 套餐
|
|
442
|
+
'bundleGroup.bundleItem',
|
|
443
|
+
// 单规格
|
|
444
|
+
'optionGroup.optionItem',
|
|
445
|
+
// 组合规格
|
|
446
|
+
'variantGroup.variantItem'],
|
|
447
|
+
open_deposit: 1,
|
|
448
|
+
with_count: ['bundleGroup', 'optionGroup'],
|
|
449
|
+
status: 'published',
|
|
450
|
+
num: 500,
|
|
451
|
+
skip: 1,
|
|
452
|
+
category_ids: category_ids,
|
|
453
|
+
ids: product_ids,
|
|
454
|
+
collection: collection,
|
|
455
|
+
front_end_cache_id: cacheId,
|
|
456
|
+
application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel
|
|
457
|
+
}, {
|
|
458
|
+
useCache: true
|
|
459
|
+
});
|
|
460
|
+
case 4:
|
|
461
|
+
productsData = _context6.sent;
|
|
462
|
+
_context6.next = 7;
|
|
463
|
+
return this.saveProductsToIndexDB((productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || []);
|
|
464
|
+
case 7:
|
|
465
|
+
_context6.next = 9;
|
|
466
|
+
return this.core.effects.emit(ProductsHooks.onProductsLoaded, productsData.data.list);
|
|
467
|
+
case 9:
|
|
468
|
+
return _context6.abrupt("return", productsData.data.list);
|
|
469
|
+
case 12:
|
|
470
|
+
_context6.prev = 12;
|
|
471
|
+
_context6.t0 = _context6["catch"](1);
|
|
472
|
+
console.error('[Products] 加载商品数据失败:', _context6.t0);
|
|
473
|
+
return _context6.abrupt("return", []);
|
|
474
|
+
case 16:
|
|
475
|
+
case "end":
|
|
476
|
+
return _context6.stop();
|
|
477
|
+
}
|
|
478
|
+
}, _callee6, this, [[1, 12]]);
|
|
479
|
+
}));
|
|
480
|
+
function loadProductsByServer(_x10) {
|
|
481
|
+
return _loadProductsByServer.apply(this, arguments);
|
|
482
|
+
}
|
|
483
|
+
return loadProductsByServer;
|
|
484
|
+
}()
|
|
485
|
+
/**
|
|
486
|
+
* 获取商品列表(从缓存)
|
|
487
|
+
*/
|
|
488
|
+
)
|
|
489
|
+
}, {
|
|
490
|
+
key: "getProducts",
|
|
491
|
+
value: (function () {
|
|
492
|
+
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
493
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
494
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
495
|
+
case 0:
|
|
496
|
+
return _context7.abrupt("return", cloneDeep(this.store.list));
|
|
497
|
+
case 1:
|
|
498
|
+
case "end":
|
|
499
|
+
return _context7.stop();
|
|
500
|
+
}
|
|
501
|
+
}, _callee7, this);
|
|
502
|
+
}));
|
|
503
|
+
function getProducts() {
|
|
504
|
+
return _getProducts.apply(this, arguments);
|
|
505
|
+
}
|
|
506
|
+
return getProducts;
|
|
507
|
+
}()
|
|
508
|
+
/**
|
|
509
|
+
* 根据ID获取单个商品(从内存缓存)
|
|
510
|
+
* 使用 Map 快速查询,时间复杂度 O(1)
|
|
511
|
+
*/
|
|
512
|
+
)
|
|
513
|
+
}, {
|
|
514
|
+
key: "getProductById",
|
|
515
|
+
value: (function () {
|
|
516
|
+
var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(id) {
|
|
517
|
+
var product;
|
|
518
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
519
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
520
|
+
case 0:
|
|
521
|
+
product = this.store.map.get(id);
|
|
522
|
+
return _context8.abrupt("return", product ? cloneDeep(product) : undefined);
|
|
523
|
+
case 2:
|
|
524
|
+
case "end":
|
|
525
|
+
return _context8.stop();
|
|
526
|
+
}
|
|
527
|
+
}, _callee8, this);
|
|
528
|
+
}));
|
|
529
|
+
function getProductById(_x11) {
|
|
530
|
+
return _getProductById.apply(this, arguments);
|
|
531
|
+
}
|
|
532
|
+
return getProductById;
|
|
533
|
+
}()
|
|
534
|
+
/**
|
|
535
|
+
* 清空缓存
|
|
536
|
+
*/
|
|
537
|
+
)
|
|
538
|
+
}, {
|
|
539
|
+
key: "clear",
|
|
540
|
+
value: (function () {
|
|
541
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
542
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
543
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
544
|
+
case 0:
|
|
545
|
+
this.store.list = [];
|
|
546
|
+
this.store.map.clear();
|
|
547
|
+
|
|
548
|
+
// 同时清空 IndexDB 中的所有数据(包括商品和元数据)
|
|
549
|
+
if (!this.dbManager) {
|
|
550
|
+
_context9.next = 12;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
_context9.prev = 3;
|
|
554
|
+
_context9.next = 6;
|
|
555
|
+
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
556
|
+
case 6:
|
|
557
|
+
console.log('[Products] IndexDB 缓存已清空');
|
|
558
|
+
_context9.next = 12;
|
|
559
|
+
break;
|
|
560
|
+
case 9:
|
|
561
|
+
_context9.prev = 9;
|
|
562
|
+
_context9.t0 = _context9["catch"](3);
|
|
563
|
+
console.error('[Products] 清空 IndexDB 缓存失败:', _context9.t0);
|
|
564
|
+
case 12:
|
|
565
|
+
console.log('[Products] 缓存已清空');
|
|
566
|
+
case 13:
|
|
567
|
+
case "end":
|
|
568
|
+
return _context9.stop();
|
|
569
|
+
}
|
|
570
|
+
}, _callee9, this, [[3, 9]]);
|
|
571
|
+
}));
|
|
572
|
+
function clear() {
|
|
573
|
+
return _clear.apply(this, arguments);
|
|
574
|
+
}
|
|
575
|
+
return clear;
|
|
576
|
+
}()
|
|
577
|
+
/**
|
|
578
|
+
* 从 IndexDB 加载商品数据
|
|
579
|
+
* @private
|
|
580
|
+
*/
|
|
581
|
+
)
|
|
582
|
+
}, {
|
|
583
|
+
key: "loadProductsFromIndexDB",
|
|
584
|
+
value: (function () {
|
|
585
|
+
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
586
|
+
var products;
|
|
587
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
588
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
589
|
+
case 0:
|
|
590
|
+
if (this.dbManager) {
|
|
591
|
+
_context10.next = 2;
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
return _context10.abrupt("return", []);
|
|
595
|
+
case 2:
|
|
596
|
+
_context10.prev = 2;
|
|
597
|
+
_context10.next = 5;
|
|
598
|
+
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
599
|
+
case 5:
|
|
600
|
+
products = _context10.sent;
|
|
601
|
+
return _context10.abrupt("return", products || []);
|
|
602
|
+
case 9:
|
|
603
|
+
_context10.prev = 9;
|
|
604
|
+
_context10.t0 = _context10["catch"](2);
|
|
605
|
+
console.error('[Products] 从 IndexDB 读取数据失败:', _context10.t0);
|
|
606
|
+
return _context10.abrupt("return", []);
|
|
607
|
+
case 13:
|
|
608
|
+
case "end":
|
|
609
|
+
return _context10.stop();
|
|
610
|
+
}
|
|
611
|
+
}, _callee10, this, [[2, 9]]);
|
|
612
|
+
}));
|
|
613
|
+
function loadProductsFromIndexDB() {
|
|
614
|
+
return _loadProductsFromIndexDB.apply(this, arguments);
|
|
615
|
+
}
|
|
616
|
+
return loadProductsFromIndexDB;
|
|
617
|
+
}()
|
|
618
|
+
/**
|
|
619
|
+
* 保存商品数据到 IndexDB(平铺存储)
|
|
620
|
+
* @private
|
|
621
|
+
*/
|
|
622
|
+
)
|
|
623
|
+
}, {
|
|
624
|
+
key: "saveProductsToIndexDB",
|
|
625
|
+
value: (function () {
|
|
626
|
+
var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(products) {
|
|
627
|
+
var _this2 = this;
|
|
628
|
+
var savePromises;
|
|
629
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
630
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
631
|
+
case 0:
|
|
632
|
+
if (this.dbManager) {
|
|
633
|
+
_context11.next = 2;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
return _context11.abrupt("return");
|
|
637
|
+
case 2:
|
|
638
|
+
_context11.prev = 2;
|
|
639
|
+
_context11.next = 5;
|
|
640
|
+
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
641
|
+
case 5:
|
|
642
|
+
// 逐个保存商品(每个商品是独立的记录)
|
|
643
|
+
savePromises = products.map(function (product) {
|
|
644
|
+
return _this2.dbManager.add(INDEXDB_STORE_NAME, product);
|
|
645
|
+
});
|
|
646
|
+
_context11.next = 8;
|
|
647
|
+
return Promise.all(savePromises);
|
|
648
|
+
case 8:
|
|
649
|
+
console.log("[Products] \u5DF2\u5C06 ".concat(products.length, " \u4E2A\u5546\u54C1\u5E73\u94FA\u4FDD\u5B58\u5230 IndexDB"));
|
|
650
|
+
_context11.next = 14;
|
|
651
|
+
break;
|
|
652
|
+
case 11:
|
|
653
|
+
_context11.prev = 11;
|
|
654
|
+
_context11.t0 = _context11["catch"](2);
|
|
655
|
+
console.error('[Products] 保存数据到 IndexDB 失败:', _context11.t0);
|
|
656
|
+
case 14:
|
|
657
|
+
case "end":
|
|
658
|
+
return _context11.stop();
|
|
659
|
+
}
|
|
660
|
+
}, _callee11, this, [[2, 11]]);
|
|
661
|
+
}));
|
|
662
|
+
function saveProductsToIndexDB(_x12) {
|
|
663
|
+
return _saveProductsToIndexDB.apply(this, arguments);
|
|
664
|
+
}
|
|
665
|
+
return saveProductsToIndexDB;
|
|
666
|
+
}()
|
|
667
|
+
/**
|
|
668
|
+
* 同步更新商品 Map 缓存
|
|
669
|
+
* 将 list 中的商品同步到 map,以 id 为 key
|
|
670
|
+
* @private
|
|
671
|
+
*/
|
|
672
|
+
)
|
|
673
|
+
}, {
|
|
674
|
+
key: "syncProductsMap",
|
|
675
|
+
value: function syncProductsMap() {
|
|
676
|
+
this.store.map.clear();
|
|
677
|
+
var _iterator = _createForOfIteratorHelper(this.store.list),
|
|
678
|
+
_step;
|
|
679
|
+
try {
|
|
680
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
681
|
+
var product = _step.value;
|
|
682
|
+
this.store.map.set(product.id, product);
|
|
683
|
+
}
|
|
684
|
+
} catch (err) {
|
|
685
|
+
_iterator.e(err);
|
|
686
|
+
} finally {
|
|
687
|
+
_iterator.f();
|
|
688
|
+
}
|
|
689
|
+
console.log("[Products] Map \u7F13\u5B58\u5DF2\u540C\u6B65\uFF0C\u5171 ".concat(this.store.map.size, " \u4E2A\u5546\u54C1"));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* 预加载模块数据(统一接口)
|
|
694
|
+
* 在模块注册后自动调用
|
|
695
|
+
*/
|
|
696
|
+
}, {
|
|
697
|
+
key: "preload",
|
|
698
|
+
value: (function () {
|
|
699
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
700
|
+
var cachedData, products;
|
|
701
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
702
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
703
|
+
case 0:
|
|
704
|
+
console.log('[Products] 开始预加载数据...');
|
|
705
|
+
_context12.prev = 1;
|
|
706
|
+
_context12.next = 4;
|
|
707
|
+
return this.loadProductsFromIndexDB();
|
|
708
|
+
case 4:
|
|
709
|
+
cachedData = _context12.sent;
|
|
710
|
+
if (!(cachedData && cachedData.length > 0)) {
|
|
711
|
+
_context12.next = 11;
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
|
|
715
|
+
// 将缓存数据放入 list
|
|
716
|
+
this.store.list = cloneDeep(cachedData);
|
|
717
|
+
// 同步更新 Map 缓存
|
|
718
|
+
this.syncProductsMap();
|
|
719
|
+
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
720
|
+
return _context12.abrupt("return");
|
|
721
|
+
case 11:
|
|
722
|
+
console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
|
|
723
|
+
_context12.next = 17;
|
|
724
|
+
break;
|
|
725
|
+
case 14:
|
|
726
|
+
_context12.prev = 14;
|
|
727
|
+
_context12.t0 = _context12["catch"](1);
|
|
728
|
+
console.warn('[Products] 从 IndexDB 加载数据失败:', _context12.t0);
|
|
729
|
+
case 17:
|
|
730
|
+
_context12.next = 19;
|
|
731
|
+
return this.loadProductsByServer();
|
|
732
|
+
case 19:
|
|
733
|
+
products = _context12.sent;
|
|
734
|
+
if (!(products && products.length > 0)) {
|
|
735
|
+
_context12.next = 26;
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
_context12.next = 23;
|
|
739
|
+
return this.saveProductsToIndexDB(products);
|
|
740
|
+
case 23:
|
|
741
|
+
this.store.list = cloneDeep(products);
|
|
742
|
+
// 同步更新 Map 缓存
|
|
743
|
+
this.syncProductsMap();
|
|
744
|
+
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
745
|
+
case 26:
|
|
746
|
+
case "end":
|
|
747
|
+
return _context12.stop();
|
|
748
|
+
}
|
|
749
|
+
}, _callee12, this, [[1, 14]]);
|
|
750
|
+
}));
|
|
751
|
+
function preload() {
|
|
752
|
+
return _preload.apply(this, arguments);
|
|
753
|
+
}
|
|
754
|
+
return preload;
|
|
755
|
+
}()
|
|
756
|
+
/**
|
|
757
|
+
* 获取模块的路由定义
|
|
758
|
+
* Products 模块暂不提供路由,由 Server 层统一处理
|
|
759
|
+
*/
|
|
760
|
+
)
|
|
761
|
+
}, {
|
|
762
|
+
key: "getRoutes",
|
|
763
|
+
value: function getRoutes() {
|
|
764
|
+
return [];
|
|
765
|
+
}
|
|
766
|
+
}]);
|
|
767
|
+
return ProductsModule;
|
|
768
|
+
}(BaseModule);
|