@pisell/materials 3.3.21 → 3.3.22

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.
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect } from 'react';
2
2
  import useEngineContext from "../../../hooks/useEngineContext";
3
3
  export var useNativeScanner = function useNativeScanner(onChange) {
4
- var _context$appHelper;
4
+ var _context$appHelper, _interaction$utils3, _interaction$utils3$i;
5
5
  var context = useEngineContext();
6
6
  var _ref = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {},
7
7
  interaction = _ref.interaction,
@@ -30,6 +30,6 @@ export var useNativeScanner = function useNativeScanner(onChange) {
30
30
  }, []);
31
31
  return {
32
32
  activeNativeScanner: activeNativeScanner,
33
- isTerminal: isTerminal && isTerminal()
33
+ isTerminal: isTerminal && isTerminal() || (interaction === null || interaction === void 0 || (_interaction$utils3 = interaction.utils) === null || _interaction$utils3 === void 0 || (_interaction$utils3$i = _interaction$utils3.isAppEnv) === null || _interaction$utils3$i === void 0 ? void 0 : _interaction$utils3$i.call(_interaction$utils3))
34
34
  };
35
35
  };
@@ -76,13 +76,34 @@ var toBooleanValue = function toBooleanValue(value) {
76
76
  };
77
77
 
78
78
  // 自定义钩子:处理二维码/条形码模态框
