@choerodon/master
Version:
A package of Master for Choerodon platform.
135 lines (106 loc) • 6.09 kB
JavaScript
var _dec, _class;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
import React, { Component, Suspense } from 'react';
import { withRouter, Route, Switch } from 'react-router-dom';
import { inject, observer } from 'mobx-react';
import "./style";
import { Loading } from '@choerodon/components';
import AppState from "../../../../stores/c7n/AppState";
var Unauthorized = /*#__PURE__*/React.lazy(function () {
return import("../unauthorized");
});
var Outward = (_dec = inject('AppState'), withRouter(_class = _dec(_class = observer(_class = /*#__PURE__*/function (_Component) {
_inherits(Outward, _Component);
var _super = _createSuper(Outward);
function Outward() {
var _this;
_classCallCheck(this, Outward);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_this.isInOutward = function (pathname) {
// eslint-disable-next-line no-underscore-dangle
var injectOutward = window._env_.outward;
if (injectOutward) {
var arr = injectOutward.split(',').concat(['/unauthorized']).map(function (r) {
return r.replace(/['"']/g, '');
});
return arr.some(function (v) {
return pathname.startsWith(v);
});
}
return false;
};
return _this;
}
_createClass(Outward, [{
key: "componentDidMount",
value: function componentDidMount() {
if (!AppState.siteInfo.systemTitle) {
this.initFavicon();
}
AppState.changeMenuType({
type: 'site'
});
}
}, {
key: "initFavicon",
value: function initFavicon() {
AppState.loadSiteInfo().then(function (data) {
var link = document.createElement('link');
var linkDom = document.getElementsByTagName('link');
if (linkDom) {
for (var i = 0; i < linkDom.length; i += 1) {
if (linkDom[i].getAttribute('rel') === 'shortcut icon') document.head.removeChild(linkDom[i]);
}
}
link.id = 'dynamic-favicon';
link.rel = 'shortcut icon';
link.href = data.favicon || 'favicon.ico';
document.head.appendChild(link);
if (data.systemTitle) {
document.getElementsByTagName('title')[0].innerText = data.systemTitle;
}
AppState.setSiteInfo(data);
});
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
AutoRouter = _this$props.AutoRouter,
history = _this$props.history,
match = _this$props.match;
if (this.isInOutward(this.props.location.pathname)) {
return /*#__PURE__*/React.createElement("div", {
className: "page-wrapper"
}, /*#__PURE__*/React.createElement(Suspense, {
fallback: /*#__PURE__*/React.createElement(Loading, {
type: "c7n"
})
}, /*#__PURE__*/React.createElement(Switch, null, /*#__PURE__*/React.createElement(Route, {
exact: true,
path: "".concat(match.url, "unauthorized"),
component: Unauthorized
}), /*#__PURE__*/React.createElement(Route, {
path: match.url,
component: AutoRouter
}))));
}
history.push('/unauthorized');
return null;
}
}]);
return Outward;
}(Component)) || _class) || _class) || _class);
export default Outward;