From 5cfffb47305ae6e97f95ca2a2e2937a49d50218c Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 11 Oct 2024 15:42:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/user/Admin.php | 213 ++++++++++++++++++++++++ app/admin/model/User.php | 14 ++ app/admin/view/user/admin/add.html | 71 ++++++++ app/admin/view/user/admin/edit.html | 47 ++++++ app/admin/view/user/admin/index.html | 10 ++ app/admin/view/user/admin/password.html | 27 +++ app/api/common.php | 13 -- app/common.php | 14 ++ composer.json | 2 +- public/static/admin/js/user/admin.js | 62 +++++++ 10 files changed, 459 insertions(+), 14 deletions(-) create mode 100644 app/admin/controller/user/Admin.php create mode 100644 app/admin/model/User.php create mode 100644 app/admin/view/user/admin/add.html create mode 100644 app/admin/view/user/admin/edit.html create mode 100644 app/admin/view/user/admin/index.html create mode 100644 app/admin/view/user/admin/password.html create mode 100644 public/static/admin/js/user/admin.js diff --git a/app/admin/controller/user/Admin.php b/app/admin/controller/user/Admin.php new file mode 100644 index 0000000..81f2a48 --- /dev/null +++ b/app/admin/controller/user/Admin.php @@ -0,0 +1,213 @@ +model = new User(); + } + + /** + * @NodeAnotation(title="列表") + */ + public function index() + { + if ($this->request->isAjax()) { + if (input('selectFields')) { + return $this->selectList(); + } + list($page, $limit, $where) = $this->buildTableParames(); + $count = $this->model + ->where($where) + ->count(); + $list = $this->model + ->withoutField('password,salt,delete_time') + ->field('uid as id') + ->where($where) + ->page($page, $limit) + ->order('uid') + ->select(); + $data = [ + 'code' => 0, + 'msg' => '', + 'count' => $count, + 'data' => $list + ]; + return json($data); + } + return $this->fetch(); + } + + /** + * @NodeAnotation(title="添加") + */ + public function add() + { + if ($this->request->isPost()) { + $post = $this->request->post(); + $rule = [ + 'avatar|用户头像' => 'require', + 'nick_name|用户名' => 'require|unique:user', + 'password|密码' => 'require', + 'qr_password|确认密码' => 'require|confirm:password', + 'mobile|手机' => 'require|mobile', + 'gender|性别' => 'require|in:1,2,3', + 'status|状态' => 'require|in:0,1' + ]; + $this->validate($post, $rule); + try { + $salt = makeSalt(6); + $post['salt'] = $salt; + $post['password'] = password($post['password'] . $salt); + $save = $this->model->save($post); + } catch (\Exception $e) { + $this->error('保存失败'); + } + $save ? $this->success('保存成功') : $this->error('保存失败'); + } + return $this->fetch(); + } + + /** + * @NodeAnotation(title="编辑") + */ + public function edit($id) + { + $row = $this->model->where('uid', $id)->find(); + empty($row) && $this->error('数据不存在'); + if ($this->request->isPost()) { + $post = $this->request->post(); + $rule = [ + 'avatar|用户头像' => 'require', + 'mobile|手机' => 'require|mobile', + 'gender|性别' => 'require|in:1,2,3', + 'status|状态' => 'require|in:0,1' + ]; + $this->validate($post, $rule); + try { + $save = $row->save($post); + } catch (\Exception $e) { + $this->error('保存失败'); + } + $save ? $this->success('保存成功') : $this->error('保存失败'); + } + $this->assign('row', $row); + return $this->fetch(); + } + + /** + * @NodeAnotation(title="编辑") + */ + public function password($id) + { + $row = $this->model->where('uid', $id)->find(); + empty($row) && $this->error('数据不存在'); + if ($this->request->isAjax()) { + $this->checkPostRequest(); + $post = $this->request->post(); + $rule = [ + 'password|密码' => 'require', + 'qr_password|确认密码' => 'require|confirm:password', + ]; + $this->validate($post, $rule); + try { + $salt = makeSalt(6); + $post['salt'] = $salt; + $save = $row->save([ + 'salt' => $salt, + 'password' => password($post['password'] . $salt) + ]); + } catch (\Exception $e) { + $this->error('保存失败'); + } + $save ? $this->success('保存成功') : $this->error('保存失败'); + } + $this->assign('row', $row); + return $this->fetch(); + } + + /** + * @NodeAnotation(title="删除") + */ + public function delete($id) + { + $this->checkPostRequest(); + $row = $this->model->whereIn('uid', $id)->select(); + $row->isEmpty() && $this->error('数据不存在'); + try { + $save = false; + foreach ($row as $value) { + $save = $this->model->where('uid', $value['uid'])->useSoftDelete('delete_time',time())->delete(); + } + } catch (\Exception $e) { + $this->error('删除失败'); + } + $save ? $this->success('删除成功') : $this->error('删除失败'); + } + + /** + * @NodeAnotation(title="属性修改") + */ + public function modify() + { + $this->checkPostRequest(); + $post = $this->request->post(); + $rule = [ + 'id|ID' => 'require', + 'field|字段' => 'require', + 'value|值' => 'require', + ]; + $this->validate($post, $rule); + if (!in_array($post['field'], $this->allowModifyFields)) { + $this->error('该字段不允许修改:' . $post['field']); + } + $row = $this->model->where('uid',$post['id'])->find(); + empty($row) && $this->error('数据不存在'); + try { + $row->save([ + $post['field'] => $post['value'], + ]); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + $this->success('保存成功'); + } + + /** + * @NodeAnotation(title="导出") + */ + public function export() + { + list($page, $limit, $where) = $this->buildTableParames(); + $tableName = $this->model->getName(); + $tableName = CommonTool::humpToLine(lcfirst($tableName)); + $prefix = config('database.connections.mysql.prefix'); + $dbList = Db::query("show full columns from {$prefix}{$tableName}"); + $header = []; + foreach ($dbList as $vo) { + $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field']; + if (!in_array($vo['Field'], $this->noExportFields)) { + $header[] = [$comment, $vo['Field']]; + } + } + $list = $this->model + ->where($where) + ->limit(100000) + ->order('uid', 'desc') + ->select() + ->toArray(); + $fileName = time(); + return Excel::exportData($list, $header, $fileName, 'xlsx'); + } +} \ No newline at end of file diff --git a/app/admin/model/User.php b/app/admin/model/User.php new file mode 100644 index 0000000..b03b214 --- /dev/null +++ b/app/admin/model/User.php @@ -0,0 +1,14 @@ + +
+ +
+ +
+ + +
+
+ +
+ +
+ + 填写登录账户。 +
+
+ +
+ +
+ + 填写登录密码。 +
+
+ +
+ +
+ + 填写确认登录密码。 +
+
+ +
+ +
+ + 填写用户手机。 +
+
+ +
+ +
+ + + +
+
+ +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ \ No newline at end of file diff --git a/app/admin/view/user/admin/edit.html b/app/admin/view/user/admin/edit.html new file mode 100644 index 0000000..916d2ea --- /dev/null +++ b/app/admin/view/user/admin/edit.html @@ -0,0 +1,47 @@ +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + 填写用户手机。 +
+
+ +
+ +
+ + + +
+
+ +
+ +
+ + +
+
+ +
+
+ + +
+ +
+
diff --git a/app/admin/view/user/admin/index.html b/app/admin/view/user/admin/index.html new file mode 100644 index 0000000..3892d3c --- /dev/null +++ b/app/admin/view/user/admin/index.html @@ -0,0 +1,10 @@ +
+
+ +
+
+
diff --git a/app/admin/view/user/admin/password.html b/app/admin/view/user/admin/password.html new file mode 100644 index 0000000..4137665 --- /dev/null +++ b/app/admin/view/user/admin/password.html @@ -0,0 +1,27 @@ +
+
+ +
+ +
+ + 填写登录密码。 +
+
+ +
+ +
+ + 填写确认登录密码。 +
+
+ +
+
+ + +
+ +
+
\ No newline at end of file diff --git a/app/api/common.php b/app/api/common.php index 873c690..b3d9bbc 100644 --- a/app/api/common.php +++ b/app/api/common.php @@ -1,14 +1 @@ =7.1.0", - "topthink/framework": "^6.0.0", + "topthink/framework": "6.0.8", "topthink/think-orm": "^2.0", "topthink/think-multi-app": "^1.0", "topthink/think-view": "^1.0", diff --git a/public/static/admin/js/user/admin.js b/public/static/admin/js/user/admin.js new file mode 100644 index 0000000..cb7c30f --- /dev/null +++ b/public/static/admin/js/user/admin.js @@ -0,0 +1,62 @@ +define(["jquery", "easy-admin"], function ($, ea) { + + var init = { + table_elem: '#currentTable', + table_render_id: 'currentTableRenderId', + index_url: 'user.admin/index', + add_url: 'user.admin/add', + edit_url: 'user.admin/edit', + delete_url: 'user.admin/delete', + modify_url: 'user.admin/modify', + export_url: 'user.admin/export', + password_url: 'user.admin/password', + }; + + var Controller = { + + index: function () { + + ea.table.render({ + init: init, + cols: [[ + {type: "checkbox"}, + {field: 'uid', width: 80, title: '用户ID'}, + {field: 'nick_name', minWidth: 80, title: '用户昵称'}, + {field: 'avatar', minWidth: 80, title: '头像', search: false, templet: ea.table.image}, + {field: 'mobile', minWidth: 80, title: '手机号'}, + {field: 'last_login_time', minWidth: 80, title: '最后登录时间'}, + {field: 'status', title: '状态', width: 100, search: 'select', selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch}, + {field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'}, + { + width: 250, + title: '操作', + templet: ea.table.tool, + operat: [ + 'edit', + [{ + text: '设置密码', + url: init.password_url, + method: 'open', + auth: 'password', + class: 'layui-btn layui-btn-normal layui-btn-xs', + }], + 'delete' + ] + } + ]], + }); + + ea.listen(); + }, + add: function () { + ea.listen(); + }, + edit: function () { + ea.listen(); + }, + password: function () { + ea.listen(); + } + }; + return Controller; +}); \ No newline at end of file