@aliretail/react-materials-components
Version:
144 lines (130 loc) • 4.37 kB
JavaScript
import _Loading from "@alifd/next/es/loading";
import _Button from "@alifd/next/es/button";
import _Balloon from "@alifd/next/es/balloon";
import _Icon from "@alifd/next/es/icon";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _Grid from "@alifd/next/es/grid";
import * as React from 'react';
import * as PropTypes from 'prop-types';
import _ from 'lodash';
import { StatusTag } from "../StatusTag";
var Row = _Grid.Row,
Col = _Grid.Col;
var colMax = 6;
var typeToColor = {
warning: 'orange',
middle: 'blue',
success: 'green',
cancel: 'gray',
error: 'red'
};
var ShowWrapper = function ShowWrapper(props) {
var isShow = props.isShow,
children = props.children;
if (isShow) {
return children;
} else {
return null;
}
};
var Dashboard = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(Dashboard, _React$Component);
function Dashboard() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
_this.getSpan = function (len) {
// 一行最多放6个,多了显示在下一行
var span = '0';
if (len === 5) {
span = '1p5';
} else if (len <= colMax) {
span = "" + 24 / len;
} else {
span = '4';
}
return span;
};
return _this;
}
var _proto = Dashboard.prototype;
_proto.render = function render() {
var _this$props = this.props,
dataSource = _this$props.dataSource,
isLoading = _this$props.isLoading;
var span = this.getSpan(dataSource.length);
return /*#__PURE__*/React.createElement(_Loading, {
visible: isLoading,
style: {
width: '100%'
}
}, /*#__PURE__*/React.createElement("div", {
className: "aliretail-dashboard-wrapper"
}, _.chunk(dataSource, colMax).map(function (row, index) {
return /*#__PURE__*/React.createElement(Row, {
key: index,
className: "row",
gutter: 5
}, row.map(function (col, colIndex) {
return /*#__PURE__*/React.createElement(Col, {
key: colIndex,
span: span
}, /*#__PURE__*/React.createElement("div", {
className: "aliretail-dashboard-item"
}, /*#__PURE__*/React.createElement("div", {
className: "aliretail-dashboard-item-label"
}, /*#__PURE__*/React.createElement("span", {
className: "label"
}, col.label), /*#__PURE__*/React.createElement(ShowWrapper, {
isShow: !!col.labelStatus
}, /*#__PURE__*/React.createElement("div", {
className: "aliretail-dashboard-item-labelStatus"
}, /*#__PURE__*/React.createElement(StatusTag, {
color: typeToColor[col.labelStatusType],
text: col.labelStatus
}))), /*#__PURE__*/React.createElement(ShowWrapper, {
isShow: !!col.labelTooltipContent
}, /*#__PURE__*/React.createElement(_Balloon, {
closable: false,
trigger: /*#__PURE__*/React.createElement(_Icon, {
type: "prompt",
size: "medium",
className: "tooltip-icon",
style: {
color: '#ACADB6',
marginLeft: '4px'
}
}),
triggerType: "click"
}, col.labelTooltipContent))), /*#__PURE__*/React.createElement("div", {
className: "aliretail-dashboard-item-value"
}, /*#__PURE__*/React.createElement("span", {
className: "value"
}, col.value), /*#__PURE__*/React.createElement(ShowWrapper, {
isShow: !!col.valueTooltipTitle
}, /*#__PURE__*/React.createElement(_Balloon, {
closable: false,
trigger: /*#__PURE__*/React.createElement(_Button, {
type: "primary",
text: true,
style: {
marginLeft: '12px',
fontSize: '14px'
}
}, col.valueTooltipTitle),
triggerType: "click"
}, col.valueTooltipContent)))));
}));
})));
};
return Dashboard;
}(React.Component);
Dashboard.propTypes = {
dataSource: PropTypes.arrayOf(PropTypes.object).isRequired
};
Dashboard.defaultProps = {
data: []
};
export default Dashboard;