UNPKG

@choerodon/master

Version:
708 lines (582 loc) 28.5 kB
import "choerodon-ui/lib/spin/style"; import _Spin from "@hzero-front-ui/c7n-ui/lib/Spin"; import "choerodon-ui/pro/lib/modal/style"; import _Modal from "choerodon-ui/pro/lib/modal"; import "choerodon-ui/pro/lib/message/style"; import _message from "choerodon-ui/pro/lib/message"; 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 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); } } 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); }); }; } 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, createRef } from 'react'; import { withRouter } from 'react-router-dom'; import { inject, observer } from 'mobx-react'; import queryString from 'query-string'; import get from 'lodash/get'; import { mount, get as cherodonGet } from '@choerodon/inject'; import getSearchString from "../util/gotoSome"; import MasterServices from "./services"; import axios from "../../../../components/axios"; import MasterHeader from "../ui/header"; import PlatformAnnouncement, { axiosGetNewSticky } from "../components/PlatformAnnouncement"; import SaaSUserAnnouncement, { getSaaSUserAvilableDays } from "../components/SaaSUserAnnouncement"; import RouteIndex from "./RouteIndex"; import "./style"; import Skeleton from "../../../../components/skeleton"; import CommonMenu, { defaultBlackList } from "../ui/menu"; import popoverHead from "../../../../assets/images/popoverHead.png"; import MasterApis from "./apis"; import AnnouncementBannerPro from "../components/AnnouncementBannerPro"; var spinStyle = { textAlign: 'center', paddingTop: 300 }; // 这里是没有菜单的界面合集 // 记录下route和code 为了方便查询该界面的文档地址 var routeWithNoMenu = [{ route: 'workbench', code: 'workbench' }, { route: 'projects', code: 'project-list' }, { route: 'knowledge/organization', code: 'knowledge' }, { route: 'app-market', code: 'app-market' }]; function parseQueryToMenuType(search) { var menuType = {}; if (search) { var _queryString$parse = queryString.parse(search), type = _queryString$parse.type, name = _queryString$parse.name, id = _queryString$parse.id, organizationId = _queryString$parse.organizationId, category = _queryString$parse.category; if (type) { menuType.type = type; } if (category) { menuType.category = category; } if (name) { menuType.name = name; } if (organizationId) { menuType.organizationId = organizationId; menuType.orgId = organizationId; } if (id) { menuType.id = id; if (type === 'project') { menuType.projectId = id; } else if (type === 'organization') { menuType.organizationId = id; } } if (type === 'project' && organizationId) { menuType.organizationId = organizationId; } } return menuType; } var Masters = (_dec = inject('AppState', 'MenuStore', 'HeaderStore'), withRouter(_class = _dec(_class = observer(_class = /*#__PURE__*/function (_Component) { _inherits(Masters, _Component); var _super = _createSuper(Masters); function Masters(props) { var _this; _classCallCheck(this, Masters); _this = _super.call(this, props); _this.getGuideContentByLocationChange = function (newProps, oldProps) { var _newProps$location = newProps.location, newPathname = _newProps$location.pathname, newSearch = _newProps$location.search; var _oldProps$location = oldProps.location, oldPathname = _oldProps$location.pathname, oldSearch = _oldProps$location.search; if (newPathname !== oldPathname || newSearch !== oldSearch) { var _this$cRef, _this$cRef$current, _this$cRef3, _this$cRef3$current; if ((_this$cRef = _this.cRef) === null || _this$cRef === void 0 ? void 0 : (_this$cRef$current = _this$cRef.current) === null || _this$cRef$current === void 0 ? void 0 : _this$cRef$current.guideOpen) { var _this$cRef2, _this$cRef2$current; (_this$cRef2 = _this.cRef) === null || _this$cRef2 === void 0 ? void 0 : (_this$cRef2$current = _this$cRef2.current) === null || _this$cRef2$current === void 0 ? void 0 : _this$cRef2$current.setguideOpen(false); } (_this$cRef3 = _this.cRef) === null || _this$cRef3 === void 0 ? void 0 : (_this$cRef3$current = _this$cRef3.current) === null || _this$cRef3$current === void 0 ? void 0 : _this$cRef3$current.handleSetGuideContent(newProps); cherodonGet('base-pro:handleGetHelpDocUrl') && cherodonGet('base-pro:handleGetHelpDocUrl')(_this.props, routeWithNoMenu, _this.setDocUrl); } }; _this.setDocUrl = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(params) { var result; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!(JSON.stringify(params) !== '{}')) { _context.next = 5; break; } _context.next = 3; return MasterServices.axiosGetHelpDoc(params); case 3: result = _context.sent; if (result) { _this.props.AppState.setDocUrl(result); } case 5: case "end": return _context.stop(); } } }, _callee); })); return function (_x) { return _ref.apply(this, arguments); }; }(); _this.judgeIfGetUserCountCheck = function (newProps, oldProps) { var newParams = new URLSearchParams(newProps.location.search); var oldParams = new URLSearchParams(oldProps.location.search); if (newParams.get('organizationId') !== oldParams.get('organizationId')) { var _this$userRef, _this$userRef$current; if ((_this$userRef = _this.userRef) === null || _this$userRef === void 0 ? void 0 : (_this$userRef$current = _this$userRef.current) === null || _this$userRef$current === void 0 ? void 0 : _this$userRef$current.getUserCountCheck) { _this.userRef.current.getUserCountCheck(newParams.get('organizationId')); } _this.initStarAndRecentProjects(newParams.get('organizationId'), newProps.AppState); } }; _this.initStarAndRecentProjects = function (newOrgId, appState) { var talentId = appState.userInfo.tenantId; // 如果userInfo的tanantId变化了 则去重查 if (String(newOrgId) === String(talentId)) { appState.getProjects(); } else { setTimeout(function () { _this.initStarAndRecentProjects(newOrgId, _this.props.AppState); }, 500); } }; _this.getPlatformAnnouncement = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { var res, HeaderStore, identity; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.prev = 0; _context2.next = 3; return axiosGetNewSticky(); case 3: res = _context2.sent; if (!(res && res.failed)) { _context2.next = 7; break; } _message.error(res === null || res === void 0 ? void 0 : res.message); return _context2.abrupt("return"); case 7: HeaderStore = _this.props.HeaderStore; identity = 'platform_announcement'; if (res && (!localStorage.lastClosedId || localStorage.lastClosedId !== (res === null || res === void 0 ? void 0 : res.id))) { HeaderStore.innsertAnnouncement(identity, { data: res, onCloseCallback: function onCloseCallback() { window.localStorage.setItem('lastClosedId', "".concat(res === null || res === void 0 ? void 0 : res.id)); }, component: /*#__PURE__*/React.createElement(PlatformAnnouncement, { data: res }) }); } _context2.next = 15; break; case 12: _context2.prev = 12; _context2.t0 = _context2["catch"](0); throw new Error(_context2.t0); case 15: case "end": return _context2.stop(); } } }, _callee2, null, [[0, 12]]); })); _this.getSaaSUserRestDays = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { var _ref4, organizationId, res, HeaderStore, identity; return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _ref4 = _this.props.AppState.currentMenuType || {}, organizationId = _ref4.organizationId; if (!(window._env_.BUSINESS || !organizationId)) { _context3.next = 3; break; } return _context3.abrupt("return"); case 3: _context3.prev = 3; _context3.next = 6; return getSaaSUserAvilableDays(organizationId); case 6: res = _context3.sent; if (!(res && res.failed)) { _context3.next = 10; break; } _message.error(res === null || res === void 0 ? void 0 : res.message); return _context3.abrupt("return"); case 10: HeaderStore = _this.props.HeaderStore; identity = 'saas_restdays_announcement'; if (res && (!localStorage.saaslastClosedId || localStorage.saaslastClosedId !== (res === null || res === void 0 ? void 0 : res.link))) { HeaderStore.innsertAnnouncement(identity, { data: res, onCloseCallback: function onCloseCallback() { window.localStorage.setItem('saaslastClosedId', "".concat(res === null || res === void 0 ? void 0 : res.link)); }, component: /*#__PURE__*/React.createElement(SaaSUserAnnouncement, { data: res }) }); } _context3.next = 18; break; case 15: _context3.prev = 15; _context3.t0 = _context3["catch"](3); throw new Error(_context3.t0); case 18: case "end": return _context3.stop(); } } }, _callee3, null, [[3, 15]]); })); _this.isInOutward = function (pathname) { // eslint-disable-next-line no-underscore-dangle var injectOutward = window._env_.outward; if (injectOutward) { var arr = injectOutward.split(',').concat(['/unauthorized']); return arr.some(function (v) { return pathname.startsWith(v); }); } return false; }; _this.cRef = /*#__PURE__*/createRef(); _this.userRef = /*#__PURE__*/createRef(); _this.info = queryString.parse(props.history.location.search); return _this; } _createClass(Masters, [{ key: "componentWillMount", value: function componentWillMount() { var _this2 = this; var _this$props = this.props, AppState = _this$props.AppState, history = _this$props.history; AppState.loadUserInfo().then(function (res) { if (res.changePasswordFlag === 1 && !sessionStorage.getItem('infoCheckFlag')) { _Modal.open({ title: '密码到期提醒', key: _Modal.key(), destroyOnClose: true, width: 520, children: '您的密码即将到期,为保证消息的正常接收及您的账户安全和后续的正常使用,请前往个人中心进行修改。', okText: '个人中心', onCancel: function onCancel() { sessionStorage.setItem('infoCheckFlag', true); }, onOk: function onOk() { history.push("/iam/user-info?type=user&organizationId=".concat(_this2.info.organizationId)); sessionStorage.setItem('infoCheckFlag', true); } }); } }); this.initMenuType(this.props); cherodonGet('base-pro:handleGetHelpDocUrl') && cherodonGet('base-pro:handleGetHelpDocUrl')(this.props, routeWithNoMenu, this.setDocUrl); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { this.judgeIfGetUserCountCheck(nextProps, this.props); this.initMenuType(nextProps); this.getGuideContentByLocationChange(nextProps, this.props); } }, { key: "componentDidMount", value: function componentDidMount() { this.initFavicon(); // 获取系统公告 this.getPlatformAnnouncement(); // 获取适用天数in the base-pro, only applied in the hand version this.getSaaSUserRestDays(); } }, { key: "changePrimaryColor", value: /** * @description: 根据返回的themeColor改变全局primaryColor变量 * @param {*} * @return {*} */ function changePrimaryColor(_ref5) { var color = _ref5.color; if (color) { document.documentElement.style.setProperty('--primary-color', color); document.documentElement.style.setProperty('--primary-color-background', "".concat(color, "0D")); } } }, { key: "initFavicon", value: function initFavicon() { var _this3 = this; var AppState = this.props.AppState; AppState.loadSiteInfo().then(function (data) { _this3.changePrimaryColor({ color: data.themeColor }); 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 = get(data, 'favicon') || 'favicon.ico'; document.head.appendChild(link); if (data) { data.defaultTitle = document.getElementsByTagName('title')[0].innerText; document.getElementsByTagName('title')[0].innerText = get(data, 'systemTitle'); } AppState.setSiteInfo(data); }); } }, { key: "initMenuType", value: function initMenuType(props) { var location = props.location, MenuStore = props.MenuStore, HeaderStore = props.HeaderStore, history = props.history, AppState = props.AppState; var pathname = location.pathname, search = location.search; var isUser = false; var needLoad = false; var menuType = parseQueryToMenuType(search); if (pathname === '/') { var recent = HeaderStore.getRecentItem; if (recent.length && !sessionStorage.home_first_redirect) { var _recent$ = recent[0], id = _recent$.id, name = _recent$.name, type = _recent$.type, organizationId = _recent$.organizationId; menuType = { id: id, name: name, type: type, organizationId: organizationId }; needLoad = true; } else { menuType = {}; } sessionStorage.home_first_redirect = 'yes'; } else if (menuType.type === 'site') { isUser = true; } else if (!menuType.type) { menuType.type = 'site'; } function checkUrl() { return _checkUrl.apply(this, arguments); } function _checkUrl() { _checkUrl = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { var goSafty, _goSafty, _res$categories, currentProject, res, checkArray; return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _goSafty = function _goSafty3() { _goSafty = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(data) { var recents, newRecents, queryObj, _search; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: if (HeaderStore.getOrgData) { _context4.next = 4; break; } setTimeout(function () { goSafty(); }, 500); _context4.next = 13; break; case 4: _message.info(data ? '该项目已停用' : '地址过期'); // 说明是停用项目 需要删除最近使用的数据 if (data) { recents = JSON.parse(localStorage.getItem('recentItem')); newRecents = recents.filter(function (r) { return r.code !== data.code; }); localStorage.setItem('recentItem', JSON.stringify(newRecents)); HeaderStore.recentItem = newRecents; } AppState.setCurrentProject(null); queryObj = queryString.parse(history.location.search); _context4.next = 10; return getSearchString('organization', 'id', queryObj.organizationId); case 10: _search = _context4.sent; MenuStore.setActiveMenu(null); history.push("/projects".concat(_search)); case 13: case "end": return _context4.stop(); } } }, _callee4); })); return _goSafty.apply(this, arguments); }; goSafty = function _goSafty2(_x2) { return _goSafty.apply(this, arguments); }; if (!menuType.projectId) { _context5.next = 30; break; } currentProject = AppState.getCurrentProject; if (!(!currentProject || String(menuType.projectId) !== String(currentProject === null || currentProject === void 0 ? void 0 : currentProject.id))) { _context5.next = 23; break; } _context5.prev = 5; _context5.next = 8; return axios.get("/iam/choerodon/v1/projects/".concat(menuType.projectId, "/basic_info")); case 8: res = _context5.sent; if (!res.enabled) { goSafty(res); } if (!(String(res.id) === String(new URLSearchParams(location.search).get('id')))) { _context5.next = 14; break; } AppState.setCurrentProject(res); _context5.next = 15; break; case 14: return _context5.abrupt("return", true); case 15: _context5.next = 21; break; case 17: _context5.prev = 17; _context5.t0 = _context5["catch"](5); goSafty(); return _context5.abrupt("return", true); case 21: _context5.next = 24; break; case 23: res = currentProject; case 24: checkArray = ['name', 'organizationId']; if (!checkArray.some(function (c) { if (menuType[c] && menuType[c] !== 'undefined' && String(menuType[c]) !== String(res[c])) { return true; } })) { _context5.next = 28; break; } goSafty(); return _context5.abrupt("return", true); case 28: AppState.changeMenuType(_objectSpread(_objectSpread({}, menuType), {}, { categories: (_res$categories = res.categories) === null || _res$categories === void 0 ? void 0 : _res$categories.slice() })); return _context5.abrupt("return", true); case 30: case "end": return _context5.stop(); } } }, _callee5, null, [[5, 17]]); })); return _checkUrl.apply(this, arguments); } AppState.setTypeUser(isUser); AppState.changeMenuType(menuType, checkUrl); } }, { key: "render", value: function render() { var _this4 = this; var _this$props2 = this.props, AutoRouter = _this$props2.AutoRouter, AppState = _this$props2.AppState, location = _this$props2.location; var search = new URLSearchParams(location.search); var fullPage = search.get('fullPage'); if (this.isInOutward(this.props.location.pathname)) { return /*#__PURE__*/React.createElement("div", { className: "page-wrapper" }, /*#__PURE__*/React.createElement(RouteIndex, { AutoRouter: AutoRouter })); } return AppState.isAuth && AppState.currentMenuType ? /*#__PURE__*/React.createElement("div", { className: "page-wrapper" }, /*#__PURE__*/React.createElement("div", { className: "page-header", style: fullPage ? { display: 'none' } : {} }, /*#__PURE__*/React.createElement(AnnouncementBannerPro, null), /*#__PURE__*/React.createElement(MasterHeader, null)), /*#__PURE__*/React.createElement("div", { className: "page-body" }, /*#__PURE__*/React.createElement("div", { className: "content-wrapper" }, /*#__PURE__*/React.createElement("div", { id: "menu", style: fullPage ? { display: 'none' } : {} }, /*#__PURE__*/React.createElement(CommonMenu, null)), mount('base-pro:Guide', _objectSpread(_objectSpread({}, this.props), {}, { MasterServices: MasterServices, popoverHead: popoverHead, cRef: this.cRef })), mount('base-pro:UserCheck', _objectSpread(_objectSpread({}, this.props), {}, { MasterServices: MasterServices, MasterApis: MasterApis, cRef: this.userRef })), /*#__PURE__*/React.createElement("div", { id: "autoRouter", className: "content" }, AppState.getCanShowRoute || defaultBlackList.some(function (v) { return _this4.props.location.pathname.startsWith(v); }) ? /*#__PURE__*/React.createElement(RouteIndex, { AutoRouter: AutoRouter }) : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Skeleton, null)))))) : /*#__PURE__*/React.createElement("div", { style: spinStyle }, /*#__PURE__*/React.createElement(_Spin, null)); } }]); return Masters; }(Component)) || _class) || _class) || _class); export default Masters;