lihai-oa/public/static/assets/gougu/module/treeGrid.js

6 lines
41 KiB
JavaScript
Raw Normal View History

2023-10-24 15:17:16 +08:00
/**
码云地址https://gitee.com/beijiyi/tree_table_treegrid_based_on_layui
在线demohttp://beijiyi.com/
*/
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};layui.config({}).extend({}).define(["laytpl","laypage","layer","form"],function(e){var t=layui.$,i=layui.laytpl,a=layui.laypage,n=layui.layer,o=layui.form,r=layui.hint(),l=layui.device(),c={config:{indexName:"lay_table_index",cols:{isCheckName:"lay_is_checked",isRadio:"lay_is_radio",isOpen:"lay_is_open",isShow:"lay_is_show",level:"lay_level",children:"children",isRowCheck:"lay_is_row_check",cheDisabled:"lay_che_disabled",radDisabled:"lay_rad_disabled",iconOpen:"lay_icon_open",iconClose:"lay_icon_close",icon:"lay_icon"},initWidth:{checkbox:48,space:15,numbers:40,radio:48}},cache:{tableId:{data:{list:[],map:{},treeList:[],upIds:[]}},cla:{claIds:{tableId:!0},claObjs:{tableId:{}}},selectcode:{demokey:[{key:{value:""}}]}},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,s,e,t)},getClass:function(e){return c.cache.cla.claObjs[e]},pushClass:function(e,t){c.cache.cla.claObjs[e]=t},isCalss:function(e){return(this.cache.cla.claIds||{}).hasOwnProperty(e)||!1},isClassYes:function(e){return(this.cache.cla.claIds||{})[e]||!1},pushClassIds:function(e,t){this.cache.cla.claIds[e]=t},setObj:function(e,t,i){this.obj[e]||(this.obj[e]={}),this.obj[e][t]=i},getObj:function(e,t){return this.obj[e]?this.obj[e][t]:null},getDataList:function(e){return c.cache[e]?c.cache[e].data.list:[]},setDataList:function(e,t){c.cache[e]||(c.cache[e]={}),c.cache[e].data||(c.cache[e].data={}),c.cache[e].data.list||(c.cache[e].data.list=[]),c.cache[e].data.list=t},getDataMap:function(e){return c.cache[e]?c.cache[e].data.map:{}},setDataMap:function(e,t){c.cache[e]||(c.cache[e]={}),c.cache[e].data||(c.cache[e].data={}),c.cache[e].data.map||(c.cache[e].data.map={}),c.cache[e].data.map=t},getDataTreeList:function(e){return c.cache[e]?c.cache[e].data.treeList:[]},setDataTreeList:function(e,t){c.cache[e]||(c.cache[e]={}),c.cache[e].data||(c.cache[e].data={}),c.cache[e].data.treeList||(c.cache[e].data.treeList={}),c.cache[e].data.treeList=t},getDataRootList:function(e){return c.cache[e]?c.cache[e].data.upIds||[]:[]},setDataRootList:function(e,t){c.cache[e]||(c.cache[e]={}),c.cache[e].data||(c.cache[e].data={}),c.cache[e].data.upIds||(c.cache[e].data.upIds=[]),c.cache[e].data.upIds=t},init:function(e,i){i=i||{};var a=this,n=t(e?'table[lay-filter="'+e+'"]':f+"[lay-data]"),o="Table element property lay-data configuration item has a syntax error: ";return n.each(function(){var a=t(this),n=a.attr("lay-data");try{n=new Function("return "+n)()}catch(e){r.error(o+n)}var l=[],d=t.extend({elem:this,cols:[],data:[],skin:a.attr("lay-skin"),size:a.attr("lay-size"),even:"string"==typeof a.attr("lay-even")},c.config,i,n);e&&a.hide(),a.find("thead>tr").each(function(e){d.cols[e]=[],t(this).children().each(function(i){var a=t(this),n=a.attr("lay-data");try{n=new Function("return "+n)()}catch(e){return r.error(o+n)}var c=t.extend({title:a.text(),colspan:a.attr("colspan")||0,rowspan:a.attr("rowspan")||0},n);c.colspan<2&&l.push(c),d.cols[e].push(c)})}),a.find("tbody>tr").each(function(e){var i=t(this),a={};i.children("td").each(function(e,i){var n=t(this),o=n.data("field");if(o)return a[o]=n.html()}),layui.each(l,function(e,t){var n=i.children("td").eq(e);a[t.field]=n.html()}),d.data[e]=a}),c.render(d)}),a},render:function(e){c.pushClassIds(e.id);var t=new k(e);return d.call(t)},ready:function(e,t){function i(){if(e){var o=c.getClass(e);if(o&&o.hasOwnProperty("layBody"))t(o),a=!0;else{(new Date).getTime()-n.getTime()<=1e4&&!a&&setTimeout(i,50)}}}var a=!1,n=new Date;e&&t&&setTimeout(i,50)},checkStatus:function(e){var t=0,i=0,a=[],n=c.getDataList(e)||[];return layui.each(n,function(e,n){if(n.constructor===Array)return void i++;n[c.config.cols.isCheckName]&&(t++,a.push(c.clearCacheKey(n)))}),{data:a,isAll:!!n.length&&t===n.length-i}},setCheckStatus:function(e,
var e=this;e.columnWidthInit(),e.tableHeight(),e.resizeHeight(),e.resizeWidth()},k.prototype.setArea=function(){var e=this;e.columnWidthInit(),e.tableHeight()},k.prototype.columnWidthInit=function(){var e=this,t=e.config,i=0,a=0,n=0,o=0,r=t.width||function(){return function e(i){var a,n;i=i||t.elem.parent(),a=i.width();try{n="none"===i.css("display")}catch(e){}return!i[0]||a&&!n?a:e(i.parent())}()}()-17;e.eachCols(function(){i++}),r-=function(){return"line"===t.skin||"nob"===t.skin?2:i+1}(),layui.each(t.cols,function(t,i){layui.each(i,function(t,n){var l;if(!n)return void i.splice(t,1);e.initOpts(n),l=n.width||0,n.colspan>1||(/\d+%$/.test(l)?n.width=l=Math.floor(parseFloat(l)/100*r):!n._is_width_dev&&l||(n._is_width_dev=!0,n.width=l=0,a++),o+=l)})}),e.autoColNums=a,r>o&&a&&(n=(r-o)/a),layui.each(t.cols,function(e,i){layui.each(i,function(e,i){var a=i.minWidth||t.cellMinWidth;i.colspan>1||0===i.width&&(i.width=Math.floor(n>=a?n:a))})})},k.prototype.resizeWidth=function(){this.renderTdCss()},k.prototype.tableHeight=function(){var e=this,i=e.config,a=e.configFirst;if(!c.kit.isNumber(a.height)){var n=0;if(i.heightRemove&&c.kit.isArray(i.heightRemove)){i.heightRemove.forEach(function(e){var i=c.kit.isNumber(e)?e:t(e).outerHeight(!0);c.kit.isNumber(i)&&(n+=i)})}var o=x.height()-n-1;e.fullHeightGap=0,i.height&&/^full-\d+$/.test(i.height)&&(e.fullHeightGap=i.height.split("-")[1]),i.height=o-e.fullHeightGap}},k.prototype.resizeHeight=function(){var e,t=this,i=t.config,a=i.height;a<135&&(a=135),t.elem.css("height",a-80);var n=i.isFilter?76:38;e=parseFloat(a)-("tree"==t.config.model?0:n)-1,i.toolbar&&(e-=t.layTool.outerHeight()),i.isPage&&(e=e-t.layPage.outerHeight()-1),t.layMain.css("height",e-80)},k.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},k.prototype.scrollPatch=function(){var e=this,i=e.layMain.children("table"),a=e.layMain.width()-e.layMain.prop("clientWidth"),n=e.layMain.height()-e.layMain.prop("clientHeight"),o=e.getScrollWidth(e.layMain[0]),r=i.outerWidth()-e.layMain.width();if(e.autoColNums&&r<5&&!e.scrollPatchWStatus){var l=e.layHeader.eq(0).find("thead th:last-child"),c=l.data("field");e.getCssRule(c,function(t){var i=t.style.width||l.outerWidth();t.style.width=parseFloat(i)-o-r+"px",e.layMain.height()-e.layMain.prop("clientHeight")>0&&(t.style.width=parseFloat(t.style.width)-1+"px"),e.scrollPatchWStatus=!0})}if(a&&n){if(e.elem.find(".layui-table-patch").length<=0){var d=t('<th class="layui-table-patch"><div class="layui-table-cell"></div></th>');d.find("div").css({width:a}),e.layHeader.eq(0).find("thead tr").append(d)}}else e.layFilter.eq(0).find(".layui-table-patch").remove(),e.layHeader.eq(0).find(".layui-table-patch").remove();var s=e.layMain.height(),f=s-n;e.layFixed.find(".layui-table-body").css("height",i.height()-80>f?f:"auto"),e.layFixRight[r>0?"removeClass":"addClass"]("layui-hide"),e.layFixRight.css("right",a-1)},k.prototype.events=function(){var e,i=this,a=i.config,o=t("body"),r={},l=i.layHeader.find("th"),d=i.layBody.find("tr");d.unbind("click").on("click",function(e){var a=t(this).attr("data-index");c.treeRowCheck(i.config.id,a)}),d.unbind("dblclick").on("dblclick",function(e){var n=t(this).attr("data-index"),o=c.getDataList(i.config.id),r=o[n];"function"==typeof a.onDblClickRow&&a.onDblClickRow(n,r)}),l.unbind("mousemove").on("mousemove",function(e){var i=t(this),a=i.offset().left,n=e.clientX-a;i.attr("colspan")>1||i.data("unresize")||r.resizeStart||(r.allowResize=i.width()-n<=10,o.css("cursor",r.allowResize?"col-resize":""))}),l.unbind("mouseleave").on("mouseleave",function(){t(this);r.resizeStart||o.css("cursor","")}),l.unbind("mousedown").on("mousedown",function(e){var n=t(this);if(r.allowResize){var o=n.data("field");e.preventDefault(),r.resizeStart=!0,r.offset=[e.clientX,e.clientY],i.getCssRule(o,function(e){var t=e.style.width||n.outerWidth();r.rule=e,r.ruleWidth=