@alipay/ams-checkout 0.0.1744283958-dev.5 → 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.
@@ -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";
@@ -218,6 +218,9 @@ export var EVENT = {
218
218
  },
219
219
  webAppReady: {
220
220
  name: 'webAppReady'
221
+ },
222
+ showToast: {
223
+ name: 'showToast'
221
224
  }
222
225
  };
223
226
  export var COMPONENT_CONTAINER_ID = 'ams-component-container';
@@ -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
@@ -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
  // 新增变量
@@ -302,6 +302,7 @@ var ElementController = /*#__PURE__*/function () {
302
302
  _this4.destroyHandle();
303
303
  });
304
304
  this.serviceMap.EventCenter.listen(EVENT.webAppReady.name, function (data) {
305
+ clearTimeout(_this4.initTimeout);
305
306
  if (_this4.elementContainerService.getContainerService(data.source)) {
306
307
  renderCallback({
307
308
  success: true
@@ -310,6 +311,9 @@ var ElementController = /*#__PURE__*/function () {
310
311
  }
311
312
  _this4.changeLoading(false);
312
313
  });
314
+ this.serviceMap.EventCenter.listen(EVENT.showToast.name, function (data) {
315
+ showToast(data);
316
+ });
313
317
  }
314
318
  }, {
315
319
  key: "sendRequestAndWaitWebLaunch",
@@ -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 };
@@ -28,6 +28,7 @@ export declare class DisplayInfo {
28
28
  selector: string;
29
29
  appearance?: Record<string, any>;
30
30
  appendAliasContainerId?: boolean;
31
+ iframeStyle?: Partial<CSSStyleDeclaration>;
31
32
  constructor();
32
33
  }
33
34
  /**
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1744283958-dev.5",
3
+ "version": "0.0.1744283958-dev.6",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",