田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
 * 收藏功能
 * 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);
});