@pisell/pisellos 1.0.52 → 1.0.54

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.
@@ -8,6 +8,7 @@ export declare class ProductList extends BaseModule implements Module {
8
8
  protected defaultVersion: string;
9
9
  private store;
10
10
  private request;
11
+ private otherParams;
11
12
  constructor(name?: string, version?: string);
12
13
  initialize(core: PisellCore, options: any): Promise<void>;
13
14
  storeChange(path?: string, value?: any): Promise<void>;
@@ -31,6 +31,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
31
31
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
32
32
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
33
33
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
34
35
  return _this;
35
36
  }
36
37
  _createClass(ProductList, [{
@@ -43,6 +44,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
43
44
  case 0:
44
45
  this.core = core;
45
46
  this.store = options.store;
47
+ this.otherParams = options.otherParams || {};
46
48
  if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
47
49
  this.store.list = options.initialState.list;
48
50
  this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
@@ -53,7 +55,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
53
55
  this.store.selectProducts = [];
54
56
  }
55
57
  this.request = core.getPlugin('request');
56
- case 4:
58
+ case 5:
57
59
  case "end":
58
60
  return _context.stop();
59
61
  }
@@ -100,6 +102,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
100
102
  key: "loadProducts",
101
103
  value: function () {
102
104
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
105
+ var _this$otherParams;
103
106
  var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$menu_list_ids, menu_list_ids, paramsCustomerId, _ref$with_count, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, userPlugin, customer_id, _userPlugin$get, productsData;
104
107
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
105
108
  while (1) switch (_context3.prev = _context3.next) {
@@ -144,7 +147,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
144
147
  // client_schedule_ids: schedule_ids,
145
148
  schedule_date: schedule_date,
146
149
  with_schedule: with_schedule,
147
- schedule_datetime: schedule_datetime
150
+ schedule_datetime: schedule_datetime,
151
+ application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel
148
152
  }, {
149
153
  useCache: true
150
154
  });
@@ -281,7 +281,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
281
281
  onlyComputed: true,
282
282
  // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
283
283
  metadata: _objectSpread(_objectSpread({}, resourcesMap[id].metadata), {}, {
284
- combined_resource: resourcesMap[id].combined_resource
284
+ combined_resource: resourcesMap[id].combined_resource,
285
+ form_name: item.title,
286
+ resource_name: resourcesMap[id].main_field
285
287
  })
286
288
  }));
287
289
  }
@@ -292,7 +294,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
292
294
  resourceType: item.type,
293
295
  children: combiningResources,
294
296
  metadata: _objectSpread(_objectSpread({}, resourcesMap[d].metadata), {}, {
295
- combined_resource: resourcesMap[d].combined_resource
297
+ combined_resource: resourcesMap[d].combined_resource,
298
+ form_name: item.title,
299
+ resource_name: resourcesMap[d].main_field
296
300
  })
297
301
  }));
298
302
  }
@@ -315,7 +319,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
315
319
  onlyComputed: true,
316
320
  // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
317
321
  metadata: _objectSpread(_objectSpread({}, resourcesMap[id].metadata), {}, {
318
- combined_resource: resourcesMap[id].combined_resource
322
+ combined_resource: resourcesMap[id].combined_resource,
323
+ form_name: item.title,
324
+ resource_name: resourcesMap[id].main_field
319
325
  })
320
326
  }));
321
327
  }
@@ -327,7 +333,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
327
333
  is_default: 1,
328
334
  children: combiningResources,
329
335
  metadata: _objectSpread(_objectSpread({}, resourcesMap[d].metadata), {}, {
330
- combined_resource: resourcesMap[d].combined_resource
336
+ combined_resource: resourcesMap[d].combined_resource,
337
+ form_name: item.title,
338
+ resource_name: resourcesMap[d].main_field
331
339
  })
332
340
  }));
333
341
  }
@@ -138,6 +138,18 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
138
138
  activateCamera(data?: {
139
139
  [key: string]: any;
140
140
  }): void;
