@pisell/pisellos 0.0.215 → 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.
@@ -155,6 +155,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
155
155
  num: num,
156
156
  sort_by: SORT_BY,
157
157
  with: ['latestWalletDetail.wallet'],
158
+ search_wallet_flag: 1,
158
159
  search_wallet_pass_flag: 1
159
160
  }, search && {
160
161
  search: search
@@ -33,4 +33,10 @@ export declare class ProductList extends BaseModule implements Module {
33
33
  getProduct(id: number): Promise<Product | undefined>;
34
34
  addProduct(products: ProductData[]): Promise<void>;
35
35
  selectProducts(products: ProductData[]): Promise<void>;
36
+ /**
37
+ * 根据商品编码或条码搜索商品
38
+ * @param code 商品编码或条码
39
+ * @returns 匹配的商品列表,如果没有匹配则返回空数组
40
+ */
41
+ findProductsByCodeOrBarcode(code: string): ProductData[];
36
42
  }
@@ -301,6 +301,26 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
301
301
  }
302
302
  return selectProducts;
303
303
  }()
304
+ /**
305
+ * 根据商品编码或条码搜索商品
306
+ * @param code 商品编码或条码
307
+ * @returns 匹配的商品列表,如果没有匹配则返回空数组
308
+ */
309
+ }, {
310
+ key: "findProductsByCodeOrBarcode",
311
+ value: function findProductsByCodeOrBarcode(code) {
312
+ if (!code || typeof code !== 'string') {
313
+ return [];
314
+ }
315
+ var trimmedCode = code.trim();
316
+ if (!trimmedCode) {
317
+ return [];
318
+ }
319
+ var matchingProducts = this.store.list.filter(function (product) {
320
+ return product.code && product.code.trim() === trimmedCode || product.barcode && product.barcode.trim() === trimmedCode;
321
+ });
322
+ return cloneDeep(matchingProducts);
323
+ }
304
324
  }]);
305
325
  return ProductList;
306
326
  }(BaseModule);
@@ -105,6 +105,13 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
105
105
  scanCustomerListener(callback: (data: IScanResult) => void): {
106
106
  remove: () => void;
107
107
  };
