🚀 202405重置版

This commit is contained in:
wolfcode
2024-05-13 11:16:20 +08:00
parent 504ab4c4cf
commit a6fd81b0ed
242 changed files with 1169 additions and 2698 deletions

View File

@@ -8,7 +8,10 @@ use app\common\constants\AdminConstant;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\Request;
use think\App;
use think\db\exception\DbException;
use think\response\Json;
/**
* Class Admin
@@ -18,8 +21,6 @@ use think\App;
class Admin extends AdminController
{
use \app\admin\traits\Curd;
protected array $sort = [
'sort' => 'desc',
'id' => 'desc',
@@ -34,10 +35,11 @@ class Admin extends AdminController
/**
* @NodeAnnotation(title="列表")
* @throws DbException
*/
public function index()
public function index(Request $request): Json|string
{
if ($this->request->isAjax()) {
if ($request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
@@ -50,7 +52,7 @@ class Admin extends AdminController
->where($where)
->page($page, $limit)
->order($this->sort)
->select();
->select()->toArray();
$data = [
'code' => 0,
'msg' => '',
@@ -65,11 +67,11 @@ class Admin extends AdminController
/**
* @NodeAnnotation(title="添加")
*/
public function add()
public function add(Request $request): string
{
if ($this->request->isPost()) {
$post = $this->request->post();
$authIds = $this->request->post('auth_ids', []);
if ($request->isPost()) {
$post = $request->post();
$authIds = $request->post('auth_ids', []);
$post['auth_ids'] = implode(',', array_keys($authIds));
$rule = [];
$this->validate($post, $rule);
@@ -77,7 +79,7 @@ class Admin extends AdminController
$post['password'] = password($post['password']);
try {
$save = $this->model->save($post);
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('保存失败');
}
$save ? $this->success('保存成功') : $this->error('保存失败');
@@ -88,13 +90,13 @@ class Admin extends AdminController
/**
* @NodeAnnotation(title="编辑")
*/
public function edit($id)
public function edit(Request $request, $id = 0): string
{
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
if ($this->request->isPost()) {
$post = $this->request->post();
$authIds = $this->request->post('auth_ids', []);
if ($request->isPost()) {
$post = $request->post();
$authIds = $request->post('auth_ids', []);
$post['auth_ids'] = implode(',', array_keys($authIds));
$rule = [];
$this->validate($post, $rule);
@@ -104,7 +106,7 @@ class Admin extends AdminController
try {
$save = $row->save($post);
TriggerService::updateMenu($id);
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('保存失败');
}
$save ? $this->success('保存成功') : $this->error('保存失败');
@@ -117,12 +119,12 @@ class Admin extends AdminController
/**
* @NodeAnnotation(title="编辑")
*/
public function password($id)
public function password(Request $request, $id): string
{
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
if ($this->request->isAjax()) {
$post = $this->request->post();
if ($request->isAjax()) {
$post = $request->post();
$rule = [
'password|登录密码' => 'require',
'password_again|确认密码' => 'require',
@@ -133,9 +135,9 @@ class Admin extends AdminController
}
try {
$save = $row->save([
'password' => password($post['password']),
]);
} catch (\Exception $e) {
'password' => password($post['password']),
]);
}catch (\Exception $e) {
$this->error('保存失败');
}
$save ? $this->success('保存成功') : $this->error('保存失败');
@@ -148,7 +150,7 @@ class Admin extends AdminController
/**
* @NodeAnnotation(title="删除")
*/
public function delete($id)
public function delete($id): void
{
$this->checkPostRequest();
$row = $this->model->whereIn('id', $id)->select();
@@ -161,7 +163,7 @@ class Admin extends AdminController
}
try {
$save = $row->delete();
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('删除失败');
}
$save ? $this->success('删除成功') : $this->error('删除失败');
@@ -170,14 +172,14 @@ class Admin extends AdminController
/**
* @NodeAnnotation(title="属性修改")
*/
public function modify()
public function modify(Request $request): void
{
$this->checkPostRequest();
$post = $this->request->post();
$post = $request->post();
$rule = [
'id|ID' => 'require',
'id|ID' => 'require',
'field|字段' => 'require',
'value|值' => 'require',
'value|值' => 'require',
];
$this->validate($post, $rule);
if (!in_array($post['field'], $this->allowModifyFields)) {
@@ -190,9 +192,9 @@ class Admin extends AdminController
empty($row) && $this->error('数据不存在');
try {
$row->save([
$post['field'] => $post['value'],
]);
} catch (\Exception $e) {
$post['field'] => $post['value'],
]);
}catch (\Exception $e) {
$this->error($e->getMessage());
}
$this->success('保存成功');

View File

@@ -8,6 +8,7 @@ use app\admin\service\TriggerService;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\Request;
use think\App;
/**
@@ -18,8 +19,6 @@ use think\App;
class Auth extends AdminController
{
use \app\admin\traits\Curd;
protected array $sort = [
'sort' => 'desc',
'id' => 'desc',
@@ -34,11 +33,11 @@ class Auth extends AdminController
/**
* @NodeAnnotation(title="授权")
*/
public function authorize($id)
public function authorize(Request $request, $id): string
{
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
if ($this->request->isAjax()) {
if ($request->isAjax()) {
$list = $this->model->getAuthorizeNodeListByAdminId($id);
$this->success('获取成功', $list);
}
@@ -49,11 +48,11 @@ class Auth extends AdminController
/**
* @NodeAnnotation(title="授权保存")
*/
public function saveAuthorize()
public function saveAuthorize(Request $request): void
{
$this->checkPostRequest();
$id = $this->request->post('id');
$node = $this->request->post('node', "[]");
$id = $request->post('id');
$node = $request->post('node', "[]");
$node = json_decode($node, true);
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
@@ -71,7 +70,7 @@ class Auth extends AdminController
$authNode->saveAll($saveAll);
}
TriggerService::updateMenu();
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('保存失败');
}
$this->success('保存成功');

View File

@@ -7,7 +7,9 @@ use app\admin\service\TriggerService;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\Request;
use think\App;
use think\response\Json;
/**
* Class Config
@@ -28,7 +30,7 @@ class Config extends AdminController
/**
* @NodeAnnotation(title="列表")
*/
public function index()
public function index(Request $request): Json|string
{
return $this->fetch();
}
@@ -36,10 +38,10 @@ class Config extends AdminController
/**
* @NodeAnnotation(title="保存")
*/
public function save()
public function save(Request $request): void
{
$this->checkPostRequest();
$post = $this->request->post();
$post = $request->post();
$notAddFields = ['_token', 'file', 'group'];
try {
$group = $post['group'] ?? '';
@@ -53,7 +55,7 @@ class Config extends AdminController
if (in_array($key, $notAddFields)) continue;
if ($this->model->where('name', $key)->count()) {
$this->model->where('name', $key)->update(['value' => $val,]);
} else {
}else {
$this->model->create(
[
'name' => $key,
@@ -63,8 +65,8 @@ class Config extends AdminController
}
}
TriggerService::updateMenu();
TriggerService::updateSysconfig();
} catch (\Exception $e) {
TriggerService::updatesysConfig();
}catch (\Exception $e) {
$this->error('保存失败');
}
$this->success('保存成功');

View File

@@ -23,7 +23,7 @@ class CurdGenerate extends AdminController
/**
* @NodeAnnotation(title="列表")
*/
public function index()
public function index(Request $request): Json|string
{
return $this->fetch();
}
@@ -74,7 +74,7 @@ class CurdGenerate extends AdminController
$_fileExp_last = array_slice($_fileExp, -2);
$_fileExp_last_0 = $_fileExp_last[0] . '.';
if ($_fileExp_last[0] == 'controller') $_fileExp_last_0 = '';
$link = '/' . env('EASYADMIN.ADMIN', 'admin') . '/' . $_fileExp_last_0 . Str::snake(explode('.php', end($_fileExp_last))[0] ?? '') . '/index';
$link = '/' . config('admin.alias_name') . '/' . $_fileExp_last_0 . Str::snake(explode('.php', end($_fileExp_last))[0] ?? '') . '/index';
}
$this->success('生成成功', compact('result', 'link'));
}catch (FileException $exception) {

View File

@@ -4,15 +4,16 @@ namespace app\admin\controller\system;
use app\admin\model\SystemLog;
use app\admin\service\tool\CommonTool;
use app\admin\traits\Curd;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\Request;
use jianyan\excel\Excel;
use think\App;
use think\db\exception\DbException;
use think\db\exception\PDOException;
use think\facade\Db;
use think\response\Json;
/**
* @ControllerAnnotation(title="操作日志管理")
@@ -21,7 +22,6 @@ use think\facade\Db;
*/
class Log extends AdminController
{
use Curd;
public function __construct(App $app)
{
@@ -32,9 +32,9 @@ class Log extends AdminController
/**
* @NodeAnnotation(title="列表")
*/
public function index()
public function index(Request $request): Json|string
{
if ($this->request->isAjax()) {
if ($request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
@@ -44,7 +44,7 @@ class Log extends AdminController
try {
$count = $model->count();
$list = $model->page($page, $limit)->order($this->sort)->select();
} catch (PDOException|DbException $exception) {
}catch (PDOException|DbException $exception) {
$count = 0;
$list = [];
}
@@ -62,7 +62,7 @@ class Log extends AdminController
/**
* @NodeAnnotation(title="导出")
*/
public function export()
public function export(): bool
{
if (env('EASYADMIN.IS_DEMO', false)) {
$this->error('演示环境下不允许操作');
@@ -88,7 +88,7 @@ class Log extends AdminController
->order('id', 'desc')
->select()
->toArray();
} catch (PDOException|DbException $exception) {
}catch (PDOException|DbException $exception) {
$this->error($exception->getMessage());
}
$fileName = time();

View File

@@ -5,12 +5,14 @@ namespace app\admin\controller\system;
use app\admin\model\SystemMenu;
use app\admin\model\SystemNode;
use app\admin\service\TriggerService;
use app\admin\traits\Curd;
use app\common\constants\MenuConstant;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\common\controller\AdminController;
use app\Request;
use think\App;
use think\db\exception\DbException;
use think\response\Json;
/**
* Class Menu
@@ -20,8 +22,6 @@ use think\App;
class Menu extends AdminController
{
use Curd;
protected array $sort = [
'sort' => 'desc',
'id' => 'asc',
@@ -35,15 +35,16 @@ class Menu extends AdminController
/**
* @NodeAnnotation(title="列表")
* @throws DbException
*/
public function index()
public function index(Request $request): Json|string
{
if ($this->request->isAjax()) {
if ($request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
$count = $this->model->count();
$list = $this->model->order($this->sort)->select();
$list = $this->model->order($this->sort)->select()->toArray();
$data = [
'code' => 0,
'msg' => '',
@@ -58,14 +59,15 @@ class Menu extends AdminController
/**
* @NodeAnnotation(title="添加")
*/
public function add($id = null)
public function add(Request $request): string
{
$id = $request->param('id');
$homeId = $this->model->where(['pid' => MenuConstant::HOME_PID,])->value('id');
if ($id == $homeId) {
$this->error('首页不能添加子菜单');
}
if ($this->request->isPost()) {
$post = $this->request->post();
if ($request->isPost()) {
$post = $request->post();
$rule = [
'pid|上级菜单' => 'require',
'title|菜单名称' => 'require',
@@ -74,13 +76,13 @@ class Menu extends AdminController
$this->validate($post, $rule);
try {
$save = $this->model->save($post);
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('保存失败');
}
if ($save) {
TriggerService::updateMenu();
$this->success('保存成功');
} else {
}else {
$this->error('保存失败');
}
}
@@ -93,12 +95,12 @@ class Menu extends AdminController
/**
* @NodeAnnotation(title="编辑")
*/
public function edit($id)
public function edit(Request $request, $id = 0): string
{
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
if ($this->request->isPost()) {
$post = $this->request->post();
if ($request->isPost()) {
$post = $request->post();
$rule = [
'pid|上级菜单' => 'require',
'title|菜单名称' => 'require',
@@ -108,42 +110,42 @@ class Menu extends AdminController
if ($row->pid == MenuConstant::HOME_PID) $post['pid'] = MenuConstant::HOME_PID;
try {
$save = $row->save($post);
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('保存失败');
}
if (!empty($save)) {
TriggerService::updateMenu();
$this->success('保存成功');
} else {
}else {
$this->error('保存失败');
}
}
$pidMenuList = $this->model->getPidMenuList();
$this->assign([
'id' => $id,
'pidMenuList' => $pidMenuList,
'row' => $row,
]);
'id' => $id,
'pidMenuList' => $pidMenuList,
'row' => $row,
]);
return $this->fetch();
}
/**
* @NodeAnnotation(title="删除")
*/
public function delete($id)
public function delete($id): void
{
$this->checkPostRequest();
$row = $this->model->whereIn('id', $id)->select();
empty($row) && $this->error('数据不存在');
try {
$save = $row->delete();
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('删除失败');
}
if ($save) {
TriggerService::updateMenu();
$this->success('删除成功');
} else {
}else {
$this->error('删除失败');
}
}
@@ -151,14 +153,14 @@ class Menu extends AdminController
/**
* @NodeAnnotation(title="属性修改")
*/
public function modify()
public function modify(Request $request): void
{
$this->checkPostRequest();
$post = $this->request->post();
$post = $request->post();
$rule = [
'id|ID' => 'require',
'id|ID' => 'require',
'field|字段' => 'require',
'value|值' => 'require',
'value|值' => 'require',
];
$this->validate($post, $rule);
$row = $this->model->find($post['id']);
@@ -170,17 +172,17 @@ class Menu extends AdminController
}
$homeId = $this->model
->where([
'pid' => MenuConstant::HOME_PID,
])
'pid' => MenuConstant::HOME_PID,
])
->value('id');
if ($post['id'] == $homeId && $post['field'] == 'status') {
$this->error('首页状态不允许关闭');
}
try {
$row->save([
$post['field'] => $post['value'],
]);
} catch (\Exception $e) {
$post['field'] => $post['value'],
]);
}catch (\Exception $e) {
$this->error($e->getMessage());
}
TriggerService::updateMenu();
@@ -190,18 +192,18 @@ class Menu extends AdminController
/**
* @NodeAnnotation(title="添加菜单提示")
*/
public function getMenuTips()
public function getMenuTips(): Json
{
$node = input('get.keywords');
$list = SystemNode::whereLike('node', "%{$node}%")
->field('node,title')
->limit(10)
->select();
->select()->toArray();
return json([
'code' => 0,
'content' => $list,
'type' => 'success',
]);
'code' => 0,
'content' => $list,
'type' => 'success',
]);
}
}

View File

@@ -8,7 +8,10 @@ use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\admin\service\NodeService;
use app\Request;
use think\App;
use think\db\exception\DbException;
use think\response\Json;
/**
* @ControllerAnnotation(title="系统节点管理")
@@ -18,8 +21,6 @@ use think\App;
class Node extends AdminController
{
use \app\admin\traits\Curd;
public function __construct(App $app)
{
parent::__construct($app);
@@ -28,10 +29,11 @@ class Node extends AdminController
/**
* @NodeAnnotation(title="列表")
* @throws DbException
*/
public function index()
public function index(Request $request): Json|string
{
if ($this->request->isAjax()) {
if ($request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
@@ -86,7 +88,7 @@ class Node extends AdminController
}
$model->saveAll($nodeList);
TriggerService::updateNode();
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('节点更新失败');
}
$this->success('节点更新成功');
@@ -107,7 +109,7 @@ class Node extends AdminController
!isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->delete();
}
TriggerService::updateNode();
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error('节点更新失败');
}
$this->success('节点更新成功');

View File

@@ -17,8 +17,6 @@ use think\App;
class Quick extends AdminController
{
use \app\admin\traits\Curd;
protected array $sort = [
'sort' => 'desc',
'id' => 'desc',

View File

@@ -10,14 +10,11 @@ use think\App;
/**
* @ControllerAnnotation(title="上传文件管理")
* Class Uploadfile
* @package app\admin\controller\system
*/
class Uploadfile extends AdminController
{
use \app\admin\traits\Curd;
public function __construct(App $app)
{
parent::__construct($app);