UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

745 lines (721 loc) 39.7 kB
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); } 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; } 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; } 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; } 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); } } 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); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } 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); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 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); }; } 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); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } 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; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } 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); } import { BaseModule } from "../../modules/BaseModule"; import { createModule } from "./types"; import Scan from "./utils/scan"; import { handleGlobalScan, handleCustomerScan, handleUniversalScan } from "./utils/scan/handleScan"; import scanCache from "./utils/scan/scanCache"; export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) { _inherits(BookingTicketImpl, _BaseModule); var _super = _createSuper(BookingTicketImpl); function BookingTicketImpl() { var _this; _classCallCheck(this, BookingTicketImpl); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "defaultName", 'bookingTicket'); _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0'); _defineProperty(_assertThisInitialized(_this), "isSolution", true); _defineProperty(_assertThisInitialized(_this), "request", void 0); _defineProperty(_assertThisInitialized(_this), "window", void 0); _defineProperty(_assertThisInitialized(_this), "shopStore", void 0); _defineProperty(_assertThisInitialized(_this), "store", void 0); _defineProperty(_assertThisInitialized(_this), "otherParams", {}); _defineProperty(_assertThisInitialized(_this), "cacheId", void 0); _defineProperty(_assertThisInitialized(_this), "platform", void 0); // 平台类型,用于判断是 PC / H5 _defineProperty(_assertThisInitialized(_this), "scan", void 0); return _this; } _createClass(BookingTicketImpl, [{ key: "initialize", value: function () { var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) { var _this$otherParams, _this$otherParams2, _this$otherParams3, _this2 = this; var targetCacheData, sessionData, _data, moduleArr; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: this.core = core; this.store = options.store || {}; this.otherParams = options.otherParams || {}; console.log('[BookingTicket] 初始化完成'); // 获取依赖的插件 this.request = core.getPlugin('request'); this.window = core.getPlugin('window'); this.shopStore = core.getPlugin('shopStore'); if (this.request) { _context.next = 9; break; } throw new Error('bookingTicket解决方案需要 request 插件支持'); case 9: if (this.shopStore) { _context.next = 11; break; } throw new Error('bookingTicket解决方案需要 shopStore 插件支持'); case 11: // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据 targetCacheData = {}; this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId; this.platform = (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform; this.scan = new Scan(this, 'BOOKING_TICKET_SCAN'); if ((_this$otherParams3 = this.otherParams) !== null && _this$otherParams3 !== void 0 && _this$otherParams3.cacheId) { sessionData = this.window.sessionStorage.getItem(this.name); if (sessionData) { _data = JSON.parse(sessionData); targetCacheData = _data[this.otherParams.cacheId]; } } moduleArr = ['cart', 'products', 'accountList', 'customer', 'order']; moduleArr.forEach(function (step) { var targetModule = createModule(step, _this2.name); if (targetModule) { var _targetCacheData, _this2$otherParams, _this2$otherParams2; _this2.store[step] = targetModule; _this2.core.registerModule(targetModule, { initialState: (_targetCacheData = targetCacheData) === null || _targetCacheData === void 0 ? void 0 : _targetCacheData[targetModule.name], otherParams: _objectSpread(_objectSpread({}, _this2.otherParams), {}, { fatherModule: _this2.name, openCache: (_this2$otherParams = _this2.otherParams) !== null && _this2$otherParams !== void 0 && _this2$otherParams.cacheId ? true : false, cacheId: (_this2$otherParams2 = _this2.otherParams) === null || _this2$otherParams2 === void 0 ? void 0 : _this2$otherParams2.cacheId }) }); } else { throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728")); } }); this.core.effects.emit("".concat(this.name, ":onInited"), {}); case 19: case "end": return _context.stop(); } }, _callee, this); })); function initialize(_x, _x2) { return _initialize.apply(this, arguments); } return initialize; }() /** * 获取商品列表 * @param params 包含 schedule_date 的参数 * @returns 商品列表 */ }, { key: "loadProducts", value: (function () { var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { var params, options, schedule_date, customer_id, menu_list_ids, schedule_datetime, _result, _args2 = arguments; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}; options = _args2.length > 1 ? _args2[1] : undefined; schedule_date = params.schedule_date, customer_id = params.customer_id, menu_list_ids = params.menu_list_ids, schedule_datetime = params.schedule_datetime; _context2.prev = 3; _context2.next = 6; return this.store.products.loadProducts(_objectSpread(_objectSpread({ with_count: ['bundleGroup', 'optionGroup'], with_schedule: 1 }, params), {}, { cacheId: this.cacheId }), options); case 6: _result = _context2.sent; this.core.effects.emit("".concat(this.name, ":onProductsLoaded"), _result); return _context2.abrupt("return", _result); case 11: _context2.prev = 11; _context2.t0 = _context2["catch"](3); console.error('Failed to load products:', _context2.t0); throw _context2.t0; case 15: case "end": return _context2.stop(); } }, _callee2, this, [[3, 11]]); })); function loadProducts() { return _loadProducts.apply(this, arguments); } return loadProducts; }() /** * 取消商品查询订阅 * @param subscriberId 订阅时传入的 subscriberId */ ) }, { key: "unsubscribeProductQuery", value: function unsubscribeProductQuery(subscriberId) { var _this$core$server; (_this$core$server = this.core.server) === null || _this$core$server === void 0 || _this$core$server.removeProductQuerySubscriber(subscriberId); } /** * 初始化外设扫码结果监听 */ }, { key: "initPeripheralsListener", value: function initPeripheralsListener() { this.scan.initPeripheralsListener(); } /** * 获取商品列表(不加载到模块中) * @returns 商品列表 */ }, { key: "getProducts", value: (function () { var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() { return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: return _context3.abrupt("return", this.store.products.getProducts()); case 1: case "end": return _context3.stop(); } }, _callee3, this); })); function getProducts() { return _getProducts.apply(this, arguments); } return getProducts; }() /** * 获取日程时间段点 * @param params 参数 * @returns 日程时间段点 */ ) }, { key: "getScheduleTimePoints", value: (function () { var _getScheduleTimePoints = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) { var result; return _regeneratorRuntime().wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return this.request.post('/menu/schedule-time-points', { menu_list_ids: params.menu_list_ids }, { osServer: true }); case 2: result = _context4.sent; return _context4.abrupt("return", result.data || []); case 4: case "end": return _context4.stop(); } }, _callee4, this); })); function getScheduleTimePoints(_x3) { return _getScheduleTimePoints.apply(this, arguments); } return getScheduleTimePoints; }() /** * 获取客户列表 * @param params 查询参数 * @returns 客户列表响应 */ ) }, { key: "getCustomerList", value: (function () { var _getCustomerList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() { var params, _result2, _args5 = arguments; return _regeneratorRuntime().wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: params = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}; _context5.prev = 1; _context5.next = 4; return this.store.customer.getCustomerList(params); case 4: _result2 = _context5.sent; return _context5.abrupt("return", _result2); case 8: _context5.prev = 8; _context5.t0 = _context5["catch"](1); console.error('Failed to get customer list:', _context5.t0); throw _context5.t0; case 12: case "end": return _context5.stop(); } }, _callee5, this, [[1, 8]]); })); function getCustomerList() { return _getCustomerList.apply(this, arguments); } return getCustomerList; }() /** * 设置活跃客户 * @param customer 客户信息 */ ) }, { key: "setActiveCustomer", value: function setActiveCustomer(customer) { this.store.customer.setSelectedCustomer(customer); this.core.effects.emit("".concat(this.name, ":onCustomerSelected"), { customer: customer }); } /** * 获取当前活跃客户 * @returns 当前活跃客户 */ }, { key: "getActiveCustomer", value: function getActiveCustomer() { return this.store.customer.getSelectedCustomer(); } /** * 根据ID设置选中的客户 * @param customerId 客户ID */ }, { key: "setSelectedCustomerById", value: function setSelectedCustomerById(customerId) { var customer = this.store.customer.getCustomerById(customerId); if (customer) { this.store.customer.setSelectedCustomer(customer); this.core.effects.emit("".concat(this.name, ":onCustomerSelected"), { customer: customer }); } } /** * 获取所有客户 * @returns 客户列表 */ }, { key: "getCustomers", value: function getCustomers() { return this.store.customer.getCustomers(); } /** * 根据ID获取客户 * @param customerId 客户ID * @returns 客户信息 */ }, { key: "getCustomerById", value: function getCustomerById(customerId) { return this.store.customer.getCustomerById(customerId); } /** * 清空客户列表 */ }, { key: "clearCustomers", value: function clearCustomers() { this.store.customer.clearCustomers(); } /** * 添加客户到列表第一位 * @param customer 要添加的客户信息 */ }, { key: "addCustomerToFirst", value: function addCustomerToFirst(customer) { this.store.customer.addCustomerToFirst(customer); } /** * 获取客户分页信息 * @returns 分页信息 */ }, { key: "getCustomerPaginationInfo", value: function getCustomerPaginationInfo() { return this.store.customer.getPaginationInfo(); } /** * 获取客户列表总数 * @returns 总数 */ }, { key: "getCustomerTotal", value: function getCustomerTotal() { return this.store.customer.getState().total; } /** * 设置客户分页信息 * @param page 页码 * @param pageSize 每页数量 */ }, { key: "setCustomerPaginationInfo", value: function setCustomerPaginationInfo(page, pageSize) { this.store.customer.setPaginationInfo(page, pageSize); } /** * 便捷方法:切换客户分页并自动获取数据 * @param page 页码 * @param pageSize 每页数量(可选) * @returns 客户列表响应 */ }, { key: "changeCustomerPage", value: (function () { var _changeCustomerPage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(page, pageSize) { var _result3; return _regeneratorRuntime().wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: _context6.prev = 0; _context6.next = 3; return this.store.customer.changeCustomerPage(page, pageSize); case 3: _result3 = _context6.sent; return _context6.abrupt("return", _result3); case 7: _context6.prev = 7; _context6.t0 = _context6["catch"](0); console.error('Failed to change customer page:', _context6.t0); throw _context6.t0; case 11: case "end": return _context6.stop(); } }, _callee6, this, [[0, 7]]); })); function changeCustomerPage(_x4, _x5) { return _changeCustomerPage.apply(this, arguments); } return changeCustomerPage; }() /** * 滚动加载更多客户数据 - 数据会追加到现有列表中 * @returns 客户列表响应 */ ) }, { key: "loadMoreCustomers", value: (function () { var _loadMoreCustomers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() { var _result4; return _regeneratorRuntime().wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: _context7.prev = 0; _context7.next = 3; return this.store.customer.loadMoreCustomers(); case 3: _result4 = _context7.sent; this.core.effects.emit("".concat(this.name, ":onCustomerListUpdate"), _result4); return _context7.abrupt("return", _result4); case 8: _context7.prev = 8; _context7.t0 = _context7["catch"](0); console.error('Failed to load more customers:', _context7.t0); throw _context7.t0; case 12: case "end": return _context7.stop(); } }, _callee7, this, [[0, 8]]); })); function loadMoreCustomers() { return _loadMoreCustomers.apply(this, arguments); } return loadMoreCustomers; }() /** * 重置并重新开始滚动加载客户数据 * @param params 查询参数 * @returns 客户列表响应 */ ) }, { key: "resetAndLoadCustomers", value: (function () { var _resetAndLoadCustomers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() { var params, _result5, _args8 = arguments; return _regeneratorRuntime().wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: params = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {}; _context8.prev = 1; _context8.next = 4; return this.store.customer.resetAndLoadCustomers(params); case 4: _result5 = _context8.sent; this.core.effects.emit("".concat(this.name, ":onCustomerListReset"), _result5); return _context8.abrupt("return", _result5); case 9: _context8.prev = 9; _context8.t0 = _context8["catch"](1); console.error('Failed to reset and load customers:', _context8.t0); throw _context8.t0; case 13: case "end": return _context8.stop(); } }, _callee8, this, [[1, 9]]); })); function resetAndLoadCustomers() { return _resetAndLoadCustomers.apply(this, arguments); } return resetAndLoadCustomers; }() /** * 检查是否还有更多客户数据可以加载 * @returns 是否还有更多数据 */ ) }, { key: "hasMoreCustomers", value: function hasMoreCustomers() { return this.store.customer.hasMoreCustomers(); } /** * 获取当前的客户搜索条件 * @returns 当前搜索条件 */ }, { key: "getCurrentCustomerSearchParams", value: function getCurrentCustomerSearchParams() { return this.store.customer.getCurrentSearchParams(); } /** * 获取客户列表状态(包含滚动加载相关状态) * @returns 客户状态 */ }, { key: "getCustomerState", value: function getCustomerState() { return this.store.customer.getState(); } /** * 全局扫描监听 * @param callback 回调 */ }, { key: "scanGlobalListener", value: function scanGlobalListener(callback) { var _this3 = this; var localSearch = function localSearch(v) { return _this3.store.products.findProductsByCodeOrBarcode(v); }; var scanCallback = handleGlobalScan(this.request, localSearch); var safeCallback = function safeCallback(d) { try { callback(d); } catch (error) { console.error('scanGlobalListener传入的回调函数异常', error); } }; var listener = { key: 'global', callback: safeCallback }; var removeListener = this.scan.addListener(listener, scanCallback); return removeListener; } /** * 客户扫描监听 * @param callback 回调 */ }, { key: "scanCustomerListener", value: function scanCustomerListener(callback) { var scanCallback = handleCustomerScan(); var safeCallback = function safeCallback(d) { try { callback(d); } catch (error) { console.error('scanCustomerListener传入的回调函数异常', error); } }; var listener = { key: 'customer', callback: safeCallback }; var removeListener = this.scan.addListener(listener, scanCallback); return removeListener; } /** * @title 通用扫描监听 * @description 直接将扫描结果返回给调用方 * @param callback 回调 */ }, { key: "scanUniversalListener", value: function scanUniversalListener(callback, key) { var scanCallback = handleUniversalScan(); var safeCallback = function safeCallback(d) { try { callback(d); } catch (error) { console.error("scanUniversalListener\u4F20\u5165\u7684\u56DE\u8C03\u51FD\u6570\u5F02\u5E38, key: ".concat(key), error); } }; var listener = { key: key, callback: safeCallback }; var removeListener = this.scan.addListener(listener, scanCallback); return removeListener; } /** * 调用摄像头 * @param data 用户自定义数据 */ }, { key: "activateCamera", value: function activateCamera(data) { var _this$window, _this$window$postMess; (_this$window = this.window) === null || _this$window === void 0 || (_this$window = _this$window.interaction) === null || _this$window === void 0 || (_this$window = _this$window.utils) === null || _this$window === void 0 || (_this$window$postMess = _this$window.postMessageToApp) === null || _this$window$postMess === void 0 || _this$window$postMess.call(_this$window, { module: 'global', key: 'active_native_scanner', data: data }); } /** * 禁用所有扫描监听 */ }, { key: "disableAllScanListeners", value: function disableAllScanListeners() { this.scan.disableAllListeners(); } /** * 启用所有扫描监听 */ }, { key: "enableAllScanListeners", value: function enableAllScanListeners() { this.scan.enableAllListeners(); } /** * 清空所有扫描监听对应的任务执行队列 */ }, { key: "clearAllScanListenersTaskQueue", value: function clearAllScanListenersTaskQueue() { this.scan.clearTaskQueue(); } /** * 设置其他参数 * @param params 参数 * @param options 选项 */ }, { key: "setOtherParams", value: (function () { var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) { var _ref, _ref$cover, cover, _args9 = arguments; return _regeneratorRuntime().wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: _ref = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {}, _ref$cover = _ref.cover, cover = _ref$cover === void 0 ? false : _ref$cover; if (cover) { this.otherParams = params; } else { this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params); } case 2: case "end": return _context9.stop(); } }, _callee9, this); })); function setOtherParams(_x6) { return _setOtherParams.apply(this, arguments); } return setOtherParams; }() /** * 获取其他参数 * @returns 其他参数 */ ) }, { key: "getOtherParams", value: (function () { var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() { return _regeneratorRuntime().wrap(function _callee10$(_context10) { while (1) switch (_context10.prev = _context10.next) { case 0: return _context10.abrupt("return", this.otherParams); case 1: case "end": return _context10.stop(); } }, _callee10, this); })); function getOtherParams() { return _getOtherParams.apply(this, arguments); } return getOtherParams; }() /** * 销毁模块 */ ) }, { key: "destroy", value: function destroy() { var _this$store$cart, _this$store$products, _this$store$accountLi, _this$store$customer, _this$store$order; (_this$store$cart = this.store.cart) === null || _this$store$cart === void 0 || _this$store$cart.destroy(); (_this$store$products = this.store.products) === null || _this$store$products === void 0 || _this$store$products.destroy(); (_this$store$accountLi = this.store.accountList) === null || _this$store$accountLi === void 0 || _this$store$accountLi.destroy(); (_this$store$customer = this.store.customer) === null || _this$store$customer === void 0 || _this$store$customer.destroy(); (_this$store$order = this.store.order) === null || _this$store$order === void 0 || _this$store$order.destroy(); this.core.effects.offByModuleDestroy(this.name); this.core.unregisterModule(this); // 清除所有的监听 this.scan.removeAllListeners(); // 清除scan数据内存缓存 scanCache.clear(); } }]); return BookingTicketImpl; }(BaseModule); // 导出相关类型和实现 export * from "./types"; export { BookingTicketImpl as BookingTicket };