/**
* 收藏功能
* Created by weidy on 2018/5/2.
*/
layui.define(['layer','carousel'],function(exports){
var Fav = function(){
this.moduleKey = "vciBaseFavPortlet";
this.id ='vciBaseFavPortlet';
this.backPath = configData.compatibility?path:configData.frameworkPath;
this.menuConfig= {//这里的配置都是默认的,在使用的时候可以覆盖
menuIconType:"iconFont",//菜单图标的获取方式,支持iconSrc.iconFont,id方式,iconSrc表示在平台中的菜单desc里配置,id表示使用菜单唯一编号
defaultMenuIconPath:'style/images/menuicons',
defaultMenuIcon:'layui-icon-app',
favUrl:"favFunctionController/listFavFunction"
};
this.favStore = {};
};
Fav.prototype.getContent = function(){
var that = this;
return '
';
};
Fav.prototype.init = function(){
var that = this;
$webUtil.copyConfig(that,that.moduleKey);
$webUtil.get(that.menuConfig.favUrl,{},function(result){
if(result.success){
var carousel = layui.carousel;
//自己加条目,而不是由carousel加
var html = "";
layui.each(result.obj,function(_index,record){
record.text = record.name;
if(_index%8==0){
//8的整数倍
html += '
';
}
//添加本功能
html += '';
if(_index%8==7 || _index == result.obj.length-1){
html += '
';
}
if(!that.favStore){
that.favStore = {};
}
that.favStore[record.oid] = record;
});
html += '
';
$("#" + that.id).html(html);
carousel.render({
elem:'#' + that.id,
width:'100%',
autoplay:false,
arrow:'none',
indicator:'inside'
});
that.bindButtonListener();
}
},function(xhr,error){},that.backPath);
};
Fav.prototype.getIconHtml = function(record){
var me = this;
var iconSrc = '';
var menuIconType = me.menuConfig.menuIconType;
if(record.menuIconType) {
menuIconType = record.menuIconType;
}
if(menuIconType == "iconSrc" && $webUtil.isNotNull(record.iconSrc)){
iconSrc = me.menuConfig.defaultMenuIconPath + "/" + record.iconSrc;
}else if(menuIconType == "id"){
iconSrc = me.menuConfig.defaultMenuIconPath + "/" + record.id + ".png";
}else if(menuIconType == "iconFont"){
iconSrc = record.iconSrc;
if($webUtil.isNull(iconSrc)){
iconSrc = me.menuConfig.defaultMenuIcon;
}
}
if($webUtil.isNull(iconSrc)){
iconSrc = me.menuConfig.defaultMenuIcon;
}
var html = "";
if(iconSrc.indexOf(".")>-1){
html += '
';
}else{
html += '';
}
return html;
};
Fav.prototype.bindButtonListener = function(){
var that = this;
$(".vciWebFavMenu").click(function(){
var id = $(this).attr("data-id");
var menuObject = null;
for(var key in that.favStore){
if(key == id){
menuObject = that.favStore[key];
break;
}
}
if(menuObject!=null){
portal.showTabByMenu(id,menuObject);
}
});
};
var fav = new Fav();
exports('portal/vciBaseFavPortlet',fav);
});