xwdt.js 1.81 KB
$(function () {
    layui.use('element', function () {
        let element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
        //监听导航点击
        element.on('nav(demo)', function (elem) {
            console.log(elem)
            layer.msg(elem.text());
        });
    });
    LoadNewsData();
    addTabs('#news');
});
//加载新闻列表数据
function LoadNewsData(currentPage=1) {   
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/hlwj/MhNews/getNewsArticleList",//路径 
        data:{
            "currentPage":currentPage,
            "pageSize":5
        }, 
        dataType: "json",
        async: false,
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理 
            data.total = result.data.total
            if (result.code == 200 && result.data != null) {
                data.list = result.data.records;                
            }
        }
    })
    layui.use('laytpl', function () {
        laytpl = layui.laytpl;
        var getTpl = document.getElementById('demo').innerHTML
            , view = document.getElementById('ulNews');
        laytpl(getTpl).render(data, function (html) {
            view.innerHTML = html;
        });
    });
}
layui.use('laypage', function () {
    let laypage = layui.laypage;
    //执行一个laypage实例
    laypage.render({
        elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号
        , count: data.total //数据总数,从服务端得到
        , limit: 5
        , prev: '<'
        , next: '>'
        , theme: '#0091FF'
        , jump: function(obj, first){
            LoadNewsData(obj.curr);
        }
    });
})
var data = { //数据
    "list": [],
    total: undefined
};