@pisell/private-materials 3.0.136 → 3.0.138
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.
- package/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/preview.js +8 -8
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +12 -12
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +11 -11
- package/es/components/booking/forms/single/index.js +3 -0
- package/es/components/eftpos/const.d.ts +26 -0
- package/es/components/eftpos/const.js +40 -8
- package/es/components/eftpos/device.d.ts +3 -2
- package/es/components/eftpos/device.js +6 -5
- package/es/components/eftpos/form/index.d.ts +5 -0
- package/es/components/eftpos/form/index.js +8 -0
- package/es/components/eftpos/hooks.d.ts +34 -0
- package/es/components/{eftposPay/windcave/hook.js → eftpos/hooks.js} +96 -122
- package/es/components/eftpos/icon/apiKey.d.ts +5 -0
- package/es/components/eftpos/icon/apiKey.js +17 -0
- package/es/components/eftpos/icon/device.d.ts +5 -0
- package/es/components/eftpos/icon/device.js +19 -0
- package/es/components/eftpos/index.d.ts +10 -0
- package/es/components/eftpos/index.js +329 -46
- package/es/components/eftpos/index.less +38 -1
- package/es/components/eftpos/locales.d.ts +12 -0
- package/es/components/eftpos/locales.js +15 -3
- package/es/components/eftpos/log.d.ts +8 -0
- package/es/components/eftpos/log.js +85 -0
- package/es/components/eftpos/pos.d.ts +1 -1
- package/es/components/eftpos/pos.js +8 -5
- package/es/components/eftpos/surcharge/index.d.ts +25 -2
- package/es/components/eftpos/surcharge/index.js +100 -16
- package/es/components/eftpos/table.d.ts +4 -0
- package/es/components/eftpos/table.js +102 -10
- package/es/components/eftposPay/amount.d.ts +7 -1
- package/es/components/eftposPay/amount.js +65 -38
- package/es/components/eftposPay/component/fail/failCustom.js +65 -20
- package/es/components/eftposPay/component/fail/index.js +60 -30
- package/es/components/eftposPay/component/fail/network.d.ts +5 -0
- package/es/components/eftposPay/component/fail/network.js +13 -0
- package/es/components/eftposPay/component/fail/unknow.d.ts +6 -0
- package/es/components/eftposPay/component/fail/unknow.js +18 -3
- package/es/components/eftposPay/component/header/index.d.ts +2 -1
- package/es/components/eftposPay/component/header/index.js +4 -1
- package/es/components/eftposPay/component/header/index.less +1 -10
- package/es/components/eftposPay/component/manual/index.d.ts +6 -1
- package/es/components/eftposPay/component/manual/index.js +174 -23
- package/es/components/eftposPay/component/manual/index.less +42 -14
- package/es/components/eftposPay/component/signature/index.d.ts +5 -0
- package/es/components/eftposPay/component/signature/index.js +20 -2
- package/es/components/eftposPay/component/step/index.d.ts +7 -7
- package/es/components/eftposPay/component/step/step.d.ts +4 -4
- package/es/components/eftposPay/const.d.ts +19 -4
- package/es/components/eftposPay/const.js +4 -2
- package/es/components/eftposPay/device.d.ts +7 -0
- package/es/components/eftposPay/device.js +22 -0
- package/es/components/eftposPay/helper.d.ts +54 -0
- package/es/components/eftposPay/helper.js +93 -1
- package/es/components/eftposPay/hooks.d.ts +30 -1
- package/es/components/eftposPay/hooks.js +181 -26
- package/es/components/eftposPay/index.d.ts +2 -4
- package/es/components/eftposPay/index.js +119 -31
- package/es/components/eftposPay/index.less +27 -19
- package/es/components/eftposPay/locales.d.ts +45 -0
- package/es/components/eftposPay/locales.js +348 -3
- package/es/components/eftposPay/manufacturer.d.ts +2 -2
- package/es/components/eftposPay/manufacturer.js +9 -10
- package/es/components/eftposPay/pay.d.ts +10 -1
- package/es/components/eftposPay/pay.js +112 -34
- package/es/components/eftposPay/payo/config.js +137 -270
- package/es/components/eftposPay/payo/const.d.ts +22 -2
- package/es/components/eftposPay/payo/const.js +83 -33
- package/es/components/eftposPay/payo/hooks.d.ts +5 -0
- package/es/components/eftposPay/payo/hooks.js +19 -2
- package/es/components/eftposPay/store/index.d.ts +154 -53
- package/es/components/eftposPay/store/index.js +112 -60
- package/es/components/eftposPay/tyro/const.d.ts +17 -0
- package/es/components/eftposPay/{eftpos → tyro}/const.js +71 -90
- package/es/components/eftposPay/tyro/hooks.d.ts +14 -0
- package/es/components/eftposPay/tyro/hooks.js +40 -0
- package/es/components/eftposPay/tyro/index.d.ts +9 -0
- package/es/components/eftposPay/tyro/index.js +575 -0
- package/es/components/eftposPay/windcave/const.d.ts +24 -9
- package/es/components/eftposPay/windcave/const.js +90 -81
- package/es/components/eftposPay/windcave/helper.d.ts +16 -2
- package/es/components/eftposPay/windcave/helper.js +175 -42
- package/es/components/eftposPay/windcave/receiptAction.d.ts +12 -0
- package/es/components/eftposPay/windcave/receiptAction.js +91 -43
- package/es/components/eftposPay/windcave/timer.d.ts +13 -1
- package/es/components/eftposPay/windcave/timer.js +18 -1
- package/es/components/eftposPay/windcave/windcave.d.ts +2 -1
- package/es/components/eftposPay/windcave/windcave.js +155 -139
- package/es/utils/load.d.ts +11 -0
- package/es/utils/load.js +85 -0
- package/lib/components/booking/forms/single/index.js +1 -0
- package/lib/components/eftpos/const.d.ts +26 -0
- package/lib/components/eftpos/const.js +13 -1
- package/lib/components/eftpos/device.d.ts +3 -2
- package/lib/components/eftpos/device.js +2 -2
- package/lib/components/eftpos/form/index.d.ts +5 -0
- package/lib/components/eftpos/hooks.d.ts +34 -0
- package/lib/components/eftpos/hooks.js +106 -0
- package/lib/components/eftpos/icon/apiKey.d.ts +5 -0
- package/lib/components/eftpos/icon/apiKey.js +57 -0
- package/lib/components/eftpos/icon/device.d.ts +5 -0
- package/lib/components/eftpos/icon/device.js +57 -0
- package/lib/components/eftpos/index.d.ts +10 -0
- package/lib/components/eftpos/index.js +262 -97
- package/lib/components/eftpos/index.less +38 -1
- package/lib/components/eftpos/locales.d.ts +12 -0
- package/lib/components/eftpos/locales.js +15 -3
- package/lib/components/eftpos/log.d.ts +8 -0
- package/lib/components/eftpos/log.js +87 -0
- package/lib/components/eftpos/pos.d.ts +1 -1
- package/lib/components/eftpos/pos.js +5 -4
- package/lib/components/eftpos/surcharge/index.d.ts +25 -2
- package/lib/components/eftpos/surcharge/index.js +36 -6
- package/lib/components/eftpos/table.d.ts +4 -0
- package/lib/components/eftpos/table.js +40 -8
- package/lib/components/eftposPay/amount.d.ts +7 -1
- package/lib/components/eftposPay/amount.js +10 -33
- package/lib/components/eftposPay/component/fail/failCustom.js +27 -6
- package/lib/components/eftposPay/component/fail/index.js +39 -18
- package/lib/components/eftposPay/component/fail/network.d.ts +5 -0
- package/lib/components/eftposPay/component/fail/unknow.d.ts +6 -0
- package/lib/components/eftposPay/component/fail/unknow.js +3 -3
- package/lib/components/eftposPay/component/header/index.d.ts +2 -1
- package/lib/components/eftposPay/component/header/index.js +2 -1
- package/lib/components/eftposPay/component/header/index.less +1 -10
- package/lib/components/eftposPay/component/manual/index.d.ts +6 -1
- package/lib/components/eftposPay/component/manual/index.js +122 -31
- package/lib/components/eftposPay/component/manual/index.less +42 -14
- package/lib/components/eftposPay/component/signature/index.d.ts +5 -0
- package/lib/components/eftposPay/component/signature/index.js +2 -2
- package/lib/components/eftposPay/component/step/index.d.ts +7 -7
- package/lib/components/eftposPay/component/step/step.d.ts +4 -4
- package/lib/components/eftposPay/const.d.ts +19 -4
- package/lib/components/eftposPay/const.js +3 -1
- package/lib/components/eftposPay/device.d.ts +7 -0
- package/lib/components/eftposPay/helper.d.ts +54 -0
- package/lib/components/eftposPay/helper.js +64 -0
- package/lib/components/eftposPay/hooks.d.ts +30 -1
- package/lib/components/eftposPay/hooks.js +182 -44
- package/lib/components/eftposPay/index.d.ts +2 -4
- package/lib/components/eftposPay/index.js +74 -27
- package/lib/components/eftposPay/index.less +27 -19
- package/lib/components/eftposPay/locales.d.ts +45 -0
- package/lib/components/eftposPay/locales.js +352 -3
- package/lib/components/eftposPay/manufacturer.d.ts +2 -2
- package/lib/components/eftposPay/manufacturer.js +13 -13
- package/lib/components/eftposPay/pay.d.ts +10 -1
- package/lib/components/eftposPay/pay.js +86 -25
- package/lib/components/eftposPay/payo/config.js +121 -268
- package/lib/components/eftposPay/payo/const.d.ts +22 -2
- package/lib/components/eftposPay/payo/const.js +55 -36
- package/lib/components/eftposPay/payo/hooks.d.ts +5 -0
- package/lib/components/eftposPay/payo/hooks.js +1 -1
- package/lib/components/eftposPay/store/index.d.ts +154 -53
- package/lib/components/eftposPay/store/index.js +7 -66
- package/lib/components/eftposPay/tyro/const.d.ts +17 -0
- package/lib/components/eftposPay/tyro/const.js +114 -0
- package/lib/components/eftposPay/tyro/hooks.d.ts +14 -0
- package/lib/components/eftposPay/{eftpos/index.js → tyro/hooks.js} +31 -36
- package/lib/components/eftposPay/tyro/index.d.ts +9 -0
- package/lib/components/eftposPay/tyro/index.js +558 -0
- package/lib/components/eftposPay/windcave/const.d.ts +24 -9
- package/lib/components/eftposPay/windcave/const.js +53 -104
- package/lib/components/eftposPay/windcave/helper.d.ts +16 -2
- package/lib/components/eftposPay/windcave/helper.js +163 -48
- package/lib/components/eftposPay/windcave/receiptAction.d.ts +12 -0
- package/lib/components/eftposPay/windcave/receiptAction.js +15 -47
- package/lib/components/eftposPay/windcave/timer.d.ts +13 -1
- package/lib/components/eftposPay/windcave/timer.js +5 -0
- package/lib/components/eftposPay/windcave/windcave.d.ts +2 -1
- package/lib/components/eftposPay/windcave/windcave.js +130 -130
- package/lib/utils/load.d.ts +11 -0
- package/lib/utils/load.js +100 -0
- package/lowcode/eftpos/meta.ts +202 -160
- package/lowcode/eftpos-pay/meta.ts +45 -12
- package/package.json +4 -4
- package/es/components/eftposPay/eftpos/config.d.ts +0 -11
- package/es/components/eftposPay/eftpos/config.js +0 -178
- package/es/components/eftposPay/eftpos/const.d.ts +0 -10
- package/es/components/eftposPay/eftpos/index.d.ts +0 -7
- package/es/components/eftposPay/eftpos/index.js +0 -35
- package/es/components/eftposPay/windcave/action.d.ts +0 -8
- package/es/components/eftposPay/windcave/action.js +0 -104
- package/es/components/eftposPay/windcave/hook.d.ts +0 -14
- package/es/components/eftposPay/windcave/index.d.ts +0 -8
- package/es/components/eftposPay/windcave/index.js +0 -49
- package/es/components/eftposPay/windcave/pos.d.ts +0 -8
- package/es/components/eftposPay/windcave/pos.js +0 -180
- package/es/components/eftposPay/windcave/pwd.d.ts +0 -8
- package/es/components/eftposPay/windcave/pwd.js +0 -124
- package/es/components/eftposPay/windcave/receipet.d.ts +0 -6
- package/es/components/eftposPay/windcave/receipet.js +0 -67
- package/es/components/eftposPay/windcave/wait.d.ts +0 -12
- package/es/components/eftposPay/windcave/wait.js +0 -139
- package/lib/components/eftposPay/eftpos/config.d.ts +0 -11
- package/lib/components/eftposPay/eftpos/config.js +0 -199
- package/lib/components/eftposPay/eftpos/const.d.ts +0 -10
- package/lib/components/eftposPay/eftpos/const.js +0 -165
- package/lib/components/eftposPay/eftpos/index.d.ts +0 -7
- package/lib/components/eftposPay/windcave/action.d.ts +0 -8
- package/lib/components/eftposPay/windcave/action.js +0 -143
- package/lib/components/eftposPay/windcave/hook.d.ts +0 -14
- package/lib/components/eftposPay/windcave/hook.js +0 -139
- package/lib/components/eftposPay/windcave/index.d.ts +0 -8
- package/lib/components/eftposPay/windcave/index.js +0 -78
- package/lib/components/eftposPay/windcave/pos.d.ts +0 -8
- package/lib/components/eftposPay/windcave/pos.js +0 -197
- package/lib/components/eftposPay/windcave/pwd.d.ts +0 -8
- package/lib/components/eftposPay/windcave/pwd.js +0 -143
- package/lib/components/eftposPay/windcave/receipet.d.ts +0 -6
- package/lib/components/eftposPay/windcave/receipet.js +0 -93
- package/lib/components/eftposPay/windcave/wait.d.ts +0 -12
- package/lib/components/eftposPay/windcave/wait.js +0 -163
|
@@ -38,6 +38,7 @@ var import_antd = require("antd");
|
|
|
38
38
|
var import_react = __toESM(require("react"));
|
|
39
39
|
var import_const = require("../const");
|
|
40
40
|
var import_store = require("../store");
|
|
41
|
+
var import_hooks = require("../hooks");
|
|
41
42
|
var import_const2 = require("./const");
|
|
42
43
|
var ReceiptAction = ({
|
|
43
44
|
api,
|
|
@@ -45,7 +46,7 @@ var ReceiptAction = ({
|
|
|
45
46
|
}) => {
|
|
46
47
|
const dispatch = (0, import_store.useDispatch)();
|
|
47
48
|
const { custom, mode } = (0, import_store.useContextData)();
|
|
48
|
-
const
|
|
49
|
+
const { numRef } = (0, import_hooks.useStoreRef)();
|
|
49
50
|
const listRef = (0, import_react.useRef)(custom == null ? void 0 : custom.list);
|
|
50
51
|
const [receiptLoading, setReceiptLoading] = (0, import_react.useState)(
|
|
51
52
|
(custom == null ? void 0 : custom.receiptLoading) || false
|
|
@@ -65,15 +66,12 @@ var ReceiptAction = ({
|
|
|
65
66
|
(0, import_react.useEffect)(() => {
|
|
66
67
|
listRef.current = custom == null ? void 0 : custom.list;
|
|
67
68
|
}, [custom == null ? void 0 : custom.list]);
|
|
68
|
-
(0, import_react.useEffect)(() => {
|
|
69
|
-
ref.current = custom == null ? void 0 : custom.number;
|
|
70
|
-
}, [custom == null ? void 0 : custom.number]);
|
|
71
69
|
const onAccept = () => {
|
|
72
70
|
dispatch((0, import_store.updateStatus)(import_const.StatusEnum.Loading));
|
|
73
71
|
dispatch(
|
|
74
72
|
(0, import_store.updateCustom)({
|
|
75
73
|
list: listRef.current.map(
|
|
76
|
-
(item) => item.index ===
|
|
74
|
+
(item) => item.index === import_const2.StepStatusEnum.Receipt ? { ...item, status: "resolve" } : item
|
|
77
75
|
)
|
|
78
76
|
})
|
|
79
77
|
);
|
|
@@ -85,12 +83,12 @@ var ReceiptAction = ({
|
|
|
85
83
|
setReceiptLoading(true);
|
|
86
84
|
api.update({
|
|
87
85
|
type: "YES",
|
|
88
|
-
number:
|
|
86
|
+
number: numRef.current
|
|
89
87
|
}).then((res) => {
|
|
90
88
|
if (unloadRef.current) {
|
|
91
89
|
return res;
|
|
92
90
|
}
|
|
93
|
-
if (res &&
|
|
91
|
+
if (res && `${res.code}` === "200") {
|
|
94
92
|
setReceiptLoading(false);
|
|
95
93
|
const current = listRef.current.map((item) => {
|
|
96
94
|
if (Number(item == null ? void 0 : item.index) < import_const2.StepStatusEnum.Wait) {
|
|
@@ -116,8 +114,7 @@ var ReceiptAction = ({
|
|
|
116
114
|
dispatch(
|
|
117
115
|
(0, import_store.updateCustom)({
|
|
118
116
|
step: import_const2.StepStatusEnum.Wait,
|
|
119
|
-
list: current
|
|
120
|
-
isDeclineReceipt: false
|
|
117
|
+
list: current
|
|
121
118
|
})
|
|
122
119
|
);
|
|
123
120
|
onChange(true);
|
|
@@ -132,8 +129,7 @@ var ReceiptAction = ({
|
|
|
132
129
|
(0, import_store.updateCustom)({
|
|
133
130
|
list: listRef.current.map(
|
|
134
131
|
(item) => item.index === import_const2.StepStatusEnum.Receipt ? { ...item, status: "pedding" } : item
|
|
135
|
-
)
|
|
136
|
-
isDeclineReceipt: false
|
|
132
|
+
)
|
|
137
133
|
})
|
|
138
134
|
);
|
|
139
135
|
dispatch(
|
|
@@ -175,13 +171,13 @@ var ReceiptAction = ({
|
|
|
175
171
|
setReceiptLoading(true);
|
|
176
172
|
api.update({
|
|
177
173
|
type: "NO",
|
|
178
|
-
number:
|
|
174
|
+
number: numRef.current
|
|
179
175
|
}).then((res) => {
|
|
180
176
|
if (unloadRef.current) {
|
|
181
177
|
return res;
|
|
182
178
|
}
|
|
183
179
|
setReceiptLoading(false);
|
|
184
|
-
if (res &&
|
|
180
|
+
if (res && `${res.code}` === "200") {
|
|
185
181
|
const current = listRef.current.map((item) => {
|
|
186
182
|
if (Number(item == null ? void 0 : item.index) === import_const2.StepStatusEnum.Receipt) {
|
|
187
183
|
return {
|
|
@@ -216,8 +212,7 @@ var ReceiptAction = ({
|
|
|
216
212
|
dispatch(
|
|
217
213
|
(0, import_store.updateCustom)({
|
|
218
214
|
step: import_const2.StepStatusEnum.Wait,
|
|
219
|
-
list: current
|
|
220
|
-
isDeclineReceipt: true
|
|
215
|
+
list: current
|
|
221
216
|
})
|
|
222
217
|
);
|
|
223
218
|
onChange(true);
|
|
@@ -234,8 +229,7 @@ var ReceiptAction = ({
|
|
|
234
229
|
(0, import_store.updateCustom)({
|
|
235
230
|
list: listRef.current.map(
|
|
236
231
|
(item) => item.index === import_const2.StepStatusEnum.Receipt ? { ...item, status: "pedding" } : item
|
|
237
|
-
)
|
|
238
|
-
isDeclineReceipt: false
|
|
232
|
+
)
|
|
239
233
|
})
|
|
240
234
|
);
|
|
241
235
|
dispatch(
|
|
@@ -253,11 +247,7 @@ var ReceiptAction = ({
|
|
|
253
247
|
(0, import_store.updateState)({
|
|
254
248
|
title: import_utils.locales.getText("page.eftpos-pay.text.signature.title"),
|
|
255
249
|
// 'page.eftpos-pay.text.waiting.signature'), // 等待签名
|
|
256
|
-
status: import_const.StatusEnum.Warn
|
|
257
|
-
})
|
|
258
|
-
);
|
|
259
|
-
dispatch(
|
|
260
|
-
(0, import_store.updateState)({
|
|
250
|
+
status: import_const.StatusEnum.Warn,
|
|
261
251
|
custom: {
|
|
262
252
|
...custom,
|
|
263
253
|
receiptPage: "again"
|
|
@@ -329,18 +319,7 @@ var Action = ({
|
|
|
329
319
|
}) => {
|
|
330
320
|
const dispatch = (0, import_store.useDispatch)();
|
|
331
321
|
const { custom, mode } = (0, import_store.useContextData)();
|
|
332
|
-
|
|
333
|
-
dispatch(
|
|
334
|
-
(0, import_store.updateState)({
|
|
335
|
-
manual: {
|
|
336
|
-
title: import_utils.locales.getText("page.eftpos-pay.text.request.title")(mode),
|
|
337
|
-
text: import_utils.locales.getText("page.eftpos-pay.text.request.text")(mode)
|
|
338
|
-
}
|
|
339
|
-
})
|
|
340
|
-
);
|
|
341
|
-
dispatch((0, import_store.updateComponent)("Manual", true));
|
|
342
|
-
};
|
|
343
|
-
if (index < import_const2.StepStatusEnum.Account) {
|
|
322
|
+
if (index < import_const2.StepStatusEnum.Application) {
|
|
344
323
|
return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ import_react.default.createElement(
|
|
345
324
|
import_antd.Button,
|
|
346
325
|
{
|
|
@@ -352,7 +331,7 @@ var Action = ({
|
|
|
352
331
|
import_utils.locales.getText("page.eftpos-pay.text.cancel")
|
|
353
332
|
));
|
|
354
333
|
}
|
|
355
|
-
if (index >= import_const2.StepStatusEnum.
|
|
334
|
+
if (index >= import_const2.StepStatusEnum.Application && index < import_const2.StepStatusEnum.Receipt) {
|
|
356
335
|
return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ import_react.default.createElement(
|
|
357
336
|
import_antd.Button,
|
|
358
337
|
{
|
|
@@ -366,18 +345,7 @@ var Action = ({
|
|
|
366
345
|
if (index === import_const2.StepStatusEnum.Receipt) {
|
|
367
346
|
return null;
|
|
368
347
|
}
|
|
369
|
-
|
|
370
|
-
/* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { block: true, className: "pisell-lowcode__eft-pay-step-item-btn", disabled: true }, import_utils.locales.getText("page.eftpos-pay.text.leave")));
|
|
371
|
-
}
|
|
372
|
-
return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ import_react.default.createElement(
|
|
373
|
-
import_antd.Button,
|
|
374
|
-
{
|
|
375
|
-
block: true,
|
|
376
|
-
className: "pisell-lowcode__eft-pay-step-item-btn",
|
|
377
|
-
onClick: onManually
|
|
378
|
-
},
|
|
379
|
-
import_utils.locales.getText("page.eftpos-pay.text.manual.marking")
|
|
380
|
-
));
|
|
348
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { block: true, className: "pisell-lowcode__eft-pay-step-item-btn", disabled: true }, import_utils.locales.getText("page.eftpos-pay.text.leave")));
|
|
381
349
|
};
|
|
382
350
|
var receiptAction_default = Action;
|
|
383
351
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title: 定时,轮询
|
|
3
|
+
* @description: 双层 proxy , 1. 轮询 2. 定时 关闭轮询 ,特殊状态码,前端 701001 超时关闭 -1 外部用户关闭
|
|
4
|
+
* @return null
|
|
5
|
+
* @Author: hongbing.wang
|
|
6
|
+
* @Date: 2024-08-12 11:25
|
|
7
|
+
*/
|
|
1
8
|
export default class XhrTimer {
|
|
2
9
|
clearTimeout: number;
|
|
3
10
|
isTimeoutClose: boolean;
|
|
@@ -10,8 +17,13 @@ export default class XhrTimer {
|
|
|
10
17
|
constructor({ xhr, timeout, callback, max, }: {
|
|
11
18
|
xhr: (...agrn: unknown[]) => Promise<unknown>;
|
|
12
19
|
timeout: number;
|
|
13
|
-
callback: (...agrn:
|
|
20
|
+
callback: (...agrn: any[]) => unknown;
|
|
14
21
|
max?: number;
|
|
15
22
|
});
|
|
23
|
+
/**
|
|
24
|
+
* @title: 关闭 循环
|
|
25
|
+
* @Author: hongbing.wang
|
|
26
|
+
* @Date: 2024-08-20 12:48
|
|
27
|
+
*/
|
|
16
28
|
close(): void;
|
|
17
29
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
declare const _default: ({ api, onChange }: {
|
|
2
|
+
declare const _default: ({ api, onChange, formatAmount, }: {
|
|
3
3
|
api: any;
|
|
4
4
|
onChange: any;
|
|
5
|
+
formatAmount(amount: number | string, precision: number, symbol: string): string;
|
|
5
6
|
}) => React.JSX.Element;
|
|
6
7
|
export default _default;
|
|
@@ -34,7 +34,7 @@ __export(windcave_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(windcave_exports);
|
|
35
35
|
var import_utils = require("@pisell/utils");
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
|
-
var
|
|
37
|
+
var import_hooks = require("../hooks");
|
|
38
38
|
var import_step = __toESM(require("../component/step/step"));
|
|
39
39
|
var import_const = require("../const");
|
|
40
40
|
var import_helper = require("../helper");
|
|
@@ -43,24 +43,32 @@ var import_const2 = require("./const");
|
|
|
43
43
|
var import_helper2 = require("./helper");
|
|
44
44
|
var import_receiptAction = __toESM(require("./receiptAction"));
|
|
45
45
|
var Minute = 1e3 * 60;
|
|
46
|
-
var windcave_default = ({
|
|
47
|
-
|
|
46
|
+
var windcave_default = ({
|
|
47
|
+
api,
|
|
48
|
+
onChange,
|
|
49
|
+
formatAmount = (number, precision, symbol) => `${symbol}${number}`
|
|
50
|
+
}) => {
|
|
51
|
+
const { custom, status } = (0, import_store.useContextData)();
|
|
52
|
+
const {
|
|
53
|
+
deviceRef,
|
|
54
|
+
payRef,
|
|
55
|
+
numRef,
|
|
56
|
+
orderIdRef,
|
|
57
|
+
modeRef,
|
|
58
|
+
statusRef,
|
|
59
|
+
netRef,
|
|
60
|
+
symbolRef,
|
|
61
|
+
amountRef,
|
|
62
|
+
eftposRef
|
|
63
|
+
} = (0, import_hooks.useStoreRef)();
|
|
48
64
|
const dispatch = (0, import_store.useDispatch)();
|
|
49
65
|
const fail = (0, import_helper2.useFail)();
|
|
50
66
|
const failRef = (0, import_react.useRef)(fail);
|
|
51
|
-
const modeRef = (0, import_react.useRef)(mode);
|
|
52
|
-
const statusRef = (0, import_react.useRef)(status);
|
|
53
67
|
const unloadRef = (0, import_react.useRef)(false);
|
|
54
|
-
const customRef = (0, import_react.useRef)(custom);
|
|
55
|
-
const deviceRef = (0, import_react.useRef)(device);
|
|
56
|
-
const refundRef = (0, import_react.useRef)(
|
|
57
|
-
custom == null ? void 0 : custom.refund
|
|
58
|
-
);
|
|
59
|
-
const ref = (0, import_react.useRef)(custom == null ? void 0 : custom.number);
|
|
60
68
|
const stepRef = (0, import_react.useRef)(custom == null ? void 0 : custom.step);
|
|
61
69
|
const listRef = (0, import_react.useRef)(custom == null ? void 0 : custom.list);
|
|
62
70
|
const initRef = (0, import_react.useRef)(false);
|
|
63
|
-
const
|
|
71
|
+
const clearRef = (0, import_react.useRef)();
|
|
64
72
|
const isReceiptPage = (0, import_react.useMemo)(
|
|
65
73
|
() => (custom == null ? void 0 : custom.step) === import_const2.StepStatusEnum.Receipt,
|
|
66
74
|
[custom == null ? void 0 : custom.step]
|
|
@@ -70,91 +78,66 @@ var windcave_default = ({ api, onChange }) => {
|
|
|
70
78
|
[custom == null ? void 0 : custom.step, custom == null ? void 0 : custom.receiptPage]
|
|
71
79
|
);
|
|
72
80
|
const [disabled, setDisabled] = (0, import_react.useState)(false);
|
|
73
|
-
(0, import_react.useEffect)(() => {
|
|
74
|
-
statusRef.current = status;
|
|
75
|
-
}, [status]);
|
|
76
|
-
(0, import_react.useEffect)(() => {
|
|
77
|
-
modeRef.current = mode;
|
|
78
|
-
}, [mode]);
|
|
79
|
-
(0, import_react.useEffect)(() => {
|
|
80
|
-
isPayRef.current = custom == null ? void 0 : custom.isPay;
|
|
81
|
-
}, [custom == null ? void 0 : custom.isPay]);
|
|
82
81
|
(0, import_react.useEffect)(() => {
|
|
83
82
|
listRef.current = custom == null ? void 0 : custom.list;
|
|
84
83
|
}, [custom == null ? void 0 : custom.list]);
|
|
85
84
|
(0, import_react.useEffect)(() => {
|
|
86
85
|
stepRef.current = custom == null ? void 0 : custom.step;
|
|
87
86
|
}, [custom == null ? void 0 : custom.step]);
|
|
88
|
-
(0, import_react.useEffect)(() => {
|
|
89
|
-
refundRef.current = custom == null ? void 0 : custom.refund;
|
|
90
|
-
}, [custom == null ? void 0 : custom.refund]);
|
|
91
|
-
(0, import_react.useEffect)(() => {
|
|
92
|
-
customRef.current = custom;
|
|
93
|
-
}, [custom]);
|
|
94
|
-
(0, import_react.useEffect)(() => {
|
|
95
|
-
deviceRef.current = device;
|
|
96
|
-
}, [device]);
|
|
97
|
-
(0, import_react.useEffect)(() => {
|
|
98
|
-
ref.current = custom == null ? void 0 : custom.number;
|
|
99
|
-
}, [custom == null ? void 0 : custom.number]);
|
|
100
87
|
(0, import_react.useEffect)(() => {
|
|
101
88
|
failRef.current = fail;
|
|
102
89
|
}, [fail]);
|
|
103
|
-
const [run] = (0, import_helper2.useValidate)(api.check, Minute, (res) => {
|
|
90
|
+
const [run, validateRef] = (0, import_helper2.useValidate)(api.check, Minute, (res) => {
|
|
104
91
|
dispatch(
|
|
105
92
|
(0, import_store.updateCustom)({
|
|
106
93
|
list: listRef.current.map((item) => ({
|
|
107
94
|
...item,
|
|
108
95
|
status: "resolve"
|
|
109
|
-
}))
|
|
96
|
+
})),
|
|
97
|
+
card_reader_surcharge: (res == null ? void 0 : res.card_reader_surcharge) || 0
|
|
110
98
|
})
|
|
111
99
|
);
|
|
112
100
|
dispatch(
|
|
113
101
|
(0, import_store.updateState)({
|
|
114
102
|
status: "success",
|
|
115
|
-
title: import_utils.locales.getText("page.eftpos-pay.text.successful")(
|
|
103
|
+
title: import_utils.locales.getText("page.eftpos-pay.text.successful")(
|
|
104
|
+
modeRef.current
|
|
105
|
+
)
|
|
116
106
|
})
|
|
117
107
|
);
|
|
118
|
-
setTimeout(() => {
|
|
119
|
-
var _a;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const obj = refundRef.current || {};
|
|
140
|
-
onChange("success", {
|
|
141
|
-
...obj,
|
|
142
|
-
number: ref.current,
|
|
143
|
-
device: deviceRef.current
|
|
144
|
-
});
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
onChange("success", { number: ref.current });
|
|
108
|
+
clearRef.current = setTimeout(() => {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
const params = (0, import_helper.getPayParams)(
|
|
111
|
+
{
|
|
112
|
+
mode: modeRef.current,
|
|
113
|
+
amount: amountRef.current,
|
|
114
|
+
order_id: orderIdRef.current,
|
|
115
|
+
number: numRef.current,
|
|
116
|
+
device: deviceRef.current,
|
|
117
|
+
pay: payRef.current,
|
|
118
|
+
custom: {
|
|
119
|
+
card_reader_surcharge: (res == null ? void 0 : res.card_reader_surcharge) || 0
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"success"
|
|
123
|
+
);
|
|
124
|
+
const receipt = Array.isArray(res.receipt) ? res.receipt : [res.receipt];
|
|
125
|
+
onChange("success", {
|
|
126
|
+
...params,
|
|
127
|
+
receipt: ((_b = (_a = deviceRef.current) == null ? void 0 : _a.setting) == null ? void 0 : _b.receipts) ? [] : receipt
|
|
128
|
+
});
|
|
148
129
|
}, 1e3);
|
|
149
130
|
});
|
|
150
131
|
const controllerRef = (0, import_react.useRef)();
|
|
151
132
|
(0, import_react.useEffect)(() => {
|
|
152
|
-
var _a, _b
|
|
133
|
+
var _a, _b;
|
|
134
|
+
if (statusRef.current === import_const.StatusEnum.Success || statusRef.current === import_const.StatusEnum.Fail) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
153
137
|
if (initRef.current) {
|
|
154
138
|
return;
|
|
155
139
|
}
|
|
156
140
|
initRef.current = true;
|
|
157
|
-
const { pay, order_id } = customRef.current;
|
|
158
141
|
if (stepRef.current === import_const2.StepStatusEnum.Receipt) {
|
|
159
142
|
if (import_const.StatusEnum.Loading === statusRef.current) {
|
|
160
143
|
run();
|
|
@@ -164,68 +147,68 @@ var windcave_default = ({ api, onChange }) => {
|
|
|
164
147
|
return;
|
|
165
148
|
}
|
|
166
149
|
controllerRef.current = new AbortController();
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
ref.current = (0, import_helper.getUuid)();
|
|
170
|
-
dispatch(
|
|
171
|
-
(0, import_store.updateCustom)({
|
|
172
|
-
number: ref.current
|
|
173
|
-
})
|
|
174
|
-
);
|
|
175
|
-
const resultPromise = modeRef.current === import_const.ModeEnum.Pay ? api.pay(
|
|
176
|
-
{
|
|
177
|
-
order_id,
|
|
178
|
-
amount: pay.total,
|
|
179
|
-
card_reader_type: eftpos,
|
|
180
|
-
card_reader_id: (_a = deviceRef.current) == null ? void 0 : _a.id,
|
|
181
|
-
number: ref.current
|
|
182
|
-
},
|
|
183
|
-
{ signal: controllerRef.current.signal }
|
|
184
|
-
) : api.refund(
|
|
185
|
-
{
|
|
186
|
-
order_id,
|
|
187
|
-
amount: (_b = refundRef.current) == null ? void 0 : _b.total,
|
|
188
|
-
card_reader_type: eftpos,
|
|
189
|
-
card_reader_id: (_c = deviceRef.current) == null ? void 0 : _c.id,
|
|
190
|
-
number: ref.current
|
|
191
|
-
},
|
|
192
|
-
{ signal: controllerRef.current.signal }
|
|
193
|
-
);
|
|
194
|
-
resultPromise.then((res) => {
|
|
195
|
-
var _a2;
|
|
196
|
-
if (unloadRef.current) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (!((_a2 = customRef.current) == null ? void 0 : _a2.net)) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (res && (res.code === 200 || res.code === "200")) {
|
|
203
|
-
dispatch(
|
|
204
|
-
(0, import_store.updateCustom)({
|
|
205
|
-
isPay: true
|
|
206
|
-
})
|
|
207
|
-
);
|
|
208
|
-
run();
|
|
209
|
-
}
|
|
210
|
-
}).catch((res) => {
|
|
211
|
-
var _a2, _b2;
|
|
212
|
-
if (unloadRef.current) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (!((_a2 = customRef.current) == null ? void 0 : _a2.net)) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
(_b2 = failRef.current) == null ? void 0 : _b2.call(failRef, res, stepRef.current >= 3);
|
|
219
|
-
});
|
|
150
|
+
if (numRef.current) {
|
|
151
|
+
run();
|
|
220
152
|
return;
|
|
221
153
|
}
|
|
222
|
-
|
|
223
|
-
|
|
154
|
+
console.log("modeRef.current = ", modeRef.current);
|
|
155
|
+
numRef.current = (0, import_helper.getUuid)();
|
|
156
|
+
dispatch(
|
|
157
|
+
(0, import_store.updateState)({
|
|
158
|
+
number: numRef.current
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
const resultPromise = modeRef.current === import_const.ModeEnum.Pay ? api.pay(
|
|
162
|
+
{
|
|
163
|
+
order_id: orderIdRef.current,
|
|
164
|
+
amount: payRef.current.total,
|
|
165
|
+
card_reader_type: eftposRef.current,
|
|
166
|
+
card_reader_id: (_a = deviceRef.current) == null ? void 0 : _a.id,
|
|
167
|
+
number: numRef.current
|
|
168
|
+
},
|
|
169
|
+
{ signal: controllerRef.current.signal }
|
|
170
|
+
) : api.refund(
|
|
171
|
+
{
|
|
172
|
+
order_id: orderIdRef.current,
|
|
173
|
+
amount: amountRef.current,
|
|
174
|
+
card_reader_type: eftposRef.current,
|
|
175
|
+
card_reader_id: (_b = deviceRef.current) == null ? void 0 : _b.id,
|
|
176
|
+
number: numRef.current
|
|
177
|
+
},
|
|
178
|
+
{ signal: controllerRef.current.signal }
|
|
179
|
+
);
|
|
180
|
+
resultPromise.then((res) => {
|
|
181
|
+
var _a2, _b2;
|
|
182
|
+
if (unloadRef.current || !netRef.current) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (res && `${res.code}` === "200" && res.data && res.data.txn_status_id) {
|
|
186
|
+
(_a2 = validateRef.current) == null ? void 0 : _a2.call(validateRef, res, true);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
(_b2 = failRef.current) == null ? void 0 : _b2.call(
|
|
190
|
+
failRef,
|
|
191
|
+
res,
|
|
192
|
+
stepRef.current >= import_const2.StepStatusEnum.Account
|
|
193
|
+
);
|
|
194
|
+
}).catch((res) => {
|
|
195
|
+
var _a2;
|
|
196
|
+
if (unloadRef.current || !netRef.current) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
(_a2 = failRef.current) == null ? void 0 : _a2.call(
|
|
200
|
+
failRef,
|
|
201
|
+
res,
|
|
202
|
+
stepRef.current >= import_const2.StepStatusEnum.Account
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
return;
|
|
206
|
+
}, [api, run, dispatch]);
|
|
224
207
|
const onCancel = () => {
|
|
225
208
|
setDisabled(true);
|
|
226
209
|
api.update({
|
|
227
210
|
type: "CANCEL",
|
|
228
|
-
number:
|
|
211
|
+
number: numRef.current
|
|
229
212
|
});
|
|
230
213
|
};
|
|
231
214
|
(0, import_react.useEffect)(
|
|
@@ -233,6 +216,9 @@ var windcave_default = ({ api, onChange }) => {
|
|
|
233
216
|
var _a, _b;
|
|
234
217
|
unloadRef.current = true;
|
|
235
218
|
(_b = (_a = controllerRef.current) == null ? void 0 : _a.abort) == null ? void 0 : _b.call(_a);
|
|
219
|
+
if (clearRef.current) {
|
|
220
|
+
clearTimeout(clearRef.current);
|
|
221
|
+
}
|
|
236
222
|
},
|
|
237
223
|
[]
|
|
238
224
|
);
|
|
@@ -242,22 +228,34 @@ var windcave_default = ({ api, onChange }) => {
|
|
|
242
228
|
}
|
|
243
229
|
};
|
|
244
230
|
(0, import_react.useEffect)(() => {
|
|
245
|
-
var _a
|
|
231
|
+
var _a;
|
|
246
232
|
if (listRef.current.length === 0) {
|
|
247
233
|
let totalUnit = "";
|
|
248
234
|
if (modeRef.current === import_const.ModeEnum.Pay) {
|
|
249
|
-
totalUnit = (
|
|
235
|
+
totalUnit = (_a = payRef.current) == null ? void 0 : _a.totalUnit;
|
|
250
236
|
} else if (modeRef.current === import_const.ModeEnum.Refund) {
|
|
251
|
-
|
|
237
|
+
if (payRef.current) {
|
|
238
|
+
totalUnit = payRef.current.totalUnit;
|
|
239
|
+
} else {
|
|
240
|
+
totalUnit = formatAmount(amountRef.current, 2, symbolRef.current);
|
|
241
|
+
dispatch(
|
|
242
|
+
(0, import_store.updateState)({
|
|
243
|
+
pay: {
|
|
244
|
+
total: amountRef.current,
|
|
245
|
+
totalUnit
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
);
|
|
249
|
+
}
|
|
252
250
|
}
|
|
253
251
|
const nextStep = (0, import_const2.getStepMapping)(import_const2.StepStatusEnum.Free, {
|
|
254
252
|
money: totalUnit,
|
|
255
|
-
mode
|
|
253
|
+
mode: modeRef.current
|
|
256
254
|
});
|
|
257
255
|
dispatch(
|
|
258
256
|
(0, import_store.updateCustom)({
|
|
259
257
|
list: [nextStep],
|
|
260
|
-
step:
|
|
258
|
+
step: import_const2.StepStatusEnum.Free
|
|
261
259
|
})
|
|
262
260
|
);
|
|
263
261
|
}
|
|
@@ -272,7 +270,9 @@ var windcave_default = ({ api, onChange }) => {
|
|
|
272
270
|
status: item.status,
|
|
273
271
|
className: item.type === import_const2.StemTypeEnum.Passive && item.status === "pedding" ? "pisell-lowcode__eft-pay-step-item-warn" : ""
|
|
274
272
|
}
|
|
275
|
-
)) : null, receiptPage === "again" ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-warn-text pisell-lowcode__eft-pay-body" }, import_utils.locales.getText("page.eftpos-pay.text.signature.text")(
|
|
273
|
+
)) : null, receiptPage === "again" ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-warn-text pisell-lowcode__eft-pay-body" }, import_utils.locales.getText("page.eftpos-pay.text.signature.text")(
|
|
274
|
+
modeRef.current
|
|
275
|
+
)) : null, status === import_const.StatusEnum.Loading ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item pisell-lowcode__eft-pay-step-item-tip" }, import_utils.locales.getText("page.eftpos-pay.text.processing")) : null, status === import_const.StatusEnum.Success ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item pisell-lowcode__eft-pay-step-item-tip" }, import_utils.locales.getText("page.eftpos-pay.text.transaction.end")) : null), !isReceiptPage && status !== import_const.StatusEnum.Success ? /* @__PURE__ */ import_react.default.createElement(
|
|
276
276
|
import_receiptAction.default,
|
|
277
277
|
{
|
|
278
278
|
index: custom == null ? void 0 : custom.step,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type OptionType = {
|
|
2
|
+
id?: string;
|
|
3
|
+
url: string;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
allowExternal?: boolean;
|
|
6
|
+
text?: string;
|
|
7
|
+
type?: 'text/javascript';
|
|
8
|
+
async?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export default function exec(options: OptionType | string, parent: HTMLElement): Promise<unknown>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/load.ts
|
|
20
|
+
var load_exports = {};
|
|
21
|
+
__export(load_exports, {
|
|
22
|
+
default: () => exec
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(load_exports);
|
|
25
|
+
var cache = {};
|
|
26
|
+
function createScript(options) {
|
|
27
|
+
const script = document.createElement("script");
|
|
28
|
+
script.type = options.type || "text/javascript";
|
|
29
|
+
script.async = !!options.async;
|
|
30
|
+
script.id = options.id || options.url;
|
|
31
|
+
if (options.url) {
|
|
32
|
+
script.src = options.url;
|
|
33
|
+
}
|
|
34
|
+
if (options.text) {
|
|
35
|
+
script.text = options.text;
|
|
36
|
+
}
|
|
37
|
+
return script;
|
|
38
|
+
}
|
|
39
|
+
function loadScript(head, script) {
|
|
40
|
+
return new Promise(function(resolve, reject) {
|
|
41
|
+
let done = false;
|
|
42
|
+
script.onload = script.onreadystatechange = function() {
|
|
43
|
+
if (!done && (!script.readyState || script.readyState === "loaded" || script.readyState === "complete")) {
|
|
44
|
+
done = true;
|
|
45
|
+
script.onload = null;
|
|
46
|
+
resolve(script);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
script.onerror = reject;
|
|
50
|
+
head.appendChild(script);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function getScriptById(id) {
|
|
54
|
+
const script = id && document.getElementById(id);
|
|
55
|
+
if (script) {
|
|
56
|
+
return script;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function getScriptByUrl(url) {
|
|
60
|
+
const script = url && document.querySelector("script[src='" + url + "']");
|
|
61
|
+
if (script) {
|
|
62
|
+
return script;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function exec(options, parent) {
|
|
66
|
+
if (typeof options === "string") {
|
|
67
|
+
options = {
|
|
68
|
+
url: options,
|
|
69
|
+
debug: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const cacheId = options.id || options.url;
|
|
73
|
+
const cacheEntry = cache[cacheId];
|
|
74
|
+
if (cacheEntry) {
|
|
75
|
+
if (!!options.debug) {
|
|
76
|
+
console.log("load-js: cache hit", cacheId);
|
|
77
|
+
}
|
|
78
|
+
return cacheEntry;
|
|
79
|
+
}
|
|
80
|
+
if (options.allowExternal !== false) {
|
|
81
|
+
let el;
|
|
82
|
+
if (options.id) {
|
|
83
|
+
el = getScriptById(options.id);
|
|
84
|
+
}
|
|
85
|
+
if (!el) {
|
|
86
|
+
el = getScriptByUrl(options.url);
|
|
87
|
+
}
|
|
88
|
+
if (el) {
|
|
89
|
+
const promise = Promise.resolve(el);
|
|
90
|
+
if (cacheId) {
|
|
91
|
+
cache[cacheId] = promise;
|
|
92
|
+
}
|
|
93
|
+
return promise;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (!options.url && !options.text) {
|
|
97
|
+
throw new Error("load-js: must provide a url or text to load");
|
|
98
|
+
}
|
|
99
|
+
return loadScript(parent, createScript(options));
|
|
100
|
+
}
|