141
+ /**
142
+ * 禁用所有扫描监听
143
+ */
144
+ disableAllScanListeners(): void;
145
+ /**
146
+ * 启用所有扫描监听
147
+ */
148
+ enableAllScanListeners(): void;
149
+ /**
150
+ * 清空所有扫描监听对应的任务执行队列
151
+ */
152
+ clearAllScanListenersTaskQueue(): void;
141
153
  /**
142
154
  * 设置其他参数
143
155
  * @param params 参数
@@ -552,6 +552,33 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) {
552
552
  });
553
553
  }
554
554
 
555
+ /**
556
+ * 禁用所有扫描监听
557
+ */
558
+ }, {
559
+ key: "disableAllScanListeners",
560
+ value: function disableAllScanListeners() {
561
+ this.scan.disableAllListeners();
562
+ }
563
+
564
+ /**
565
+ * 启用所有扫描监听
566
+ */
567
+ }, {
568
+ key: "enableAllScanListeners",
569
+ value: function enableAllScanListeners() {
570
+ this.scan.enableAllListeners();
571
+ }
572
+
573
+ /**
574
+ * 清空所有扫描监听对应的任务执行队列
575
+ */
576
+ }, {
577
+ key: "clearAllScanListenersTaskQueue",
578
+ value: function clearAllScanListenersTaskQueue() {
579
+ this.scan.clearTaskQueue();
580
+ }
581
+
555
582
  /**
556
583
  * 设置其他参数
557
584
  * @param params 参数
@@ -624,6 +651,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseModule) {
624
651
  (_this$store$order = this.store.order) === null || _this$store$order === void 0 || _this$store$order.destroy();
625
652
  this.core.effects.offByModuleDestroy(this.name);
626
653
  this.core.unregisterModule(this);
654
+ // 清除所有的监听
655
+ this.scan.removeAllListeners();
627
656
  // 清除scan数据内存缓存
628
657
  scanCache.clear();
629
658
  }
@@ -18,6 +18,20 @@ export default class Scan {
18
18
  private watchKey;
19
19
  private listenerConfig;
20
20
  constructor(solution: BookingTicketImpl, watchKey: string);
21
+ /**
22
+ * 处理扫码事件
23
+ * @param eventKey 事件key
24
+ * @param value 扫码结果
25
+ */
26
+ handleScan(result: {
27
+ type: string;
28
+ value: string;
29
+ }): void;
30
+ /**
31
+ * 生成uuid
32
+ * @returns uuid
33
+ */
34
+ generateUuid(): string;
21
35
  /**
22
36
  * 添加扫码信息监听
23
37
  * @param watchKey 监听的key
@@ -33,14 +47,22 @@ export default class Scan {
33
47
  */
34
48
  removeListener(event: WatchEventItem): void;
35
49
  /**
36
- * 处理扫码事件
50
+ * 移除所有监听
51
+ */
52
+ removeAllListeners(): void;
53
+ /**
54
+ * 启用所有监听
55
+ */
56
+ enableAllListeners(): void;
57
+ /**
58
+ * 禁用所有监听,并清空任务执行队列
59
+ */
60
+ disableAllListeners(): void;
61
+ /**
62
+ * 清空监听对应的任务执行队列,不传入eventKey则清空所有监听对应的任务执行队列
37
63
  * @param eventKey 事件key
38
- * @param value 扫码结果
39
64
  */
40
- handleScan(value: {
41
- type: string;
42
- value: string;
43
- }): void;
65
+ clearTaskQueue(eventKey?: string): void;
44
66
  /**
45
67
  * 获取监听配置
46
68
  * @param eventKey 事件key
@@ -51,9 +73,9 @@ export default class Scan {
51
73
  task: Tasks;
52
74
  } | undefined;
53
75
  /**
54
- * 处理扫码结果
76
+ * 扫码任务执行函数
55
77
  * @param args 参数
56
78
  */
57
- handleScanResultFn(...args: any[]): Promise<void>;
79
+ scanTaskAction(...args: any[]): Promise<void>;
58
80
  }
59
81
  export {};
@@ -41,11 +41,45 @@ var Scan = /*#__PURE__*/function () {
41
41
  }
42
42
 
43
43
  /**
44
- * 添加扫码信息监听
45
- * @param watchKey 监听的key
46
- * @param event 事件
44
+ * 处理扫码事件
45
+ * @param eventKey 事件key
46
+ * @param value 扫码结果
47
47
  */
