diff --git a/database/migrations/20250321053230_new_admin_nickname_column.php b/database/migrations/20250321053230_new_admin_nickname_column.php new file mode 100644 index 0000000..55b8308 --- /dev/null +++ b/database/migrations/20250321053230_new_admin_nickname_column.php @@ -0,0 +1,39 @@ +table('system_admin'); + + if(!$table->hasColumn('nickname')){ + $table->addColumn(Column::string('nickname', 50)->setDefault('')->setComment('昵称')); + $table->update(); + } + } +} diff --git a/extend/base/admin/controller/IndexBase.php b/extend/base/admin/controller/IndexBase.php index 6d070b9..857b211 100644 --- a/extend/base/admin/controller/IndexBase.php +++ b/extend/base/admin/controller/IndexBase.php @@ -60,15 +60,25 @@ class IndexBase extends AdminController $this->isDemo && $this->error('演示环境下不允许修改'); $rule = []; $this->validate($post, $rule); + if (empty($post['nickname'])) { + $post['nickname'] = $row['username']; + } try { + $model_admin = SystemAdmin::where('username', $post['username']) + ->where('id', '<>', $id) + ->find(); + if (!empty($model_admin)) { + throw new \Exception('同名用户已存在'); + } + $save = $row - ->allowField(['head_img', 'phone', 'remark', 'update_time']) + ->allowField(['head_img', 'phone', 'remark', 'update_time', 'nickname']) ->save($post); } catch (\Exception $e) { if (App::isDebug()) { throw $e; } - $this->error('保存失败'); + $this->error('保存失败:'. $e->getMessage()); } $save ? $this->success('保存成功') : $this->error('保存失败'); } @@ -110,7 +120,7 @@ class IndexBase extends AdminController 'password' => password($post['password']), ]); } catch (\Exception $e) { - if(App::isDebug()){ + if (App::isDebug()) { throw $e; } $this->error('保存失败'); @@ -140,8 +150,8 @@ class IndexBase extends AdminController 'sort' => 'desc', 'id' => 'asc', ]) - ->where('status', 1) - ->select(); + ->where('status', 1) + ->select(); $list_menu_pid = SystemMenu::group('pid')->column('pid'); diff --git a/extend/base/admin/controller/system/AdminBase.php b/extend/base/admin/controller/system/AdminBase.php index 23224dc..b8d50da 100644 --- a/extend/base/admin/controller/system/AdminBase.php +++ b/extend/base/admin/controller/system/AdminBase.php @@ -84,6 +84,9 @@ class AdminBase extends AdminController $post['password'] = password(sysconfig('site', 'site_default_password', '123456')); $this->validate($post, $rule); + if (empty($post['nickname'])) { + $post['nickname'] = $post['username']; + } try { $model_admin = SystemAdmin::where('username', $post['username'])->find(); @@ -117,11 +120,21 @@ class AdminBase extends AdminController if (isset($row['password'])) { unset($row['password']); } + if (empty($post['nickname'])) { + $post['nickname'] = $post['username']; + } try { + $model_admin = SystemAdmin::where('username', $post['username']) + ->where('id', '<>', $id) + ->find(); + if (!empty($model_admin)) { + throw new \Exception('同名用户已存在'); + } + $save = $row->save($post); TriggerService::updateMenu($id); } catch (\Exception $e) { - $this->error('保存失败'); + $this->error('保存失败:' . $e->getMessage()); } $save ? $this->success('保存成功') : $this->error('保存失败'); } diff --git a/extend/base/admin/view/index/edit_admin.html b/extend/base/admin/view/index/edit_admin.html index 61d583c..b00e06c 100644 --- a/extend/base/admin/view/index/edit_admin.html +++ b/extend/base/admin/view/index/edit_admin.html @@ -17,11 +17,18 @@