@pisell/pisellos 0.0.214 → 0.0.216

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.
Files changed (82) hide show
  1. package/dist/core/index.js +2 -1
  2. package/dist/effects/index.d.ts +4 -3
  3. package/dist/effects/index.js +15 -6
  4. package/dist/modules/AccountList/index.d.ts +7 -1
  5. package/dist/modules/AccountList/index.js +81 -14
  6. package/dist/modules/AccountList/types.d.ts +28 -0
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/Customer/constants.d.ts +7 -0
  9. package/dist/modules/Customer/constants.js +12 -0
  10. package/dist/modules/Customer/index.d.ts +89 -0
  11. package/dist/modules/Customer/index.js +440 -0
  12. package/dist/modules/Customer/types.d.ts +130 -0
  13. package/dist/modules/Customer/types.js +39 -0
  14. package/dist/modules/ProductList/index.d.ts +12 -1
  15. package/dist/modules/ProductList/index.js +28 -4
  16. package/dist/modules/Rules/index.js +7 -5
  17. package/dist/modules/Rules/types.d.ts +1 -0
  18. package/dist/modules/index.d.ts +1 -0
  19. package/dist/modules/index.js +1 -0
  20. package/dist/plugins/window.d.ts +1 -0
  21. package/dist/solution/BookingByStep/index.js +8 -15
  22. package/dist/solution/BookingTicket/index.d.ts +134 -0
  23. package/dist/solution/BookingTicket/index.js +534 -0
  24. package/dist/solution/BookingTicket/types.d.ts +66 -0
  25. package/dist/solution/BookingTicket/types.js +41 -0
  26. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  27. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
  28. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +19 -0
  29. package/dist/solution/BookingTicket/utils/scan/handleScan.js +182 -0
  30. package/dist/solution/BookingTicket/utils/scan/index.d.ts +59 -0
  31. package/dist/solution/BookingTicket/utils/scan/index.js +201 -0
  32. package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  33. package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
  34. package/dist/solution/ShopDiscount/index.js +4 -2
  35. package/dist/solution/index.d.ts +1 -0
  36. package/dist/solution/index.js +1 -0
  37. package/dist/types/index.d.ts +3 -1
  38. package/dist/utils/task.d.ts +31 -0
  39. package/dist/utils/task.js +150 -0
  40. package/dist/utils/watch.d.ts +102 -0
  41. package/dist/utils/watch.js +294 -0
  42. package/lib/core/index.js +1 -1
  43. package/lib/effects/index.d.ts +4 -3
  44. package/lib/effects/index.js +4 -1
  45. package/lib/modules/AccountList/index.d.ts +7 -1
  46. package/lib/modules/AccountList/index.js +27 -0
  47. package/lib/modules/AccountList/types.d.ts +28 -0
  48. package/lib/modules/Customer/constants.d.ts +7 -0
  49. package/lib/modules/Customer/constants.js +39 -0
  50. package/lib/modules/Customer/index.d.ts +89 -0
  51. package/lib/modules/Customer/index.js +305 -0
  52. package/lib/modules/Customer/types.d.ts +130 -0
  53. package/lib/modules/Customer/types.js +35 -0
  54. package/lib/modules/ProductList/index.d.ts +12 -1
  55. package/lib/modules/ProductList/index.js +30 -3
  56. package/lib/modules/Rules/index.js +4 -3
  57. package/lib/modules/Rules/types.d.ts +1 -0
  58. package/lib/modules/index.d.ts +1 -0
  59. package/lib/modules/index.js +2 -0
  60. package/lib/plugins/window.d.ts +1 -0
  61. package/lib/solution/BookingByStep/index.js +0 -7
  62. package/lib/solution/BookingTicket/index.d.ts +134 -0
  63. package/lib/solution/BookingTicket/index.js +331 -0
  64. package/lib/solution/BookingTicket/types.d.ts +66 -0
  65. package/lib/solution/BookingTicket/types.js +70 -0
  66. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  67. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
  68. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +19 -0
  69. package/lib/solution/BookingTicket/utils/scan/handleScan.js +137 -0
  70. package/lib/solution/BookingTicket/utils/scan/index.d.ts +59 -0
  71. package/lib/solution/BookingTicket/utils/scan/index.js +149 -0
  72. package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  73. package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
  74. package/lib/solution/ShopDiscount/index.js +2 -1
  75. package/lib/solution/index.d.ts +1 -0
  76. package/lib/solution/index.js +2 -0
  77. package/lib/types/index.d.ts +3 -1
  78. package/lib/utils/task.d.ts +31 -0
  79. package/lib/utils/task.js +84 -0
  80. package/lib/utils/watch.d.ts +102 -0
  81. package/lib/utils/watch.js +217 -0
  82. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/solution/BookingTicket/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ BookingTicketHooks: () => BookingTicketHooks,
