UNPKG

@doreamonjs/gate

Version:
81 lines 4.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = tslib_1.__importDefault(require("react")); const dva_1 = require("dva"); const icons_1 = require("@ant-design/icons"); const antd_1 = require("antd"); const compatible_1 = require("@ant-design/compatible"); require("./index.less"); const Connect = (props) => { var _a; let cfg = null; try { cfg = JSON.parse(props.config); } catch (_b) { // } const renderIcon = (e) => { var _a, _b; if (((_a = cfg === null || cfg === void 0 ? void 0 : cfg.mode) === null || _a === void 0 ? void 0 : _a.logo) === 'logo') { return (react_1.default.createElement("img", { style: { width: 24, height: 24, borderRadius: 2, }, src: e.logo })); } if (((_b = cfg === null || cfg === void 0 ? void 0 : cfg.mode) === null || _b === void 0 ? void 0 : _b.logo) === 'icon') { return (react_1.default.createElement(compatible_1.Icon, { type: e === null || e === void 0 ? void 0 : e.icon })); } return null; }; const renderTitle = (e) => { var _a; return (_a = e === null || e === void 0 ? void 0 : e.title) !== null && _a !== void 0 ? _a : '未命名'; }; let menuItems = []; const apps = (cfg === null || cfg === void 0 ? void 0 : cfg.apps) || []; if (!!((_a = cfg === null || cfg === void 0 ? void 0 : cfg.apps) === null || _a === void 0 ? void 0 : _a.length)) { menuItems = apps.map((e) => { var _a, _b, _c; const type = (_a = e === null || e === void 0 ? void 0 : e.type) !== null && _a !== void 0 ? _a : 'text'; const icon = renderIcon(e); const title = renderTitle(e); switch (type) { case 'text': return (react_1.default.createElement(antd_1.Menu.Item, { key: e === null || e === void 0 ? void 0 : e.key }, icon, " ", title)); case 'link': return (react_1.default.createElement(antd_1.Menu.Item, { key: e === null || e === void 0 ? void 0 : e.key }, react_1.default.createElement("a", { href: (_b = e === null || e === void 0 ? void 0 : e.link) === null || _b === void 0 ? void 0 : _b.href, target: "_blank", rel: "noopener noreferrer" }, icon, " ", title))); case 'action': return (react_1.default.createElement(antd_1.Menu.Item, { key: e === null || e === void 0 ? void 0 : e.key }, react_1.default.createElement("a", { href: (_c = e === null || e === void 0 ? void 0 : e.link) === null || _c === void 0 ? void 0 : _c.href, target: "_blank", rel: "noopener noreferrer" }, icon, " ", title))); default: return (react_1.default.createElement(antd_1.Menu.Item, { key: e === null || e === void 0 ? void 0 : e.key }, react_1.default.createElement("span", null, "\u672A\u77E5\u7C7B\u578B\uFF1A", type))); } }); } if (!menuItems.length) { return (react_1.default.createElement("span", { className: 'barIcon', title: "Connect" }, react_1.default.createElement(icons_1.AppstoreOutlined, null))); } const menu = react_1.default.createElement(antd_1.Menu, { style: { minWidth: 150 } }, menuItems); return (react_1.default.createElement(antd_1.Dropdown, { overlay: menu, placement: "bottomCenter" }, react_1.default.createElement("span", { className: 'barIcon', title: "Connect" }, react_1.default.createElement(icons_1.AppstoreOutlined, null)))); }; exports.default = dva_1.connect()(Connect); //# sourceMappingURL=connect.js.map