yylib-quick-mobile
Version:
yylib-quick-mobile
311 lines (279 loc) • 10.2 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _grid = require('antd-mobile/lib/grid');
var _grid2 = _interopRequireDefault(_grid);
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; }; }();
require('antd-mobile/lib/grid/style/css');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _reactDom = require('react-dom');
var _reactDom2 = _interopRequireDefault(_reactDom);
require('./YYGrid.less');
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _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; }
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; }
var defaultImg = require('./img/default.png');
var YYGrid = function (_Component) {
_inherits(YYGrid, _Component);
function YYGrid(props) {
_classCallCheck(this, YYGrid);
var _this = _possibleConstructorReturn(this, (YYGrid.__proto__ || Object.getPrototypeOf(YYGrid)).call(this, props));
_this.state = {
dataSource: []
};
return _this;
}
_createClass(YYGrid, [{
key: 'getOtherProps',
value: function getOtherProps(props) {
var otherProps = {};
var activeStyle = props.activeStyle,
hasLine = props.hasLine,
isCarousel = props.isCarousel,
carouselMaxRow = props.carouselMaxRow,
customDraw = props.customDraw,
columnNum = props.columnNum,
itemheight = props.itemheight,
visible = props.visible;
var wrapClz = (0, _classnames2.default)('yy-grid', this.props.className);
otherProps = {
activeStyle: activeStyle,
hasLine: hasLine,
className: wrapClz,
isCarousel: isCarousel,
carouselMaxRow: carouselMaxRow,
columnNum: columnNum,
itemStyle: customDraw && { height: itemheight }
};
return otherProps;
}
}, {
key: 'createDesignData',
value: function createDesignData() {
var data = [{
icon: require('./img/check.png'),
text: "安全检查",
state: "0",
num: 10
}, {
icon: require('./img/rectify.png'),
text: "安全整改",
state: "1",
num: 10
}, {
icon: require('./img/photo.png'),
text: "拍照检查"
}, {
icon: require('./img/check.png'),
text: "安全检查",
state: "0",
num: 10
}, {
icon: require('./img/rectify.png'),
text: "安全整改",
state: "1",
num: 10
}, {
icon: require('./img/photo.png'),
text: "拍照检查"
}, {
icon: require('./img/check.png'),
text: "安全检查",
state: "0",
num: 10
}, {
icon: require('./img/rectify.png'),
text: "安全整改",
state: "1",
num: 10
}, {
icon: require('./img/photo.png'),
text: "拍照检查"
}];
this.setState({
dataSource: data
});
}
}, {
key: 'setData',
value: function setData(data) {
this.setState({
dataSource: data
});
}
}, {
key: 'onClick',
value: function onClick(el, index) {
if (this.props.onClick) {
this.props.onClick(el, index);
}
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
var _props = this.props,
RunInDesign = _props.RunInDesign,
data = _props.data;
if (RunInDesign) {
this.createDesignData();
}
if (data && data.length > 0) {
this.setState({
dataSource: data
});
}
}
}, {
key: 'createRow',
value: function createRow(row, index) {
var _props2 = this.props,
iconwidth = _props2.iconwidth,
columnNum = _props2.columnNum,
renderItem = _props2.renderItem,
customDraw = _props2.customDraw,
type = _props2.type,
RunInDesign = _props2.RunInDesign;
if (RunInDesign && !customDraw) {
if (type === 'img') {
return _react2.default.createElement(
'div',
{ className: 'gridDiv-zk' },
_react2.default.createElement('img', { className: 'gridImg-zk', src: row["icon"] }),
_react2.default.createElement(
'div',
{ className: 'gridDec-zk' },
row["text"]
),
row["state"] && row["num"] !== 0 ? _react2.default.createElement(
'span',
null,
row["num"]
) : null
);
} else if (type === 'num') {
return _react2.default.createElement(
'li',
{ key: index },
_react2.default.createElement(
'span',
null,
row["num"]
),
_react2.default.createElement(
'p',
null,
row["text"]
)
);
}
} else {
if (customDraw) {
if (renderItem) {
return renderItem(row, index);
}
} else {
if (type === 'img') {
return _react2.default.createElement(
'div',
{ className: 'gridDiv-zk' },
_react2.default.createElement('img', { className: 'gridImg-zk', src: row["icon"] ? row["icon"] : defaultImg }),
_react2.default.createElement(
'div',
{ className: 'gridDec-zk' },
row["text"]
),
row["state"] && row["num"] !== 0 ? _react2.default.createElement(
'span',
null,
row["num"]
) : null
);
} else if (type === 'num') {
return _react2.default.createElement(
'li',
{ key: index },
_react2.default.createElement(
'span',
null,
row["num"]
),
_react2.default.createElement(
'p',
null,
row["text"]
)
);
}
}
}
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextprops) {
if (nextprops.data && nextprops.data.length > 0) {
this.setState({
dataSource: nextprops.data
});
}
if (nextprops.RunInDesign) {
this.createDesignData();
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var refProps = this.getOtherProps(this.props);
var _props3 = this.props,
data = _props3.data,
headerText = _props3.headerText,
RunInDesign = _props3.RunInDesign,
visible = _props3.visible,
restProps = _objectWithoutProperties(_props3, ['data', 'headerText', 'RunInDesign', 'visible']);
var dataSource = this.state.dataSource;
var clz = (0, _classnames2.default)('grid-zk', !visible && 'hidden');
var wrapClz = (0, _classnames2.default)('yy-grid', !visible && 'hidden', this.props.className);
return headerText ? _react2.default.createElement(
'div',
{ className: clz },
_react2.default.createElement(
'p',
null,
headerText
),
_react2.default.createElement(_grid2.default, _extends({
ref: 'myGrid'
}, restProps, refProps, {
className: wrapClz,
square: true,
data: this.state.dataSource,
onClick: this.onClick.bind(this),
renderItem: function renderItem(row, index) {
return _this2.createRow(row, index);
} }))
) : _react2.default.createElement(_grid2.default, _extends({
ref: 'myGrid'
}, restProps, refProps, {
className: wrapClz,
square: true,
data: this.state.dataSource,
onClick: this.onClick.bind(this),
renderItem: function renderItem(row, index) {
return _this2.createRow(row, index);
} }));
}
}]);
return YYGrid;
}(_react.Component);
YYGrid.defaultProps = {
data: [],
visible: true
};
exports.default = YYGrid;
;