79
- var useCodeModal = function useCodeModal(cardNo, onCodeClick) {
79
+ var useCodeModal = function useCodeModal(cardNo, onCodeClick, codeType) {
80
+ var _context$appHelper;
80
81
  var _useState = useState(false),
81
82
  _useState2 = _slicedToArray(_useState, 2),
82
83
  isModalOpen = _useState2[0],
83
84
  setIsModalOpen = _useState2[1];
85
+ var context = useEngineContext();
86
+ var _ref = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {},
87
+ interaction = _ref.interaction;
84
88
  var handleCodeClick = function handleCodeClick(e) {
89
+ var _interaction$utils, _interaction$utils$is;
85
90
  e.stopPropagation();
91
+ if (interaction !== null && interaction !== void 0 && (_interaction$utils = interaction.utils) !== null && _interaction$utils !== void 0 && (_interaction$utils$is = _interaction$utils.isAppEnv) !== null && _interaction$utils$is !== void 0 && _interaction$utils$is.call(_interaction$utils)) {
92
+ var _interaction$utils2, _interaction$utils2$p;
93
+ var typeMap = {
94
+ orCode: "qrCode",
95
+ barCode: "barCode"
96
+ };
97
+ interaction === null || interaction === void 0 || (_interaction$utils2 = interaction.utils) === null || _interaction$utils2 === void 0 || (_interaction$utils2$p = _interaction$utils2.postMessageToApp) === null || _interaction$utils2$p === void 0 || _interaction$utils2$p.call(_interaction$utils2, {
98
+ module: 'global',
99
+ key: 'openCodeModal',
100
+ data: {
101
+ type: typeMap[codeType] || codeType,
102
+ value: cardNo
103
+ }
104
+ });
105
+ return;
106
+ }
86
107
  if (onCodeClick) {
87
108
  onCodeClick();
88
109
  } else {
@@ -101,32 +122,32 @@ var useCodeModal = function useCodeModal(cardNo, onCodeClick) {
101
122
  };
102
123
 
103
124
  // 子组件:卡片头部
104
- var CardHeader = function CardHeader(_ref) {
105
- var _ref$showIcon = _ref.showIcon,
106
- showIcon = _ref$showIcon === void 0 ? true : _ref$showIcon,
107
- _ref$showWalletName = _ref.showWalletName,
108
- showWalletName = _ref$showWalletName === void 0 ? true : _ref$showWalletName,
109
- _ref$showShopName = _ref.showShopName,
110
- showShopName = _ref$showShopName === void 0 ? true : _ref$showShopName,
111
- _ref$showCardNo = _ref.showCardNo,
112
- showCardNo = _ref$showCardNo === void 0 ? true : _ref$showCardNo,
113
- _ref$showCode = _ref.showCode,
114
- showCode = _ref$showCode === void 0 ? true : _ref$showCode,
115
- iconImg = _ref.iconImg,
116
- mode = _ref.mode,
117
- _ref$walletName = _ref.walletName,
118
- walletName = _ref$walletName === void 0 ? 'Level' : _ref$walletName,
119
- _ref$shopName = _ref.shopName,
120
- shopName = _ref$shopName === void 0 ? 'Store name' : _ref$shopName,
121
- _ref$cardNo = _ref.cardNo,
122
- cardNo = _ref$cardNo === void 0 ? 'Wallet number' : _ref$cardNo,
123
- _ref$cardStyle = _ref.cardStyle,
124
- cardStyle = _ref$cardStyle === void 0 ? 'normal' : _ref$cardStyle,
125
- _ref$codeType = _ref.codeType,
126
- codeType = _ref$codeType === void 0 ? 'barCode' : _ref$codeType,
127
- onCodeClick = _ref.onCodeClick,
128
- _ref$isLogin = _ref.isLogin,
129
- isLogin = _ref$isLogin === void 0 ? false : _ref$isLogin;
125
+ var CardHeader = function CardHeader(_ref2) {
126
+ var _ref2$showIcon = _ref2.showIcon,
127
+ showIcon = _ref2$showIcon === void 0 ? true : _ref2$showIcon,
128
+ _ref2$showWalletName = _ref2.showWalletName,
129
+ showWalletName = _ref2$showWalletName === void 0 ? true : _ref2$showWalletName,
130
+ _ref2$showShopName = _ref2.showShopName,
131
+ showShopName = _ref2$showShopName === void 0 ? true : _ref2$showShopName,
132
+ _ref2$showCardNo = _ref2.showCardNo,
133
+ showCardNo = _ref2$showCardNo === void 0 ? true : _ref2$showCardNo,
134
+ _ref2$showCode = _ref2.showCode,
135
+ showCode = _ref2$showCode === void 0 ? true : _ref2$showCode,
136
+ iconImg = _ref2.iconImg,
137
+ mode = _ref2.mode,
138
+ _ref2$walletName = _ref2.walletName,
139
+ walletName = _ref2$walletName === void 0 ? 'Level' : _ref2$walletName,
140
+ _ref2$shopName = _ref2.shopName,
141
+ shopName = _ref2$shopName === void 0 ? 'Store name' : _ref2$shopName,
142
+ _ref2$cardNo = _ref2.cardNo,
143
+ cardNo = _ref2$cardNo === void 0 ? 'Wallet number' : _ref2$cardNo,
144
+ _ref2$cardStyle = _ref2.cardStyle,
145
+ cardStyle = _ref2$cardStyle === void 0 ? 'normal' : _ref2$cardStyle,
146
+ _ref2$codeType = _ref2.codeType,
147
+ codeType = _ref2$codeType === void 0 ? 'barCode' : _ref2$codeType,
148
+ onCodeClick = _ref2.onCodeClick,
149
+ _ref2$isLogin = _ref2.isLogin,
150
+ isLogin = _ref2$isLogin === void 0 ? false : _ref2$isLogin;
130
151
  // 处理可能为0/1的布尔值
131
152
  var processedShowIcon = toBooleanValue(showIcon);
132
153
  var processedShowWalletName = toBooleanValue(showWalletName);
@@ -165,9 +186,9 @@ var CardHeader = function CardHeader(_ref) {
165
186
  };
166
187
 
167
188
  // 子组件:卡片内容项
168
- var CardItem = function CardItem(_ref2) {
169
- var item = _ref2.item,
170
- symbol = _ref2.symbol;
189
+ var CardItem = function CardItem(_ref3) {
190
+ var item = _ref3.item,
191
+ symbol = _ref3.symbol;
171
192
  var key = item.key,
172
193
  label = item.label,
173
194
  value = item.value;
@@ -188,9 +209,9 @@ var CardItem = function CardItem(_ref2) {
188
209
  };
189
210
 
190
211
  // 子组件:卡片内容
191
- var CardContent = function CardContent(_ref3) {
192
- var items = _ref3.items,
193
- symbol = _ref3.symbol;
212
+ var CardContent = function CardContent(_ref4) {
213
+ var items = _ref4.items,
214
+ symbol = _ref4.symbol;
194
215
  // 定义期望的顺序
195
216
  var expectedOrder = ['piont', 'balance', 'discount', 'voucher'];
196
217
 
@@ -218,9 +239,9 @@ var CardContent = function CardContent(_ref3) {
218
239
  };
219
240
 
220
241
  // 子组件:二维码/条形码显示
221
- var CodeDisplay = function CodeDisplay(_ref4) {
222
- var codeType = _ref4.codeType,
223
- cardNo = _ref4.cardNo;
242
+ var CodeDisplay = function CodeDisplay(_ref5) {
243
+ var codeType = _ref5.codeType,
244
+ cardNo = _ref5.cardNo;
224
245
  if (!cardNo) return null;
225
246
  return /*#__PURE__*/React.createElement("div", {
226
247
  className: "pisell-wallet-card-code"
@@ -250,12 +271,12 @@ var blockEvent = function blockEvent(e) {
250
271
  };
251
272
 
252
273
  // 子组件:二维码/条形码模态框
253
- var CodeModal = function CodeModal(_ref5) {
254
- var isOpen = _ref5.isOpen,
255
- onClose = _ref5.onClose,
256
- codeType = _ref5.codeType,
257
- cardNo = _ref5.cardNo,
258
- platform = _ref5.platform;
274
+ var CodeModal = function CodeModal(_ref6) {
275
+ var isOpen = _ref6.isOpen,
276
+ onClose = _ref6.onClose,
277
+ codeType = _ref6.codeType,
278
+ cardNo = _ref6.cardNo,
279
+ platform = _ref6.platform;
259
280
  return /*#__PURE__*/React.createElement(PisellModal, {
260
281
  title: getText(codeType === 'barCode' ? 'walletCard-barcode' : 'walletCard-qrcode'),
261
282
  platform: platform,
@@ -316,10 +337,10 @@ var WalletCard = function WalletCard(props) {
316
337
  var showCode = toBooleanValue(mergedProps.showCode);
317
338
  var isLogin = toBooleanValue(mergedProps.isLogin);
318
339
  var context = useEngineContext();
319
- var _ref6 = context.appHelper || {},
320
- utils = _ref6.utils;
340
+ var _ref7 = context.appHelper || {},
341
+ utils = _ref7.utils;
321
342
  // 使用自定义钩子处理模态框逻辑
322
- var _useCodeModal = useCodeModal(cardNo, onCodeClick),
343
+ var _useCodeModal = useCodeModal(cardNo, onCodeClick, codeType),
323
344
  isModalOpen = _useCodeModal.isModalOpen,
324
345
  handleCodeClick = _useCodeModal.handleCodeClick,
325
346
  closeModal = _useCodeModal.closeModal;
@@ -35,12 +35,12 @@ module.exports = __toCommonJS(useNativeScanner_exports);
35
35
  var import_react = require("react");
36
36
  var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
37
37
  var useNativeScanner = (onChange) => {
38
- var _a;
38
+ var _a, _b, _c;
39
39
  const context = (0, import_useEngineContext.default)();
40
40
  const { interaction, isTerminal } = ((_a = context.appHelper) == null ? void 0 : _a.utils) || {};
41
41
  (0, import_react.useEffect)(() => {
42
- var _a2, _b;
43
- (_b = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.mountFunction) == null ? void 0 : _b.call(
42
+ var _a2, _b2;
43
+ (_b2 = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.mountFunction) == null ? void 0 : _b2.call(
44
44
  _a2,
45
45
  "global",
46
46
  "nativeScannerResult",
@@ -55,8 +55,8 @@ var useNativeScanner = (onChange) => {
55
55
  );
56
56
  }, []);
57
57
  const activeNativeScanner = (0, import_react.useCallback)(() => {
58
- var _a2, _b;
59
- (_b = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.postMessageToApp) == null ? void 0 : _b.call(_a2, {
58
+ var _a2, _b2;
59
+ (_b2 = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.postMessageToApp) == null ? void 0 : _b2.call(_a2, {
60
60
  module: "global",
61
61
  key: "active_native_scanner",
62
62
  data: {
@@ -66,7 +66,7 @@ var useNativeScanner = (onChange) => {
66
66
  }, []);
67
67
  return {
68
68
  activeNativeScanner,
69
- isTerminal: isTerminal && isTerminal()
69
+ isTerminal: isTerminal && isTerminal() || ((_c = (_b = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _b.isAppEnv) == null ? void 0 : _c.call(_b))
70
70
  };
71
71
  };
72
72
  // Annotate the CommonJS export names for ESM import in node:
@@ -89,10 +89,29 @@ var toBooleanValue = (value) => {
89
89
  if (value === 1 || value === "1") return true;
90
90
  return !!value;
91
91
  };
92
- var useCodeModal = (cardNo, onCodeClick) => {
92
+ var useCodeModal = (cardNo, onCodeClick, codeType) => {
93
+ var _a;
93
94
  const [isModalOpen, setIsModalOpen] = (0, import_react.useState)(false);
95
+ const context = (0, import_useEngineContext.default)();
96
+ const { interaction } = ((_a = context.appHelper) == null ? void 0 : _a.utils) || {};
94
97
  const handleCodeClick = (e) => {
98
+ var _a2, _b, _c, _d;
95
99
  e.stopPropagation();
100
+ if ((_b = (_a2 = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _a2.isAppEnv) == null ? void 0 : _b.call(_a2)) {
101
+ const typeMap = {
102
+ orCode: "qrCode",
103
+ barCode: "barCode"
104
+ };
105
+ (_d = (_c = interaction == null ? void 0 : interaction.utils) == null ? void 0 : _c.postMessageToApp) == null ? void 0 : _d.call(_c, {
106
+ module: "global",
107
+ key: "openCodeModal",
108
+ data: {
109
+ type: typeMap[codeType] || codeType,
110
+ value: cardNo
111
+ }
112
+ });
113
+ return;
114
+ }
96
115
  if (onCodeClick) {
97
116
  onCodeClick();
98
117
  } else {
@@ -269,7 +288,8 @@ var WalletCard = (props) => {
269
288
  const { utils } = context.appHelper || {};
270
289
  const { isModalOpen, handleCodeClick, closeModal } = useCodeModal(
271
290
  cardNo,
272
- onCodeClick
291
+ onCodeClick,
292
+ codeType
273
293
  );
274
294
  const backgroundStyle = (0, import_react.useMemo)(() => {
275
295
  if (props.customBackgroundImage) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "3.3.21",
3
+ "version": "3.3.22",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",