@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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server 模块导出
|
|
3
|
+
* 包含新增的 Products、Menu、Quotation 和扩展的 Schedule 模块
|
|
4
|
+
*/
|
|
5
|
+
export { ProductsModule } from './products';
|
|
6
|
+
export type { ProductsState } from './products/types';
|
|
7
|
+
export { ProductsHooks } from './products/types';
|
|
8
|
+
export { MenuModule } from './menu';
|
|
9
|
+
export type { MenuState, MenuData } from './menu/types';
|
|
10
|
+
export { MenuHooks } from './menu/types';
|
|
11
|
+
export { QuotationModule } from './quotation';
|
|
12
|
+
export type { QuotationState, QuotationData, QuotationProductPrice } from './quotation/types';
|
|
13
|
+
export { QuotationHooks } from './quotation/types';
|
|
14
|
+
export { ScheduleModuleEx } from './schedule';
|
|
15
|
+
export type { ScheduleState, ScheduleItem } from './schedule/types';
|
|
16
|
+
export type { RouteHandler, HttpMethod, RouteDefinition, Router, ModuleRegistryConfig, } from '../types';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server 模块导出
|
|
3
|
+
* 包含新增的 Products、Menu、Quotation 和扩展的 Schedule 模块
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Products 模块
|
|
7
|
+
export { ProductsModule } from "./products";
|
|
8
|
+
export { ProductsHooks } from "./products/types";
|
|
9
|
+
|
|
10
|
+
// Menu 模块(餐牌)
|
|
11
|
+
export { MenuModule } from "./menu";
|
|
12
|
+
export { MenuHooks } from "./menu/types";
|
|
13
|
+
|
|
14
|
+
// Quotation 模块(报价单)
|
|
15
|
+
export { QuotationModule } from "./quotation";
|
|
16
|
+
export { QuotationHooks } from "./quotation/types";
|
|
17
|
+
|
|
18
|
+
// Schedule 模块(扩展版本)
|
|
19
|
+
export { ScheduleModuleEx } from "./schedule";
|
|
20
|
+
|
|
21
|
+
// Server 类型
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from '../../../types';
|
|
2
|
+
import { BaseModule } from '../../../modules/BaseModule';
|
|
3
|
+
import type { RouteDefinition } from '../../types';
|
|
4
|
+
import { MenuData } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* 餐牌模块 - 用于管理餐牌数据和根据餐牌过滤商品
|
|
7
|
+
*/
|
|
8
|
+
export declare class MenuModule extends BaseModule implements Module {
|
|
9
|
+
protected defaultName: string;
|
|
10
|
+
protected defaultVersion: string;
|
|
11
|
+
private request;
|
|
12
|
+
private store;
|
|
13
|
+
private dbManager;
|
|
14
|
+
constructor(name?: string, version?: string);
|
|
15
|
+
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* 加载餐牌列表(从服务器)
|
|
18
|
+
*/
|
|
19
|
+
loadMenuList(): Promise<MenuData[]>;
|
|
20
|
+
/**
|
|
21
|
+
* 设置餐牌列表
|
|
22
|
+
*/
|
|
23
|
+
setMenuList(menuList: MenuData[]): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 获取餐牌列表
|
|
26
|
+
*/
|
|
27
|
+
getMenuList(): MenuData[];
|
|
28
|
+
/**
|
|
29
|
+
* 根据 form_record_id 数组获取餐牌详情
|
|
30
|
+
* 使用 Map 快速查询,时间复杂度 O(m),m 为 ids 数量
|
|
31
|
+
*/
|
|
32
|
+
getMenuByIds(ids: number[]): MenuData[];
|
|
33
|
+
/**
|
|
34
|
+
* 同步更新餐牌 Map 缓存
|
|
35
|
+
* 将 menuList 中的餐牌同步到 map,以 form_record_id 为 key
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
private syncMenuMap;
|
|
39
|
+
/**
|
|
40
|
+
* 清空缓存
|
|
41
|
+
*/
|
|
42
|
+
clear(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* 从 IndexDB 加载餐牌数据
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
private loadMenuFromIndexDB;
|
|
48
|
+
/**
|
|
49
|
+
* 保存餐牌数据到 IndexDB
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
private saveMenuToIndexDB;
|
|
53
|
+
/**
|
|
54
|
+
* 预加载模块数据(统一接口)
|
|
55
|
+
* 在模块注册后自动调用
|
|
56
|
+
*/
|
|
57
|
+
preload(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* 获取模块的路由定义
|
|
60
|
+
* 返回该模块需要注册的 API 路由
|
|
61
|
+
*/
|
|
62
|
+
getRoutes(): RouteDefinition[];
|
|
63
|
+
}
|
|
@@ -0,0 +1,476 @@
|
|
|
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 _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; }
|
|
6
|
+
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); } }
|
|
7
|
+
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); }); }; }
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
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); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
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); }
|
|
12
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
13
|
+
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); }; }
|
|
14
|
+
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); }
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
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; } }
|
|
17
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
20
|
+
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); }
|
|
21
|
+
import { cloneDeep } from 'lodash-es';
|
|
22
|
+
import { BaseModule } from "../../../modules/BaseModule";
|
|
23
|
+
import { MenuHooks } from "./types";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* IndexDB 存储名称
|
|
27
|
+
*/
|
|
28
|
+
var INDEXDB_STORE_NAME = 'menu';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 餐牌模块 - 用于管理餐牌数据和根据餐牌过滤商品
|
|
32
|
+
*/
|
|
33
|
+
export var MenuModule = /*#__PURE__*/function (_BaseModule) {
|
|
34
|
+
_inherits(MenuModule, _BaseModule);
|
|
35
|
+
var _super = _createSuper(MenuModule);
|
|
36
|
+
// IndexDBManager 实例
|
|
37
|
+
|
|
38
|
+
function MenuModule(name, version) {
|
|
39
|
+
var _this;
|
|
40
|
+
_classCallCheck(this, MenuModule);
|
|
41
|
+
_this = _super.call(this, name, version);
|
|
42
|
+
_defineProperty(_assertThisInitialized(_this), "defaultName", 'menu');
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
44
|
+
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
|
|
47
|
+
return _this;
|
|
48
|
+
}
|
|
49
|
+
_createClass(MenuModule, [{
|
|
50
|
+
key: "initialize",
|
|
51
|
+
value: function () {
|
|
52
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
53
|
+
var _options$initialState;
|
|
54
|
+
var appPlugin, app;
|
|
55
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
56
|
+
while (1) switch (_context.prev = _context.next) {
|
|
57
|
+
case 0:
|
|
58
|
+
this.core = core;
|
|
59
|
+
this.store = options === null || options === void 0 ? void 0 : options.store;
|
|
60
|
+
|
|
61
|
+
// 获取依赖的插件
|
|
62
|
+
this.request = core.getPlugin('request');
|
|
63
|
+
if (this.request) {
|
|
64
|
+
_context.next = 5;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
throw new Error('MenuModule 需要 request 插件支持');
|
|
68
|
+
case 5:
|
|
69
|
+
if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.menuList)) {
|
|
70
|
+
this.store.menuList = options === null || options === void 0 ? void 0 : options.initialState.menuList;
|
|
71
|
+
// 同步更新 Map 缓存
|
|
72
|
+
this.syncMenuMap();
|
|
73
|
+
this.core.effects.emit(MenuHooks.onMenuChanged, this.store.menuList);
|
|
74
|
+
} else {
|
|
75
|
+
this.store.menuList = [];
|
|
76
|
+
this.store.map = new Map();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 获取并存储 dbManager
|
|
80
|
+
appPlugin = core.getPlugin('app');
|
|
81
|
+
if (appPlugin) {
|
|
82
|
+
app = appPlugin.getApp();
|
|
83
|
+
this.dbManager = app.dbManager;
|
|
84
|
+
if (this.dbManager) {
|
|
85
|
+
console.log('[Menu] IndexDB Manager 已初始化');
|
|
86
|
+
} else {
|
|
87
|
+
console.warn('[Menu] IndexDB Manager 未找到');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
case 8:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}, _callee, this);
|
|
95
|
+
}));
|
|
96
|
+
function initialize(_x, _x2) {
|
|
97
|
+
return _initialize.apply(this, arguments);
|
|
98
|
+
}
|
|
99
|
+
return initialize;
|
|
100
|
+
}()
|
|
101
|
+
/**
|
|
102
|
+
* 加载餐牌列表(从服务器)
|
|
103
|
+
*/
|
|
104
|
+
}, {
|
|
105
|
+
key: "loadMenuList",
|
|
106
|
+
value: (function () {
|
|
107
|
+
var _loadMenuList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
108
|
+
var _response$data, response, menuList;
|
|
109
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
110
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
111
|
+
case 0:
|
|
112
|
+
_context2.prev = 0;
|
|
113
|
+
_context2.next = 3;
|
|
114
|
+
return this.request.get("/form/data/v1", {
|
|
115
|
+
skip: 1,
|
|
116
|
+
num: 999,
|
|
117
|
+
code: 'menu_list'
|
|
118
|
+
}, {
|
|
119
|
+
useCache: true
|
|
120
|
+
});
|
|
121
|
+
case 3:
|
|
122
|
+
response = _context2.sent;
|
|
123
|
+
menuList = (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || []; // 保存到 IndexDB
|
|
124
|
+
_context2.next = 7;
|
|
125
|
+
return this.saveMenuToIndexDB(menuList);
|
|
126
|
+
case 7:
|
|
127
|
+
_context2.next = 9;
|
|
128
|
+
return this.setMenuList(menuList);
|
|
129
|
+
case 9:
|
|
130
|
+
return _context2.abrupt("return", menuList);
|
|
131
|
+
case 12:
|
|
132
|
+
_context2.prev = 12;
|
|
133
|
+
_context2.t0 = _context2["catch"](0);
|
|
134
|
+
console.error('[Menu] 加载餐牌数据失败:', _context2.t0);
|
|
135
|
+
return _context2.abrupt("return", []);
|
|
136
|
+
case 16:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context2.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee2, this, [[0, 12]]);
|
|
141
|
+
}));
|
|
142
|
+
function loadMenuList() {
|
|
143
|
+
return _loadMenuList.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
return loadMenuList;
|
|
146
|
+
}()
|
|
147
|
+
/**
|
|
148
|
+
* 设置餐牌列表
|
|
149
|
+
*/
|
|
150
|
+
)
|
|
151
|
+
}, {
|
|
152
|
+
key: "setMenuList",
|
|
153
|
+
value: (function () {
|
|
154
|
+
var _setMenuList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(menuList) {
|
|
155
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
156
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
157
|
+
case 0:
|
|
158
|
+
this.store.menuList = menuList;
|
|
159
|
+
// 同步更新 Map 缓存
|
|
160
|
+
this.syncMenuMap();
|
|
161
|
+
_context3.next = 4;
|
|
162
|
+
return this.core.effects.emit(MenuHooks.onMenuLoaded, menuList);
|
|
163
|
+
case 4:
|
|
164
|
+
case "end":
|
|
165
|
+
return _context3.stop();
|
|
166
|
+
}
|
|
167
|
+
}, _callee3, this);
|
|
168
|
+
}));
|
|
169
|
+
function setMenuList(_x3) {
|
|
170
|
+
return _setMenuList.apply(this, arguments);
|
|
171
|
+
}
|
|
172
|
+
return setMenuList;
|
|
173
|
+
}()
|
|
174
|
+
/**
|
|
175
|
+
* 获取餐牌列表
|
|
176
|
+
*/
|
|
177
|
+
)
|
|
178
|
+
}, {
|
|
179
|
+
key: "getMenuList",
|
|
180
|
+
value: function getMenuList() {
|
|
181
|
+
return this.store.menuList;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 根据 form_record_id 数组获取餐牌详情
|
|
186
|
+
* 使用 Map 快速查询,时间复杂度 O(m),m 为 ids 数量
|
|
187
|
+
*/
|
|
188
|
+
}, {
|
|
189
|
+
key: "getMenuByIds",
|
|
190
|
+
value: function getMenuByIds(ids) {
|
|
191
|
+
if (!ids || ids.length === 0) {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
var result = [];
|
|
195
|
+
var _iterator = _createForOfIteratorHelper(ids),
|
|
196
|
+
_step;
|
|
197
|
+
try {
|
|
198
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
199
|
+
var id = _step.value;
|
|
200
|
+
var menu = this.store.map.get(id);
|
|
201
|
+
if (menu) {
|
|
202
|
+
result.push(menu);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
} catch (err) {
|
|
206
|
+
_iterator.e(err);
|
|
207
|
+
} finally {
|
|
208
|
+
_iterator.f();
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 同步更新餐牌 Map 缓存
|
|
215
|
+
* 将 menuList 中的餐牌同步到 map,以 form_record_id 为 key
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
}, {
|
|
219
|
+
key: "syncMenuMap",
|
|
220
|
+
value: function syncMenuMap() {
|
|
221
|
+
this.store.map.clear();
|
|
222
|
+
var _iterator2 = _createForOfIteratorHelper(this.store.menuList),
|
|
223
|
+
_step2;
|
|
224
|
+
try {
|
|
225
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
226
|
+
var menu = _step2.value;
|
|
227
|
+
this.store.map.set(menu.form_record_id, menu);
|
|
228
|
+
}
|
|
229
|
+
} catch (err) {
|
|
230
|
+
_iterator2.e(err);
|
|
231
|
+
} finally {
|
|
232
|
+
_iterator2.f();
|
|
233
|
+
}
|
|
234
|
+
console.log("[Menu] Map \u7F13\u5B58\u5DF2\u540C\u6B65\uFF0C\u5171 ".concat(this.store.map.size, " \u4E2A\u9910\u724C"));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 清空缓存
|
|
239
|
+
*/
|
|
240
|
+
}, {
|
|
241
|
+
key: "clear",
|
|
242
|
+
value: (function () {
|
|
243
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
244
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
245
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
246
|
+
case 0:
|
|
247
|
+
this.store.menuList = [];
|
|
248
|
+
this.store.map.clear();
|
|
249
|
+
this.store.currentMenu = undefined;
|
|
250
|
+
|
|
251
|
+
// 同时清空 IndexDB 中的数据
|
|
252
|
+
if (!this.dbManager) {
|
|
253
|
+
_context4.next = 13;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
_context4.prev = 4;
|
|
257
|
+
_context4.next = 7;
|
|
258
|
+
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
259
|
+
case 7:
|
|
260
|
+
console.log('[Menu] IndexDB 缓存已清空');
|
|
261
|
+
_context4.next = 13;
|
|
262
|
+
break;
|
|
263
|
+
case 10:
|
|
264
|
+
_context4.prev = 10;
|
|
265
|
+
_context4.t0 = _context4["catch"](4);
|
|
266
|
+
console.error('[Menu] 清空 IndexDB 缓存失败:', _context4.t0);
|
|
267
|
+
case 13:
|
|
268
|
+
console.log('[Menu] 缓存已清空');
|
|
269
|
+
case 14:
|
|
270
|
+
case "end":
|
|
271
|
+
return _context4.stop();
|
|
272
|
+
}
|
|
273
|
+
}, _callee4, this, [[4, 10]]);
|
|
274
|
+
}));
|
|
275
|
+
function clear() {
|
|
276
|
+
return _clear.apply(this, arguments);
|
|
277
|
+
}
|
|
278
|
+
return clear;
|
|
279
|
+
}()
|
|
280
|
+
/**
|
|
281
|
+
* 从 IndexDB 加载餐牌数据
|
|
282
|
+
* @private
|
|
283
|
+
*/
|
|
284
|
+
)
|
|
285
|
+
}, {
|
|
286
|
+
key: "loadMenuFromIndexDB",
|
|
287
|
+
value: (function () {
|
|
288
|
+
var _loadMenuFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
289
|
+
var menuList;
|
|
290
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
291
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
292
|
+
case 0:
|
|
293
|
+
if (this.dbManager) {
|
|
294
|
+
_context5.next = 2;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
return _context5.abrupt("return", []);
|
|
298
|
+
case 2:
|
|
299
|
+
_context5.prev = 2;
|
|
300
|
+
_context5.next = 5;
|
|
301
|
+
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
302
|
+
case 5:
|
|
303
|
+
menuList = _context5.sent;
|
|
304
|
+
return _context5.abrupt("return", menuList || []);
|
|
305
|
+
case 9:
|
|
306
|
+
_context5.prev = 9;
|
|
307
|
+
_context5.t0 = _context5["catch"](2);
|
|
308
|
+
console.error('[Menu] 从 IndexDB 读取数据失败:', _context5.t0);
|
|
309
|
+
return _context5.abrupt("return", []);
|
|
310
|
+
case 13:
|
|
311
|
+
case "end":
|
|
312
|
+
return _context5.stop();
|
|
313
|
+
}
|
|
314
|
+
}, _callee5, this, [[2, 9]]);
|
|
315
|
+
}));
|
|
316
|
+
function loadMenuFromIndexDB() {
|
|
317
|
+
return _loadMenuFromIndexDB.apply(this, arguments);
|
|
318
|
+
}
|
|
319
|
+
return loadMenuFromIndexDB;
|
|
320
|
+
}()
|
|
321
|
+
/**
|
|
322
|
+
* 保存餐牌数据到 IndexDB
|
|
323
|
+
* @private
|
|
324
|
+
*/
|
|
325
|
+
)
|
|
326
|
+
}, {
|
|
327
|
+
key: "saveMenuToIndexDB",
|
|
328
|
+
value: (function () {
|
|
329
|
+
var _saveMenuToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(menuList) {
|
|
330
|
+
var _this2 = this;
|
|
331
|
+
var savePromises;
|
|
332
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
333
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
334
|
+
case 0:
|
|
335
|
+
if (this.dbManager) {
|
|
336
|
+
_context6.next = 2;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
return _context6.abrupt("return");
|
|
340
|
+
case 2:
|
|
341
|
+
_context6.prev = 2;
|
|
342
|
+
_context6.next = 5;
|
|
343
|
+
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
344
|
+
case 5:
|
|
345
|
+
// 逐个保存餐牌(每个餐牌是独立的记录)
|
|
346
|
+
savePromises = menuList.map(function (menu) {
|
|
347
|
+
return _this2.dbManager.add(INDEXDB_STORE_NAME, menu);
|
|
348
|
+
});
|
|
349
|
+
_context6.next = 8;
|
|
350
|
+
return Promise.all(savePromises);
|
|
351
|
+
case 8:
|
|
352
|
+
console.log("[Menu] \u5DF2\u5C06 ".concat(menuList.length, " \u6761\u9910\u724C\u6570\u636E\u4FDD\u5B58\u5230 IndexDB"));
|
|
353
|
+
_context6.next = 14;
|
|
354
|
+
break;
|
|
355
|
+
case 11:
|
|
356
|
+
_context6.prev = 11;
|
|
357
|
+
_context6.t0 = _context6["catch"](2);
|
|
358
|
+
console.error('[Menu] 保存数据到 IndexDB 失败:', _context6.t0);
|
|
359
|
+
case 14:
|
|
360
|
+
case "end":
|
|
361
|
+
return _context6.stop();
|
|
362
|
+
}
|
|
363
|
+
}, _callee6, this, [[2, 11]]);
|
|
364
|
+
}));
|
|
365
|
+
function saveMenuToIndexDB(_x4) {
|
|
366
|
+
return _saveMenuToIndexDB.apply(this, arguments);
|
|
367
|
+
}
|
|
368
|
+
return saveMenuToIndexDB;
|
|
369
|
+
}()
|
|
370
|
+
/**
|
|
371
|
+
* 预加载模块数据(统一接口)
|
|
372
|
+
* 在模块注册后自动调用
|
|
373
|
+
*/
|
|
374
|
+
)
|
|
375
|
+
}, {
|
|
376
|
+
key: "preload",
|
|
377
|
+
value: (function () {
|
|
378
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
379
|
+
var cachedData, menuList;
|
|
380
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
381
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
382
|
+
case 0:
|
|
383
|
+
console.log('[Menu] 开始预加载数据...');
|
|
384
|
+
_context7.prev = 1;
|
|
385
|
+
_context7.next = 4;
|
|
386
|
+
return this.loadMenuFromIndexDB();
|
|
387
|
+
case 4:
|
|
388
|
+
cachedData = _context7.sent;
|
|
389
|
+
if (!(cachedData && cachedData.length > 0)) {
|
|
390
|
+
_context7.next = 11;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
console.log("[Menu] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u6761\u9910\u724C\u6570\u636E"));
|
|
394
|
+
// 将缓存数据放入 store
|
|
395
|
+
this.store.menuList = cloneDeep(cachedData);
|
|
396
|
+
// 同步更新 Map 缓存
|
|
397
|
+
this.syncMenuMap();
|
|
398
|
+
this.core.effects.emit(MenuHooks.onMenuChanged, this.store.menuList);
|
|
399
|
+
return _context7.abrupt("return");
|
|
400
|
+
case 11:
|
|
401
|
+
console.log('[Menu] IndexDB 中没有缓存数据,从服务器加载...');
|
|
402
|
+
_context7.next = 17;
|
|
403
|
+
break;
|
|
404
|
+
case 14:
|
|
405
|
+
_context7.prev = 14;
|
|
406
|
+
_context7.t0 = _context7["catch"](1);
|
|
407
|
+
console.warn('[Menu] 从 IndexDB 加载数据失败:', _context7.t0);
|
|
408
|
+
case 17:
|
|
409
|
+
_context7.next = 19;
|
|
410
|
+
return this.loadMenuList();
|
|
411
|
+
case 19:
|
|
412
|
+
menuList = _context7.sent;
|
|
413
|
+
if (!(menuList && menuList.length > 0)) {
|
|
414
|
+
_context7.next = 26;
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
_context7.next = 23;
|
|
418
|
+
return this.saveMenuToIndexDB(menuList);
|
|
419
|
+
case 23:
|
|
420
|
+
this.store.menuList = cloneDeep(menuList);
|
|
421
|
+
// 同步更新 Map 缓存
|
|
422
|
+
this.syncMenuMap();
|
|
423
|
+
this.core.effects.emit(MenuHooks.onMenuChanged, this.store.menuList);
|
|
424
|
+
case 26:
|
|
425
|
+
case "end":
|
|
426
|
+
return _context7.stop();
|
|
427
|
+
}
|
|
428
|
+
}, _callee7, this, [[1, 14]]);
|
|
429
|
+
}));
|
|
430
|
+
function preload() {
|
|
431
|
+
return _preload.apply(this, arguments);
|
|
432
|
+
}
|
|
433
|
+
return preload;
|
|
434
|
+
}()
|
|
435
|
+
/**
|
|
436
|
+
* 获取模块的路由定义
|
|
437
|
+
* 返回该模块需要注册的 API 路由
|
|
438
|
+
*/
|
|
439
|
+
)
|
|
440
|
+
}, {
|
|
441
|
+
key: "getRoutes",
|
|
442
|
+
value: function getRoutes() {
|
|
443
|
+
var _this3 = this;
|
|
444
|
+
return [
|
|
445
|
+
// GET /api/menu - 获取所有餐牌
|
|
446
|
+
{
|
|
447
|
+
method: 'get',
|
|
448
|
+
path: '/api/menu',
|
|
449
|
+
handler: function () {
|
|
450
|
+
var _handler = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
451
|
+
var menuList;
|
|
452
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
453
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
454
|
+
case 0:
|
|
455
|
+
menuList = _this3.getMenuList();
|
|
456
|
+
return _context8.abrupt("return", {
|
|
457
|
+
success: true,
|
|
458
|
+
data: menuList,
|
|
459
|
+
total: menuList.length
|
|
460
|
+
});
|
|
461
|
+
case 2:
|
|
462
|
+
case "end":
|
|
463
|
+
return _context8.stop();
|
|
464
|
+
}
|
|
465
|
+
}, _callee8);
|
|
466
|
+
}));
|
|
467
|
+
function handler() {
|
|
468
|
+
return _handler.apply(this, arguments);
|
|
469
|
+
}
|
|
470
|
+
return handler;
|
|
471
|
+
}()
|
|
472
|
+
}];
|
|
473
|
+
}
|
|
474
|
+
}]);
|
|
475
|
+
return MenuModule;
|
|
476
|
+
}(BaseModule);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 餐牌模块状态
|
|
3
|
+
*/
|
|
4
|
+
export interface MenuState {
|
|
5
|
+
/** 餐牌列表 */
|
|
6
|
+
menuList: MenuData[];
|
|
7
|
+
/** 餐牌 Map 缓存(以 form_record_id 为 key,加速查询) */
|
|
8
|
+
map: Map<number, MenuData>;
|
|
9
|
+
/** 当前生效的餐牌 */
|
|
10
|
+
currentMenu?: MenuData;
|
|
11
|
+
}
|
|
12
|
+
type ProductItemType = {
|
|
13
|
+
/** 商品集合 ID */
|
|
14
|
+
product_collection_id: number;
|
|
15
|
+
/** 商品 ID */
|
|
16
|
+
product_id: number;
|
|
17
|
+
/** 商品规格 ID */
|
|
18
|
+
product_variant_id: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 餐牌数据结构
|
|
22
|
+
*/
|
|
23
|
+
export interface MenuData {
|
|
24
|
+
/** 餐牌名称 */
|
|
25
|
+
name: string;
|
|
26
|
+
/** 副标题 */
|
|
27
|
+
subtitle: string;
|
|
28
|
+
/** 媒体资源 */
|
|
29
|
+
media: any[];
|
|
30
|
+
/** 描述 */
|
|
31
|
+
description: string;
|
|
32
|
+
/** 状态 */
|
|
33
|
+
status: 'valid' | 'invalid';
|
|
34
|
+
/** 绑定的日程 ID 列表 */
|
|
35
|
+
schedule: number[];
|
|
36
|
+
/** 商品配置 */
|
|
37
|
+
partyroom_package: {
|
|
38
|
+
/** 类型:product_all 表示所有商品,product_ids 表示指定商品,product_collection 表示商品集合 */
|
|
39
|
+
type: 'product_all' | 'products' | 'product_collection';
|
|
40
|
+
/** 指定的商品 或 商品集合 */
|
|
41
|
+
products: ProductItemType[];
|
|
42
|
+
filter?: number;
|
|
43
|
+
};
|
|
44
|
+
/** 表单标签 */
|
|
45
|
+
form_tag: string;
|
|
46
|
+
/** 商品字段 */
|
|
47
|
+
products: string;
|
|
48
|
+
/** 容量 */
|
|
49
|
+
capacity: number;
|
|
50
|
+
/** 表单记录 ID */
|
|
51
|
+
form_record_id: number;
|
|
52
|
+
/** 表单 ID */
|
|
53
|
+
form_id: number;
|
|
54
|
+
/** 主字段 */
|
|
55
|
+
main_field: string;
|
|
56
|
+
/** 过期时间 */
|
|
57
|
+
expired_at: string | null;
|
|
58
|
+
/** 创建时间 */
|
|
59
|
+
created_at: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 餐牌模块钩子
|
|
63
|
+
*/
|
|
64
|
+
export declare enum MenuHooks {
|
|
65
|
+
onMenuLoaded = "menu:onMenuLoaded",
|
|
66
|
+
onMenuChanged = "menu:onMenuChanged"
|
|
67
|
+
}
|
|
68
|
+
export {};
|