48
48
  _createClass(Scan, [{
49
+ key: "handleScan",
50
+ value: function handleScan(result) {
51
+ var lastEnableEventKey = watch.getLastEnableEventKey(this.watchKey);
52
+ if (lastEnableEventKey) {
53
+ var listenerConfig = this.listenerConfig.get(lastEnableEventKey);
54
+ if (listenerConfig) {
55
+ listenerConfig.task.addTask({
56
+ uuid: this.generateUuid(),
57
+ type: lastEnableEventKey,
58
+ actionParams: {
59
+ scanResult: result
60
+ }
61
+ });
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * 生成uuid
68
+ * @returns uuid
69
+ */
70
+ }, {
71
+ key: "generateUuid",
72
+ value: function generateUuid() {
73
+ // 需要加入时间戳,避免重复
74
+ return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
75
+ }
76
+
77
+ /**
78
+ * 添加扫码信息监听
79
+ * @param watchKey 监听的key
80
+ * @param event 事件
81
+ */
82
+ }, {
49
83
  key: "addListener",
50
84
  value: function addListener(event, scanCallback) {
51
85
  var _this2 = this;
@@ -57,7 +91,7 @@ var Scan = /*#__PURE__*/function () {
57
91
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
58
92
  args[_key] = arguments[_key];
59
93
  }
60
- return _this2.handleScanResultFn.apply(_this2, [event.key].concat(args));
94
+ return _this2.scanTaskAction.apply(_this2, [event.key].concat(args));
61
95
  });
62
96
 
63
97
  // 创建监听配置
@@ -82,29 +116,66 @@ var Scan = /*#__PURE__*/function () {
82
116
  value: function removeListener(event) {
83
117
  var _this$listenerConfig$;
84
118
  watch.unsubscribe(this.watchKey, event);
85
- (_this$listenerConfig$ = this.listenerConfig.get(event.key)) === null || _this$listenerConfig$ === void 0 || _this$listenerConfig$.task.clear();
119
+ (_this$listenerConfig$ = this.listenerConfig.get(event.key)) === null || _this$listenerConfig$ === void 0 || (_this$listenerConfig$ = _this$listenerConfig$.task) === null || _this$listenerConfig$ === void 0 || _this$listenerConfig$.clear();
86
120
  this.listenerConfig.delete(event.key);
87
121
  }
88
122
 
89
123
  /**
90
- * 处理扫码事件
124
+ * 移除所有监听
125
+ */
126
+ }, {
127
+ key: "removeAllListeners",
128
+ value: function removeAllListeners() {
129
+ var _this$listenerConfig, _this$listenerConfig$2, _this$listenerConfig2, _this$listenerConfig3;
130
+ watch.clearEvent(this.watchKey);
131
+ (_this$listenerConfig = this.listenerConfig) === null || _this$listenerConfig === void 0 || (_this$listenerConfig$2 = _this$listenerConfig.forEach) === null || _this$listenerConfig$2 === void 0 || _this$listenerConfig$2.call(_this$listenerConfig, function (item) {
132
+ var _item$task;
133
+ item === null || item === void 0 || (_item$task = item.task) === null || _item$task === void 0 || _item$task.clear();
134
+ });
135
+ (_this$listenerConfig2 = this.listenerConfig) === null || _this$listenerConfig2 === void 0 || (_this$listenerConfig3 = _this$listenerConfig2.clear) === null || _this$listenerConfig3 === void 0 || _this$listenerConfig3.call(_this$listenerConfig2);
136
+ }
137
+
138
+ /**
139
+ * 启用所有监听
140
+ */
141
+ }, {
142
+ key: "enableAllListeners",
143
+ value: function enableAllListeners() {
144
+ watch.enableAllEventByWatchKey(this.watchKey);
145
+ }
146
+
147
+ /**
148
+ * 禁用所有监听,并清空任务执行队列
149
+ */
150
+ }, {
151
+ key: "disableAllListeners",
152
+ value: function disableAllListeners() {
153
+ var _this$listenerConfig4, _this$listenerConfig5;
154
+ watch.disabledAllEventByWatchKey(this.watchKey);
155
+ // 清空任务
156
+ (_this$listenerConfig4 = this.listenerConfig) === null || _this$listenerConfig4 === void 0 || (_this$listenerConfig5 = _this$listenerConfig4.forEach) === null || _this$listenerConfig5 === void 0 || _this$listenerConfig5.call(_this$listenerConfig4, function (item) {
157
+ var _item$task2;
158
+ item === null || item === void 0 || (_item$task2 = item.task) === null || _item$task2 === void 0 || _item$task2.clearTaskQueue();
159
+ });
160
+ }
161
+
162
+ /**
163
+ * 清空监听对应的任务执行队列,不传入eventKey则清空所有监听对应的任务执行队列
91
164
  * @param eventKey 事件key
92
- * @param value 扫码结果
93
165
  */
94
166
  }, {
95
- key: "handleScan",
96
- value: function handleScan(value) {
97
- var lastEnableEventKey = watch.getLastEnableEventKey(this.watchKey);
98
- if (lastEnableEventKey) {
99
- var listenerConfig = this.listenerConfig.get(lastEnableEventKey);
100
- if (listenerConfig) {
101
- listenerConfig.task.addTask({
102
- type: lastEnableEventKey,
103
- actionParams: {
104
- scanResult: value
105
- }
106
- });
107
- }
167
+ key: "clearTaskQueue",
168
+ value: function clearTaskQueue(eventKey) {
169
+ console.log('clearTaskQueue>>>>>>>', eventKey);
170
+ if (eventKey) {
171
+ var _this$listenerConfig$3;
172
+ (_this$listenerConfig$3 = this.listenerConfig.get(eventKey)) === null || _this$listenerConfig$3 === void 0 || _this$listenerConfig$3.task.clearTaskQueue();
173
+ } else {
174
+ var _this$listenerConfig6, _this$listenerConfig7;
175
+ (_this$listenerConfig6 = this.listenerConfig) === null || _this$listenerConfig6 === void 0 || (_this$listenerConfig7 = _this$listenerConfig6.forEach) === null || _this$listenerConfig7 === void 0 || _this$listenerConfig7.call(_this$listenerConfig6, function (item) {
176
+ var _item$task3;
177
+ item === null || item === void 0 || (_item$task3 = item.task) === null || _item$task3 === void 0 || _item$task3.clearTaskQueue();
178
+ });
108
179
  }
109
180
  }
110
181
 
@@ -116,19 +187,18 @@ var Scan = /*#__PURE__*/function () {
116
187
  }, {
117
188
  key: "getListenerConfig",
118
189
  value: function getListenerConfig(eventKey) {
119
- var _this$listenerConfig;
120
- return (_this$listenerConfig = this.listenerConfig) === null || _this$listenerConfig === void 0 ? void 0 : _this$listenerConfig.get(eventKey);
190
+ var _this$listenerConfig8;
191
+ return (_this$listenerConfig8 = this.listenerConfig) === null || _this$listenerConfig8 === void 0 ? void 0 : _this$listenerConfig8.get(eventKey);
121
192
  }
122
193
 
123
194
  /**
124
- * 处理扫码结果
195
+ * 扫码任务执行函数
125
196
  * @param args 参数
126
197
  */
127
198
  }, {
128
- key: "handleScanResultFn",
199
+ key: "scanTaskAction",
129
200
  value: (function () {
130
- var _handleScanResultFn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
131
- var _this$getListenerConf;
201
+ var _scanTaskAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
132
202
  var _len2,
133
203
  args,
134
204
  _key2,
@@ -138,7 +208,10 @@ var Scan = /*#__PURE__*/function () {
138
208
  type,
139
209
  value,
140
210
  data,
211
+ taskItemUuid,
212
+ _ref2,
141
213
  scanCallback,
214
+ task,
142
215
  _result2,
143
216
  _args = arguments;
144
217
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -149,51 +222,62 @@ var Scan = /*#__PURE__*/function () {
149
222
  }
150
223
  eventKey = args[0], other = args[1];
151
224
  _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;
225
+ taskItemUuid = other === null || other === void 0 ? void 0 : other.uuid;
226
+ _ref2 = this.getListenerConfig(eventKey) || {}, scanCallback = _ref2.scanCallback, task = _ref2.task;
153
227
  if (!scanCallback) {
154
- _context.next = 17;
228
+ _context.next = 18;
155
229
  break;
156
230
  }
157
- _context.prev = 5;
158
- _context.next = 8;
231
+ _context.prev = 6;
232
+ _context.next = 9;
159
233
  return scanCallback({
160
234
  type: type,
161
235
  value: value
162
236
  });
163
- case 8:
237
+ case 9:
164
238
  _result2 = _context.sent;
165
239
  console.log("".concat(eventKey, "_result>>>>>>>"), _result2);
166
- watch.publishByEventKey(this.watchKey, eventKey, {
167
- type: eventKey,
168
- status: 'success',
169
- scanType: type,
170
- scanCode: value,
171
- scanData: data,
172
- result: _result2
173
- });
174
- _context.next = 17;
240
+ // 如果任务存在,则发布结果
241
+ if (taskItemUuid && task !== null && task !== void 0 && task.isTaskExist(taskItemUuid)) {
242
+ watch.publishByEventKey(this.watchKey, eventKey, {
243
+ type: eventKey,
244
+ status: 'success',
245
+ scanType: type,
246
+ scanCode: value,
247
+ scanData: data,
248
+ result: _result2
249
+ });
250
+ } else {
251
+ console.warn("".concat(eventKey, "_result_task_not_exist>>>>>>>"), task);
252
+ }
253
+ _context.next = 18;
175
254
  break;
176
- case 13:
177
- _context.prev = 13;
178
- _context.t0 = _context["catch"](5);
255
+ case 14:
256
+ _context.prev = 14;
257
+ _context.t0 = _context["catch"](6);
179
258
  console.log("".concat(eventKey, "_result_error>>>>>>>"), _context.t0);
180
- watch.publishByEventKey(this.watchKey, eventKey, {
181
- type: eventKey,
182
- status: 'failed',
183
- scanType: type,
184
- scanCode: value,
185
- scanData: data
186
- });
187
- case 17:
259
+ // 如果任务存在,则发布结果
260
+ if (taskItemUuid && task !== null && task !== void 0 && task.isTaskExist(taskItemUuid)) {
261
+ watch.publishByEventKey(this.watchKey, eventKey, {
262
+ type: eventKey,
263
+ status: 'failed',
264
+ scanType: type,
265
+ scanCode: value,
266
+ scanData: data
267
+ });
268
+ } else {
269
+ console.warn("".concat(eventKey, "_result_error_task_not_exist>>>>>>>"), task);
270
+ }
271
+ case 18:
188
272
  case "end":
189
273
  return _context.stop();
190
274
  }
191
- }, _callee, this, [[5, 13]]);
275
+ }, _callee, this, [[6, 14]]);
192
276
  }));
193
- function handleScanResultFn() {
194
- return _handleScanResultFn.apply(this, arguments);
277
+ function scanTaskAction() {
278
+ return _scanTaskAction.apply(this, arguments);
195
279
  }
196
- return handleScanResultFn;
280
+ return scanTaskAction;
197
281
  }())
198
282
  }]);
