@pisell/pisellos 0.10.19 → 0.10.21
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/OpenData/index.d.ts +10 -1
- package/dist/modules/OpenData/index.js +268 -14
- package/dist/modules/OpenData/types.d.ts +14 -1
- package/dist/modules/OpenData/utils.d.ts +6 -0
- package/dist/modules/OpenData/utils.js +50 -5
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/plugins/request.d.ts +2 -1
- package/dist/plugins/request.js +4 -2
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +80 -41
- package/dist/server/utils/small-ticket.js +52 -0
- package/dist/solution/BaseSales/index.js +23 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +13 -1
- package/dist/solution/BookingTicket/index.js +25 -18
- package/dist/solution/Sales/index.js +29 -22
- package/dist/solution/UnifiedBookingSales/index.js +25 -18
- package/lib/modules/OpenData/index.d.ts +10 -1
- package/lib/modules/OpenData/index.js +170 -3
- package/lib/modules/OpenData/types.d.ts +14 -1
- package/lib/modules/OpenData/utils.d.ts +6 -0
- package/lib/modules/OpenData/utils.js +40 -5
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/plugins/request.d.ts +2 -1
- package/lib/plugins/request.js +3 -2
- package/lib/server/index.d.ts +5 -0
- package/lib/server/index.js +47 -11
- package/lib/server/utils/small-ticket.js +52 -0
- package/lib/solution/BaseSales/index.js +21 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +13 -1
- package/lib/solution/BookingTicket/index.js +3 -0
- package/lib/solution/Sales/index.js +3 -0
- package/lib/solution/UnifiedBookingSales/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -3,7 +3,7 @@ import { BaseModule } from '../BaseModule';
|
|
|
3
3
|
import type { ScheduleModule } from '../Schedule';
|
|
4
4
|
import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
|
|
5
5
|
export * from './types';
|
|
6
|
-
export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, } from './utils';
|
|
6
|
+
export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales, } from './utils';
|
|
7
7
|
export declare class OpenDataModule extends BaseModule implements Module {
|
|
8
8
|
protected defaultName: string;
|
|
9
9
|
protected defaultVersion: string;
|
|
@@ -16,6 +16,9 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
16
16
|
private fatherModule;
|
|
17
17
|
private otherParams;
|
|
18
18
|
private fetchRevision;
|
|
19
|
+
private invoiceTemplateCacheRevision;
|
|
20
|
+
private invoiceTemplateDocumentCache;
|
|
21
|
+
private invoiceTemplateDocumentInFlight;
|
|
19
22
|
constructor(name?: string, version?: string);
|
|
20
23
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
21
24
|
/**
|
|
@@ -29,6 +32,12 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
29
32
|
getOpenData(): OpenDataConfig | null;
|
|
30
33
|
getInvoiceLayoutConfig(): InvoiceLayoutConfig;
|
|
31
34
|
getInvoiceTemplateSettings(): InvoiceTemplateSettings;
|
|
35
|
+
ensureInvoiceTemplateSettings(target: string): Promise<InvoiceTemplateSettings>;
|
|
36
|
+
private commitInvoiceTemplateSettings;
|
|
37
|
+
private resolveInvoiceTemplateSettings;
|
|
38
|
+
private buildInvoiceTemplateCacheKey;
|
|
39
|
+
private fetchInvoiceTemplateDocument;
|
|
40
|
+
private logInvoiceTemplateDocumentFallback;
|
|
32
41
|
getLastFetchedAt(): number | null;
|
|
33
42
|
/** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
|
|
34
43
|
clearCache(): void;
|
|
@@ -1,4 +1,3 @@
|
|
|
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
1
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
2
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
3
|
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); }); }; }
|
|
@@ -15,10 +14,30 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
15
14
|
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; }
|
|
16
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
16
|
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); }
|
|
17
|
+
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); }
|
|
18
18
|
import { BaseModule } from "../BaseModule";
|
|
19
|
-
import { computeAvailability,
|
|
19
|
+
import { computeAvailability, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings } from "./utils";
|
|
20
20
|
export * from "./types";
|
|
21
|
-
export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings } from "./utils";
|
|
21
|
+
export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales } from "./utils";
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return !!value && _typeof(value) === 'object' && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function resolveInvoiceDocumentId(value) {
|
|
26
|
+
if (typeof value === 'number') {
|
|
27
|
+
return Number.isSafeInteger(value) && value > 0 ? String(value) : null;
|
|
28
|
+
}
|
|
29
|
+
if (typeof value !== 'string') return null;
|
|
30
|
+
var normalized = value.trim();
|
|
31
|
+
if (!/^\d+$/.test(normalized)) return null;
|
|
32
|
+
var numericId = Number(normalized);
|
|
33
|
+
return Number.isSafeInteger(numericId) && numericId > 0 ? String(numericId) : null;
|
|
34
|
+
}
|
|
35
|
+
function isLegacyInvoiceTemplate(value) {
|
|
36
|
+
if (typeof value !== 'string' || value.trim().length === 0) return false;
|
|
37
|
+
var normalized = value.trim();
|
|
38
|
+
var numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
39
|
+
return !numericLike.test(normalized);
|
|
40
|
+
}
|
|
22
41
|
export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
23
42
|
_inherits(OpenDataModule, _BaseModule);
|
|
24
43
|
var _super = _createSuper(OpenDataModule);
|
|
@@ -37,6 +56,9 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
37
56
|
_defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
|
|
38
57
|
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
39
58
|
_defineProperty(_assertThisInitialized(_this), "fetchRevision", 0);
|
|
59
|
+
_defineProperty(_assertThisInitialized(_this), "invoiceTemplateCacheRevision", 0);
|
|
60
|
+
_defineProperty(_assertThisInitialized(_this), "invoiceTemplateDocumentCache", new Map());
|
|
61
|
+
_defineProperty(_assertThisInitialized(_this), "invoiceTemplateDocumentInFlight", new Map());
|
|
40
62
|
return _this;
|
|
41
63
|
}
|
|
42
64
|
_createClass(OpenDataModule, [{
|
|
@@ -52,6 +74,12 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
52
74
|
this.store = options.store;
|
|
53
75
|
this.store.data = (_options$initialState = (_options$initialState2 = options.initialState) === null || _options$initialState2 === void 0 ? void 0 : _options$initialState2.data) !== null && _options$initialState !== void 0 ? _options$initialState : null;
|
|
54
76
|
this.store.lastFetchedAt = (_options$initialState3 = (_options$initialState4 = options.initialState) === null || _options$initialState4 === void 0 ? void 0 : _options$initialState4.lastFetchedAt) !== null && _options$initialState3 !== void 0 ? _options$initialState3 : null;
|
|
77
|
+
// Document 解析结果只在当前模块实例内复用。页面刷新后即使恢复了原始
|
|
78
|
+
// OpenData,也必须重新查询一次 NocoBase,以取得当前模板内容。
|
|
79
|
+
this.store.invoiceTemplateSettings = null;
|
|
80
|
+
this.store.invoiceTemplateTarget = null;
|
|
81
|
+
this.store.invoiceTemplateDocumentId = null;
|
|
82
|
+
this.store.invoiceTemplateCacheKey = null;
|
|
55
83
|
this.otherParams = options.otherParams || {};
|
|
56
84
|
if (this.otherParams.cacheId) {
|
|
57
85
|
this.openCache = (_this$otherParams$ope = this.otherParams.openCache) !== null && _this$otherParams$ope !== void 0 ? _this$otherParams$ope : false;
|
|
@@ -64,17 +92,17 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
64
92
|
this.window = core.getPlugin('window');
|
|
65
93
|
this.appPlugin = core.getPlugin('app');
|
|
66
94
|
if (this.request) {
|
|
67
|
-
_context.next =
|
|
95
|
+
_context.next = 16;
|
|
68
96
|
break;
|
|
69
97
|
}
|
|
70
98
|
throw new Error('OpenDataModule 需要 request 插件支持');
|
|
71
|
-
case
|
|
99
|
+
case 16:
|
|
72
100
|
if (this.window) {
|
|
73
|
-
_context.next =
|
|
101
|
+
_context.next = 18;
|
|
74
102
|
break;
|
|
75
103
|
}
|
|
76
104
|
throw new Error('OpenDataModule 需要 window 插件支持');
|
|
77
|
-
case
|
|
105
|
+
case 18:
|
|
78
106
|
case "end":
|
|
79
107
|
return _context.stop();
|
|
80
108
|
}
|
|
@@ -105,7 +133,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
105
133
|
value: function () {
|
|
106
134
|
var _fetchOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
107
135
|
var _this$appPlugin, _this$appPlugin$getDa;
|
|
108
|
-
var fetchRevision, getData, shopId, tenantId, headers, response, data;
|
|
136
|
+
var fetchRevision, getData, shopId, tenantId, headers, response, data, resolvedInvoiceTemplate;
|
|
109
137
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
110
138
|
while (1) switch (_context2.prev = _context2.next) {
|
|
111
139
|
case 0:
|
|
@@ -140,13 +168,19 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
140
168
|
}
|
|
141
169
|
throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取 OpenData 配置失败');
|
|
142
170
|
case 13:
|
|
143
|
-
data = (response === null || response === void 0 ? void 0 : response.data) || {};
|
|
171
|
+
data = (response === null || response === void 0 ? void 0 : response.data) || {};
|
|
172
|
+
_context2.next = 16;
|
|
173
|
+
return this.resolveInvoiceTemplateSettings(data, params.target);
|
|
174
|
+
case 16:
|
|
175
|
+
resolvedInvoiceTemplate = _context2.sent;
|
|
176
|
+
// clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
|
|
144
177
|
if (fetchRevision === this.fetchRevision) {
|
|
145
178
|
this.store.data = data;
|
|
146
179
|
this.store.lastFetchedAt = Date.now();
|
|
180
|
+
this.commitInvoiceTemplateSettings(params.target, resolvedInvoiceTemplate);
|
|
147
181
|
}
|
|
148
182
|
return _context2.abrupt("return", data);
|
|
149
|
-
case
|
|
183
|
+
case 19:
|
|
150
184
|
case "end":
|
|
151
185
|
return _context2.stop();
|
|
152
186
|
}
|
|
@@ -165,12 +199,225 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
165
199
|
}, {
|
|
166
200
|
key: "getInvoiceLayoutConfig",
|
|
167
201
|
value: function getInvoiceLayoutConfig() {
|
|
168
|
-
return
|
|
202
|
+
return normalizeInvoiceLayoutFromTemplateSettings(this.getInvoiceTemplateSettings());
|
|
169
203
|
}
|
|
170
204
|
}, {
|
|
171
205
|
key: "getInvoiceTemplateSettings",
|
|
172
206
|
value: function getInvoiceTemplateSettings() {
|
|
173
|
-
|
|
207
|
+
var _this$store$data2;
|
|
208
|
+
if (isRecord(this.store.invoiceTemplateSettings)) {
|
|
209
|
+
var _this$store$data;
|
|
210
|
+
var documentId = resolveInvoiceDocumentId((_this$store$data = this.store.data) === null || _this$store$data === void 0 ? void 0 : _this$store$data['documents.invoice_template']);
|
|
211
|
+
if (documentId) {
|
|
212
|
+
var target = this.store.invoiceTemplateTarget;
|
|
213
|
+
if (!target || this.store.invoiceTemplateCacheKey !== this.buildInvoiceTemplateCacheKey(target, documentId)) {
|
|
214
|
+
return getDefaultInvoiceTemplateSettings();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return normalizeRawInvoiceTemplateSettings(this.store.invoiceTemplateSettings);
|
|
218
|
+
}
|
|
219
|
+
if (isLegacyInvoiceTemplate((_this$store$data2 = this.store.data) === null || _this$store$data2 === void 0 ? void 0 : _this$store$data2['documents.invoice_template'])) {
|
|
220
|
+
return normalizeInvoiceTemplateSettings(this.store.data);
|
|
221
|
+
}
|
|
222
|
+
return getDefaultInvoiceTemplateSettings();
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "ensureInvoiceTemplateSettings",
|
|
226
|
+
value: function () {
|
|
227
|
+
var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target) {
|
|
228
|
+
var normalizedTarget, config, fetchRevision, resolved;
|
|
229
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
230
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
231
|
+
case 0:
|
|
232
|
+
normalizedTarget = String(target || '').trim();
|
|
233
|
+
config = this.store.data;
|
|
234
|
+
if (!(!normalizedTarget || !config)) {
|
|
235
|
+
_context3.next = 4;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
239
|
+
case 4:
|
|
240
|
+
fetchRevision = this.fetchRevision;
|
|
241
|
+
_context3.next = 7;
|
|
242
|
+
return this.resolveInvoiceTemplateSettings(config, normalizedTarget);
|
|
243
|
+
case 7:
|
|
244
|
+
resolved = _context3.sent;
|
|
245
|
+
if (!(fetchRevision !== this.fetchRevision || this.store.data !== config)) {
|
|
246
|
+
_context3.next = 10;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
250
|
+
case 10:
|
|
251
|
+
this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
|
|
252
|
+
return _context3.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
|
|
253
|
+
case 12:
|
|
254
|
+
case "end":
|
|
255
|
+
return _context3.stop();
|
|
256
|
+
}
|
|
257
|
+
}, _callee3, this);
|
|
258
|
+
}));
|
|
259
|
+
function ensureInvoiceTemplateSettings(_x4) {
|
|
260
|
+
return _ensureInvoiceTemplateSettings.apply(this, arguments);
|
|
261
|
+
}
|
|
262
|
+
return ensureInvoiceTemplateSettings;
|
|
263
|
+
}()
|
|
264
|
+
}, {
|
|
265
|
+
key: "commitInvoiceTemplateSettings",
|
|
266
|
+
value: function commitInvoiceTemplateSettings(target, resolved) {
|
|
267
|
+
this.store.invoiceTemplateSettings = normalizeRawInvoiceTemplateSettings(resolved.settings);
|
|
268
|
+
this.store.invoiceTemplateTarget = target;
|
|
269
|
+
this.store.invoiceTemplateDocumentId = resolved.documentId;
|
|
270
|
+
this.store.invoiceTemplateCacheKey = resolved.cacheKey;
|
|
271
|
+
}
|
|
272
|
+
}, {
|
|
273
|
+
key: "resolveInvoiceTemplateSettings",
|
|
274
|
+
value: function () {
|
|
275
|
+
var _resolveInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config, target) {
|
|
276
|
+
var _this2 = this;
|
|
277
|
+
var rawTemplate, documentId, cacheKey, cachedSettings, request, cacheRevision;
|
|
278
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
279
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
280
|
+
case 0:
|
|
281
|
+
rawTemplate = config['documents.invoice_template'];
|
|
282
|
+
documentId = resolveInvoiceDocumentId(rawTemplate);
|
|
283
|
+
if (documentId) {
|
|
284
|
+
_context4.next = 4;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
return _context4.abrupt("return", {
|
|
288
|
+
settings: isLegacyInvoiceTemplate(rawTemplate) ? normalizeInvoiceTemplateSettings(config) : getDefaultInvoiceTemplateSettings(),
|
|
289
|
+
documentId: null,
|
|
290
|
+
cacheKey: null
|
|
291
|
+
});
|
|
292
|
+
case 4:
|
|
293
|
+
cacheKey = this.buildInvoiceTemplateCacheKey(target, documentId);
|
|
294
|
+
if (!(this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings))) {
|
|
295
|
+
_context4.next = 7;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
return _context4.abrupt("return", {
|
|
299
|
+
settings: normalizeRawInvoiceTemplateSettings(this.store.invoiceTemplateSettings),
|
|
300
|
+
documentId: documentId,
|
|
301
|
+
cacheKey: cacheKey
|
|
302
|
+
});
|
|
303
|
+
case 7:
|
|
304
|
+
cachedSettings = this.invoiceTemplateDocumentCache.get(cacheKey);
|
|
305
|
+
if (!cachedSettings) {
|
|
306
|
+
_context4.next = 10;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
return _context4.abrupt("return", {
|
|
310
|
+
settings: normalizeRawInvoiceTemplateSettings(cachedSettings),
|
|
311
|
+
documentId: documentId,
|
|
312
|
+
cacheKey: cacheKey
|
|
313
|
+
});
|
|
314
|
+
case 10:
|
|
315
|
+
request = this.invoiceTemplateDocumentInFlight.get(cacheKey);
|
|
316
|
+
if (!request) {
|
|
317
|
+
cacheRevision = this.invoiceTemplateCacheRevision;
|
|
318
|
+
request = this.fetchInvoiceTemplateDocument(documentId).catch(function (error) {
|
|
319
|
+
_this2.logInvoiceTemplateDocumentFallback(error, target, documentId);
|
|
320
|
+
return getDefaultInvoiceTemplateSettings();
|
|
321
|
+
}).then(function (settings) {
|
|
322
|
+
var normalized = normalizeRawInvoiceTemplateSettings(settings);
|
|
323
|
+
if (cacheRevision === _this2.invoiceTemplateCacheRevision) {
|
|
324
|
+
_this2.invoiceTemplateDocumentCache.set(cacheKey, normalized);
|
|
325
|
+
}
|
|
326
|
+
return normalized;
|
|
327
|
+
}).finally(function () {
|
|
328
|
+
if (_this2.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
|
|
329
|
+
_this2.invoiceTemplateDocumentInFlight.delete(cacheKey);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
this.invoiceTemplateDocumentInFlight.set(cacheKey, request);
|
|
333
|
+
}
|
|
334
|
+
_context4.next = 14;
|
|
335
|
+
return request;
|
|
336
|
+
case 14:
|
|
337
|
+
_context4.t0 = _context4.sent;
|
|
338
|
+
_context4.t1 = documentId;
|
|
339
|
+
_context4.t2 = cacheKey;
|
|
340
|
+
return _context4.abrupt("return", {
|
|
341
|
+
settings: _context4.t0,
|
|
342
|
+
documentId: _context4.t1,
|
|
343
|
+
cacheKey: _context4.t2
|
|
344
|
+
});
|
|
345
|
+
case 18:
|
|
346
|
+
case "end":
|
|
347
|
+
return _context4.stop();
|
|
348
|
+
}
|
|
349
|
+
}, _callee4, this);
|
|
350
|
+
}));
|
|
351
|
+
function resolveInvoiceTemplateSettings(_x5, _x6) {
|
|
352
|
+
return _resolveInvoiceTemplateSettings.apply(this, arguments);
|
|
353
|
+
}
|
|
354
|
+
return resolveInvoiceTemplateSettings;
|
|
355
|
+
}()
|
|
356
|
+
}, {
|
|
357
|
+
key: "buildInvoiceTemplateCacheKey",
|
|
358
|
+
value: function buildInvoiceTemplateCacheKey(target, documentId) {
|
|
359
|
+
var _this$appPlugin2, _this$appPlugin2$getD, _getData, _getData2;
|
|
360
|
+
var getData = (_this$appPlugin2 = this.appPlugin) === null || _this$appPlugin2 === void 0 || (_this$appPlugin2$getD = _this$appPlugin2.getData) === null || _this$appPlugin2$getD === void 0 ? void 0 : _this$appPlugin2$getD.call(_this$appPlugin2);
|
|
361
|
+
return JSON.stringify([(_getData = getData === null || getData === void 0 ? void 0 : getData('tenant_id')) !== null && _getData !== void 0 ? _getData : null, (_getData2 = getData === null || getData === void 0 ? void 0 : getData('shop_id')) !== null && _getData2 !== void 0 ? _getData2 : null, target, documentId]);
|
|
362
|
+
}
|
|
363
|
+
}, {
|
|
364
|
+
key: "fetchInvoiceTemplateDocument",
|
|
365
|
+
value: function () {
|
|
366
|
+
var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(documentId) {
|
|
367
|
+
var response, document;
|
|
368
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
369
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
370
|
+
case 0:
|
|
371
|
+
_context5.next = 2;
|
|
372
|
+
return this.request.get("/document:get?filterByTk=".concat(encodeURIComponent(documentId)), {}, {
|
|
373
|
+
isNocobase: true,
|
|
374
|
+
prefix: false,
|
|
375
|
+
headers: {
|
|
376
|
+
'x-data-source': 'pisell2'
|
|
377
|
+
},
|
|
378
|
+
customToast: function customToast() {}
|
|
379
|
+
});
|
|
380
|
+
case 2:
|
|
381
|
+
response = _context5.sent;
|
|
382
|
+
document = response === null || response === void 0 ? void 0 : response.data;
|
|
383
|
+
if (!(!document || resolveInvoiceDocumentId(document.id) !== documentId)) {
|
|
384
|
+
_context5.next = 6;
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
throw new Error("Invoice Document ".concat(documentId, " \u8FD4\u56DE\u7684 ID \u4E0D\u5339\u914D"));
|
|
388
|
+
case 6:
|
|
389
|
+
if (!(document.deleted_at !== null && document.deleted_at !== undefined)) {
|
|
390
|
+
_context5.next = 8;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
throw new Error("Invoice Document ".concat(documentId, " \u5DF2\u88AB\u5220\u9664"));
|
|
394
|
+
case 8:
|
|
395
|
+
if (!(!isRecord(document.data) || !isRecord(document.data.template_settings))) {
|
|
396
|
+
_context5.next = 10;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
throw new Error("Invoice Document ".concat(documentId, " \u7F3A\u5C11 template_settings"));
|
|
400
|
+
case 10:
|
|
401
|
+
return _context5.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
|
|
402
|
+
case 11:
|
|
403
|
+
case "end":
|
|
404
|
+
return _context5.stop();
|
|
405
|
+
}
|
|
406
|
+
}, _callee5, this);
|
|
407
|
+
}));
|
|
408
|
+
function fetchInvoiceTemplateDocument(_x7) {
|
|
409
|
+
return _fetchInvoiceTemplateDocument.apply(this, arguments);
|
|
410
|
+
}
|
|
411
|
+
return fetchInvoiceTemplateDocument;
|
|
412
|
+
}()
|
|
413
|
+
}, {
|
|
414
|
+
key: "logInvoiceTemplateDocumentFallback",
|
|
415
|
+
value: function logInvoiceTemplateDocumentFallback(error, target, documentId) {
|
|
416
|
+
console.warn('[OpenDataModule] Invoice Document 加载失败,使用 DEFAULT', {
|
|
417
|
+
target: target,
|
|
418
|
+
documentId: documentId,
|
|
419
|
+
message: error instanceof Error ? error.message : String(error)
|
|
420
|
+
});
|
|
174
421
|
}
|
|
175
422
|
}, {
|
|
176
423
|
key: "getLastFetchedAt",
|
|
@@ -184,14 +431,21 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
184
431
|
key: "clearCache",
|
|
185
432
|
value: function clearCache() {
|
|
186
433
|
this.fetchRevision += 1;
|
|
434
|
+
this.invoiceTemplateCacheRevision += 1;
|
|
435
|
+
this.invoiceTemplateDocumentCache.clear();
|
|
436
|
+
this.invoiceTemplateDocumentInFlight.clear();
|
|
187
437
|
this.store.data = null;
|
|
188
438
|
this.store.lastFetchedAt = null;
|
|
439
|
+
this.store.invoiceTemplateSettings = null;
|
|
440
|
+
this.store.invoiceTemplateTarget = null;
|
|
441
|
+
this.store.invoiceTemplateDocumentId = null;
|
|
442
|
+
this.store.invoiceTemplateCacheKey = null;
|
|
189
443
|
}
|
|
190
444
|
}, {
|
|
191
445
|
key: "checkAvailability",
|
|
192
446
|
value: function checkAvailability(scheduleModule) {
|
|
193
|
-
var _this$store$
|
|
194
|
-
var scheduleList = scheduleModule ? scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(((_this$store$
|
|
447
|
+
var _this$store$data3;
|
|
448
|
+
var scheduleList = scheduleModule ? scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(((_this$store$data3 = this.store.data) === null || _this$store$data3 === void 0 ? void 0 : _this$store$data3['availability.operating_hours']) || []) : undefined;
|
|
195
449
|
return computeAvailability({
|
|
196
450
|
config: this.store.data,
|
|
197
451
|
scheduleList: scheduleList
|
|
@@ -32,6 +32,15 @@ export interface InvoiceTemplateSettings {
|
|
|
32
32
|
modules: InvoiceTemplateModuleConfig[];
|
|
33
33
|
[key: string]: unknown;
|
|
34
34
|
}
|
|
35
|
+
export interface InvoiceDocumentResponse {
|
|
36
|
+
data?: {
|
|
37
|
+
id?: number | string;
|
|
38
|
+
deleted_at?: string | null;
|
|
39
|
+
data?: {
|
|
40
|
+
template_settings?: unknown;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
35
44
|
export type RawInvoiceEditConfig = string | {
|
|
36
45
|
language?: unknown;
|
|
37
46
|
modules?: unknown;
|
|
@@ -79,7 +88,7 @@ export interface OpenDataConfig {
|
|
|
79
88
|
label: string;
|
|
80
89
|
value: number;
|
|
81
90
|
}>;
|
|
82
|
-
'documents.invoice_template'?: string;
|
|
91
|
+
'documents.invoice_template'?: string | number;
|
|
83
92
|
'documents.invoice_edit'?: RawInvoiceEditConfig;
|
|
84
93
|
/** @deprecated 仅保留旧调用方的类型兼容,Invoice 读取逻辑不再消费该字段。 */
|
|
85
94
|
'documents.invoice'?: RawInvoiceLayoutConfig;
|
|
@@ -92,6 +101,10 @@ export interface OpenDataConfig {
|
|
|
92
101
|
export interface OpenDataState {
|
|
93
102
|
data: OpenDataConfig | null;
|
|
94
103
|
lastFetchedAt: number | null;
|
|
104
|
+
invoiceTemplateSettings?: InvoiceTemplateSettings | null;
|
|
105
|
+
invoiceTemplateTarget?: string | null;
|
|
106
|
+
invoiceTemplateDocumentId?: string | null;
|
|
107
|
+
invoiceTemplateCacheKey?: string | null;
|
|
95
108
|
}
|
|
96
109
|
export interface OpenDataFetchParams {
|
|
97
110
|
scope: string;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { OpenDataConfig, OpenDataAvailabilityResult, ComputeAvailabilityParams, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
|
|
2
2
|
export declare function getDefaultInvoiceLayoutConfig(): InvoiceLayoutConfig;
|
|
3
3
|
export declare function getDefaultInvoiceTemplateSettings(): InvoiceTemplateSettings;
|
|
4
|
+
/**
|
|
5
|
+
* 将非 DEFAULT Invoice 模板启用的语言转换为 small_ticket_data locale。
|
|
6
|
+
* cn_en 是中英组合打印模式,因此展开为 en 与 zh_CN 两份数据。
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveInvoiceReceiptLocales(settings?: InvoiceTemplateSettings | null): string[];
|
|
4
9
|
/**
|
|
5
10
|
* 规范化已经提取出的公开 template_settings 值,供打印入口复用。
|
|
6
11
|
*/
|
|
@@ -9,6 +14,7 @@ export declare function normalizeRawInvoiceTemplateSettings(value: unknown): Inv
|
|
|
9
14
|
* 从 OpenData Documents section 的两个扁平字段中构造 Native Invoice 配置。
|
|
10
15
|
*/
|
|
11
16
|
export declare function normalizeInvoiceTemplateSettings(config: OpenDataConfig | null | undefined): InvoiceTemplateSettings;
|
|
17
|
+
export declare function normalizeInvoiceLayoutFromTemplateSettings(settings: InvoiceTemplateSettings | null | undefined): InvoiceLayoutConfig;
|
|
12
18
|
/**
|
|
13
19
|
* 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
|
|
14
20
|
*/
|
|
@@ -3,6 +3,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
3
3
|
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; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
5
|
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); }
|
|
6
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
10
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
12
|
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); }
|
|
7
13
|
import dayjs from 'dayjs';
|
|
8
14
|
import { getDateIsInSchedule } from "../Schedule/getDateIsInSchedule";
|
|
@@ -38,6 +44,42 @@ export function getDefaultInvoiceTemplateSettings() {
|
|
|
38
44
|
modules: []
|
|
39
45
|
};
|
|
40
46
|
}
|
|
47
|
+
var INVOICE_RECEIPT_LOCALE_ORDER = ['en', 'zh_CN', 'zh_HK', 'ja', 'pt'];
|
|
48
|
+
var INVOICE_RECEIPT_LOCALE_MAPPING = {
|
|
49
|
+
en: ['en'],
|
|
50
|
+
zh_cn: ['zh_CN'],
|
|
51
|
+
zh_hk: ['zh_HK'],
|
|
52
|
+
ja: ['ja'],
|
|
53
|
+
pt: ['pt'],
|
|
54
|
+
cn_en: ['en', 'zh_CN']
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 将非 DEFAULT Invoice 模板启用的语言转换为 small_ticket_data locale。
|
|
59
|
+
* cn_en 是中英组合打印模式,因此展开为 en 与 zh_CN 两份数据。
|
|
60
|
+
*/
|
|
61
|
+
export function resolveInvoiceReceiptLocales(settings) {
|
|
62
|
+
if (typeof (settings === null || settings === void 0 ? void 0 : settings.template) !== 'string' || settings.template.trim().length === 0 || settings.template.trim().toUpperCase() === 'DEFAULT' || !isRecord(settings.language)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
var enabledLocales = new Set();
|
|
66
|
+
Object.entries(settings.language).forEach(function (_ref) {
|
|
67
|
+
var _INVOICE_RECEIPT_LOCA;
|
|
68
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
69
|
+
rawKey = _ref2[0],
|
|
70
|
+
count = _ref2[1];
|
|
71
|
+
if (typeof count !== 'number' || !Number.isFinite(count) || count <= 0) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
var key = rawKey.trim().toLowerCase().replace(/-/g, '_');
|
|
75
|
+
(_INVOICE_RECEIPT_LOCA = INVOICE_RECEIPT_LOCALE_MAPPING[key]) === null || _INVOICE_RECEIPT_LOCA === void 0 || _INVOICE_RECEIPT_LOCA.forEach(function (locale) {
|
|
76
|
+
enabledLocales.add(locale);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
return INVOICE_RECEIPT_LOCALE_ORDER.filter(function (locale) {
|
|
80
|
+
return enabledLocales.has(locale);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
41
83
|
function normalizeInvoiceTemplate(value) {
|
|
42
84
|
if (typeof value !== 'string' || value.trim().length === 0) return 'DEFAULT';
|
|
43
85
|
return value.trim().toUpperCase() === 'DEFAULT' ? 'DEFAULT' : value;
|
|
@@ -83,16 +125,19 @@ export function normalizeInvoiceTemplateSettings(config) {
|
|
|
83
125
|
template: normalizeInvoiceTemplate(config === null || config === void 0 ? void 0 : config['documents.invoice_template'])
|
|
84
126
|
}));
|
|
85
127
|
}
|
|
128
|
+
export function normalizeInvoiceLayoutFromTemplateSettings(settings) {
|
|
129
|
+
var modules = normalizeRawInvoiceTemplateSettings(settings).modules;
|
|
130
|
+
if (modules.length === 0) return getDefaultInvoiceLayoutConfig();
|
|
131
|
+
return {
|
|
132
|
+
module: modules
|
|
133
|
+
};
|
|
134
|
+
}
|
|
86
135
|
|
|
87
136
|
/**
|
|
88
137
|
* 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
|
|
89
138
|
*/
|
|
90
139
|
export function normalizeInvoiceLayoutConfig(config) {
|
|
91
|
-
|
|
92
|
-
if (modules.length === 0) return getDefaultInvoiceLayoutConfig();
|
|
93
|
-
return {
|
|
94
|
-
module: modules
|
|
95
|
-
};
|
|
140
|
+
return normalizeInvoiceLayoutFromTemplateSettings(normalizeInvoiceTemplateSettings(config));
|
|
96
141
|
}
|
|
97
142
|
function toBoolean(value) {
|
|
98
143
|
if (typeof value === 'boolean') return value;
|
|
@@ -528,7 +528,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
528
528
|
generateIdempotencyToken(): string;
|
|
529
529
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
530
530
|
createOrder(params: CommitOrderParams['query']): {
|
|
531
|
-
type: "
|
|
531
|
+
type: "appointment_booking" | "virtual";
|
|
532
532
|
platform: string;
|
|
533
533
|
sales_channel: string;
|
|
534
534
|
order_sales_channel: string;
|
|
@@ -69,6 +69,7 @@ export interface RequestOptions {
|
|
|
69
69
|
customToast?: () => void;
|
|
70
70
|
cache?: CacheProps;
|
|
71
71
|
osServer?: boolean;
|
|
72
|
+
isNocobase?: boolean;
|
|
72
73
|
prefix?: boolean;
|
|
73
74
|
callback?: (res: any) => void;
|
|
74
75
|
subscriberId?: string;
|
|
@@ -124,7 +125,7 @@ declare class RequestPluginImpl implements RequestPlugin {
|
|
|
124
125
|
/**
|
|
125
126
|
* GET 请求
|
|
126
127
|
*/
|
|
127
|
-
get<T = any>(url: string, options?: RequestOptions): Promise<T>;
|
|
128
|
+
get<T = any>(url: string, dataOrOptions?: any, options?: RequestOptions): Promise<T>;
|
|
128
129
|
/**
|
|
129
130
|
* POST 请求
|
|
130
131
|
*/
|
package/dist/plugins/request.js
CHANGED
|
@@ -147,8 +147,10 @@ var RequestPluginImpl = /*#__PURE__*/function () {
|
|
|
147
147
|
}, {
|
|
148
148
|
key: "get",
|
|
149
149
|
value: function get(url) {
|
|
150
|
-
var
|
|
151
|
-
|
|
150
|
+
var dataOrOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
151
|
+
var options = arguments.length > 2 ? arguments[2] : undefined;
|
|
152
|
+
var requestOptions = options !== null && options !== void 0 ? options : dataOrOptions;
|
|
153
|
+
return this.request(_objectSpread(_objectSpread({}, requestOptions), {}, {
|
|
152
154
|
url: url,
|
|
153
155
|
method: 'GET'
|
|
154
156
|
}));
|
package/dist/server/index.d.ts
CHANGED
|
@@ -532,6 +532,11 @@ declare class Server {
|
|
|
532
532
|
private handleOrderDraftSubmit;
|
|
533
533
|
private handlePendingSyncCheckoutOrder;
|
|
534
534
|
private buildPendingSyncCheckoutOrder;
|
|
535
|
+
/**
|
|
536
|
+
* Checkout 与本地小票必须消费同一份规范化子项快照。
|
|
537
|
+
* 商品/预约只折叠持久化 ID 或协议 UID 相同的行;支付额外兼容 payment_number。
|
|
538
|
+
*/
|
|
539
|
+
private normalizeCheckoutCollections;
|
|
535
540
|
/**
|
|
536
541
|
* Android 结账自动小票由当前设备设置控制;其它平台保持原有行为。
|
|
537
542
|
*/
|