/**
|
* 收藏功能
|
* 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 '<div class="layui-carousel layui-vci-fav " id="' + that.id + '"></div>';
|
};
|
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 = "<div carousel-item>";
|
layui.each(result.obj,function(_index,record){
|
record.text = record.name;
|
if(_index%8==0){
|
//8的整数倍
|
html += '<ul class="layui-row layui-col-space10 ' + (_index == 0?'layui-this':'') + '">';
|
}
|
//添加本功能
|
html += '<li class="layui-col-xs3"><a href="javascript:;" class="vciWebFavMenu" data-id="' + record.oid + '">' + that.getIconHtml(record) + '<cite>' + record.name + '</cite></a></li>';
|
if(_index%8==7 || _index == result.obj.length-1){
|
html += '</ul>';
|
}
|
if(!that.favStore){
|
that.favStore = {};
|
}
|
that.favStore[record.oid] = record;
|
});
|
html += '</div>';
|
$("#" + 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 += '<img src="' + iconSrc + '" style="width:30px;height:30px;">';
|
}else{
|
html += '<i class="layui-icon ' + iconSrc + '" style="font-size: 30px; "></i>';
|
}
|
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);
|
});
|