From 57c1b91f26b087a2eb218a8f5be3eefa1a54a0f8 Mon Sep 17 00:00:00 2001
From: weizhiqiang <598748873@qq.com>
Date: Thu, 10 Oct 2019 16:55:46 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=8A=A0=E8=BD=BD=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../assets/lib/layui/lay/modules/table.js | 2511 ++++++++---------
1 file changed, 1217 insertions(+), 1294 deletions(-)
diff --git a/erp-web/src/main/resources/template/assets/lib/layui/lay/modules/table.js b/erp-web/src/main/resources/template/assets/lib/layui/lay/modules/table.js
index 7c1f30aa..f209f556 100644
--- a/erp-web/src/main/resources/template/assets/lib/layui/lay/modules/table.js
+++ b/erp-web/src/main/resources/template/assets/lib/layui/lay/modules/table.js
@@ -1,1295 +1,1218 @@
-/**
- @Name:layui.table 表格操作
- */
-
-layui.define(['laytpl', 'laypage', 'layer', 'form'], function(exports){
- "use strict";
-
- var $ = layui.$
- ,laytpl = layui.laytpl
- ,laypage = layui.laypage
- ,layer = layui.layer
- ,form = layui.form
- ,hint = layui.hint()
- ,device = layui.device()
-
- //外部接口
- ,table = {
- config: {
- checkName: 'LAY_CHECKED' //是否选中状态的字段名
- ,indexName: 'LAY_TABLE_INDEX' //下标索引名
- } //全局配置项
- ,cache: {} //数据缓存
- ,index: layui.table ? (layui.table.index + 10000) : 0
-
- //设置全局项
- ,set: function(options){
- var that = this;
- that.config = $.extend({}, that.config, options);
- return that;
- }
-
- //事件监听
- ,on: function(events, callback){
- return layui.onevent.call(this, MOD_NAME, events, callback);
- }
- }
-
- //操作当前实例
- ,thisTable = function(){
- var that = this
- ,options = that.config
- ,id = options.id;
-
- id && (thisTable.config[id] = options);
-
- return {
- reload: function(options){
- that.reload.call(that, options);
- }
- ,config: options
- }
- }
-
- //字符常量
- ,MOD_NAME = 'table', ELEM = '.layui-table', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', DISABLED = 'layui-disabled', NONE = 'layui-none'
-
- ,ELEM_VIEW = 'layui-table-view', ELEM_HEADER = '.layui-table-header', ELEM_BODY = '.layui-table-body', ELEM_MAIN = '.layui-table-main', ELEM_FIXED = '.layui-table-fixed', ELEM_FIXL = '.layui-table-fixed-l', ELEM_FIXR = '.layui-table-fixed-r', ELEM_TOOL = '.layui-table-tool', ELEM_PAGE = '.layui-table-page', ELEM_SORT = '.layui-table-sort', ELEM_EDIT = 'layui-table-edit', ELEM_HOVER = 'layui-table-hover'
-
- //thead区域模板
- ,TPL_HEADER = function(options){
- var rowCols = '{{#if(item2.colspan){}} colspan="{{item2.colspan}}"{{#} if(item2.rowspan){}} rowspan="{{item2.rowspan}}"{{#}}}';
-
- options = options || {};
- return ['
'
- ,''
- ,'{{# layui.each(d.data.cols, function(i1, item1){ }}'
- ,''
- ,'{{# layui.each(item1, function(i2, item2){ }}'
- ,'{{# if(item2.fixed && item2.fixed !== "right"){ left = true; } }}'
- ,'{{# if(item2.fixed === "right"){ right = true; } }}'
- ,function(){
- if(options.fixed && options.fixed !== 'right'){
- return '{{# if(item2.fixed && item2.fixed !== "right"){ }}';
- }
- if(options.fixed === 'right'){
- return '{{# if(item2.fixed === "right"){ }}';
- }
- return '';
- }()
- ,''
- ,' '
- ,'{{# if(item2.type === "checkbox"){ }}' //复选框
- ,''
- ,'{{# } else { }}'
- ,'{{item2.title||""}}'
- ,'{{# if(!(item2.colspan > 1) && item2.sort){ }}'
- ,''
- ,'{{# } }}'
- ,'{{# } }}'
- ,' '
- ,' | '
- ,(options.fixed ? '{{# }; }}' : '')
- ,'{{# }); }}'
- ,'
'
- ,'{{# }); }}'
- ,''
- ,'
'].join('');
- }
-
- //tbody区域模板
- ,TPL_BODY = [''].join('')
-
- //主模板
- ,TPL_MAIN = [''].join('')
-
- ,_WIN = $(window)
- ,_DOC = $(document)
-
- //构造器
- ,Class = function(options){
- var that = this;
- that.index = ++table.index;
- that.config = $.extend({}, that.config, table.config, options);
- that.render();
- };
-
- //默认配置
- Class.prototype.config = {
- limit: 10 //每页显示的数量
- ,loading: true //请求数据时,是否显示loading
- ,cellMinWidth: 60 //所有单元格默认最小宽度
- ,text: {
- none: '无数据'
- }
- };
-
- //表格渲染
- Class.prototype.render = function(){
- var that = this
- ,options = that.config;
-
- options.elem = $(options.elem);
- options.where = options.where || {};
- options.id = options.id || options.elem.attr('id');
-
- //请求参数的自定义格式
- options.request = $.extend({
- pageName: 'page'
- ,limitName: 'limit'
- }, options.request)
-
- //响应数据的自定义格式
- options.response = $.extend({
- statusName: 'returnCode'
- ,statusCode: 0
- ,msgName: 'returnMessage'
- ,dataName: 'rows'
- ,countName: 'total'
- }, options.response);
-
- //如果 page 传入 laypage 对象
- if(typeof options.page === 'object'){
- options.limit = options.page.limit || options.limit;
- options.limits = options.page.limits || options.limits;
- that.page = options.page.curr = options.page.curr || 1;
- delete options.page.elem;
- delete options.page.jump;
- }
-
- if(!options.elem[0]) return that;
-
- that.setArea(); //动态分配列宽高
-
- //开始插入替代元素
- var othis = options.elem
- ,hasRender = othis.next('.' + ELEM_VIEW)
-
- //主容器
- ,reElem = that.elem = $(laytpl(TPL_MAIN).render({
- VIEW_CLASS: ELEM_VIEW
- ,data: options
- ,index: that.index //索引
- }));
-
- options.index = that.index;
-
- //生成替代元素
- hasRender[0] && hasRender.remove(); //如果已经渲染,则Rerender
- othis.after(reElem);
-
- //各级容器
- that.layHeader = reElem.find(ELEM_HEADER);
- that.layMain = reElem.find(ELEM_MAIN);
- that.layBody = reElem.find(ELEM_BODY);
- that.layFixed = reElem.find(ELEM_FIXED);
- that.layFixLeft = reElem.find(ELEM_FIXL);
- that.layFixRight = reElem.find(ELEM_FIXR);
- that.layTool = reElem.find(ELEM_TOOL);
- that.layPage = reElem.find(ELEM_PAGE);
-
- that.layTool.html(
- laytpl($(options.toolbar).html()||'').render(options)
- );
-
- if(options.height) that.fullSize(); //设置body区域高度
-
- //如果多级表头,则填补表头高度
- if(options.cols.length > 1){
- var th = that.layFixed.find(ELEM_HEADER).find('th');
- th.height(that.layHeader.height() - 1 - parseFloat(th.css('padding-top')) - parseFloat(th.css('padding-bottom')));
- }
-
- //请求数据
- that.pullData(that.page);
- that.events();
- };
-
- //根据列类型,定制化参数
- Class.prototype.initOpts = function(item){
- var that = this,
- options = that.config
- ,initWidth = {
- checkbox: 48
- ,space: 15
- ,numbers: 40
- };
-
- //让 type 参数兼容旧版本
- if(item.checkbox) item.type = "checkbox";
- if(item.space) item.type = "space";
- if(!item.type) item.type = "normal";
-
- if(item.type !== "normal"){
- item.unresize = true;
- item.width = item.width || initWidth[item.type];
- }
- };
-
- //动态分配列宽高
- Class.prototype.setArea = function(){
- var that = this,
- options = that.config
- ,colNums = 0 //列个数
- ,autoColNums = 0 //自动列宽的列个数
- ,autoWidth = 0 //自动列分配的宽度
- ,countWidth = 0 //所有列总宽度和
- ,cntrWidth = options.width || function(){ //获取容器宽度
- //如果父元素宽度为0(一般为隐藏元素),则继续查找上层元素,直到找到真实宽度为止
- var getWidth = function(parent){
- var width, isNone;
- parent = parent || options.elem.parent()
- width = parent.width();
- try {
- isNone = parent.css('display') === 'none';
- } catch(e){}
- if(parent[0] && (!width || isNone)) return getWidth(parent.parent());
- return width;
- };
- return getWidth();
- }();
-
- //统计列个数
- that.eachCols(function(){
- colNums++;
- });
-
- //减去边框差
- cntrWidth = cntrWidth - function(){
- return (options.skin === 'line' || options.skin === 'nob') ? 2 : colNums + 1;
- }();
-
- //遍历所有列
- layui.each(options.cols, function(i1, item1){
- layui.each(item1, function(i2, item2){
- var width;
-
- if(!item2){
- item1.splice(i2, 1);
- return;
- }
-
- that.initOpts(item2);
- width = item2.width || 0;
-
- if(item2.colspan > 1) return;
-
- if(/\d+%$/.test(width)){
- item2.width = width = Math.floor((parseFloat(width) / 100) * cntrWidth);
- } else if(!width){ //列宽未填写
- item2.width = width = 0;
- autoColNums++;
- }
-
- countWidth = countWidth + width;
- });
- });
-
- that.autoColNums = autoColNums; //记录自动列数
-
- //如果未填充满,则将剩余宽度平分。否则,给未设定宽度的列赋值一个默认宽
- (cntrWidth > countWidth && autoColNums) && (
- autoWidth = (cntrWidth - countWidth) / autoColNums
- );
-
- layui.each(options.cols, function(i1, item1){
- layui.each(item1, function(i2, item2){
- var minWidth = item2.minWidth || options.cellMinWidth;
- if(item2.colspan > 1) return;
- if(item2.width === 0){
- item2.width = Math.floor(autoWidth >= minWidth ? autoWidth : minWidth); //不能低于设定的最小宽度
- }
- });
- });
-
- //高度铺满:full-差距值
- if(options.height && /^full-\d+$/.test(options.height)){
- that.fullHeightGap = options.height.split('-')[1];
- options.height = _WIN.height() - that.fullHeightGap;
- }
- };
-
- //表格重载
- Class.prototype.reload = function(options){
- var that = this;
- if(that.config.data && that.config.data.constructor === Array) delete that.config.data;
- that.config = $.extend({}, that.config, options);
- that.render();
- };
-
- //页码
- Class.prototype.page = 1;
-
- //获得数据
- Class.prototype.pullData = function(curr, loadIndex){
- var that = this
- ,options = that.config
- ,request = options.request
- ,response = options.response
- ,sort = function(){
- if(typeof options.initSort === 'object'){
- that.sort(options.initSort.field, options.initSort.type);
- }
- };
-
- that.startTime = new Date().getTime(); //渲染开始时间
-
- if(options.url){ //Ajax请求
- var params = {};
- params[request.pageName] = curr;
- params[request.limitName] = options.limit;
- options.where.userToken = getCookie('userToken');
- options.where.loginPCIp = returnCitySN["cip"];
- $.ajax({
- type: options.method || 'get'
- ,url: options.url
- ,data: $.extend(params, options.where)
- ,dataType: 'json'
- ,success: function(res){
- if(res[response.statusName] != response.statusCode){
- that.renderForm();
- that.layMain.html(''+ (res[response.msgName] || '返回的数据状态异常') +'
');
- } else {
- that.renderData(res, curr, res[response.countName]), sort();
- options.time = (new Date().getTime() - that.startTime) + ' ms'; //耗时(接口请求+视图渲染)
- }
- loadIndex && layer.close(loadIndex);
- typeof options.done === 'function' && options.done(res, curr, res[response.countName]);
- }
- ,error: function(XMLHttpRequest, e, m){
- var sessionstatus = XMLHttpRequest.getResponseHeader('SESSIONSTATUS');
- if (sessionstatus == "TIMEOUT") {//超时跳转
- var win = window;
- while (win != win.top){
- win = win.top;
- }
- win.location.href = reqBasePath + "/tpl/index/login.html";//XMLHttpRequest.getResponseHeader("CONTEXTPATH");
- }else if(sessionstatus == "NOAUTHPOINT"){
- that.layMain.html('您不具备该权限。
');
- that.renderForm();
- loadIndex && layer.close(loadIndex);
- }else{
- that.layMain.html('数据接口请求异常
');
- that.renderForm();
- loadIndex && layer.close(loadIndex);
+/** layui-v2.4.5 MIT License By https://www.layui.com */ ;
+layui.define(["laytpl", "laypage", "layer", "form", "util"], function(e) {
+ "use strict";
+ var t = layui.$,
+ i = layui.laytpl,
+ a = layui.laypage,
+ l = layui.layer,
+ n = layui.form,
+ o = (layui.util,
+ layui.hint()),
+ r = layui.device(),
+ d = {
+ config: {
+ checkName: "LAY_CHECKED",
+ indexName: "LAY_TABLE_INDEX"
+ },
+ cache: {},
+ index: layui.table ? layui.table.index + 1e4 : 0,
+ set: function(e) {
+ var i = this;
+ return i.config = t.extend({}, i.config, e),
+ i
+ },
+ on: function(e, t) {
+ return layui.onevent.call(this, u, e, t)
}
- }
- });
- } else if(options.data && options.data.constructor === Array){ //已知数据
- var res = {}
- ,startLimit = curr*options.limit - options.limit
-
- res[response.dataName] = options.data.concat().splice(startLimit, options.limit);
- res[response.countName] = options.data.length;
-
- that.renderData(res, curr, options.data.length), sort();
- typeof options.done === 'function' && options.done(res, curr, res[response.countName]);
- }
- };
-
- //遍历表头
- Class.prototype.eachCols = function(callback){
- var cols = $.extend(true, [], this.config.cols)
- ,arrs = [], index = 0;
-
- //重新整理表头结构
- layui.each(cols, function(i1, item1){
- layui.each(item1, function(i2, item2){
- //如果是组合列,则捕获对应的子列
- if(item2.colspan > 1){
- var childIndex = 0;
- index++
- item2.CHILD_COLS = [];
- layui.each(cols[i1 + 1], function(i22, item22){
- if(item22.PARENT_COL || childIndex == item2.colspan) return;
- item22.PARENT_COL = index;
- item2.CHILD_COLS.push(item22);
- childIndex = childIndex + (item22.colspan > 1 ? item22.colspan : 1);
- });
- }
- if(item2.PARENT_COL) return; //如果是子列,则不进行追加,因为已经存储在父列中
- arrs.push(item2)
- });
- });
-
- //重新遍历列,如果有子列,则进入递归
- var eachArrs = function(obj){
- layui.each(obj || arrs, function(i, item){
- if(item.CHILD_COLS) return eachArrs(item.CHILD_COLS);
- callback(i, item);
- });
- };
-
- eachArrs();
- };
-
- //数据渲染
- Class.prototype.renderData = function(res, curr, count, sort){
- var that = this
- ,options = that.config
- ,data = res[options.response.dataName] || []
- ,trs = []
- ,trs_fixed = []
- ,trs_fixed_r = []
-
- //渲染视图
- ,render = function(){ //后续性能提升的重点
- if(!sort && that.sortKey){
- return that.sort(that.sortKey.field, that.sortKey.sort, true);
- }
- layui.each(data, function(i1, item1){
- var tds = [], tds_fixed = [], tds_fixed_r = []
- ,numbers = i1 + options.limit*(curr - 1) + 1; //序号
-
- if(item1.length === 0) return;
- if(!sort){
- item1[table.config.indexName] = i1;
- }
-
- that.eachCols(function(i3, item3){
- var field = item3.field || i3, content = item1[field]
- ,cell = that.getColElem(that.layHeader, field);
-
- if(content === undefined || content === null) content = '';
- if(item3.colspan > 1) return;
-
- //td内容
- var td = [''
- ,' ' + function(){
- var tplData = $.extend(true, {
- LAY_INDEX: numbers
- }, item1);
-
- //渲染复选框列视图
- if(item3.type === 'checkbox'){
- return '';
- } else if(item3.type === 'numbers'){ //渲染序号
- return numbers;
- }
-
- //解析工具列模板
- if(item3.toolbar){
- return laytpl($(item3.toolbar).html()||'').render(tplData);
- }
- return item3.templet ? function(){
- return typeof item3.templet === 'function'
- ? item3.templet(tplData)
- : laytpl($(item3.templet).html() || String(content)).render(tplData)
- }() : content;
- }()
- ,' | '].join('');
-
- tds.push(td);
- if(item3.fixed && item3.fixed !== 'right') tds_fixed.push(td);
- if(item3.fixed === 'right') tds_fixed_r.push(td);
- });
-
- trs.push(''+ tds.join('') + '
');
- trs_fixed.push(''+ tds_fixed.join('') + '
');
- trs_fixed_r.push(''+ tds_fixed_r.join('') + '
');
- });
-
- //if(data.length === 0) return;
-
- that.layBody.scrollTop(0);
- that.layMain.find('.'+ NONE).remove();
- that.layMain.find('tbody').html(trs.join(''));
- that.layFixLeft.find('tbody').html(trs_fixed.join(''));
- that.layFixRight.find('tbody').html(trs_fixed_r.join(''));
-
- that.renderForm();
- that.syncCheckAll();
- that.haveInit ? that.scrollPatch() : setTimeout(function(){
- that.scrollPatch();
- }, 50);
- that.haveInit = true;
- layer.close(that.tipsIndex);
- };
-
- that.key = options.id || options.index;
- table.cache[that.key] = data; //记录数据
-
- //显示隐藏分页栏
- that.layPage[data.length === 0 && curr == 1 ? 'addClass' : 'removeClass'](HIDE);
-
- //排序
- if(sort){
- return render();
- }
-
- if(data.length === 0){
- that.renderForm();
- that.layFixed.remove();
- that.layMain.find('tbody').html('');
- that.layMain.find('.'+ NONE).remove();
- return that.layMain.append(''+ options.text.none +'
');
- }
-
- render();
-
- //同步分页状态
- if(options.page){
- options.page = $.extend({
- elem: 'layui-table-page' + options.index
- ,count: count
- ,limit: options.limit
- ,limits: options.limits || [10,20,30,40,50,60,70,80,90]
- ,groups: 3
- ,layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
- ,prev: ''
- ,next: ''
- ,jump: function(obj, first){
- if(!first){
- //分页本身并非需要做以下更新,下面参数的同步,主要是因为其它处理统一用到了它们
- //而并非用的是 options.page 中的参数(以确保分页未开启的情况仍能正常使用)
- that.page = obj.curr; //更新页码
- options.limit = obj.limit; //更新每页条数
-
- that.pullData(obj.curr, that.loading());
- }
- }
- }, options.page);
- options.page.count = count; //更新总条数
- laypage.render(options.page);
- }
- };
-
- //找到对应的列元素
- Class.prototype.getColElem = function(parent, field){
- var that = this
- ,options = that.config;
- return parent.eq(0).find('.laytable-cell-'+ (options.index + '-' + field) + ':eq(0)');
- };
-
- //渲染表单
- Class.prototype.renderForm = function(type){
- form.render(type, 'LAY-table-'+ this.index);
- }
-
- //数据排序
- Class.prototype.sort = function(th, type, pull, formEvent){
- var that = this
- ,field
- ,res = {}
- ,options = that.config
- ,filter = options.elem.attr('lay-filter')
- ,data = table.cache[that.key], thisData;
-
- //字段匹配
- if(typeof th === 'string'){
- that.layHeader.find('th').each(function(i, item){
- var othis = $(this)
- ,_field = othis.data('field');
- if(_field === th){
- th = othis;
- field = _field;
- return false;
- }
- });
- }
-
- try {
- var field = field || th.data('field');
-
- //如果欲执行的排序已在状态中,则不执行渲染
- if(that.sortKey && !pull){
- if(field === that.sortKey.field && type === that.sortKey.sort){
- return;
- }
- }
-
- var elemSort = that.layHeader.find('th .laytable-cell-'+ options.index +'-'+ field).find(ELEM_SORT);
- that.layHeader.find('th').find(ELEM_SORT).removeAttr('lay-sort'); //清除其它标题排序状态
- elemSort.attr('lay-sort', type || null);
- that.layFixed.find('th')
- } catch(e){
- return hint.error('Table modules: Did not match to field');
- }
-
- //记录排序索引和类型
- that.sortKey = {
- field: field
- ,sort: type
- };
-
- if(type === 'asc'){ //升序
- thisData = layui.sort(data, field);
- } else if(type === 'desc'){ //降序
- thisData = layui.sort(data, field, true);
- } else { //清除排序
- thisData = layui.sort(data, table.config.indexName);
- delete that.sortKey;
- }
-
- res[options.response.dataName] = thisData;
- that.renderData(res, that.page, that.count, true);
-
- if(formEvent){
- layui.event.call(th, MOD_NAME, 'sort('+ filter +')', {
- field: field
- ,type: type
- });
- }
- };
-
- //请求loading
- Class.prototype.loading = function(){
- var that = this
- ,options = that.config;
- if(options.loading && options.url){
- return layer.msg('数据请求中', {
- icon: 16
- ,offset: [
- that.elem.offset().top + that.elem.height()/2 - 35 - _WIN.scrollTop() + 'px'
- ,that.elem.offset().left + that.elem.width()/2 - 90 - _WIN.scrollLeft() + 'px'
- ]
- ,time: -1
- ,anim: -1
- ,fixed: false
- });
- }
- };
-
- //同步选中值状态
- Class.prototype.setCheckData = function(index, checked){
- var that = this
- ,options = that.config
- ,thisData = table.cache[that.key];
- if(!thisData[index]) return;
- if(thisData[index].constructor === Array) return;
- thisData[index][options.checkName] = checked;
- };
-
- //同步全选按钮状态
- Class.prototype.syncCheckAll = function(){
- var that = this
- ,options = that.config
- ,checkAllElem = that.layHeader.find('input[name="layTableCheckbox"]')
- ,syncColsCheck = function(checked){
- that.eachCols(function(i, item){
- if(item.type === 'checkbox'){
- item[options.checkName] = checked;
- }
- });
- return checked;
- };
-
- if(!checkAllElem[0]) return;
-
- if(table.checkStatus(that.key).isAll){
- if(!checkAllElem[0].checked){
- checkAllElem.prop('checked', true);
- that.renderForm('checkbox');
- }
- syncColsCheck(true);
- } else {
- if(checkAllElem[0].checked){
- checkAllElem.prop('checked', false);
- that.renderForm('checkbox');
- }
- syncColsCheck(false);
- }
- };
-
- //获取cssRule
- Class.prototype.getCssRule = function(field, callback){
- var that = this
- ,style = that.elem.find('style')[0]
- ,sheet = style.sheet || style.styleSheet || {}
- ,rules = sheet.cssRules || sheet.rules;
- layui.each(rules, function(i, item){
- if(item.selectorText === ('.laytable-cell-'+ that.index +'-'+ field)){
- return callback(item), true;
- }
- });
- };
-
- //铺满表格主体高度
- Class.prototype.fullSize = function(){
- var that = this
- ,options = that.config
- ,height = options.height, bodyHeight;
-
- if(that.fullHeightGap){
- height = _WIN.height() - that.fullHeightGap;
- if(height < 135) height = 135;
- that.elem.css('height', height);
- }
-
- //tbody区域高度
- bodyHeight = parseFloat(height) - parseFloat(that.layHeader.height()) - 1;
- if(options.toolbar){
- bodyHeight = bodyHeight - that.layTool.outerHeight();
- }
- if(options.page){
- bodyHeight = bodyHeight - that.layPage.outerHeight() - 1;
- }
- that.layMain.css('height', bodyHeight);
- };
-
- //获取滚动条宽度
- Class.prototype.getScrollWidth = function(elem){
- var width = 0;
- if(elem){
- width = elem.offsetWidth - elem.clientWidth;
- } else {
- elem = document.createElement('div');
- elem.style.width = '100px';
- elem.style.height = '100px';
- elem.style.overflowY = 'scroll';
-
- document.body.appendChild(elem);
- width = elem.offsetWidth - elem.clientWidth;
- document.body.removeChild(elem);
- }
- return width;
- };
-
- //滚动条补丁
- Class.prototype.scrollPatch = function(){
- var that = this
- ,layMainTable = that.layMain.children('table')
- ,scollWidth = that.layMain.width() - that.layMain.prop('clientWidth') //纵向滚动条宽度
- ,scollHeight = that.layMain.height() - that.layMain.prop('clientHeight') //横向滚动条高度
- ,getScrollWidth = that.getScrollWidth(that.layMain[0]) //获取主容器滚动条宽度,如果有的话
- ,outWidth = layMainTable.outerWidth() - that.layMain.width(); //表格内容器的超出宽度
-
- //如果存在自动列宽,则要保证绝对填充满,并且不能出现横向滚动条
- if(that.autoColNums && outWidth < 5 && !that.scrollPatchWStatus){
- var th = that.layHeader.eq(0).find('thead th:last-child')
- ,field = th.data('field');
- that.getCssRule(field, function(item){
- var width = item.style.width || th.outerWidth();
- item.style.width = (parseFloat(width) - getScrollWidth - outWidth) + 'px';
-
- //二次校验,如果仍然出现横向滚动条
- if(that.layMain.height() - that.layMain.prop('clientHeight') > 0){
- item.style.width = parseFloat(item.style.width) - 1 + 'px';
- }
-
- that.scrollPatchWStatus = true;
- });
- }
-
- if(scollWidth && scollHeight){
- if(!that.elem.find('.layui-table-patch')[0]){
- var patchElem = $(' | '); //补丁元素
- patchElem.find('div').css({
- width: scollWidth
- });
- that.layHeader.eq(0).find('thead tr').append(patchElem)
- }
- } else {
- that.layHeader.eq(0).find('.layui-table-patch').remove();
- }
-
- //固定列区域高度
- var mainHeight = that.layMain.height()
- ,fixHeight = mainHeight - scollHeight;
- that.layFixed.find(ELEM_BODY).css('height', layMainTable.height() > fixHeight ? fixHeight : 'auto');
-
- //表格宽度小于容器宽度时,隐藏固定列
- that.layFixRight[outWidth > 0 ? 'removeClass' : 'addClass'](HIDE);
-
- //操作栏
- that.layFixRight.css('right', scollWidth - 1);
- };
-
- //事件处理
- Class.prototype.events = function(){
- var that = this
- ,options = that.config
- ,_BODY = $('body')
- ,dict = {}
- ,th = that.layHeader.find('th')
- ,resizing
- ,ELEM_CELL = '.layui-table-cell'
- ,filter = options.elem.attr('lay-filter');
-
- //拖拽调整宽度
- th.on('mousemove', function(e){
- var othis = $(this)
- ,oLeft = othis.offset().left
- ,pLeft = e.clientX - oLeft;
- if(othis.attr('colspan') > 1 || othis.data('unresize') || dict.resizeStart){
- return;
- }
- dict.allowResize = othis.width() - pLeft <= 10; //是否处于拖拽允许区域
- _BODY.css('cursor', (dict.allowResize ? 'col-resize' : ''));
- }).on('mouseleave', function(){
- var othis = $(this);
- if(dict.resizeStart) return;
- _BODY.css('cursor', '');
- }).on('mousedown', function(e){
- var othis = $(this);
- if(dict.allowResize){
- var field = othis.data('field');
- e.preventDefault();
- dict.resizeStart = true; //开始拖拽
- dict.offset = [e.clientX, e.clientY]; //记录初始坐标
-
- that.getCssRule(field, function(item){
- var width = item.style.width || othis.outerWidth();
- dict.rule = item;
- dict.ruleWidth = parseFloat(width);
- dict.minWidth = othis.data('minwidth') || options.cellMinWidth;
- });
- }
- });
- //拖拽中
- _DOC.on('mousemove', function(e){
- if(dict.resizeStart){
- e.preventDefault();
- if(dict.rule){
- var setWidth = dict.ruleWidth + e.clientX - dict.offset[0];
- if(setWidth < dict.minWidth) setWidth = dict.minWidth;
- dict.rule.style.width = setWidth + 'px';
- layer.close(that.tipsIndex);
- }
- resizing = 1
- }
- }).on('mouseup', function(e){
- if(dict.resizeStart){
- dict = {};
- _BODY.css('cursor', '');
- that.scrollPatch();
- }
- if(resizing === 2){
- resizing = null;
- }
- });
-
- //排序
- th.on('click', function(){
- var othis = $(this)
- ,elemSort = othis.find(ELEM_SORT)
- ,nowType = elemSort.attr('lay-sort')
- ,type;
-
- if(!elemSort[0] || resizing === 1) return resizing = 2;
-
- if(nowType === 'asc'){
- type = 'desc';
- } else if(nowType === 'desc'){
- type = null;
- } else {
- type = 'asc';
- }
- that.sort(othis, type, null, true);
- }).find(ELEM_SORT+' .layui-edge ').on('click', function(e){
- var othis = $(this)
- ,index = othis.index()
- ,field = othis.parents('th').eq(0).data('field')
- layui.stope(e);
- if(index === 0){
- that.sort(field, 'asc', null, true);
- } else {
- that.sort(field, 'desc', null, true);
- }
- });
-
- //复选框选择
- that.elem.on('click', 'input[name="layTableCheckbox"]+', function(){
- var checkbox = $(this).prev()
- ,childs = that.layBody.find('input[name="layTableCheckbox"]')
- ,index = checkbox.parents('tr').eq(0).data('index')
- ,checked = checkbox[0].checked
- ,isAll = checkbox.attr('lay-filter') === 'layTableAllChoose';
-
- //全选
- if(isAll){
- childs.each(function(i, item){
- item.checked = checked;
- that.setCheckData(i, checked);
- });
- that.syncCheckAll();
- that.renderForm('checkbox');
- } else {
- that.setCheckData(index, checked);
- that.syncCheckAll();
- }
- layui.event.call(this, MOD_NAME, 'checkbox('+ filter +')', {
- checked: checked
- ,data: table.cache[that.key] ? (table.cache[that.key][index] || {}) : {}
- ,type: isAll ? 'all' : 'one'
- });
- });
-
- //行事件
- that.layBody.on('mouseenter', 'tr', function(){
- var othis = $(this)
- ,index = othis.index();
- that.layBody.find('tr:eq('+ index +')').addClass(ELEM_HOVER)
- }).on('mouseleave', 'tr', function(){
- var othis = $(this)
- ,index = othis.index();
- that.layBody.find('tr:eq('+ index +')').removeClass(ELEM_HOVER)
- });
-
- //单元格编辑
- that.layBody.on('change', '.'+ELEM_EDIT, function(){
- var othis = $(this)
- ,value = this.value
- ,field = othis.parent().data('field')
- ,index = othis.parents('tr').eq(0).data('index')
- ,data = table.cache[that.key][index];
-
- data[field] = value; //更新缓存中的值
-
- layui.event.call(this, MOD_NAME, 'edit('+ filter +')', {
- value: value
- ,data: data
- ,field: field
- });
- }).on('blur', '.'+ELEM_EDIT, function(){
- var templet
- ,othis = $(this)
- ,field = othis.parent().data('field')
- ,index = othis.parents('tr').eq(0).data('index')
- ,data = table.cache[that.key][index];
- that.eachCols(function(i, item){
- if(item.field == field && item.templet){
- templet = item.templet;
- }
- });
- othis.siblings(ELEM_CELL).html(
- templet ? laytpl($(templet).html() || this.value).render(data) : this.value
- );
- othis.parent().data('content', this.value);
- othis.remove();
- });
-
- //单元格事件
- that.layBody.on('click', 'td', function(){
- var othis = $(this)
- ,field = othis.data('field')
- ,editType = othis.data('edit')
- ,elemCell = othis.children(ELEM_CELL);
-
- layer.close(that.tipsIndex);
- if(othis.data('off')) return;
-
- //显示编辑表单
- if(editType){
- if(editType === 'select') { //选择框
- //var select = $('');
- //othis.find('.'+ELEM_EDIT)[0] || othis.append(select);
- } else { //输入框
- var input = $('');
- input[0].value = othis.data('content') || elemCell.text();
- othis.find('.'+ELEM_EDIT)[0] || othis.append(input);
- input.focus();
- }
- return;
- }
-
- //如果出现省略,则可查看更多
- if(elemCell.find('.layui-form-switch,.layui-form-checkbox')[0]) return; //限制不出现更多(暂时)
-
- if(Math.round(elemCell.prop('scrollWidth')) > Math.round(elemCell.outerWidth())){
- that.tipsIndex = layer.tips([
- ''
- ,elemCell.html()
- ,'
'
- ,'ဆ'
- ].join(''), elemCell[0], {
- tips: [3, '']
- ,time: -1
- ,anim: -1
- ,maxWidth: (device.ios || device.android) ? 300 : 600
- ,isOutAnim: false
- ,skin: 'layui-table-tips'
- ,success: function(layero, index){
- layero.find('.layui-table-tips-c').on('click', function(){
- layer.close(index);
- });
- }
- });
- }
- });
-
- //工具条操作事件
- that.layBody.on('click', '*[lay-event]', function(){
- var othis = $(this)
- ,index = othis.parents('tr').eq(0).data('index')
- ,tr = that.layBody.find('tr[data-index="'+ index +'"]')
- ,ELEM_CLICK = 'layui-table-click'
- ,data = table.cache[that.key][index];
-
- layui.event.call(this, MOD_NAME, 'tool('+ filter +')', {
- data: table.clearCacheKey(data)
- ,event: othis.attr('lay-event')
- ,tr: tr
- ,del: function(){
- table.cache[that.key][index] = [];
- tr.remove();
- that.scrollPatch();
- }
- ,update: function(fields){
- fields = fields || {};
- layui.each(fields, function(key, value){
- if(key in data){
- var templet, td = tr.children('td[data-field="'+ key +'"]');
- data[key] = value;
- that.eachCols(function(i, item2){
- if(item2.field == key && item2.templet){
- templet = item2.templet;
- }
- });
- td.children(ELEM_CELL).html(
- templet ? laytpl($(templet).html() || value).render(data) : value
- );
- td.data('content', value);
- }
- });
- }
- });
- tr.addClass(ELEM_CLICK).siblings('tr').removeClass(ELEM_CLICK);
- });
-
- //同步滚动条
- that.layMain.on('scroll', function(){
- var othis = $(this)
- ,scrollLeft = othis.scrollLeft()
- ,scrollTop = othis.scrollTop();
-
- that.layHeader.scrollLeft(scrollLeft);
- that.layFixed.find(ELEM_BODY).scrollTop(scrollTop);
-
- layer.close(that.tipsIndex);
- });
-
- _WIN.on('resize', function(){ //自适应
- that.fullSize();
- that.scrollPatch();
- });
- };
-
- //初始化
- table.init = function(filter, settings){
- settings = settings || {};
- var that = this
- ,elemTable = filter ? $('table[lay-filter="'+ filter +'"]') : $(ELEM + '[lay-data]')
- ,errorTips = 'Table element property lay-data configuration item has a syntax error: ';
-
- //遍历数据表格
- elemTable.each(function(){
- var othis = $(this), tableData = othis.attr('lay-data');
-
- try{
- tableData = new Function('return '+ tableData)();
- } catch(e){
- hint.error(errorTips + tableData)
- }
-
- var cols = [], options = $.extend({
- elem: this
- ,cols: []
- ,data: []
- ,skin: othis.attr('lay-skin') //风格
- ,size: othis.attr('lay-size') //尺寸
- ,even: typeof othis.attr('lay-even') === 'string' //偶数行背景
- }, table.config, settings, tableData);
-
- filter && othis.hide();
-
- //获取表头数据
- othis.find('thead>tr').each(function(i){
- options.cols[i] = [];
- $(this).children().each(function(ii){
- var th = $(this), itemData = th.attr('lay-data');
-
- try{
- itemData = new Function('return '+ itemData)();
- } catch(e){
- return hint.error(errorTips + itemData)
- }
-
- var row = $.extend({
- title: th.text()
- ,colspan: th.attr('colspan') || 0 //列单元格
- ,rowspan: th.attr('rowspan') || 0 //行单元格
- }, itemData);
-
- if(row.colspan < 2) cols.push(row);
- options.cols[i].push(row);
- });
- });
-
- //获取表体数据
- othis.find('tbody>tr').each(function(i1){
- var tr = $(this), row = {};
- //如果定义了字段名
- tr.children('td').each(function(i2, item2){
- var td = $(this)
- ,field = td.data('field');
- if(field){
- return row[field] = td.html();
- }
- });
- //如果未定义字段名
- layui.each(cols, function(i3, item3){
- var td = tr.children('td').eq(i3);
- row[item3.field] = td.html();
- });
- options.data[i1] = row;
- });
- table.render(options);
- });
-
- return that;
- };
-
- //表格选中状态
- table.checkStatus = function(id){
- var nums = 0
- ,invalidNum = 0
- ,arr = []
- ,data = table.cache[id] || [];
- //计算全选个数
- layui.each(data, function(i, item){
- if(item.constructor === Array){
- invalidNum++; //无效数据,或已删除的
- return;
- }
- if(item[table.config.checkName]){
- nums++;
- arr.push(table.clearCacheKey(item));
- }
- });
- return {
- data: arr //选中的数据
- ,isAll: data.length ? (nums === (data.length - invalidNum)) : false //是否全选
- };
- };
-
- //表格重载
- thisTable.config = {};
- table.reload = function(id, options){
- var config = thisTable.config[id];
- options = options || {};
- if(!config) return hint.error('The ID option was not found in the table instance');
- if(options.data && options.data.constructor === Array) delete config.data;
- return table.render($.extend(true, {}, config, options));
- };
-
- //核心入口
- table.render = function(options){
- var inst = new Class(options);
- return thisTable.call(inst);
- };
-
- //清除临时Key
- table.clearCacheKey = function(data){
- data = $.extend({}, data);
- delete data[table.config.checkName];
- delete data[table.config.indexName];
- return data;
- };
-
- //自动完成渲染
- table.init();
-
- exports(MOD_NAME, table);
-});
-
-
+ },
+ c = function() {
+ var e = this,
+ t = e.config,
+ i = t.id || t.index;
+ return i && (c.that[i] = e,
+ c.config[i] = t), {
+ reload: function(t) {
+ e.reload.call(e, t)
+ },
+ setColsWidth: function() {
+ e.setColsWidth.call(e)
+ },
+ resize: function() {
+ e.resize.call(e)
+ },
+ config: t
+ }
+ },
+ s = function(e) {
+ var t = c.config[e];
+ return t || o.error("The ID option was not found in the table instance"),
+ t || null
+ },
+ u = "table",
+ h = ".layui-table",
+ y = "layui-hide",
+ f = "layui-none",
+ p = "layui-table-view",
+ v = ".layui-table-tool",
+ m = ".layui-table-box",
+ g = ".layui-table-init",
+ b = ".layui-table-header",
+ x = ".layui-table-body",
+ k = ".layui-table-main",
+ C = ".layui-table-fixed",
+ w = ".layui-table-fixed-l",
+ T = ".layui-table-fixed-r",
+ A = ".layui-table-total",
+ L = ".layui-table-page",
+ S = ".layui-table-sort",
+ N = "layui-table-edit",
+ W = "layui-table-hover",
+ _ = function(e) {
+ var t = '{{#if(item2.colspan){}} colspan="{{item2.colspan}}"{{#} if(item2.rowspan){}} rowspan="{{item2.rowspan}}"{{#}}}';
+ return e = e || {}, ['', "", "{{# layui.each(d.data.cols, function(i1, item1){ }}", "", "{{# layui.each(item1, function(i2, item2){ }}", '{{# if(item2.fixed && item2.fixed !== "right"){ left = true; } }}', '{{# if(item2.fixed === "right"){ right = true; } }}', function() {
+ return e.fixed && "right" !== e.fixed ? '{{# if(item2.fixed && item2.fixed !== "right"){ }}' : "right" === e.fixed ? '{{# if(item2.fixed === "right"){ }}' : ""
+ }(), "{{# var isSort = !(item2.colGroup) && item2.sort; }}",
+ '', ' ', '{{# if(item2.type === "checkbox"){ }}',
+ '',
+ "{{# } else { }}", '{{item2.title||""}}', "{{# if(isSort){ }}",
+ '',
+ "{{# } }}", "{{# } }}", " ", " | ", e.fixed ? "{{# }; }}" : "", "{{# }); }}", "
", "{{# }); }}", "", "
"].join("")
+ },
+ E = ['"].join(""),
+ z = ['"].join(""),
+ H = t(window),
+ R = t(document),
+ F = function(e) {
+ var i = this;
+ i.index = ++d.index,
+ i.config = t.extend({}, i.config, d.config, e),
+ i.render()
+ };
+ F.prototype.config = {
+ limit: 10,
+ loading: !0,
+ cellMinWidth: 60,
+ defaultToolbar: ["filter", "exports", "print"],
+ autoSort: !0,
+ text: {
+ none: "无数据"
+ }
+ },
+ F.prototype.render = function() {
+ var e = this,
+ a = e.config;
+ if(a.elem = t(a.elem),
+ a.where = a.where || {},
+ a.id = a.id || a.elem.attr("id") || e.index,
+ a.request = t.extend({
+ pageName: "page",
+ limitName: "limit"
+ }, a.request),
+ a.response = t.extend({
+ statusName: 'returnCode',
+ statusCode: 0,
+ msgName: 'returnMessage',
+ dataName: 'rows',
+ countName: 'total'
+ }, a.response),
+ "object" == typeof a.page && (a.limit = a.page.limit || a.limit,
+ a.limits = a.page.limits || a.limits,
+ e.page = a.page.curr = a.page.curr || 1,
+ delete a.page.elem,
+ delete a.page.jump), !a.elem[0])
+ return e;
+ a.height && /^full-\d+$/.test(a.height) && (e.fullHeightGap = a.height.split("-")[1],
+ a.height = H.height() - e.fullHeightGap),
+ e.setInit();
+ var l = a.elem,
+ n = l.next("." + p),
+ o = e.elem = t(i(z).render({
+ VIEW_CLASS: p,
+ data: a,
+ index: e.index
+ }));
+ if(a.index = e.index,
+ n[0] && n.remove(),
+ l.after(o),
+ e.layTool = o.find(v),
+ e.layBox = o.find(m),
+ e.layHeader = o.find(b),
+ e.layMain = o.find(k),
+ e.layBody = o.find(x),
+ e.layFixed = o.find(C),
+ e.layFixLeft = o.find(w),
+ e.layFixRight = o.find(T),
+ e.layTotal = o.find(A),
+ e.layPage = o.find(L),
+ e.renderToolbar(),
+ e.fullSize(),
+ a.cols.length > 1) {
+ var r = e.layFixed.find(b).find("th");
+ r.height(e.layHeader.height() - 1 - parseFloat(r.css("padding-top")) - parseFloat(r.css("padding-bottom")))
+ }
+ e.pullData(e.page),
+ e.events()
+ },
+ F.prototype.initOpts = function(e) {
+ var t = this,
+ i = (t.config, {
+ checkbox: 48,
+ radio: 48,
+ space: 15,
+ numbers: 40
+ });
+ e.checkbox && (e.type = "checkbox"),
+ e.space && (e.type = "space"),
+ e.type || (e.type = "normal"),
+ "normal" !== e.type && (e.unresize = !0,
+ e.width = e.width || i[e.type])
+ },
+ F.prototype.setInit = function(e) {
+ var t = this,
+ i = t.config;
+ return i.clientWidth = i.width || function() {
+ var e = function(t) {
+ var a, l;
+ t = t || i.elem.parent(),
+ a = t.width();
+ try {
+ l = "none" === t.css("display")
+ } catch(n) {}
+ return !t[0] || a && !l ? a : e(t.parent())
+ };
+ return e()
+ }(),
+ "width" === e ? i.clientWidth : void layui.each(i.cols, function(e, a) {
+ layui.each(a, function(l, n) {
+ if(!n)
+ return void a.splice(l, 1);
+ if(n.key = e + "-" + l,
+ n.hide = n.hide || !1,
+ n.colGroup || n.colspan > 1) {
+ var o = 0;
+ layui.each(i.cols[e + 1], function(t, i) {
+ i.HAS_PARENT || o > 1 && o == n.colspan || (i.HAS_PARENT = !0,
+ i.parentKey = e + "-" + l,
+ o += parseInt(i.colspan > 1 ? i.colspan : 1))
+ }),
+ n.colGroup = !0
+ }
+ t.initOpts(n)
+ })
+ })
+ },
+ F.prototype.renderToolbar = function() {
+ var e = this,
+ a = e.config,
+ l = ['
', '
', '
'].join(""),
+ n = e.layTool.find(".layui-table-tool-temp");
+ if("default" === a.toolbar)
+ n.html(l);
+ else if("string" == typeof a.toolbar) {
+ var o = t(a.toolbar).html() || "";
+ o && n.html(i(o).render(a))
+ }
+ var r = {
+ filter: {
+ title: "筛选列",
+ layEvent: "LAYTABLE_COLS",
+ icon: "layui-icon-cols"
+ },
+ exports: {
+ title: "导出",
+ layEvent: "LAYTABLE_EXPORT",
+ icon: "layui-icon-export"
+ },
+ print: {
+ title: "打印",
+ layEvent: "LAYTABLE_PRINT",
+ icon: "layui-icon-print"
+ }
+ },
+ d = [];
+ "object" == typeof a.defaultToolbar && layui.each(a.defaultToolbar, function(e, t) {
+ var i = r[t];
+ i && d.push('
')
+ }),
+ e.layTool.find(".layui-table-tool-self").html(d.join(""))
+ },
+ F.prototype.setParentCol = function(e, t) {
+ var i = this,
+ a = i.config,
+ l = i.layHeader.find('th[data-key="' + a.index + "-" + t + '"]'),
+ n = parseInt(l.attr("colspan")) || 0;
+ if(l[0]) {
+ var o = t.split("-"),
+ r = a.cols[o[0]][o[1]];
+ e ? n-- : n++,
+ l.attr("colspan", n),
+ l[n < 1 ? "addClass" : "removeClass"](y),
+ r.colspan = n,
+ r.hide = n < 1;
+ var d = l.data("parentkey");
+ d && i.setParentCol(e, d)
+ }
+ },
+ F.prototype.setColsPatch = function() {
+ var e = this,
+ t = e.config;
+ layui.each(t.cols, function(t, i) {
+ layui.each(i, function(t, i) {
+ i.hide && e.setParentCol(i.hide, i.parentKey)
+ })
+ })
+ },
+ F.prototype.setColsWidth = function() {
+ var e = this,
+ t = e.config,
+ i = 0,
+ a = 0,
+ l = 0,
+ n = 0,
+ o = e.setInit("width");
+ e.eachCols(function(e, t) {
+ t.hide || i++
+ }),
+ o = o - function() {
+ return "line" === t.skin || "nob" === t.skin ? 2 : i + 1
+ }() - e.getScrollWidth(e.layMain[0]) - 1;
+ var r = function(e) {
+ layui.each(t.cols, function(i, r) {
+ layui.each(r, function(i, d) {
+ var c = 0,
+ s = d.minWidth || t.cellMinWidth;
+ return d ? void(d.colGroup || d.hide || (e ? l && l < s && (a--,
+ c = s) : (c = d.width || 0,
+ /\d+%$/.test(c) ? (c = Math.floor(parseFloat(c) / 100 * o),
+ c < s && (c = s)) : c || (d.width = c = 0,
+ a++)),
+ d.hide && (c = 0),
+ n += c)) : void r.splice(i, 1)
+ })
+ }),
+ o > n && a && (l = (o - n) / a)
+ };
+ r(),
+ r(!0),
+ e.autoColNums = a,
+ e.eachCols(function(i, a) {
+ var n = a.minWidth || t.cellMinWidth;
+ a.colGroup || a.hide || (0 === a.width ? e.getCssRule(t.index + "-" + a.key, function(e) {
+ e.style.width = Math.floor(l >= n ? l : n) + "px"
+ }) : /\d+%$/.test(a.width) && e.getCssRule(t.index + "-" + a.key, function(e) {
+ e.style.width = Math.floor(parseFloat(a.width) / 100 * o) + "px"
+ }))
+ });
+ var d = e.layMain.width() - e.getScrollWidth(e.layMain[0]) - e.layMain.children("table").outerWidth();
+ if(e.autoColNums && d >= -i && d <= i) {
+ var c = function(t) {
+ var i;
+ return t = t || e.layHeader.eq(0).find("thead th:last-child"),
+ i = t.data("field"), !i && t.prev()[0] ? c(t.prev()) : t
+ },
+ s = c(),
+ u = s.data("key");
+ e.getCssRule(u, function(t) {
+ var i = t.style.width || s.outerWidth();
+ t.style.width = parseFloat(i) + d + "px",
+ e.layMain.height() - e.layMain.prop("clientHeight") > 0 && (t.style.width = parseFloat(t.style.width) - 1 + "px")
+ })
+ }
+ e.loading(!0)
+ },
+ F.prototype.resize = function() {
+ var e = this;
+ e.fullSize(),
+ e.setColsWidth(),
+ e.scrollPatch()
+ },
+ F.prototype.reload = function(e) {
+ var i = this;
+ i.config.data && i.config.data.constructor === Array && delete i.config.data,
+ i.config = t.extend({}, i.config, e),
+ i.render()
+ },
+ F.prototype.page = 1,
+ F.prototype.pullData = function(e) {
+ var i = this,
+ a = i.config,
+ l = a.request,
+ n = a.response,
+ o = function() {
+ "object" == typeof a.initSort && i.sort(a.initSort.field, a.initSort.type)
+ };
+ if(i.startTime = (new Date).getTime(),
+ a.url) {
+ var r = {};
+ r[l.pageName] = e,
+ r[l.limitName] = a.limit;
+ a.where.userToken = getCookie('userToken');
+ a.where.loginPCIp = returnCitySN["cip"];
+ var d = t.extend(r, a.where);
+ a.contentType && 0 == a.contentType.indexOf("application/json") && (d = JSON.stringify(d)),
+ t.ajax({
+ type: a.method || "get",
+ url: a.url,
+ contentType: a.contentType,
+ data: d,
+ dataType: "json",
+ headers: a.headers || {},
+ success: function(t) {
+ //移除请求遮罩层
+ $("body").find(".mask-req-str").remove();
+ "function" == typeof a.parseData && (t = a.parseData(t) || t),
+ t[n.statusName] != n.statusCode ? (i.renderForm(),
+ i.layMain.html('' + (t[n.msgName] || "返回的数据不符合规范,正确的成功状态码 (" + n.statusName + ") 应为:" + n.statusCode) + "
")) : (i.renderData(t, e, t[n.countName]),
+ o(),
+ a.time = (new Date).getTime() - i.startTime + " ms"),
+ i.setColsWidth(),
+ "function" == typeof a.done && a.done(t, e, t[n.countName])
+ },
+ error: function(XMLHttpRequest, e, t) {
+ //移除请求遮罩层
+ $("body").find(".mask-req-str").remove();
+ var sessionstatus = XMLHttpRequest.getResponseHeader('SESSIONSTATUS');
+ if(sessionstatus == "TIMEOUT") { //超时跳转
+ var win = window;
+ while(win != win.top) {
+ win = win.top;
+ }
+ win.location.href = reqBasePath + "/tpl/index/login.html"; //XMLHttpRequest.getResponseHeader("CONTEXTPATH");
+ } else if(sessionstatus == "NOAUTHPOINT") {
+ i.layMain.html('您不具备该权限。
'),
+ i.renderForm(),
+ i.setColsWidth();
+ } else {
+ i.layMain.html('数据接口请求异常:' + t + "
"),
+ i.renderForm(),
+ i.setColsWidth();
+ }
+ }
+ })
+ } else if(a.data && a.data.constructor === Array) {
+ var c = {},
+ s = e * a.limit - a.limit;
+ c[n.dataName] = a.data.concat().splice(s, a.limit),
+ c[n.countName] = a.data.length,
+ i.renderData(c, e, a.data.length),
+ o(),
+ i.setColsWidth(),
+ "function" == typeof a.done && a.done(c, e, c[n.countName])
+ } else if(a.data) {
+ var c = {},
+ s = e * a.limit - a.limit;
+ c[n.dataName] = a.data.concat().splice(s, a.limit),
+ c[n.countName] = a.data.length,
+ i.renderData(c, e, a.data.length),
+ o(),
+ i.setColsWidth(),
+ "function" == typeof a.done && a.done(c, e, c[n.countName])
+ }
+ },
+ F.prototype.eachCols = function(e) {
+ var t = this;
+ return d.eachCols(null, e, t.config.cols),
+ t
+ },
+ F.prototype.renderData = function(e, n, o, r) {
+ var c = this,
+ s = c.config,
+ u = e[s.response.dataName] || [],
+ h = [],
+ p = [],
+ v = [],
+ m = function() {
+ var e;
+ return !r && c.sortKey ? c.sort(c.sortKey.field, c.sortKey.sort, !0) : (layui.each(u, function(a, l) {
+ var o = [],
+ u = [],
+ f = [],
+ m = a + s.limit * (n - 1) + 1;
+ 0 !== l.length && (r || (l[d.config.indexName] = a),
+ c.eachCols(function(n, r) {
+ var c = r.field || n,
+ h = s.index + "-" + r.key,
+ p = l[c];
+ if(void 0 !== p && null !== p || (p = ""), !r.colGroup) {
+ var v = ['', ' ' + function() {
+ var n = t.extend(!0, {
+ LAY_INDEX: m
+ }, l),
+ o = d.config.checkName;
+ switch(r.type) {
+ case "checkbox":
+ return '";
+ case "radio":
+ return n[o] && (e = a),
+ '';
+ case "numbers":
+ return m
+ }
+ return r.toolbar ? i(t(r.toolbar).html() || "").render(n) : r.templet ? function() {
+ return "function" == typeof r.templet ? r.templet(n) : i(t(r.templet).html() || String(p)).render(n)
+ }() : p
+ }(), " | "].join("");
+ o.push(v),
+ r.fixed && "right" !== r.fixed && u.push(v),
+ "right" === r.fixed && f.push(v)
+ }
+ }),
+ h.push('' + o.join("") + "
"),
+ p.push('' + u.join("") + "
"),
+ v.push('' + f.join("") + "
"))
+ }),
+ c.layBody.scrollTop(0),
+ c.layMain.find("." + f).remove(),
+ c.layMain.find("tbody").html(h.join("")),
+ c.layFixLeft.find("tbody").html(p.join("")),
+ c.layFixRight.find("tbody").html(v.join("")),
+ c.renderForm(),
+ "number" == typeof e && c.setThisRowChecked(e),
+ c.syncCheckAll(),
+ c.haveInit ? c.scrollPatch() : setTimeout(function() {
+ c.scrollPatch()
+ }, 50),
+ c.haveInit = !0,
+ l.close(c.tipsIndex),
+ s.HAS_SET_COLS_PATCH || c.setColsPatch(),
+ void(s.HAS_SET_COLS_PATCH = !0))
+ };
+ return c.key = s.id || s.index,
+ d.cache[c.key] = u,
+ c.layPage[0 == o || 0 === u.length && 1 == n ? "addClass" : "removeClass"](y),
+ r ? m() : 0 === u.length ? (c.renderForm(),
+ c.layFixed.remove(),
+ c.layMain.find("tbody").html(""),
+ c.layMain.find("." + f).remove(),
+ c.layMain.append('' + s.text.none + "
")) : (m(),
+ c.renderTotal(u),
+ void(s.page && (s.page = t.extend({
+ elem: "layui-table-page" + s.index,
+ count: o,
+ limit: s.limit,
+ limits: s.limits || [10, 20, 30, 40, 50, 60, 70, 80, 90],
+ groups: 3,
+ layout: ["prev", "page", "next", "skip", "count", "limit"],
+ prev: '',
+ next: '',
+ jump: function(e, t) {
+ t || (c.page = e.curr,
+ s.limit = e.limit,
+ c.loading(),
+ c.pullData(e.curr))
+ }
+ }, s.page),
+ s.page.count = o,
+ a.render(s.page))))
+ },
+ F.prototype.renderTotal = function(e) {
+ var t = this,
+ i = t.config,
+ a = {};
+ if(i.totalRow) {
+ layui.each(e, function(e, i) {
+ 0 !== i.length && t.eachCols(function(e, t) {
+ var l = t.field || e,
+ n = i[l];
+ t.totalRow && (a[l] = (a[l] || 0) + (parseFloat(n) || 0))
+ })
+ });
+ var l = [];
+ t.eachCols(function(e, t) {
+ var n = t.field || e,
+ o = ['', ' ' + function() {
+ var e = t.totalRowText || "";
+ return t.totalRow ? parseFloat(a[n]).toFixed(2) || e : e
+ }(), " | "].join("");
+ l.push(o)
+ }),
+ t.layTotal.find("tbody").html("" + l.join("") + "
")
+ }
+ },
+ F.prototype.getColElem = function(e, t) {
+ var i = this,
+ a = i.config;
+ return e.eq(0).find(".laytable-cell-" + (a.index + "-" + t) + ":eq(0)")
+ },
+ F.prototype.renderForm = function(e) {
+ n.render(e, "LAY-table-" + this.index)
+ },
+ F.prototype.setThisRowChecked = function(e) {
+ var t = this,
+ i = (t.config,
+ "layui-table-click"),
+ a = t.layBody.find('tr[data-index="' + e + '"]');
+ a.addClass(i).siblings("tr").removeClass(i)
+ },
+ F.prototype.sort = function(e, i, a, l) {
+ var n, r, c = this,
+ s = {},
+ h = c.config,
+ y = h.elem.attr("lay-filter"),
+ f = d.cache[c.key];
+ "string" == typeof e && c.layHeader.find("th").each(function(i, a) {
+ var l = t(this),
+ o = l.data("field");
+ if(o === e)
+ return e = l,
+ n = o, !1
+ });
+ try {
+ var n = n || e.data("field"),
+ p = e.data("key");
+ if(c.sortKey && !a && n === c.sortKey.field && i === c.sortKey.sort)
+ return;
+ var v = c.layHeader.find("th .laytable-cell-" + p).find(S);
+ c.layHeader.find("th").find(S).removeAttr("lay-sort"),
+ v.attr("lay-sort", i || null),
+ c.layFixed.find("th")
+ } catch(m) {
+ return o.error("Table modules: Did not match to field")
+ }
+ c.sortKey = {
+ field: n,
+ sort: i
+ },
+ h.autoSort && ("asc" === i ? r = layui.sort(f, n) : "desc" === i ? r = layui.sort(f, n, !0) : (r = layui.sort(f, d.config.indexName),
+ delete c.sortKey)),
+ s[h.response.dataName] = r || f,
+ c.renderData(s, c.page, c.count, !0),
+ l && layui.event.call(e, u, "sort(" + y + ")", {
+ field: n,
+ type: i
+ })
+ },
+ F.prototype.loading = function(e) {
+ var i = this,
+ a = i.config;
+ a.loading && (e ? (i.layInit && i.layInit.remove(),
+ delete i.layInit,
+ i.layBox.find(g).remove()) : (i.layInit = t(['', '', "
"].join("")),
+ i.layBox.append(i.layInit)))
+ },
+ F.prototype.setCheckData = function(e, t) {
+ var i = this,
+ a = i.config,
+ l = d.cache[i.key];
+ l[e] && l[e].constructor !== Array && (l[e][a.checkName] = t)
+ },
+ F.prototype.syncCheckAll = function() {
+ var e = this,
+ t = e.config,
+ i = e.layHeader.find('input[name="layTableCheckbox"]'),
+ a = function(i) {
+ return e.eachCols(function(e, a) {
+ "checkbox" === a.type && (a[t.checkName] = i)
+ }),
+ i
+ };
+ i[0] && (d.checkStatus(e.key).isAll ? (i[0].checked || (i.prop("checked", !0),
+ e.renderForm("checkbox")),
+ a(!0)) : (i[0].checked && (i.prop("checked", !1),
+ e.renderForm("checkbox")),
+ a(!1)))
+ },
+ F.prototype.getCssRule = function(e, t) {
+ var i = this,
+ a = i.elem.find("style")[0],
+ l = a.sheet || a.styleSheet || {},
+ n = l.cssRules || l.rules;
+ layui.each(n, function(i, a) {
+ if(a.selectorText === ".laytable-cell-" + e)
+ return t(a), !0
+ })
+ },
+ F.prototype.fullSize = function() {
+ var e, t = this,
+ i = t.config,
+ a = i.height;
+ t.fullHeightGap && (a = H.height() - t.fullHeightGap,
+ a < 135 && (a = 135),
+ t.elem.css("height", a)),
+ a && (e = parseFloat(a) - (t.layHeader.outerHeight() || 38),
+ i.toolbar && (e -= t.layTool.outerHeight() || 50),
+ i.totalRow && (e -= t.layTotal.outerHeight() || 40),
+ i.page && (e = e - (t.layPage.outerHeight() || 41) - 2),
+ t.layMain.css("height", e))
+ },
+ F.prototype.getScrollWidth = function(e) {
+ var t = 0;
+ return e ? t = e.offsetWidth - e.clientWidth : (e = document.createElement("div"),
+ e.style.width = "100px",
+ e.style.height = "100px",
+ e.style.overflowY = "scroll",
+ document.body.appendChild(e),
+ t = e.offsetWidth - e.clientWidth,
+ document.body.removeChild(e)),
+ t
+ },
+ F.prototype.scrollPatch = function() {
+ var e = this,
+ i = e.layMain.children("table"),
+ a = e.layMain.width() - e.layMain.prop("clientWidth"),
+ l = e.layMain.height() - e.layMain.prop("clientHeight"),
+ n = (e.getScrollWidth(e.layMain[0]),
+ i.outerWidth() - e.layMain.width()),
+ o = function(e) {
+ if(a && l) {
+ if(e = e.eq(0), !e.find(".layui-table-patch")[0]) {
+ var i = t(' | ');
+ i.find("div").css({
+ width: a
+ }),
+ e.find("tr").append(i)
+ }
+ } else
+ e.find(".layui-table-patch").remove()
+ };
+ o(e.layHeader),
+ o(e.layTotal);
+ var r = e.layMain.height(),
+ d = r - l;
+ e.layFixed.find(x).css("height", i.height() >= d ? d : "auto"),
+ e.layFixRight[n > 0 ? "removeClass" : "addClass"](y),
+ e.layFixRight.css("right", a - 1)
+ },
+ F.prototype.events = function() {
+ var e, a = this,
+ o = a.config,
+ c = t("body"),
+ s = {},
+ h = a.layHeader.find("th"),
+ f = ".layui-table-cell",
+ p = o.elem.attr("lay-filter");
+ a.layTool.on("click", "*[lay-event]", function(e) {
+ var i = t(this),
+ c = i.attr("lay-event"),
+ s = function(e) {
+ var l = t(e.list),
+ n = t('');
+ n.html(l),
+ o.height && n.css("max-height", o.height - (a.layTool.outerHeight() || 50)),
+ i.find(".layui-table-tool-panel")[0] || i.append(n),
+ a.renderForm(),
+ n.on("click", function(e) {
+ layui.stope(e)
+ }),
+ e.done && e.done(n, l)
+ };
+ switch(layui.stope(e),
+ R.trigger("table.tool.panel.remove"),
+ l.close(a.tipsIndex),
+ c) {
+ case "LAYTABLE_COLS":
+ s({
+ list: function() {
+ var e = [];
+ return a.eachCols(function(t, i) {
+ i.field && "normal" == i.type && e.push('')
+ }),
+ e.join("")
+ }(),
+ done: function() {
+ n.on("checkbox(LAY_TABLE_TOOL_COLS)", function(e) {
+ var i = t(e.elem),
+ l = this.checked,
+ n = i.data("key"),
+ r = i.data("parentkey");
+ layui.each(o.cols, function(e, t) {
+ layui.each(t, function(t, i) {
+ if(e + "-" + t === n) {
+ var d = i.hide;
+ i.hide = !l,
+ a.elem.find('*[data-key="' + o.index + "-" + n + '"]')[l ? "removeClass" : "addClass"](y),
+ d != i.hide && a.setParentCol(!l, r),
+ a.resize()
+ }
+ })
+ })
+ })
+ }
+ });
+ break;
+ case "LAYTABLE_EXPORT":
+ r.ie ? l.tips("导出功能不支持 IE,请用 Chrome 等高级浏览器导出", this, {
+ tips: 3
+ }) : s({
+ list: function() {
+ return ['导出到 Csv 文件', '导出到 Excel 文件'].join("")
+ }(),
+ done: function(e, i) {
+ i.on("click", function() {
+ var e = t(this).data("type");
+ d.exportFile(o.id, null, e)
+ })
+ }
+ });
+ break;
+ case "LAYTABLE_PRINT":
+ var h = window.open("打印窗口", "_blank"),
+ f = [""].join(""),
+ v = t(a.layHeader.html());
+ v.append(a.layMain.find("table").html()),
+ v.find("th.layui-table-patch").remove(),
+ v.find(".layui-table-col-special").remove(),
+ h.document.write(f + v.prop("outerHTML")),
+ h.document.close(),
+ h.print(),
+ h.close()
+ }
+ layui.event.call(this, u, "toolbar(" + p + ")", t.extend({
+ event: c,
+ config: o
+ }, {}))
+ }),
+ h.on("mousemove", function(e) {
+ var i = t(this),
+ a = i.offset().left,
+ l = e.clientX - a;
+ i.data("unresize") || s.resizeStart || (s.allowResize = i.width() - l <= 10,
+ c.css("cursor", s.allowResize ? "col-resize" : ""))
+ }).on("mouseleave", function() {
+ t(this);
+ s.resizeStart || c.css("cursor", "")
+ }).on("mousedown", function(e) {
+ var i = t(this);
+ if(s.allowResize) {
+ var l = i.data("key");
+ e.preventDefault(),
+ s.resizeStart = !0,
+ s.offset = [e.clientX, e.clientY],
+ a.getCssRule(l, function(e) {
+ var t = e.style.width || i.outerWidth();
+ s.rule = e,
+ s.ruleWidth = parseFloat(t),
+ s.minWidth = i.data("minwidth") || o.cellMinWidth
+ })
+ }
+ }),
+ R.on("mousemove", function(t) {
+ if(s.resizeStart) {
+ if(t.preventDefault(),
+ s.rule) {
+ var i = s.ruleWidth + t.clientX - s.offset[0];
+ i < s.minWidth && (i = s.minWidth),
+ s.rule.style.width = i + "px",
+ l.close(a.tipsIndex)
+ }
+ e = 1
+ }
+ }).on("mouseup", function(t) {
+ s.resizeStart && (s = {},
+ c.css("cursor", ""),
+ a.scrollPatch()),
+ 2 === e && (e = null)
+ }),
+ h.on("click", function(i) {
+ var l, n = t(this),
+ o = n.find(S),
+ r = o.attr("lay-sort");
+ return o[0] && 1 !== e ? (l = "asc" === r ? "desc" : "desc" === r ? null : "asc",
+ void a.sort(n, l, null, !0)) : e = 2
+ }).find(S + " .layui-edge ").on("click", function(e) {
+ var i = t(this),
+ l = i.index(),
+ n = i.parents("th").eq(0).data("field");
+ layui.stope(e),
+ 0 === l ? a.sort(n, "asc", null, !0) : a.sort(n, "desc", null, !0)
+ });
+ var v = function(e) {
+ var l = t(this),
+ n = l.parents("tr").eq(0).data("index"),
+ o = a.layBody.find('tr[data-index="' + n + '"]'),
+ r = d.cache[a.key][n];
+ return t.extend({
+ tr: o,
+ data: d.clearCacheKey(r),
+ del: function() {
+ d.cache[a.key][n] = [],
+ o.remove(),
+ a.scrollPatch()
+ },
+ update: function(e) {
+ e = e || {},
+ layui.each(e, function(e, l) {
+ if(e in r) {
+ var n, d = o.children('td[data-field="' + e + '"]');
+ r[e] = l,
+ a.eachCols(function(t, i) {
+ i.field == e && i.templet && (n = i.templet)
+ }),
+ d.children(f).html(function() {
+ return n ? function() {
+ return "function" == typeof n ? n(r) : i(t(n).html() || l).render(r)
+ }() : l
+ }()),
+ d.data("content", l)
+ }
+ })
+ }
+ }, e)
+ };
+ a.elem.on("click", 'input[name="layTableCheckbox"]+', function() {
+ var e = t(this).prev(),
+ i = a.layBody.find('input[name="layTableCheckbox"]'),
+ l = e.parents("tr").eq(0).data("index"),
+ n = e[0].checked,
+ o = "layTableAllChoose" === e.attr("lay-filter");
+ o ? (i.each(function(e, t) {
+ t.checked = n,
+ a.setCheckData(e, n)
+ }),
+ a.syncCheckAll(),
+ a.renderForm("checkbox")) : (a.setCheckData(l, n),
+ a.syncCheckAll()),
+ layui.event.call(e[0], u, "checkbox(" + p + ")", v.call(e[0], {
+ checked: n,
+ type: o ? "all" : "one"
+ }))
+ }),
+ a.elem.on("click", 'input[lay-type="layTableRadio"]+', function() {
+ var e = t(this).prev(),
+ i = e[0].checked,
+ l = d.cache[a.key],
+ n = e.parents("tr").eq(0).data("index");
+ layui.each(l, function(e, t) {
+ n === e ? t.LAY_CHECKED = !0 : delete t.LAY_CHECKED
+ }),
+ a.setThisRowChecked(n),
+ layui.event.call(this, u, "radio(" + p + ")", v.call(this, {
+ checked: i
+ }))
+ }),
+ a.layBody.on("mouseenter", "tr", function() {
+ var e = t(this),
+ i = e.index();
+ a.layBody.find("tr:eq(" + i + ")").addClass(W)
+ }).on("mouseleave", "tr", function() {
+ var e = t(this),
+ i = e.index();
+ a.layBody.find("tr:eq(" + i + ")").removeClass(W)
+ }).on("click", "tr", function() {
+ m.call(this, "row")
+ }).on("dblclick", "tr", function() {
+ m.call(this, "rowDouble")
+ });
+ var m = function(e) {
+ var i = t(this);
+ layui.event.call(this, u, e + "(" + p + ")", v.call(i.children("td")[0]))
+ };
+ a.layBody.on("change", "." + N, function() {
+ var e = t(this),
+ i = this.value,
+ l = e.parent().data("field"),
+ n = e.parents("tr").eq(0).data("index"),
+ o = d.cache[a.key][n];
+ o[l] = i,
+ layui.event.call(this, u, "edit(" + p + ")", v.call(this, {
+ value: i,
+ field: l
+ }))
+ }).on("blur", "." + N, function() {
+ var e, l = t(this),
+ n = l.parent().data("field"),
+ o = l.parents("tr").eq(0).data("index"),
+ r = d.cache[a.key][o];
+ a.eachCols(function(t, i) {
+ i.field == n && i.templet && (e = i.templet)
+ }),
+ l.siblings(f).html(function(a) {
+ return e ? function() {
+ return "function" == typeof e ? e(r) : i(t(e).html() || this.value).render(r)
+ }() : a
+ }(this.value)),
+ l.parent().data("content", this.value),
+ l.remove()
+ }),
+ a.layBody.on("click", "td", function(e) {
+ var i = t(this),
+ a = (i.data("field"),
+ i.data("edit")),
+ l = i.children(f);
+ if(!i.data("off") && a) {
+ var n = t('');
+ return n[0].value = i.data("content") || l.text(),
+ i.find("." + N)[0] || i.append(n),
+ n.focus(),
+ void layui.stope(e)
+ }
+ }).on("mouseenter", "td", function() {
+ b.call(this)
+ }).on("mouseleave", "td", function() {
+ b.call(this, "hide")
+ });
+ var g = "layui-table-grid-down",
+ b = function(e) {
+ var i = t(this),
+ a = i.children(f);
+ if(e)
+ i.find(".layui-table-grid-down").remove();
+ else if(a.prop("scrollWidth") > a.outerWidth()) {
+ if(a.find("." + g)[0])
+ return;
+ i.append('
')
+ }
+ };
+ a.layBody.on("click", "." + g, function(e) {
+ var i = t(this),
+ n = i.parent(),
+ d = n.children(f);
+ a.tipsIndex = l.tips(['', d.html(), "
", ''].join(""), d[0], {
+ tips: [3, ""],
+ time: -1,
+ anim: -1,
+ maxWidth: r.ios || r.android ? 300 : a.elem.width() / 2,
+ isOutAnim: !1,
+ skin: "layui-table-tips",
+ success: function(e, t) {
+ e.find(".layui-table-tips-c").on("click", function() {
+ l.close(t)
+ })
+ }
+ }),
+ layui.stope(e)
+ }),
+ a.layBody.on("click", "*[lay-event]", function() {
+ var e = t(this),
+ i = e.parents("tr").eq(0).data("index");
+ layui.event.call(this, u, "tool(" + p + ")", v.call(this, {
+ event: e.attr("lay-event")
+ })),
+ a.setThisRowChecked(i)
+ }),
+ a.layMain.on("scroll", function() {
+ var e = t(this),
+ i = e.scrollLeft(),
+ n = e.scrollTop();
+ a.layHeader.scrollLeft(i),
+ a.layTotal.scrollLeft(i),
+ a.layFixed.find(x).scrollTop(n),
+ l.close(a.tipsIndex)
+ }),
+ R.on("click", function() {
+ R.trigger("table.remove.tool.panel")
+ }),
+ R.on("table.remove.tool.panel", function() {
+ t(".layui-table-tool-panel").remove()
+ }),
+ H.on("resize", function() {
+ a.resize()
+ })
+ },
+ d.init = function(e, i) {
+ i = i || {};
+ var a = this,
+ l = t(e ? 'table[lay-filter="' + e + '"]' : h + "[lay-data]"),
+ n = "Table element property lay-data configuration item has a syntax error: ";
+ return l.each(function() {
+ var a = t(this),
+ l = a.attr("lay-data");
+ try {
+ l = new Function("return " + l)()
+ } catch(r) {
+ o.error(n + l)
+ }
+ var c = [],
+ s = t.extend({
+ elem: this,
+ cols: [],
+ data: [],
+ skin: a.attr("lay-skin"),
+ size: a.attr("lay-size"),
+ even: "string" == typeof a.attr("lay-even")
+ }, d.config, i, l);
+ e && a.hide(),
+ a.find("thead>tr").each(function(e) {
+ s.cols[e] = [],
+ t(this).children().each(function(i) {
+ var a = t(this),
+ l = a.attr("lay-data");
+ try {
+ l = new Function("return " + l)()
+ } catch(r) {
+ return o.error(n + l)
+ }
+ var d = t.extend({
+ title: a.text(),
+ colspan: a.attr("colspan") || 0,
+ rowspan: a.attr("rowspan") || 0
+ }, l);
+ d.colspan < 2 && c.push(d),
+ s.cols[e].push(d)
+ })
+ }),
+ a.find("tbody>tr").each(function(e) {
+ var i = t(this),
+ a = {};
+ i.children("td").each(function(e, i) {
+ var l = t(this),
+ n = l.data("field");
+ if(n)
+ return a[n] = l.html()
+ }),
+ layui.each(c, function(e, t) {
+ var l = i.children("td").eq(e);
+ a[t.field] = l.html()
+ }),
+ s.data[e] = a
+ }),
+ d.render(s)
+ }),
+ a
+ },
+ c.that = {},
+ c.config = {},
+ d.eachCols = function(e, i, a) {
+ var l = c.config[e] || {},
+ n = [],
+ o = 0;
+ a = t.extend(!0, [], a || l.cols),
+ layui.each(a, function(e, t) {
+ layui.each(t, function(t, i) {
+ if(i.colGroup) {
+ var l = 0;
+ o++,
+ i.CHILD_COLS = [],
+ layui.each(a[e + 1], function(e, t) {
+ t.PARENT_COL_INDEX || l > 1 && l == i.colspan || (t.PARENT_COL_INDEX = o,
+ i.CHILD_COLS.push(t),
+ l += parseInt(t.colspan > 1 ? t.colspan : 1))
+ })
+ }
+ i.PARENT_COL_INDEX || n.push(i)
+ })
+ });
+ var r = function(e) {
+ layui.each(e || n, function(e, t) {
+ return t.CHILD_COLS ? r(t.CHILD_COLS) : void("function" == typeof i && i(e, t))
+ })
+ };
+ r()
+ },
+ d.checkStatus = function(e) {
+ var t = 0,
+ i = 0,
+ a = [],
+ l = d.cache[e] || [];
+ return layui.each(l, function(e, l) {
+ return l.constructor === Array ? void i++ : void(l[d.config.checkName] && (t++,
+ a.push(d.clearCacheKey(l))))
+ }), {
+ data: a,
+ isAll: !!l.length && t === l.length - i
+ }
+ },
+ d.exportFile = function(e, t, i) {
+ t = t || d.clearCacheKey(d.cache[e]),
+ i = i || "csv";
+ var a = c.config[e] || {},
+ l = {
+ csv: "text/csv",
+ xls: "application/vnd.ms-excel"
+ }[i],
+ n = document.createElement("a");
+ return r.ie ? o.error("IE_NOT_SUPPORT_EXPORTS") : (n.href = "data:" + l + ";charset=utf-8,\ufeff" + encodeURIComponent(function() {
+ var i = [],
+ a = [];
+ return layui.each(t, function(t, l) {
+ var n = [];
+ "object" == typeof e ? (layui.each(e, function(e, a) {
+ 0 == t && i.push(a || "")
+ }),
+ layui.each(d.clearCacheKey(l), function(e, t) {
+ n.push(t)
+ })) : d.eachCols(e, function(e, a) {
+ a.field && "normal" == a.type && !a.hide && (0 == t && i.push(a.title || ""),
+ n.push(l[a.field]))
+ }),
+ a.push(n.join(","))
+ }),
+ i.join(",") + "\r\n" + a.join("\r\n")
+ }()),
+ n.download = (a.title || "table_" + (a.index || "")) + "." + i,
+ document.body.appendChild(n),
+ n.click(),
+ void document.body.removeChild(n))
+ },
+ d.resize = function(e) {
+ if(e) {
+ var t = s(e);
+ if(!t)
+ return;
+ c.that[e].resize()
+ } else
+ layui.each(c.that, function() {
+ this.resize()
+ })
+ },
+ d.reload = function(e, i) {
+ i = i || {};
+ var a = s(e);
+ if(a)
+ return i.data && i.data.constructor === Array && delete a.data,
+ d.render(t.extend(!0, {}, a, i))
+ },
+ d.render = function(e) {
+ var t = new F(e);
+ return c.call(t)
+ },
+ d.clearCacheKey = function(e) {
+ return e = t.extend({}, e),
+ delete e[d.config.checkName],
+ delete e[d.config.indexName],
+ e
+ },
+ d.init(),
+ e(u, d)
+});
\ No newline at end of file