UNPKG

wiz-frameworks

Version:

wizlong react framework

136 lines (115 loc) 5.48 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * WizLayoutTemplate 通用布局模版 * @author mll * @date 2019-10-15 */ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { templateUtils } from '../../utils'; import 'antd/dist/antd.css'; import { component_tool, utils_tool } from '../../tool'; import { WizContainer } from '../WizContainer'; var WizLayout = component_tool.WizLayout; var log = utils_tool.log, Session = utils_tool.Session; var WizLayoutTemplate = function (_WizContainer) { _inherits(WizLayoutTemplate, _WizContainer); function WizLayoutTemplate(props) { _classCallCheck(this, WizLayoutTemplate); var _this = _possibleConstructorReturn(this, (WizLayoutTemplate.__proto__ || Object.getPrototypeOf(WizLayoutTemplate)).call(this, props)); _this.componentName = ''; _this._layout = function (key, node) { var params = _this.props.params; var Comp = WizLayout[key]; if (node) { return React.createElement( Comp, _extends({ key: _this.componentName + '@' + key }, node['componentProps']), templateUtils.getComponentByConfig(node, _extends({}, _this, { jumpPage: _this.jumpPage, accessBtns: _this.state.accessBtns, params: params })) ); } return null; }; _this.state = {}; return _this; } _createClass(WizLayoutTemplate, [{ key: '_componentWillMount', value: function _componentWillMount() { var _this2 = this; var _componentName = this.props.componentName; if (_componentName && _componentName !== '') { this.componentName = _componentName; } else { log.error('WizLayoutTemplate: 必须传入 容器名称(componentName)!'); } //获取页面的按钮权限 var accessBtns = this.getMenuBtn(function (accessBtns) { _this2.setState({ accessBtns: accessBtns }); }); this.setState({ accessBtns: accessBtns }); } }, { key: '_render', value: function _render() { var _props = this.props, mainProps = _props.mainProps, header = _props.header, content = _props.content, sider = _props.sider, footer = _props.footer; if (sider) { return React.createElement( WizLayout, _extends({ key: this.componentName + '@Layout', className: 'full-layout' }, mainProps), this._layout('Sider', sider), React.createElement( WizLayout, _extends({ key: this.componentName + '@Layout' }, mainProps), this._layout('Header', header), this._layout('Content', content), this._layout('Footer', footer) ) ); } else { return React.createElement( WizLayout, _extends({ key: this.componentName + '@Layout', className: 'full-layout' }, mainProps), this._layout('Header', header), this._layout('Content', content), this._layout('Footer', footer) ); } } }]); return WizLayoutTemplate; }(WizContainer); export default WizLayoutTemplate; /** * 参数定义 * isRequired 是必传标示 * mainProps:主题容器的属性(基于antd-Layout的属性) * componentName:必传⭐️,容器名称 * header:头部组件,布局容器 * content:必传⭐️,主要组件,布局容器 * sider:侧边栏组件,布局容器 * footer:页脚组件,布局容器 * * 具体配置请看文档:sgm_template.md */ WizLayoutTemplate.propTypes = { mainProps: PropTypes.any, componentName: PropTypes.string.isRequired, header: PropTypes.any, content: PropTypes.any.isRequired, sider: PropTypes.any, footer: PropTypes.any /** * 默认值 */ };WizLayoutTemplate.defaultProps = {};