From c26870b8c5c2b721e6bd8f540808b9ce12e38536 Mon Sep 17 00:00:00 2001 From: panx <651666084@qq.com> Date: Sat, 17 Aug 2024 16:39:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=89=A9=E6=96=99=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=8A=9F=E8=83=BD=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + app/admin/controller/PdmParttype.php | 186 +++++++++++++++++ app/admin/model/PdmParttype.php | 46 ++++ app/admin/validate/PdmParttype.php | 36 ++++ app/admin/view/pdm_parttype/add.html | 124 +++++++++++ app/admin/view/pdm_parttype/index.html | 196 ++++++++++++++++++ config/event.php | 2 +- public/static/plugin/partmanage/index.js | 1 - .../system/plugin/partmanage/function.js | 1 - 9 files changed, 591 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 app/admin/controller/PdmParttype.php create mode 100644 app/admin/model/PdmParttype.php create mode 100644 app/admin/validate/PdmParttype.php create mode 100644 app/admin/view/pdm_parttype/add.html create mode 100644 app/admin/view/pdm_parttype/index.html delete mode 100644 public/static/plugin/partmanage/index.js delete mode 100644 public/static/system/plugin/partmanage/function.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf6f1e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +public/static/json/2/treeTable/demo-1.json +public/test.html diff --git a/app/admin/controller/PdmParttype.php b/app/admin/controller/PdmParttype.php new file mode 100644 index 0000000..5decd5b --- /dev/null +++ b/app/admin/controller/PdmParttype.php @@ -0,0 +1,186 @@ + + * Class PdmParttype + * @package app\admin\controller + */ +class PdmParttype extends AdminController +{ + /** + * PdmParttype模型对象 + * @var \app\admin\model\PdmParttype + */ + + public function __construct() + { + parent::__construct(); + $this->model = new PdmParttypeModel; + } + + /** + * 默认生成的方法为index/add/edit/del/status 五个方法 + * 当创建CURD的时候,DIY的函数体和模板为空,请自行编写代码 + */ + + /** + * 获取资源列表 + * return Response + */ + public function index(): Response + { + if (request()->isAjax()) { + list($count, $list) = PdmParttype::dataList(request()->all()); + $rules = list_to_tree($list,'id','pid','children',0); + + + return $this->success('获取成功', '/',$rules, $count); + } + + return view('/pdm_parttype/index'); + } + + /** + * 获取资源列表 + * @param array $params + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public static function dataList(array $params): array + { + $where = array(); + if (!empty($params['parttypetitle'])) { + $where[] = ['parttypetitle','like','%'.$params['parttypetitle'].'%']; + } + if (!empty($params['parttypevalue'])) { + $where[] = ['parttypevalue','like','%'.$params['parttypevalue'].'%']; + } + $model = new PdmParttypeModel(); + $count = $model->where($where)->count(); + $list = $model->where($where)->order('sort asc')->select()->toArray(); + foreach ($list as $key => $value) { + $list[$key]['parttypetitle'] = __($value['parttypetitle']); + } + // $users = array(); + $users = $model->usernames(); + + // throw new \Exception(json_encode($users)); + foreach ($list as $key => $value) { + foreach ($users as $keyuser => $valueuser) { + // if ($users[$keyuser]['id'] == $list[$key]['id']){ + // // $list[$key]['createrid'] = __($users[$keyuser]['nickname']); + // $list[$key]['createrid'] = __($users[$keyuser]['name']); + // break; + // } + if ($value['createrid'] == $valueuser['id']) { + // $list[$key]['createrid'] = __($valueuser['name']); + $list[$key]['createrid'] = __($valueuser['nickname']); + break; + }else{ + $list[$key]['createrid'] =$list[$key]['createrid'].'|'. __('未知用户'); + } + + } + } + + return [$count, $list]; + } + + + + /** + * 添加节点数据 + * @return Response + */ + public function add(): Response + { + if (request()->isPost()) { + $post = \request()->post(); + // validate(\app\common\validate\system\AdminRules::class . '.add')->check($post); + $userid = get_admin_id(); + $post['createrid'] = $userid ; + // if(empty($userid)){ + // $post['createrid'] = 'empty'; + // }else{ + // $post['createrid'] = 'noneempty' ; + // } + if ($this->model->create($post)) { + return $this->success('添加分类成功!'); + } + } + + $data = $this->getTableFields(); + $data['pid'] = input('pid', 0); + $data['auth'] = 1; + $data['type'] = 1; + + list($count, $list) = PdmParttype::dataList(request()->all()); + return view('/pdm_parttype/add', [ + 'data' => $data, + 'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE), + ]); + } + + /** + * 编辑节点数据 + * @return Response + * @throws DbException + * @throws DataNotFoundException + * @throws ModelNotFoundException + */ + public function edit(): Response + { + $id = input('id', 0); + $data = $this->model->find($id); + if (request()->isPost()) { + $post = \request()->post(); + // validate(\app\common\validate\system\AdminRules::class . '.edit')->check($post); + if ($this->model->update($post)) { + return $this->success('更新分类成功!'); + } + } + + list($count, $list) = PdmParttype::dataList(request()->all()); + return view('/pdm_parttype/add', [ + 'data' => $data, + 'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE), + ]); + } + + /** + * 删除节点数据 + * @return Response + * @throws DbException + */ + public function del(): Response + { + $id = input('id'); + if (!empty($id)) { + // 查询子节点 + if ($this->model->where('pid',$id)->count()) { + return $this->error('当前菜单存在子菜单!'); + } + + // 删除单个 + if ($this->model::destroy($id)) { + return $this->success('删除菜单成功!'); + } + } + + return $this->error('删除失败,请检查您的参数!'); + } + + + +} diff --git a/app/admin/model/PdmParttype.php b/app/admin/model/PdmParttype.php new file mode 100644 index 0000000..96df81c --- /dev/null +++ b/app/admin/model/PdmParttype.php @@ -0,0 +1,46 @@ + + * 分类目录 + * Class PdmParttype + * @package app\admin\model + */ +class PdmParttype extends Model +{ + + use SoftDelete; + + // 定义时间戳字段名 + protected $createTime = 'create_time'; + protected $updateTime = 'update_time'; + protected $deleteTime = 'delete_time'; + + + /** + * 定义 sa_user 关联模型 + * @localKey id + * @bind name,nickname + */ + public function user() + { + return $this->hasOne(\app\common\model\system\User::Class,'createrid','id')->bind(['nickname']); + } + + public function usernames() + { + // return \app\common\model\system\User::select()->toArray(); + return \app\common\model\system\Admin::select()->toArray(); + } + + + + + +} \ No newline at end of file diff --git a/app/admin/validate/PdmParttype.php b/app/admin/validate/PdmParttype.php new file mode 100644 index 0000000..00902e5 --- /dev/null +++ b/app/admin/validate/PdmParttype.php @@ -0,0 +1,36 @@ + + * PdmParttype 验证器 + * Class PdmParttype + * @package app\admin\validate + */ +class PdmParttype extends Validate +{ + /** + * 验证规则 + */ + protected $rule = [ + ]; + + + /** + * 提示消息 + */ + protected $message = [ + ]; + + + /** + * 验证场景 + */ + protected $scene = [ + 'add' => [], + 'edit' => [], + ]; + +} diff --git a/app/admin/view/pdm_parttype/add.html b/app/admin/view/pdm_parttype/add.html new file mode 100644 index 0000000..d0167ed --- /dev/null +++ b/app/admin/view/pdm_parttype/add.html @@ -0,0 +1,124 @@ + + + + +
+
+ +
+ + + + + +
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ + + +
+ + + + diff --git a/app/admin/view/pdm_parttype/index.html b/app/admin/view/pdm_parttype/index.html new file mode 100644 index 0000000..8a61394 --- /dev/null +++ b/app/admin/view/pdm_parttype/index.html @@ -0,0 +1,196 @@ + + +
+
+ +
+
+ + +
+
+
{:__('Parttype')}
+
+ +
+
+
+ + + + + + + +
+
+
+
+ +
+
+
+ + + + + + + + + + + + + diff --git a/config/event.php b/config/event.php index cddf11e..1e18d21 100644 --- a/config/event.php +++ b/config/event.php @@ -4,6 +4,6 @@ return [ [plugin\easyflow\Easyflow::class, 'appInit'], ], 'testhook'=> [ - [\plugin\demo\Demo::class, 'testhook'], + [plugin\demo\Demo::class, 'testhook'], ], ]; \ No newline at end of file diff --git a/public/static/plugin/partmanage/index.js b/public/static/plugin/partmanage/index.js deleted file mode 100644 index 99ba0e1..0000000 --- a/public/static/plugin/partmanage/index.js +++ /dev/null @@ -1 +0,0 @@ -// 前端JS文件 \ No newline at end of file diff --git a/public/static/system/plugin/partmanage/function.js b/public/static/system/plugin/partmanage/function.js deleted file mode 100644 index 9985cec..0000000 --- a/public/static/system/plugin/partmanage/function.js +++ /dev/null @@ -1 +0,0 @@ -// 后端JS文件 \ No newline at end of file