@alipay/ams-checkout 0.0.1744283958-dev.4 → 0.0.1744283958-dev.6
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/dist/umd/ams-checkout.min.js +1 -1
- package/esm/constant/index.d.ts +3 -0
- package/esm/constant/index.js +3 -0
- package/esm/core/component/element/elementContainerService/containerService.d.ts +1 -0
- package/esm/core/component/element/elementContainerService/containerService.js +10 -1
- package/esm/core/component/element/elementContainerService/index.js +3 -0
- package/esm/core/component/element/elementController/index.d.ts +1 -0
- package/esm/core/component/element/elementController/index.js +21 -9
- package/esm/core/component/element/type.d.ts +13 -0
- package/esm/core/component/element/util.d.ts +2 -1
- package/esm/core/component/element/util.js +124 -0
- package/esm/foundation/index.d.ts +1 -0
- package/esm/foundation/index.js +1 -0
- package/esm/foundation/service/container/index.js +7 -0
- package/package.json +1 -1
package/esm/constant/index.d.ts
CHANGED
@@ -216,6 +216,9 @@ export declare const EVENT: {
|
|
216
216
|
webAppReady: {
|
217
217
|
name: string;
|
218
218
|
};
|
219
|
+
showToast: {
|
220
|
+
name: string;
|
221
|
+
};
|
219
222
|
};
|
220
223
|
export declare const COMPONENT_CONTAINER_ID = "ams-component-container";
|
221
224
|
export declare const COMPONENT_SECTION_ID = "ams-component-section";
|
package/esm/constant/index.js
CHANGED
@@ -45,7 +45,10 @@ export var ContainerController = /*#__PURE__*/function () {
|
|
45
45
|
platform: PlatformEnum.desktop,
|
46
46
|
isRetention: false,
|
47
47
|
selector: selector,
|
48
|
-
appendAliasContainerId: true
|
48
|
+
appendAliasContainerId: true,
|
49
|
+
iframeStyle: {
|
50
|
+
display: 'block'
|
51
|
+
}
|
49
52
|
}, processor.generateIframeSrc({
|
50
53
|
link: options === null || options === void 0 || (_options$debugProps = options.debugProps) === null || _options$debugProps === void 0 ? void 0 : _options$debugProps.localLink,
|
51
54
|
instanceId: this.instanceId
|
@@ -103,6 +106,12 @@ export var ContainerController = /*#__PURE__*/function () {
|
|
103
106
|
value: function getEventService() {
|
104
107
|
return this.eventService;
|
105
108
|
}
|
109
|
+
}, {
|
110
|
+
key: "destroy",
|
111
|
+
value: function destroy() {
|
112
|
+
this.eventService.destroy();
|
113
|
+
this.containerElement.remove();
|
114
|
+
}
|
106
115
|
}, {
|
107
116
|
key: "getContainerService",
|
108
117
|
value: function getContainerService() {
|
@@ -31,7 +31,7 @@ import { ElementContainerService } from "../elementContainerService"; // 引入
|
|
31
31
|
import { IContainerStatus } from "../elementContainerService/containerService";
|
32
32
|
import { oneAccountUpdate, sdkActionUpdate } from "../mock";
|
33
33
|
import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode } from "../type";
|
34
|
-
import { checkCanMount, checkCanUpdate, handleRedirect } from "../util";
|
34
|
+
import { checkCanMount, checkCanUpdate, handleRedirect, showToast } from "../util";
|
35
35
|
var TIMEOUT_DURATION = 10000;
|
36
36
|
var ElementController = /*#__PURE__*/function () {
|
37
37
|
// 新增变量
|
@@ -164,9 +164,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
164
164
|
function readyCallback(payload) {
|
165
165
|
var _this2 = this;
|
166
166
|
var resultData = _objectSpread({
|
167
|
-
getValue: this.elementProcessors[renderOptions.type].getValue.bind(this.elementProcessors[renderOptions.type]),
|
167
|
+
getValue: this === null || this === void 0 ? void 0 : this.elementProcessors[renderOptions.type].getValue.bind(this === null || this === void 0 ? void 0 : this.elementProcessors[renderOptions.type]),
|
168
168
|
on: function on(event, callback) {
|
169
|
-
_this2.elementProcessors[renderOptions.type].registerEventListener(event, callback);
|
169
|
+
_this2 === null || _this2 === void 0 || _this2.elementProcessors[renderOptions.type].registerEventListener(event, callback);
|
170
170
|
}
|
171
171
|
}, payload);
|
172
172
|
resolve(resultData);
|
@@ -297,7 +297,12 @@ var ElementController = /*#__PURE__*/function () {
|
|
297
297
|
this.serviceMap.EventCenter.listen(EVENT.redirect.name, function (data) {
|
298
298
|
handleRedirect(data);
|
299
299
|
});
|
300
|
+
this.serviceMap.EventCenter.listen(EVENT.destroy.name, function () {
|
301
|
+
_this4.elementContainer.setStatus(IContainerStatus.READY);
|
302
|
+
_this4.destroyHandle();
|
303
|
+
});
|
300
304
|
this.serviceMap.EventCenter.listen(EVENT.webAppReady.name, function (data) {
|
305
|
+
clearTimeout(_this4.initTimeout);
|
301
306
|
if (_this4.elementContainerService.getContainerService(data.source)) {
|
302
307
|
renderCallback({
|
303
308
|
success: true
|
@@ -306,6 +311,9 @@ var ElementController = /*#__PURE__*/function () {
|
|
306
311
|
}
|
307
312
|
_this4.changeLoading(false);
|
308
313
|
});
|
314
|
+
this.serviceMap.EventCenter.listen(EVENT.showToast.name, function (data) {
|
315
|
+
showToast(data);
|
316
|
+
});
|
309
317
|
}
|
310
318
|
}, {
|
311
319
|
key: "sendRequestAndWaitWebLaunch",
|
@@ -418,17 +426,21 @@ var ElementController = /*#__PURE__*/function () {
|
|
418
426
|
return updatePayment;
|
419
427
|
}()
|
420
428
|
}, {
|
421
|
-
key: "
|
422
|
-
value: function
|
429
|
+
key: "destroyHandle",
|
430
|
+
value: function destroyHandle() {
|
423
431
|
this.elementContainer.destroy();
|
424
|
-
this.
|
432
|
+
this.elementContainerService.destroy();
|
433
|
+
this.serviceMap.EventCenter.cleanIFrames();
|
425
434
|
// popup未注册会报错,但element不需要感知popup是否被注册
|
426
435
|
try {
|
427
436
|
destroyModal(); // 关闭popup弹窗
|
428
437
|
} catch (error) {}
|
429
|
-
|
430
|
-
|
431
|
-
|
438
|
+
}
|
439
|
+
}, {
|
440
|
+
key: "destroy",
|
441
|
+
value: function destroy() {
|
442
|
+
this.destroyHandle();
|
443
|
+
this.elementContainer.setStatus(IContainerStatus.DESTROYED);
|
432
444
|
}
|
433
445
|
}]);
|
434
446
|
return ElementController;
|
@@ -375,4 +375,17 @@ export interface IElementProcessors {
|
|
375
375
|
[ElementType.address]: AddressProcessor;
|
376
376
|
[ElementType.payment]: PaymentProcessor;
|
377
377
|
}
|
378
|
+
export interface IToastOptions {
|
379
|
+
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'center';
|
380
|
+
backgroundColor?: string;
|
381
|
+
color?: string;
|
382
|
+
padding?: string;
|
383
|
+
borderRadius?: string;
|
384
|
+
fontSize?: string;
|
385
|
+
zIndex?: number;
|
386
|
+
width?: string;
|
387
|
+
duration?: number;
|
388
|
+
icon?: 'SUCCESS' | 'FAIL';
|
389
|
+
spin?: boolean;
|
390
|
+
}
|
378
391
|
export {};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { IElementStatus } from '../../../foundation';
|
2
2
|
import { Ianalytics, IPaymentSessionMetaData } from '../../../types';
|
3
3
|
import { ContainerController } from './elementContainerService/containerService';
|
4
|
-
import { ELEMENT_ENVIRONMENT_TYPE, IElementOptions } from './type';
|
4
|
+
import { ELEMENT_ENVIRONMENT_TYPE, IElementOptions, IToastOptions } from './type';
|
5
5
|
declare const formatElementOption: (options: IElementOptions) => {
|
6
6
|
environment: ELEMENT_ENVIRONMENT_TYPE;
|
7
7
|
locale?: string;
|
@@ -56,4 +56,5 @@ export declare function redirect(data: {
|
|
56
56
|
applinkUrl?: string;
|
57
57
|
callAppJudgeTime?: number;
|
58
58
|
}): Promise<void>;
|
59
|
+
export declare function showToast(options?: IToastOptions, callback?: Function): void;
|
59
60
|
export { formatElementOption };
|
@@ -324,4 +324,128 @@ export function redirect(data) {
|
|
324
324
|
}
|
325
325
|
});
|
326
326
|
}
|
327
|
+
export function showToast() {
|
328
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
329
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
330
|
+
var createNode = function createNode() {
|
331
|
+
var tag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'div';
|
332
|
+
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
333
|
+
var children = arguments.length > 2 ? arguments[2] : undefined;
|
334
|
+
var node = document.createElement(tag);
|
335
|
+
Object.keys(props).forEach(function (key) {
|
336
|
+
if (key === 'style') {
|
337
|
+
Object.keys(props[key]).forEach(function (styleKey) {
|
338
|
+
node.style[styleKey] = props[key][styleKey];
|
339
|
+
});
|
340
|
+
} else {
|
341
|
+
node.setAttribute(key, props[key]);
|
342
|
+
}
|
343
|
+
});
|
344
|
+
if (typeof children === 'string') node.textContent = children;
|
345
|
+
return node;
|
346
|
+
};
|
347
|
+
var defaultOptions = {
|
348
|
+
position: 'bottom-right',
|
349
|
+
backgroundColor: 'rgba(0, 0, 0, 0.80)',
|
350
|
+
color: '#ffffff',
|
351
|
+
padding: '20px 16px',
|
352
|
+
borderRadius: '8px',
|
353
|
+
fontSize: '14px',
|
354
|
+
zIndex: 9999,
|
355
|
+
width: '148px',
|
356
|
+
duration: 2000
|
357
|
+
};
|
358
|
+
var defaultIcon = {
|
359
|
+
SUCCESS: 'https://cdn.marmot-cloud.com/storage/2024/07/10/10b191d6-0b0a-4bd9-96cc-310b7f2a8530.svg',
|
360
|
+
FAIL: 'https://cdn.marmot-cloud.com/storage/2024/11/08/4ae27343-61d2-4a07-b323-c951c7711b40.svg'
|
361
|
+
};
|
362
|
+
var config = _objectSpread(_objectSpread({}, defaultOptions), options);
|
363
|
+
var container = document.getElementById('antom_toast-container');
|
364
|
+
if (!container) {
|
365
|
+
container = createNode('div', {
|
366
|
+
style: {
|
367
|
+
position: 'fixed',
|
368
|
+
display: 'flex',
|
369
|
+
justifyContent: 'center',
|
370
|
+
alignItems: 'center',
|
371
|
+
pointerEvents: 'none'
|
372
|
+
},
|
373
|
+
id: 'antom_toast-container'
|
374
|
+
});
|
375
|
+
document.body.appendChild(container);
|
376
|
+
} else {
|
377
|
+
container.innerHTML = '';
|
378
|
+
}
|
379
|
+
switch (config.position) {
|
380
|
+
case 'top-left':
|
381
|
+
container.style.top = '20px';
|
382
|
+
container.style.left = '20px';
|
383
|
+
break;
|
384
|
+
case 'top-right':
|
385
|
+
container.style.top = '20px';
|
386
|
+
container.style.right = '20px';
|
387
|
+
break;
|
388
|
+
case 'bottom-left':
|
389
|
+
container.style.bottom = '20px';
|
390
|
+
container.style.left = '20px';
|
391
|
+
break;
|
392
|
+
case 'bottom-right':
|
393
|
+
default:
|
394
|
+
container.style.bottom = '0';
|
395
|
+
container.style.right = '0';
|
396
|
+
container.style.top = '0';
|
397
|
+
container.style.left = '0';
|
398
|
+
break;
|
399
|
+
}
|
400
|
+
var toast = createNode('div', {
|
401
|
+
style: {
|
402
|
+
backgroundColor: config.backgroundColor,
|
403
|
+
color: config.color,
|
404
|
+
padding: config.padding,
|
405
|
+
borderRadius: config.borderRadius,
|
406
|
+
fontSize: config.fontSize,
|
407
|
+
opacity: '0',
|
408
|
+
transition: 'opacity 0.3s ease-in-out',
|
409
|
+
display: 'flex',
|
410
|
+
alignItems: 'center',
|
411
|
+
justifyContent: 'center',
|
412
|
+
flexDirection: 'column',
|
413
|
+
width: config.width,
|
414
|
+
boxSizing: 'border-box'
|
415
|
+
}
|
416
|
+
});
|
417
|
+
if (config.icon) {
|
418
|
+
var icon = createNode('img', {
|
419
|
+
style: {
|
420
|
+
width: '40px',
|
421
|
+
height: '40px'
|
422
|
+
},
|
423
|
+
src: config.icon ? defaultIcon[config.icon] : ''
|
424
|
+
});
|
425
|
+
toast.appendChild(icon);
|
426
|
+
}
|
427
|
+
var text = createNode('span', {
|
428
|
+
style: {
|
429
|
+
textAlign: 'center',
|
430
|
+
marginTop: '12px',
|
431
|
+
lineHeight: '20px',
|
432
|
+
fontFamily: "Noto Sans",
|
433
|
+
fontWeight: 400,
|
434
|
+
fontSize: '14px'
|
435
|
+
}
|
436
|
+
}, config.message);
|
437
|
+
toast.appendChild(text);
|
438
|
+
container.appendChild(toast);
|
439
|
+
setTimeout(function () {
|
440
|
+
toast.style.opacity = '1';
|
441
|
+
}, 10);
|
442
|
+
setTimeout(function () {
|
443
|
+
toast.style.opacity = '0';
|
444
|
+
setTimeout(function () {
|
445
|
+
var _container;
|
446
|
+
(_container = container) === null || _container === void 0 || _container.remove();
|
447
|
+
callback && callback();
|
448
|
+
}, 300);
|
449
|
+
}, config.duration);
|
450
|
+
}
|
327
451
|
export { formatElementOption };
|
package/esm/foundation/index.js
CHANGED
@@ -26,6 +26,7 @@ export var DisplayInfo = /*#__PURE__*/_createClass(function DisplayInfo() {
|
|
26
26
|
_defineProperty(this, "appearance", void 0);
|
27
27
|
// append selector name to containerId
|
28
28
|
_defineProperty(this, "appendAliasContainerId", void 0);
|
29
|
+
_defineProperty(this, "iframeStyle", void 0);
|
29
30
|
this.platform = isPC() ? PlatformEnum.desktop : PlatformEnum.mobile;
|
30
31
|
this.isRetention = true;
|
31
32
|
this.type = DisplayTypeEnum.popup;
|
@@ -7,6 +7,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
7
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
9
9
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
10
|
+
import { isEmpty } from "../../../util";
|
10
11
|
import { addInlineLoading, createInlineBaseElement } from "../../../component/component.inline.style";
|
11
12
|
import { addPopupLoading, createBaseElement } from "../../../component/component.popup.style";
|
12
13
|
import { insertStyleSheet } from "../../../component/popupWindow.style";
|
@@ -64,6 +65,12 @@ export var ContainerService = /*#__PURE__*/function () {
|
|
64
65
|
type = displayInfo.type,
|
65
66
|
platform = displayInfo.platform;
|
66
67
|
var webApp = createIframe('antom-sdk-web-app' + (displayInfo.appendAliasContainerId ? "-".concat(selector) : ''));
|
68
|
+
if (!isEmpty(displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.iframeStyle)) {
|
69
|
+
Object.keys(displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.iframeStyle).forEach(function (key) {
|
70
|
+
var _displayInfo$iframeSt;
|
71
|
+
webApp.style[key] = displayInfo === null || displayInfo === void 0 || (_displayInfo$iframeSt = displayInfo.iframeStyle) === null || _displayInfo$iframeSt === void 0 ? void 0 : _displayInfo$iframeSt[key];
|
72
|
+
});
|
73
|
+
}
|
67
74
|
this.webApp = webApp;
|
68
75
|
this.displayInfo = displayInfo;
|
69
76
|
webApp.src = url;
|