UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

79 lines (78 loc) 5.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LionLoginAmazon = void 0; var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importDefault)(require("react")); var Modal_1 = (0, tslib_1.__importDefault)(require("antd/lib/Modal")); var msgsub_1 = (0, tslib_1.__importDefault)(require("../../utils/msgsub")); var LoginAmazonPage = /** @class */ (function (_super) { (0, tslib_1.__extends)(LoginAmazonPage, _super); function LoginAmazonPage() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = {}; _this.handleParams = function () { var _a, _b; var _c = _this.props, action = _c.action, ctx = _c.ctx, env = _c.env; var schemaApi = action.schemaApi; var iHeight = 800; // https://sellercentral.amazon.com/apps/authorize/consent?state=loginAmazonKey&application_id=amzn1.sp.solution.237e541c-022e-42db-b5c2-9e6700a457b3&version=betahttps://saasdev.fastlion.cn/saas_dev/schema-app.html var iWidth = (((_a = document === null || document === void 0 ? void 0 : document.documentElement) === null || _a === void 0 ? void 0 : _a.clientHeight) || ((_b = document === null || document === void 0 ? void 0 : document.body) === null || _b === void 0 ? void 0 : _b.clientHeight)) - 30; var iTop = (window.screen.height - iHeight) / 2; var iLeft = (window.screen.width - iWidth - 10) / 2; var config = "toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no,height=" + iHeight + ",width=" + iWidth + "top=" + iTop + ",left=" + iLeft; env === null || env === void 0 ? void 0 : env.fetcher(schemaApi, ctx).then(function (res) { var _a, _b, _c, _d, _e; if ((res === null || res === void 0 ? void 0 : res.ok) && (res === null || res === void 0 ? void 0 : res.status) === 0) { var sellerUrl = ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.sellerUrl) ? (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.sellerUrl : ''; var _redirectUri = "redirect_uri=" + location.origin + location.pathname; var _applicationId = "application_id=" + (((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.applicationId) ? (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.applicationId : ''); var state = JSON.stringify((0, tslib_1.__assign)((0, tslib_1.__assign)({}, ctx), { api: (_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.api, _hash: location.hash })); var stateKey = 'loginAmazonKey'; localStorage.setItem(stateKey, state); var _sellerUrl = sellerUrl + '?' + ("state=" + stateKey) + '&' + _applicationId + '&' + 'version=beta' + '&' + _redirectUri; window._opener = window.open(_sellerUrl, "_blank", config); } else { msgsub_1.default._error('系统异常,授权信息确认失败,清稍候再试', env === null || env === void 0 ? void 0 : env.getModalContainer); return; } }); }; return _this; } LoginAmazonPage.prototype.componentDidMount = function () { var _a; var env = this.props.env; try { if (!(window === null || window === void 0 ? void 0 : window._opener) || ((_a = window === null || window === void 0 ? void 0 : window._opener) === null || _a === void 0 ? void 0 : _a.closed)) { this.handleParams(); } // else if (window.origin === window?._opener?.origin) { // window._opener.focus() // } else { window._opener.focus(); } } catch (err) { msgsub_1.default._info('已有被打开的授权窗口,请先关闭该窗口或完成授权', env === null || env === void 0 ? void 0 : env.getModalContainer); } }; LoginAmazonPage.prototype.render = function () { return null; }; return LoginAmazonPage; }(react_1.default.Component)); var LionLoginAmazon = function (action, ctx, env) { var modal = Modal_1.default.info({ className: "lion-wrapper-export", getContainer: env === null || env === void 0 ? void 0 : env.getModalContainer, mask: false, maskClosable: true }); modal.update({ content: react_1.default.createElement(LoginAmazonPage, { env: env, action: action, ctx: ctx }) }); }; exports.LionLoginAmazon = LionLoginAmazon; //# sourceMappingURL=./renderers/Lion/components/Actions/LoginAmazon.js.map