@pisell/private-materials 6.4.69 → 6.4.71

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.
@@ -117,7 +117,7 @@ export var formatProductBundle = function formatProductBundle(bundle) {
117
117
  // checkout 2.0 新增
118
118
  "price_type": d === null || d === void 0 ? void 0 : d.price_type,
119
119
  // checkout 2.0 新增
120
- "custom_price": new Decimal(d === null || d === void 0 ? void 0 : d.price).sub(option_price).toNumber().toFixed(2),
120
+ "custom_price": Math.abs(new Decimal(d === null || d === void 0 ? void 0 : d.price).sub(option_price).toNumber()).toFixed(2),
121
121
  "custom_price_type": d === null || d === void 0 ? void 0 : d.price_type,
122
122
  "option": option
123
123
  };
@@ -4,6 +4,6 @@ declare const useSendModal: (bookingId?: number) => {
4
4
  setOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
5
5
  handleOpen: () => void;
6
6
  handleValuesChange: (val: any) => void;
7
- handleOk: (values: SendModalValues) => Promise<any>;
7
+ handleOk: (values: SendModalValues) => Promise<boolean | undefined>;
8
8
  };
9
9
  export default useSendModal;
@@ -350,11 +350,6 @@ var CartClientCard = /*#__PURE__*/forwardRef(function (_ref, ref) {
350
350
  setHandleSetClient(handleSetClient);
351
351
  }
352
352
  }, [isActive]);
