1. 程式人生 > >js基於Layui模塊化封裝

js基於Layui模塊化封裝

top 顯示 size nal too false layui span 動態綁定

//設置body高度
$(function () {
    var topHei = 0;
    var CH = window.innerHeight || document.documentElement.clientHeight;
    document.getElementsByTagName("body")[0].style.height = CH - topHei + ‘px‘;
    return CH - topHei;
});

//-------------對UI中表格進行模塊化封裝處理-----------------------------------
var laytable;
//基礎參數配置 var baseCfg = { datatype: ‘table‘, page: { //支持傳入 laypage 組件的所有參數(某些參數除外,如:jump/elem) - 詳見文檔 layout: [‘limit‘, ‘count‘, ‘prev‘, ‘page‘, ‘next‘, ‘skip‘] //自定義分頁布局 , groups: 3 //只顯示 1 個連續頁碼 , first: false //不顯示首頁 , last: false //不顯示尾頁 , limit: 5 , curr: location.hash.replace(
‘#!fenye=‘, ‘‘) //獲取起始頁 , hash: ‘fenye‘ //自定義hash值 } , height: 415 , id: ‘TableDataReload‘ , method: "post" }; var le= le|| {}; (function () { var commerical = function (cusCfg) { this.config = {}; $.extend(this.config, baseCfg); $.extend(this.config, cusCfg);
this.__init(this.config); this.__bindEvent(); }; commerical.prototype = { __init: function (cfg) { layui.use([‘table‘], function () { laytable = layui.table; laytable.render(cfg); if (cfg.actionBar) { laytable.on(‘tool(‘ + cfg.actionBarFilter + ‘)‘, function (obj) { var data = obj.data; var type = obj.event; active[type] ? active[type].call(this, data) : ‘‘; }); } }); }, __bindEvent: function () { //動態綁定全局.layui-btn按鈕事件 $(‘.layui-btn‘).on(‘click‘, function () { var type = $(this).data(‘type‘); active[type] ? active[type].call(this) : ‘‘; }); } }; le.sy = function () { return { init: function (config) { try { if (config == undefined || config == null) { throw ‘config is empty!‘; } else { return new commerical(config); } } catch (e) { return e; } }, reload: function (obj) { laytable.reload(‘TableDataReload‘, { where: obj }); }, layerOpen: function (domId,title) { layer.open({ type: 1, shade: 0.8, btnAlign: ‘c‘, resize: false, title: title||"編輯", area: [‘440px‘, ‘410px‘], offset: [‘100px‘, ‘200px‘], content: $(‘#‘ + domId) }); }, layerClose: function () { }, msg: function (msg) { layer.msg(msg); } } }(); })();

js基於Layui模塊化封裝