From 5ce6bfb2e237b9fbf092a03cf80e86d928ac7ca6 Mon Sep 17 00:00:00 2001 From: 野心家 <1051256694@qq.com> Date: 星期二, 20 六月 2023 16:40:51 +0800 Subject: [PATCH] 孚能 --- src/main/webapp/static/js/user/user.js | 490 +++++++++++++++++------------------------------------- 1 files changed, 154 insertions(+), 336 deletions(-) diff --git a/src/main/webapp/static/js/user/user.js b/src/main/webapp/static/js/user/user.js index c04f8ba..0e06c7e 100644 --- a/src/main/webapp/static/js/user/user.js +++ b/src/main/webapp/static/js/user/user.js @@ -1,34 +1,40 @@ var pageCurr; -layui.use(['table','laydate', 'form'], function(){ +var tableData; +var insTb2; +layui.config({ + base: baseUrl + "/static/layui/lay/modules/" +}).use(['table','laydate', 'form', 'util', 'admin'], function(){ var table = layui.table; var $ = layui.jquery; var layer = layui.layer; var layDate = layui.laydate; var form = layui.form; + var admin = layui.admin; + var util = layui.util; - // 鏁版嵁娓叉煋 - tableIns = table.render({ - elem: '#user', + insTb2 = table.render({ + elem: '#userTable', headers: {token: localStorage.getItem('token')}, url: baseUrl+'/user/list/auth', page: true, - limit: 16, - limits: [16, 30, 50, 100, 200, 500], - toolbar: '#toolbar', - even: true, - cellMinWidth: 50, + limit: 15, + limits: [15, 30, 50, 100, 200, 500], + toolbar: '#userToolbar', + height: 'full-100', cols: [[ {type: 'checkbox'} - ,{field: 'id', title: 'ID', sort: true,align: 'center', width: 80} - // ,{field: 'hostName', align: 'center',title: '鎺堟潈鍟嗘埛'} - ,{field: 'mobile', align: 'center',title: '璐﹀彿'} - ,{field: 'username', align: 'center',title: '鍚嶇О'} - ,{field: 'password', align: 'center',title: '瀵嗙爜'} + // ,{field: 'hostName', align: 'center',title: '鎺堟潈鍟嗘埛', templet: '#hostTpl', width: 140} + // ,{field: 'nickname', align: 'center',title: '鐢ㄦ埛鍚�'} + ,{field: 'username', align: 'center',title: '鐧诲綍璐︽埛'} + ,{field: 'mobile', align: 'center',title: '鎵嬫満鍙�'} + // ,{field: 'deptName', align: 'center',title: '鎵�灞為儴闂�'} ,{field: 'roleName', align: 'center',title: '瑙掕壊'} - // ,{field: 'createTime$', align: 'center',title: '娉ㄥ唽鏃堕棿'} - ,{field: 'status$', align: 'center',title: '鐘舵��'} + ,{field: 'email', align: 'center',title: '閭'} + // ,{field: 'sex$', align: 'center',title: '鎬у埆'} + ,{field: 'createTime$', align: 'center',title: '娉ㄥ唽鏃堕棿', hide: true} + ,{field: 'status$', align: 'center',title: '鐘舵��', templet: '#statusTpl', width: 120, unresize: true} - ,{fixed: 'right', title:'鎿嶄綔', align: 'center', toolbar: '#operate', width:100} + ,{fixed: 'right', title:'鎿嶄綔', align: 'center', toolbar: '#operate', width:170} ]], request: { pageName: 'curr', @@ -49,314 +55,172 @@ if (res.code === 403) { top.location.href = baseUrl+"/"; } + tableData = table.cache.userTable; pageCurr=curr; limit(); } }); - - // 鐩戝惉鎺掑簭浜嬩欢 - table.on('sort(user)', function (obj) { - var searchData = {}; - $.each($('#search-box [name]').serializeArray(), function() { - searchData[this.name] = this.value; - }); - searchData['orderByField'] = obj.field; - searchData['orderByType'] = obj.type; - tableIns.reload({ - where: searchData, - page: { - curr: 1 - }, - done: function (res, curr, count) { - if (res.code === 403) { - top.location.href = baseUrl+"/"; - } - pageCurr=curr; - limit(); - } - }); + /* 琛ㄦ牸2鎼滅储 */ + form.on('submit(userTbSearch)', function (data) { + insTb2.reload({where: data.field, page: {curr: 1}}); + return false; }); - // 鐩戝惉澶村伐鍏锋爮浜嬩欢 - table.on('toolbar(user)', function (obj) { - var checkStatus = table.checkStatus(obj.config.id); - switch(obj.event) { - case 'addData': - layer.open({ - type: 2, - title: '鏂板', - maxmin: true, - area: [top.detailWidth, top.detailHeight], - shadeClose: true, - content: 'user_detail.html', - success: function(layero, index){ - clearFormVal(layer.getChildFrame('#detail', index)); - layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); - } - }); - break; - case 'refreshData': - tableIns.reload({ - page: { - curr: pageCurr - } - }); - limit(); - break; - case 'deleteData': - var data = checkStatus.data; - var ids=[]; - data.map(function (track) { - ids.push(track.id); - }); - if (ids.length === 0){ - layer.msg('璇烽�夋嫨鏁版嵁'); - } else { - layer.confirm('纭畾鍒犻櫎'+(ids.length===1?'姝�':ids.length)+'鏉℃暟鎹悧', function(){ - $.ajax({ - url: baseUrl+"/user/delete/auth", - headers: {'token': localStorage.getItem('token')}, - data: {ids: ids}, - method: 'POST', - traditional:true, - success: function (res) { - if (res.code === 200){ - layer.closeAll(); - tableReload(false); - } else if (res.code === 403){ - top.location.href = baseUrl+"/"; - } else { - layer.msg(res.msg) - } - } - }) - }); - } - break; - case 'exportData': - layer.confirm('纭畾瀵煎嚭Excel鍚�', {shadeClose: true}, function() { - var titles = []; - var fields = []; - obj.config.cols[0].map(function (col) { - if (col.type === 'normal' && col.hide === false && col.toolbar == null) { - titles.push(col.title); - fields.push(col.field); - } - }); - var exportData = {}; - $.each($('#search-box [name]').serializeArray(), function () { - exportData[this.name] = this.value; - }); - var param = { - 'user': exportData, - 'fields': fields - }; - $.ajax({ - url: baseUrl+"/user/export/auth", - headers: {'token': localStorage.getItem('token')}, - data: JSON.stringify(param), - dataType: 'json', - contentType: 'application/json;charset=UTF-8', - method: 'POST', - success: function (res) { - layer.closeAll(); - if (res.code === 200) { - table.exportFile(titles, res.data, 'xls'); - } else if (res.code === 403) { - top.location.href = baseUrl+"/"; - } else { - layer.msg(res.msg) - } - } - }); - }); - break; + /* 琛ㄦ牸2澶村伐鍏锋爮鐐瑰嚮浜嬩欢 */ + table.on('toolbar(userTable)', function (obj) { + var checkStatus = table.checkStatus(obj.config.id).data; + if (obj.event === 'add') { // 娣诲姞 + showEditModel() + } else if (obj.event === 'del') { // 鍒犻櫎 + if (checkStatus.length === 0) { + layer.msg('璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁', {icon: 2}); + return; + } + del(checkStatus.map(function (d) { + return d.id; + })); } }); - // 鐩戝惉琛屽伐鍏蜂簨浠� - table.on('tool(user)', function(obj){ + // 淇敼鐘舵�� + form.on('switch(statusSwitch)', function (obj) { + var index = obj.othis.parents('tr').attr("data-index"); + var data = tableData[index]; + data[this.name] = obj.elem.checked?1:0; + http.post(baseUrl+"/user/edit/auth", {id: data.id, status: data[this.name]}, function (res) { + layer.msg(res.msg, {icon: 1}); + }) + }) + + /* 琛ㄦ牸2宸ュ叿鏉$偣鍑讳簨浠� */ + table.on('tool(userTable)', function (obj) { var data = obj.data; switch (obj.event) { - // 璇︽儏 - case 'detail': - layer.open({ - type: 2, - title: '璇︽儏', - maxmin: true, - area: [top.detailWidth, top.detailHeight], - shadeClose: false, - content: 'user_detail.html', - success: function(layero, index){ - setFormVal(layer.getChildFrame('#detail', index), data); - top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true); - layer.getChildFrame('#data-detail-submit,#prompt', index).hide(); - layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); - layero.find('iframe')[0].contentWindow.layui.form.render('select'); - } - }); - break; // 缂栬緫 case 'edit': - layer.open({ - type: 2, - title: '淇敼', - maxmin: true, - area: [top.detailWidth, top.detailHeight], + showEditModel(data) + break; + // 鍒犻櫎 + case 'del': + del([data.id]); + break; + // 閲嶇疆瀵嗙爜 + case 'resetPwd': + admin.open({ + type: 1, + title: '閲嶇疆瀵嗙爜', + offset: '150px', + area: ['360px'], + shade: 0.1, shadeClose: true, - content: 'user_detail.html', + content: $("#resetpwd-window").html(), success: function(layero, index){ - setFormVal(layer.getChildFrame('#detail', index), data); - top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false); - layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); - layero.find('iframe')[0].contentWindow.layui.form.render('select'); + layer.iframeAuto(index); + $('#resetUserId').val(data.id); } }); - break; - case 'Role': - var param = top.reObject(data).roleId; - if (param === undefined) { - layer.msg("鏃犳暟鎹�"); - } else { - layer.open({ - type: 2, - title: '璇︽儏', - maxmin: true, - area: [top.detailHeight, top.detailWidth], - shadeClose: false, - content: '../role/role_detail.html', - success: function(layero, index){ - $.ajax({ - url: baseUrl+"/role/"+ param +"/auth", - headers: {'token': localStorage.getItem('token')}, - method: 'GET', - success: function (res) { - if (res.code === 200){ - setFormVal(layer.getChildFrame('#detail', index), res.data); - top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true); - layer.getChildFrame('#data-detail-submit,#prompt', index).hide(); - layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); - layero.find('iframe')[0].contentWindow.layui.form.render('select'); - } else if (res.code === 403){ - parent.location.href = "/"; - }else { - layer.msg(res.msg) - } - } - }) - } - }); - } - break; - case 'Host': - var param = top.reObject(data).hostId; - if (param === undefined) { - layer.msg("鏃犳暟鎹�"); - } else { - layer.open({ - type: 2, - title: '璇︽儏', - maxmin: true, - area: [top.detailHeight, top.detailWidth], - shadeClose: false, - content: '../host/host_detail.html', - success: function(layero, index){ - $.ajax({ - url: baseUrl+"/host/"+ param +"/auth", - headers: {'token': localStorage.getItem('token')}, - method: 'GET', - success: function (res) { - if (res.code === 200){ - setFormVal(layer.getChildFrame('#detail', index), res.data); - top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true); - layer.getChildFrame('#data-detail-submit,#prompt', index).hide(); - layer.iframeAuto(index); - layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"}); - layero.find('iframe')[0].contentWindow.layui.form.render('select'); - } else if (res.code === 403){ - parent.location.href = "/"; - }else { - layer.msg(res.msg) - } - } - }) - } - }); - } break; } }); - // 鏁版嵁淇敼鍔ㄤ綔 - form.on('submit(edit)', function () { - var index = layer.load(1, { - shade: [0.5,'#000'] //0.1閫忔槑搴︾殑鑳屾櫙 + /* 鏄剧ず琛ㄥ崟寮圭獥 */ + function showEditModel(mData) { + admin.open({ + type: 1, + area: '600px', + title: (mData ? '淇敼' : '娣诲姞') + '鐢ㄦ埛', + content: $('#editDialog').html(), + success: function (layero, dIndex) { + // 鍥炴樉琛ㄥ崟鏁版嵁 + form.val('detail', mData); + // 琛ㄥ崟鎻愪氦浜嬩欢 + form.on('submit(editSubmit)', function (data) { + if (isEmpty(data.field.roleId)) { + layer.msg('璇烽�夋嫨瑙掕壊', {icon: 2}); + return false; + } + var loadIndex = layer.load(2); + $.ajax({ + url: baseUrl+"/user/"+(mData?'update':'add')+"/auth", + headers: {'token': localStorage.getItem('token')}, + data: data.field, + method: 'POST', + success: function (res) { + layer.close(loadIndex); + if (res.code === 200){ + layer.close(dIndex); + layer.msg(res.msg, {icon: 1}); + $(".layui-laypage-btn")[0].click(); + } else if (res.code === 403){ + top.location.href = baseUrl+"/"; + }else { + layer.msg(res.msg, {icon: 2}); + } + } + }) + return false; + }); + // 寮圭獥涓嶅嚭鐜版粴鍔ㄦ潯 + $(layero).children('.layui-layer-content').css('overflow', 'visible'); + layui.form.render('select'); + } }); - var data = { - id: $('#id').val(), - hostId: $('#hostId').val(), - username: $('#username').val(), - mobile: $('#mobile').val(), - password: $('#password').val(), - roleId: $('#roleId').val(), - createTime: top.strToDate($('#createTime\\$').val()), - status: $('#status').val(), + } - }; + + /* 鍒犻櫎璁㈠崟 */ + function del(ids) { + layer.confirm('纭畾瑕佸垹闄ら�変腑鏁版嵁鍚楋紵', { + skin: 'layui-layer-admin', + shade: .1 + }, function (i) { + layer.close(i); + var loadIndex = layer.load(2); + $.ajax({ + url: baseUrl+"/user/delete/auth", + headers: {'token': localStorage.getItem('token')}, + data: {ids: ids}, + method: 'POST', + success: function (res) { + layer.close(loadIndex); + if (res.code === 200){ + layer.msg(res.msg, {icon: 1}); + $(".layui-laypage-btn")[0].click(); + } else if (res.code === 403){ + top.location.href = baseUrl+"/"; + }else { + layer.msg(res.msg, {icon: 2}); + } + } + }) + + }); + } + + // 閲嶇疆瀵嗙爜 + form.on('submit(savePwd)', function (data) { $.ajax({ - url: baseUrl+"/user/edit/auth", + url: baseUrl+"/user/update/auth", headers: {'token': localStorage.getItem('token')}, - data: top.reObject(data), + data: { + id: data.field.resetUserId, + password: hex_md5(data.field.resetPassword) + }, method: 'POST', success: function (res) { if (res.code === 200){ - parent.layer.closeAll(); - tableReload(true); - $("#data-detail :input").each(function () { - $(this).val(""); - }); + layer.closeAll(); + layer.msg("閲嶇疆瀵嗙爜鎴愬姛", {icon: 1}); } else if (res.code === 403){ top.location.href = baseUrl+"/"; }else { - layer.msg(res.msg) + layer.msg(res.msg, {icon: 2}) } - layer.close(index); } }) - }); + return false; + }) - // 鎼滅储鏍忔悳绱簨浠� - form.on('submit(search)', function (data) { - pageCurr = 1; - tableReload(false); - }); - - // 鎼滅储鏍忛噸缃簨浠� - form.on('submit(reset)', function (data) { - pageCurr = 1; - clearFormVal($('#search-box')); - tableReload(false); - }); - - // 鏃堕棿閫夋嫨鍣� - layDate.render({ - elem: '#createTime\\$', - type: 'datetime' - }); - layDate.render({ - elem: '#create_time\\>', - type: 'datetime' - }); - layDate.render({ - elem: '#create_time\\<', - type: 'datetime' - }); - -}); - -// 鍏抽棴鍔ㄤ綔 -$(document).on('click','#data-detail-close', function () { - parent.layer.closeAll(); }); function tableReload(child) { @@ -368,53 +232,7 @@ where: searchData, page: { curr: pageCurr - }, - done: function (res, curr, count) { - if (res.code === 403) { - top.location.href = baseUrl+"/"; - } - pageCurr=curr; - if (res.data.length === 0 && count !== 0) { - tableIns.reload({ - where: searchData, - page: { - curr: pageCurr-1 - } - }); - pageCurr -= 1; - } - limit(child); } }); } - -function setFormVal(el, data) { - for (var val in data) { - el.find(":input[id='" + val + "']").val(data[val]); - } -} - -function clearFormVal(el) { - $(':input', el) - .val('') - .removeAttr('checked') - .removeAttr('selected'); -} - -function detailScreen(index) { - var detail = layer.getChildFrame('#data-detail', index); - var height = detail.height()+60; - if (height > ($(window).height()*0.9)) { - height = ($(window).height()*0.9); - } - layer.style(index, { - height: height +'px' - }); -} - -$('body').keydown(function () { - if (event.keyCode === 13) { - $("#search").click(); - } -}); -- Gitblit v1.9.1