diff --git a/code-doc/src/main/resources/template/js/sysdevelopdoc/sysdevelopdoclist.js b/code-doc/src/main/resources/template/js/sysdevelopdoc/sysdevelopdoclist.js index ee3569386038dc04880887a80b6b6db5b3854f00..c41fc1ab855d2c80a11d72825856b2100a24f7df 100644 --- a/code-doc/src/main/resources/template/js/sysdevelopdoc/sysdevelopdoclist.js +++ b/code-doc/src/main/resources/template/js/sysdevelopdoc/sysdevelopdoclist.js @@ -6,25 +6,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1553740371701'); - - treeGrid.render({ + + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'sysdevelopdoc001', - cellMinWidth: 100, where: {typeName: $("#typeName").val()}, - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'title',//以树形式显示的字段 cols: [[ {field:'title', width:200, title: '目录'}, {field:'contentNum', width:80, title: '文档数'}, @@ -35,10 +30,13 @@ layui.config({ done: function(){ matchingLanguage(); }, - isPage:false - }); - - treeGrid.on('tool(messageTable)', function (obj) { + }, { + keyId: 'id', + keyPid: 'pId', + title: 'title', + }); + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -164,7 +162,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where:{typeName: $("#typeName").val()}}); + tableTree.reload("messageTable", {where:{typeName: $("#typeName").val()}}); } exports('sysdevelopdoclist', {}); diff --git a/common/src/main/resources/template/js/sysEveModelType/sysEveModelTypeList.js b/common/src/main/resources/template/js/sysEveModelType/sysEveModelTypeList.js index a92604fa27cae2b5af5b421909f3c9eda2d99575..7b47c70f2e0fe8685dab87b768253ea7397b0f3b 100644 --- a/common/src/main/resources/template/js/sysEveModelType/sysEveModelTypeList.js +++ b/common/src/main/resources/template/js/sysEveModelType/sysEveModelTypeList.js @@ -6,24 +6,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1637420150374'); - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'sysevemodeltype001', where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'parentId',//树形父id字段名称 - treeShowName: 'typeName',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'}, { field: 'typeName', title: '名称', width: 360 }, @@ -33,13 +29,16 @@ layui.config({ { field: 'lastUpdateTime', title: systemLanguage["com.skyeye.lastUpdateTime"][languageType], align: 'center', width: 150}, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 130, toolbar: '#tableBar'} ]], - isPage: false, done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'parentId', + title: 'typeName', }); - treeGrid.on('tool(messageTable)', function (obj) { + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if(layEvent === 'delet'){ // 删除 @@ -101,7 +100,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ diff --git a/dsform/src/main/resources/template/js/dsFormPageType/dsFormPageTypeList.js b/dsform/src/main/resources/template/js/dsFormPageType/dsFormPageTypeList.js index 8fcdbf34f5ee11791e7f1a8dcb8cd7f3ff79dbbf..006e590dcb3ab04ef3325eb694b4bc7298e5795c 100644 --- a/dsform/src/main/resources/template/js/dsFormPageType/dsFormPageTypeList.js +++ b/dsform/src/main/resources/template/js/dsFormPageType/dsFormPageTypeList.js @@ -6,24 +6,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1636280749353'); - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: flowableBasePath + 'dsformpagetype001', where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'parentId',//树形父id字段名称 - treeShowName: 'typeName',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'}, { field: 'typeName', title: '中文名称', width: 180 }, @@ -35,13 +31,16 @@ layui.config({ { field: 'lastUpdateTime', title: systemLanguage["com.skyeye.lastUpdateTime"][languageType], align: 'center', width: 150}, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 130, toolbar: '#tableBar'} ]], - isPage: false, done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'parentId', + title: 'typeName', }); - treeGrid.on('tool(messageTable)', function (obj) { + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if(layEvent === 'delet'){ // 删除 @@ -103,7 +102,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ diff --git a/erp/src/main/resources/template/js/materialCategory/materialCategoryList.js b/erp/src/main/resources/template/js/materialCategory/materialCategoryList.js index 8cb04b8a5d03c60e5223b67cdad772ae793175b2..151060ad7d68c84da19e1f50142c7162687f9165 100644 --- a/erp/src/main/resources/template/js/materialCategory/materialCategoryList.js +++ b/erp/src/main/resources/template/js/materialCategory/materialCategoryList.js @@ -6,24 +6,19 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1568558491168'); - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: flowableBasePath + 'materialcategory001', - cellMinWidth: 100, where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'name',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'}, { field: 'name', title: '名称', align: 'left', width: 360 }, @@ -31,13 +26,16 @@ layui.config({ { field: 'remark', title: '备注', align: 'left', width: 200 }, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 250, toolbar: '#tableBar'} ]], - isPage:false, done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'name', }); - - treeGrid.on('tool(messageTable)', function (obj) { + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { //编辑 @@ -109,7 +107,7 @@ layui.config({ form.render(); form.on('submit(formSearch)', function (data) { if (winui.verifyForm(data.elem)) { - refreshloadTable(); + loadTable(); } return false; }); @@ -120,13 +118,9 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } - function refreshloadTable(){ - treeGrid.query("messageTable", {page: {curr: 1}, where: getTableParams()}); - } - function getTableParams(){ return { name: $("#name").val() diff --git a/knowlg/src/main/resources/template/js/knowledgetype/knowledgetypelist.js b/knowlg/src/main/resources/template/js/knowledgetype/knowledgetypelist.js index 89e657f4456bc0abec2772d9855690729dd47db0..970b825a0d9cf467c5647aec7f911430da182949 100644 --- a/knowlg/src/main/resources/template/js/knowledgetype/knowledgetypelist.js +++ b/knowlg/src/main/resources/template/js/knowledgetype/knowledgetypelist.js @@ -5,24 +5,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1568476869775'); - treeGrid.render({ + + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'knowledgetype001', - cellMinWidth: 100, where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'name',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'}, { field: 'name', title: '名称', width: 360 }, @@ -45,9 +41,13 @@ layui.config({ done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'name', }); - - treeGrid.on('tool(messageTable)', function (obj) { + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { //编辑 @@ -138,12 +138,12 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ return { - name:$("#name").val() + name: $("#name").val() }; } diff --git a/message/src/main/resources/template/js/sysnoticetype/sysnoticetypelist.js b/message/src/main/resources/template/js/sysnoticetype/sysnoticetypelist.js index 78f3c77132d819eed7f1010143e23db718bc236f..4486a84d7fe1f292dfcf397c1780ebb516650eb2 100644 --- a/message/src/main/resources/template/js/sysnoticetype/sysnoticetypelist.js +++ b/message/src/main/resources/template/js/sysnoticetype/sysnoticetypelist.js @@ -5,25 +5,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1561106812907'); // 公告类型列表 - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'noticetype001', - cellMinWidth: 100, where: {name:$("#name").val(),parentId:$("#firstType").val()}, - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'name',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'}, { field: 'name', title: '类型名称', align: 'center', width: 120 }, @@ -49,16 +44,19 @@ layui.config({ { field: 'createTime', title: systemLanguage["com.skyeye.createTime"][languageType], align: 'center', width: 180 }, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 257, toolbar: '#tableBar'} ]], - isPage:false, done: function(){ matchingLanguage(); if(!loadFirstType){ initFirstType(); } } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'name', }); - - treeGrid.on('tool(messageTable)', function (obj) { + + tableTree.on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { //编辑 @@ -98,8 +96,7 @@ layui.config({ }); form.render(); - - + $("body").on("click", "#formSearch", function() { loadTable(); }); @@ -190,7 +187,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where:{name:$("#name").val(),parentId:$("#firstType").val()}}); + tableTree.reload("messageTable", {where:{name:$("#name").val(),parentId:$("#firstType").val()}}); } exports('sysnoticetypelist', {}); diff --git a/organization/src/main/resources/template/js/companyjob/companyjoblist.js b/organization/src/main/resources/template/js/companyjob/companyjoblist.js index 86c246f14639471afaf0ab5a4498b213661b19f9..cf6dbbdd56503512ac8ef8a6d41bdc4a7a4c3787 100644 --- a/organization/src/main/resources/template/js/companyjob/companyjoblist.js +++ b/organization/src/main/resources/template/js/companyjob/companyjoblist.js @@ -6,11 +6,11 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; var selTemplate = getFileContent('tpl/template/select-option.tpl') authBtn('1552962689111'); @@ -47,16 +47,12 @@ layui.config({ } function initLoadTable(){ - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'companyjob001', where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'jobName',//以树形式显示的字段 cols: [[ { field: 'jobName', title: '职位名称', width: 180 }, { field: 'id', title: '职位简介', width: 80, align: 'center', templet: function (d) { @@ -68,14 +64,17 @@ layui.config({ { field: 'createTime', title: systemLanguage["com.skyeye.createTime"][languageType], width: 150 }, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 240, toolbar: '#tableBar'} ]], - isPage:false, done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'jobName', }); } - treeGrid.on('tool(messageTable)', function (obj) { + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -99,7 +98,7 @@ layui.config({ form.render(); form.on('submit(formSearch)', function (data) { if (winui.verifyForm(data.elem)) { - refreshTable(); + loadTable(); } return false; }); @@ -160,13 +159,9 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } - function refreshTable(){ - treeGrid.query("messageTable", {page: {curr: 1}, where: getTableParams()}); - } - function getTableParams(){ return { companyId: $("#companyId").val(), diff --git a/organization/src/main/resources/template/js/companymation/companymationlist.js b/organization/src/main/resources/template/js/companymation/companymationlist.js index 79c7ec278042540d3e1e6916dceac3934b744361..0a38ed5b54dd664d64942f8fc8841eecce1a1c54 100644 --- a/organization/src/main/resources/template/js/companymation/companymationlist.js +++ b/organization/src/main/resources/template/js/companymation/companymationlist.js @@ -6,25 +6,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1552959308337'); // 公司列表 - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'companymation001', - cellMinWidth: 100, where:{companyName: $("#companyName").val()}, - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'companyName',//以树形式显示的字段 cols: [[ { field: 'companyName', width: 300, title: '公司名称'}, { field: 'companyDesc', width: 80, title: '公司简介', align: 'center', templet: function (d) { @@ -55,9 +50,13 @@ layui.config({ done: function(){ matchingLanguage(); } - }); - - treeGrid.on('tool(messageTable)', function (obj) { + }, { + keyId: 'id', + keyPid: 'pId', + title: 'companyName', + }); + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -128,7 +127,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where:{companyName: $("#companyName").val()}}); + tableTree.reload("messageTable", {where:{companyName: $("#companyName").val()}}); } exports('companymationlist', {}); diff --git a/pro/src/main/resources/template/js/protask/protasklist.js b/pro/src/main/resources/template/js/protask/protasklist.js index d70081eac74f8ccbde6e80f4031c261c2b8402b8..3c72d55bab09376f6a4b4b6cad02c410de356c6a 100644 --- a/pro/src/main/resources/template/js/protask/protasklist.js +++ b/pro/src/main/resources/template/js/protask/protasklist.js @@ -9,32 +9,24 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'jquery', 'winui', 'form', 'laydate', 'treeGrid'], function (exports) { +}).define(['window', 'jquery', 'winui', 'form', 'laydate', 'tableTreeDj'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, laydate = layui.laydate, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1574644930825'); - //任务开始时间 - laydate.render({ - elem: '#startTime', //指定元素 - range: '~' - }); + // 任务开始时间 + laydate.render({elem: '#startTime', range: '~'}); - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: flowableBasePath + 'protask011', - cellMinWidth: 100, where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'taskName',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers', rowspan: 2}, { field: 'taskName', title: '名称', rowspan: 2, width: 200, templet: function (d) { @@ -80,9 +72,13 @@ layui.config({ done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'taskName', }); - treeGrid.on('tool(messageTable)', function (obj) { + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'details'){ //详情 @@ -263,7 +259,7 @@ layui.config({ form.render(); form.on('submit(formSearch)', function (data) { if (winui.verifyForm(data.elem)) { - treeGrid.query("messageTable", {page: {curr: 1}, where: getTableParams()}); + loadTable(); } return false; }); @@ -274,12 +270,12 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ var theStartTime = "", theEndTime = ""; - if(!isNull($("#startTime").val())){ + if (!isNull($("#startTime").val())) { theStartTime = $("#startTime").val().split('~')[0].trim() + ' 00:00:00'; theEndTime = $("#startTime").val().split('~')[1].trim() + ' 23:59:59'; } diff --git a/pro/src/main/resources/template/js/protaskall/protasklist.js b/pro/src/main/resources/template/js/protaskall/protasklist.js index 3edebb04f5d32f93e30c3ddd7e5eaf1eb109b468..246db1be14a2592efb3ca0e9ba8a799c8945f209 100644 --- a/pro/src/main/resources/template/js/protaskall/protasklist.js +++ b/pro/src/main/resources/template/js/protaskall/protasklist.js @@ -6,30 +6,22 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'jquery', 'winui', 'form', 'laydate', 'treeGrid'], function (exports) { +}).define(['window', 'jquery', 'winui', 'form', 'laydate', 'tableTreeDj'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, laydate = layui.laydate, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; - //任务开始时间 - laydate.render({ - elem: '#startTime', //指定元素 - range: '~' - }); + // 任务开始时间 + laydate.render({elem: '#startTime', range: '~'}); - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: flowableBasePath + 'protask001', - cellMinWidth: 100, where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'taskName',//以树形式显示的字段 cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers', rowspan: 2}, { field: 'taskName', title: '名称', rowspan: 2, width: 200, templet: function (d) { @@ -75,9 +67,13 @@ layui.config({ done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'taskName', }); - treeGrid.on('tool(messageTable)', function (obj) { + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'details'){ //详情 @@ -104,7 +100,7 @@ layui.config({ form.render(); form.on('submit(formSearch)', function (data) { if (winui.verifyForm(data.elem)) { - treeGrid.query("messageTable", {page: {curr: 1}, where: getTableParams()}); + loadTable(); } return false; }); @@ -115,12 +111,12 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ var theStartTime = "", theEndTime = ""; - if(!isNull($("#startTime").val())){ + if (!isNull($("#startTime").val())) { theStartTime = $("#startTime").val().split('~')[0].trim() + ' 00:00:00'; theEndTime = $("#startTime").val().split('~')[1].trim() + ' 23:59:59'; } diff --git a/report/src/main/resources/template/js/reportModelType/reportModelTypeList.js b/report/src/main/resources/template/js/reportModelType/reportModelTypeList.js index 61bc5487e3dface55a9b8d24b78f945f65f1d6da..092aaf319e16b92c7d385dd5517092a3c4bb0bf2 100644 --- a/report/src/main/resources/template/js/reportModelType/reportModelTypeList.js +++ b/report/src/main/resources/template/js/reportModelType/reportModelTypeList.js @@ -6,25 +6,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window', -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1635086167509'); - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reportBasePath + 'reportmodeltype001', - cellMinWidth: 100, where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'parentId',//树形父id字段名称 - treeShowName: 'name',//以树形式显示的字段 cols: [[ { field: 'name', width: 300, title: '名称'}, { field: 'createName', title: '创建人', align: 'left', width: 100 }, @@ -35,11 +30,14 @@ layui.config({ ]], done: function(){ matchingLanguage(); - }, - isPage:false + } + }, { + keyId: 'id', + keyPid: 'parentId', + title: 'name', }); - treeGrid.on('tool(messageTable)', function (obj) { + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -101,7 +99,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ diff --git a/school/src/main/resources/template/js/schoolgrademation/schoolgrademationlist.js b/school/src/main/resources/template/js/schoolgrademation/schoolgrademationlist.js index beebcbddd19edebefdf2158e9a08a35004e48798..413cd16251e98c8e4701b9b5196202e633b34ee8 100644 --- a/school/src/main/resources/template/js/schoolgrademation/schoolgrademationlist.js +++ b/school/src/main/resources/template/js/schoolgrademation/schoolgrademationlist.js @@ -6,11 +6,11 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1586314893391'); @@ -22,17 +22,12 @@ layui.config({ }); function initTable(){ - treeGrid.render({ + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: schoolBasePath + 'grademation001', - cellMinWidth: 100, where: getTableParams(), - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'gradeName',//以树形式显示的字段 cols: [[ { field: 'gradeName', width: 150, title: '年级名称'}, { field: 'schoolName', width: 200, title: '所属学校'}, @@ -40,13 +35,16 @@ layui.config({ { field:'typeName', width: 120, title: '年级状态'}, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 240, toolbar: '#tableBar'} ]], - isPage:false, done: function(){ matchingLanguage(); } - }); - - treeGrid.on('tool(messageTable)', function (obj) { + }, { + keyId: 'id', + keyPid: 'pId', + title: 'gradeName', + }); + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -130,7 +128,7 @@ layui.config({ } function loadTable(){ - treeGrid.query("messageTable", {where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } function getTableParams() { diff --git a/school/src/main/resources/template/js/schoolmation/schoolmationlist.js b/school/src/main/resources/template/js/schoolmation/schoolmationlist.js index 99894e94a5c1597641960dad5306883a13196231..f2fe02f61bfd504961b7310176e2d976e89f0380 100644 --- a/school/src/main/resources/template/js/schoolmation/schoolmationlist.js +++ b/school/src/main/resources/template/js/schoolmation/schoolmationlist.js @@ -6,27 +6,20 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); - var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1585824465120'); - - - treeGrid.render({ + + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: schoolBasePath + 'schoolmation001', - cellMinWidth: 100, - where:{schoolName: $("#schoolName").val()}, - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'schoolName',//以树形式显示的字段 + where: {schoolName: $("#schoolName").val()}, cols: [[ { field: 'schoolName', width: 300, title: '学校名称'}, { field: 'schoolDesc', width: 80, title: '学校简介', align: 'center', templet: function (d) { @@ -37,13 +30,16 @@ layui.config({ { field:'powerName', width: 120, align: 'center', title: '数据权限'}, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 240, toolbar: '#tableBar'} ]], - isPage:false, done: function(){ matchingLanguage(); } - }); - - treeGrid.on('tool(messageTable)', function (obj) { + }, { + keyId: 'id', + keyPid: 'pId', + title: 'schoolName', + }); + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -64,7 +60,6 @@ layui.config({ form.render(); form.on('submit(formSearch)', function (data) { - if (winui.verifyForm(data.elem)) { loadTable(); } @@ -115,7 +110,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where:{schoolName: $("#schoolName").val()}}); + tableTree.reload("messageTable", {where:{schoolName: $("#schoolName").val()}}); } exports('schoolmationlist', {}); diff --git a/userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointadd.js b/userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.js similarity index 85% rename from userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointadd.js rename to userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.js index 398e7778237d5a71d5ea9fafa205a861a28ad9bf..930c277f78507f8cd7b70b4cc3e3bd93e7f2a769 100644 --- a/userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointadd.js +++ b/userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.js @@ -19,7 +19,7 @@ layui.config({ authMenu: $("#authMenu").val(), menuId: parent.menuId }; - AjaxPostUtil.request({url: reqBasePath + "sysevemenuauthpoint002", params: params, type: 'json', callback: function (json) { + AjaxPostUtil.request({url: reqBasePath + "writeSysEveMenuAuthPointMation", params: params, type: 'json', callback: function (json) { parent.layer.close(index); parent.refreshCode = '0'; }}); diff --git a/userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointedit.js b/userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.js similarity index 79% rename from userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointedit.js rename to userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.js index fbb0b5f690b5b03a61a648fc1afec4c4831f4688..5737a08884964f7ba2c5b73b4b67c6dd87f9f72c 100644 --- a/userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointedit.js +++ b/userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.js @@ -20,10 +20,12 @@ layui.config({ var params = { authMenuName: $("#authMenuName").val(), authMenu: $("#authMenu").val(), - rowId: parent.rowId, - menuId: parent.menuId + menuId: parent.menuId, + parentId: json.bean.parentId, + type: json.bean.type, + id: parent.rowId }; - AjaxPostUtil.request({url: reqBasePath + "sysevemenuauthpoint004", params: params, type: 'json', callback: function (json) { + AjaxPostUtil.request({url: reqBasePath + "writeSysEveMenuAuthPointMation", params: params, type: 'json', callback: function (json) { parent.layer.close(index); parent.refreshCode = '0'; }}); @@ -32,11 +34,9 @@ layui.config({ }); }}); - - //取消 + // 取消 $("body").on("click", "#cancle", function() { parent.layer.close(index); }); }); - }); \ No newline at end of file diff --git a/userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointlist.js b/userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointList.js similarity index 73% rename from userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointlist.js rename to userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointList.js index 6a414a6ae8e2126b929c64d98701ee59b34849a3..25efae106603c7e38f30349e3923ceb334082237 100644 --- a/userauth/src/main/resources/template/js/sysevemenuauthpoint/sysevemenuauthpointlist.js +++ b/userauth/src/main/resources/template/js/sysEveMenuAuthPoint/sysEveMenuAuthPointList.js @@ -7,27 +7,22 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'table', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); - var $ = layui.$, form = layui.form, - table = layui.table; + tableTree = layui.tableTreeDj; authBtn('1552958039634'); menuId = parent.menuId; - - table.render({ + + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', url: reqBasePath + 'sysevemenuauthpoint001', where: getTableParams(), - even: true, - page: true, - limits: getLimits(), - limit: getLimit(), cols: [[ { title: systemLanguage["com.skyeye.serialNumber"][languageType], type: 'numbers'}, { field: 'authMenuName', title: '权限点名称', width: 120 }, @@ -39,9 +34,13 @@ layui.config({ done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'parentId', + title: 'authMenuName', }); - - table.on('tool(messageTable)', function (obj) { + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'del') { //删除 @@ -51,15 +50,7 @@ layui.config({ } }); - form.render(); - form.on('submit(formSearch)', function (data) { - if (winui.verifyForm(data.elem)) { - refreshTable(); - } - return false; - }); - - //删除 + // 删除 function del(data, obj){ layer.confirm(systemLanguage["com.skyeye.deleteOperationMsg"][languageType], {icon: 3, title: systemLanguage["com.skyeye.deleteOperation"][languageType]}, function(index){ layer.close(index); @@ -70,13 +61,13 @@ layui.config({ }); } - //编辑权限点 + // 编辑权限点 function edit(data){ rowId = data.id; _openNewWindows({ - url: "../../tpl/sysevemenuauthpoint/sysevemenuauthpointedit.html", + url: "../../tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.html", title: "编辑权限点", - pageId: "sysevemenuauthpointedit", + pageId: "sysEveMenuAuthPointEdit", area: ['500px', '300px'], callBack: function(refreshCode){ winui.window.msg(systemLanguage["com.skyeye.successfulOperation"][languageType], {icon: 1, time: 2000}); @@ -84,32 +75,36 @@ layui.config({ }}); } - //刷新数据 - $("body").on("click", "#reloadTable", function() { - loadTable(); - }); - - //新增权限点 + // 新增权限点 $("body").on("click", "#addBean", function() { _openNewWindows({ - url: "../../tpl/sysevemenuauthpoint/sysevemenuauthpointadd.html", + url: "../../tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.html", title: "新增权限点", - pageId: "sysevemenuauthpointadd", + pageId: "sysEveMenuAuthPointAdd", area: ['500px', '300px'], callBack: function(refreshCode){ winui.window.msg(systemLanguage["com.skyeye.successfulOperation"][languageType], {icon: 1, time: 2000}); loadTable(); }}); }); - + + form.render(); + form.on('submit(formSearch)', function (data) { + if (winui.verifyForm(data.elem)) { + loadTable(); + } + return false; + }); + + // 刷新数据 + $("body").on("click", "#reloadTable", function() { + loadTable(); + }); + function loadTable(){ - table.reload("messageTable", {where: getTableParams()}); - } - - function refreshTable(){ - table.reload("messageTable", {page: {curr: 1}, where: getTableParams()}); + tableTree.reload("messageTable", {where: getTableParams()}); } - + function getTableParams(){ return { authMenuName: $("#authMenuName").val(), @@ -119,5 +114,5 @@ layui.config({ }; } - exports('sysevemenuauthpointlist', {}); + exports('sysEveMenuAuthPointList', {}); }); diff --git a/userauth/src/main/resources/template/js/sysevemenu/sysevemenulist.js b/userauth/src/main/resources/template/js/sysevemenu/sysevemenulist.js index 4f57dd8f231c17998f9ff9dedaa37120b9f09b1b..b75c296134031436991cb71b1ddab0ce274bb57b 100644 --- a/userauth/src/main/resources/template/js/sysevemenu/sysevemenulist.js +++ b/userauth/src/main/resources/template/js/sysevemenu/sysevemenulist.js @@ -127,17 +127,8 @@ layui.config({ details(data); } }); - } - form.render(); - form.on('submit(formSearch)', function (data) { - if (winui.verifyForm(data.elem)) { - table.reload("messageTable", {page: {curr: 1}, where: getTableParams()}); - } - return false; - }); - /********* tree 处理 start *************/ var trees = {}; var treeDoms = $("ul.fsTree"); @@ -264,29 +255,37 @@ layui.config({ function authpoint(data){ menuId = data.id; _openNewWindows({ - url: "../../tpl/sysevemenuauthpoint/sysevemenuauthpointlist.html", + url: "../../tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointList.html", title: systemLanguage["com.skyeye.authorityPointPage"][languageType], - pageId: "sysevemenuauthpoint", + pageId: "sysEveMenuAuthPointList", area: ['90vw', '90vh'], callBack: function(refreshCode){ loadTable(); }}); } + + form.render(); + form.on('submit(formSearch)', function (data) { + if (winui.verifyForm(data.elem)) { + table.reload("messageTable", {page: {curr: 1}, where: getTableParams()}); + } + return false; + }); function loadTable(){ table.reload("messageTable", {where: getTableParams()}); } function getTableParams(){ - return { - menuName:$("#menuName").val(), - menuUrl:$("#menuUrl").val(), - parentId:parentId, - menuLevel:$("#menuLevel").val(), - desktopId:$("#desktop").val(), - isShare:$("#isShare").val(), - parentMenuName:$("#parentMenuName").val() - }; + return { + menuName: $("#menuName").val(), + menuUrl: $("#menuUrl").val(), + parentId: parentId, + menuLevel: $("#menuLevel").val(), + desktopId: $("#desktop").val(), + isShare: $("#isShare").val(), + parentMenuName: $("#parentMenuName").val() + }; } exports('sysevemenulist', {}); diff --git a/userauth/src/main/resources/template/js/syswintype/syswintypelist.js b/userauth/src/main/resources/template/js/syswintype/syswintypelist.js index f21f84978c686ce9bfb51ac29cfca9a190f399fd..addac481ccdccf46d9742053003ddd674973bdfd 100644 --- a/userauth/src/main/resources/template/js/syswintype/syswintypelist.js +++ b/userauth/src/main/resources/template/js/syswintype/syswintypelist.js @@ -6,11 +6,11 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; authBtn('1552962225700'); @@ -21,18 +21,13 @@ layui.config({ } return false; }); - - treeGrid.render({ + + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'sysevewintype001', - cellMinWidth: 100, where: {typeName: $("#typeName").val(), state: $("#state").val()}, - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'name',//以树形式显示的字段 cols: [[ { field:'name', width:300, title: '分类名称'}, { field:'stateName', width:100, title: '状态'}, @@ -40,13 +35,16 @@ layui.config({ { field:'orderBy', width:100, title: '排序'}, { title: systemLanguage["com.skyeye.operation"][languageType], fixed: 'right', align: 'center', width: 240, toolbar: '#tableBar'} ]], - isPage:false, done: function(){ matchingLanguage(); } - }); - - treeGrid.on('tool(messageTable)', function (obj) { + }, { + keyId: 'id', + keyPid: 'pId', + title: 'name', + }); + + tableTree.getTable().on('tool(messageTable)', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { //编辑 @@ -148,7 +146,7 @@ layui.config({ }); function loadTable(){ - treeGrid.query("messageTable", {where:{typeName: $("#typeName").val(), state: $("#state").val()}}); + tableTree.reload("messageTable", {where:{typeName: $("#typeName").val(), state: $("#state").val()}}); } exports('syswintypelist', {}); diff --git a/userauth/src/main/resources/template/js/tarea/tarea.js b/userauth/src/main/resources/template/js/tarea/tarea.js index f0582b53ce0216f8ff9fa38e7bb2ec2ebf4b6d54..69679359fafcebdafb3dc660531efe9b05562fbc 100644 --- a/userauth/src/main/resources/template/js/tarea/tarea.js +++ b/userauth/src/main/resources/template/js/tarea/tarea.js @@ -4,12 +4,11 @@ layui.config({ version: skyeyeVersion }).extend({ window: 'js/winui.window' -}).define(['window', 'treeGrid', 'jquery', 'winui', 'form'], function (exports) { +}).define(['window', 'tableTreeDj', 'jquery', 'winui', 'form'], function (exports) { winui.renderColor(); - var $ = layui.$, form = layui.form, - treeGrid = layui.treeGrid; + tableTree = layui.tableTreeDj; form.render(); form.on('submit(formSearch)', function (data) { @@ -18,18 +17,13 @@ layui.config({ } return false; }); - - treeGrid.render({ + + tableTree.render({ id: 'messageTable', elem: '#messageTable', method: 'post', - idField: 'id', url: reqBasePath + 'systarea001', - cellMinWidth: 100, where: {addressName: $("#addressName").val()}, - treeId: 'id',//树形id字段名称 - treeUpId: 'pId',//树形父id字段名称 - treeShowName: 'name',//以树形式显示的字段 cols: [[ {field:'name', width:300, title: '区域名称'}, {field:'id', width:100, title: 'id'}, @@ -39,15 +33,19 @@ layui.config({ done: function(){ matchingLanguage(); } + }, { + keyId: 'id', + keyPid: 'pId', + title: 'name', }); - //刷新数据 + // 刷新数据 $("body").on("click", "#reloadTable", function() { loadTable(); }); function loadTable(){ - treeGrid.query("messageTable", {where:{addressName: $("#addressName").val()}}); + tableTree.reload("messageTable", {where:{addressName: $("#addressName").val()}}); } exports('tarea', {}); diff --git a/userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointadd.html b/userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.html similarity index 94% rename from userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointadd.html rename to userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.html index 67c15bdbafc371fc8011bf4c4616af644914650e..d7ae7d02040f4c99bc1eb86af318b5688bac1039 100644 --- a/userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointadd.html +++ b/userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointAdd.html @@ -32,7 +32,7 @@ \ No newline at end of file diff --git a/userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointedit.html b/userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.html similarity index 94% rename from userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointedit.html rename to userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.html index cc2ce7acc7f7ded6923af4ca463ac46b57f0d9e3..4036bdf91c79c251abf0b8d90fe8f8b87156b28d 100644 --- a/userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointedit.html +++ b/userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointEdit.html @@ -32,7 +32,7 @@ \ No newline at end of file diff --git a/userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointlist.html b/userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointList.html similarity index 95% rename from userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointlist.html rename to userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointList.html index e138635008ac5a083a3c240c7e1b270cf83bc253..b0d53bd6e832c72233fbf6e581d96682383dfab1 100644 --- a/userauth/src/main/resources/template/tpl/sysevemenuauthpoint/sysevemenuauthpointlist.html +++ b/userauth/src/main/resources/template/tpl/sysEveMenuAuthPoint/sysEveMenuAuthPointList.html @@ -38,7 +38,7 @@
\ No newline at end of file diff --git a/web/src/main/resources/template/assets/lib/layui/lay/modules/treetable/tableTreeDj.js b/web/src/main/resources/template/assets/lib/layui/lay/modules/treetable/tableTreeDj.js new file mode 100644 index 0000000000000000000000000000000000000000..cbdd3953c7c4cc91d948c74b4006a6020ab48264 --- /dev/null +++ b/web/src/main/resources/template/assets/lib/layui/lay/modules/treetable/tableTreeDj.js @@ -0,0 +1,696 @@ +layui.define(['table', 'jquery'], function(exports) { + const MOD_NAME = 'tableTreeDj'; + const $ = layui.jquery; + const table = layui.table; + + class Tree { + constructor() { + this.config = { + keyId: "id" // 当前ID + , keyPid: "pid" // 上级ID + , title: "name" // 标题名称字段,此字段td用于绑定单击折叠展开功能 + , indent: '    ' // 缩进.可以是其他字符 + // 图标 + , icon: { + open: 'fa fas fa-caret-down', // 展开时候图标 + close: 'fa fas fa-caret-right', // 折叠时候图标 + } + + // 是否启用展开状态缓存 + // 传true表示启用缓存,占用 localStorage的key = unfoldStatus + // 传具体字符串表示启用, 字符串会设置成key + , showCache: false + , sort: 'asc' // 排序方式.['asc', 'desc'].必须小写 + // 点击展开时候的回调函数 + ,showByPidCallback: {} + + // 点击折叠时候的回调函数 + ,hideByPidCallback: {} + ,defaultShow: false // 全部展开,如果开启缓存,只有缓存里面没有展开状态时候此配置才生效.否则按缓存里面的展开状态来初始化数据 + }; + // 运行数据模板 + this.runTemplate = { + hasChild: [] // 是否有子级[id=>true] + , parentChild: {} // 父子级关系 [pid=> [id, id]] + , level: [] // 层级 [{id:level}] + , childParent: {} // 子级与父级对应关系 [id=>pid] + , dataIndex: {} // 表格 data-index 与 数据id 的对应关系 + , unfoldStatus: {} // id=>true ,true展开, false折叠. + , idArr: [] // id数组 + , pidArr: [] // pid数组 + } + // 实际运行时候的数据 + this.run = {} + + // table参数,作为中转变量,以期二次渲染的时候不用再次传入 + this.objTable = {}; + + // 原始data + this.dataOri = []; + } + + // 渲染 + render(obj, config) { + // 此操作是为了在多次调用render方法的时候,可以忽略obj参数 + if(!!obj) { + this.objTable = obj; + } else { + obj = this.objTable; + } + if(obj.url == null) { + console.error("url不可为空"); + return; + } + + if(!!config) { + this.config = $.extend(this.config, config); + } + + // 整理数据初始状态 + const parseData = obj.parseData || {}; + obj.parseData = (res) => { + if(JSON.stringify(parseData) !== "{}") { + res = parseData(res) + } + this._initDo() + res.rows = this._parse(res.rows); + return res; + } + + // 数据渲染之后,执行的操作 + const done = obj.done || {}; + obj.done = (res, curr, count) => { + this._done(obj, res, curr, count); + if(JSON.stringify(done) !== "{}") { + done(res, curr, count); + } + } + table.render(obj); + } + + // 重载 + reload(tableId, obj) { + this._initDo(); + tableId = tableId || this.objTable.id; + table.reload(tableId, obj); + } + + // 获取table对象 + getTable() { + return table; + } + + + // ================ 以下方法外部也可以调用 ======================== + + // 隐藏全部子级 + hideAll(obj) { + const dataIndex = this.getDataIndex(); + const layId = obj.id; + + for(let id in dataIndex) { + if(this.run.hasChild.indexOf(id) !== -1) { + this.hideByPid(id, layId); + } + } + } + + // 显示全部子级 + showAll(obj) { + const dataIndex = this.getDataIndex(); + const layId = obj.id; + + for(let id in dataIndex) { + if(this.run.hasChild.indexOf(id) !== -1) { + this.showByPid(id, layId); + } + } + } + + getElemTrByIndex(layId, index) { + return $("[lay-id='"+ layId +"'] table tr[data-index='"+ index +"']"); + } + + getElemTdByIndex(layId) { + const title = this.getTitle(); + return $('[lay-id="'+ layId +'"] [data-field="'+ title +'"]') + } + + getElemIconByIndex(layId, index) { + const title = this.getTitle(); + return $("[lay-id='"+ layId +"'] table tr[data-index='"+ index +"'] td[data-field="+ title +"] div span"); + } + + // 根据父元素隐藏子元素 + hideByPid(id, layId) { + const idArr = this.getParentChild(id); + if(!idArr) { + return false; + } + + const dataIndex = this.getDataIndex(); + + // 执行隐藏操作 + Object.keys(idArr).forEach((idChildKey) => { + const idChild = idArr[idChildKey]; + const index = dataIndex[idChild]; + this.hideByDataIndex(layId, index); + + // 递归的执行下级 + this.hideByPid(idChild, layId); + }); + + // 图标改为 close + const index = dataIndex[id]; + const iconClose = this.getIconClose(); + const elemIcon = this.getElemIconByIndex(layId, index); + elemIcon.removeClass().addClass(iconClose); + + // 当前ID 折叠状态设为 false + this.setUnfoldStatus(id, false); + + this._hideByPidCallback(idArr); + } + + showByPid(id, layId) { + const idArr = this.getParentChild(id); + if(!idArr) { + return false; + } + + const dataIndex = this.getDataIndex(); + + // 当前折叠状态, 执行展开操作 + Object.keys(idArr).forEach((idChildKey) => { + const idChild = idArr[idChildKey]; + const index = dataIndex[idChild]; + this.showByDataIndex(layId, index); + }); + + // 更换图标 + // 图标改为 open + const index = dataIndex[id]; + const iconOpen = this.getIconOpen(); + const elemIcon = this.getElemIconByIndex(layId, index); + elemIcon.removeClass().addClass(iconOpen); + + // 当前ID 折叠状态设为 true + this.setUnfoldStatus(id, true); + + // 回调函数 + this._showByPidCallback(idArr); + } + + // 根据 data-index 隐藏一行 + hideByDataIndex(layId, index) { + const elem = this.getElemTrByIndex(layId, index); + elem.addClass('layui-hide'); + } + + // 根据 data-index 显示一行 + showByDataIndex(layId, index) { + const elem = this.getElemTrByIndex(layId, index); + elem.removeClass('layui-hide'); + } + + // ================== 获取器 ==================== + // 获取主键 key + + getDataOri() { + return this.dataOri; + } + + getRun() { + return this.run; + } + + getKeyId() { + return this.config.keyId; + } + + // 获取上级 key + getKeyPid() { + return this.config.keyPid; + } + + // 获取要缩进的字段 + getTitle() { + return this.config.title; + } + + // 获取缩进字符 + getIndent() { + return this.config.indent; + } + + // 获取图标开启 + getIconOpen() { + return this.config.icon.open; + } + + // 获取图标关闭 + getIconClose() { + return this.config.icon.close; + } + + // 获取层级 + getLevel(id) { + if(!!id) { + const level = this.run.level; + for(let i=0; i { + const id = obj[keyId]; + this.run.idArr.push(id); + }); + + // 二. pid数组 + data.forEach((obj) => { + const pid = obj[keyPid]; + if(this.run.idArr.indexOf(pid) !== -1) { + // 判断本条pid对应的数据是否存在 + if(this.run.pidArr.indexOf(pid) === -1) { + // 如果没有才添加 + this.run.pidArr.push(pid); + } + } + }); + + // 三. 子级与父级 / 父级与子级 对应关系 + data.forEach((obj) => { + const id = obj[keyId]; + const pid = obj[keyPid]; + + if(this.run.idArr.indexOf(id) !== -1 && this.run.pidArr.indexOf(pid) !== -1) { + // 整理子级与父级对应关系 + this.run.childParent[id] = pid; + + // 整理父级与子级对应关系 + let parentChild = this.run.parentChild[pid] || []; + parentChild.push(id); + this.run.parentChild[pid] = parentChild; + } + }); + + // 四. hasChild, level + data.forEach((obj) => { + const id = obj[keyId]; + const pid = obj[keyPid]; + + // 1. 整理 hasChild + if(this.run.idArr.indexOf(pid) !== -1) { + // 数据真实存在才添加到 hasChild + // 1. 整理 hasChild 是否有子级[id1, id2, id3] + if (this.run.hasChild.indexOf(pid) === -1) { + // 没有才追加 + this.run.hasChild.push(pid); + } + } + + // 2. 整理 level, 根据当前向上找pid.一直找到不存在. + let hasParent = true; + let level = 0; + let idCheck = id; + while(hasParent) { + // 判断当前父级是否存在.不存在则退出 + if(!this.run.childParent.hasOwnProperty(idCheck)) { + hasParent = false; + break; + } + + // 获取父级ID,用于下次检测 + idCheck = this.run.childParent[idCheck]; + level++; + } + this.run.level.push({"id": id, "level": level}); + + }); + } + + // 开始渲染 + _parseDo(data) { + // 显示图标 -- 给标题增加图标span + data = this._showIcon(data); + + // 显示缩进 + data = this._showIndent(data); + + // 排序, 使子级紧挨在父级下面 + data = this._disposalSortParent(data); + return data; + } + + // 数据整理(总) - 获取数据之后,渲染数据之前. + _parse(data) { + if(!data) data = []; + + // 保留原始data + this._setDataOri(data); + + // 整理渲染时候的数据.this.run + this._parseInit(data); + + // 开始渲染 + data = this._parseDo(data) + return data; + } + + // 整理done之前的准备工作 + _doneInit(data) { + // 一点扫尾工作,必须等待整理完数据才可以执行 + // 整理 data-index 与 id 的对应关系,点击得到 data-index => $(data-index) => id; id => dataIndex[id] => data-index + this._disposalDataIndex(data); + } + + _doneDo(obj, data) { + const id = obj.id + // 初始化展开状态, 优先根据缓存确定是否展开,缓存没有则判断是否默认展开,以上不符合则隐藏子级 + this._initShow(data, obj); + + // 给标题绑定点击事件 + this._bindTitleClick(id); + } + + // 数据渲染之后,执行的操作 + _done(obj, res, curr, count) { + this._doneInit(res.rows); + this._doneDo(obj, res.rows); + } + + // 初始化展开状态, 根据缓存确定是否展开 + _initShow(data, obj) { + const layId = obj.id + const that = this; + + // 判断是否有缓存存在 + const hasUnfold = that.getUnfoldStatus() + if(JSON.stringify(hasUnfold) !== '{}') { + const keyId = this.getKeyId(); + data.forEach((item) => { + const id = item[keyId]; + + // 判断当前折叠还是展开 + const unfoldId = that.getUnfoldStatus(id); + if(unfoldId) { + // 下级展开 + that.showByPid(id, layId); + } else { + // 下级折叠 + that.hideByPid(id, layId); + } + }); + return; + } + + const defaultShow = that._getDefaultShow() + if(defaultShow) { + // 如果缓存不存在,则判断是否配置全部展开 + that.showAll(obj) + } else { + // 否则全部折叠 + that.hideAll(obj) + } + } + + _titleClick(e) { + const that = e.data.that + const layId = e.data.layId + + var index = $(e.target).parents('tr').attr("data-index"); + let id; + $.each(that.getDataIndex(), function (key, value) { + if (parseInt(index) === value) { + id = key; + } + }); + + // 判断当前折叠还是展开 + const unfoldId = that.getUnfoldStatus(id); + if(unfoldId) { + // 下级折叠 + that.hideByPid(id, layId); + } else { + // 下级展开 + that.showByPid(id, layId); + } + } + + // 给标题绑定点击事件 + _bindTitleClick(layId) { + const param = { + layId: layId, + that: this + } + + const tdTitle = this.getElemTdByIndex(layId) + tdTitle.off('click').bind('click', param, this._titleClick) + } + + // 整理数据 - 整理 layui.table 行中的 data-index 与 数据id 的对应关系[id=>index] + _disposalDataIndex(data) { + let dataIndex = {}; + const keyId = this.getKeyId(); + data.forEach((item, index) => { + const id = item[keyId]; + dataIndex[id] = index; + }) + this.run.dataIndex = dataIndex; + } + + // 排序 - 使子级紧挨在父级下面 + _disposalSortParent(data) { + const resData = []; + + const level = this.getLevel(); + const pc = this.getParentChild(); + const sort = this.getSort(); + + // 1. 先排序顶级 + const dataTop = []; + for(let i=0; i 0; + while (dataTopHas) { + const id = dataTop[0]; + + const i = this._getdataOriIndexById(id, data); + + // 先将值取出来存入 resData 中 + resData.push(data[i]); + + // 再从 data 中删除这个元素. 注意要用完再删 + data.splice(i, 1); + dataTop.splice(0, 1); + + let child = pc[id]; + if(child) { + if(sort !== 'asc') { + child = child.reverse(); + } + + dataTop.splice(0, 0, ...child); + } + + dataTopHas = dataTop.length > 0; + } + + return resData; + } + + // 获取某id=x所在某个数组的位置 + _getdataOriIndexById(id, data) { + const keyId = this.getKeyId(); + for(let i=0; i { + const id = item[keyId]; + const title = this.getTitle(); + let indentItem = ''; + let levelValue = 0; + for(let i=0; i { + const id = item[keyId]; + const title = this.getTitle(); + const iconClose = this.getIconClose(); + if(hasChild.indexOf(id) !== -1) { + item[title] = '' + item[title]; + } + tmp.push(item); + }); + return tmp; + } + + // 展开回调函数 + _showByPidCallback(idArr) { + let callback = this.config.showByPidCallback + if(JSON.stringify(callback) !== "{}") { + callback(idArr); + } + } + + // 折叠回调函数 + _hideByPidCallback(idArr) { + let callback = this.config.hideByPidCallback + if(JSON.stringify(callback) !== "{}") { + callback(idArr); + } + } + + // 获取是否默认展开 + _getDefaultShow() { + return this.config.defaultShow + } + + _setDefaultShow(defaultShow) { + this.config.defaultShow = defaultShow + } + + _setDataOri(dataOri) { + this.dataOri = JSON.parse(JSON.stringify(dataOri)); + } + + clone() { + return new Tree(); + } + } + + const obj = new Tree(); + exports(MOD_NAME, obj) +}); \ No newline at end of file diff --git a/web/src/main/resources/template/assets/lib/layui/lay/modules/treetable/treeGrid.js b/web/src/main/resources/template/assets/lib/layui/lay/modules/treetable/treeGrid.js deleted file mode 100644 index f2edb12d4b83049c74553e86e03487fa9ee851f8..0000000000000000000000000000000000000000 --- a/web/src/main/resources/template/assets/lib/layui/lay/modules/treetable/treeGrid.js +++ /dev/null @@ -1,2718 +0,0 @@ -layui.config({}).extend({}).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: { //全局配置项,表格级别 - indexName: 'lay_table_index', //下标索引名 - cols: { //节点级别的附加字段 - isCheckName: 'lay_is_checked', //选中状态(true,false) - isRadio: 'lay_is_radio', //单选状态(true,false) - isOpen: 'lay_is_open', //是否展开节点 - isShow: 'lay_is_show', //是否显示节点 - level: 'lay_level', //节点的层级关系(不需要设置) - children: 'children', //存放下级的变量 - cheDisabled: 'lay_che_disabled', //禁止多选(true,false) - radDisabled: 'lay_rad_disabled', //禁止单选(true,false) - iconOpen: 'lay_icon_open', //打开的图标 - iconClose: 'lay_icon_close', //关闭的图标 - icon: 'lay_icon' //叶子节点图标 - }, - initWidth: { //默认列宽度定义 - checkbox: 48, - space: 15, - numbers: 40, - radio: 48 - } - } - /** - * 缓存数据 - * - * 结构图示 - * cache{} 缓存(对象) - * key['data']{} 全部数据缓存(对象) - * key[list][] 列表数据对象(数组) - * key[map]{} 列表数据Map对象(Map) - * key[treeList][] 树状结构的对象(数组) - * key['cla']{} 全部已初始化过的Calss对象类(注意渲染是异步执行) - * key['claIds'][] 全部已经吊用过初始化方法的表格类 - * key[claObjs]{key[tableId]} 全部已经初始化好的cla对象 - * - */ - , - cache: { - tableId: { - data: { - list: [], //列表数据 - map: {}, //列表数据以idField或唯一值作为key的Map数据 - treeList: [], //树状数据 - upIds: [] //父节点集合 在一次外部请求前严格按照第一次的顺序 - } - }, - cla: { - claIds: { - tableId: true - }, - claObjs: { - tableId: {} - } - }, - selectcode: { //数据字典缓存 - demokey: [{ - key: { - value: '' - } - }] - } - }, - index: layui.table ? (layui.table.index + 10000) : 0, - /** - * 设置全局项 - * @param options - * @return {table} - */ - set: function(options) { - var that = this; - that.config = $.extend({}, that.config, options); - return that; - }, - /** - * 事件监听 - * @param events - * @param callback - * @return {*} - */ - on: function(events, callback) { - return layui.onevent.call(this, MOD_NAME, events, callback); - }, - getClass: function(tableId) { - return table.cache.cla.claObjs[tableId];; - }, - pushClass: function(tableId, that) { - table.cache.cla.claObjs[tableId] = that; - }, - isCalss: function(tableId) { - var ids = this.cache.cla.claIds || {}; - return ids.hasOwnProperty(tableId) || false; - }, - isClassYes: function(tableId) { - var ids = this.cache.cla.claIds || {}; - return ids[tableId] || false; - }, - pushClassIds: function(tableId, is) { - this.cache.cla.claIds[tableId] = is; - }, - setObj: function(tableId, key, o) { - if(!this.obj[tableId]) this.obj[tableId] = {}; - this.obj[tableId][key] = o; - }, - getObj: function(tableId, key) { - return this.obj[tableId] ? this.obj[tableId][key] : null; - }, - /** - * 获取列表数据 - */ - getDataList: function(tableId) { - if(table.cache[tableId]) { - return table.cache[tableId].data.list; - } - return []; - }, - /** - * 设置列表数据 - */ - setDataList: function(tableId, list) { - if(!table.cache[tableId]) table.cache[tableId] = {}; - if(!table.cache[tableId].data) table.cache[tableId].data = {}; - if(!table.cache[tableId].data.list) table.cache[tableId].data.list = []; - table.cache[tableId].data.list = list; - }, - /** - * 获取列表数据 - */ - getDataMap: function(tableId) { - if(table.cache[tableId]) { - return table.cache[tableId].data.map; - } - return {}; - } - /** - * 设置列表数据 - */ - , - setDataMap: function(tableId, map) { - if(!table.cache[tableId]) table.cache[tableId] = {}; - if(!table.cache[tableId].data) table.cache[tableId].data = {}; - if(!table.cache[tableId].data.map) table.cache[tableId].data.map = {}; - table.cache[tableId].data.map = map; - } - /** - * 获取树状数据 - */ - , - getDataTreeList: function(tableId) { - if(table.cache[tableId]) { - return table.cache[tableId].data.treeList; - } - return []; - } - /** - * 设置树状数据 - */ - , - setDataTreeList: function(tableId, treeList) { - if(!table.cache[tableId]) table.cache[tableId] = {}; - if(!table.cache[tableId].data) table.cache[tableId].data = {}; - if(!table.cache[tableId].data.treeList) table.cache[tableId].data.treeList = {}; - table.cache[tableId].data.treeList = treeList; - } - /** - * 获取根节点数据 - */ - , - getDataRootList: function(tableId) { - if(table.cache[tableId]) { - return table.cache[tableId].data.upIds || []; - } - return []; - } - /** - * 设置根节点数据 - */ - , - setDataRootList: function(tableId, rootList) { - if(!table.cache[tableId]) table.cache[tableId] = {}; - if(!table.cache[tableId].data) table.cache[tableId].data = {}; - if(!table.cache[tableId].data.upIds) table.cache[tableId].data.upIds = []; - table.cache[tableId].data.upIds = rootList; - } - /** - * 初始化 - * @param filter - * @param settings - * @return {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; - } - /** - * 渲染入口方法(核心入口) - */ - , - render: function(options) { - table.pushClassIds(options.id); - var inst = new Class(options); - return thisTable.call(inst); - } - /** - * 对应的表格加载完成后执行 - * @param tableId - * @param fn - */ - , - ready: function(tableId, fn) { - var is = false; - var myDate = new Date(); - - function isReady() { - if(tableId) { - var that = table.getClass(tableId); - if(that && that.hasOwnProperty('layBody')) { - fn(that); - is = true; - } else { - var myDate2 = new Date(); - var i = myDate2.getTime() - myDate.getTime(); - if(i <= (1000 * 10) && !is) { //大于10秒退出 - setTimeout(isReady, 50); - } - } - } - } - if(tableId && fn) { - setTimeout(isReady, 50); - } - } - /** - * 获取表格选中记录 - * @param tableId - * @return {{data: Array, isAll: boolean}} - */ - , - checkStatus: function(tableId) { - var nums = 0, - invalidNum = 0, - arr = [], - data = table.getDataList(tableId) || []; - //计算全选个数 - layui.each(data, function(i, item) { - if(item.constructor === Array) { - invalidNum++; //无效数据,或已删除的 - return; - } - if(item[table.config.cols.isCheckName]) { - nums++; - arr.push(table.clearCacheKey(item)); - } - }); - return { - data: arr //选中的数据 - , - isAll: data.length ? (nums === (data.length - invalidNum)) : false //是否全选 - }; - } - /** - * 设置表格复选状态 - * @param tableId - * @param value 此值存在时为设置操作 - * @returns {*} - */ - , - setCheckStatus: function(tableId, fildName, ids) { - var retObj = null; - var that = table.getClass(tableId), - invalidNum = 0, - arr = [], - data = table.getDataList(tableId) || [], - childs = that.layBody.find('input[name="layTableCheckbox"]') //复选框 - ; - if(fildName && ids) { //设置选中 - var idsarr = ids.split(','); - idsarr.forEach(function(o) { - var temo = null; - data.forEach(function(e) { - var b1 = e[fildName] + ""; - var b2 = o + ""; - if(b1 == b2) { - temo = e; - return; - }; - }); - if(temo) { - var v = temo[table.config.indexName]; - that.layBody.find('input[name="layTableCheckbox"][value="' + v + '"]').prop("checked", true); - that.setCheckData(v, true); - } - }); - that.syncCheckAll(); - that.renderForm('checkbox'); - } - return retObj; - } - /** - * 表格单选状态 - * @param tableId - * @param value 此值存在时为设置操作 - * @returns {*} - */ - , - radioStatus: function(tableId) { - var retObj = null; - var nums = 0, - invalidNum = 0, - arr = [], - data = table.getDataList(tableId) || []; - var v = $("input[name='" + TABLE_RADIO_ID + tableId + "']:checked").val(); - v = parseInt(v); - data.forEach(function(e) { - if(e[table.config.indexName] == v) { - retObj = e; - }; - }); - return table.clearCacheKey(retObj); - } - /** - * 设置表格单选状态 - * @param tableId - * @param value 此值存在时为设置操作 - * @returns {*} - */ - , - setRadioStatus: function(tableId, fildName, value) { - var retObj = null; - var nums = 0, - invalidNum = 0, - arr = [], - data = table.getDataList(tableId) || []; - - if(fildName && value) { //设置选中 - data.forEach(function(e) { - var b1 = e[fildName] + ""; - var b2 = value + ""; - if(b1 == b2) { - retObj = e; - return; - }; - }); - - if(retObj) { - var v = retObj[table.config.indexName]; - $("input:radio[name='" + TABLE_RADIO_ID + tableId + "'][value='" + v + "']").prop("checked", true); - form.render('radio'); - } - } - return retObj; - } - /** - * 清除临时Key - * @param data - * @return {*} - */ - , - clearCacheKey: function(data) { - data = $.extend({}, data); - delete data[table.config.cols.isCheckName]; - delete data[table.config.indexName]; - return data; - } - /** - * 刷新数据 - * @param id - * @param options - * @return {*} - */ - , - query: function(tableId, options) { - var that = table.getClass(tableId); - that.renderTdCss(); - if(that.config.data && that.config.data.constructor === Array) delete that.config.data; - that.config = $.extend({}, that.config, options); - that.pullData(that.page, that.loading()); - } - /** - * 此方法为整体重新渲染(重量级刷新方法) - * @param id - * @param options - */ - , - reload: function(tableId, options) { - var config = thisTable.config[tableId]; - 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; - config.cols = options.cols; - return table.render($.extend(true, {}, config, options)); - } - /** - * 添加一行或多行数据 - * @param tableId 表格id - * @param index 在第几个位置插入(从0开始) - * @param data 数据 - * @returns {*} - */ - , - addRow: function(tableId, index, data) { - var that = table.getClass(tableId), - options = that.config, - uo = [] //父级节点 - , - treeList = table.getDataTreeList(tableId), - list = table.getDataList(tableId) || []; - that.resetData(data); - //插入到父节点后面 - list.splice(index, 0, data); //更新缓存 - table.kit.restNumbers(list); //重置下标 - table.setDataMap(tableId, that.resetDataMap(list)); //处理map - if(options.isTree) { //处理层级 - //1、处理父级 2、处理treeObj 3、层级 - var uo = that.treeFindUpData(data); - if(uo) { - var clist = uo.children; - uo.children.push(data); - data[table.config.cols.level] = uo[table.config.cols.level] + 1; - } else { - data[table.config.cols.level] = 1; - treeList.push(data); - } - } - //生成html - var tds = that.renderTr(data, data[table.config.indexName]); - var trs = '' + tds.join('') + ''; - if(index == 0) { //在第一个位置插入 - var tbody = that.layBody.find('table tbody'); - $(tbody).prepend(trs); - that.layBody.find(".layui-none").remove(); - } else { - var o = that.layBody.find('[data-index=' + (index - 1) + ']'); //父节点dom树 - $(o).after(trs); - } - that.renderForm(); - if(options.isPage) that.renderPage(that.config.page.count + 1); //分页渲染 - that.restNumbers(); - that.events(); - if(options.isTree) { //展开节点 - that.treeNodeOpen(uo, true); - that.renderTreeConvertShowName(uo); - } - } - /** - * 删除一行或多行数据 - * (如果是树状则删除自己和子节点) - * @param tableId - * @param data(1、数组;2、对象) - */ - , - delRow: function(tableId, data) { - //1、页面清除 2、缓存清除 - var that = table.getClass(tableId), - options = that.config, - list = table.getDataList(tableId); - var sonList = []; //需要删除的数据 - var delIds = {}; //需要删除的数据map - var delDatas = []; - var upDelDatas = []; //全部待删除节点的父节点(处理折叠) - if(!that || !data) return; - if(table.kit.isArray(data)) { //是数组,删除多个 - delDatas = data; - } else { - delDatas[0] = data; - } - delDatas.forEach(function(temo) { //记录全部父节点 - var uo = that.treeFindUpData(temo); - if(uo) { - upDelDatas.push(uo); - } - }); - sonList = options.isTree ? table.treeFindSonList(that.config.id, delDatas) : delDatas; - //页面元素处理 - sonList.forEach(function(temo) { - var index = temo[table.config.indexName]; - delIds[index] = index; //设置代删除的id集合 - var tr = that.layBody.find('tr[data-index="' + index + '"]'); - tr.remove(); - }); - //数据处理 - that.restNumbers(); - var newList = []; //重构一个新的数组 - for(var i = 0, len = list.length; i < len; i++) { - var isP = true; - var temo1 = null; - sonList.forEach(function(temo) { - if(temo[table.config.indexName] === list[i][table.config.indexName]) { - isP = false; - } - }); - if(isP) { - newList.push(list[i]); - } - } - table.kit.restNumbers(newList); - //that.resetDatas(newList);//更新缓存数据 - //处理父级节点 - upDelDatas.forEach(function(temo) { - that.renderTreeConvertShowName(temo); - }); - if(options.isPage) that.renderPage(that.config.page.count - Object.keys(delIds).length); //分页渲染 - //处理list - table.setDataList(tableId, newList); - //处理map - table.setDataMap(tableId, that.resetDataMap(newList)); - //处理树结构 - table.setDataTreeList(tableId, that.resetDataTreeList(newList, table.getDataRootList(tableId))); - that.events(); - } - /** - * 更新指定的记录 - * @param obj - * @param index - */ - , - updateRow: function(tableId, obj) { - var that = table.getClass(tableId); - if(!that || !obj) return; - var id = obj[that.config.idField]; - //更新缓存数据 - var maps = table.getDataMap(tableId); - var thisobj = maps[id]; - if(thisobj) { - $.extend(thisobj, obj); - } else { - return; - } - //更新页面 - var oi = thisobj[table.config.indexName]; - var tds = that.renderTr(thisobj, oi); - var tr = that.layBody.find('tr[data-index=' + oi + ']'); - $(tr).html(tds); - }, - treeNodeOpen: function(tableId, o, isOpen) { - var that = table.getClass(tableId); - if(!that || !o) return; - that.treeNodeOpen(o, isOpen); - } - /** - * 折叠或展开全部(默认为展开全部节点) - * @param tableId - * @param isOpen 展开还是折叠(默认值为true 展开) - */ - , - treeOpenAll: function(tableId, isOpen) { - var that = table.getClass(tableId); - if(!that) return; - if(isOpen === undefined) { - isOpen = true; - } - var list = table.getDataList(tableId); - if(!list) return; - list.forEach(function(temo) { - that.treeNodeOpen(temo, isOpen); - }); - } - /** - * 获取全部需要子节点对象集合 - * @param data(数组或对象) - */ - , - treeFindSonList: function(tableId, data) { - var that = table.getClass(tableId); - if(!that || !data) return []; - var delDatas = []; - var sonList = []; //需要删除的数据 - var delIds = {}; //需要删除的数据map - if(table.kit.isArray(data)) { //是数组,删除多个 - delDatas = data; - } else { - delDatas[0] = data; - } - delDatas.forEach(function(temo) { - if(temo.children.length > 0) { - var temSonList = that.treeFindSonData(temo); - temSonList.forEach(function(temii) { - if(!delIds[temii[table.config.indexName]]) { - sonList.push(temii); - delIds[temii[table.config.indexName]] = temii[table.config.indexName]; - } - }); - } - sonList.push(temo); - delIds[temo[table.config.indexName]] = temo[table.config.indexName]; - }); - return sonList; - }, - treeFindUpDatas: function(tableId, o) { - var that = table.getClass(tableId); - if(!that || !o) return []; - return that.treeFindUpDatas(o); - }, - treeFindUpData: function(tableId, o) { - var that = table.getClass(tableId); - if(!that || !o) return []; - return that.treeFindUpData(o); - } - /** - * 获取全部需要子节点id集合 - * @param data(数组或对象) - */ - , - treeFindSonIds: function(tableId, data) { - var delIds = []; - var sonList = table.treeFindSonList(tableId, data); - sonList.forEach(function(temo) { - delIds.push([table.config.indexName]); - }); - return delIds; - } - /** - * 获取全部的id字段集合 - * @param tableId - * @param data - * @returns {Array} - */ - , - treeFindSonIdFields: function(tableId, data) { - var idField = []; - var that = table.getClass(tableId); - var sonList = table.treeFindSonList(tableId, data); - sonList.forEach(function(temo) { - idField.push(temo[that.config.idField]); - }); - return idField; - }, - treeIconRender: function(tableId, o) { - var that = table.getClass(tableId); - if(!that || !o) return []; - return that.treeIconRender(o, false); - } - /** - * 工具方法对象 - */ - , - kit: { - isArray: function(o) { - return Object.prototype.toString.call(o) === '[object Array]'; - }, - isNumber: function(val) { - var regPos = /^\d+(\.\d+)?$/; //非负浮点数 - var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数 - if(regPos.test(val) || regNeg.test(val)) { - return true; - } else { - return false; - } - - }, - restNumbers: function(list) { - if(!list) return; - var i = 0; - list.forEach(function(o) { - o[table.config.indexName] = i; - i++; - }); - } - } - } - //操作当前实例 - , - 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 = 'treeGrid', - 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', - TABLE_RADIO_ID = 'table_radio_', - ELEM_FILTER = '.layui-table-filter', - TREE_ID = 'treeId', - TREE_UPID = 'treeUpId', - TREE_SHOW_NAME = 'treeShowName', - TREE_KEY_MAP = 'tree_key_map' - //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 ''; - }(), '', (options.fixed ? '{{# }; }}' : ''), '{{# }); }}', '', '{{# }); }}', '', '
', '
', '{{# if(item2.type === "checkbox"){ }}' //复选框 - , '', '{{# } else { }}', '{{item2.title||""}}', '{{# if(!(item2.colspan > 1) && item2.sort){ }}', '', '{{# } }}', '{{# } }}', '
', '
' - ].join(''); - } - /** - * 行内过滤区域 - */ - , - TPL_FILTER = function(options) {} - //tbody区域模板 - , - TPL_BODY = ['', '', '
'].join('') - //主模板 - , - TPL_MAIN = ['
' - - , '{{# if(d.data.toolbar){ }}', '
', '{{# } }}' - - , '
', '{{# var left, right; }}', '
', TPL_HEADER(), '
', '
', TPL_FILTER(), '
', '
', TPL_BODY, '
' - - , '{{# if(left){ }}', '
', '
', TPL_HEADER({ - fixed: true - }), '
', '
', TPL_BODY, '
', '
', '{{# }; }}' - - , '{{# if(right){ }}', '
', '
', TPL_HEADER({ - fixed: 'right' - }), '
', '
', '
', TPL_BODY, '
', '
', '{{# }; }}', '
' - - , '{{# if(d.data.isPage){ }}', '
', '
', '
', '{{# } }}' - - /*,''*/ - , '
' - ].join(''), - _WIN = $(window), - _DOC = $(document) - - //构造器 - , - Class = function(options) { - var that = this; - that.index = ++table.index; - that.config = $.extend({}, that.config, table.config, options); - that.configFirst = $.extend({}, that.config, table.config, options); - that.render(); - table.pushClass(options.id, that); - }; - /** - * 表格行为属性(默认配置) - */ - Class.prototype.config = { - limit: 10 //每页显示的数量 - , - loading: true //请求数据时,是否显示loading - , - cellMinWidth: 60 //所有单元格默认最小宽度 - , - heightRemove: [] //非固定高度情况下,不参与计算的高度 - , - text: { - none: '无数据' - }, - isFilter: false //是否开启行内过滤 - , - method: 'post' //默认以post方式请求后台 - , - radDisabledNum: 0 //禁止单选的记录数 - , - cheDisabledNum: 0 //禁止多选的记录数 - //树相关图表 - , - branch: ['', ''] //父节点 - , - leaf: '' //叶节点 - , - iconOpen: true //默认开启树节点图标 - , - isOpenDefault: true //默认展开还是折叠节点 - , - parseData: null //加载数据后的回调方法 - , - onClickRow: null //行单击事件 - , - onDblClickRow: null //行双击事件 - , - onBeforeCheck: null //复选前事件 - , - isTree: true //默认为树表格 - , - isPage: false //不分页 - , - height: '100%' //默认高度100% - }; - Class.prototype.configFirst = {}; //页面定义时原始参数 - - 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'); - that.test(); - //请求参数的自定义格式 - 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.columnWidthInit(); //列宽度计算 - //开始插入替代元素 - 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.renderTdCss(); - //各级容器 - 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.layFilter = reElem.find(ELEM_FILTER); //行内过滤条件区域 - that.layTool.html( - laytpl($(options.toolbar).html() || '').render(options) - ); - if(options.height) { - that.tableHeight(); //表格高度计算 - that.resizeHeight(); //高度控制 - that.renderCss(); - } - //如果多级表头,则填补表头高度 - 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'))); - } - //渲染过滤区域 - if(options.isFilter) { - that.layFilter.html( - that.renderFilter() - ); - } - - that.layHeader.find(".layui-table thead tr").append('
'); - - //请求数据 - that.pullData(that.page, that.loading()); - that.test(); - }; - //根据列类型,定制化参数 - Class.prototype.initOpts = function(item) { - var that = this, - options = that.config; - //让 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 || table.config.initWidth[item.type]; - } - - if(options.isFilter) { //开启行内过滤 - if(item.isFilter != false) { - item.isFilter = true; - } - } - }; - - /** - * 表格获取父容器高度 - * @param tableId - */ - Class.prototype.getParentDivHeight = function(tableId) { - var th = $("#" + tableId).parent().height(); - return th; - }; - - /** - * 获取列定义 - * @param tableId - */ - Class.prototype.getCols = function(field) { - var that = this; - var o = {}; - var cols = that.config.cols[0]; - var isInt = false; - var reg = /^[0-9]+.?[0-9]*$/; - if(reg.test(field)) { //数字 - isInt = true; - } - for(var ii in cols) { - if(isInt) { - if(ii == parseInt(field)) return cols[ii]; - } else { - if(field == cols[ii].field) return cols[ii]; - } - } - return o; - }; - - //表格重载 - 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.configFirst = $.extend({}, that.config, options); - //获取行内过滤的值 - that.render(); - }; - //页码 - Class.prototype.page = 1; - /** - * 重置下标(插入删除等操作) - * 1、data-index中的下标 - * 2、tr中data的值 - * 3、下标字段的值 - * @param list - */ - Class.prototype.restNumbers = function() { - var that = this, - options = that.config; - var trs = that.layBody.find('table tbody tr'); - var i = 0; - trs.each(function(o) { - $(this).attr("data-index", i); - $(this).find(".laytable-cell-numbers p").text(i + 1); - $(this).data('index', i); - i++; - }); - } - - /** - * 初始化节点 - * 在每一次数据加载时只执行一次 - * query、reload时会执行 - * @param o - */ - Class.prototype.resetData = function(n) { - var that = this, - options = that.config; - if(options.isTree) { - if(!n.hasOwnProperty(table.config.cols.isOpen)) { //如果不存在该属性则默认为true - n[table.config.cols.isOpen] = options.isOpenDefault; - } - if(!n.hasOwnProperty(table.config.cols.isShow)) { //如果不存在该属性则默认为true - n[table.config.cols.isShow] = options.isOpenDefault ? true : false; - } - } - //禁止设置 - if(!n.hasOwnProperty(table.config.cols.cheDisabled)) { //不存在则默认为false - n[table.config.cols.cheDisabled] = false; - } - //记录禁止多选、单选的记录数 - if(n[table.config.cols.cheDisabled]) options.cheDisabledNum++; - if(n[table.config.cols.radDisabled]) options.radDisabledNum++; - n.children = []; - } - /** - * 构建map数据 - * @param list - * @return {{}} - */ - Class.prototype.resetDataMap = function(list) { - var that = this, - options = that.config; - var field_Id = options.idField; - var map = {}; - if(!isNull(list)) { - list.forEach(function(o) { - map[o[field_Id]] = o; - }); - } - return map; - } - Class.prototype.resetDataresetRoot = true; //是否重新确定根节点 - /** - * 确定根节点id(重新登录根节点) - */ - Class.prototype.resetDataRoot = function(list) { - var that = this, - options = that.config; - var field_Id = options[TREE_ID]; - var field_upId = options[TREE_UPID]; - var map = table.getDataMap(that.config.id); //列表map,fieldId为key //设置map数据集合 - var rootList = table.cache[options.id].data.upIds || []; //根节点list集合 - var rootMap = {}; //根节点map集合 - table.cache[options.id].data.upIds = []; - rootList = table.cache[options.id].data.upIds; - for(var i = 0; i < list.length; i++) { - var temo = list[i]; - if(!map[temo[field_upId]]) { //没有找到父节点 - if(!rootMap[temo[field_upId]]) { //还不存在 - var temis = true; - rootList.forEach(function(temoo) { - if(temoo === temo[field_upId]) temis = false; - }); - if(temis) rootList.push(temo[field_upId]); - } - rootMap[temo[field_upId]] = temo[field_upId]; - } - } - return rootList; - } - /** - * 处理树结构 - * 1、原始列表数据 - * 2、根节点集合 - */ - Class.prototype.resetDataTreeList = function(list, rootList) { - var that = this, - options = that.config; - var field_Id = options[TREE_ID]; - var field_upId = options[TREE_UPID]; - var treeList = []; - //处理树结构 - var fa = function(upId) { - var _array = []; - for(var i = 0; i < list.length; i++) { - var n = list[i]; - if(n[field_upId] === upId) { - n.children = fa(n[field_Id]); - _array.push(n); - } - } - return _array; - } - rootList.forEach(function(temo) { - var temTreeObj = fa(temo); //递归 - if(temTreeObj) { - temTreeObj.forEach(function(o) { - treeList.push(o); - }); - } - }); - return treeList; - } - - /** - * 处理数据列表结构 - * 1、树结构 - */ - Class.prototype.resetDataTableList = function(treeList) { - var that = this, - options = that.config; - var field_Id = options[TREE_ID]; - var field_upId = options[TREE_UPID]; - var tableList = []; - //处理表格结构 - var fa2 = function(l, level) { - for(var i = 0; i < l.length; i++) { - var n = l[i]; - n[table.config.cols.level] = level; //设置当前层级 - tableList.push(n); - if(n.children && n.children.length > 0) { - fa2(n.children, 1 + level); - } - } - return; - } - fa2(treeList, 1); - - //设置isOpen 和is_show状态 - tableList.forEach(function(o) { - var uo = that.treeFindUpData(o); - if(!uo || (uo[table.config.cols.isOpen] && uo[table.config.cols.isShow])) { //没有父亲:显示;父亲打开状态(显示状态:显示;隐藏状态:隐藏) - o[table.config.cols.isShow] = true; - } else { - o[table.config.cols.isShow] = false; - } - }); - return tableList; - } - - /** - * 重置当前表格的数据(1、普通列表;2树状表格) - * 将列表数据转成树形结构和符合table展示的列表 - * @param list 列表数据 - * @param field_Id 树形结构主键字段 - * @param field_upId 树形结构上级字段 - * @returns {Array} [0]表格列表 [1]树形结构 - */ - Class.prototype.resetDatas = function(list) { - //console.time("resetDatas"); - var that = this, - options = that.config; - var field_Id = options[TREE_ID]; - var field_upId = options[TREE_UPID]; - var datas = []; - var treeList = []; - var tableList = list; - var map = that.resetDataMap(list); //列表map,fieldId为key //设置map数据集合 - datas.push(tableList); //table结构 - datas.push(treeList) //tree树结构 - datas.push(map) //data数据 map结构 - //设置到内存中去 - table.setDataList(that.config.id, tableList); - table.setDataTreeList(that.config.id, treeList); - table.setDataMap(that.config.id, map); - if(list == null || list.length <= 0) return datas; - //设置默认参数 - for(var i = 0; i < list.length; i++) { - that.resetData(list[i]); - } - if(options.isTree) { //树状 - tableList = []; - table.setDataList(that.config.id, tableList); - var rootList = table.cache[options.id].data.upIds || []; //根节点list集合 - if(rootList.length <= 0 || that.resetDataresetRoot) { //确定根节点 - table.cache[options.id].data.upIds = []; - rootList = that.resetDataRoot(list); - that.resetDataresetRoot = false; - } - treeList = that.resetDataTreeList(list, rootList); - table.setDataTreeList(that.config.id, treeList); //设置树结构到缓存 - tableList = that.resetDataTableList(treeList); - table.setDataList(that.config.id, tableList); //设置数据列表结构到缓存 - } - //console.timeEnd("resetDatas"); - return datas; - } - /** - * 根据id从表格数据中获取对象 - * @param data - * @param field_Id - * @param field_upId - * @returns {Array} - */ - Class.prototype.treeFindDataById = function(u_Id) { - var that = this, - options = that.config; - var e = null; - var list = table.getDataList(that.key); - var key = options[TREE_ID]; - list.forEach(function(o) { - if(o[key] == u_Id) { - e = o; - return; - } - }); - return e; - } - /** - * 获取父节点 - * @param u_Id - */ - Class.prototype.treeFindUpData = function(o) { - var uOjb = null; - var that = this, - options = that.config; - //处理父级 - var key = options[TREE_UPID]; //父节点key名称 - var mapData = table.getDataMap(that.config.id); //获取map形式对象集合 - uOjb = mapData[o[key]]; - return uOjb; - } - /** - * 获取全部父节点集合,返回list(不包含自己) - * @param u_Id - */ - Class.prototype.treeFindUpDatas = function(o) { - var uOjb = null; - var that = this, - options = that.config; - var list = []; - var temf = function(temo) { - var uo = that.treeFindUpData(temo); - if(uo) { - list.push(uo); - temf(uo); - } - }; - temf(o); - return list; - } - /** - * 根据父id获取全部的叶子节点(递归) - * @param o 数据对象 - * @return {string} - */ - Class.prototype.treeFindSonData = function(data) { - var objs = []; - - function f(o) { - if(o.children.length > 0) { - o.children.forEach(function(i) { - objs.push(i); - if(i.children.length > 0) { - f(i); - } - }); - } - } - f(data); - return objs; - }; - /** - * 叶子节点显示转换 - * @param o 数据 - * @param fieldName 树显示列名 - * @returns {string} - */ - Class.prototype.treeConvertShowName = function(o) { - var that = this, - options = that.config; - var isTreeNode = (o.children && o.children.length > 0); - var temhtml = '
' + - function() { //位移量 - var nbspHtml = "" //一次位移 - for(var i = 1; i < o[table.config.cols.level]; i++) { - nbspHtml = nbspHtml + "    "; - } - nbspHtml = nbspHtml + ""; - return nbspHtml; - }() + - function() { //图标或占位符 - var temTreeHtml = ''; - var temTreeIsOpen = o[table.config.cols.isOpen] ? "" : ""; - if(isTreeNode) { //父节点 - temTreeHtml = '' + temTreeIsOpen + '' + - that.treeIconRender(o, true); - } else { //叶子节点 - temTreeHtml += that.treeIconRender(o, true); - } - return temTreeHtml; - }() + - '
'; - return temhtml; - }; - /** - * 节点的展开或折叠 - * @param o 节点数据(树状表格) - * @param isOpen 展开(true)或折叠(false) - * - * 每个节点有两种状态, - * 1、打开状态(isOpen) 打开状态只需在点击瞬间控制,其他时候不需要变动 - * 2、显示状态(显示或隐藏) 显示状态根据父级节点控制,父级节点是显示并且打开状态的则显示,否则不显示,但不影响其打开状态 - */ - Class.prototype.treeNodeOpen = function(o, isOpen) { - var that = this, - tr = that.layBody.find('tr[data-index="' + o[table.config.indexName] + '"]'); - if(!o) { - return - } - o[table.config.cols.isOpen] = isOpen; - //处理树结构 - var fa = function(e) { - if(e.children && e.children.length > 0) { - var temList = e.children; - for(var i = 0; i < temList.length; i++) { - var n = temList[i]; - if(o[table.config.cols.isOpen]) { //打开状态的,关闭 - if(e[table.config.cols.isOpen] && e[table.config.cols.isShow]) { //该节点显示 - var temo = that.layBody.find('tr[data-index="' + n[table.config.indexName] + '"]'); - temo.css('display', ''); - n[table.config.cols.isShow] = true; - } - } else { - var temo = that.layBody.find('tr[data-index="' + n[table.config.indexName] + '"]'); - temo.css('display', 'none'); - n[table.config.cols.isShow] = false; - } - fa(n); - } - } - } - fa(o); - //处理图标 - that.treeIconRender(o, false); - var dbClickI = tr.find('.layui-tree-head'); - if(o[table.config.cols.isOpen]) { //打开状态 - dbClickI.html(''); - } else { - dbClickI.html(''); - } - }; - - /** - * icon渲染 - * @param o - * @param isHtml true(返回html) false(立即渲染) - */ - Class.prototype.treeIconRender = function(o, isHtml) { - var that = this, - options = that.config, - iconOpen = options.iconOpen, - isTreeNode = (o.children && o.children.length > 0); - var temTreeHtml = ''; - if(iconOpen) { - var temf = function() { //自定义图标 - var temhtml = ''; - return temhtml; - } - if(isTreeNode) { //父节点 - if((o[table.config.cols.iconOpen] || o[table.config.cols.iconClose])) { - temTreeHtml = temf(); - } else { - temTreeHtml = '' + (o[table.config.cols.isOpen] ? that.config.branch[1] : that.config.branch[0]) + ''; - } - } else { //叶子节点 - if(o[table.config.cols.icon]) { - temTreeHtml = temf(); - } else { - temTreeHtml += '' + that.config.leaf + ''; - } - } - if(isHtml) { - return temTreeHtml; - } else { - var temdiv = that.layBody.find('tr[data-index="' + o[table.config.indexName] + '"]').find('td[data-field=' + options[TREE_SHOW_NAME] + ']').find('.layui-table-cell'); - $(temdiv).find('div .layui-tree-' + o[options.idField]).remove(); //节点附加div - $(temdiv).find('div').append(temTreeHtml); - } - } else { - return temTreeHtml; - } - } - //获得数据 - 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; - that.filterRulesSet(params); //行内过滤条件 - that.sortSet(params); //排序条件 - $.ajax({ - type: options.method || 'get', - url: options.url, - data: $.extend(params, options.where), - headers: getRequestHeaders(), - dataType: 'json', - success: function(res) { - //移除请求遮罩层 - $("body").find(".mask-req-str").remove(); - that.resetDataresetRoot = true; - //如果有数据解析的回调,则获得其返回的数据 - if(typeof options.parseData === 'function') { - res = options.parseData(res) || res; - } - that.resetDatas(res[response.dataName]); - res[response.dataName] = table.getDataList(options.id); - if(res[response.statusName] != response.statusCode) { - that.renderForm(); - that.layMain.html('
' + (res[response.msgName] || '返回的数据状态异常') + '
'); - } else { - that.renderData(res, curr, res[response.countName]); - options.time = (new Date().getTime() - that.startTime) + ' ms'; //耗时(接口请求+视图渲染) - } - loadIndex && layer.close(loadIndex); - that.events(); - typeof options.done === 'function' && options.done(res, curr, res[response.countName]); - }, - error: function(XMLHttpRequest, e, m) { - //移除请求遮罩层 - $("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 = "../../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); - } - } - }); - } 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); - that.resetDatas(res[response.dataName]); - res[response.countName] = options.data.length; - that.renderData(res, curr, options.data.length); - that.events(); - typeof options.done === 'function' && options.done(res, curr, res[response.countName]); - } - }; - /** - * 设置过滤条件 - */ - Class.prototype.filterRulesSet = function(p) { - var that = this; - p["filterRules"] = JSON.stringify(that.filterRules()); - } - /** - * 获取过滤条件 - * filterRules: - * [ - * {"field":"XXXX","op":"equals","value":["1"],"datatype":"array"} - * ,{"field":"XXXX","op":"contains","value":"3","datatype":"string"} - * ] - */ - Class.prototype.filterRules = function() { - var that = this; - var filterRules = []; - //行内过滤条件 - var list = that.layFilter.find("[name^='filter_']"); - layui.each(list, function(i, o) { - if($(o).val()) { - var tem = { - "field": o.name, - "op": "like", - "value": $(o).val(), - "datatype": "string" - } - filterRules.push(tem); - } - }); - // console.log(filterRules,filterRules.toString(),JSON.stringify(filterRules)); - return filterRules; - } - - //遍历表头 - 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(); - }; - /** - * 渲染节点显示 - * @param callback - */ - Class.prototype.renderTreeConvertShowName = function(o) { - var that = this, - options = that.config, - m = options.elem, - hasRender = m.next('.' + ELEM_VIEW); - var temhtml = that.treeConvertShowName(o); - var temdiv = that.layBody.find('tr[data-index="' + o[table.config.indexName] + '"]').find('td[data-field=' + options[TREE_SHOW_NAME] + ']').find('.layui-table-cell'); - $(temdiv).find('div').remove(); - $(temdiv).prepend(temhtml); - } - /** - * 渲染表格单元格样式(宽度样式设置) - * @param callback - */ - Class.prototype.renderTdCss = function() { - var that = this, - options = that.config, - m = options.elem, - hasRender = m.next('.' + ELEM_VIEW); - var id = that.index + "_" + MOD_NAME + '_td_style'; - hasRender.find("#" + id).remove(); - var styel = ''; - hasRender.append(styel); - } - - /** - * 插件内css - */ - Class.prototype.renderCss = function() { - var that = this, - options = that.config, - m = options.elem, - hasRender = m.next('.' + ELEM_VIEW); - var id = that.index + "_" + MOD_NAME + '_style'; - hasRender.find("#" + id).remove(); - var styel = ''; - hasRender.append(styel); - } - - /** - * 生成单元格 - * @param obj 行数据 - * @param numbers 下标 - * @param cols 列定义数据 - * @param i3 第几列 - */ - Class.prototype.renderTrUpids = function(obj) { - var that = this, - options = that.config; - var tree_upid_key = options[TREE_UPID]; - var upids = ' upids="' + obj["upIds"] + '" '; - var u_id = ' u_id="' + obj[tree_upid_key] + '" ' - var ret = options.isTree ? u_id : ''; - return ret; - } - /** - * 生成单元格 - * @param obj 行数据 - * @param numbers 下标 - * @param cols 列定义数据 - * @param i3 第几列 - */ - Class.prototype.renderTd = function(obj, cols, numbers, i3) { - var that = this, - options = that.config; - var v = obj[cols.field] == null ? '' : String(obj[cols.field]); - - var field = cols.field || i3, - content = v, - cell = that.getColElem(that.layHeader, field); - - var treeImgHtml = ''; - if(options.isTree) { - if(options.treeShowName == cols.field) { - treeImgHtml = that.treeConvertShowName(obj); - } - } - //td内容 - var td = ['', '
' + treeImgHtml + '

' + function() { - var tplData = $.extend(true, { - LAY_INDEX: numbers - }, obj); - //渲染复选框列视图 - if(cols.type === 'checkbox') { - return tplData[table.config.cols.cheDisabled] ? '' : - ''; - } else if(cols.type === 'numbers') { //渲染序号 - return numbers; - } else if(cols.type === 'drop') { //下拉框 - var rowsField = dl.ui.table.drop.findFieldObj(options.cols[0], field); - if(rowsField && rowsField['drop']) { - var o = dl.cache.code.get(rowsField.drop); - return dl.ui.table.drop.findDropLable(rowsField.drop, content); - } - } else if(cols.type === 'radio') { //单选 - return tplData[table.config.cols.radDisabled] ? '' : - ''; - } - - //解析工具列模板 - if(cols.toolbar) { - return laytpl($(cols.toolbar).html() || '').render(tplData); - } - - return cols.templet ? function() { - return typeof cols.templet === 'function' ? - cols.templet(tplData) : - laytpl($(cols.templet).html() || String(content)).render(tplData) - }() : content; - }(), '

'].join(''); - return td; - } - /** - * 生成tr中的一行 - * @param obj 行数据 - * @param numbers 行号 - */ - Class.prototype.renderTr = function(obj, numbers) { - var that = this, - options = that.config; - var tds = []; - that.eachCols(function(i3, cols) { //cols列定义 - var field = cols.field || i3, - content = obj[field]; - if(cols.colspan > 1) return; - var td = that.renderTd(obj, cols, numbers, i3); //td内容 - tds.push(td); - // if(item3.fixed && item3.fixed !== 'right') tds_fixed.push(td); - // if(item3.fixed === 'right') tds_fixed_r.push(td); - }); - return tds; - }; - /** - * 表格数据部分渲染入口 - * @param res - * @param curr - * @param count - * @param sort - */ - 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, obj) { - var uo = that.treeFindUpData(obj); - var display = ""; - if(!obj[table.config.cols.isShow] && options.isTree) { - display = "display: none;"; - } - var tds = [], - tds_fixed = [], - tds_fixed_r = [], - numbers = i1 + options.limit * (curr - 1) + 1; //序号 - if(obj.length === 0) return; - if(!sort) { - obj[table.config.indexName] = i1; - } - tds = that.renderTr(obj, numbers); - 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.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; //记录数据 - table.setDataList(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(); - that.renderPage(count); //分页渲染 - //calss加载完成 - table.pushClassIds(options.id, true); - }; - /** - * 渲染分页 - */ - Class.prototype.renderPage = function(count) { - var that = this, - options = that.config; - //同步分页状态 - if(options.isPage) { - options.page = $.extend({ - elem: 'layui-table-page' + options.index, - count: count, - limit: options.limit, - limits: options.limits || [10, 15, 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.renderFilter = function() { - var that = this, - options = that.config, - VIEW_CLASS = ELEM_VIEW, - index = that.index; //索引 - var v = []; - v.push('
'); - v.push(''); - layui.each(options.cols, function(i, o) { - layui.each(o, function(i2, item2) { - var field = item2.field || i2; - var minW = item2.minWidth ? "data-minwidth='" + item2.minWidth + "'" : ""; - var rowCols = item2.colspan ? 'colspan="' + item2.colspan + '"' : ''; - var rowspan = item2.rowspan ? 'rowspan="' + item2.rowspan + '"' : ''; - var unresize = item2.unresize ? 'data-unresize="true"' : ''; - v.push(''); - - }); - }); - v.push('
'); - v.push('
1) { - tem = 'group'; - } else { - tem = index + "-" + field; - if(item2.type !== "normal") { - tem += " laytable-cell-" + item2.type; - } - } - return tem; - }() + '">'); - if(!item2.isFilter || !item2.field) { //不开启行内过滤或没有列名 - v.push(''); - } else { - v.push(''); - } - v.push('
'); - v.push('
'); - return v.join(''); - }; - //找到对应的列元素 - 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); - } - /** - * 设置排序参数 - * @param p - */ - Class.prototype.sortSet = function(p) { - var that = this; - var sort = []; - var cols = that.config.cols[0]; - cols.forEach(function(t) { - if(t.sortType) { - var tem = { - "field": t.field, - "sort": t.sortType - } - sort.push(tem); - } - }); - p.sort = JSON.stringify(sort); - } - /** - * 设置排序字段 - * @param th - * @param type - * @param pull - * @param formEvent - */ - Class.prototype.sort = function(th, type, pull, formEvent) { - var that = this, - field, res = {}, - options = that.config, - filter = options.elem.attr('lay-filter'), - data = table.getDataList(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'){ //升序 - } else if(type === 'desc'){ //降序 - thisData = layui.sort(data, field, true); - } else { //清除排序 - thisData = layui.sort(data, table.config.indexName); - } - */ - var cols = that.getCols(field); - if(cols) { - cols.sortType = 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.getDataList(that.key); - if(!thisData[index]) return; - if(thisData[index].constructor === Array) return; - thisData[index][table.config.cols.isCheckName] = checked; - }; - //同步全选按钮状态 - Class.prototype.syncCheckAll = function() { - var that = this, - options = that.config; - var list = table.getDataList(that.config.id); - if(!list) return; - var temis = true; //全选 - var checkNum = 0; //选中的个数 - list.forEach(function(t) { - if(!t[table.config.cols.cheDisabled]) { - if(t[table.config.cols.isCheckName]) { - var checkAllElem = that.layBody.find('tr[data-index=' + t[table.config.indexName] + ']').find('input[name="layTableCheckbox"]'); - checkAllElem.prop('checked', true); - checkNum++; - } else { - temis = false; - var checkAllElem = that.layBody.find('tr[data-index=' + t[table.config.indexName] + ']').find('input[name="layTableCheckbox"]'); - checkAllElem.prop('checked', false); - } - } - }); - if(temis) { //设置全选 - var checkAllElem = that.layHeader.find('input[name="layTableCheckbox"]'); - checkAllElem.prop('checked', true); - } - if(checkNum < (list.length - options.cheDisabledNum)) { - var checkAllElem = that.layHeader.find('input[name="layTableCheckbox"]'); - checkAllElem.prop('checked', false); - } - console.time("pullData"); - console.timeEnd("pullData"); - - that.renderForm('checkbox'); - }; - //获取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.test = function() {} - /** - * 窗体变化自适应 - */ - Class.prototype.resize = function() { - var that = this; - //根据父窗体高度设置table的高度 - // 1、table自身顶级容器高度(layui-table-view) - // 2、内容区域高度(layui-table-main) - that.columnWidthInit(); //列宽度计算 - that.tableHeight(); //表格高度计算 - that.resizeHeight(); //高度控制 - that.resizeWidth(); //宽度控制 - }; - - //动态分配列宽高 - Class.prototype.setArea = function() { - var that = this; - that.columnWidthInit(); //列宽度计算 - that.tableHeight(); //表格高度计算 - }; - /** - * 列宽度计算 - */ - Class.prototype.columnWidthInit = 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(); - }() - 17; - //统计列个数 - 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(item2._is_width_dev || !width) { //列宽未填写 - item2._is_width_dev = true; //采用默认宽度的列 - 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); //不能低于设定的最小宽度 - } - }); - }); - }; - /** - * 重新渲染宽度 - */ - Class.prototype.resizeWidth = function() { - var that = this; - that.renderTdCss(); - }; - /** - * 表格高度计算 - */ - Class.prototype.tableHeight = function() { - var that = this, - options = that.config, - optionsFirst = that.configFirst; - //确定高度 - if(!table.kit.isNumber(optionsFirst.height)) { //如果非固定高度,则计算高度 - var htremove = 0; //减去的高度 - if(options.heightRemove && table.kit.isArray(options.heightRemove)) { - var htatt = options.heightRemove; - htatt.forEach(function(t) { - var temh = table.kit.isNumber(t) ? t : $(t).outerHeight(true); - if(table.kit.isNumber(temh)) { - htremove += temh; - } - }); - } - //高度铺满:full-差距值 - var th = _WIN.height() - htremove - 1; //that.getParentDivHeight(options.id); - that.fullHeightGap = 0; - if(options.height) { - if(/^full-\d+$/.test(options.height)) { - that.fullHeightGap = options.height.split('-')[1]; - } - } - options.height = th - that.fullHeightGap; - } - }; - /** - * 重新渲染高度 - */ - Class.prototype.resizeHeight = function() { - var that = this, - options = that.config, - height = options.height, - bodyHeight; - if(height < 135) height = 135; - that.elem.css('height', 'auto'); - //tbody区域高度 - // bodyHeight = parseFloat(height) - parseFloat(that.layHeader.height()) - 1;//原本代码 - var theader = options.isFilter ? 76 : 38; //没有行内过滤区域 - bodyHeight = parseFloat(height) - theader - 1; //###注意:现在写死表头固定高度为38px,即不支持多表头方式(在tab方式下无法获取正确的高度,待处理) - if(options.toolbar) { - bodyHeight = bodyHeight - that.layTool.outerHeight(); - } - if(options.isPage) { - bodyHeight = bodyHeight - that.layPage.outerHeight() - 1; - } - that.layMain.css('height', 'auto'); - - //是否存在滚动条 - var sw = that.getScrollWidth(that.layMain[0]); - if(sw) { - that.layHeader.find(".layui-table thead tr th[data-field=_swth]").show(); - } else { - that.layHeader.find(".layui-table thead tr th[data-field=_swth]").hide(); - } - }; - //获取滚动条宽度 - 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').length <= 0) { - var patchElem = $('
'); //补丁元素 - patchElem.find('div').css({ - width: scollWidth - }); - that.layHeader.eq(0).find('thead tr').append(patchElem); - //that.layFilter.find('table thead tr').append(patchElem); - } - } else { - that.layFilter.eq(0).find('.layui-table-patch').remove(); - 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'), - bodytr = that.layBody.find('tr'), - resizing; - //行点击事件 - bodytr.unbind('click').on('click', function(e) { - var index = $(this).attr("data-index"); - var list = table.getDataList(that.config.id); - var o = list[index]; - typeof options.onClickRow === 'function' && options.onClickRow(index, o); - }); - //行双击事件 - bodytr.unbind('dblclick').on('dblclick', function(e) { - var index = $(this).attr("data-index"); - var list = table.getDataList(that.config.id); - var o = list[index]; - if(!isNull(that.config.onDblClickRow)) { - that.config.onDblClickRow(index, o); - } - }); - //拖拽调整宽度 - th.unbind('mousemove').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' : '')); - }) - th.unbind('mouseleave').on('mouseleave', function() { - var othis = $(this); - if(dict.resizeStart) return; - _BODY.css('cursor', ''); - }) - th.unbind('mousedown').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.unbind('mousemove').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 - } - }) - _DOC.unbind('mouseup').on('mouseup', function(e) { - if(dict.resizeStart) { - dict = {}; - _BODY.css('cursor', ''); - that.scrollPatch(); - } - if(resizing === 2) { - resizing = null; - } - }); - //排序 - th.unbind('click').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); - table.query(that.key); //从新查询 - }) - th.find(ELEM_SORT + ' .layui-edge ').unbind('click').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); - } - table.query(that.key); //从新查询 - }); - if(!that.eventsinitIsRun) { - that.eventsinit(); - that.eventsinitIsRun = true; - } - //同步滚动条 - that.layMain.unbind('scroll').on('scroll', function() { - var othis = $(this), - scrollLeft = othis.scrollLeft(), - scrollTop = othis.scrollTop(); - - that.layHeader.scrollLeft(scrollLeft); - that.layFilter.scrollLeft(scrollLeft); - that.layFixed.find(ELEM_BODY).scrollTop(scrollTop); - - layer.close(that.tipsIndex); - }); - _WIN.unbind('resize').on('resize', function() { //自适应 - that.resize(); - }); - }; - //事件处理单元格编辑(只执行一次) - Class.prototype.eventsinitIsRun = false; - //只执行一次的事件 - Class.prototype.eventsinit = function() { - var that = this, - options = that.config, - ELEM_CELL = '.layui-table-cell', - filter = options.elem.attr('lay-filter'); - //行内过滤 - that.layFilter.on('keyup', "[name^='filter_']", function() { - that.page = 1; - that.pullData(that.page, that.loading()); - }); - //行事件 - that.layBody.on('mouseenter', 'tr', function() { - var othis = $(this), - index = othis.index(); - that.layBody.find('tr:eq(' + index + ')').addClass(ELEM_HOVER) - }) - that.layBody.on('mouseleave', 'tr', function() { - var othis = $(this), - index = othis.index(); - that.layBody.find('tr:eq(' + index + ')').removeClass(ELEM_HOVER) - }); - //单元格事件 - that.layBody.on('click', 'td div.layui-table-cell p', function() { - var othis = $(this).parent().parent(), - field = othis.data('field'), - editType = othis.data('edit'), - index = othis.parents('tr').eq(0).data('index'), - data = table.getDataList(that.key)[index], - elemCell = othis.children(ELEM_CELL); - var options = that.config; - layer.close(that.tipsIndex); - if(othis.data('off')) return; - - //显示编辑表单 - if(editType) { - if(editType === 'select') { //选择框 - var dropName = othis.data('drop'); - var rowsField = dl.ui.table.drop.findFieldObj(options.cols[0], field); - var o = dl.cache.code.get(rowsField.drop); - var html = ''; - var scv = o.syscodevaluecache; - for(var i in scv) { - var isSelected = ""; - if(scv[i].scv_value == data[field]) { - isSelected = "selected='selected'"; - } - //选中 - html += '' - } - var select = $(''); - othis.find('.' + ELEM_EDIT)[0] || othis.append(select); - } else { //输入框 - var input = $(''); - input[0].value = $.trim($(this).text()); // othis.data('content') || elemCell.text(); - othis.find('.' + ELEM_EDIT)[0] || othis.append(input); - input.focus(); - } - return; - } - - //如果出现省略,则可查看更多 - var c = that.getCols(field); - - if(!table.config.initWidth[c["type"]]) { - 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('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.getDataList(that.key)[index]; - data[field] = value; //更新缓存中的值 - layui.event.call(this, MOD_NAME, 'edit(' + filter + ')', { - value: value, - data: data, - field: field - }); - }); - that.layBody.on('blur', '.' + ELEM_EDIT, function() { //单元格失去焦点 - var templet, othis = $(this), - field = othis.parent().data('field'), - index = othis.parents('tr').eq(0).data('index'), - editType = othis.parent().data('edit'), - data = table.getDataList(that.key)[index]; - var options = that.config; - that.eachCols(function(i, item) { - if(item.field == field && item.templet) { - templet = item.templet; - } - }); - var value = ""; - if(editType === 'select') { //选择框 - var rowsField = dl.ui.table.drop.findFieldObj(options.cols[0], field); - if(rowsField && rowsField['drop']) { - var o = dl.cache.code.get(rowsField.drop); - value = dl.ui.table.drop.findDropLable(rowsField.drop, this.value); - } - othis.parent().find(ELEM_CELL + ' p').html( - templet ? laytpl($(templet).html() || value).render(data) : value - ); - } else { //输入框 - othis.parent().find(ELEM_CELL + ' p').html( - templet ? laytpl($(templet).html() || this.value).render(data) : this.value - ); - } - othis.parent().data('content', this.value); - othis.remove(); - }); - //树形节点点击事件(隐藏展开下级节点) - that.elem.on('click', 'i.layui-tree-head', function() { - var othis = $(this), - index = othis.parents('tr').eq(0).data('index'), - options = that.config, - datas = table.getDataList(that.key); //数据 - var o = datas[index]; - that.treeNodeOpen(o, !o[table.config.cols.isOpen]); - that.resize(); - }); - //复选框选择 - 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, - obj = table.getDataList(that.config.id)[index], - isAll = checkbox.attr('lay-filter') === 'layTableAllChoose'; - //全选 - if(isAll) { - var list = table.getDataList(that.key); - list.forEach(function(temo) { - if(!temo[table.config.cols.cheDisabled]) { //可以选择的才设置 - that.setCheckData(temo[table.config.indexName], checked); - } - }); - } else { - that.setCheckData(index, checked); - if(options.isTree) { - //处理下级 - var sonList = that.treeFindSonData(obj); - sonList.forEach(function(temo) { - if(!temo[table.config.cols.cheDisabled]) { //可以选择的才设置 - that.setCheckData(temo[table.config.indexName], checked); - } - }); - - //处理上级 - var temf = function(o) { - if(o == null) return; - if(o && o.children.length > 0) { - var temis = true; - o.children.forEach(function(temo) { - if(!temo[table.config.cols.isCheckName]) { - temis = false; - } - }); - if(temis) { - that.setCheckData(o[table.config.indexName], checked); - } - - var temuo = that.treeFindUpData(o); - if(temuo) { - temf(temuo); - } - } - } - var uo = that.treeFindUpData(obj); - temf(uo); - } - } - that.syncCheckAll(); - layui.event.call(this, MOD_NAME, 'checkbox(' + filter + ')', { - checked: checked, - data: table.getDataList(that.key) ? (obj || {}) : {}, - type: isAll ? 'all' : 'one' - }); - }); - //工具条操作事件 - 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', - list = table.getDataList(that.key), - data = table.getDataList(that.key)[index]; - layui.event.call(this, MOD_NAME, 'tool(' + filter + ')', { - data: data //table.clearCacheKey(data) - , - event: othis.attr('lay-event'), - tr: tr, - del: function() { - table.delRow(options.id, data); - }, - 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); - }); - } - //表格重载 - thisTable.config = {}; - //自动完成渲染 - table.init(); - // layui.link('treeGrid.css'); - exports(MOD_NAME, table); -}); \ No newline at end of file diff --git a/web/src/main/resources/template/assets/lib/layui/layui.js b/web/src/main/resources/template/assets/lib/layui/layui.js index 671e43062d35c63f56f953ce36179772011ff6e1..cbe16a0d55eef384926f810c967da694ba009b12 100644 --- a/web/src/main/resources/template/assets/lib/layui/layui.js +++ b/web/src/main/resources/template/assets/lib/layui/layui.js @@ -273,7 +273,7 @@ function isNull(str){ zclip: 'jquery.zclip',//复制插件 swiper: 'swiper/swiper.min',//滚动插件 tableSelect: 'tableSelect',//tableSelect 下拉表格选择器 - treeGrid: 'treetable/treeGrid',//树表格 + tableTreeDj: 'treetable/tableTreeDj',//树表格 g6: 'flowchart/g6.min',//流程图 g6Plugins: 'flowchart/g6-plugins.min',//流程图 dtree: 'dtree/dtree',//