Blogger Information
Blog 52
fans 1
comment 1
visits 38835
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1、创建用户列表、添加、修改功能 2、创建用户日志列表 3、完善记账分类、添加、修改功能
小丑0o鱼
Original
322 people have browsed it

部署流程

thinkphp:使用thinkphp6.0 ,在数据库表里每个管理员都有相对应的id字段,我们点击编辑的时候,会自动获取管理员id字段,进行判断点击的是哪个管理员,当我们修改信息的时候,会判断所填的信息是否为空,如果不为空则添加或修改成功,会默认给一个修改和添加时间,删除就是判断当前点击的管理员字段id,进行where条件查找,然后进行删除
HTML 代码块

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>管理员账号列表</title>
  8. <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" />
  9. <script src="/static/layui-v2.6.8/layui/layui.js"></script>
  10. </head>
  11. <body style="padding: 10px;min-width:737px">
  12. <div class="layui-item" >
  13. <span style="color:#777;font-size:20px;height:30px;line-height:30px">首页/</span>
  14. <span style="color:#ccc">管理员列表</span>
  15. <button class="layui-btn layui-btn-sm" style="float:right;margin:5px" onclick="add()">添加</button>
  16. </div>
  17. <table class="layui-table" >
  18. <thead>
  19. <tr>
  20. <th>ID</th>
  21. <th>用户名</th>
  22. <th>管理员级别</th>
  23. <th>真实姓名</th>
  24. <th>注册时间</th>
  25. <th>状态</th>
  26. <th>编辑</th>
  27. </tr>
  28. </thead>
  29. <tbody>
  30. {foreach $admin as $v}
  31. <tr>
  32. <td>{$v['id']}</td>
  33. <td>{$v['username']}</td>
  34. <td>{$v['gid']}</td>
  35. <td>{$v['truename']}</td>
  36. <td>{:date('Y-m-d H:i:s',$v['add_time'])}</td>
  37. <td style="color:{$v['status']==0 ? 'green' : 'red'};">
  38. {$v['status']==0 ? '开启' : '关闭'}
  39. </td>
  40. <td>
  41. <button class="layui-btn layui-btn-sm " onclick="edit({$v['id']})">编辑</button>
  42. <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="dle({$v['id']})">删除</button>
  43. </td>
  44. </tr>
  45. {/foreach}
  46. </tbody>
  47. </table>
  48. </body>
  49. <script>
  50. $ = layui.jquery;
  51. //修改信息
  52. function edit(aid) {
  53. layer.open({
  54. type:2,
  55. title: '修改信息',
  56. shadeClose: true,
  57. shade: 0.8,
  58. area: ['450px', '450px'],
  59. content: '/admin/Admin/edit?aid='+aid
  60. });
  61. }
  62. //删除
  63. function dle(aid) {
  64. layer.confirm('确定删除吗?', {
  65. btn: ['确定','取消'],
  66. },
  67. function(){
  68. let date = {};
  69. $.post('/admin/Admin/dle?aid='+aid,date,function(res){
  70. if (res.id == 1) {
  71. layer.alert(res.msg,{icon:1});
  72. setTimeout(() => {
  73. window.location.reload();
  74. }, 1000);
  75. }else{
  76. layer.alert(res.msg,{icon:2});
  77. }
  78. },'json')
  79. });
  80. }
  81. //添加管理员
  82. function add()
  83. {
  84. layer.open({
  85. type:2,
  86. title: '添加信息',
  87. shadeClose: true,
  88. shade: 0.8,
  89. area: ['450px', '450px'],
  90. content: '/admin/Admin/add'
  91. });
  92. }
  93. </script>
  94. </html>
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\Base;
  4. use think\facade\Request;
  5. use think\facade\Db;
  6. use think\facade\View;
  7. use think\facade\Session;
  8. /**
  9. * 管理员账号管理
  10. */
  11. class Admin extends Base
  12. {
  13. //账号列表
  14. public function index()
  15. {
  16. //获取信息 渲染到账号列表
  17. $admin = Db::table('admin a')
  18. ->select()
  19. ->toArray();
  20. //管理员角色
  21. $group = Db::table('admin_group')->field(['gid','title'])->select()->toArray();
  22. foreach ($admin as $key => $av) {
  23. $admin[$key]['gid'] = '';
  24. foreach ($group as $gv) {
  25. if ($av['gid'] == $gv['gid']) {
  26. $admin[$key]['gid'] = $gv['title'];
  27. break;
  28. }
  29. }
  30. }
  31. View::assign([
  32. 'admin' => $admin
  33. ]);
  34. return View('/admin/index');
  35. }
  36. //管理员编辑
  37. public function edit()
  38. {
  39. $aid =(int)Request::get('aid');
  40. $user = Db::table('admin')->where('id',$aid)->find();
  41. $group = $group = Db::table('admin_group')->field(['gid','title'])->select();
  42. View::assign([
  43. 'user'=>$user,
  44. 'group'=>$group,
  45. 'aid'=>$aid
  46. ]);
  47. return View('/admin/edit');
  48. }
  49. //管理员添加页面
  50. public function add()
  51. {
  52. $group = $group = Db::table('admin_group')->field(['gid','title'])->select();
  53. View::assign([
  54. 'group'=>$group,
  55. ]);
  56. return View('/admin/add');
  57. }
  58. //添加管理员信息
  59. public function add_user()
  60. {
  61. //管理员信息接收
  62. $data['username'] = Request::post('username');
  63. $data['password'] = md5($data['username'].Request::post('password'));
  64. $data['gid'] = Request::post('gid');
  65. $data['truename'] = Request::post('truename');
  66. $data['add_time'] = time();
  67. $data['lastlogin'] = time();
  68. $data['status'] = Request::post('status');
  69. $data['phone'] = Request::post('phone','');
  70. //查询是否有此管理员
  71. if (!empty($data)) {
  72. $find = Db::table('admin')->where('username',$data['username'])->field('username')->find();
  73. }
  74. //添加管理员
  75. if (!empty($find)) {
  76. exit(json_encode(['id'=>0,"msg"=>'该用户名已存在']));
  77. }else {
  78. if (!empty($data)) {
  79. $insert = Db::table('admin')->insert($data);
  80. }
  81. }
  82. if (!empty($insert)) {
  83. exit(json_encode(['id'=>1,"msg"=>'添加成功']));
  84. }else {
  85. exit(json_encode(['id'=>0,"msg"=>'添加失败']));
  86. }
  87. }
  88. //管理员账号修改
  89. public function edit_user()
  90. {
  91. //管理员信息接收
  92. $id = Request::param('aid');
  93. $data['username'] = Request::post('username');
  94. $data['password'] = md5($data['username'].Request::post('password'));
  95. $data['gid'] = Request::post('gid');
  96. $data['truename'] = Request::post('truename');
  97. $data['lastlogin'] = time();
  98. $data['status'] = Request::post('status');
  99. if (!empty($data)) {
  100. //更新用户信息
  101. $update = Db::table("admin")->where('id',$id)->update($data);
  102. }
  103. if (!empty($update)) {
  104. echo json_encode(['id' =>1 ,'msg'=>'修改成功' ]);
  105. }else {
  106. echo json_encode(['id' =>0 ,'msg'=>'修改失败' ]);
  107. }
  108. }
  109. //用户删除
  110. public function dle()
  111. {
  112. $aid = Request::param("aid");
  113. if (!empty($aid)) {
  114. $delete = Db::table("admin")->where('id',$aid)->delete();
  115. }
  116. if (!empty($delete)) {
  117. echo json_encode(['id' => 1 ,'msg'=>'删除成功']);
  118. }else {
  119. echo json_encode(['id' => 0 ,'msg'=>'删除失败']);
  120. }
  121. }
  122. }
Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post