199
283
  return Scan;
@@ -1,5 +1,6 @@
1
1
  type Action = (...args: any[]) => Promise<any>;
2
2
  type Task = {
3
+ uuid: string;
3
4
  type: string;
4
5
  actionParams?: Record<string, any>;
5
6
  };
@@ -9,9 +10,13 @@ declare class Tasks {
9
10
  isRunning: boolean;
10
11
  constructor(actions?: Map<string, Action>);
11
12
  /**
12
- * 清空任务队列
13
+ * 清空所有任务
13
14
  */
14
15
  clear(): void;
16
+ /**
17
+ * 清空任务执行队列
18
+ */
19
+ clearTaskQueue(): void;
15
20
  /**
16
21
  * 添加action
17
22
  * @param name action名称
@@ -27,5 +32,9 @@ declare class Tasks {
27
32
  * 执行任务
28
33
  */
29
34
  run(): Promise<void>;
35
+ /**
36
+ * 判定当前的任务是否依然存在
37
+ */
38
+ isTaskExist(uuid: string): boolean;
30
39
  }
31
40
  export default Tasks;
@@ -1,5 +1,7 @@
1
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
2
  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
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
5
  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
6
  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
7
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -20,7 +22,7 @@ var Tasks = /*#__PURE__*/function () {
20
22
  }
21
23
 
22
24
  /**
23
- * 清空任务队列
25
+ * 清空所有任务
24
26
  */
