@alipay/ams-checkout 0.0.1723203704-dev.3 → 0.0.1723203704-dev.5
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 +0 -4
- package/esm/constant/index.js +0 -4
- package/esm/core/component/address.d.ts +3 -31
- package/esm/core/component/address.js +15 -241
- package/esm/core/component/index.js +54 -49
- package/esm/core/instance/index.js +8 -0
- package/esm/index.d.ts +2 -5
- package/esm/index.js +7 -19
- package/esm/plugin/component/cashierApp.js +4 -0
- package/esm/plugin/component/index.js +81 -59
- package/esm/types/index.d.ts +100 -0
- package/esm/types/index.js +4 -0
- package/package.json +1 -1
- package/esm/core/instance/address.d.ts +0 -76
- package/esm/core/instance/address.js +0 -283
- package/esm/plugin/address/cashierApp.d.ts +0 -34
- package/esm/plugin/address/cashierApp.js +0 -218
- package/esm/plugin/address/channel.d.ts +0 -20
- package/esm/plugin/address/channel.js +0 -52
- package/esm/plugin/address/component.inline.style.d.ts +0 -11
- package/esm/plugin/address/component.inline.style.js +0 -38
- package/esm/plugin/address/component.popup.style.d.ts +0 -16
- package/esm/plugin/address/component.popup.style.js +0 -174
- package/esm/plugin/address/index.d.ts +0 -108
- package/esm/plugin/address/index.js +0 -862
- package/esm/plugin/address/popupWindow.style.d.ts +0 -8
- package/esm/plugin/address/popupWindow.style.js +0 -65
- package/esm/types/address.d.ts +0 -92
- package/esm/types/address.js +0 -7
@@ -1,862 +0,0 @@
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
2
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
5
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
7
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
8
|
-
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; }
|
9
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
10
|
-
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); }
|
11
|
-
/**
|
12
|
-
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
14
|
-
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
15
|
-
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
16
|
-
*/
|
17
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
18
|
-
import { sdkVersion } from "../../config";
|
19
|
-
import { COMPONENTPLUGINID, COMPONENT_CONTAINER_ID, COMPONENT_RETENTION_ID, COMPONENT_SECTION_ID, ERRORMESSAGE, EVENT, LISTENER_PREFIX, LOADING_ID, LOADTIME_LIMIT, MOCKUP_ID, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../constant";
|
20
|
-
import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
|
21
|
-
import { getType, isJsonString, isPC } from "../../util";
|
22
|
-
import { createIframe, createPreloadIframe, getAppDomain, getIframeUrl } from "./cashierApp";
|
23
|
-
import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
|
24
|
-
import { addPopupLoading, createBaseElement, createRetentionPopup, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup, slideInAndOutKeyframes } from "./component.popup.style";
|
25
|
-
import { insertStyleSheet } from "./popupWindow.style";
|
26
|
-
window.changingPageHeight = window.innerHeight;
|
27
|
-
var ComponentApp = /*#__PURE__*/function () {
|
28
|
-
function ComponentApp() {
|
29
|
-
_classCallCheck(this, ComponentApp);
|
30
|
-
_defineProperty(this, "app", void 0);
|
31
|
-
_defineProperty(this, "AMSSDK", void 0);
|
32
|
-
_defineProperty(this, "platform", void 0);
|
33
|
-
_defineProperty(this, "_performanceData", []);
|
34
|
-
_defineProperty(this, "_loadAppPromiseResolve", null);
|
35
|
-
_defineProperty(this, "_isInitComponent", void 0);
|
36
|
-
_defineProperty(this, "_globalData", void 0);
|
37
|
-
_defineProperty(this, "popupApp", void 0);
|
38
|
-
_defineProperty(this, "appDomain", void 0);
|
39
|
-
_defineProperty(this, "createIframeNode", void 0);
|
40
|
-
_defineProperty(this, "createPreloadIframeNode", void 0);
|
41
|
-
_defineProperty(this, "_selector", void 0);
|
42
|
-
_defineProperty(this, "_appVersion", void 0);
|
43
|
-
_defineProperty(this, "_isRetention", void 0);
|
44
|
-
_defineProperty(this, "_allowSubmitPayCallAhead", void 0);
|
45
|
-
_defineProperty(this, "_actionQueryPromise", null);
|
46
|
-
_defineProperty(this, "_actionSubmitPromise", null);
|
47
|
-
_defineProperty(this, "_renderParams", null);
|
48
|
-
_defineProperty(this, "_componentSign", componentSignEnum.NONE);
|
49
|
-
_defineProperty(this, "_appLocationSearch", void 0);
|
50
|
-
_defineProperty(this, "_renderDisplayType", renderDisplayTypeEnum.popup);
|
51
|
-
_defineProperty(this, "_multipleCallbackEvents", void 0);
|
52
|
-
_defineProperty(this, "_merchantAppointParam", void 0);
|
53
|
-
_defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
|
54
|
-
this._appVersion = '1.19.0';
|
55
|
-
this._isInitComponent = false;
|
56
|
-
this._selector = "#".concat(COMPONENT_SECTION_ID);
|
57
|
-
this.createIframeNode = function () {
|
58
|
-
return Promise.resolve();
|
59
|
-
};
|
60
|
-
this.createPreloadIframeNode = function () {
|
61
|
-
return Promise.resolve();
|
62
|
-
};
|
63
|
-
this.platform = isPC() ? platformEnum.desktop : platformEnum.mobile;
|
64
|
-
this._isRetention = true;
|
65
|
-
this._appLocationSearch = '';
|
66
|
-
this._performanceData.push({
|
67
|
-
key: 'sdk_init',
|
68
|
-
value: Date.now()
|
69
|
-
});
|
70
|
-
this._globalData = new Map();
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* @description Cancel listening and destroy the dom
|
75
|
-
*/
|
76
|
-
_createClass(ComponentApp, [{
|
77
|
-
key: "logoutPlugin",
|
78
|
-
value: function logoutPlugin() {
|
79
|
-
this.cleanContainer(true);
|
80
|
-
}
|
81
|
-
|
82
|
-
/**
|
83
|
-
* @description When SDK registers plug-ins, it is a required function to receive SDK instances
|
84
|
-
*/
|
85
|
-
}, {
|
86
|
-
key: "applyPlugin",
|
87
|
-
value: function applyPlugin(AMSSDK) {
|
88
|
-
this.AMSSDK = AMSSDK;
|
89
|
-
this.subscribeFromSDK();
|
90
|
-
}
|
91
|
-
}, {
|
92
|
-
key: "initLoggerMeta",
|
93
|
-
value: function initLoggerMeta() {
|
94
|
-
this.AMSSDK.logger.setMedta({
|
95
|
-
platform: this.platform === platformEnum.desktop ? 'PC' : 'WAP',
|
96
|
-
// PC/WAP,
|
97
|
-
sdkVersion: sdkVersion,
|
98
|
-
webAppVersion: this._appVersion,
|
99
|
-
instanceId: this.AMSSDK._instanceId,
|
100
|
-
storageId: this.AMSSDK._storageId // the better way to use md5 paymentSesionID
|
101
|
-
});
|
102
|
-
}
|
103
|
-
|
104
|
-
/**
|
105
|
-
* @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
|
106
|
-
*/
|
107
|
-
}, {
|
108
|
-
key: "setRender",
|
109
|
-
value: function setRender(renderFunc) {
|
110
|
-
this.createIframeNode = renderFunc;
|
111
|
-
}
|
112
|
-
}, {
|
113
|
-
key: "setPreloadRender",
|
114
|
-
value: function setPreloadRender(renderFunc) {
|
115
|
-
this.createPreloadIframeNode = renderFunc;
|
116
|
-
}
|
117
|
-
}, {
|
118
|
-
key: "initSecurity",
|
119
|
-
value: function initSecurity() {
|
120
|
-
var _this = this;
|
121
|
-
var product = productSceneEnum.ELEMENT_ADDRESS;
|
122
|
-
if (componentSignEnum.ELEMENT_ADDRESS === this._componentSign) return;
|
123
|
-
var securitySDK = this.AMSSDK._getSecuritySDKByProductScene({
|
124
|
-
product: product
|
125
|
-
});
|
126
|
-
if (!securitySDK) {
|
127
|
-
this.AMSSDK.logger.logInfo({
|
128
|
-
title: 'sdk_event_securitySdkInit'
|
129
|
-
});
|
130
|
-
this.AMSSDK._newSecuritySDKByScene({
|
131
|
-
product: product
|
132
|
-
}, function () {
|
133
|
-
_this.AMSSDK.logger.logInfo({
|
134
|
-
title: 'sdk_event_securitySdkInitSuccess'
|
135
|
-
});
|
136
|
-
}, function () {
|
137
|
-
_this.AMSSDK.logger.logError({
|
138
|
-
title: 'sdk_error_securitySdkInitFailed'
|
139
|
-
}, {
|
140
|
-
sign: 'SDK internal initialization'
|
141
|
-
});
|
142
|
-
});
|
143
|
-
}
|
144
|
-
}
|
145
|
-
}, {
|
146
|
-
key: "getDeviceIdAndLog",
|
147
|
-
value: function getDeviceIdAndLog() {
|
148
|
-
var _this2 = this;
|
149
|
-
var deviceIdParameter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
150
|
-
var isPolling = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
151
|
-
return new Promise(function (resolve) {
|
152
|
-
// To avoid rendering being blocked, move the logic to the next event loop for processing
|
153
|
-
setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
154
|
-
var getDeviceIdStartTime, securitySDK, deviceId;
|
155
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
156
|
-
while (1) switch (_context.prev = _context.next) {
|
157
|
-
case 0:
|
158
|
-
getDeviceIdStartTime = Date.now();
|
159
|
-
securitySDK = _this2.AMSSDK._getSecuritySDKByProductScene({
|
160
|
-
product: productSceneEnum.ELEMENT_ADDRESS
|
161
|
-
});
|
162
|
-
deviceId = '';
|
163
|
-
if (!securitySDK) {
|
164
|
-
_context.next = 15;
|
165
|
-
break;
|
166
|
-
}
|
167
|
-
if (!(isPolling && parseInt(deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.tokenCollectTime) > 0)) {
|
168
|
-
_context.next = 10;
|
169
|
-
break;
|
170
|
-
}
|
171
|
-
_context.next = 7;
|
172
|
-
return securitySDK.pollingGetApdidToken(deviceIdParameter);
|
173
|
-
case 7:
|
174
|
-
_context.t0 = _context.sent;
|
175
|
-
_context.next = 13;
|
176
|
-
break;
|
177
|
-
case 10:
|
178
|
-
_context.next = 12;
|
179
|
-
return securitySDK.getApdidToken();
|
180
|
-
case 12:
|
181
|
-
_context.t0 = _context.sent;
|
182
|
-
case 13:
|
183
|
-
deviceId = _context.t0;
|
184
|
-
_this2.logDeviceId(deviceId, getDeviceIdStartTime);
|
185
|
-
case 15:
|
186
|
-
resolve(deviceId);
|
187
|
-
case 16:
|
188
|
-
case "end":
|
189
|
-
return _context.stop();
|
190
|
-
}
|
191
|
-
}, _callee);
|
192
|
-
})), 0);
|
193
|
-
});
|
194
|
-
}
|
195
|
-
}, {
|
196
|
-
key: "logDeviceId",
|
197
|
-
value: function logDeviceId(deviceId, getDeviceIdStartTime) {
|
198
|
-
var time = "".concat(Date.now() - getDeviceIdStartTime);
|
199
|
-
if (deviceId) {
|
200
|
-
this.AMSSDK.logger.logInfo({
|
201
|
-
title: 'sdk_event_securitySdkGetTokenSuccess'
|
202
|
-
}, {
|
203
|
-
deviceId: deviceId,
|
204
|
-
time: time
|
205
|
-
}).send();
|
206
|
-
} else {
|
207
|
-
this.AMSSDK.logger.logInfo({
|
208
|
-
title: 'sdk_error_securitySdkGetTokenFailed'
|
209
|
-
}, {
|
210
|
-
deviceId: deviceId,
|
211
|
-
time: time
|
212
|
-
}).send();
|
213
|
-
}
|
214
|
-
}
|
215
|
-
|
216
|
-
/**
|
217
|
-
* @description render iframe content
|
218
|
-
*/
|
219
|
-
}, {
|
220
|
-
key: "appendIframeNodes",
|
221
|
-
value: function appendIframeNodes(componentSign, renderParams) {
|
222
|
-
var _this3 = this;
|
223
|
-
if (this._isInitComponent) {
|
224
|
-
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
|
225
|
-
return Promise.reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
|
226
|
-
}
|
227
|
-
this._isInitComponent = true;
|
228
|
-
this._renderParams = renderParams;
|
229
|
-
this._componentSign = componentSign;
|
230
|
-
if (renderParams !== null && renderParams !== void 0 && renderParams.selector) this._selector = renderParams.selector;
|
231
|
-
this._renderDisplayType = renderParams.renderDisplayType;
|
232
|
-
var insertedNode = this._renderDisplayType === renderDisplayTypeEnum.inline ? "#".concat(COMPONENT_CONTAINER_ID) : this._selector;
|
233
|
-
this.initLoggerMeta();
|
234
|
-
this.initSecurity();
|
235
|
-
this._performanceData.push({
|
236
|
-
key: 'sdk_create_component',
|
237
|
-
value: Date.now()
|
238
|
-
});
|
239
|
-
this.AMSSDK.logger.logInfo({
|
240
|
-
title: 'sdk_event_createComponent'
|
241
|
-
}, {
|
242
|
-
product: productSceneEnum.ELEMENT_ADDRESS
|
243
|
-
}).send();
|
244
|
-
this.dispatchToSDK(EVENT.eventCallback.name, {
|
245
|
-
code: eventCodeEnum.SDK_START_OF_LOADING
|
246
|
-
});
|
247
|
-
if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
|
248
|
-
var container = createInlineBaseElement(this._selector);
|
249
|
-
if (container) this.renderInlineLoading(renderParams, container);
|
250
|
-
insertStyleSheet();
|
251
|
-
}
|
252
|
-
if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
|
253
|
-
createBaseElement(this.platform, this.closeBtnFunc.bind(this));
|
254
|
-
createRetentionPopup(this.platform, this.hideRetentionPopupFunc.bind(this), this.retentionPopupLeaveFunc.bind(this));
|
255
|
-
this.renderPopupLoading(renderParams);
|
256
|
-
}
|
257
|
-
this.createApp(renderParams);
|
258
|
-
return Promise.all([this.createIframeNode(this, insertedNode, this._renderDisplayType), this._createLoadAppPromise()]).then(function () {
|
259
|
-
return Promise.resolve();
|
260
|
-
}).catch(function (error) {
|
261
|
-
_this3.AMSSDK.logger.logError({
|
262
|
-
title: 'sdk_error_created_app_process_failed'
|
263
|
-
}).send();
|
264
|
-
_this3._isInitComponent = false;
|
265
|
-
_this3.cleanContainer();
|
266
|
-
return Promise.reject(error);
|
267
|
-
});
|
268
|
-
}
|
269
|
-
}, {
|
270
|
-
key: "showRetentionPopup",
|
271
|
-
value: function showRetentionPopup() {
|
272
|
-
var retentionPopup = document.getElementById(COMPONENT_RETENTION_ID);
|
273
|
-
var container = document.getElementById(COMPONENT_CONTAINER_ID);
|
274
|
-
if (retentionPopup) {
|
275
|
-
container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-opacity"));
|
276
|
-
retentionPopup.classList.remove("".concat(COMPONENT_RETENTION_ID, "-hidden"));
|
277
|
-
retentionPopup.classList.add("".concat(COMPONENT_RETENTION_ID, "-show"));
|
278
|
-
}
|
279
|
-
}
|
280
|
-
}, {
|
281
|
-
key: "closeBtnFunc",
|
282
|
-
value: function closeBtnFunc() {
|
283
|
-
// element && element.removeEventListener()
|
284
|
-
if (this._isRetention) this.showRetentionPopup();else {
|
285
|
-
this.cleanContainer();
|
286
|
-
this.dispatchToSDK(EVENT.close.name, {});
|
287
|
-
this.handleDeclarePopWindowCallback();
|
288
|
-
}
|
289
|
-
}
|
290
|
-
}, {
|
291
|
-
key: "appendPreloadIframeNodes",
|
292
|
-
value: function appendPreloadIframeNodes(componentSign, productSceneVersion) {
|
293
|
-
var virtualPreloadIframe = this.createPreloadApp(componentSign, productSceneVersion);
|
294
|
-
this.createPreloadIframeNode(virtualPreloadIframe);
|
295
|
-
this.AMSSDK.logger.logInfo({
|
296
|
-
title: 'performance_optimization_preload'
|
297
|
-
}, {
|
298
|
-
componentSign: componentSign,
|
299
|
-
productSceneVersion: productSceneVersion
|
300
|
-
});
|
301
|
-
}
|
302
|
-
}, {
|
303
|
-
key: "renderInlineLoading",
|
304
|
-
value: function renderInlineLoading(renderParams, selector) {
|
305
|
-
var _renderParams$appeara;
|
306
|
-
var showLoading = renderParams === null || renderParams === void 0 || (_renderParams$appeara = renderParams.appearance) === null || _renderParams$appeara === void 0 ? void 0 : _renderParams$appeara.showLoading;
|
307
|
-
showLoading = typeof showLoading === 'boolean' ? showLoading : true;
|
308
|
-
if (showLoading) addInlineLoading(selector, this.platform);
|
309
|
-
}
|
310
|
-
}, {
|
311
|
-
key: "renderPopupLoading",
|
312
|
-
value: function renderPopupLoading(renderParams) {
|
313
|
-
var _renderParams$appeara2;
|
314
|
-
var showLoading = renderParams === null || renderParams === void 0 || (_renderParams$appeara2 = renderParams.appearance) === null || _renderParams$appeara2 === void 0 ? void 0 : _renderParams$appeara2.showLoading;
|
315
|
-
showLoading = typeof showLoading === 'boolean' ? showLoading : true;
|
316
|
-
if (!showLoading) return;
|
317
|
-
var mockup = document.getElementById(MOCKUP_ID);
|
318
|
-
if (mockup) mockup.style.display = 'block';
|
319
|
-
addPopupLoading();
|
320
|
-
}
|
321
|
-
}, {
|
322
|
-
key: "_createLoadAppPromise",
|
323
|
-
value: function _createLoadAppPromise(loadTimeLimit) {
|
324
|
-
var _this4 = this;
|
325
|
-
return new Promise(function (resolve, reject) {
|
326
|
-
_this4._loadAppPromiseResolve = resolve;
|
327
|
-
setTimeout(function () {
|
328
|
-
reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
|
329
|
-
}, loadTimeLimit !== null && loadTimeLimit !== void 0 ? loadTimeLimit : LOADTIME_LIMIT);
|
330
|
-
}).catch(function (error) {
|
331
|
-
_this4.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
|
332
|
-
_this4.AMSSDK.logger.logError({
|
333
|
-
title: 'sdk_error_web_app_timeout'
|
334
|
-
}).send();
|
335
|
-
return Promise.reject(error);
|
336
|
-
});
|
337
|
-
}
|
338
|
-
}, {
|
339
|
-
key: "cleanElement",
|
340
|
-
value: function cleanElement() {
|
341
|
-
try {
|
342
|
-
var _document$getElementB;
|
343
|
-
// selector and container
|
344
|
-
if (getType(this._selector) === 'string') {
|
345
|
-
var selectorDom = document.querySelector(this._selector);
|
346
|
-
if (selectorDom) selectorDom.innerHTML = '';
|
347
|
-
}
|
348
|
-
var container = document.getElementById(COMPONENT_CONTAINER_ID);
|
349
|
-
if (container) container === null || container === void 0 || container.remove();
|
350
|
-
|
351
|
-
// animation
|
352
|
-
(_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style"))) === null || _document$getElementB === void 0 || _document$getElementB.remove();
|
353
|
-
|
354
|
-
// mockup
|
355
|
-
var body = document.getElementsByTagName('body')[0];
|
356
|
-
body.style.overflow = 'auto';
|
357
|
-
var mockup = document.getElementById(MOCKUP_ID);
|
358
|
-
mockup === null || mockup === void 0 || mockup.remove();
|
359
|
-
|
360
|
-
// retentionPopup
|
361
|
-
this.removeRetentionPopup(this.platform);
|
362
|
-
|
363
|
-
// listener
|
364
|
-
this.removeEventListener();
|
365
|
-
} catch (error) {
|
366
|
-
console.error(error);
|
367
|
-
}
|
368
|
-
}
|
369
|
-
}, {
|
370
|
-
key: "removeRetentionPopup",
|
371
|
-
value: function removeRetentionPopup(platform) {
|
372
|
-
_removeRetentionPopup(platform, this.hideRetentionPopupFunc.bind(this), this.retentionPopupLeaveFunc.bind(this));
|
373
|
-
}
|
374
|
-
}, {
|
375
|
-
key: "hideRetentionPopupFunc",
|
376
|
-
value: function hideRetentionPopupFunc() {
|
377
|
-
hideRetentionPopup();
|
378
|
-
}
|
379
|
-
}, {
|
380
|
-
key: "retentionPopupLeaveFunc",
|
381
|
-
value: function retentionPopupLeaveFunc() {
|
382
|
-
this.dispatchToSDK(EVENT.close.name, {});
|
383
|
-
this.hideRetentionPopupFunc();
|
384
|
-
this.cleanContainer();
|
385
|
-
this.handleDeclarePopWindowCallback();
|
386
|
-
}
|
387
|
-
}, {
|
388
|
-
key: "handleDeclarePopWindowCallback",
|
389
|
-
value: function handleDeclarePopWindowCallback() {
|
390
|
-
var eventInfoName = 'popWindowEventInfo';
|
391
|
-
if (this._multipleCallbackEvents && eventInfoName in this._multipleCallbackEvents) {
|
392
|
-
var eventInfo = this._multipleCallbackEvents[eventInfoName];
|
393
|
-
if (eventInfo.enableCallback) {
|
394
|
-
this.dispatchToSDK(EVENT.eventCallback.name, {
|
395
|
-
code: eventInfo.eventName,
|
396
|
-
result: {
|
397
|
-
result: eventInfo.eventResult || {}
|
398
|
-
}
|
399
|
-
});
|
400
|
-
}
|
401
|
-
} else {
|
402
|
-
console.log("not valid ".concat(eventInfoName, " in "), this._multipleCallbackEvents);
|
403
|
-
}
|
404
|
-
}
|
405
|
-
|
406
|
-
// 预加载iframe创建
|
407
|
-
}, {
|
408
|
-
key: "createPreloadApp",
|
409
|
-
value: function createPreloadApp(componentSign) {
|
410
|
-
var productSceneVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1.0';
|
411
|
-
var preloadIframe = createPreloadIframe(componentSign, productSceneVersion);
|
412
|
-
var _getIframeUrl = getIframeUrl({
|
413
|
-
renderDisplayType: renderDisplayTypeEnum.popup,
|
414
|
-
componentSign: componentSign,
|
415
|
-
analytics: {
|
416
|
-
enabled: false
|
417
|
-
},
|
418
|
-
productScene: componentSign,
|
419
|
-
productSceneVersion: productSceneVersion,
|
420
|
-
environment: this.AMSSDK.options.env.environment,
|
421
|
-
appVersion: this._appVersion,
|
422
|
-
instanceId: '',
|
423
|
-
isPreload: 'true'
|
424
|
-
}),
|
425
|
-
path = _getIframeUrl.path,
|
426
|
-
locationSearch = _getIframeUrl.locationSearch;
|
427
|
-
preloadIframe.src = "".concat(path, "?").concat(locationSearch);
|
428
|
-
if (!path) {
|
429
|
-
this.AMSSDK.logger.logError({
|
430
|
-
title: 'performance_optimization_preload_path_error'
|
431
|
-
}, {
|
432
|
-
path: path,
|
433
|
-
locationSearch: locationSearch
|
434
|
-
});
|
435
|
-
}
|
436
|
-
return preloadIframe;
|
437
|
-
}
|
438
|
-
/**
|
439
|
-
* @description Create app
|
440
|
-
*/
|
441
|
-
}, {
|
442
|
-
key: "createApp",
|
443
|
-
value: function createApp(renderParams) {
|
444
|
-
if (!!window.postMessage !== true) {
|
445
|
-
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE);
|
446
|
-
return;
|
447
|
-
}
|
448
|
-
this._performanceData.push({
|
449
|
-
key: 'sdk_popup_start',
|
450
|
-
value: Date.now()
|
451
|
-
});
|
452
|
-
try {
|
453
|
-
var productSceneVersion = '';
|
454
|
-
var productScene = '';
|
455
|
-
var extendInfo = '';
|
456
|
-
var mid = '';
|
457
|
-
var environment = this.AMSSDK.options.env.environment;
|
458
|
-
this.appDomain = getAppDomain({
|
459
|
-
environment: environment,
|
460
|
-
appVersion: this._appVersion,
|
461
|
-
componentSign: this._componentSign,
|
462
|
-
productScene: productScene,
|
463
|
-
productSceneVersion: productSceneVersion,
|
464
|
-
extendInfo: extendInfo,
|
465
|
-
mid: mid
|
466
|
-
});
|
467
|
-
console.log(this.appDomain, 'this.appDomainthis.appDomain');
|
468
|
-
// TODO: 暂时写死本地调试
|
469
|
-
this.appDomain = 'http://page.alipay.net';
|
470
|
-
this.app = createIframe(this.AMSSDK.options.mode, this.platform);
|
471
|
-
// const hostSign = (renderParams?.sessionData || '').split('&&')[1] || '';
|
472
|
-
var _getIframeUrl2 = getIframeUrl({
|
473
|
-
renderDisplayType: renderParams.renderDisplayType,
|
474
|
-
componentSign: this._componentSign,
|
475
|
-
analytics: this.AMSSDK.options.analytics,
|
476
|
-
productScene: productScene,
|
477
|
-
productSceneVersion: productSceneVersion,
|
478
|
-
environment: environment,
|
479
|
-
appVersion: this._appVersion,
|
480
|
-
extendInfo: extendInfo,
|
481
|
-
locale: this.AMSSDK.options.locale,
|
482
|
-
instanceId: this.AMSSDK._instanceId,
|
483
|
-
// hostSign,
|
484
|
-
mid: mid
|
485
|
-
}),
|
486
|
-
path = _getIframeUrl2.path,
|
487
|
-
locationSearch = _getIframeUrl2.locationSearch;
|
488
|
-
console.log(path, 'this.appDomainthis.appDomain');
|
489
|
-
// TODO: 暂时写死本地调试
|
490
|
-
path = 'http://page.alipay.net/page/antom-web-checkout-v2/element-address/1.20.0/pages/address/index.html';
|
491
|
-
this._appLocationSearch = locationSearch;
|
492
|
-
// locationSearch 是一个序列化好的字符串
|
493
|
-
// 先判断path 是否有QueryParams,如果有需要扩展,否则直接拼?xx=xx
|
494
|
-
if (path.indexOf('?') !== -1) {
|
495
|
-
this.app.src = "".concat(path, "&").concat(locationSearch);
|
496
|
-
} else {
|
497
|
-
this.app.src = "".concat(path, "?").concat(locationSearch);
|
498
|
-
}
|
499
|
-
// Subscribe to messages from iframe
|
500
|
-
this.addEventListener();
|
501
|
-
} catch (error) {
|
502
|
-
this.AMSSDK.logger.logError({
|
503
|
-
title: 'sdk_error_created_app_failed'
|
504
|
-
}).send();
|
505
|
-
this.dispatchToSDK(EVENT.error.name, Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
|
506
|
-
stack: error
|
507
|
-
}));
|
508
|
-
}
|
509
|
-
}
|
510
|
-
}, {
|
511
|
-
key: "listener",
|
512
|
-
value: function listener(e) {
|
513
|
-
var _e$data;
|
514
|
-
if (e.origin !== this.appDomain) return;
|
515
|
-
if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.source) === 'react-devtools-content-script') {
|
516
|
-
// 防止 react 开发工具发的消息,非常频繁影响查看日志
|
517
|
-
return;
|
518
|
-
}
|
519
|
-
var isJson = isJsonString(e.data);
|
520
|
-
if (isJson) {
|
521
|
-
var data = JSON.parse(e.data);
|
522
|
-
if (data.name !== messageName.APP_TO_SDK && data.name !== messageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) return;
|
523
|
-
this._handleAppMessage(data);
|
524
|
-
} else {
|
525
|
-
console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
|
526
|
-
this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.NOT_JSON_FORMAT);
|
527
|
-
}
|
528
|
-
}
|
529
|
-
}, {
|
530
|
-
key: "resizeListener",
|
531
|
-
value: function resizeListener(e) {
|
532
|
-
var _e$target, _e$target2;
|
533
|
-
var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
|
534
|
-
cashier.style.transition = 'none';
|
535
|
-
this.dispatchToApp({
|
536
|
-
context: {
|
537
|
-
event: 'renderResize',
|
538
|
-
data: {
|
539
|
-
heightOfVisible: (e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.innerHeight) || window.innerHeight,
|
540
|
-
widthOfVisible: (e === null || e === void 0 || (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : _e$target2.innerWidth) || window.innerWidth
|
541
|
-
}
|
542
|
-
}
|
543
|
-
});
|
544
|
-
}
|
545
|
-
|
546
|
-
/**
|
547
|
-
* @description Initialize subscription iframe message
|
548
|
-
*/
|
549
|
-
}, {
|
550
|
-
key: "addEventListener",
|
551
|
-
value: function addEventListener() {
|
552
|
-
console.log('进行了监听898989', this.AMSSDK._instanceId);
|
553
|
-
this.removeEventListener();
|
554
|
-
window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
|
555
|
-
window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")] = this.resizeListener.bind(this);
|
556
|
-
window.addEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
|
557
|
-
window.addEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
|
558
|
-
}
|
559
|
-
}, {
|
560
|
-
key: "removeEventListener",
|
561
|
-
value: function removeEventListener() {
|
562
|
-
window.removeEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
|
563
|
-
window.removeEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
|
564
|
-
}
|
565
|
-
|
566
|
-
/**
|
567
|
-
* @description Processing messages from iframe
|
568
|
-
*/
|
569
|
-
}, {
|
570
|
-
key: "_handleAppMessage",
|
571
|
-
value: function _handleAppMessage(data) {
|
572
|
-
var eventKeyMap = Object.keys(EVENT).map(function (key) {
|
573
|
-
return EVENT[key].name;
|
574
|
-
});
|
575
|
-
if (!eventKeyMap.includes(data.context.event)) {
|
576
|
-
return;
|
577
|
-
}
|
578
|
-
if (data.context.event === EVENT.launch.name) {
|
579
|
-
this._performanceData.push({
|
580
|
-
key: 'sdk_onLaunch',
|
581
|
-
value: Date.now()
|
582
|
-
});
|
583
|
-
this.AMSSDK.logger.logInfo({
|
584
|
-
title: 'sdk_event_webAppOnLaunch'
|
585
|
-
}).send();
|
586
|
-
this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
|
587
|
-
this.sendRenderEvent();
|
588
|
-
return;
|
589
|
-
}
|
590
|
-
if (data.context.event === EVENT.sizeChanged.name) {
|
591
|
-
this.handleSizeChanged(data);
|
592
|
-
}
|
593
|
-
if (data.context.event === EVENT.appHeartBeat.name) {
|
594
|
-
this.handleAppHeartBeat();
|
595
|
-
return;
|
596
|
-
}
|
597
|
-
// The plug-in communicates with the sdk after processing
|
598
|
-
this.dispatchToSDK(data.context.event, data.context.data, data.context.eventCallbackId);
|
599
|
-
}
|
600
|
-
}, {
|
601
|
-
key: "dismissLoadingFunc",
|
602
|
-
value: function dismissLoadingFunc() {
|
603
|
-
var _document$getElementB2;
|
604
|
-
var isShowMockup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
605
|
-
var mockup = document.getElementById(MOCKUP_ID);
|
606
|
-
if (mockup) {
|
607
|
-
mockup.style.background = 'rgb(0, 0, 0, 0.6)';
|
608
|
-
mockup.style.display = isShowMockup ? 'block' : 'none';
|
609
|
-
}
|
610
|
-
(_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 || _document$getElementB2.remove();
|
611
|
-
}
|
612
|
-
}, {
|
613
|
-
key: "handleSizeChanged",
|
614
|
-
value: function handleSizeChanged(data) {
|
615
|
-
var _data$context$data;
|
616
|
-
console.log(data, 'datadatadatadatadata');
|
617
|
-
var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
|
618
|
-
if (((_data$context$data = data.context.data) === null || _data$context$data === void 0 ? void 0 : _data$context$data.height) <= 1 || data.context.data.height === parseInt(cashier.style.height)) return;
|
619
|
-
cashier.style.height = "".concat(data.context.data.height, "px");
|
620
|
-
this.app.style.opacity = '1';
|
621
|
-
// alert(this._renderDisplayType)
|
622
|
-
if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
|
623
|
-
if (this.platform === 'desktop') {
|
624
|
-
if (data.context.data.width) cashier.style.width = "".concat(data.context.data.width, "px");
|
625
|
-
cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
|
626
|
-
this.app.style.height = "".concat(data.context.data.height, "px");
|
627
|
-
}
|
628
|
-
if (this.platform === 'mobile') {
|
629
|
-
cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
|
630
|
-
var animationStyleId = "".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style");
|
631
|
-
var animationStyle = document.getElementById(animationStyleId);
|
632
|
-
if (animationStyle) animationStyle === null || animationStyle === void 0 || animationStyle.remove();
|
633
|
-
|
634
|
-
// 此style用于弹窗出现和高度变化时动画,动画不同,属性不同
|
635
|
-
this.app.style.height = parseInt(this.app.style.height) > 0 ? '100%' : "".concat(data.context.data.height, "px");
|
636
|
-
// 弹出和弹入动画
|
637
|
-
var runkeyframes = slideInAndOutKeyframes(COMPONENT_CONTAINER_ID, data.context.data.height);
|
638
|
-
// 创建style标签
|
639
|
-
var style = document.createElement('style');
|
640
|
-
style.id = animationStyleId;
|
641
|
-
// 设置style属性
|
642
|
-
style.type = 'text/css';
|
643
|
-
// 将 keyframes样式写入style内
|
644
|
-
style.innerHTML = runkeyframes;
|
645
|
-
// 将style样式存放到head标签
|
646
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
647
|
-
// size变动时动画
|
648
|
-
setTimeout(function () {
|
649
|
-
cashier.style.transition = 'height 0.28s ease-in-out';
|
650
|
-
}, 500);
|
651
|
-
}
|
652
|
-
// 关闭loading,保留蒙层
|
653
|
-
this.dismissLoadingFunc();
|
654
|
-
}
|
655
|
-
if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
|
656
|
-
var _document$getElementB3;
|
657
|
-
(_document$getElementB3 = document.getElementById(LOADING_ID)) === null || _document$getElementB3 === void 0 || _document$getElementB3.remove();
|
658
|
-
this.app.style.height = "".concat(data.context.data.height, "px");
|
659
|
-
}
|
660
|
-
}
|
661
|
-
}, {
|
662
|
-
key: "handleAppHeartBeat",
|
663
|
-
value: function handleAppHeartBeat() {
|
664
|
-
var _this5 = this;
|
665
|
-
try {
|
666
|
-
if (!this._webAppHeartBeatTimeoutFn) {
|
667
|
-
this._webAppHeartBeatTimeoutFn = function () {
|
668
|
-
if (_this5.isAppAttached()) {
|
669
|
-
_this5.AMSSDK.logger.logError({
|
670
|
-
title: 'sdk_error_appHeartBeatTimeout'
|
671
|
-
});
|
672
|
-
}
|
673
|
-
};
|
674
|
-
}
|
675
|
-
if (window._webAppHeartBeatTimeoutId) {
|
676
|
-
clearTimeout(window._webAppHeartBeatTimeoutId);
|
677
|
-
window._webAppHeartBeatTimeoutId = null;
|
678
|
-
}
|
679
|
-
if (this._webAppHeartBeatTimeoutFn) {
|
680
|
-
window._webAppHeartBeatTimeoutId = setTimeout(this._webAppHeartBeatTimeoutFn, TIMEOUT_WEB_APP_HEART_BEAT);
|
681
|
-
}
|
682
|
-
setTimeout(function () {
|
683
|
-
if (_this5.isAppAttached()) {
|
684
|
-
_this5.dispatchToApp({
|
685
|
-
context: {
|
686
|
-
event: 'sdkHeartBeat',
|
687
|
-
data: {}
|
688
|
-
}
|
689
|
-
});
|
690
|
-
}
|
691
|
-
}, TIME_DELAY_SEND_HEART_BEAT);
|
692
|
-
} catch (error) {
|
693
|
-
this.AMSSDK.logger.logError({
|
694
|
-
title: 'sdk_error_handleAppHeartBeat'
|
695
|
-
}, {
|
696
|
-
errorMessage: error.message
|
697
|
-
});
|
698
|
-
}
|
699
|
-
}
|
700
|
-
}, {
|
701
|
-
key: "isAppAttached",
|
702
|
-
value: function isAppAttached() {
|
703
|
-
return this.app || this.popupApp;
|
704
|
-
}
|
705
|
-
|
706
|
-
/**
|
707
|
-
* @description Send message to SDK
|
708
|
-
*/
|
709
|
-
}, {
|
710
|
-
key: "dispatchToSDK",
|
711
|
-
value: function dispatchToSDK(event, data, eventCallbackId) {
|
712
|
-
this.AMSSDK._eventCenter.emit(event, data);
|
713
|
-
if (eventCallbackId) this.AMSSDK._eventCenter.emit(eventCallbackId, data);
|
714
|
-
}
|
715
|
-
|
716
|
-
/**
|
717
|
-
* @description Send message to iframe
|
718
|
-
*/
|
719
|
-
}, {
|
720
|
-
key: "dispatchToApp",
|
721
|
-
value: function dispatchToApp(payload) {
|
722
|
-
var targetElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
723
|
-
var data = Object.assign({}, payload, {
|
724
|
-
name: messageName.SDK_TO_APP,
|
725
|
-
mode: this.AMSSDK.options.mode,
|
726
|
-
appId: COMPONENTPLUGINID,
|
727
|
-
instanceId: this.AMSSDK._instanceId
|
728
|
-
});
|
729
|
-
if (targetElement && targetElement.contentWindow) {
|
730
|
-
return targetElement.contentWindow.postMessage(JSON.stringify(data), '*');
|
731
|
-
}
|
732
|
-
if (this.app || this.popupApp) {
|
733
|
-
var _this$app, _this$app2, _this$popupApp, _this$popupApp2;
|
734
|
-
(this === null || this === void 0 || (_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.contentWindow) && (this === null || this === void 0 || (_this$app2 = this.app) === null || _this$app2 === void 0 ? void 0 : _this$app2.contentWindow.postMessage(JSON.stringify(data), this.appDomain));
|
735
|
-
(this === null || this === void 0 || (_this$popupApp = this.popupApp) === null || _this$popupApp === void 0 ? void 0 : _this$popupApp.contentWindow) && (this === null || this === void 0 || (_this$popupApp2 = this.popupApp) === null || _this$popupApp2 === void 0 ? void 0 : _this$popupApp2.contentWindow.postMessage(JSON.stringify(data), '*'));
|
736
|
-
return;
|
737
|
-
}
|
738
|
-
throw new Error(ERRORMESSAGE.SDK_SUBMIT_ERROR.message);
|
739
|
-
}
|
740
|
-
|
741
|
-
/**
|
742
|
-
* @description Subscribe to messages from SDK
|
743
|
-
*/
|
744
|
-
}, {
|
745
|
-
key: "subscribeFromSDK",
|
746
|
-
value: function subscribeFromSDK() {
|
747
|
-
var eventKeyMap = {};
|
748
|
-
for (var key in eventKeyMap) {
|
749
|
-
// eslint-disable-next-line no-prototype-builtins
|
750
|
-
if (eventKeyMap.hasOwnProperty(key)) {
|
751
|
-
this.AMSSDK._eventCenter.on("".concat(COMPONENTPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
|
752
|
-
}
|
753
|
-
}
|
754
|
-
console.log(eventKeyMap, 'eventKeyMap');
|
755
|
-
}
|
756
|
-
|
757
|
-
/**
|
758
|
-
* @description Send rendering events to iframe
|
759
|
-
*/
|
760
|
-
}, {
|
761
|
-
key: "sendRenderEvent",
|
762
|
-
value: (function () {
|
763
|
-
var _sendRenderEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
764
|
-
var _this$_renderParams, _this$_renderParams2, _this$_renderParams3, _this$_renderParams4, _this$_renderParams5, _this$AMSSDK$logger, _this$_renderParams6, _this$AMSSDK;
|
765
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
766
|
-
while (1) switch (_context2.prev = _context2.next) {
|
767
|
-
case 0:
|
768
|
-
try {
|
769
|
-
this._performanceData.push({
|
770
|
-
key: 'sdk_render_component',
|
771
|
-
value: Date.now()
|
772
|
-
});
|
773
|
-
this.dispatchToApp({
|
774
|
-
context: {
|
775
|
-
event: 'renderComponent',
|
776
|
-
data: {
|
777
|
-
heightOfVisible: Math.max(window.changingPageHeight, window.innerHeight),
|
778
|
-
renderDisplayType: (_this$_renderParams = this._renderParams) === null || _this$_renderParams === void 0 ? void 0 : _this$_renderParams.renderDisplayType,
|
779
|
-
appearance: (_this$_renderParams2 = this._renderParams) === null || _this$_renderParams2 === void 0 ? void 0 : _this$_renderParams2.appearance,
|
780
|
-
configParams: (_this$_renderParams3 = this._renderParams) === null || _this$_renderParams3 === void 0 ? void 0 : _this$_renderParams3.configParams,
|
781
|
-
appId: (_this$_renderParams4 = this._renderParams) === null || _this$_renderParams4 === void 0 ? void 0 : _this$_renderParams4.appId,
|
782
|
-
prefillValue: (_this$_renderParams5 = this._renderParams) === null || _this$_renderParams5 === void 0 ? void 0 : _this$_renderParams5.prefillValue,
|
783
|
-
envInfo: {
|
784
|
-
screenHeight: screen.height,
|
785
|
-
screenWidth: screen.width
|
786
|
-
},
|
787
|
-
logMetaData: {
|
788
|
-
platform: this.platform,
|
789
|
-
firstLogTime: (_this$AMSSDK$logger = this.AMSSDK.logger) === null || _this$AMSSDK$logger === void 0 ? void 0 : _this$AMSSDK$logger.getComponentStartTime(),
|
790
|
-
renderDisplayType: (_this$_renderParams6 = this._renderParams) === null || _this$_renderParams6 === void 0 ? void 0 : _this$_renderParams6.renderDisplayType,
|
791
|
-
sdkVersion: this._appVersion,
|
792
|
-
instanceId: (_this$AMSSDK = this.AMSSDK) === null || _this$AMSSDK === void 0 ? void 0 : _this$AMSSDK._instanceId,
|
793
|
-
performanceData: this._performanceData
|
794
|
-
}
|
795
|
-
}
|
796
|
-
}
|
797
|
-
}, null);
|
798
|
-
this.AMSSDK.logger.logInfo({
|
799
|
-
title: 'sdk_event_renderComponent'
|
800
|
-
});
|
801
|
-
this.dispatchToApp({
|
802
|
-
context: {
|
803
|
-
event: 'web-sdk-performance',
|
804
|
-
data: {
|
805
|
-
performanceData: this._performanceData
|
806
|
-
}
|
807
|
-
}
|
808
|
-
});
|
809
|
-
// eslint-disable-next-line no-empty
|
810
|
-
} catch (error) {}
|
811
|
-
case 1:
|
812
|
-
case "end":
|
813
|
-
return _context2.stop();
|
814
|
-
}
|
815
|
-
}, _callee2, this);
|
816
|
-
}));
|
817
|
-
function sendRenderEvent() {
|
818
|
-
return _sendRenderEvent.apply(this, arguments);
|
819
|
-
}
|
820
|
-
return sendRenderEvent;
|
821
|
-
}()
|
822
|
-
/**
|
823
|
-
* @description close cashier
|
824
|
-
*/
|
825
|
-
)
|
826
|
-
}, {
|
827
|
-
key: "cleanContainer",
|
828
|
-
value: function cleanContainer() {
|
829
|
-
var _document$getElementB4,
|
830
|
-
_this6 = this;
|
831
|
-
var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
832
|
-
(_document$getElementB4 = document.getElementById(LOADING_ID)) === null || _document$getElementB4 === void 0 || _document$getElementB4.remove();
|
833
|
-
this.hideComponentAnimation();
|
834
|
-
var mockup = document.getElementById(MOCKUP_ID);
|
835
|
-
mockup === null || mockup === void 0 || mockup.classList.add("".concat(MOCKUP_ID, "-hidden"));
|
836
|
-
this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
|
837
|
-
this._performanceData = [];
|
838
|
-
this._isInitComponent = false;
|
839
|
-
this.app = null;
|
840
|
-
if (immediately) this.cleanElement();else {
|
841
|
-
setTimeout(function () {
|
842
|
-
_this6.cleanElement();
|
843
|
-
}, 300);
|
844
|
-
}
|
845
|
-
}
|
846
|
-
}, {
|
847
|
-
key: "hideComponentAnimation",
|
848
|
-
value: function hideComponentAnimation() {
|
849
|
-
var container = document.getElementById(COMPONENT_CONTAINER_ID);
|
850
|
-
if (this.app) this.app.style.height = container.style.height;
|
851
|
-
if (container) {
|
852
|
-
// size变化动画取消
|
853
|
-
container.style.transition = '';
|
854
|
-
container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform));
|
855
|
-
container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
|
856
|
-
container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.platform));
|
857
|
-
}
|
858
|
-
}
|
859
|
-
}]);
|
860
|
-
return ComponentApp;
|
861
|
-
}();
|
862
|
-
export { ComponentApp as default };
|