From 1ecfffee554bc9dadc17b0f002e0a3751f0b9f62 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Sat, 20 Oct 2018 11:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8C=89=E9=92=AE=E5=92=8C=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Index.php | 57 ++++++++++++++------ application/admin/view/index/index.html | 10 ++-- application/common/view/list.html | 70 ++++++++++++++++++------- route/admin.php | 1 + route/home.php | 15 ------ 5 files changed, 98 insertions(+), 55 deletions(-) delete mode 100644 route/home.php diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index e1d54f4d..571fd661 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -128,13 +128,10 @@ class Index extends Base $msg = array(); - if($data == 1) - { - $data =['msg'=>'添加成功','val'=>1]; - }else{ - $data =['msg'=>'数据处理错误','val'=>0]; - } + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + // 返回信息 return json($data); } @@ -187,13 +184,10 @@ class Index extends Base $data = $admin->save($list,['id'=>$id]); - if($data == 1) - { - $data =['msg'=>'更新成功','val'=>1]; - }else{ - $data =['msg'=>'数据处理错误','val'=>0]; - } + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + // 返回信息 return json($data); } @@ -215,8 +209,10 @@ class Index extends Base $data = $admin->destroy($id); - $data = ['msg'=>'删除成功','val'=>1]; + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'删除成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + // 返回信息 return json($data); } @@ -241,9 +237,40 @@ class Index extends Base $data = $list->save(); // 根据更新结果设置返回提示信息 - $data ? $data=['msg'=>'操作成功'] : $data=['msg'=>'数据处理错误']; + $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; - // 返回信息 + // 返回信息 return json($data); } + + + // 重置密码 + public function resetpassword($id) + { + + // 实例化管理员数据模型类 + $admin = new Admin(); + // 实例化加密类 + $md5 = new APR1_MD5(); + + // 生成密码 + $password = $md5->hash('123456'); + + // 查询用户信息 + $list = $admin->get($id); + + // 设置管理员新信息 + $list->password = $password; + + // 更新密码 + $data = $list->save(); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'密码重置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + + + } } diff --git a/application/admin/view/index/index.html b/application/admin/view/index/index.html index 3ba52b3c..666588fb 100644 --- a/application/admin/view/index/index.html +++ b/application/admin/view/index/index.html @@ -16,7 +16,7 @@
- + 批量删除 @@ -91,7 +91,7 @@ "className":'.td-manage', "render": function(data, type, row, meta) { // 初始化密码 - resetpw = ''; + resetpwbut = ''; // 停用按钮 stopbut = ''; // 启用按钮 @@ -100,12 +100,12 @@ readbut = ''; // 编辑按钮 editbut = ''; - delbut = ''; + delbut = ''; if(row.status == '已停用') { - buts = resetpw + startbut + readbut + editbut + delbut; + buts = resetpwbut + startbut + readbut + editbut + delbut; }else{ - buts = resetpw + stopbut + readbut + editbut + delbut; + buts = resetpwbut + stopbut + readbut + editbut + delbut; } return buts; diff --git a/application/common/view/list.html b/application/common/view/list.html index 50fa1835..ba088ce1 100644 --- a/application/common/view/list.html +++ b/application/common/view/list.html @@ -141,12 +141,18 @@ function stop(obj,id){ value: 0, }, success: function(data){ - $(obj).html(''); - $(obj).parents("tr").find("span").parents("td").html('已停用'); - layer.msg('已停用!',{icon: 5,time:1000}); + if(data.val == 1 || data.val == 0) + { + $(obj).parents("tr").find("span").parents("td").html('已停用'); + $(obj).replaceWith('') + + layer.msg('已停用!',{icon: 5,time:1000}); + }else{ + layer.msg(data.msg); + } }, error:function(data) { - console.log(data.msg); + layer.msg('操作失败'); }, }); }); @@ -164,12 +170,18 @@ function start(obj,id){ value: 1, }, success: function(data){ - $(obj).html(''); - $(obj).parents("tr").find("span").parents("td").html('已启用'); - layer.msg('已启用!',{icon: 6,time:1000}); + if(data.val == 1 || data.val == 0) + { + $(obj).parents("tr").find("span").parents("td").html('已启用'); + $(obj).replaceWith(''); + layer.msg('已启用!',{icon: 6,time:1000}); + }else{ + layer.msg(data.msg); + } + }, error:function(data) { - console.log(data.msg); + layer.msg('操作失败'); }, }); }); @@ -183,24 +195,29 @@ function change_password(title,url,id,w,h){ layer_show(title,url,w,h); } /*用户-删除*/ -function del(obj,id){ +function del(obj,url){ layer.confirm('确认要删除吗?',function(index){ $.ajax({ type: 'DELETE', - url: "/admin/" + id, + url: url, dataType: 'json', success: function(data){ - $(obj).parents("tr").remove(); - layer.msg('已删除!',{icon:1,time:1000}); + if(data.val == 1) + { + $(obj).parents("tr").remove(); + // layer.alert(data.msg,{icon:1,time:1000}); + } + layer.alert(data.msg); + }, error:function(data) { - console.log(data.msg); + layer.alert('删除失败'); }, }); }); } /*批量删除*/ -function dels(){ +function dels(url){ //声明数组 var chk_value =[]; //获取所有被选中的值 @@ -221,7 +238,7 @@ function dels(){ layer.confirm('确认要删除选中的内容吗?',function(index){ $.ajax({ type: 'DELETE', - url:'/admin/m', + url:url, dataType: 'json', data: { ids:chk_value, @@ -229,21 +246,34 @@ function dels(){ success: function(data){ if(data.val == 1){ - layer.alert('删除成功'); $('input[name="test"]:checked').each(function(){ $(this).parents("tr").remove(); }); - - }else{ - layer.alert('数据处理失败'); } + layer.alert(data.msg); }, error:function(data) { - layer.msg('删除失败'); + layer.msg('操作失败'); }, }); }); } +/*用户-密码重置*/ +function resetpw(obj,id){ + layer.confirm('确认要重置密码吗?',function(index){ + $.ajax({ + type: 'GET', + url: "/resetpassword/" + id, + dataType: 'json', + success: function(data){ + layer.alert(data.msg,{icon:1,time:1000}); + }, + error:function(data) { + layer.alert('操作失败'); + }, + }); + }); +} \ No newline at end of file diff --git a/route/admin.php b/route/admin.php index 94138262..dfec147a 100644 --- a/route/admin.php +++ b/route/admin.php @@ -11,3 +11,4 @@ //系统设置路由 Route::resource('admin','admin/index'); +Route::get('resetpassword/:id','admin/index/resetpassword'); diff --git a/route/home.php b/route/home.php deleted file mode 100644 index dac97d6a..00000000 --- a/route/home.php +++ /dev/null @@ -1,15 +0,0 @@ - -// +---------------------------------------------------------------------- - -// 错误页面 -// 找不到操作提示 -Route::rule('success','home/index/mysuccess'); -Route::rule('notfound','home/index/notfound');