25
27
  _createClass(Tasks, [{
26
28
  key: "clear",
@@ -30,6 +32,16 @@ var Tasks = /*#__PURE__*/function () {
30
32
  this.isRunning = false;
31
33
  }
32
34
 
35
+ /**
36
+ * 清空任务执行队列
37
+ */
38
+ }, {
39
+ key: "clearTaskQueue",
40
+ value: function clearTaskQueue() {
41
+ this.taskQueue = [];
42
+ this.isRunning = false;
43
+ }
44
+
33
45
  /**
34
46
  * 添加action
35
47
  * @param name action名称
@@ -60,7 +72,7 @@ var Tasks = /*#__PURE__*/function () {
60
72
  key: "run",
61
73
  value: (function () {
62
74
  var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
63
- var task, action;
75
+ var _this$taskQueue, task, action, _task, _task2;
64
76
  return _regeneratorRuntime().wrap(function _callee$(_context) {
65
77
  while (1) switch (_context.prev = _context.next) {
66
78
  case 0:
@@ -82,11 +94,11 @@ var Tasks = /*#__PURE__*/function () {
82
94
  // 遍历任务队列
83
95
  case 6:
84
96
  if (!(this.taskQueue.length > 0)) {
85
- _context.next = 17;
97
+ _context.next = 32;
86
98
  break;
87
99
  }
88
- // 获取任务
89
- task = this.taskQueue.shift(); // 如果没有任务则直接结束
100
+ // 获取任务,但是不删除
101
+ task = (_this$taskQueue = this.taskQueue) === null || _this$taskQueue === void 0 ? void 0 : _this$taskQueue[0]; // 如果没有任务则直接结束
90
102
  if (task) {
91
103
  _context.next = 11;
92
104
  break;
@@ -97,54 +109,63 @@ var Tasks = /*#__PURE__*/function () {
97
109
  // 获取任务对应的action
98
110
  action = this.actions.get(task.type); // 如果找到对应的action,则执行
99
111
  if (!action) {
100
- _context.next = 15;
112
+ _context.next = 28;
101
113
  break;
102
114
  }
103
- _context.next = 15;
104
- return action((task === null || task === void 0 ? void 0 : task.actionParams) || {});
105
- case 15:
115
+ _context.prev = 13;
116
+ _context.next = 16;
117
+ return action(_objectSpread(_objectSpread({}, (task === null || task === void 0 ? void 0 : task.actionParams) || {}), {}, {
118
+ uuid: task === null || task === void 0 ? void 0 : task.uuid
119
+ }));
120
+ case 16:
121
+ console.log('task_success>>>>>>>', task);
122
+ _context.next = 22;
123
+ break;
124
+ case 19:
125
+ _context.prev = 19;
126
+ _context.t0 = _context["catch"](13);
127
+ console.error('task_error>>>>>>>', _context.t0);
128
+ case 22:
129
+ _context.prev = 22;
130
+ // 将任务删除
131
+ _task = this.taskQueue.shift();
132
+ console.log('task_shift>>>>>>>', _task);
133
+ return _context.finish(22);
134
+ case 26:
135
+ _context.next = 30;
136
+ break;
137
+ case 28:
138
+ // 如果找不到对应的action,则删除任务
139
+ _task2 = this.taskQueue.shift();
140
+ console.log('task_action_not_found>>>>>>>', _task2);
141
+ case 30:
106
142
  _context.next = 6;
107
143
  break;
108
- case 17:
144
+ case 32:
109
145
  this.isRunning = false;
110
- case 18:
146
+ case 33:
111
147
  case "end":
112
148
  return _context.stop();
113
149
  }
114
- }, _callee, this);
150
+ }, _callee, this, [[13, 19, 22, 26]]);
115
151
  }));
116
152
  function run() {
117
153
  return _run.apply(this, arguments);
118
154
  }
119
155
  return run;
120
- }())
156
+ }()
157
+ /**
158
+ * 判定当前的任务是否依然存在
159
+ */
160
+ )
161
+ }, {
162
+ key: "isTaskExist",
163
+ value: function isTaskExist(uuid) {
164
+ return this.taskQueue.some(function (task) {
165
+ return (task === null || task === void 0 ? void 0 : task.uuid) === uuid;
166
+ });
167
+ }
121
168
  }]);
122
169
  return Tasks;
123
170
  }();
