var Event = require('bcore/event');
var $ = require('jquery');
var _ = require('lodash');
import Swiper from 'swiper/swiper-bundle.min.js';
import 'swiper/swiper-bundle.css';
module.exports = Event.extend(function Base(container, config) {
this.config = {
theme: {}
}
this.container = $(container);
this.apis = config.apis;
this._data = null;
this.chart = null;
this.init(config);
}, {
init: function (config) {
this.mergeConfig(config);
this.updateLayout();
this.updateStyle();
},
render: function (data, config) {
data = this.data(data);
var cfg = this.mergeConfig(config);
let date = new Date()
let _class = "wxz" + date.getTime() + date.getSeconds()
let _strHtml = `<div class="swiper ${_class}" style="height: 100%">
<div class="swiper-wrapper">
</div>
</div>`
this.container.html(_strHtml)
console.log(this.container)
for (let i = 0; i < data.length; i++) {
this.container.children().children().append(`<div class="swiper-slide"><a href="${data[i].linkTo}" target="_blank"><img style="width: 100%;height: 100%" src="${data[i].url}"></a></div>`)
}
let swiper = new Swiper(`.${_class}`, {
slidesPerView: cfg.slidesPerView,
spaceBetween: cfg.spaceBetween,
loop:true,
autoplay: {
delay: 1000,
stopOnLastSlide: false,
pauseOnMouseEnter:true,
disableOnInteraction: false,
},
freeMode: true,
});
this.updateStyle();
},
resize: function (width, height) {
this.updateLayout(width, height);
},
setColors: function () {
},
data: function (data) {
if (data) {
this._data = data;
}
return this._data;
},
mergeConfig: function (config) {
if (!config) {return this.config}
this.config.theme = _.defaultsDeep(config.theme || {}, this.config.theme);
this.setColors();
this.config = _.defaultsDeep(config || {}, this.config);
return this.config;
},
updateLayout: function () {},
updateStyle: function () {
var cfg = this.config;
this.container.css({
'font-size': cfg.size + 'px',
'color': cfg.color || '#fff'
});
},
destroy: function(){console.log('请实现 destroy 方法')}
});