353
- useEffect(function () {
354
- return function () {
355
- setHandleSetClient(null);
356
- };
357
- }, [isActive]);
358
353
  var tags = useMemo(function () {
359
354
  var _latest_wallet_detail;
360
355
  if (!selectedCustomer) return;
@@ -17,7 +17,7 @@ export declare const useWalletPass: (props: {
17
17
  cardData: any;
18
18
  handleSelectWallet: (value: number[]) => void;
19
19
  selectedWalletIds: any[];
20
- expiredWalletIds: any;
20
+ expiredWalletIds: any[];
21
21
  expiredWalletData: any;
22
22
  disabledWalletData: any[];
23
23
  clearAllSelectedWallet: () => void;
@@ -19,7 +19,7 @@ export declare const useStoreRef: <T extends {
19
19
  readonly netRef: React.MutableRefObject<boolean | undefined>;
20
20
  readonly symbolRef: React.MutableRefObject<string>;
21
21
  readonly amountRef: React.MutableRefObject<string | number>;
22
- readonly eftposRef: React.MutableRefObject<"stripe" | "tyro" | "windcave" | "payo" | "linkly">;
22
+ readonly eftposRef: React.MutableRefObject<"stripe" | "payo" | "tyro" | "windcave" | "linkly">;
23
23
  readonly clientRef: React.MutableRefObject<ClientEnum>;
24
24
  readonly dataRef: React.MutableRefObject<import("./store").State>;
25
25
  };
@@ -297,8 +297,8 @@ export declare const backUpFree: (payload: Partial<State>) => {
297
297
  amount?: string | number | undefined;
298
298
  mode?: "pay" | "refund" | "fullPay" | "query" | undefined;
299
299
  order_id?: string | number | undefined;
300
- eftpos?: "stripe" | "tyro" | "windcave" | "payo" | "linkly" | undefined;
301
- action?: "amount" | "pay" | "deviceList" | undefined;
300
+ eftpos?: "stripe" | "payo" | "tyro" | "windcave" | "linkly" | undefined;
301
+ action?: "pay" | "amount" | "deviceList" | undefined;
302
302
  key?: number | undefined;
303
303
  step?: number | undefined;
304
304
  title?: string | undefined;
@@ -13,7 +13,15 @@ import { useBookingTicket } from "./bookingTicket";
13
13
  import { useState, useRef } from 'react';
14
14
  import { useOsKey } from "../../context/OsKeyContext";
15
15
  import { getProductCache, setProductCache } from "../../utils/productCache";
16
+ import { useEngineContext } from "../../../../hooks";
17
+ // 等待函数
18
+ var sleep = function sleep(ms) {
19
+ return new Promise(function (resolve) {
20
+ return setTimeout(resolve, ms);
21
+ });
22
+ };
16
23
  export var useProducts = function useProducts(notAvailableRef) {
24
+ var _context$appHelper;
17
25
  var bookingTicket = useBookingTicket();
18
26
  var osKey = useOsKey();
19
27
  var _useState = useState([]),
@@ -26,17 +34,21 @@ export var useProducts = function useProducts(notAvailableRef) {
26
34
  setLoading = _useState4[1];
27
35
  var isFirstLoadRef = useRef(true);
28
36
  var isFirstLoadDataRef = useRef(true);
37
+ var context = useEngineContext();
38
+ var _ref = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {},
39
+ getApp = _ref.getApp;
40
+ var app = getApp();
29
41
  var getProducts = useMemoizedFn( /*#__PURE__*/function () {
30
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
31
- var cachedProducts, freshProducts, _notAvailableRef$curr;
42
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
43
+ var cachedProducts, maxRetries, lastError, freshProducts, attempt, _app$logger, _app$logger$addLog, _app$logger2, _app$logger3, _app$logger3$addLog, _lastError, _notAvailableRef$curr;
32
44
  return _regeneratorRuntime().wrap(function _callee$(_context) {
33
45
  while (1) switch (_context.prev = _context.next) {
34
46
  case 0:
35
47
  // 1. 如果是首次加载,尝试从缓存中获取数据
36
48
  if (isFirstLoadRef.current && osKey) {
37
49
  cachedProducts = getProductCache(osKey);
38
- if (cachedProducts) {
39
- // 先展示缓存数据
50
+ if (cachedProducts && cachedProducts.length > 0) {
51
+ // 先展示缓存数据(只有非空时才展示)
40
52
  setProducts(cachedProducts);
41
53
  setLoading(false);
42
54
  }
@@ -45,45 +57,107 @@ export var useProducts = function useProducts(notAvailableRef) {
45
57
  setLoading(true);
46
58
  }
47
59
 
48
- // 2. 无论是否有缓存,都调用接口获取最新数据
49
- _context.prev = 1;
50
- _context.next = 4;
60
+ // 2. 重试逻辑:最多尝试3次,每次等待1秒
61
+ maxRetries = 3;
62
+ lastError = null;
63
+ freshProducts = [];
64
+ attempt = 1;
65
+ case 5:
66
+ if (!(attempt <= maxRetries)) {
67
+ _context.next = 33;
68
+ break;
69
+ }
70
+ _context.prev = 6;
71
+ console.log("[ProductCache] \u5C1D\u8BD5\u52A0\u8F7D\u6570\u636E\uFF0C\u7B2C ".concat(attempt, "/").concat(maxRetries, " \u6B21"));
72
+ _context.next = 10;
51
73
  return bookingTicket.loadProducts(params);
52
- case 4:
74
+ case 10:
53
75
  freshProducts = _context.sent;
54
- isFirstLoadDataRef.current = false;
55
- // 3. 更新展示数据
56
- setProducts(freshProducts);
76
+ if (!(freshProducts && freshProducts.length > 0)) {
77
+ _context.next = 14;
78
+ break;
79
+ }
80
+ console.log("[ProductCache] \u7B2C ".concat(attempt, " \u6B21\u5C1D\u8BD5\u6210\u529F\uFF0C\u83B7\u53D6\u5230 ").concat(freshProducts.length, " \u6761\u6570\u636E"));
81
+ return _context.abrupt("break", 33);
82
+ case 14:
83
+ // 数据为空,记录并准备重试
84
+ console.log("[ProductCache] \u7B2C ".concat(attempt, " \u6B21\u5C1D\u8BD5\u8FD4\u56DE\u7A7A\u6570\u636E"));
85
+ if (!(attempt < maxRetries)) {
86
+ _context.next = 19;
87
+ break;
88
+ }
89
+ console.log("[ProductCache] \u7B49\u5F85 1 \u79D2\u540E\u91CD\u8BD5...");
90
+ _context.next = 19;
91
+ return sleep(1000);
92
+ case 19:
93
+ _context.next = 30;
94
+ break;
95
+ case 21:
96
+ _context.prev = 21;
97
+ _context.t0 = _context["catch"](6);
98
+ lastError = _context.t0;
99
+ console.log("[ProductCache] \u7B2C ".concat(attempt, " \u6B21\u5C1D\u8BD5\u5931\u8D25:"), _context.t0);
100
+ app === null || app === void 0 || (_app$logger = app.logger) === null || _app$logger === void 0 || (_app$logger$addLog = (_app$logger2 = _app$logger).addLog) === null || _app$logger$addLog === void 0 || _app$logger$addLog.call(_app$logger2, {
101
+ type: 'info',
102
+ title: "[getProduct] bookingTicket.loadProducts error (attempt ".concat(attempt, "/").concat(maxRetries, ")"),
103
+ metadata: {
104
+ error: _context.t0,
105
+ attempt: attempt
106
+ }
107
+ });
57
108
 
58
- // 4. 将新数据缓存到 storage
59
- if (osKey) {
60
- setProductCache(osKey, freshProducts);
61
- console.log('[ProductCache] 已更新缓存');
109
+ // 如果还有重试机会,等待后继续
110
+ if (!(attempt < maxRetries)) {
111
+ _context.next = 30;
112
+ break;
62
113
  }
63
- _context.next = 16;
114
+ console.log("[ProductCache] \u7B49\u5F85 1 \u79D2\u540E\u91CD\u8BD5...");
115
+ _context.next = 30;
116
+ return sleep(1000);
117
+ case 30:
118
+ attempt++;
119
+ _context.next = 5;
64
120
  break;
65
- case 10:
66
- _context.prev = 10;
67
- _context.t0 = _context["catch"](1);
68
- // 只有在第一次加载或之前有数据时才显示 notAvailable
69
- if ((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.code) === 607100 && (isFirstLoadDataRef.current || products.length > 0)) {
70
- (_notAvailableRef$curr = notAvailableRef.current) === null || _notAvailableRef$curr === void 0 || _notAvailableRef$curr.open();
121
+ case 33:
122
+ // 3. 处理最终结果
123
+ if (freshProducts && freshProducts.length > 0) {
124
+ // 成功获取到数据
125
+ isFirstLoadDataRef.current = false;
126
+ setProducts(freshProducts);
127
+
128
+ // 将新数据缓存到 storage
129
+ if (osKey) {
130
+ setProductCache(osKey, freshProducts);
131
+ console.log('[ProductCache] 已更新缓存');
132
+ }
133
+ setLoading(false);
134
+ } else {
135
+ // 3次尝试后仍然没有数据
136
+ console.log('[ProductCache] 3次尝试后仍未获取到数据');
137
+ app === null || app === void 0 || (_app$logger3 = app.logger) === null || _app$logger3 === void 0 || (_app$logger3$addLog = _app$logger3.addLog) === null || _app$logger3$addLog === void 0 || _app$logger3$addLog.call(_app$logger3, {
138
+ type: 'error',
139
+ title: '[getProduct] 3次尝试后仍未获取到数据',
140
+ metadata: {
141
+ error: lastError
142
+ }
143
+ });
144
+
145
+ // 只有在第一次加载或之前有数据时才显示 notAvailable
146
+ if (((_lastError = lastError) === null || _lastError === void 0 ? void 0 : _lastError.code) === 607100 && (isFirstLoadDataRef.current || products.length > 0)) {
147
+ (_notAvailableRef$curr = notAvailableRef.current) === null || _notAvailableRef$curr === void 0 || _notAvailableRef$curr.open();
148
+ }
149
+ setLoading(false);
150
+ setProducts([]);
151
+ isFirstLoadDataRef.current = false;
71
152
  }
72
- setLoading(false);
73
- setProducts([]);
74
- isFirstLoadDataRef.current = false;
75
- case 16:
76
- _context.prev = 16;
77
- setLoading(false);
78
- return _context.finish(16);
79
- case 19:
153
+ case 34:
80
154
  case "end":
81
155
  return _context.stop();
82
156
  }
83
- }, _callee, null, [[1, 10, 16, 19]]);
157
+ }, _callee, null, [[6, 21]]);
84
158
  }));
85
159
  return function (_x) {
86
- return _ref.apply(this, arguments);
160
+ return _ref2.apply(this, arguments);
87
161
  };
88
162
  }());
89
163
  return {
@@ -120,7 +120,7 @@ var formatProductBundle = (bundle) => {
120
120
  // checkout 2.0 新增
121
121
  "price_type": d == null ? void 0 : d.price_type,
122
122
  // checkout 2.0 新增
123
- "custom_price": new import_decimal.default(d == null ? void 0 : d.price).sub(option_price).toNumber().toFixed(2),
123
+ "custom_price": Math.abs(new import_decimal.default(d == null ? void 0 : d.price).sub(option_price).toNumber()).toFixed(2),
124
124
  "custom_price_type": d == null ? void 0 : d.price_type,
125
125
  "option": option
126
126
  };
@@ -4,6 +4,6 @@ declare const useSendModal: (bookingId?: number) => {
4
4
  setOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
5
5
  handleOpen: () => void;
6
6
  handleValuesChange: (val: any) => void;
7
- handleOk: (values: SendModalValues) => Promise<any>;
7
+ handleOk: (values: SendModalValues) => Promise<boolean | undefined>;
8
8
  };
9
9
  export default useSendModal;
@@ -262,11 +262,6 @@ var CartClientCard = (0, import_react.forwardRef)(({
262
262
  (0, import_utils3.setHandleSetClient)(handleSetClient);
263
263
  }
264
264
  }, [isActive]);
265
- (0, import_react.useEffect)(() => {
266
- return () => {
267
- (0, import_utils3.setHandleSetClient)(null);
268
- };
269
- }, [isActive]);
270
265
  const tags = (0, import_react.useMemo)(() => {
271
266
  var _a2;
272
267
  if (!selectedCustomer) return;
@@ -17,7 +17,7 @@ export declare const useWalletPass: (props: {
17
17
  cardData: any;
18
18
  handleSelectWallet: (value: number[]) => void;
19
19
  selectedWalletIds: any[];
20
- expiredWalletIds: any;
20
+ expiredWalletIds: any[];
21
21
  expiredWalletData: any;
22
22
  disabledWalletData: any[];
23
23
  clearAllSelectedWallet: () => void;
@@ -19,7 +19,7 @@ export declare const useStoreRef: <T extends {
19
19
  readonly netRef: React.MutableRefObject<boolean | undefined>;
20
20
  readonly symbolRef: React.MutableRefObject<string>;
21
21
  readonly amountRef: React.MutableRefObject<string | number>;
22
- readonly eftposRef: React.MutableRefObject<"stripe" | "tyro" | "windcave" | "payo" | "linkly">;
22
+ readonly eftposRef: React.MutableRefObject<"stripe" | "payo" | "tyro" | "windcave" | "linkly">;
23
23
  readonly clientRef: React.MutableRefObject<ClientEnum>;
24
24
  readonly dataRef: React.MutableRefObject<import("./store").State>;
25
25
  };
@@ -297,8 +297,8 @@ export declare const backUpFree: (payload: Partial<State>) => {
297
297
  amount?: string | number | undefined;
298
298
  mode?: "pay" | "refund" | "fullPay" | "query" | undefined;
299
299
  order_id?: string | number | undefined;
300
- eftpos?: "stripe" | "tyro" | "windcave" | "payo" | "linkly" | undefined;
301
- action?: "amount" | "pay" | "deviceList" | undefined;
300
+ eftpos?: "stripe" | "payo" | "tyro" | "windcave" | "linkly" | undefined;
301
+ action?: "pay" | "amount" | "deviceList" | undefined;
302
302
  key?: number | undefined;
303
303
  step?: number | undefined;
304
304
  title?: string | undefined;
@@ -27,18 +27,24 @@ var import_bookingTicket = require("./bookingTicket");
27
27
  var import_react = require("react");
28
28
  var import_OsKeyContext = require("../../context/OsKeyContext");
29
29
  var import_productCache = require("../../utils/productCache");
30
+ var import_hooks = require("../../../../hooks");
31
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
30
32
  var useProducts = (notAvailableRef) => {
33
+ var _a;
31
34
  const bookingTicket = (0, import_bookingTicket.useBookingTicket)();
32
35
  const osKey = (0, import_OsKeyContext.useOsKey)();
33
36
  const [products, setProducts] = (0, import_react.useState)([]);
34
37
  const [loading, setLoading] = (0, import_react.useState)(true);
35
38
  const isFirstLoadRef = (0, import_react.useRef)(true);
36
39
  const isFirstLoadDataRef = (0, import_react.useRef)(true);
40
+ const context = (0, import_hooks.useEngineContext)();
41
+ const { getApp } = ((_a = context.appHelper) == null ? void 0 : _a.utils) || {};
42
+ const app = getApp();
37
43
  const getProducts = (0, import_ahooks.useMemoizedFn)(async (params) => {
38
- var _a;
44
+ var _a2, _b, _c, _d, _e;
39
45
  if (isFirstLoadRef.current && osKey) {
40
46
  const cachedProducts = (0, import_productCache.getProductCache)(osKey);
41
- if (cachedProducts) {
47
+ if (cachedProducts && cachedProducts.length > 0) {
42
48
  setProducts(cachedProducts);
43
49
  setLoading(false);
44
50
  }
@@ -46,23 +52,62 @@ var useProducts = (notAvailableRef) => {
46
52
  } else {
47
53
  setLoading(true);
48
54
  }
49
- try {
50
- const freshProducts = await bookingTicket.loadProducts(params);
55
+ const maxRetries = 3;
56
+ let lastError = null;
57
+ let freshProducts = [];
58
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
59
+ try {
60
+ console.log(`[ProductCache] 尝试加载数据,第 ${attempt}/${maxRetries} 次`);
61
+ freshProducts = await bookingTicket.loadProducts(params);
62
+ if (freshProducts && freshProducts.length > 0) {
63
+ console.log(`[ProductCache] 第 ${attempt} 次尝试成功,获取到 ${freshProducts.length} 条数据`);
64
+ break;
65
+ }
66
+ console.log(`[ProductCache] 第 ${attempt} 次尝试返回空数据`);
67
+ if (attempt < maxRetries) {
68
+ console.log(`[ProductCache] 等待 1 秒后重试...`);
69
+ await sleep(1e3);
70
+ }
71
+ } catch (error) {
72
+ lastError = error;
73
+ console.log(`[ProductCache] 第 ${attempt} 次尝试失败:`, error);
74
+ (_b = (_a2 = app == null ? void 0 : app.logger) == null ? void 0 : _a2.addLog) == null ? void 0 : _b.call(_a2, {
75
+ type: "info",
76
+ title: `[getProduct] bookingTicket.loadProducts error (attempt ${attempt}/${maxRetries})`,
77
+ metadata: {
78
+ error,
79
+ attempt
80
+ }
81
+ });
82
+ if (attempt < maxRetries) {
83
+ console.log(`[ProductCache] 等待 1 秒后重试...`);
84
+ await sleep(1e3);
85
+ }
86
+ }
87
+ }
88
+ if (freshProducts && freshProducts.length > 0) {
51
89
  isFirstLoadDataRef.current = false;
52
90
  setProducts(freshProducts);
53
91
  if (osKey) {
54
92
  (0, import_productCache.setProductCache)(osKey, freshProducts);
55
93
  console.log("[ProductCache] 已更新缓存");
56
94
  }
57
- } catch (error) {
58
- if ((error == null ? void 0 : error.code) === 607100 && (isFirstLoadDataRef.current || products.length > 0)) {
59
- (_a = notAvailableRef.current) == null ? void 0 : _a.open();
95
+ setLoading(false);
96
+ } else {
97
+ console.log("[ProductCache] 3次尝试后仍未获取到数据");
98
+ (_d = (_c = app == null ? void 0 : app.logger) == null ? void 0 : _c.addLog) == null ? void 0 : _d.call(_c, {
99
+ type: "error",
100
+ title: "[getProduct] 3次尝试后仍未获取到数据",
101
+ metadata: {
102
+ error: lastError
103
+ }
104
+ });
105
+ if ((lastError == null ? void 0 : lastError.code) === 607100 && (isFirstLoadDataRef.current || products.length > 0)) {
106
+ (_e = notAvailableRef.current) == null ? void 0 : _e.open();
60
107
  }
61
108
  setLoading(false);
62
109
  setProducts([]);
63
110
  isFirstLoadDataRef.current = false;
64
- } finally {
65
- setLoading(false);
66
111
  }
67
112
  });
68
113
  return {
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.4.69",
3
+ "version": "6.4.71",
4
+ "scripts": {
5
+ "dev": "father dev",
6
+ "build": "father build",
7
+ "lowcode:dev": "build-scripts start --config ./build.lowcode.js",
8
+ "lowcode:build": " build-scripts build --config ./build.lowcode.js"
9
+ },
4
10
  "main": "./lib/index.js",
5
11
  "module": "./es/index.js",
6
12
  "types": "./lib/index.d.ts",
@@ -50,6 +56,10 @@
50
56
  "@dnd-kit/modifiers": "^6.0.1",
51
57
  "@dnd-kit/sortable": "^7.0.2",
52
58
  "@dnd-kit/utilities": "^3.2.1",
59
+ "@pisell/date-picker": "workspace:*",
60
+ "@pisell/icon": "workspace:*",
61
+ "@pisell/materials": "workspace:*",
62
+ "@pisell/utils": "workspace:*",
53
63
  "ahooks": "^3.7.6",
54
64
  "antd": "^5.6.3",
55
65
  "classnames": "^2.3.2",
@@ -60,11 +70,7 @@
60
70
  "react-resizable": "^3.0.5",
61
71
  "styled-components": "^6.0.0-rc.3",
62
72
  "@react-spring/web": "^9.6.1",
63
- "@use-gesture/react": "^10.3.1",
64
- "@pisell/icon": "0.0.11",
65
- "@pisell/date-picker": "3.0.7",
66
- "@pisell/utils": "3.0.2",
67
- "@pisell/materials": "6.4.17"
73
+ "@use-gesture/react": "^10.3.1"
68
74
  },
69
75
  "peerDependencies": {
70
76
  "react": "^18.0.0",
@@ -72,11 +78,5 @@
72
78
  },
73
79
  "componentConfig": {
74
80
  "materialSchema": "https://unpkg.com/@pisell/materials@1.0.1/build/lowcode/assets-prod.json"
75
- },
76
- "scripts": {
77
- "dev": "father dev",
78
- "build": "father build",
79
- "lowcode:dev": "build-scripts start --config ./build.lowcode.js",
80
- "lowcode:build": " build-scripts build --config ./build.lowcode.js"
81
81
  }
82
- }
82
+ }