123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- layui.use([ 'laypage', 'layer', 'table', 'element','form','transfer','util'], function(){
- var laypage = layui.laypage //分页
- ,layer = layui.layer //弹层
- ,table = layui.table //表格
- ,transfer = layui.transfer
- ,util = layui.util
- ,element = layui.element //元素操作
- ,form = layui.form;
- //第一个实例
- table.render({
- elem: '#userlist'
- ,url: '/user/homefrom' //数据接口
- ,where:{token:csrfToken}
- ,method:'post'
- ,id:'tablerReload'
- ,page: true //开启分页
- ,text:'数据加载中'
- ,limit : 15
- ,cols: [[ //表头
- // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
- {type:'numbers',fixed:"left",title:'序号'},
- {field: 'user', title: '账号', align:'center'}
- ,{field: 'name', title: '姓名', width:150,align:'center'}
- ,{field: 'status', title: '状态', width:80,align:'center', templet: function (d) {
- if (d.status == 2) {
- return '<input type="checkbox" value="' + d.uid + '" data-status="1" lay-skin="switch" lay-filter="switchTest3" lay-text="开启|关闭">'
- } else {
- return '<input type="checkbox" checked value="' + d.uid + '" data-status="2" lay-skin="switch" lay-filter="switchTest3" lay-text="开启|关闭">'
- }
- }}
- ,{field: 'create_at', title: '注册时间', width:200,align:'center'}
- ,{field: 'login_num', title: '登录次数', width:150,align:'center'}
- ,{field: 'login_time', title: '上次登录时间', width:200,align:'center'}
- ,{fixed: 'right',title:'操作', width: 250, align:'center', toolbar: '#operate'}
- ]]
- });
- table.reload('tablerReload'); //重新加载
- //列表操作
- table.on('tool(userlist)', function(obj){
- var layEvent = obj.event,
- data = obj.data;
- if(layEvent === 'edit'){
- layer.open({
- type: 2,
- title: '修改用户信息',
- area: ['600px', '500px'],
- anim: 2,
- content: '/user/edit?id='+data.uid //iframe的url,no代表不显示滚动条
- });
- } else if(layEvent === 'userrole') {
- layer.open({
- type: 2,
- title: '用户添加角色',
- closeBtn: 1, //不显示关闭按钮
- // shade: [0],
- area: ['700px', '550px'],
- anim: 2,
- content:'/user/adduserrole?uid='+data.uid,
- });
- }
- });
- //监听指定开关
- form.on('switch(switchTest3)', function (data) {
- var id = data.value
- ,status = $(this).data('status')
- layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
- $.post('/user/usersetstatus', {id:id, status: status}, function (data) {
- layer.msg(data.msg);
- table.reload('tablerReload');
- })
- }, function (aa) {
- table.reload('tablerReload'); //重新加载
- })
- });
- var $ = layui.$, active = {
- addData: function(){ //获取选中数据
- layer.open({
- type: 2,
- title: '添加账号',
- closeBtn: 1, //不显示关闭按钮
- shade: [0],
- area: ['600px', '500px'],
- anim: 2,
- content: ['/user/adduser', 'no'], //iframe的url,no代表不显示滚动条
- });
- }
- };
- $('.demoTable .layui-btn').on('click', function(){
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
- //添加
- form.on('submit(userSubmit)', function(data){
- var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
- $.post('/user/adduserfrom',{'data':data.field},function (data) {
- if(data.code == 200)
- {
- top.layer.close(index); //关闭数据提交信息
- layer.msg(data.msg);
- parent.layui.table.reload('userlist');
- TableClose();
- } else if(data.code == 300 ) {
- top.layer.close(index); //关闭数据提交信息
- layer.msg(data.msg);
- }
- })
- return false;
- });
- /**
- * 2020.6.24 lyy 用户管理优化
- * 用户状态修改
- * 用户添加角色
- *begin
- * ****/
- var data1 = [];
- var data2 = [];
- $('#userrolelist .y_role').each(function () {
- let t = {"value": $(this).data('id'), "title": $(this).data('name')};
- data1.push(t);
- })
- $('#userrolelist .c_role').each(function () {
- data2.push($(this).data('id'))
- })
- //显示搜索框
- transfer.render({
- elem: '#test4'
- , data: data1
- , value: data2
- , title: ['未赋予', '已赋予']
- , showSearch: true
- , id: "keyuserrole"
- })
- util.event('lay-demoTransferActive', {
- getData: function (othis) {
- var getData = transfer.getData('keyuserrole'); //获取右侧数据
- var rid = [];
- for(var v of getData){
- rid.push(v.value);
- }
- var index = top.layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- $.post('/user/adduserrolefrom', {'data': {rid:rid,uid:$(this).data('uid'),type:$(this).data('type')}}, function (data) {
- if (data.code == 200) {
- top.layer.close(index); //关闭数据提交信息
- layer.msg(data.msg);
- parent.layui.table.reload('userlist');
- TableClose();
- } else if (data.code == 300) {
- top.layer.close(index); //关闭数据提交信息
- layer.msg(data.msg);
- }
- })
- }
- , reload: function () {
- //实例重载
- transfer.reload('keyuserrole', {
- title: ['未赋予', '已赋予']
- , data: data1
- , value: data2
- , showSearch: true
- })
- }
- });
- //用户添加角色
- // form.on('submit(add_user_role)', function(data){
- // var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
- // $.post('/user/adduserrolefrom',{'data':data.field},function (data) {
- // if(data.code == 200)
- // {
- // top.layer.close(index); //关闭数据提交信息
- // layer.msg(data.msg);
- // TableClose();
- // } else if(data.code == 300 ) {
- // top.layer.close(index); //关闭数据提交信息
- // layer.msg(data.msg);
- // }
- // })
- // return false;
- // });
- //给角色添加节点
- form.on('submit(userEditSubmit)', function(data){
- $.post('/user/editform',{'data':data.field},function (data) {
- if(data.code == 200)
- {
- layer.msg(data.msg);
- TableClose();
- } else if(data.code == 300 ) {
- layer.msg(data.msg);
- }
- });
- return false;
- });
- //个人修改密码
- form.on('submit(userPwdSubmit)', function(data){
- var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
- $.post('/user/pwdsaveform',{'data':data.field},function (data) {
- top.layer.close(index); //关闭数据提交信息
- if(data.code == 200)
- {
- layer.msg(data.msg);
- window.parent.location.href = '/public/login';
- } else if(data.code == 300 ) {
- layer.msg(data.msg);
- }
- })
- top.layer.close(index); //关闭数据提交信息
- return false;
- });
- function TableClose() {
- setTimeout(function () {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- },1000)
- }
- });
|