124
- export default Tasks;
125
-
126
- // const tasks = new Tasks(new Map([
127
- // ['查询客户', async () => {
128
- // console.log('action1');
129
- // // 1. 获取东西
130
- // }],
131
- // ['action2', async () => {
132
- // console.log('action2');
133
- // }],
134
- // ]));
135
-
136
- // const fn = (str: string) => {
137
-
138
- // if (str === '查询客户') {
139
- // tasks.addTask({ type: '查询客户' });
140
- // }
141
- // if (str === '查询客户') {
142
- // tasks.addTask({ type: '查询客户' });
143
- // }
144
- // if (str === '查询客户') {
145
- // tasks.addTask({ type: '查询客户' });
146
- // }
147
- // if (str === '查询客户') {
148
- // tasks.addTask({ type: '查询客户' });
149
- // }
150
- // }
171
+ export default Tasks;
@@ -73,7 +73,7 @@ declare class Watch {
73
73
  * @param event 事件名称
74
74
  * @returns 是否成功移除
75
75
  */
76
- clearEvent(watchKey: string): boolean;
76
+ clearEvent(watchKey: string): void;
77
77
  /**
78
78
  * 移除所有事件订阅
79
79
  */
@@ -221,7 +221,7 @@ var Watch = /*#__PURE__*/function () {
221
221
  // 禁用所有事件
222
222
  this.disabledAllEventByWatchKey(watchKey);
223
223
  // 删除监听列表
224
- return this.events.delete(watchKey);
224
+ this.events.delete(watchKey);
225
225
  }
226
226
 
227
227
  /**
@@ -8,6 +8,7 @@ export declare class ProductList extends BaseModule implements Module {
8
8
  protected defaultVersion: string;
9
9
  private store;
10
10
  private request;
11
+ private otherParams;
11
12
  constructor(name?: string, version?: string);
12
13
  initialize(core: PisellCore, options: any): Promise<void>;
13
14
  storeChange(path?: string, value?: any): Promise<void>;
@@ -33,11 +33,13 @@ var ProductList = class extends import_BaseModule.BaseModule {
33
33
  super(name, version);
34
34
  this.defaultName = "productList";
35
35
  this.defaultVersion = "1.0.0";
36
+ this.otherParams = {};
36
37
  }
37
38
  async initialize(core, options) {
38
39
  var _a;
39
40
  this.core = core;
40
41
  this.store = options.store;
42
+ this.otherParams = options.otherParams || {};
41
43
  if (Array.isArray((_a = options.initialState) == null ? void 0 : _a.list)) {
42
44
  this.store.list = options.initialState.list;
43
45
  this.core.effects.emit(`${this.name}:changed`, this.store.list);
@@ -76,7 +78,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
76
78
  cacheId,
77
79
  with_schedule
78
80
  }) {
79
- var _a;
81
+ var _a, _b;
80
82
  let userPlugin = this.core.getPlugin("user");
81
83
  let customer_id = void 0;
82
84
  try {
@@ -111,7 +113,8 @@ var ProductList = class extends import_BaseModule.BaseModule {
111
113
  // client_schedule_ids: schedule_ids,
112
114
  schedule_date,
113
115
  with_schedule,
114
- schedule_datetime
116
+ schedule_datetime,
117
+ application_code: (_b = this.otherParams) == null ? void 0 : _b.channel
115
118
  },
116
119
  { useCache: true }
117
120
  );
@@ -215,7 +215,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
215
215
  // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
216
216
  metadata: {
217
217
  ...resourcesMap[id].metadata,
218
- combined_resource: resourcesMap[id].combined_resource
218
+ combined_resource: resourcesMap[id].combined_resource,
219
+ form_name: item.title,
220
+ resource_name: resourcesMap[id].main_field
219
221
  }
220
222
  })
221
223
  );
@@ -230,7 +232,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
230
232
  children: combiningResources,
231
233
  metadata: {
232
234
  ...resourcesMap[d].metadata,
233
- combined_resource: resourcesMap[d].combined_resource
235
+ combined_resource: resourcesMap[d].combined_resource,
236
+ form_name: item.title,
237
+ resource_name: resourcesMap[d].main_field
234
238
  }
235
239
  })
236
240
  );
@@ -259,7 +263,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
259
263
  // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
260
264
  metadata: {
261
265
  ...resourcesMap[id].metadata,
262
- combined_resource: resourcesMap[id].combined_resource
266
+ combined_resource: resourcesMap[id].combined_resource,
267
+ form_name: item.title,
268
+ resource_name: resourcesMap[id].main_field
263
269
  }
264
270
  })
265
271
  );
@@ -275,7 +281,9 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
275
281
  children: combiningResources,
276
282
  metadata: {
277
283
  ...resourcesMap[d].metadata,
278
- combined_resource: resourcesMap[d].combined_resource
284
+ combined_resource: resourcesMap[d].combined_resource,
285
+ form_name: item.title,
286
+ resource_name: resourcesMap[d].main_field
279
287
  }
280
288
  })
281
289
  );
@@ -138,6 +138,18 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
138
138
  activateCamera(data?: {
139
139
  [key: string]: any;
140
140
  }): void;
141
+ /**
142
+ * 禁用所有扫描监听
143
+ */
144
+ disableAllScanListeners(): void;
145
+ /**
146
+ * 启用所有扫描监听
147
+ */
148
+ enableAllScanListeners(): void;
149
+ /**
150
+ * 清空所有扫描监听对应的任务执行队列
151
+ */
152
+ clearAllScanListenersTaskQueue(): void;
141
153
  /**
142
154
  * 设置其他参数
143
155
  * @param params 参数
@@ -338,6 +338,24 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
338
338
  data
339
339
  });
340
340
  }
341
+ /**
342
+ * 禁用所有扫描监听
343
+ */
344
+ disableAllScanListeners() {
345
+ this.scan.disableAllListeners();
346
+ }
347
+ /**
348
+ * 启用所有扫描监听
349
+ */
350
+ enableAllScanListeners() {
351
+ this.scan.enableAllListeners();
352
+ }
353
+ /**
354
+ * 清空所有扫描监听对应的任务执行队列
355
+ */
356
+ clearAllScanListenersTaskQueue() {
357
+ this.scan.clearTaskQueue();
358
+ }
341
359
  /**
342
360
  * 设置其他参数
343
361
  * @param params 参数
@@ -369,6 +387,7 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
369
387
  (_e = this.store.order) == null ? void 0 : _e.destroy();
370
388
  this.core.effects.offByModuleDestroy(this.name);
371
389
  this.core.unregisterModule(this);
390
+ this.scan.removeAllListeners();
372
391
  import_scanCache.default.clear();
373
392
  }
374
393
  };
@@ -18,6 +18,20 @@ export default class Scan {
18
18
  private watchKey;
19
19
  private listenerConfig;
20
20
  constructor(solution: BookingTicketImpl, watchKey: string);
21
+ /**
22
+ * 处理扫码事件
23
+ * @param eventKey 事件key
24
+ * @param value 扫码结果
25
+ */
26
+ handleScan(result: {
27
+ type: string;
28
+ value: string;
29
+ }): void;
30
+ /**
31
+ * 生成uuid
32
+ * @returns uuid
33
+ */
34
+ generateUuid(): string;
21
35
  /**
22
36
  * 添加扫码信息监听
23
37
  * @param watchKey 监听的key
@@ -33,14 +47,22 @@ export default class Scan {
33
47
  */
34
48
  removeListener(event: WatchEventItem): void;
35
49
  /**
36
- * 处理扫码事件
50
+ * 移除所有监听
51
+ */
52
+ removeAllListeners(): void;
53
+ /**
54
+ * 启用所有监听
55
+ */
56
+ enableAllListeners(): void;
57
+ /**
58
+ * 禁用所有监听,并清空任务执行队列
59
+ */
60
+ disableAllListeners(): void;
61
+ /**
62
+ * 清空监听对应的任务执行队列,不传入eventKey则清空所有监听对应的任务执行队列
37
63
  * @param eventKey 事件key
38
- * @param value 扫码结果
39
64
  */
40
- handleScan(value: {
41
- type: string;
42
- value: string;
43
- }): void;
65
+ clearTaskQueue(eventKey?: string): void;
44
66
  /**
45
67
  * 获取监听配置
46
68
  * @param eventKey 事件key
@@ -51,9 +73,9 @@ export default class Scan {
51
73
  task: Tasks;
52
74
  } | undefined;
53
75
  /**
54
- * 处理扫码结果
76
+ * 扫码任务执行函数
55
77
  * @param args 参数
56
78
  */
57
- handleScanResultFn(...args: any[]): Promise<void>;
79
+ scanTaskAction(...args: any[]): Promise<void>;
58
80
  }