23
+ createModule: () => createModule
24
+ });
25
+ module.exports = __toCommonJS(types_exports);
26
+ var import_modules = require("../../modules");
27
+ var import_Customer = require("../../modules/Customer");
28
+ function createModule(moduleName, solutionName, name, version) {
29
+ switch (moduleName) {
30
+ case "cart":
31
+ return new import_modules.CartModule(
32
+ `${solutionName}_${name || moduleName}`,
33
+ version
34
+ );
35
+ case "products":
36
+ return new import_modules.ProductList(
37
+ `${solutionName}_${name || moduleName}`,
38
+ version
39
+ );
40
+ case "accountList":
41
+ return new import_modules.AccountListModule(
42
+ `${solutionName}_${name || moduleName}`,
43
+ version
44
+ );
45
+ case "customer":
46
+ return new import_Customer.CustomerModule(
47
+ `${solutionName}_${name || moduleName}`,
48
+ version
49
+ );
50
+ case "order":
51
+ return new import_modules.OrderModule(
52
+ `${solutionName}_${name || moduleName}`,
53
+ version
54
+ );
55
+ default:
56
+ throw new Error(`Unknown module type: ${moduleName}`);
57
+ }
58
+ }
59
+ var BookingTicketHooks = /* @__PURE__ */ ((BookingTicketHooks2) => {
60
+ BookingTicketHooks2["onInited"] = "bookingTicket:onInited";
61
+ BookingTicketHooks2["onDestroy"] = "bookingTicket:onDestroy";
62
+ BookingTicketHooks2["onProductsLoaded"] = "bookingTicket:onProductsLoaded";
63
+ BookingTicketHooks2["onCustomerSelected"] = "bookingTicket:onCustomerSelected";
64
+ return BookingTicketHooks2;
65
+ })(BookingTicketHooks || {});
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ BookingTicketHooks,
69
+ createModule
70
+ });
@@ -0,0 +1,22 @@
1
+ import { RequestPlugin } from '../../../../plugins';
2
+ /**
3
+ * 搜索通用识别码
4
+ */
5
+ export declare const searchWalletPass: (request: RequestPlugin, code: string) => Promise<{
6
+ searchType: string;
7
+ response: any;
8
+ }>;
9
+ /**
10
+ * 搜索钱包
11
+ */
12
+ export declare const searchWallet: (request: RequestPlugin, code: string) => Promise<{
13
+ searchType: string;
14
+ response: any;
15
+ }>;
16
+ /**
17
+ * 搜索商品
18
+ */
19
+ export declare const searchProduct: (request: RequestPlugin, code: string) => Promise<{
20
+ searchType: string;
21
+ response: any;
22
+ }>;
@@ -0,0 +1,117 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/solution/BookingTicket/utils/scan/cloudSearch.ts
20
+ var cloudSearch_exports = {};
21
+ __export(cloudSearch_exports, {
22
+ searchProduct: () => searchProduct,
23
+ searchWallet: () => searchWallet,
24
+ searchWalletPass: () => searchWalletPass
25
+ });
26
+ module.exports = __toCommonJS(cloudSearch_exports);
27
+ var searchWalletPass = async (request, code) => {
28
+ const params = {
29
+ code,
30
+ translate_flag: 1,
31
+ // 翻译识别码名称 0:不翻译 1:翻译
32
+ relation_product: 1,
33
+ // 组装关联商品: 0不处理 1处理
34
+ with: ["customer"],
35
+ tags: [
36
+ "point_card",
37
+ // 积分卡
38
+ "gift_card",
39
+ // 充值卡
40
+ "product_voucher",
41
+ // 代金券
42
+ "product_discount_card",
43
+ // 折扣卡
44
+ "good_pass",
45
+ // 商品券
46
+ "session_ticket",
47
+ // 场次票
48
+ "appointment_ticket"
49
+ // 预约类门票
50
+ ]
51
+ };
52
+ try {
53
+ const res = await (request == null ? void 0 : request.get(
54
+ "/machinecode/batch-search",
55
+ params
56
+ ));
57
+ if ((res == null ? void 0 : res.code) == 200 && !!(res == null ? void 0 : res.data)) {
58
+ return { searchType: "walletPass", response: res };
59
+ }
60
+ throw new Error("没有找到对应的识别码");
61
+ } catch (error) {
62
+ throw error;
63
+ }
64
+ };
65
+ var searchWallet = async (request, code) => {
66
+ const params = { code, with_customer: 1 };
67
+ try {
68
+ const res = await (request == null ? void 0 : request.post(
69
+ "/wallet/detail/search",
70
+ params
71
+ ));
72
+ if ((res == null ? void 0 : res.code) == 200 && !!(res == null ? void 0 : res.data)) {
73
+ return { searchType: "wallet", response: res };
74
+ }
75
+ throw new Error("没有找到对应的识别码");
76
+ } catch (error) {
77
+ throw error;
78
+ }
79
+ };
80
+ var searchProduct = async (request, code) => {
81
+ var _a, _b;
82
+ const params = {
83
+ exact_search: code,
84
+ open_bundle: 0,
85
+ // 套餐子信息
86
+ open_quotation: 1,
87
+ // 报价单
88
+ skip: 1,
89
+ num: 20,
90
+ status: "published",
91
+ with: ["variantGroup"],
92
+ with_count: ["bundleGroup", "optionGroup"],
93
+ exclude_extension_type: [
94
+ "product_party",
95
+ "product_event",
96
+ "product_series_event",
97
+ "product_package_ticket",
98
+ "ticket",
99
+ "event_item"
100
+ ]
101
+ };
102
+ try {
103
+ const res = await (request == null ? void 0 : request.post("/product/query", params));
104
+ if ((res == null ? void 0 : res.code) == 200 && ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) > 0) {
105
+ return { searchType: "product", response: res };
106
+ }
107
+ throw new Error("没有找到对应的识别码");
108
+ } catch (error) {
109
+ throw error;
110
+ }
111
+ };
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ searchProduct,
115
+ searchWallet,
116
+ searchWalletPass
117
+ });
@@ -0,0 +1,19 @@
1
+ import { RequestPlugin } from '../../../../plugins';
2
+ /**
3
+ * 处理全局扫码
4
+ * @param request 请求插件
5
+ * @returns 处理结果
6
+ */
7
+ export declare const handleGlobalScan: (request: RequestPlugin, localSearch: (v: string) => any[]) => (scanResult: {
8
+ type: string;
9
+ value: string;
10
+ }) => Promise<any>;
11
+ /**
12
+ * 处理客户扫码
13
+ * @param request 请求插件
14
+ * @returns 处理结果
15
+ */
16
+ export declare const handleCustomerScan: (request: RequestPlugin, localSearch: (v: string) => any[]) => (scanResult: {
17
+ type: string;
18
+ value: string;
19
+ }) => Promise<any>;
@@ -0,0 +1,137 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/BookingTicket/utils/scan/handleScan.ts
30
+ var handleScan_exports = {};
31
+ __export(handleScan_exports, {
32
+ handleCustomerScan: () => handleCustomerScan,
33
+ handleGlobalScan: () => handleGlobalScan
34
+ });
35
+ module.exports = __toCommonJS(handleScan_exports);
36
+ var import_cloudSearch = require("./cloudSearch");
37
+ var import_scanCache = __toESM(require("./scanCache"));
38
+ var promiseAny = async (promises) => {
39
+ if (promises.length === 0) {
40
+ throw new Error("No promises provided");
41
+ }
42
+ const errors = [];
43
+ let completedCount = 0;
44
+ return new Promise((resolve, reject) => {
45
+ promises.forEach((promise, index) => {
46
+ promise.then((result) => {
47
+ resolve(result);
48
+ }).catch((error) => {
49
+ errors[index] = error;
50
+ completedCount++;
51
+ if (completedCount === promises.length) {
52
+ const errorMessage = `All promises were rejected. Errors: ${errors.map((e) => e.message).join(", ")}`;
53
+ const combinedError = new Error(errorMessage);
54
+ combinedError.errors = errors;
55
+ reject(combinedError);
56
+ }
57
+ });
58
+ });
59
+ });
60
+ };
61
+ var handleScanFn = (getRequestList, localSearch) => {
62
+ return async (scanResult) => {
63
+ const { value } = scanResult || {};
64
+ try {
65
+ const localResult = localSearch == null ? void 0 : localSearch(value);
66
+ if ((localResult == null ? void 0 : localResult.length) > 0) {
67
+ console.log("本地搜索到数据>>>>>>>", localResult);
68
+ return {
69
+ searchType: "local_product",
70
+ response: { data: { list: localResult } }
71
+ };
72
+ } else {
73
+ console.log("本地搜索无数据>>>>>>>");
74
+ }
75
+ } catch (error) {
76
+ console.error("本地搜索到数据失败>>>>>>>", error);
77
+ }
78
+ try {
79
+ if (import_scanCache.default.has(value)) {
80
+ const result = import_scanCache.default.get(value);
81
+ console.log("缓存中搜索到数据>>>>>>>", result);
82
+ return result;
83
+ } else {
84
+ console.log("缓存中无数据>>>>>>>");
85
+ }
86
+ } catch (error) {
87
+ console.error("缓存中搜索数据失败>>>>>>>", error);
88
+ }
89
+ const requestList = (getRequestList == null ? void 0 : getRequestList(value)) || [];
90
+ if (requestList.length === 0) {
91
+ throw new Error("requestList is empty");
92
+ }
93
+ try {
94
+ const result = await promiseAny(requestList);
95
+ import_scanCache.default.set(value, result);
96
+ return result;
97
+ } catch (error) {
98
+ throw error;
99
+ }
100
+ };
101
+ };
102
+ var handleGlobalScan = (request, localSearch) => {
103
+ const getRequestList = (value) => {
104
+ let requestList = [];
105
+ if (value.startsWith("WL")) {
106
+ requestList = [(0, import_cloudSearch.searchWallet)(request, value)];
107
+ } else {
108
+ requestList = [
109
+ (0, import_cloudSearch.searchWalletPass)(request, value),
110
+ (0, import_cloudSearch.searchWallet)(request, value),
111
+ (0, import_cloudSearch.searchProduct)(request, value)
112
+ ];
113
+ }
114
+ return requestList;
115
+ };
116
+ return handleScanFn(getRequestList, localSearch);
117
+ };
118
+ var handleCustomerScan = (request, localSearch) => {
119
+ const getRequestList = (value) => {
120
+ let requestList = [];
121
+ if (value.startsWith("WL")) {
122
+ requestList = [(0, import_cloudSearch.searchWallet)(request, value)];
123
+ } else {
124
+ requestList = [
125
+ (0, import_cloudSearch.searchWalletPass)(request, value),
126
+ (0, import_cloudSearch.searchWallet)(request, value)
127
+ ];
128
+ }
129
+ return requestList;
130
+ };
131
+ return handleScanFn(getRequestList, localSearch);
132
+ };
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ handleCustomerScan,
136
+ handleGlobalScan
137
+ });
@@ -0,0 +1,59 @@
1
+ import { WatchEventItem } from '../../../../utils/watch';
2
+ import { BookingTicketImpl } from '../../index';
3
+ import Tasks from '../../../../utils/task';
4
+ interface ScanResult {
5
+ type: ScanResultType;
6
+ value: string;
7
+ data?: {
8
+ [key: string]: any;
9
+ };
10
+ }
11
+ declare enum ScanResultType {
12
+ Scanner = "scanner",
13
+ NFC = "nfc",
14
+ NativeScanner = "nativeScanner"
15
+ }
16
+ export default class Scan {
17
+ private solution;
18
+ private watchKey;
19
+ private listenerConfig;
20
+ constructor(solution: BookingTicketImpl, watchKey: string);
21
+ /**
22
+ * 添加扫码信息监听
23
+ * @param watchKey 监听的key
24
+ * @param event 事件
25
+ */
26
+ addListener(event: WatchEventItem, scanCallback?: (result: ScanResult) => Promise<any>): {
27
+ remove: () => void;
28
+ };
29
+ /**
30
+ * 移除扫码信息监听
31
+ * @param watchKey 监听的key
32
+ * @param event 事件
33
+ */
34
+ removeListener(event: WatchEventItem): void;
35
+ /**
36
+ * 处理扫码事件
37
+ * @param eventKey 事件key
38
+ * @param value 扫码结果
39
+ */
40
+ handleScan(value: {
41
+ type: string;
42
+ value: string;
43
+ }): void;
44
+ /**
45
+ * 获取监听配置
46
+ * @param eventKey 事件key
47
+ * @returns 监听配置
48
+ */
49
+ getListenerConfig(eventKey: string): {
50
+ scanCallback?: ((result: ScanResult) => Promise<any>) | undefined;
51
+ task: Tasks;
52
+ } | undefined;
53
+ /**
54
+ * 处理扫码结果
55
+ * @param args 参数
56
+ */
57
+ handleScanResultFn(...args: any[]): Promise<void>;
58
+ }
59
+ export {};
@@ -0,0 +1,149 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/BookingTicket/utils/scan/index.ts
30
+ var scan_exports = {};
31
+ __export(scan_exports, {
32
+ default: () => Scan
33
+ });
34
+ module.exports = __toCommonJS(scan_exports);
35
+ var import_watch = __toESM(require("../../../../utils/watch"));
36
+ var import_task = __toESM(require("../../../../utils/task"));
37
+ var Scan = class {
38
+ constructor(solution, watchKey) {
39
+ this.listenerConfig = /* @__PURE__ */ new Map();
40
+ var _a, _b, _c, _d, _e;
41
+ this.solution = solution;
42
+ this.watchKey = watchKey;
43
+ (_e = (_d = (_c = (_b = (_a = this.solution) == null ? void 0 : _a.window) == null ? void 0 : _b.interaction) == null ? void 0 : _c.utils) == null ? void 0 : _d.mountFunction) == null ? void 0 : _e.call(
44
+ _d,
45
+ "global",
46
+ "peripheralsResult",
47
+ (strVal) => {
48
+ try {
49
+ const result = JSON.parse(strVal);
50
+ console.log("nativeScannerResult>>>>>>>", result);
51
+ this.handleScan(result);
52
+ } catch (err) {
53
+ console.error(err);
54
+ }
55
+ }
56
+ );
57
+ }
58
+ /**
59
+ * 添加扫码信息监听
60
+ * @param watchKey 监听的key
61
+ * @param event 事件
62
+ */
63
+ addListener(event, scanCallback) {
64
+ import_watch.default.subscribe(this.watchKey, event);
65
+ const task = new import_task.default();
66
+ task.addAction(
67
+ event.key,
68
+ (...args) => this.handleScanResultFn(event.key, ...args)
69
+ );
70
+ this.listenerConfig.set(event.key, { scanCallback, task });
71
+ return {
72
+ remove: () => {
73
+ this.removeListener(event);
74
+ }
75
+ };
76
+ }
77
+ /**
78
+ * 移除扫码信息监听
79
+ * @param watchKey 监听的key
80
+ * @param event 事件
81
+ */
82
+ removeListener(event) {
83
+ var _a;
84
+ import_watch.default.unsubscribe(this.watchKey, event);
85
+ (_a = this.listenerConfig.get(event.key)) == null ? void 0 : _a.task.clear();
86
+ this.listenerConfig.delete(event.key);
87
+ }
88
+ /**
89
+ * 处理扫码事件
90
+ * @param eventKey 事件key
91
+ * @param value 扫码结果
92
+ */
93
+ handleScan(value) {
94
+ const lastEnableEventKey = import_watch.default.getLastEnableEventKey(this.watchKey);
95
+ if (lastEnableEventKey) {
96
+ const listenerConfig = this.listenerConfig.get(lastEnableEventKey);
97
+ if (listenerConfig) {
98
+ listenerConfig.task.addTask({
99
+ type: lastEnableEventKey,
100
+ actionParams: {
101
+ scanResult: value
102
+ }
103
+ });
104
+ }
105
+ }
106
+ }
107
+ /**
108
+ * 获取监听配置
109
+ * @param eventKey 事件key
110
+ * @returns 监听配置
111
+ */
112
+ getListenerConfig(eventKey) {
113
+ var _a;
114
+ return (_a = this.listenerConfig) == null ? void 0 : _a.get(eventKey);
115
+ }
116
+ /**
117
+ * 处理扫码结果
118
+ * @param args 参数
119
+ */
120
+ async handleScanResultFn(...args) {
121
+ var _a;
122
+ const [eventKey, other] = args;
123
+ const { type, value, data } = (other == null ? void 0 : other.scanResult) || {};
124
+ const scanCallback = (_a = this.getListenerConfig(eventKey)) == null ? void 0 : _a.scanCallback;
125
+ if (scanCallback) {
126
+ try {
127
+ const result = await scanCallback({ type, value });
128
+ console.log(`${eventKey}_result>>>>>>>`, result);
129
+ import_watch.default.publishByEventKey(this.watchKey, eventKey, {
130
+ type: eventKey,
131
+ status: "success",
132
+ scanType: type,
133
+ scanCode: value,
134
+ scanData: data,
135
+ result
136
+ });
137
+ } catch (error) {
138
+ console.log(`${eventKey}_result_error>>>>>>>`, error);
139
+ import_watch.default.publishByEventKey(this.watchKey, eventKey, {
140
+ type: eventKey,
141
+ status: "failed",
142
+ scanType: type,
143
+ scanCode: value,
144
+ scanData: data
145
+ });
146
+ }
147
+ }
148
+ }
149
+ };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * LRU缓存类,用于缓存接口数据
3
+ * 限制最多存储100条数据,超过时移除最久未使用的数据
4
+ * 支持数据压缩以减小缓存压力
5
+ * 尾部优先策略:新节点插入尾部,最近使用的节点移动到尾部,删除头部节点
6
+ */
7
+ declare class LRUCache<T> {
8
+ private head;
9
+ private tail;
10
+ private keyMap;
11
+ private readonly maxSize;
12
+ constructor(maxSize?: number);
13
+ /**
14
+ * 将节点移动到链表尾部(最近使用)
15
+ * @param node 要移动的节点
16
+ */
17
+ private moveToTail;
18
+ /**
19
+ * 添加新节点到链表尾部
20
+ * @param key 缓存键
21
+ * @param compressedData 压缩后的数据
22
+ * @param timestamp 时间戳
23
+ */
24
+ private addToTail;
25
+ /**
26
+ * 从链表中移除节点
27
+ * @param node 要移除的节点
28
+ */
29
+ private removeNode;
30
+ /**
31
+ * 移除最久未使用的节点(链表头部)
32
+ */
33
+ private removeOldest;
34
+ /**
35
+ * 设置缓存
36
+ * @param key 缓存键
37
+ * @param data 缓存数据
38
+ */
39
+ set(key: string, data: T): void;
40
+ /**
41
+ * 获取缓存
42
+ * @param key 缓存键
43
+ * @returns 缓存数据或undefined
44
+ */
45
+ get(key: string): T | undefined;
46
+ /**
47
+ * 检查是否存在缓存
48
+ * @param key 缓存键
49
+ * @returns 是否存在
50
+ */
51
+ has(key: string): boolean;
52
+ /**
53
+ * 清除所有缓存
54
+ */
55
+ clear(): void;
56
+ /**
57
+ * 获取缓存大小
58
+ * @returns 当前缓存数量
59
+ */
60
+ size(): number;
61
+ /**
62
+ * 获取缓存统计信息
63
+ * @returns 缓存统计信息
64
+ */
65
+ getStats(): {
66
+ size: number;
67
+ maxSize: number;
68
+ usage: number;
69
+ };
70
+ /**
71
+ * 删除指定的缓存项
72
+ * @param key 要删除的缓存键
73
+ * @returns 是否删除成功
74
+ */
75
+ delete(key: string): boolean;
76
+ }
77
+ declare const scanCache: LRUCache<any>;
78
+ export default scanCache;