@pisell/private-materials 6.5.8 → 6.5.10

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.
@@ -165,7 +165,7 @@ var VoucherCard = function VoucherCard(props) {
165
165
  productListToValue(val.productList);
166
166
  }
167
167
  }, {
168
- wait: 500
168
+ wait: 1000
169
169
  }),
170
170
  run = _useDebounceFn.run;
171
171
 
@@ -47,7 +47,7 @@ var productListSetting = {
47
47
  isStock: 0
48
48
  };
49
49
  var AddSerivce = function AddSerivce(props) {
50
- var _context$appHelper, _context$appHelper$ge, _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _state$bookingConfig2, _state$client2;
50
+ var _context$appHelper, _context$appHelper$ge, _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _state$service, _state$bookingConfig2, _state$client2;
51
51
  var onEdit = props.onEdit,
52
52
  state = props.state,
53
53
  dispatch = props.dispatch,
@@ -75,6 +75,30 @@ var AddSerivce = function AddSerivce(props) {
75
75
  var stateRef = useRef(state);
76
76
  stateRef.current = state;
77
77
  var prerenderCompletedRef = useRef(false);
78
+ var latestServiceValueRef = useRef((state === null || state === void 0 || (_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.value) || []);
79
+ var lastOperationTimeRef = useRef(0);
80
+ var isInFastClickMode = function isInFastClickMode() {
81
+ var now = Date.now();
82
+ return now - lastOperationTimeRef.current < 2000;
83
+ };
84
+ var getCurrentServiceValue = function getCurrentServiceValue() {
85
+ if (isInFastClickMode()) {
86
+ var _stateRef$current;
87
+ return latestServiceValueRef.current || ((_stateRef$current = stateRef.current) === null || _stateRef$current === void 0 || (_stateRef$current = _stateRef$current.service) === null || _stateRef$current === void 0 ? void 0 : _stateRef$current.value) || [];
88
+ } else {
89
+ var _state$service2;
90
+ var stateValue = (state === null || state === void 0 || (_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.value) || [];
91
+ latestServiceValueRef.current = null;
92
+ return stateValue;
93
+ }
94
+ };
95
+
96
+ // useEffect(() => {
97
+ // if (!isInFastClickMode()) {
98
+ // latestServiceValueRef.current = null;
99
+ // }
100
+ // }, [state?.service?.value]);
101
+
78
102
  var _useProducts = useProducts(),
79
103
  getProducts = _useProducts.getProducts,
80
104
  products = _useProducts.products,
@@ -259,6 +283,7 @@ var AddSerivce = function AddSerivce(props) {
259
283
 
260
284
  // 执行原始的回调函数
261
285
  originalCallback(finalCacheValues, '', item, true);
286
+ lastOperationTimeRef.current = Date.now();
262
287
  });
263
288
 
264
289
  // 为每个商品单独创建防抖函数
@@ -277,8 +302,8 @@ var AddSerivce = function AddSerivce(props) {
277
302
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'select';
278
303
  console.log('handleSelectProduct');
279
304
  if (!isNormalProductByDurationSchedule(item)) {
280
- var _state$service;
281
- if (!Array.isArray((_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.resourcesOrigin) || !state.service.resourcesOrigin.length) {
305
+ var _state$service3;
306
+ if (!Array.isArray((_state$service3 = state.service) === null || _state$service3 === void 0 ? void 0 : _state$service3.resourcesOrigin) || !state.service.resourcesOrigin.length) {
282
307
  dispatch({
283
308
  type: 'setService',
284
309
  payload: _objectSpread(_objectSpread({}, stateRef.current.service), {}, {
@@ -316,7 +341,7 @@ var AddSerivce = function AddSerivce(props) {
316
341
  }
317
342
  var callback = /*#__PURE__*/function () {
318
343
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e, extension_type, detail, notShowToast) {
319
- var data, _currentItem, _detail, other, cacheItem, _total, _isEdit, _state$service$cacheI, _addService2, _list, quantity, _context$appHelper$ut4, _context$appHelper$ut5, val, sendData, _window$openBookingEd, _window;
344
+ var data, _currentItem, _detail, other, cacheItem, _total, _isEdit, _state$service$cacheI, val, _addService2, _list, quantity, _context$appHelper$ut4, _context$appHelper$ut5, _val, sendData, _window$openBookingEd, _window;
320
345
  return _regeneratorRuntime().wrap(function _callee$(_context) {
321
346
  while (1) switch (_context.prev = _context.next) {
322
347
  case 0:
@@ -392,7 +417,10 @@ var AddSerivce = function AddSerivce(props) {
392
417
  if (cacheItem.autoClose) {
393
418
  cacheItem.autoClose = false;
394
419
  cacheItem._serviceKey = genServiceKey(cacheItem);
395
- _addService2 = addService(_toConsumableArray(stateRef.current.service.value), cacheItem, state), _list = _addService2.list, quantity = _addService2.quantity;
420
+ val = getCurrentServiceValue();
421
+ _addService2 = addService(_toConsumableArray(val), cacheItem, state), _list = _addService2.list, quantity = _addService2.quantity; // 更新ref以确保后续快速操作时使用最新值
422
+ latestServiceValueRef.current = _list;
423
+ lastOperationTimeRef.current = Date.now();
396
424
  if (!notShowToast) {
397
425
  handleAddToast(cacheItem.title, quantity || 1);
398
426
  }
@@ -403,7 +431,7 @@ var AddSerivce = function AddSerivce(props) {
403
431
  }));
404
432
  try {
405
433
  if (((_context$appHelper$ut4 = context.appHelper.utils.store) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut4.getState) === null || _context$appHelper$ut5 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut5.call(_context$appHelper$ut4)) === null || _context$appHelper$ut5 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut5.global) === null || _context$appHelper$ut5 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut5.globalConfig) === null || _context$appHelper$ut5 === void 0 ? void 0 : _context$appHelper$ut5.id) === 2155) {
406
- val = _list === null || _list === void 0 ? void 0 : _list.map(function (s) {
434
+ _val = _list === null || _list === void 0 ? void 0 : _list.map(function (s) {
407
435
  return {
408
436
  product_id: s === null || s === void 0 ? void 0 : s.product_id,
409
437
  detailId: s === null || s === void 0 ? void 0 : s.id,
@@ -421,7 +449,7 @@ var AddSerivce = function AddSerivce(props) {
421
449
  detailProductId: _detail === null || _detail === void 0 ? void 0 : _detail.product_id,
422
450
  product_name: _currentItem === null || _currentItem === void 0 ? void 0 : _currentItem.title,
423
451
  price: _detail === null || _detail === void 0 ? void 0 : _detail.price,
424
- serviceVal: val
452
+ serviceVal: _val
425
453
  };
426
454
  sendWarningLog({
427
455
  title: 'addService',
@@ -170,7 +170,7 @@ var VoucherCard = (props) => {
170
170
  productListToValue(val.productList);
171
171
  }
172
172
  },
173
- { wait: 500 }
173
+ { wait: 1e3 }
174
174
  );
175
175
  (0, import_react.useEffect)(() => {
176
176
  run();
@@ -62,7 +62,7 @@ var productListSetting = {
62
62
  isStock: 0
63
63
  };
64
64
  var AddSerivce = (props) => {
65
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
65
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
66
66
  const { onEdit, state, dispatch, renderMode = "current", onPrerenderComplete } = props;
67
67
  const context = (0, import_useEngineContext.default)();
68
68
  const notAvailableRef = (0, import_react.useRef)(null);
@@ -84,6 +84,22 @@ var AddSerivce = (props) => {
84
84
  const stateRef = (0, import_react.useRef)(state);
85
85
  stateRef.current = state;
86
86
  const prerenderCompletedRef = (0, import_react.useRef)(false);
87
+ const latestServiceValueRef = (0, import_react.useRef)(((_j = state == null ? void 0 : state.service) == null ? void 0 : _j.value) || []);
88
+ const lastOperationTimeRef = (0, import_react.useRef)(0);
89
+ const isInFastClickMode = () => {
90
+ const now = Date.now();
91
+ return now - lastOperationTimeRef.current < 2e3;
92
+ };
93
+ const getCurrentServiceValue = () => {
94
+ var _a2, _b2, _c2;
95
+ if (isInFastClickMode()) {
96
+ return latestServiceValueRef.current || ((_b2 = (_a2 = stateRef.current) == null ? void 0 : _a2.service) == null ? void 0 : _b2.value) || [];
97
+ } else {
98
+ const stateValue = ((_c2 = state == null ? void 0 : state.service) == null ? void 0 : _c2.value) || [];
99
+ latestServiceValueRef.current = null;
100
+ return stateValue;
101
+ }
102
+ };
87
103
  const { getProducts, products, loading } = (0, import_pisellos.useProducts)();
88
104
  (0, import_react.useEffect)(() => {
89
105
  return () => {
@@ -118,11 +134,11 @@ var AddSerivce = (props) => {
118
134
  const menuList = (0, import_react.useMemo)(() => {
119
135
  var _a2, _b2, _c2;
120
136
  return ((_c2 = (_b2 = (_a2 = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.menu_list_tab) == null ? void 0 : _c2.menu_list) || [];
121
- }, [(_j = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _j.config]);
137
+ }, [(_k = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _k.config]);
122
138
  const customerId = (0, import_react.useMemo)(() => {
123
139
  var _a2, _b2;
124
140
  return ((_b2 = (_a2 = state.client) == null ? void 0 : _a2.value) == null ? void 0 : _b2.id) || void 0;
125
- }, [(_l = (_k = state.client) == null ? void 0 : _k.value) == null ? void 0 : _l.id]);
141
+ }, [(_m = (_l = state.client) == null ? void 0 : _l.value) == null ? void 0 : _m.id]);
126
142
  const scanAddService = (0, import_ahooks.useMemoizedFn)((list, code) => {
127
143
  let newService = [...state.service.value];
128
144
  list.forEach((item) => {
@@ -171,6 +187,7 @@ var AddSerivce = (props) => {
171
187
  delete clickCountRef.current[productId];
172
188
  delete debounceTimersRef.current[productId];
173
189
  originalCallback(finalCacheValues, "", item, true);
190
+ lastOperationTimeRef.current = Date.now();
174
191
  }
175
192
  );
176
193
  const debouncedExecuteCacheValues = (0, import_ahooks.useMemoizedFn)(
@@ -278,11 +295,14 @@ var AddSerivce = (props) => {
278
295
  if (cacheItem.autoClose) {
279
296
  cacheItem.autoClose = false;
280
297
  cacheItem._serviceKey = (0, import_utils6.genServiceKey)(cacheItem);
298
+ const val = getCurrentServiceValue();
281
299
  let { list: _list, quantity } = (0, import_utils6.addService)(
282
- [...stateRef.current.service.value],
300
+ [...val],
283
301
  cacheItem,
284
302
  state
285
303
  );
304
+ latestServiceValueRef.current = _list;
305
+ lastOperationTimeRef.current = Date.now();
286
306
  if (!notShowToast) {
287
307
  handleAddToast(cacheItem.title, quantity || 1);
288
308
  }
@@ -295,7 +315,7 @@ var AddSerivce = (props) => {
295
315
  );
296
316
  try {
297
317
  if (((_f2 = (_e2 = (_d3 = (_c3 = (_b3 = context.appHelper.utils.store) == null ? void 0 : _b3.getState) == null ? void 0 : _c3.call(_b3)) == null ? void 0 : _d3.global) == null ? void 0 : _e2.globalConfig) == null ? void 0 : _f2.id) === 2155) {
298
- const val = _list == null ? void 0 : _list.map((s) => {
318
+ const val2 = _list == null ? void 0 : _list.map((s) => {
299
319
  return {
300
320
  product_id: s == null ? void 0 : s.product_id,
301
321
  detailId: s == null ? void 0 : s.id,
@@ -313,7 +333,7 @@ var AddSerivce = (props) => {
313
333
  detailProductId: _detail == null ? void 0 : _detail.product_id,
314
334
  product_name: _currentItem == null ? void 0 : _currentItem.title,
315
335
  price: _detail == null ? void 0 : _detail.price,
316
- serviceVal: val
336
+ serviceVal: val2
317
337
  };
318
338
  (0, import_utils.sendWarningLog)({
319
339
  title: "addService",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.5.8",
3
+ "version": "6.5.10",
4
4
  "scripts": {
5
5
  "dev": "father dev",
6
6
  "build": "father build",
@@ -1,7 +0,0 @@
1
- import './index.less';
2
- export declare const _formatBookingDetail: (data: any, modalState: any) => any;
3
- interface TicketBookingProps {
4
- onPrerenderComplete?: () => void;
5
- }
6
- declare const TicketBooking: (props: TicketBookingProps) => JSX.Element;
7
- export default TicketBooking;
@@ -1,7 +0,0 @@
1
- import './index.less';
2
- export declare const _formatBookingDetail: (data: any, modalState: any) => any;
3
- interface TicketBookingProps {
4
- onPrerenderComplete?: () => void;
5
- }
6
- declare const TicketBooking: (props: TicketBookingProps) => JSX.Element;
7
- export default TicketBooking;