@pisell/pisellos 2.2.302 → 2.2.303
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/dataVariant/evaluator.d.ts +18 -2
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
- package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
- package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
- package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
- package/dist/model/strategy/adapter/itemRule/type.js +19 -1
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +10 -7
- package/dist/modules/Discount/index.d.ts +2 -0
- package/dist/modules/Discount/index.js +41 -5
- package/dist/modules/Discount/types.d.ts +21 -0
- package/dist/modules/OpenData/index.d.ts +15 -2
- package/dist/modules/OpenData/index.js +307 -19
- package/dist/modules/OpenData/types.d.ts +55 -0
- package/dist/modules/OpenData/types.js +7 -1
- package/dist/modules/OpenData/utils.d.ts +21 -1
- package/dist/modules/OpenData/utils.js +138 -0
- package/dist/modules/Order/index.d.ts +50 -7
- package/dist/modules/Order/index.js +1690 -815
- package/dist/modules/Order/salesNotes.d.ts +31 -0
- package/dist/modules/Order/salesNotes.js +492 -0
- package/dist/modules/Order/types.d.ts +117 -10
- package/dist/modules/Order/types.js +6 -1
- package/dist/modules/Order/utils/virtualSettlement.d.ts +63 -0
- package/dist/modules/Order/utils/virtualSettlement.js +284 -0
- package/dist/modules/Order/utils.d.ts +5 -1
- package/dist/modules/Order/utils.js +138 -33
- package/dist/modules/Payment/walletpass.js +20 -21
- package/dist/modules/Product/types.d.ts +23 -0
- package/dist/modules/ProductList/index.d.ts +2 -1
- package/dist/modules/ProductList/index.js +100 -20
- package/dist/modules/ProductList/types.d.ts +10 -0
- package/dist/modules/Rules/index.d.ts +5 -0
- package/dist/modules/Rules/index.js +30 -14
- package/dist/modules/SalesSummary/index.d.ts +1 -0
- package/dist/modules/SalesSummary/index.js +4 -3
- package/dist/modules/SalesSummary/types.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.js +21 -1
- package/dist/plugins/request.d.ts +2 -1
- package/dist/plugins/request.js +4 -2
- package/dist/server/index.d.ts +21 -0
- package/dist/server/index.js +1774 -1285
- package/dist/server/modules/order/types.d.ts +50 -0
- package/dist/server/modules/order/types.js +2 -0
- package/dist/server/utils/small-ticket.d.ts +4 -1
- package/dist/server/utils/small-ticket.js +461 -96
- package/dist/solution/BaseSales/index.d.ts +24 -3
- package/dist/solution/BaseSales/index.js +1484 -873
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +72 -9
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +22 -5
- package/dist/solution/BookingTicket/index.js +558 -443
- package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
- package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
- package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
- package/dist/solution/RegisterAndLogin/config.js +95 -40
- package/dist/solution/RegisterAndLogin/index.js +4 -1
- package/dist/solution/Sales/index.d.ts +16 -1
- package/dist/solution/Sales/index.js +338 -63
- package/dist/solution/Sales/types.d.ts +10 -0
- package/dist/solution/ScanOrder/index.d.ts +1 -0
- package/dist/solution/ScanOrder/index.js +31 -27
- package/dist/solution/ScanOrder/utils.d.ts +1 -0
- package/dist/solution/ScanOrder/utils.js +2 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +20 -6
- package/dist/solution/UnifiedBookingSales/index.js +874 -527
- package/dist/solution/UnifiedBookingSales/types.d.ts +21 -2
- package/dist/solution/VenueBooking/index.d.ts +1 -0
- package/dist/solution/VenueBooking/index.js +8 -4
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +137 -6
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
- package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
- package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
- package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
- package/lib/model/strategy/adapter/itemRule/type.js +19 -1
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +4 -0
- package/lib/modules/Discount/index.d.ts +2 -0
- package/lib/modules/Discount/index.js +34 -2
- package/lib/modules/Discount/types.d.ts +21 -0
- package/lib/modules/OpenData/index.d.ts +15 -2
- package/lib/modules/OpenData/index.js +230 -3
- package/lib/modules/OpenData/types.d.ts +55 -0
- package/lib/modules/OpenData/types.js +9 -1
- package/lib/modules/OpenData/utils.d.ts +21 -1
- package/lib/modules/OpenData/utils.js +126 -0
- package/lib/modules/Order/index.d.ts +50 -7
- package/lib/modules/Order/index.js +704 -64
- package/lib/modules/Order/salesNotes.d.ts +31 -0
- package/lib/modules/Order/salesNotes.js +382 -0
- package/lib/modules/Order/types.d.ts +117 -10
- package/lib/modules/Order/types.js +5 -1
- package/lib/modules/Order/utils/virtualSettlement.d.ts +63 -0
- package/lib/modules/Order/utils/virtualSettlement.js +262 -0
- package/lib/modules/Order/utils.d.ts +5 -1
- package/lib/modules/Order/utils.js +127 -21
- package/lib/modules/Payment/walletpass.js +14 -11
- package/lib/modules/Product/types.d.ts +23 -0
- package/lib/modules/ProductList/index.d.ts +2 -1
- package/lib/modules/ProductList/index.js +47 -2
- package/lib/modules/ProductList/types.d.ts +10 -0
- package/lib/modules/Rules/index.d.ts +5 -0
- package/lib/modules/Rules/index.js +22 -12
- package/lib/modules/SalesSummary/index.d.ts +1 -0
- package/lib/modules/SalesSummary/index.js +4 -2
- package/lib/modules/SalesSummary/types.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.js +17 -1
- package/lib/plugins/request.d.ts +2 -1
- package/lib/plugins/request.js +3 -2
- package/lib/server/index.d.ts +21 -0
- package/lib/server/index.js +492 -108
- package/lib/server/modules/order/types.d.ts +50 -0
- package/lib/server/modules/order/types.js +1 -0
- package/lib/server/utils/small-ticket.d.ts +4 -1
- package/lib/server/utils/small-ticket.js +427 -72
- package/lib/solution/BaseSales/index.d.ts +24 -3
- package/lib/solution/BaseSales/index.js +433 -30
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +38 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +22 -5
- package/lib/solution/BookingTicket/index.js +60 -15
- package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
- package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
- package/lib/solution/RegisterAndLogin/config.js +49 -8
- package/lib/solution/RegisterAndLogin/index.js +4 -1
- package/lib/solution/Sales/index.d.ts +16 -1
- package/lib/solution/Sales/index.js +168 -1
- package/lib/solution/Sales/types.d.ts +10 -0
- package/lib/solution/ScanOrder/index.d.ts +1 -0
- package/lib/solution/ScanOrder/index.js +5 -1
- package/lib/solution/ScanOrder/utils.d.ts +1 -0
- package/lib/solution/ScanOrder/utils.js +1 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +20 -6
- package/lib/solution/UnifiedBookingSales/index.js +169 -16
- package/lib/solution/UnifiedBookingSales/types.d.ts +21 -2
- package/lib/solution/VenueBooking/index.d.ts +1 -0
- package/lib/solution/VenueBooking/index.js +5 -1
- package/package.json +1 -1
|
@@ -165,8 +165,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
165
165
|
key: "loadPrepareConfig",
|
|
166
166
|
value: function () {
|
|
167
167
|
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
168
|
-
var _params$with_availabl, _params$with_availabl2, _prepareConfig$data, _prepareConfig$data2, _prepareConfig$data3, _prepareConfig$data4, _prepareConfig$data5;
|
|
169
|
-
var prepareConfig, rawDiscountList, availableWalletList, availableWalletPassList, availableWalletIds, goodPassList;
|
|
168
|
+
var _params$with_availabl, _params$with_availabl2, _params$with_virtual_, _prepareConfig$data, _prepareConfig$data2, _prepareConfig$data3, _prepareConfig$data4, _prepareConfig$data5, _prepareConfig$data6;
|
|
169
|
+
var prepareConfig, rawDiscountList, availableWalletList, availableWalletPassList, availableWalletIds, virtualCurrencyList, goodPassList;
|
|
170
170
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
171
171
|
while (1) switch (_context4.prev = _context4.next) {
|
|
172
172
|
case 0:
|
|
@@ -176,7 +176,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
176
176
|
_context4.next = 3;
|
|
177
177
|
return this.request.post("/order/prepare/config", _objectSpread(_objectSpread({}, params), {}, {
|
|
178
178
|
with_available_wallet_flag: (_params$with_availabl = params.with_available_wallet_flag) !== null && _params$with_availabl !== void 0 ? _params$with_availabl : 1,
|
|
179
|
-
with_available_wallet_pass_flag: (_params$with_availabl2 = params.with_available_wallet_pass_flag) !== null && _params$with_availabl2 !== void 0 ? _params$with_availabl2 : 1
|
|
179
|
+
with_available_wallet_pass_flag: (_params$with_availabl2 = params.with_available_wallet_pass_flag) !== null && _params$with_availabl2 !== void 0 ? _params$with_availabl2 : 1,
|
|
180
|
+
with_virtual_currency: (_params$with_virtual_ = params.with_virtual_currency) !== null && _params$with_virtual_ !== void 0 ? _params$with_virtual_ : 1
|
|
180
181
|
}));
|
|
181
182
|
case 3:
|
|
182
183
|
prepareConfig = _context4.sent;
|
|
@@ -188,12 +189,17 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
188
189
|
})), _toConsumableArray(availableWalletPassList.map(function (item) {
|
|
189
190
|
return item === null || item === void 0 ? void 0 : item.product_id;
|
|
190
191
|
}))));
|
|
192
|
+
virtualCurrencyList = this.normalizeVirtualCurrencyList(prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data6 = prepareConfig.data) === null || _prepareConfig$data6 === void 0 ? void 0 : _prepareConfig$data6.virtual_currency_list);
|
|
191
193
|
goodPassList = this.filterEnabledDiscountList(rawDiscountList) || []; // this.setDiscountList(goodPassList);
|
|
192
194
|
return _context4.abrupt("return", {
|
|
193
195
|
discountList: goodPassList,
|
|
194
|
-
availableWalletIds: availableWalletIds
|
|
196
|
+
availableWalletIds: availableWalletIds,
|
|
197
|
+
virtualCurrencyList: virtualCurrencyList,
|
|
198
|
+
availableWalletPassList: availableWalletPassList.map(function (item) {
|
|
199
|
+
return _objectSpread({}, item || {});
|
|
200
|
+
})
|
|
195
201
|
});
|
|
196
|
-
case
|
|
202
|
+
case 11:
|
|
197
203
|
case "end":
|
|
198
204
|
return _context4.stop();
|
|
199
205
|
}
|
|
@@ -204,6 +210,36 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
204
210
|
}
|
|
205
211
|
return loadPrepareConfig;
|
|
206
212
|
}()
|
|
213
|
+
}, {
|
|
214
|
+
key: "normalizeVirtualCurrencyList",
|
|
215
|
+
value: function normalizeVirtualCurrencyList(value) {
|
|
216
|
+
if (!Array.isArray(value)) return [];
|
|
217
|
+
return value.flatMap(function (item) {
|
|
218
|
+
var _item$balance;
|
|
219
|
+
var id = Number(item === null || item === void 0 ? void 0 : item.id);
|
|
220
|
+
var productId = Number(item === null || item === void 0 ? void 0 : item.product_id);
|
|
221
|
+
if (!Number.isFinite(id) || id <= 0 || !Number.isFinite(productId) || productId <= 0) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
var displayExtension = Array.isArray(item === null || item === void 0 ? void 0 : item.extension_data) ? item.extension_data.find(function (extension) {
|
|
225
|
+
return (extension === null || extension === void 0 ? void 0 : extension.field_key) === 'virtual_currency_display';
|
|
226
|
+
}) : undefined;
|
|
227
|
+
var display = displayExtension === null || displayExtension === void 0 ? void 0 : displayExtension.value;
|
|
228
|
+
if (typeof display === 'string') {
|
|
229
|
+
try {
|
|
230
|
+
display = JSON.parse(display);
|
|
231
|
+
} catch (_unused) {
|
|
232
|
+
display = {};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return [_objectSpread(_objectSpread({}, item), {}, {
|
|
236
|
+
id: id,
|
|
237
|
+
product_id: productId,
|
|
238
|
+
balance: String((_item$balance = item === null || item === void 0 ? void 0 : item.balance) !== null && _item$balance !== void 0 ? _item$balance : '0'),
|
|
239
|
+
virtual_currency_display: display && _typeof(display) === 'object' && !Array.isArray(display) ? display : {}
|
|
240
|
+
})];
|
|
241
|
+
});
|
|
242
|
+
}
|
|
207
243
|
}, {
|
|
208
244
|
key: "batchSearch",
|
|
209
245
|
value: function () {
|
|
@@ -68,9 +68,30 @@ export interface DiscountWithReason {
|
|
|
68
68
|
discountList: Discount[];
|
|
69
69
|
unavailableReasonKey: DiscountFilterRejectKey | null;
|
|
70
70
|
}
|
|
71
|
+
export interface WalletPassPrepareConfigItem {
|
|
72
|
+
id?: number | string | null;
|
|
73
|
+
tag?: string | null;
|
|
74
|
+
product_id?: number | string | null;
|
|
75
|
+
product_name?: string | null;
|
|
76
|
+
par_value?: string | number | null;
|
|
77
|
+
used_par_value?: string | number | null;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}
|
|
71
80
|
export interface DiscountPrepareConfigResult {
|
|
72
81
|
discountList: Discount[];
|
|
73
82
|
availableWalletIds: number[];
|
|
83
|
+
virtualCurrencyList?: VirtualCurrencyAsset[];
|
|
84
|
+
availableWalletPassList?: WalletPassPrepareConfigItem[];
|
|
85
|
+
}
|
|
86
|
+
export interface VirtualCurrencyAsset extends Record<string, any> {
|
|
87
|
+
id: number;
|
|
88
|
+
product_id: number;
|
|
89
|
+
balance: string;
|
|
90
|
+
product_name?: string;
|
|
91
|
+
format_title?: Record<string, any>;
|
|
92
|
+
code?: string;
|
|
93
|
+
encoded?: string;
|
|
94
|
+
virtual_currency_display?: Record<string, any>;
|
|
74
95
|
}
|
|
75
96
|
interface ExtensionData {
|
|
76
97
|
id: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
3
|
import type { ScheduleModule } from '../Schedule';
|
|
4
|
-
import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult } from './types';
|
|
4
|
+
import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
|
|
5
5
|
export * from './types';
|
|
6
|
-
export { computeAvailability } 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;
|
|
@@ -15,6 +15,10 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
15
15
|
private openCache;
|
|
16
16
|
private fatherModule;
|
|
17
17
|
private otherParams;
|
|
18
|
+
private fetchRevision;
|
|
19
|
+
private invoiceTemplateCacheRevision;
|
|
20
|
+
private invoiceTemplateDocumentCache;
|
|
21
|
+
private invoiceTemplateDocumentInFlight;
|
|
18
22
|
constructor(name?: string, version?: string);
|
|
19
23
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
20
24
|
/**
|
|
@@ -24,8 +28,17 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
24
28
|
* openDataModule.updateOtherParams({ openCache: true, cacheId: 'cache-2' })
|
|
25
29
|
*/
|
|
26
30
|
updateOtherParams(params: Record<string, any>): void;
|
|
31
|
+
private shouldSkipInvoiceTemplateDocument;
|
|
27
32
|
fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
|
|
28
33
|
getOpenData(): OpenDataConfig | null;
|
|
34
|
+
getInvoiceLayoutConfig(): InvoiceLayoutConfig;
|
|
35
|
+
getInvoiceTemplateSettings(): InvoiceTemplateSettings;
|
|
36
|
+
ensureInvoiceTemplateSettings(target: string): Promise<InvoiceTemplateSettings>;
|
|
37
|
+
private commitInvoiceTemplateSettings;
|
|
38
|
+
private resolveInvoiceTemplateSettings;
|
|
39
|
+
private buildInvoiceTemplateCacheKey;
|
|
40
|
+
private fetchInvoiceTemplateDocument;
|
|
41
|
+
private logInvoiceTemplateDocumentFallback;
|
|
29
42
|
getLastFetchedAt(): number | null;
|
|
30
43
|
/** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
|
|
31
44
|
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 } from "./utils";
|
|
19
|
+
import { computeAvailability, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings } from "./utils";
|
|
20
20
|
export * from "./types";
|
|
21
|
-
export { computeAvailability } 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);
|
|
@@ -36,6 +55,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
36
55
|
_defineProperty(_assertThisInitialized(_this), "openCache", false);
|
|
37
56
|
_defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
|
|
38
57
|
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
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());
|
|
39
62
|
return _this;
|
|
40
63
|
}
|
|
41
64
|
_createClass(OpenDataModule, [{
|
|
@@ -51,6 +74,12 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
51
74
|
this.store = options.store;
|
|
52
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;
|
|
53
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;
|
|
54
83
|
this.otherParams = options.otherParams || {};
|
|
55
84
|
if (this.otherParams.cacheId) {
|
|
56
85
|
this.openCache = (_this$otherParams$ope = this.otherParams.openCache) !== null && _this$otherParams$ope !== void 0 ? _this$otherParams$ope : false;
|
|
@@ -63,17 +92,17 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
63
92
|
this.window = core.getPlugin('window');
|
|
64
93
|
this.appPlugin = core.getPlugin('app');
|
|
65
94
|
if (this.request) {
|
|
66
|
-
_context.next =
|
|
95
|
+
_context.next = 16;
|
|
67
96
|
break;
|
|
68
97
|
}
|
|
69
98
|
throw new Error('OpenDataModule 需要 request 插件支持');
|
|
70
|
-
case
|
|
99
|
+
case 16:
|
|
71
100
|
if (this.window) {
|
|
72
|
-
_context.next =
|
|
101
|
+
_context.next = 18;
|
|
73
102
|
break;
|
|
74
103
|
}
|
|
75
104
|
throw new Error('OpenDataModule 需要 window 插件支持');
|
|
76
|
-
case
|
|
105
|
+
case 18:
|
|
77
106
|
case "end":
|
|
78
107
|
return _context.stop();
|
|
79
108
|
}
|
|
@@ -99,27 +128,34 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
99
128
|
this.cacheId = this.otherParams.cacheId;
|
|
100
129
|
this.fatherModule = this.otherParams.fatherModule;
|
|
101
130
|
}
|
|
131
|
+
}, {
|
|
132
|
+
key: "shouldSkipInvoiceTemplateDocument",
|
|
133
|
+
value: function shouldSkipInvoiceTemplateDocument() {
|
|
134
|
+
var _this$otherParams;
|
|
135
|
+
return String(((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.platform) || '').trim().toLowerCase() === 'h5';
|
|
136
|
+
}
|
|
102
137
|
}, {
|
|
103
138
|
key: "fetchOpenData",
|
|
104
139
|
value: function () {
|
|
105
140
|
var _fetchOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
106
141
|
var _this$appPlugin, _this$appPlugin$getDa;
|
|
107
|
-
var getData, shopId, tenantId, headers, response, data;
|
|
142
|
+
var fetchRevision, getData, shopId, tenantId, headers, response, data, resolvedInvoiceTemplate;
|
|
108
143
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
109
144
|
while (1) switch (_context2.prev = _context2.next) {
|
|
110
145
|
case 0:
|
|
146
|
+
fetchRevision = ++this.fetchRevision;
|
|
111
147
|
getData = (_this$appPlugin = this.appPlugin) === null || _this$appPlugin === void 0 || (_this$appPlugin$getDa = _this$appPlugin.getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
|
|
112
148
|
shopId = getData === null || getData === void 0 ? void 0 : getData('shop_id');
|
|
113
149
|
if (shopId) {
|
|
114
|
-
_context2.next =
|
|
150
|
+
_context2.next = 5;
|
|
115
151
|
break;
|
|
116
152
|
}
|
|
117
153
|
throw new Error('[OpenDataModule] 无法获取 shop_id');
|
|
118
|
-
case
|
|
154
|
+
case 5:
|
|
119
155
|
tenantId = getData === null || getData === void 0 ? void 0 : getData('tenant_id');
|
|
120
156
|
headers = {};
|
|
121
157
|
if (tenantId) headers['Tenant-Id'] = String(tenantId);
|
|
122
|
-
_context2.next =
|
|
158
|
+
_context2.next = 10;
|
|
123
159
|
return this.request.post("/open/my-pisell/".concat(shopId, "/setting"), {
|
|
124
160
|
scope: params.scope,
|
|
125
161
|
target: params.target,
|
|
@@ -130,19 +166,27 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
130
166
|
prefix: false,
|
|
131
167
|
headers: headers
|
|
132
168
|
});
|
|
133
|
-
case
|
|
169
|
+
case 10:
|
|
134
170
|
response = _context2.sent;
|
|
135
171
|
if (!((response === null || response === void 0 ? void 0 : response.status) === false)) {
|
|
136
|
-
_context2.next =
|
|
172
|
+
_context2.next = 13;
|
|
137
173
|
break;
|
|
138
174
|
}
|
|
139
175
|
throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取 OpenData 配置失败');
|
|
140
|
-
case
|
|
176
|
+
case 13:
|
|
141
177
|
data = (response === null || response === void 0 ? void 0 : response.data) || {};
|
|
142
|
-
|
|
143
|
-
this.
|
|
144
|
-
return _context2.abrupt("return", data);
|
|
178
|
+
_context2.next = 16;
|
|
179
|
+
return this.resolveInvoiceTemplateSettings(data, params.target);
|
|
145
180
|
case 16:
|
|
181
|
+
resolvedInvoiceTemplate = _context2.sent;
|
|
182
|
+
// clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
|
|
183
|
+
if (fetchRevision === this.fetchRevision) {
|
|
184
|
+
this.store.data = data;
|
|
185
|
+
this.store.lastFetchedAt = Date.now();
|
|
186
|
+
this.commitInvoiceTemplateSettings(params.target, resolvedInvoiceTemplate);
|
|
187
|
+
}
|
|
188
|
+
return _context2.abrupt("return", data);
|
|
189
|
+
case 19:
|
|
146
190
|
case "end":
|
|
147
191
|
return _context2.stop();
|
|
148
192
|
}
|
|
@@ -158,6 +202,242 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
158
202
|
value: function getOpenData() {
|
|
159
203
|
return this.store.data;
|
|
160
204
|
}
|
|
205
|
+
}, {
|
|
206
|
+
key: "getInvoiceLayoutConfig",
|
|
207
|
+
value: function getInvoiceLayoutConfig() {
|
|
208
|
+
return normalizeInvoiceLayoutFromTemplateSettings(this.getInvoiceTemplateSettings());
|
|
209
|
+
}
|
|
210
|
+
}, {
|
|
211
|
+
key: "getInvoiceTemplateSettings",
|
|
212
|
+
value: function getInvoiceTemplateSettings() {
|
|
213
|
+
var _this$store$data2;
|
|
214
|
+
if (this.shouldSkipInvoiceTemplateDocument()) {
|
|
215
|
+
return getDefaultInvoiceTemplateSettings();
|
|
216
|
+
}
|
|
217
|
+
if (isRecord(this.store.invoiceTemplateSettings)) {
|
|
218
|
+
var _this$store$data;
|
|
219
|
+
var documentId = resolveInvoiceDocumentId((_this$store$data = this.store.data) === null || _this$store$data === void 0 ? void 0 : _this$store$data['documents.invoice_template']);
|
|
220
|
+
if (documentId) {
|
|
221
|
+
var target = this.store.invoiceTemplateTarget;
|
|
222
|
+
if (!target || this.store.invoiceTemplateCacheKey !== this.buildInvoiceTemplateCacheKey(target, documentId)) {
|
|
223
|
+
return getDefaultInvoiceTemplateSettings();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return normalizeRawInvoiceTemplateSettings(this.store.invoiceTemplateSettings);
|
|
227
|
+
}
|
|
228
|
+
if (isLegacyInvoiceTemplate((_this$store$data2 = this.store.data) === null || _this$store$data2 === void 0 ? void 0 : _this$store$data2['documents.invoice_template'])) {
|
|
229
|
+
return normalizeInvoiceTemplateSettings(this.store.data);
|
|
230
|
+
}
|
|
231
|
+
return getDefaultInvoiceTemplateSettings();
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "ensureInvoiceTemplateSettings",
|
|
235
|
+
value: function () {
|
|
236
|
+
var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target) {
|
|
237
|
+
var normalizedTarget, config, fetchRevision, resolved;
|
|
238
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
239
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
240
|
+
case 0:
|
|
241
|
+
normalizedTarget = String(target || '').trim();
|
|
242
|
+
config = this.store.data;
|
|
243
|
+
if (!(!normalizedTarget || !config)) {
|
|
244
|
+
_context3.next = 4;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
248
|
+
case 4:
|
|
249
|
+
fetchRevision = this.fetchRevision;
|
|
250
|
+
_context3.next = 7;
|
|
251
|
+
return this.resolveInvoiceTemplateSettings(config, normalizedTarget);
|
|
252
|
+
case 7:
|
|
253
|
+
resolved = _context3.sent;
|
|
254
|
+
if (!(fetchRevision !== this.fetchRevision || this.store.data !== config)) {
|
|
255
|
+
_context3.next = 10;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
259
|
+
case 10:
|
|
260
|
+
this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
|
|
261
|
+
return _context3.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
|
|
262
|
+
case 12:
|
|
263
|
+
case "end":
|
|
264
|
+
return _context3.stop();
|
|
265
|
+
}
|
|
266
|
+
}, _callee3, this);
|
|
267
|
+
}));
|
|
268
|
+
function ensureInvoiceTemplateSettings(_x4) {
|
|
269
|
+
return _ensureInvoiceTemplateSettings.apply(this, arguments);
|
|
270
|
+
}
|
|
271
|
+
return ensureInvoiceTemplateSettings;
|
|
272
|
+
}()
|
|
273
|
+
}, {
|
|
274
|
+
key: "commitInvoiceTemplateSettings",
|
|
275
|
+
value: function commitInvoiceTemplateSettings(target, resolved) {
|
|
276
|
+
this.store.invoiceTemplateSettings = normalizeRawInvoiceTemplateSettings(resolved.settings);
|
|
277
|
+
this.store.invoiceTemplateTarget = target;
|
|
278
|
+
this.store.invoiceTemplateDocumentId = resolved.documentId;
|
|
279
|
+
this.store.invoiceTemplateCacheKey = resolved.cacheKey;
|
|
280
|
+
}
|
|
281
|
+
}, {
|
|
282
|
+
key: "resolveInvoiceTemplateSettings",
|
|
283
|
+
value: function () {
|
|
284
|
+
var _resolveInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config, target) {
|
|
285
|
+
var _this2 = this;
|
|
286
|
+
var rawTemplate, documentId, cacheKey, cachedSettings, request, cacheRevision;
|
|
287
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
288
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
289
|
+
case 0:
|
|
290
|
+
if (!this.shouldSkipInvoiceTemplateDocument()) {
|
|
291
|
+
_context4.next = 2;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
return _context4.abrupt("return", {
|
|
295
|
+
settings: getDefaultInvoiceTemplateSettings(),
|
|
296
|
+
documentId: null,
|
|
297
|
+
cacheKey: null
|
|
298
|
+
});
|
|
299
|
+
case 2:
|
|
300
|
+
rawTemplate = config['documents.invoice_template'];
|
|
301
|
+
documentId = resolveInvoiceDocumentId(rawTemplate);
|
|
302
|
+
if (documentId) {
|
|
303
|
+
_context4.next = 6;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
return _context4.abrupt("return", {
|
|
307
|
+
settings: isLegacyInvoiceTemplate(rawTemplate) ? normalizeInvoiceTemplateSettings(config) : getDefaultInvoiceTemplateSettings(),
|
|
308
|
+
documentId: null,
|
|
309
|
+
cacheKey: null
|
|
310
|
+
});
|
|
311
|
+
case 6:
|
|
312
|
+
cacheKey = this.buildInvoiceTemplateCacheKey(target, documentId);
|
|
313
|
+
if (!(this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings))) {
|
|
314
|
+
_context4.next = 9;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
return _context4.abrupt("return", {
|
|
318
|
+
settings: normalizeRawInvoiceTemplateSettings(this.store.invoiceTemplateSettings),
|
|
319
|
+
documentId: documentId,
|
|
320
|
+
cacheKey: cacheKey
|
|
321
|
+
});
|
|
322
|
+
case 9:
|
|
323
|
+
cachedSettings = this.invoiceTemplateDocumentCache.get(cacheKey);
|
|
324
|
+
if (!cachedSettings) {
|
|
325
|
+
_context4.next = 12;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
return _context4.abrupt("return", {
|
|
329
|
+
settings: normalizeRawInvoiceTemplateSettings(cachedSettings),
|
|
330
|
+
documentId: documentId,
|
|
331
|
+
cacheKey: cacheKey
|
|
332
|
+
});
|
|
333
|
+
case 12:
|
|
334
|
+
request = this.invoiceTemplateDocumentInFlight.get(cacheKey);
|
|
335
|
+
if (!request) {
|
|
336
|
+
cacheRevision = this.invoiceTemplateCacheRevision;
|
|
337
|
+
request = this.fetchInvoiceTemplateDocument(documentId).catch(function (error) {
|
|
338
|
+
_this2.logInvoiceTemplateDocumentFallback(error, target, documentId);
|
|
339
|
+
return getDefaultInvoiceTemplateSettings();
|
|
340
|
+
}).then(function (settings) {
|
|
341
|
+
var normalized = normalizeRawInvoiceTemplateSettings(settings);
|
|
342
|
+
if (cacheRevision === _this2.invoiceTemplateCacheRevision) {
|
|
343
|
+
_this2.invoiceTemplateDocumentCache.set(cacheKey, normalized);
|
|
344
|
+
}
|
|
345
|
+
return normalized;
|
|
346
|
+
}).finally(function () {
|
|
347
|
+
if (_this2.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
|
|
348
|
+
_this2.invoiceTemplateDocumentInFlight.delete(cacheKey);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
this.invoiceTemplateDocumentInFlight.set(cacheKey, request);
|
|
352
|
+
}
|
|
353
|
+
_context4.next = 16;
|
|
354
|
+
return request;
|
|
355
|
+
case 16:
|
|
356
|
+
_context4.t0 = _context4.sent;
|
|
357
|
+
_context4.t1 = documentId;
|
|
358
|
+
_context4.t2 = cacheKey;
|
|
359
|
+
return _context4.abrupt("return", {
|
|
360
|
+
settings: _context4.t0,
|
|
361
|
+
documentId: _context4.t1,
|
|
362
|
+
cacheKey: _context4.t2
|
|
363
|
+
});
|
|
364
|
+
case 20:
|
|
365
|
+
case "end":
|
|
366
|
+
return _context4.stop();
|
|
367
|
+
}
|
|
368
|
+
}, _callee4, this);
|
|
369
|
+
}));
|
|
370
|
+
function resolveInvoiceTemplateSettings(_x5, _x6) {
|
|
371
|
+
return _resolveInvoiceTemplateSettings.apply(this, arguments);
|
|
372
|
+
}
|
|
373
|
+
return resolveInvoiceTemplateSettings;
|
|
374
|
+
}()
|
|
375
|
+
}, {
|
|
376
|
+
key: "buildInvoiceTemplateCacheKey",
|
|
377
|
+
value: function buildInvoiceTemplateCacheKey(target, documentId) {
|
|
378
|
+
var _this$appPlugin2, _this$appPlugin2$getD, _getData, _getData2;
|
|
379
|
+
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);
|
|
380
|
+
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]);
|
|
381
|
+
}
|
|
382
|
+
}, {
|
|
383
|
+
key: "fetchInvoiceTemplateDocument",
|
|
384
|
+
value: function () {
|
|
385
|
+
var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(documentId) {
|
|
386
|
+
var response, document;
|
|
387
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
388
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
389
|
+
case 0:
|
|
390
|
+
_context5.next = 2;
|
|
391
|
+
return this.request.get("/document:get?filterByTk=".concat(encodeURIComponent(documentId)), {}, {
|
|
392
|
+
isNocobase: true,
|
|
393
|
+
prefix: false,
|
|
394
|
+
headers: {
|
|
395
|
+
'x-data-source': 'pisell2'
|
|
396
|
+
},
|
|
397
|
+
customToast: function customToast() {}
|
|
398
|
+
});
|
|
399
|
+
case 2:
|
|
400
|
+
response = _context5.sent;
|
|
401
|
+
document = response === null || response === void 0 ? void 0 : response.data;
|
|
402
|
+
if (!(!document || resolveInvoiceDocumentId(document.id) !== documentId)) {
|
|
403
|
+
_context5.next = 6;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
throw new Error("Invoice Document ".concat(documentId, " \u8FD4\u56DE\u7684 ID \u4E0D\u5339\u914D"));
|
|
407
|
+
case 6:
|
|
408
|
+
if (!(document.deleted_at !== null && document.deleted_at !== undefined)) {
|
|
409
|
+
_context5.next = 8;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
throw new Error("Invoice Document ".concat(documentId, " \u5DF2\u88AB\u5220\u9664"));
|
|
413
|
+
case 8:
|
|
414
|
+
if (!(!isRecord(document.data) || !isRecord(document.data.template_settings))) {
|
|
415
|
+
_context5.next = 10;
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
throw new Error("Invoice Document ".concat(documentId, " \u7F3A\u5C11 template_settings"));
|
|
419
|
+
case 10:
|
|
420
|
+
return _context5.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
|
|
421
|
+
case 11:
|
|
422
|
+
case "end":
|
|
423
|
+
return _context5.stop();
|
|
424
|
+
}
|
|
425
|
+
}, _callee5, this);
|
|
426
|
+
}));
|
|
427
|
+
function fetchInvoiceTemplateDocument(_x7) {
|
|
428
|
+
return _fetchInvoiceTemplateDocument.apply(this, arguments);
|
|
429
|
+
}
|
|
430
|
+
return fetchInvoiceTemplateDocument;
|
|
431
|
+
}()
|
|
432
|
+
}, {
|
|
433
|
+
key: "logInvoiceTemplateDocumentFallback",
|
|
434
|
+
value: function logInvoiceTemplateDocumentFallback(error, target, documentId) {
|
|
435
|
+
console.warn('[OpenDataModule] Invoice Document 加载失败,使用 DEFAULT', {
|
|
436
|
+
target: target,
|
|
437
|
+
documentId: documentId,
|
|
438
|
+
message: error instanceof Error ? error.message : String(error)
|
|
439
|
+
});
|
|
440
|
+
}
|
|
161
441
|
}, {
|
|
162
442
|
key: "getLastFetchedAt",
|
|
163
443
|
value: function getLastFetchedAt() {
|
|
@@ -169,14 +449,22 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
169
449
|
}, {
|
|
170
450
|
key: "clearCache",
|
|
171
451
|
value: function clearCache() {
|
|
452
|
+
this.fetchRevision += 1;
|
|
453
|
+
this.invoiceTemplateCacheRevision += 1;
|
|
454
|
+
this.invoiceTemplateDocumentCache.clear();
|
|
455
|
+
this.invoiceTemplateDocumentInFlight.clear();
|
|
172
456
|
this.store.data = null;
|
|
173
457
|
this.store.lastFetchedAt = null;
|
|
458
|
+
this.store.invoiceTemplateSettings = null;
|
|
459
|
+
this.store.invoiceTemplateTarget = null;
|
|
460
|
+
this.store.invoiceTemplateDocumentId = null;
|
|
461
|
+
this.store.invoiceTemplateCacheKey = null;
|
|
174
462
|
}
|
|
175
463
|
}, {
|
|
176
464
|
key: "checkAvailability",
|
|
177
465
|
value: function checkAvailability(scheduleModule) {
|
|
178
|
-
var _this$store$
|
|
179
|
-
var scheduleList = scheduleModule ? scheduleModule === null || scheduleModule === void 0 ? void 0 : scheduleModule.getScheduleListByIds(((_this$store$
|
|
466
|
+
var _this$store$data3;
|
|
467
|
+
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;
|
|
180
468
|
return computeAvailability({
|
|
181
469
|
config: this.store.data,
|
|
182
470
|
scheduleList: scheduleList
|