@doreamonjs/gate
Version:
gate for doreamonjs
92 lines • 3.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const dva_1 = require("dva");
const doreamon_1 = tslib_1.__importDefault(require("@zodash/doreamon"));
const components_1 = require("@doreamonjs/components");
const utils = tslib_1.__importStar(require("../../utils"));
require("./index.less");
const componentName = 'doreamonjs-design-gate-layout-navbar';
const mapState = ({ menus }) => {
const { nav, data } = menus;
return {
type: nav.type,
nav,
menus: data,
};
};
const mapAction = (dispatch) => ({
onNavChange: (path) => dispatch({
type: 'menus/navigate',
payload: path,
}),
onNavRefresh: (path) => dispatch({
type: 'menus/nav/refresh',
payload: path,
}),
onNavClose: (path) => dispatch({
type: 'menus/nav/close',
payload: path,
}),
onNavCloseOthers: (path) => dispatch({
type: 'menus/nav/close/others',
payload: path,
}),
onNavCloseAll: () => dispatch({
type: 'menus/nav/close/all',
}),
onGoHome: () => dispatch({
type: 'menus/navigate',
payload: '/',
}),
});
let NavBar = class NavBar extends react_1.Component {
constructor() {
super(...arguments);
this.getTagNavProps = () => {
const { menus, nav, onNavChange, onNavRefresh, onNavClose, onNavCloseOthers, onNavCloseAll, } = this.props;
const tags = getNavTags(menus, nav);
return {
className: classnames_1.default(componentName, 'navBar'),
tags,
current: nav.current,
onNav(route) {
onNavChange(route.path);
},
onRefresh(route) {
onNavRefresh(route.path);
},
onClose(route) {
onNavClose(route.path);
},
onCloseOthers(route) {
onNavCloseOthers(route.path);
},
onCloseAll: onNavCloseAll,
};
};
}
render() {
const { type, nav, menus, onGoHome } = this.props;
if (type === 'breadcrumb') {
return (react_1.default.createElement(components_1.Navigation.Breadcrumb, { className: classnames_1.default(componentName, 'navBar'), path: nav.current, menus: menus, onGoHome: onGoHome }));
}
const tagNavProps = this.getTagNavProps();
if (tagNavProps.tags.length === 0) {
return null;
}
return react_1.default.createElement(components_1.Navigation.Tag, { ...tagNavProps });
}
};
NavBar = tslib_1.__decorate([
dva_1.connect(mapState, mapAction)
], NavBar);
exports.default = NavBar;
function getNavTags(menus, nav) {
const indexMenus = utils.getMenus('nest', menus).index;
const pickedMenus = doreamon_1.default.object.pick(indexMenus, nav.history);
return Object.values(pickedMenus);
}
//# sourceMappingURL=index.js.map