59
81
  export {};
@@ -55,6 +55,33 @@ var Scan = class {
55
55
  }
56
56
  );
57
57
  }
58
+ /**
59
+ * 处理扫码事件
60
+ * @param eventKey 事件key
61
+ * @param value 扫码结果
62
+ */
63
+ handleScan(result) {
64
+ const lastEnableEventKey = import_watch.default.getLastEnableEventKey(this.watchKey);
65
+ if (lastEnableEventKey) {
66
+ const listenerConfig = this.listenerConfig.get(lastEnableEventKey);
67
+ if (listenerConfig) {
68
+ listenerConfig.task.addTask({
69
+ uuid: this.generateUuid(),
70
+ type: lastEnableEventKey,
71
+ actionParams: {
72
+ scanResult: result
73
+ }
74
+ });
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * 生成uuid
80
+ * @returns uuid
81
+ */
82
+ generateUuid() {
83
+ return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
84
+ }
58
85
  /**
59
86
  * 添加扫码信息监听
60
87
  * @param watchKey 监听的key
@@ -65,7 +92,7 @@ var Scan = class {
65
92
  const task = new import_task.default();
66
93
  task.addAction(
67
94
  event.key,
68
- (...args) => this.handleScanResultFn(event.key, ...args)
95
+ (...args) => this.scanTaskAction(event.key, ...args)
69
96
  );
70
97
  this.listenerConfig.set(event.key, { scanCallback, task });
71
98
  return {
@@ -80,28 +107,54 @@ var Scan = class {
80
107
  * @param event 事件
81
108
  */
82
109
  removeListener(event) {
83
- var _a;
110
+ var _a, _b;
84
111
  import_watch.default.unsubscribe(this.watchKey, event);
85
- (_a = this.listenerConfig.get(event.key)) == null ? void 0 : _a.task.clear();
112
+ (_b = (_a = this.listenerConfig.get(event.key)) == null ? void 0 : _a.task) == null ? void 0 : _b.clear();
86
113
  this.listenerConfig.delete(event.key);
87
114
  }
88
115
  /**
89
- * 处理扫码事件
116
+ * 移除所有监听
117
+ */
118
+ removeAllListeners() {
119
+ var _a, _b, _c, _d;
120
+ import_watch.default.clearEvent(this.watchKey);
121
+ (_b = (_a = this.listenerConfig) == null ? void 0 : _a.forEach) == null ? void 0 : _b.call(_a, (item) => {
122
+ var _a2;
123
+ (_a2 = item == null ? void 0 : item.task) == null ? void 0 : _a2.clear();
124
+ });
125
+ (_d = (_c = this.listenerConfig) == null ? void 0 : _c.clear) == null ? void 0 : _d.call(_c);
126
+ }
127
+ /**
128
+ * 启用所有监听
129
+ */
130
+ enableAllListeners() {
131
+ import_watch.default.enableAllEventByWatchKey(this.watchKey);
132
+ }
133
+ /**
134
+ * 禁用所有监听,并清空任务执行队列
135
+ */
136
+ disableAllListeners() {
137
+ var _a, _b;
138
+ import_watch.default.disabledAllEventByWatchKey(this.watchKey);
139
+ (_b = (_a = this.listenerConfig) == null ? void 0 : _a.forEach) == null ? void 0 : _b.call(_a, (item) => {
140
+ var _a2;
141
+ (_a2 = item == null ? void 0 : item.task) == null ? void 0 : _a2.clearTaskQueue();
142
+ });
143
+ }
144
+ /**
145
+ * 清空监听对应的任务执行队列,不传入eventKey则清空所有监听对应的任务执行队列
90
146
  * @param eventKey 事件key
91
- * @param value 扫码结果
92
147
  */
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
- }
148
+ clearTaskQueue(eventKey) {
149
+ var _a, _b, _c;
150
+ console.log("clearTaskQueue>>>>>>>", eventKey);
151
+ if (eventKey) {
152
+ (_a = this.listenerConfig.get(eventKey)) == null ? void 0 : _a.task.clearTaskQueue();
153
+ } else {
154
+ (_c = (_b = this.listenerConfig) == null ? void 0 : _b.forEach) == null ? void 0 : _c.call(_b, (item) => {
155
+ var _a2;
156
+ (_a2 = item == null ? void 0 : item.task) == null ? void 0 : _a2.clearTaskQueue();
157
+ });
105
158
  }
106
159
  }
107
160
  /**
@@ -114,35 +167,43 @@ var Scan = class {
114
167
  return (_a = this.listenerConfig) == null ? void 0 : _a.get(eventKey);
115
168
  }
116
169
  /**
117
- * 处理扫码结果
170
+ * 扫码任务执行函数
118
171
  * @param args 参数
119
172
  */
120
- async handleScanResultFn(...args) {
121
- var _a;
173
+ async scanTaskAction(...args) {
122
174
  const [eventKey, other] = args;
123
175
  const { type, value, data } = (other == null ? void 0 : other.scanResult) || {};
124
- const scanCallback = (_a = this.getListenerConfig(eventKey)) == null ? void 0 : _a.scanCallback;
176
+ const taskItemUuid = other == null ? void 0 : other.uuid;
177
+ const { scanCallback, task } = this.getListenerConfig(eventKey) || {};
125
178
  if (scanCallback) {
126
179
  try {
127
180
  const result = await scanCallback({ type, value });
128
181
  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
- });
182
+ if (taskItemUuid && (task == null ? void 0 : task.isTaskExist(taskItemUuid))) {
183
+ import_watch.default.publishByEventKey(this.watchKey, eventKey, {
184
+ type: eventKey,
185
+ status: "success",
186
+ scanType: type,
187
+ scanCode: value,
188
+ scanData: data,
189
+ result
190
+ });
191
+ } else {
192
+ console.warn(`${eventKey}_result_task_not_exist>>>>>>>`, task);
193
+ }
137
194
  } catch (error) {
138
195
  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
- });
196
+ if (taskItemUuid && (task == null ? void 0 : task.isTaskExist(taskItemUuid))) {
197
+ import_watch.default.publishByEventKey(this.watchKey, eventKey, {
198
+ type: eventKey,
199
+ status: "failed",
200
+ scanType: type,
201
+ scanCode: value,
202
+ scanData: data
203
+ });
204
+ } else {
205
+ console.warn(`${eventKey}_result_error_task_not_exist>>>>>>>`, task);
206
+ }
146
207
  }
147
208
  }