108
+ /**
109
+ * 调用摄像头
110
+ * @param data 用户自定义数据
111
+ */
112
+ activateCamera(data?: {
113
+ [key: string]: any;
114
+ }): void;
108
115
  /**
109
116
  * 设置其他参数
110
117
  * @param params 参数
@@ -19,8 +19,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
19
19
  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); }
20
20
  import { BaseModule } from "../../modules/BaseModule";
21
21
  import { BookingTicketHooks, createModule } from "./types";
22
- import { Scan } from "./utils/scan/index";
22
+ import Scan from "./utils/scan";
23
23
  import { handleGlobalScan, handleCustomerScan } from "./utils/scan/handleScan";
24
+ import scanCache from "./utils/scan/scanCache";
24
25
  export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) {
25
26
  _inherits(BookingTicketImpl, _BaseModule);
26
27
  var _super = _createSuper(BookingTicketImpl);
@@ -387,12 +388,23 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) {
387
388
  }, {
388
389
  key: "scanGlobalListener",
389
390
  value: function scanGlobalListener(callback) {
390
- var listenerCallback = handleGlobalScan(this.request);
391
+ var _this3 = this;
392
+ var localSearch = function localSearch(v) {
393
+ return _this3.store.products.findProductsByCodeOrBarcode(v);
394
+ };
395
+ var scanCallback = handleGlobalScan(this.request, localSearch);
396
+ var safeCallback = function safeCallback(d) {
397
+ try {
398
+ callback(d);
399
+ } catch (error) {
400
+ console.error('scanGlobalListener回掉函数异常', error);
401
+ }
402
+ };
391
403
  var listener = {
392
404
  key: 'global',
393
- callback: callback
405
+ callback: safeCallback
394
406
  };
395
- var removeListener = this.scan.addListener(listener, listenerCallback);
407
+ var removeListener = this.scan.addListener(listener, scanCallback);
396
408
  return removeListener;
397
409
  }
398
410
 
@@ -403,15 +415,41 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) {
403
415
  }, {
404
416
  key: "scanCustomerListener",
405
417
  value: function scanCustomerListener(callback) {
406
- var listenerCallback = handleCustomerScan(this.request);
418
+ var _this4 = this;
419
+ var localSearch = function localSearch(v) {
420
+ return _this4.store.products.findProductsByCodeOrBarcode(v);
421
+ };
422
+ var scanCallback = handleCustomerScan(this.request, localSearch);
423
+ var safeCallback = function safeCallback(d) {
424
+ try {
425
+ callback(d);
426
+ } catch (error) {
427
+ console.error('scanCustomerListener回掉函数异常', error);
428
+ }
429
+ };
407
430
  var listener = {
408
431
  key: 'customer',
409
- callback: callback
432
+ callback: safeCallback
410
433
  };
411
- var removeListener = this.scan.addListener(listener, listenerCallback);
434
+ var removeListener = this.scan.addListener(listener, scanCallback);
412
435
  return removeListener;
413
436
  }
414
437
 
438
+ /**
439
+ * 调用摄像头
440
+ * @param data 用户自定义数据
441
+ */
442
+ }, {
443
+ key: "activateCamera",
444
+ value: function activateCamera(data) {
445
+ var _this$window, _this$window$postMess;
446
+ (_this$window = this.window) === null || _this$window === void 0 || (_this$window = _this$window.interaction) === null || _this$window === void 0 || (_this$window = _this$window.utils) === null || _this$window === void 0 || (_this$window$postMess = _this$window.postMessageToApp) === null || _this$window$postMess === void 0 || _this$window$postMess.call(_this$window, {
447
+ module: 'global',
448
+ key: 'active_native_scanner',
449
+ data: data
450
+ });
451
+ }
452
+
415
453
  /**
416
454
  * 设置其他参数
417
455
  * @param params 参数
@@ -484,6 +522,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) {
484
522
  (_this$store$order = this.store.order) === null || _this$store$order === void 0 || _this$store$order.destroy();
485
523
  this.core.effects.offByModuleDestroy(this.name);
486
524
  this.core.unregisterModule(this);
525
+ // 清除scan数据内存缓存
526
+ scanCache.clear();
487
527
  }
488
528
  }]);
489
529
  return BookingTicketImpl;
@@ -17,6 +17,7 @@ export var searchWalletPass = /*#__PURE__*/function () {
17
17
  // 翻译识别码名称 0:不翻译 1:翻译
18
18
  relation_product: 1,
19
19
  // 组装关联商品: 0不处理 1处理
20
+ with: ['customer'],
20
21
  tags: ['point_card',
21
22
  // 积分卡
22
23
  'gift_card',
@@ -72,7 +73,8 @@ export var searchWallet = /*#__PURE__*/function () {
72
73
  while (1) switch (_context2.prev = _context2.next) {
73
74
  case 0:
74
75
  params = {
75
- code: code
76
+ code: code,
77
+ with_customer: 1
76
78
  };
77
79
  _context2.prev = 1;
78
80
  _context2.next = 4;
@@ -114,11 +116,21 @@ export var searchProduct = /*#__PURE__*/function () {
114
116
  while (1) switch (_context3.prev = _context3.next) {
115
117
  case 0:
116
118
  params = {
117
- search: code
119
+ exact_search: code,
120
+ open_bundle: 0,
121
+ // 套餐子信息
122
+ open_quotation: 1,
123
+ // 报价单
124
+ skip: 1,
125
+ num: 20,
126
+ status: 'published',
127
+ with: ['variantGroup'],
128
+ with_count: ['bundleGroup', 'optionGroup'],
129
+ exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item']
118
130
  };
119
131
  _context3.prev = 1;
120
132
  _context3.next = 4;
121
- return request === null || request === void 0 ? void 0 : request.get('/product/list', params);
133
+ return request === null || request === void 0 ? void 0 : request.post('/product/query', params);
122
134
  case 4:
123
135
  res = _context3.sent;
124
136
  if (!((res === null || res === void 0 ? void 0 : res.code) == 200 && (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.list) === null || _res$data === void 0 ? void 0 : _res$data.length) > 0)) {
@@ -4,7 +4,7 @@ import { RequestPlugin } from '../../../../plugins';
4
4
  * @param request 请求插件
5
5
  * @returns 处理结果
6
6
  */
7
- export declare const handleGlobalScan: (request: RequestPlugin) => (scanResult: {
7
+ export declare const handleGlobalScan: (request: RequestPlugin, localSearch: (v: string) => any[]) => (scanResult: {
8
8
  type: string;
9
9
  value: string;
10
10
  }) => Promise<any>;
@@ -13,7 +13,7 @@ export declare const handleGlobalScan: (request: RequestPlugin) => (scanResult:
13
13
  * @param request 请求插件
14
14
  * @returns 处理结果
15
15
  */
16
- export declare const handleCustomerScan: (request: RequestPlugin) => (scanResult: {
16
+ export declare const handleCustomerScan: (request: RequestPlugin, localSearch: (v: string) => any[]) => (scanResult: {
17
17
  type: string;
18
18
  value: string;
19
19
  }) => Promise<any>;
@@ -3,6 +3,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
3
3
  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
4
  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); }); }; }
5
5
  import { searchWalletPass, searchWallet, searchProduct } from "./cloudSearch";
6
+ import scanCache from "./scanCache";
6
7
 
7
8
  /**
8
9
  * Promise.any 的替代实现
@@ -56,39 +57,85 @@ var promiseAny = /*#__PURE__*/function () {
56
57
  }();
57
58
 
58
59
  /**
59
- * 处理全局扫码
60
- * @param request 请求插件
60
+ * 处理扫码
61
+ * @param getRequestList 获取请求列表
61
62
  * @returns 处理结果
62
63
  */
63
- export var handleGlobalScan = function handleGlobalScan(request) {
64
+ var handleScanFn = function handleScanFn(getRequestList, localSearch) {
64
65
  return /*#__PURE__*/function () {
65
66
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(scanResult) {
66
- var _ref3, value, requestList, result;
67
+ var _ref3, value, localResult, result, requestList, _result;
67
68
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
68
69
  while (1) switch (_context2.prev = _context2.next) {
69
70
  case 0:
70
- _ref3 = scanResult || {}, value = _ref3.value; // TODO: 本地解析识别码
71
- requestList = []; // 如果value是已WL开头的,则认为是钱包识别码
72
- if (value.startsWith('WL')) {
73
- requestList = [searchWallet(request, value)];
74
- } else {
75
- requestList = [searchWalletPass(request, value), searchWallet(request, value), searchProduct(request, value)];
71
+ _ref3 = scanResult || {}, value = _ref3.value; // 本地解析识别码
72
+ _context2.prev = 1;
73
+ localResult = localSearch === null || localSearch === void 0 ? void 0 : localSearch(value);
74
+ if (!((localResult === null || localResult === void 0 ? void 0 : localResult.length) > 0)) {
75
+ _context2.next = 8;
76
+ break;
76
77
  }
77
- _context2.prev = 3;
78
- _context2.next = 6;
79
- return promiseAny(requestList);
80
- case 6:
81
- result = _context2.sent;
78
+ console.log('本地搜索到数据>>>>>>>', localResult);
79
+ return _context2.abrupt("return", {
80
+ searchType: 'local_product',
81
+ response: {
82
+ data: {
83
+ list: localResult
84
+ }
85
+ }
86
+ });
87
+ case 8:
88
+ console.log('本地搜索无数据>>>>>>>');
89
+ case 9:
90
+ _context2.next = 14;
91
+ break;
92
+ case 11:
93
+ _context2.prev = 11;
94
+ _context2.t0 = _context2["catch"](1);
95
+ console.error('本地搜索到数据失败>>>>>>>', _context2.t0);
96
+ case 14:
97
+ _context2.prev = 14;
98
+ if (!scanCache.has(value)) {
99
+ _context2.next = 21;
100
+ break;
101
+ }
102
+ result = scanCache.get(value);
103
+ console.log('缓存中搜索到数据>>>>>>>', result);
82
104
  return _context2.abrupt("return", result);
83
- case 10:
84
- _context2.prev = 10;
85
- _context2.t0 = _context2["catch"](3);
86
- throw _context2.t0;
87
- case 13:
105
+ case 21:
106
+ console.log('缓存中无数据>>>>>>>');
107
+ case 22:
108
+ _context2.next = 27;
109
+ break;
110
+ case 24:
111
+ _context2.prev = 24;
112
+ _context2.t1 = _context2["catch"](14);
113
+ console.error('缓存中搜索数据失败>>>>>>>', _context2.t1);
114
+ case 27:
115
+ requestList = (getRequestList === null || getRequestList === void 0 ? void 0 : getRequestList(value)) || [];
116
+ if (!(requestList.length === 0)) {
117
+ _context2.next = 30;
118
+ break;
119
+ }
120
+ throw new Error('requestList is empty');
121
+ case 30:
122
+ _context2.prev = 30;
123
+ _context2.next = 33;
124
+ return promiseAny(requestList);
125
+ case 33:
126
+ _result = _context2.sent;
127
+ // 将结果缓存
128
+ scanCache.set(value, _result);
129
+ return _context2.abrupt("return", _result);
130
+ case 38:
131
+ _context2.prev = 38;
132
+ _context2.t2 = _context2["catch"](30);
133
+ throw _context2.t2;
134
+ case 41:
88
135
  case "end":
89
136
  return _context2.stop();
90
137
  }
91
- }, _callee2, null, [[3, 10]]);
138
+ }, _callee2, null, [[1, 11], [14, 24], [30, 38]]);
92
139
  }));
93
140
  return function (_x2) {
94
141
  return _ref2.apply(this, arguments);
@@ -96,43 +143,40 @@ export var handleGlobalScan = function handleGlobalScan(request) {
96
143
  }();
97
144
  };
98
145
 
146
+ /**
147
+ * 处理全局扫码
148
+ * @param request 请求插件
149
+ * @returns 处理结果
150
+ */
151
+ export var handleGlobalScan = function handleGlobalScan(request, localSearch) {
152
+ var getRequestList = function getRequestList(value) {
153
+ var requestList = [];
154
+ // 如果value是已WL开头的,则认为是钱包识别码
155
+ if (value.startsWith('WL')) {
156
+ requestList = [searchWallet(request, value)];
157
+ } else {
158
+ requestList = [searchWalletPass(request, value), searchWallet(request, value), searchProduct(request, value)];
159
+ }
160
+ return requestList;
161
+ };
162
+ return handleScanFn(getRequestList, localSearch);
163
+ };
164
+
99
165
  /**
100
166
  * 处理客户扫码
101
167
  * @param request 请求插件
102
168
  * @returns 处理结果
103
169
  */
104
- export var handleCustomerScan = function handleCustomerScan(request) {
105
- return /*#__PURE__*/function () {
106
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(scanResult) {
107
- var _ref5, value, requestList, result;
108
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
109
- while (1) switch (_context3.prev = _context3.next) {
110
- case 0:
111
- _ref5 = scanResult || {}, value = _ref5.value; // TODO: 本地解析识别码
112
- requestList = []; // 如果value是已WL开头的,则认为是钱包识别码
113
- if (value.startsWith('WL')) {
114
- requestList = [searchWallet(request, value)];
115
- } else {
116
- requestList = [searchWalletPass(request, value), searchWallet(request, value)];
117
- }
118
- _context3.prev = 3;
119
- _context3.next = 6;
120
- return Promise.race(requestList);
121
- case 6:
122
- result = _context3.sent;
123
- return _context3.abrupt("return", result);
124
- case 10:
125
- _context3.prev = 10;
126
- _context3.t0 = _context3["catch"](3);
127
- throw _context3.t0;
128
- case 13:
129
- case "end":
130
- return _context3.stop();
131
- }
132
- }, _callee3, null, [[3, 10]]);
133
- }));
134
- return function (_x3) {
135
- return _ref4.apply(this, arguments);
136
- };
137
- }();
170
+ export var handleCustomerScan = function handleCustomerScan(request, localSearch) {
171
+ var getRequestList = function getRequestList(value) {
172
+ var requestList = [];
173
+ // 如果value是已WL开头的,则认为是钱包识别码
174
+ if (value.startsWith('WL')) {
175
+ requestList = [searchWallet(request, value)];
176
+ } else {
177
+ requestList = [searchWalletPass(request, value), searchWallet(request, value)];
178
+ }
179
+ return requestList;
180
+ };
181
+ return handleScanFn(getRequestList, localSearch);
138
182
  };
@@ -2,10 +2,18 @@ import { WatchEventItem } from '../../../../utils/watch';
2
2
  import { BookingTicketImpl } from '../../index';
3
3
  import Tasks from '../../../../utils/task';
4
4
  interface ScanResult {
5
- type: string;
5
+ type: ScanResultType;
6
6
  value: string;
7
+ data?: {
8
+ [key: string]: any;
9
+ };
10
+ }
11
+ declare enum ScanResultType {
12
+ Scanner = "scanner",
13
+ NFC = "nfc",
14
+ NativeScanner = "nativeScanner"
7
15
  }
8
- export declare class Scan {
16
+ export default class Scan {
9
17
  private solution;
10
18
  private watchKey;
11
19
  private listenerConfig;
@@ -15,7 +23,7 @@ export declare class Scan {
15
23
  * @param watchKey 监听的key
16
24
  * @param event 事件
17
25
  */
18
- addListener(event: WatchEventItem, callback?: (result: ScanResult) => Promise<any>): {
26
+ addListener(event: WatchEventItem, scanCallback?: (result: ScanResult) => Promise<any>): {
19
27
  remove: () => void;
20
28
  };
21
29
  /**
@@ -39,7 +47,7 @@ export declare class Scan {
39
47
  * @returns 监听配置
40
48
  */
41
49
  getListenerConfig(eventKey: string): {
42
- callback?: ((result: ScanResult) => Promise<any>) | undefined;
50
+ scanCallback?: ((result: ScanResult) => Promise<any>) | undefined;
43
51
  task: Tasks;
44
52
  } | undefined;
45
53
  /**
@@ -10,10 +10,15 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
10
10
  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); }
11
11
  import watch from "../../../../utils/watch";
12
12
  import Tasks from "../../../../utils/task";
13
- export var Scan = /*#__PURE__*/function () {
13
+ var ScanResultType = /*#__PURE__*/function (ScanResultType) {
14
+ ScanResultType["Scanner"] = "scanner";
15
+ ScanResultType["NFC"] = "nfc";
16
+ ScanResultType["NativeScanner"] = "nativeScanner";
17
+ return ScanResultType;
18
+ }(ScanResultType || {});
19
+ var Scan = /*#__PURE__*/function () {
14
20
  function Scan(solution, watchKey) {
15
- var _solution$window,
16
- _this$solution,
21
+ var _this$solution,
17
22
  _this$solution$mountF,
18
23
  _this = this;
19
24
  _classCallCheck(this, Scan);
@@ -22,9 +27,9 @@ export var Scan = /*#__PURE__*/function () {
22
27
  _defineProperty(this, "listenerConfig", new Map());
23
28
  this.solution = solution;
24
29
  this.watchKey = watchKey;
25
- console.log('this.solution?.window?.interaction', solution === null || solution === void 0 || (_solution$window = solution.window) === null || _solution$window === void 0 ? void 0 : _solution$window.interaction);
30
+
26
31
  // 监听扫码结果
27
- (_this$solution = this.solution) === null || _this$solution === void 0 || (_this$solution = _this$solution.window) === null || _this$solution === void 0 || (_this$solution = _this$solution.interaction) === null || _this$solution === void 0 || (_this$solution = _this$solution.utils) === null || _this$solution === void 0 || (_this$solution$mountF = _this$solution.mountFunction) === null || _this$solution$mountF === void 0 || _this$solution$mountF.call(_this$solution, 'global', 'nativeScannerResult', function (strVal) {
32
+ (_this$solution = this.solution) === null || _this$solution === void 0 || (_this$solution = _this$solution.window) === null || _this$solution === void 0 || (_this$solution = _this$solution.interaction) === null || _this$solution === void 0 || (_this$solution = _this$solution.utils) === null || _this$solution === void 0 || (_this$solution$mountF = _this$solution.mountFunction) === null || _this$solution$mountF === void 0 || _this$solution$mountF.call(_this$solution, 'global', 'peripheralsResult', function (strVal) {
28
33
  try {
29
34
  var _result = JSON.parse(strVal);
30
35
  console.log('nativeScannerResult>>>>>>>', _result);
@@ -42,7 +47,7 @@ export var Scan = /*#__PURE__*/function () {
42
47
  */
43
48
  _createClass(Scan, [{
44
49
  key: "addListener",
45
- value: function addListener(event, callback) {
50
+ value: function addListener(event, scanCallback) {
46
51
  var _this2 = this;
47
52
  // 订阅事件
48
53
  watch.subscribe(this.watchKey, event);
@@ -54,9 +59,10 @@ export var Scan = /*#__PURE__*/function () {
54
59
  }
55
60
  return _this2.handleScanResultFn.apply(_this2, [event.key].concat(args));
56
61
  });
62
+
57
63
  // 创建监听配置
58
64
  this.listenerConfig.set(event.key, {
59
- callback: callback,
65
+ scanCallback: scanCallback,
60
66
  task: task
61
67
  });
62
68
  return {
@@ -131,7 +137,8 @@ export var Scan = /*#__PURE__*/function () {
131
137
  _ref,
132
138
  type,
133
139
  value,
134
- listenerCallback,
140
+ data,
141
+ scanCallback,
135
142
  _result2,
136
143
  _args = arguments;
137
144
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -141,43 +148,47 @@ export var Scan = /*#__PURE__*/function () {
141
148
  args[_key2] = _args[_key2];
142
149
  }
143
150
  eventKey = args[0], other = args[1];
144
- _ref = (other === null || other === void 0 ? void 0 : other.scanResult) || {}, type = _ref.type, value = _ref.value;
145
- listenerCallback = (_this$getListenerConf = this.getListenerConfig(eventKey)) === null || _this$getListenerConf === void 0 ? void 0 : _this$getListenerConf.callback;
146
- if (!listenerCallback) {
147
- _context.next = 15;
151
+ _ref = (other === null || other === void 0 ? void 0 : other.scanResult) || {}, type = _ref.type, value = _ref.value, data = _ref.data;
152
+ scanCallback = (_this$getListenerConf = this.getListenerConfig(eventKey)) === null || _this$getListenerConf === void 0 ? void 0 : _this$getListenerConf.scanCallback;
153
+ if (!scanCallback) {
154
+ _context.next = 17;
148
155
  break;
149
156
  }
150
157
  _context.prev = 5;
151
158
  _context.next = 8;
152
- return listenerCallback({
159
+ return scanCallback({
153
160
  type: type,
154
161
  value: value
155
162
  });
156
163
  case 8:
157
164
  _result2 = _context.sent;
165
+ console.log("".concat(eventKey, "_result>>>>>>>"), _result2);
158
166
  watch.publishByEventKey(this.watchKey, eventKey, {
159
167
  type: eventKey,
160
168
  status: 'success',
161
169
  scanType: type,
162
170
  scanCode: value,
171
+ scanData: data,
163
172
  result: _result2
164
173
  });
165
- _context.next = 15;
174
+ _context.next = 17;
166
175
  break;
167
- case 12:
168
- _context.prev = 12;
176
+ case 13:
177
+ _context.prev = 13;
169
178
  _context.t0 = _context["catch"](5);
179
+ console.log("".concat(eventKey, "_result_error>>>>>>>"), _context.t0);
170
180
  watch.publishByEventKey(this.watchKey, eventKey, {
171
181
  type: eventKey,
172
182
  status: 'failed',
173
183
  scanType: type,
174
- scanCode: value
184
+ scanCode: value,
185
+ scanData: data
175
186
  });
176
- case 15:
187
+ case 17:
177
188
  case "end":
178
189
  return _context.stop();
179
190
  }
180
- }, _callee, this, [[5, 12]]);
191
+ }, _callee, this, [[5, 13]]);
181
192
  }));
182
193
  function handleScanResultFn() {
183
194
  return _handleScanResultFn.apply(this, arguments);
@@ -186,4 +197,5 @@ export var Scan = /*#__PURE__*/function () {
186
197
  }())
187
198
  }]);
188
199
  return Scan;
189
- }();
200
+ }();
201
+ export { Scan as default };
@@ -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;