UNPKG

9.31 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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; };
8
9var _react = require("react");
10
11var _react2 = _interopRequireDefault(_react);
12
13var _propTypes = require("prop-types");
14
15var _propTypes2 = _interopRequireDefault(_propTypes);
16
17var _Grid = require("./Grid");
18
19var _Grid2 = _interopRequireDefault(_Grid);
20
21var _beePagination = require("bee-pagination");
22
23var _beePagination2 = _interopRequireDefault(_beePagination);
24
25var _beeSelect = require("bee-select");
26
27var _beeSelect2 = _interopRequireDefault(_beeSelect);
28
29var _beeTooltip = require("bee-tooltip");
30
31var _beeTooltip2 = _interopRequireDefault(_beeTooltip);
32
33var _lodash = require("lodash.clonedeep");
34
35var _lodash2 = _interopRequireDefault(_lodash);
36
37var _lodash3 = require("lodash.isequal");
38
39var _lodash4 = _interopRequireDefault(_lodash3);
40
41function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
42
43function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
44
45function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
46
47function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
48
49function _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; }
50
51function _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) : _defaults(subClass, superClass); }
52
53var Option = _beeSelect2["default"].Option;
54
55var propsTypes = {
56 paginationObj: _propTypes2["default"].object, //分页参数
57 showPagination: _propTypes2["default"].bool, //是否显示分页
58 showTooltip: _propTypes2["default"].bool, //是否显示tooltip
59 showIndex: _propTypes2["default"].bool //是否显示index列
60};
61
62var defaultProps = {
63 paginationObj: {},
64 showPagination: true,
65 showTooltip: false,
66 showIndex: false
67};
68
69var AcGrids = function (_Component) {
70 _inherits(AcGrids, _Component);
71
72 function AcGrids(props) {
73 _classCallCheck(this, AcGrids);
74
75 var _this = _possibleConstructorReturn(this, _Component.call(this, props));
76
77 _this.onSelectChange = function (value) {
78 _this.props.paginationObj.onDataNumSelect && _this.props.paginationObj.onDataNumSelect(value);
79 };
80
81 _this.exportExcel = function () {
82 _this.grid.exportExcel();
83 };
84
85 _this.setColumns = function (col, da) {
86 var columns = (0, _lodash2["default"])(col);
87 var _this$props = _this.props,
88 showIndex = _this$props.showIndex,
89 showTooltip = _this$props.showTooltip;
90
91 if (showIndex) {
92 //给data加index
93 var data = (0, _lodash2["default"])(da);
94 if (data[0] && data[0].index == 1) {//如果index存在
95 } else {
96 data.forEach(function (item, index) {
97 item.index = index + 1;
98 });
99 _this.setState({
100 data: data
101 });
102 }
103 columns.unshift({
104 title: "序号",
105 dataIndex: "index",
106 key: "index",
107 width: 100
108 });
109 }
110 columns.forEach(function (item) {
111 item.oldRender = item.render;
112 if (typeof item.oldRender == 'function' && (item.oldRender.toString().indexOf('colSpan') != -1 || item.oldRender.toString().indexOf('rowSpan') != -1)) {
113 item.render = item.oldRender;
114 } else {
115 item.render = function (text, record, index) {
116 if (showTooltip) {
117 var placement = 'left';
118 if (item.textAlign) placement = item.textAlign == 'center' ? 'bottom' : item.textAlign;
119 var value = typeof item.oldRender == 'function' ? item.oldRender(text, record, index) : text;
120 return _react2["default"].createElement(
121 _beeTooltip2["default"],
122 { overlay: value, inverse: true, placement: placement },
123 _react2["default"].createElement(
124 "span",
125 null,
126 value
127 )
128 );
129 } else {
130 var _value = typeof item.oldRender == 'function' ? item.oldRender(text, record, index) : text;
131 return _react2["default"].createElement(
132 "span",
133 { className: "ac-grid-cell", title: typeof _value == 'string' || typeof _value == 'number' ? _value : '' },
134 _value
135 );
136 }
137 };
138 }
139 });
140 _this.setState({
141 columns: columns
142 });
143 };
144
145 _this.state = {
146 activePage: 1,
147 columns: props.columns,
148 data: props.data
149 };
150 return _this;
151 }
152
153 AcGrids.prototype.componentWillMount = function componentWillMount() {
154 this.setColumns(this.props.columns, this.props.data);
155 };
156
157 AcGrids.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
158 if (!(0, _lodash4["default"])(nextProps.data, this.state.data)) {
159 this.setState({
160 data: nextProps.data
161 });
162 }
163 };
164
165 AcGrids.prototype.render = function render() {
166 var _this2 = this;
167
168 var _props = this.props,
169 paginationObj = _props.paginationObj,
170 showPagination = _props.showPagination,
171 columns = _props.columns,
172 data = _props.data,
173 other = _objectWithoutProperties(_props, ["paginationObj", "showPagination", "columns", "data"]);
174
175 return _react2["default"].createElement(
176 "div",
177 { className: "ac-grids-wrapper" },
178 _react2["default"].createElement(_Grid2["default"], _extends({}, other, { columns: this.state.columns, data: this.state.data, ref: function ref(_ref) {
179 return _this2.grid = _ref;
180 } })),
181 showPagination ? _react2["default"].createElement(
182 "div",
183 { className: "ac-grids-wrapper-pages" },
184 _react2["default"].createElement(
185 _beeSelect2["default"],
186 { onChange: this.onSelectChange, defaultValue: "10" },
187 _react2["default"].createElement(
188 Option,
189 { value: "10" },
190 "10\u6761/\u9875"
191 ),
192 _react2["default"].createElement(
193 Option,
194 { value: "20" },
195 "20\u6761/\u9875"
196 ),
197 _react2["default"].createElement(
198 Option,
199 { value: "50" },
200 "50\u6761/\u9875"
201 ),
202 _react2["default"].createElement(
203 Option,
204 { value: "100" },
205 "100\u6761/\u9875"
206 )
207 ),
208 _react2["default"].createElement(_beePagination2["default"], _extends({
209 prev: true,
210 next: true,
211 size: "sm",
212 gap: true,
213 items: 0
214 }, paginationObj))
215 ) : ''
216 );
217 };
218
219 return AcGrids;
220}(_react.Component);
221
222AcGrids.defaultProps = defaultProps;
223AcGrids.propsTypes = propsTypes;
224AcGrids.GridToolBar = _Grid.GridToolBar;
225exports["default"] = AcGrids;
226module.exports = exports["default"];
\No newline at end of file