UNPKG

@choerodon/master

Version:
339 lines (291 loc) 15.3 kB
import "choerodon-ui/lib/icon/style"; import _Icon from "choerodon-ui/lib/icon"; import "choerodon-ui/pro/lib/button/style"; import _Button2 from "choerodon-ui/pro/lib/button"; import "choerodon-ui/lib/button/style"; import _Button from "choerodon-ui/lib/button"; import "choerodon-ui/lib/menu/style"; import _Menu from "choerodon-ui/lib/menu"; var _dec, _class; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } 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 } from 'react'; import queryString from 'query-string'; import { inject, observer } from 'mobx-react'; import { withRouter } from 'react-router-dom'; import classnames from 'classnames'; import { toJS } from 'mobx'; import { mount, get } from '@choerodon/inject'; import findFirstLeafMenu from "../../util/findFirstLeafMenu"; import { historyPushMenu } from "../../util"; import Setting from "./Setting"; import MouserOverWrapper from "./components/MouseOverWrapper"; var HAS_BASE_PRO = false; try { require.resolveWeak('@choerodon/base-business'); HAS_BASE_PRO = true; } catch (error) {} var prefixCls = 'c7n-boot-header-menu-type'; var homePage = '/workbench'; var OrgSelect = (_dec = inject('AppState', 'HeaderStore', 'MenuStore'), withRouter(_class = _dec(_class = observer(_class = /*#__PURE__*/function (_Component) { _inherits(OrgSelect, _Component); var _super = _createSuper(OrgSelect); function OrgSelect() { var _this; _classCallCheck(this, OrgSelect); 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.autoLocate = function () { var history = _this.props.history; var parsed = queryString.parse(history.location.search); var path = "".concat(history.location.pathname === '/' ? homePage : history.location.pathname, "?").concat(queryString.stringify(parsed)); historyPushMenu(history, path, null, 'replace'); }; _this.selectState = function (value, gotoHome) { var _this$props = _this.props, AppState = _this$props.AppState, HeaderStore = _this$props.HeaderStore, MenuStore = _this$props.MenuStore, history = _this$props.history; var id = value.id, name = value.name, type = value.type, organizationId = value.organizationId, category = value.category; localStorage.setItem('C7N-ORG-ID', id || organizationId); var parsed; var path; if (gotoHome) { parsed = { id: id, name: name, type: type, organizationId: id || organizationId, category: category }; path = "".concat(homePage, "?").concat(queryString.stringify(parsed)); } else { parsed = { id: id, name: name, type: type, organizationId: organizationId || id, category: category }; path = "".concat(history.location.pathname === '/' ? homePage : history.location.pathname, "?").concat(queryString.stringify(parsed)); AppState.changeMenuType(parsed); } MenuStore.setActiveMenu(null); historyPushMenu(history, path, null, 'replace'); }; return _this; } _createClass(OrgSelect, [{ key: "autoSelect", value: function autoSelect() { var _this$props2 = this.props, organizationId = _this$props2.AppState.currentMenuType.organizationId, history = _this$props2.history; var currentData = this.getCurrentData() || []; var localOrgId = localStorage.getItem('C7N-ORG-ID'); if (localOrgId && localOrgId !== 'undefined') { var orgObj = currentData.find(function (v) { return String(v.id) === localOrgId; }); if (orgObj) { this.selectState(orgObj); return; } } if (!organizationId && currentData.length) { this.selectState(currentData[0]); } } }, { key: "renderTable", value: function renderTable(dataSource) { var _this2 = this; if (dataSource && dataSource.length) { return /*#__PURE__*/React.createElement(_Menu, null, dataSource.map(function (org) { return /*#__PURE__*/React.createElement(_Menu.Item, { key: org.id, onClick: function onClick() { return _this2.selectState(org, true); }, className: "".concat(prefixCls, "-org-select-menu-item") }, /*#__PURE__*/React.createElement(MouserOverWrapper, { width: "167px", text: org.name }, /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-org-select-menu-item-text") }, org.name))); })); } return null; } }, { key: "getCurrentData", value: function getCurrentData() { var HeaderStore = this.props.HeaderStore; var orgData = toJS(HeaderStore.getOrgData); return orgData; } }, { key: "renderModalContent", value: function renderModalContent() { var currentData = this.getCurrentData(); return /*#__PURE__*/React.createElement("div", { style: { maxHeight: 400, overflow: 'auto', boxShadow: '0 0.02rem 0.08rem rgba(0, 0, 0, 0.12)', width: 200 } }, this.renderTable(currentData)); } }, { key: "render", value: function render() { var _this3 = this; var _this$props3 = this.props, HeaderStore = _this$props3.HeaderStore, _this$props3$AppState = _this$props3.AppState, _this$props3$AppState2 = _this$props3$AppState.currentMenuType, _this$props3$AppState3 = _this$props3$AppState2.name, selectTitle = _this$props3$AppState3 === void 0 ? '选择组织' : _this$props3$AppState3, type = _this$props3$AppState2.type, category = _this$props3$AppState2.category, id = _this$props3$AppState2.id, organizationId = _this$props3$AppState2.organizationId, getUserInfo = _this$props3$AppState.getUserInfo, getCurrentTheme = _this$props3$AppState.getCurrentTheme, history = _this$props3.history; var SelfButton = true ? _Button2 : _Button; var currentData = this.getCurrentData() || []; var orgObj = currentData.find(function (v) { return String(v.id) === (organizationId || id) || v.id === (organizationId || id); }); if (!orgObj && currentData.length && type !== 'project') { if (getUserInfo.admin) { var obj = queryString.parse(history.location.search); obj.into = true; obj.name = obj.name && decodeURIComponent(obj.name); if (!obj.organizationId || !obj.type || obj.type === 'site') { setTimeout(function () { _this3.autoSelect(); }, 100); return null; } this.selectState(obj); HeaderStore.setOrgData([].concat(_toConsumableArray(currentData), [_objectSpread(_objectSpread({}, obj), {}, { enabled: true })])); return null; } setTimeout(function () { _this3.autoSelect(); }, 100); return null; } if (history.location.pathname === '/') { setTimeout(function () { _this3.autoSelect(); }, 100); return null; } var buttonClass = classnames("".concat(prefixCls, "-button"), 'block', 'org-button', { 'theme4-orgSelect': true }); var orgButton = /*#__PURE__*/React.createElement(SelfButton, { className: buttonClass, funcType: "flat", style: { margin: 0, padding: '0 20px', width: 200, borderLeft: "1px solid ".concat(true ? '#D9E6F2' : 'rgba(255, 255, 255, 0.3)'), borderRight: "1px solid ".concat(true ? '#D9E6F2' : 'rgba(255, 255, 255, 0.3)'), borderTop: false ? '1px solid #D9E6F2' : 'unset', borderBottom: false ? '1px solid #D9E6F2' : 'unset', textAlign: 'left' } }, orgObj && orgObj.name ? /*#__PURE__*/React.createElement("div", null, false ? /*#__PURE__*/React.createElement("div", { style: { fontSize: '12px', lineHeight: '20px', color: 'rgba(255, 255, 255, 0.6)' } }, "\u7EC4\u7EC7") : /*#__PURE__*/React.createElement(_Icon, { type: "domain" }), /*#__PURE__*/React.createElement("div", { style: _objectSpread({ fontFamily: 'PingFangSC-Medium, PingFang SC', fontWeight: 500, color: 'rgba(15, 19, 88, 0.65)', fontSize: '14px', lineHeight: '20px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', textTransform: 'none' }, true ? { paddingLeft: 9 } : {}) }, orgObj.name)) : null, !(orgObj && orgObj.name) ? /*#__PURE__*/React.createElement("div", { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' } }, /*#__PURE__*/React.createElement("span", null, "\u8BF7\u9009\u62E9\u7EC4\u7EC7"), /*#__PURE__*/React.createElement(_Icon, { type: "arrow_drop_down" })) : null, HAS_BASE_PRO && orgObj ? /*#__PURE__*/React.createElement(_Icon, { type: "expand_more", style: { position: 'absolute', top: 0, right: 8, color: 'rgba(255, 255, 255, .65)', fontSize: '.24rem' } }) : null); return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("li", { style: { width: 'auto' } }, get('base-pro:OrgSelect_Dropdown') ? mount('base-pro:OrgSelect_Dropdown', { selectState: this.selectState, prefixCls: prefixCls, MouserOverWrapper: MouserOverWrapper, orgObj: orgObj }) : orgButton), orgObj && orgObj.into ? /*#__PURE__*/React.createElement("li", { style: { width: 'auto' } }, /*#__PURE__*/React.createElement(Setting, { org: orgObj })) : null); } }]); return OrgSelect; }(Component)) || _class) || _class) || _class); export { OrgSelect as default };