From 180bcaffa9b33f0c6cc57e98ad3a1bf25d90515b Mon Sep 17 00:00:00 2001 From: zjj <3272660260@qq.com> Date: 星期三, 14 六月 2023 14:49:09 +0800 Subject: [PATCH] #地图优化 --- src/main/webapp/static/js/user/user.js | 371 +++++++++++++++++----------------------------------- 1 files changed, 125 insertions(+), 246 deletions(-) diff --git a/src/main/webapp/static/js/user/user.js b/src/main/webapp/static/js/user/user.js index ecb99fd..0e06c7e 100644 --- a/src/main/webapp/static/js/user/user.js +++ b/src/main/webapp/static/js/user/user.js @@ -1,32 +1,37 @@ var pageCurr; var tableData; -layui.use(['table','laydate', 'form'], function(){ +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: '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:170} @@ -50,9 +55,30 @@ if (res.code === 403) { top.location.href = baseUrl+"/"; } - tableData = table.cache.user; + tableData = table.cache.userTable; pageCurr=curr; limit(); + } + }); + /* 琛ㄦ牸2鎼滅储 */ + form.on('submit(userTbSearch)', function (data) { + insTb2.reload({where: data.field, page: {curr: 1}}); + return false; + }); + + /* 琛ㄦ牸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; + })); } }); @@ -62,155 +88,32 @@ 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); + layer.msg(res.msg, {icon: 1}); }) }) - // 鐩戝惉鎺掑簭浜嬩欢 - 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+"/"; - } - tableData = table.cache.user; - pageCurr=curr; - limit(); - } - }); - }); - - // 鐩戝惉澶村伐鍏锋爮浜嬩欢 - 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: ['30%', 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 '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; - } - }); - - // 鐩戝惉琛屽伐鍏蜂簨浠� - table.on('tool(user)', function(obj){ + /* 琛ㄦ牸2宸ュ叿鏉$偣鍑讳簨浠� */ + table.on('tool(userTable)', function (obj) { var data = obj.data; switch (obj.event) { // 缂栬緫 case 'edit': - layer.open({ - type: 2, - title: '淇敼', - maxmin: true, - area: ['30%', top.detailHeight], - shadeClose: true, - content: 'user_detail.html', - success: function(layero, index){ - layer.getChildFrame('#password', index).parent().parent().hide(); - 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'); - } - }); + showEditModel(data) + break; + // 鍒犻櫎 + case 'del': + del([data.id]); break; // 閲嶇疆瀵嗙爜 case 'resetPwd': - layer.open({ + admin.open({ type: 1, title: '閲嶇疆瀵嗙爜', offset: '150px', area: ['360px'], shade: 0.1, shadeClose: true, - content: $("#resetpwd-window"), + content: $("#resetpwd-window").html(), success: function(layero, index){ layer.iframeAuto(index); $('#resetUserId').val(data.id); @@ -220,72 +123,84 @@ } }); - // 鏁版嵁淇敼鍔ㄤ綔 - form.on('submit(edit)', function () { - var index = layer.load(1, { - shade: [0.5,'#000'] //0.1閫忔槑搴︾殑鑳屾櫙 - }); - var data = { - id: $('#id').val(), - hostId: $('#hostId').val(), - username: $('#username').val(), - mobile: $('#mobile').val(), - password: hex_md5($('#password').val()), - roleId: $('#roleId').val(), - createTime: top.strToDate($('#createTime\\$').val()), - status: $('#status').val(), - - }; - $.ajax({ - url: baseUrl+"/user/edit/auth", - headers: {'token': localStorage.getItem('token')}, - data: top.reObject(data), - method: 'POST', - success: function (res) { - if (res.code === 200){ - parent.layer.closeAll(); - parent.$(".layui-laypage-btn")[0].click(); - $("#data-detail :input").each(function () { - $(this).val(""); - }); - } else if (res.code === 403){ - top.location.href = baseUrl+"/"; - }else { - layer.msg(res.msg) - } - layer.close(index); + /* 鏄剧ず琛ㄥ崟寮圭獥 */ + 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'); } - }) - }); + }); + } - // 鎼滅储鏍忔悳绱簨浠� - form.on('submit(search)', function (data) { - pageCurr = 1; - tableReload(false); - }); - // 鎼滅储鏍忛噸缃簨浠� - form.on('submit(reset)', function (data) { - pageCurr = 1; - clearFormVal($('#search-box')); - tableReload(false); - }); + /* 鍒犻櫎璁㈠崟 */ + 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}); + } + } + }) - // 鏃堕棿閫夋嫨鍣� - layDate.render({ - elem: '#createTime\\$', - type: 'datetime' - }); - layDate.render({ - elem: '.layui-laydate-range' - ,type: 'datetime' - ,range: true - }); + }); + } // 閲嶇疆瀵嗙爜 form.on('submit(savePwd)', function (data) { $.ajax({ - url: baseUrl+"/user/edit/auth", + url: baseUrl+"/user/update/auth", headers: {'token': localStorage.getItem('token')}, data: { id: data.field.resetUserId, @@ -295,24 +210,17 @@ success: function (res) { if (res.code === 200){ layer.closeAll(); - layer.msg("閲嶇疆瀵嗙爜鎴愬姛"); + layer.msg("閲嶇疆瀵嗙爜鎴愬姛", {icon: 1}); } else if (res.code === 403){ top.location.href = baseUrl+"/"; }else { - layer.msg(res.msg) + layer.msg(res.msg, {icon: 2}) } } }) + return false; }) - $('#cancel').click(function () { - layer.closeAll(); - }) -}); - -// 鍏抽棴鍔ㄤ綔 -$(document).on('click','#data-detail-close', function () { - parent.layer.closeAll(); }); function tableReload(child) { @@ -324,36 +232,7 @@ where: searchData, page: { curr: pageCurr - }, - done: function (res, curr, count) { - if (res.code === 403) { - top.location.href = baseUrl+"/"; - } - tableData = table.cache.user; - 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]); - } -} - -$('body').keydown(function () { - if (event.keyCode === 13) { - $("#search").click(); - } -}); -- Gitblit v1.9.1