148
209
  }
@@ -1,5 +1,6 @@
1
1
  type Action = (...args: any[]) => Promise<any>;
2
2
  type Task = {
3
+ uuid: string;
3
4
  type: string;
4
5
  actionParams?: Record<string, any>;
5
6
  };
@@ -9,9 +10,13 @@ declare class Tasks {
9
10
  isRunning: boolean;
10
11
  constructor(actions?: Map<string, Action>);
11
12
  /**
12
- * 清空任务队列
13
+ * 清空所有任务
13
14
  */
14
15
  clear(): void;
16
+ /**
17
+ * 清空任务执行队列
18
+ */
19
+ clearTaskQueue(): void;
15
20
  /**
16
21
  * 添加action
17
22
  * @param name action名称
@@ -27,5 +32,9 @@ declare class Tasks {
27
32
  * 执行任务
28
33
  */
29
34
  run(): Promise<void>;
35
+ /**
36
+ * 判定当前的任务是否依然存在
37
+ */
38
+ isTaskExist(uuid: string): boolean;
30
39
  }
31
40
  export default Tasks;
package/lib/utils/task.js CHANGED
@@ -32,13 +32,20 @@ var Tasks = class {
32
32
  }
33
33
  }
34
34
  /**
35
- * 清空任务队列
35
+ * 清空所有任务
36
36
  */
37
37
  clear() {
38
38
  this.actions.clear();
39
39
  this.taskQueue = [];
40
40
  this.isRunning = false;
41
41
  }
42
+ /**
43
+ * 清空任务执行队列
44
+ */
45
+ clearTaskQueue() {
46
+ this.taskQueue = [];
47
+ this.isRunning = false;
48
+ }
42
49
  /**
43
50
  * 添加action
44
51
  * @param name action名称
@@ -59,6 +66,7 @@ var Tasks = class {
59
66
  * 执行任务
60
67
  */
61
68
  async run() {
69
+ var _a;
62
70
  if (this.isRunning) {
63
71
  return;
64
72
  }
@@ -68,17 +76,34 @@ var Tasks = class {
68
76
  }
69
77
  this.isRunning = true;
70
78
  while (this.taskQueue.length > 0) {
71
- const task = this.taskQueue.shift();
79
+ const task = (_a = this.taskQueue) == null ? void 0 : _a[0];
72
80
  if (!task) {
73
81
  this.isRunning = false;
74
82
  return;
75
83
  }
76
84
  const action = this.actions.get(task.type);
77
85
  if (action) {
78
- await action((task == null ? void 0 : task.actionParams) || {});
86
+ try {
87
+ await action({ ...(task == null ? void 0 : task.actionParams) || {}, uuid: task == null ? void 0 : task.uuid });
88
+ console.log("task_success>>>>>>>", task);
89
+ } catch (error) {
90
+ console.error("task_error>>>>>>>", error);
91
+ } finally {
92
+ const _task = this.taskQueue.shift();
93
+ console.log("task_shift>>>>>>>", _task);
94
+ }
95
+ } else {
96
+ const _task = this.taskQueue.shift();
97
+ console.log("task_action_not_found>>>>>>>", _task);
79
98
  }
80
99
  }
81
100
  this.isRunning = false;
82
101
  }
102
+ /**
103
+ * 判定当前的任务是否依然存在
104
+ */
105
+ isTaskExist(uuid) {
106
+ return this.taskQueue.some((task) => (task == null ? void 0 : task.uuid) === uuid);
107
+ }
83
108
  };
84
109
  var task_default = Tasks;
@@ -73,7 +73,7 @@ declare class Watch {
73
73
  * @param event 事件名称
74
74
  * @returns 是否成功移除
75
75
  */
76
- clearEvent(watchKey: string): boolean;
76
+ clearEvent(watchKey: string): void;
77
77
  /**
78
78
  * 移除所有事件订阅
79
79
  */
@@ -170,7 +170,7 @@ var Watch = class {
170
170
  */
171
171
  clearEvent(watchKey) {
172
172
  this.disabledAllEventByWatchKey(watchKey);
173
- return this.events.delete(watchKey);
173
+ this.events.delete(watchKey);
174
174
  }
175
175
  /**
176
176
  * 移除所有事件订阅
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.52",
4
+ "version": "1.0.54",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",