yylib-quick-mobile
Version:
yylib-quick-mobile
176 lines (147 loc) • 6.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _carousel = require('antd-mobile/lib/carousel');
var _carousel2 = _interopRequireDefault(_carousel);
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/carousel/style/css');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
require('./YYCarousel.less');
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _FunctionUtil = require('../../utils/FunctionUtil');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 YYCarousel = function (_Component) {
_inherits(YYCarousel, _Component);
function YYCarousel(props) {
_classCallCheck(this, YYCarousel);
var _this = _possibleConstructorReturn(this, (YYCarousel.__proto__ || Object.getPrototypeOf(YYCarousel)).call(this, props));
_this.beforeChange = function (from, to) {
if ((0, _FunctionUtil.isFunction)(_this.props.beforeChange)) {
_this.props.beforeChange(from, to);
}
};
_this.afterChange = function (index) {
if ((0, _FunctionUtil.isFunction)(_this.props.afterChange)) {
_this.props.afterChange(index);
}
};
_this.state = {
data: []
};
return _this;
}
_createClass(YYCarousel, [{
key: 'imgClick',
value: function imgClick(item) {
if ((0, _FunctionUtil.isFunction)(this.props.imgClick)) {
this.props.imgClick(item);
}
}
}, {
key: 'getCarouselPanel',
value: function getCarouselPanel() {
var _this2 = this;
var data = this.state.data;
var _props = this.props,
height = _props.height,
type = _props.type;
if (type === 'img' && data.length) {
return data.map(function (item) {
return _react2.default.createElement('img', { key: item.id, src: item.imgsrc, style: { display: "block", position: "relative", height: height }, onClick: _this2.imgClick.bind(_this2, item) });
});
} else {
var children = this.props.children;
if (children) {
Array.prototype.slice.call(children);
children = children && children.constructor == Array ? children : [children];
return children.map(function (item, index) {
var _item$props = item.props,
nid = _item$props.nid,
child = _item$props.children;
child = child && child.constructor == Array ? child : [child];
child = child && child.length ? child : _react2.default.createElement(
'div',
null,
_react2.default.createElement(
'center',
null,
"走马灯" + (index + 1)
)
);
return _react2.default.createElement(
'div',
{ key: nid, style: { "height": "100%", "width": "100%" } },
child
);
});
}
}
return [];
}
}, {
key: 'setData',
value: function setData(data) {
this.setState({ data: data });
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
height = _props2.height,
selectedIndex = _props2.selectedIndex,
dots = _props2.dots,
vertical = _props2.vertical,
autoplay = _props2.autoplay,
autoplayInterval = _props2.autoplayInterval,
infinite = _props2.infinite,
swipeSpeed = _props2.swipeSpeed,
slideWidth = _props2.slideWidth,
visible = _props2.visible;
var wrapClz = (0, _classnames2.default)('yy-carousel', !visible && 'hidden', this.props.className);
var swidth = parseInt(slideWidth);
var itemwidth = slideWidth;
if (slideWidth.replace(swidth, "") == "%") {
itemwidth = swidth / 100;
}
var style = { height: height };
return _react2.default.createElement(
_carousel2.default,
{
selectedIndex: selectedIndex,
dots: dots,
vertical: vertical,
autoplay: autoplay,
autoplayInterval: autoplayInterval,
infinite: infinite,
swipeSpeed: swipeSpeed,
slideWidth: itemwidth,
className: wrapClz,
beforeChange: this.beforeChange,
afterChange: this.afterChange,
style: style },
this.getCarouselPanel()
);
}
}]);
return YYCarousel;
}(_react.Component);
YYCarousel.defaultProps = {
selectedIndex: 0,
dots: true,
vertical: false,
autoplay: false,
autoplayInterval: 3000,
infinite: false,
height: "120px",
swipeSpeed: 12,
slideWidth: "100%",
visible: true,
type: 'basic'
};
exports.default = YYCarousel;
;