From f81eaf40afba42292c9ce8641889b81612b2868a Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 22 May 2021 11:02:45 +0800 Subject: [PATCH] cms first commit --- catch/cms/CmsService.php | 25 ++ catch/cms/README.md | 6 + catch/cms/controller/Articles.php | 80 ++++ catch/cms/controller/Banners.php | 80 ++++ catch/cms/controller/Category.php | 91 +++++ catch/cms/controller/Comments.php | 80 ++++ catch/cms/controller/FormData.php | 80 ++++ catch/cms/controller/FormFields.php | 80 ++++ catch/cms/controller/Forms.php | 80 ++++ catch/cms/controller/ModelFields.php | 95 +++++ catch/cms/controller/Models.php | 85 ++++ catch/cms/controller/SiteLinks.php | 80 ++++ catch/cms/controller/Tags.php | 69 ++++ catch/cms/controller/Upload.php | 69 ++++ catch/cms/controller/Users.php | 80 ++++ .../20201227190439_cms_home_users.php | 44 ++ .../20201227191507_cms_category.php | 53 +++ .../20201227194032_cms_articles.php | 54 +++ .../migrations/20201227194430_cms_tags.php | 43 ++ ...20201227194630_cms_article_relate_tags.php | 37 ++ .../20201227195319_cms_comments.php | 46 +++ .../migrations/20201227195847_cms_banners.php | 43 ++ .../20201227200244_cms_site_links.php | 44 ++ .../migrations/20201227201933_cms_forms.php | 49 +++ .../20201227202845_cms_form_fields.php | 48 +++ .../20201227203533_cms_form_data.php | 44 ++ .../migrations/20201229200249_cms_model.php | 43 ++ .../20201229210020_cms_model_fields.php | 55 +++ .../20210308082210_model_auxiliary_table.php | 51 +++ .../20210430101955_add_model_fields.php | 48 +++ .../20210517014609_add_article_columns.php | 57 +++ catch/cms/exceptions/ColumnException.php | 24 ++ catch/cms/exceptions/TableException.php | 23 ++ catch/cms/model/Articles.php | 91 +++++ catch/cms/model/Banners.php | 40 ++ catch/cms/model/BaseModel.php | 27 ++ catch/cms/model/Category.php | 103 +++++ catch/cms/model/Comments.php | 46 +++ catch/cms/model/FormData.php | 42 ++ catch/cms/model/FormFields.php | 50 +++ catch/cms/model/Forms.php | 41 ++ catch/cms/model/ModelAuxiliaryTable.php | 104 +++++ catch/cms/model/ModelFields.php | 112 +++++ catch/cms/model/Models.php | 62 +++ catch/cms/model/SiteLinks.php | 56 +++ catch/cms/model/Tags.php | 46 +++ catch/cms/model/Users.php | 42 ++ catch/cms/model/events/ArticlesEvent.php | 58 +++ catch/cms/model/events/CategoryEvent.php | 83 ++++ catch/cms/model/events/ModelFieldsEvent.php | 167 ++++++++ catch/cms/model/events/ModelsEvent.php | 52 +++ catch/cms/model/scopes/CategoryScope.php | 36 ++ catch/cms/module.json | 18 + catch/cms/route.php | 49 +++ catch/cms/support/AuxiliaryTable.php | 113 ++++++ catch/cms/support/DynamicFormFields.php | 384 ++++++++++++++++++ catch/cms/support/Helper.php | 68 ++++ catch/cms/support/Table.php | 52 +++ catch/cms/support/TableColumn.php | 321 +++++++++++++++ catch/cms/tables/Articles.php | 47 +++ catch/cms/tables/Category.php | 59 +++ catch/cms/tables/Fields.php | 50 +++ catch/cms/tables/Model.php | 48 +++ catch/cms/tables/ModelUsedFields.php | 21 + catch/cms/tables/SiteLink.php | 45 ++ catch/cms/tables/Tags.php | 45 ++ catch/cms/tables/UsedAt.php | 21 + catch/cms/tables/forms/Articles.php | 71 ++++ catch/cms/tables/forms/BaseForm.php | 22 + catch/cms/tables/forms/Category.php | 73 ++++ catch/cms/tables/forms/Factory.php | 12 + catch/cms/tables/forms/Field.php | 128 ++++++ catch/cms/tables/forms/Model.php | 67 +++ catch/cms/tables/forms/ModelUsedFields.php | 66 +++ catch/cms/tables/forms/SiteLink.php | 30 ++ catch/cms/tables/forms/Tags.php | 21 + catch/cms/tables/forms/UsedAt.php | 15 + 77 files changed, 4990 insertions(+) create mode 100644 catch/cms/CmsService.php create mode 100644 catch/cms/README.md create mode 100644 catch/cms/controller/Articles.php create mode 100644 catch/cms/controller/Banners.php create mode 100644 catch/cms/controller/Category.php create mode 100644 catch/cms/controller/Comments.php create mode 100644 catch/cms/controller/FormData.php create mode 100644 catch/cms/controller/FormFields.php create mode 100644 catch/cms/controller/Forms.php create mode 100644 catch/cms/controller/ModelFields.php create mode 100644 catch/cms/controller/Models.php create mode 100644 catch/cms/controller/SiteLinks.php create mode 100644 catch/cms/controller/Tags.php create mode 100644 catch/cms/controller/Upload.php create mode 100644 catch/cms/controller/Users.php create mode 100644 catch/cms/database/migrations/20201227190439_cms_home_users.php create mode 100644 catch/cms/database/migrations/20201227191507_cms_category.php create mode 100644 catch/cms/database/migrations/20201227194032_cms_articles.php create mode 100644 catch/cms/database/migrations/20201227194430_cms_tags.php create mode 100644 catch/cms/database/migrations/20201227194630_cms_article_relate_tags.php create mode 100644 catch/cms/database/migrations/20201227195319_cms_comments.php create mode 100644 catch/cms/database/migrations/20201227195847_cms_banners.php create mode 100644 catch/cms/database/migrations/20201227200244_cms_site_links.php create mode 100644 catch/cms/database/migrations/20201227201933_cms_forms.php create mode 100644 catch/cms/database/migrations/20201227202845_cms_form_fields.php create mode 100644 catch/cms/database/migrations/20201227203533_cms_form_data.php create mode 100644 catch/cms/database/migrations/20201229200249_cms_model.php create mode 100644 catch/cms/database/migrations/20201229210020_cms_model_fields.php create mode 100644 catch/cms/database/migrations/20210308082210_model_auxiliary_table.php create mode 100644 catch/cms/database/migrations/20210430101955_add_model_fields.php create mode 100644 catch/cms/database/migrations/20210517014609_add_article_columns.php create mode 100644 catch/cms/exceptions/ColumnException.php create mode 100644 catch/cms/exceptions/TableException.php create mode 100644 catch/cms/model/Articles.php create mode 100644 catch/cms/model/Banners.php create mode 100644 catch/cms/model/BaseModel.php create mode 100644 catch/cms/model/Category.php create mode 100644 catch/cms/model/Comments.php create mode 100644 catch/cms/model/FormData.php create mode 100644 catch/cms/model/FormFields.php create mode 100644 catch/cms/model/Forms.php create mode 100644 catch/cms/model/ModelAuxiliaryTable.php create mode 100644 catch/cms/model/ModelFields.php create mode 100644 catch/cms/model/Models.php create mode 100644 catch/cms/model/SiteLinks.php create mode 100644 catch/cms/model/Tags.php create mode 100644 catch/cms/model/Users.php create mode 100644 catch/cms/model/events/ArticlesEvent.php create mode 100644 catch/cms/model/events/CategoryEvent.php create mode 100644 catch/cms/model/events/ModelFieldsEvent.php create mode 100644 catch/cms/model/events/ModelsEvent.php create mode 100644 catch/cms/model/scopes/CategoryScope.php create mode 100644 catch/cms/module.json create mode 100644 catch/cms/route.php create mode 100644 catch/cms/support/AuxiliaryTable.php create mode 100644 catch/cms/support/DynamicFormFields.php create mode 100644 catch/cms/support/Helper.php create mode 100644 catch/cms/support/Table.php create mode 100644 catch/cms/support/TableColumn.php create mode 100644 catch/cms/tables/Articles.php create mode 100644 catch/cms/tables/Category.php create mode 100644 catch/cms/tables/Fields.php create mode 100644 catch/cms/tables/Model.php create mode 100644 catch/cms/tables/ModelUsedFields.php create mode 100644 catch/cms/tables/SiteLink.php create mode 100644 catch/cms/tables/Tags.php create mode 100644 catch/cms/tables/UsedAt.php create mode 100644 catch/cms/tables/forms/Articles.php create mode 100644 catch/cms/tables/forms/BaseForm.php create mode 100644 catch/cms/tables/forms/Category.php create mode 100644 catch/cms/tables/forms/Factory.php create mode 100644 catch/cms/tables/forms/Field.php create mode 100644 catch/cms/tables/forms/Model.php create mode 100644 catch/cms/tables/forms/ModelUsedFields.php create mode 100644 catch/cms/tables/forms/SiteLink.php create mode 100644 catch/cms/tables/forms/Tags.php create mode 100644 catch/cms/tables/forms/UsedAt.php diff --git a/catch/cms/CmsService.php b/catch/cms/CmsService.php new file mode 100644 index 0000000..3ae6221 --- /dev/null +++ b/catch/cms/CmsService.php @@ -0,0 +1,25 @@ +articlesModel = $articlesModel; + } + + /** + * 列表 + * @time 2020年12月27日 19:40 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->articlesModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 19:40 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->articlesModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 19:40 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->articlesModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 19:40 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->articlesModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 19:40 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->articlesModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/Banners.php b/catch/cms/controller/Banners.php new file mode 100644 index 0000000..248036b --- /dev/null +++ b/catch/cms/controller/Banners.php @@ -0,0 +1,80 @@ +bannersModel = $bannersModel; + } + + /** + * 列表 + * @time 2020年12月27日 19:58 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->bannersModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 19:58 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->bannersModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 19:58 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->bannersModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 19:58 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->bannersModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 19:58 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->bannersModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/Category.php b/catch/cms/controller/Category.php new file mode 100644 index 0000000..4ab7c06 --- /dev/null +++ b/catch/cms/controller/Category.php @@ -0,0 +1,91 @@ +categoryModel = $categoryModel; + } + + /** + * 列表 + * @time 2020年12月27日 19:15 + * @param Request $request + * @return \think\response\Json + */ + public function index(Request $request) + { + return CatchResponse::success($this->categoryModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 19:15 + * @param Request $request + * @return \think\response\Json + */ + public function save(Request $request) + { + return CatchResponse::success($this->categoryModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 19:15 + * @param $id + * @return \think\response\Json + */ + public function read($id) + { + return CatchResponse::success($this->categoryModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 19:15 + * @param Request $request + * @param $id + * @return \think\response\Json + */ + public function update(Request $request, $id) + { + return CatchResponse::success($this->categoryModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 19:15 + * @param $id + * @return \think\response\Json + */ + public function delete($id) + { + return CatchResponse::success($this->categoryModel->deleteBy($id)); + } + +} \ No newline at end of file diff --git a/catch/cms/controller/Comments.php b/catch/cms/controller/Comments.php new file mode 100644 index 0000000..9c8ab0f --- /dev/null +++ b/catch/cms/controller/Comments.php @@ -0,0 +1,80 @@ +commentsModel = $commentsModel; + } + + /** + * 列表 + * @time 2020年12月27日 19:53 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->commentsModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 19:53 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->commentsModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 19:53 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->commentsModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 19:53 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->commentsModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 19:53 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->commentsModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/FormData.php b/catch/cms/controller/FormData.php new file mode 100644 index 0000000..cdaba8b --- /dev/null +++ b/catch/cms/controller/FormData.php @@ -0,0 +1,80 @@ +formDataModel = $formDataModel; + } + + /** + * 列表 + * @time 2020年12月27日 20:35 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->formDataModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 20:35 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->formDataModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 20:35 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->formDataModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 20:35 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->formDataModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 20:35 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->formDataModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/FormFields.php b/catch/cms/controller/FormFields.php new file mode 100644 index 0000000..29dadcb --- /dev/null +++ b/catch/cms/controller/FormFields.php @@ -0,0 +1,80 @@ +formFieldsModel = $formFieldsModel; + } + + /** + * 列表 + * @time 2020年12月27日 20:28 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->formFieldsModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 20:28 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->formFieldsModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 20:28 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->formFieldsModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 20:28 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->formFieldsModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 20:28 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->formFieldsModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/Forms.php b/catch/cms/controller/Forms.php new file mode 100644 index 0000000..ca88b3f --- /dev/null +++ b/catch/cms/controller/Forms.php @@ -0,0 +1,80 @@ +formsModel = $formsModel; + } + + /** + * 列表 + * @time 2020年12月27日 20:19 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->formsModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 20:19 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->formsModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 20:19 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->formsModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 20:19 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->formsModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 20:19 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->formsModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/ModelFields.php b/catch/cms/controller/ModelFields.php new file mode 100644 index 0000000..50313ca --- /dev/null +++ b/catch/cms/controller/ModelFields.php @@ -0,0 +1,95 @@ +modelFields = $modelFields; + } + + /** + * 列表 + * @time 2020年12月29日 21:00 + * @param Request $request + * @param Models $models + * @return \think\response\Json + */ + public function index(Request $request): \think\response\Json + { + // $columns = Table::columns($models::where('id',$request->param('model_id'))->value('table_name')); + + //foreach ($columns as &$column) { + // $column['title'] = $column['comment']; + // } + + return CatchResponse::success($this->modelFields->getFieldsByModelId($request->param('model_id'))); + } + + /** + * 保存信息 + * @time 2020年12月29日 21:00 + * @param Request $request + * @return \think\response\Json + */ + public function save(Request $request): \think\response\Json + { + return CatchResponse::success($this->modelFields->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月29日 21:00 + * @param $id + * @return \think\response\Json + */ + public function read($id): \think\response\Json + { + return CatchResponse::success($this->modelFields->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月29日 21:00 + * @param Request $request + * @param $id + * @return \think\response\Json + */ + public function update(Request $request, $id): \think\response\Json + { + return CatchResponse::success($this->modelFields->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月29日 21:00 + * @param $id + * @return \think\response\Json + */ + public function delete($id): \think\response\Json + { + return CatchResponse::success($this->modelFields->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/Models.php b/catch/cms/controller/Models.php new file mode 100644 index 0000000..50d979f --- /dev/null +++ b/catch/cms/controller/Models.php @@ -0,0 +1,85 @@ +cmsModel = $cmsModel; + } + + /** + * 列表 + * @time 2020年12月29日 20:02 + * @param Request $request + * @return \think\response\Json + */ + public function index(Request $request): \think\response\Json + { + return CatchResponse::paginate($this->cmsModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月29日 20:02 + * @param Request $request + * @return \think\response\Json + */ + public function save(Request $request): \think\response\Json + { + return CatchResponse::success($this->cmsModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月29日 20:02 + * @param $id + * @return \think\response\Json + */ + public function read($id): \think\response\Json + { + return CatchResponse::success($this->cmsModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月29日 20:02 + * @param Request $request + * @param $id + * @return \think\response\Json + */ + public function update(Request $request, $id): \think\response\Json + { + return CatchResponse::success($this->cmsModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月29日 20:02 + * @param $id + * @return \think\response\Json + */ + public function delete($id): \think\response\Json + { + return CatchResponse::success($this->cmsModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/SiteLinks.php b/catch/cms/controller/SiteLinks.php new file mode 100644 index 0000000..6c7d8ca --- /dev/null +++ b/catch/cms/controller/SiteLinks.php @@ -0,0 +1,80 @@ +siteLinksModel = $siteLinksModel; + } + + /** + * 列表 + * @time 2020年12月27日 20:02 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->siteLinksModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 20:02 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->siteLinksModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 20:02 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->siteLinksModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 20:02 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->siteLinksModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 20:02 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->siteLinksModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/Tags.php b/catch/cms/controller/Tags.php new file mode 100644 index 0000000..7b7c04b --- /dev/null +++ b/catch/cms/controller/Tags.php @@ -0,0 +1,69 @@ +tagsModel = $tagsModel; + } + + /** + * 列表 + * @time 2020年12月27日 19:44 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->tagsModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 19:44 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->tagsModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 19:44 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->tagsModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 19:44 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->tagsModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 19:44 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->tagsModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/controller/Upload.php b/catch/cms/controller/Upload.php new file mode 100644 index 0000000..0c9b6a1 --- /dev/null +++ b/catch/cms/controller/Upload.php @@ -0,0 +1,69 @@ +attachment = $attachment; + } + + /** + * image upload + * + * @time 2020年01月25日 + * @param CatchRequest $request + * @param CatchUpload $upload + * @return \think\response\Json + */ + public function image(CatchRequest $request, CatchUpload $upload): \think\response\Json + { + $images = $request->file(); + + if (!$images) { + throw new FailedException('请选择图片上传'); + } + + return CatchResponse::success([ + 'filePath' => $upload->checkImages($images)->multiUpload($images['image']) + ]); + } + + /** + * file upload + * + * @time 2020年01月25日 + * @param CatchRequest $request + * @param CatchUpload $upload + * @return \think\response\Json + */ + public function file(CatchRequest $request, CatchUpload $upload): \think\response\Json + { + $files = $request->file(); + + return CatchResponse::success([ + 'src' => $upload->checkFiles($files)->multiUpload($files['file']) + ]); + } +} diff --git a/catch/cms/controller/Users.php b/catch/cms/controller/Users.php new file mode 100644 index 0000000..5f80c86 --- /dev/null +++ b/catch/cms/controller/Users.php @@ -0,0 +1,80 @@ +usersModel = $usersModel; + } + + /** + * 列表 + * @time 2020年12月27日 19:04 + * @param Request $request + */ + public function index(Request $request) : \think\Response + { + return CatchResponse::paginate($this->usersModel->getList()); + } + + /** + * 保存信息 + * @time 2020年12月27日 19:04 + * @param Request $request + */ + public function save(Request $request) : \think\Response + { + return CatchResponse::success($this->usersModel->storeBy($request->post())); + } + + /** + * 读取 + * @time 2020年12月27日 19:04 + * @param $id + */ + public function read($id) : \think\Response + { + return CatchResponse::success($this->usersModel->findBy($id)); + } + + /** + * 更新 + * @time 2020年12月27日 19:04 + * @param Request $request + * @param $id + */ + public function update(Request $request, $id) : \think\Response + { + return CatchResponse::success($this->usersModel->updateBy($id, $request->post())); + } + + /** + * 删除 + * @time 2020年12月27日 19:04 + * @param $id + */ + public function delete($id) : \think\Response + { + return CatchResponse::success($this->usersModel->deleteBy($id)); + } +} \ No newline at end of file diff --git a/catch/cms/database/migrations/20201227190439_cms_home_users.php b/catch/cms/database/migrations/20201227190439_cms_home_users.php new file mode 100644 index 0000000..9daf437 --- /dev/null +++ b/catch/cms/database/migrations/20201227190439_cms_home_users.php @@ -0,0 +1,44 @@ +table('cms_users', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '用户表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('username', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '用户名',]) + ->addColumn('email', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '邮箱',]) + ->addColumn('mobile', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '手机号',]) + ->addColumn('avatar', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '头像',]) + ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 正常 2 禁用',]) + ->addColumn('password', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '密码',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227191507_cms_category.php b/catch/cms/database/migrations/20201227191507_cms_category.php new file mode 100644 index 0000000..318cdb7 --- /dev/null +++ b/catch/cms/database/migrations/20201227191507_cms_category.php @@ -0,0 +1,53 @@ +table('cms_category', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '分类表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('name', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '栏目名称',]) + ->addColumn('parent_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 0,'signed' => true,'comment' => '父级ID',]) + ->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'seo标题',]) + ->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'seo关键词',]) + ->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',]) + ->addColumn('url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '自定义 URL',]) + ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态',]) + ->addColumn('is_can_contribute', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '是否可以投稿',]) + ->addColumn('is_can_comment', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '是否可以评论',]) + ->addColumn('type', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '页面模式',]) + ->addColumn('weight', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 1,'signed' => true,'comment' => '权重',]) + // ->addColumn('is_link_out', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '1 是 2 否',]) + ->addColumn('link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '链接外部地址',]) + ->addColumn('limit', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 10,'signed' => true,'comment' => '每页数量',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227194032_cms_articles.php b/catch/cms/database/migrations/20201227194032_cms_articles.php new file mode 100644 index 0000000..cfa7a25 --- /dev/null +++ b/catch/cms/database/migrations/20201227194032_cms_articles.php @@ -0,0 +1,54 @@ +table('cms_articles', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '文章表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('title', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '文章标题',]) + ->addColumn('category_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => true,'signed' => true,'comment' => '分类ID',]) + ->addColumn('images', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '多图集合',]) + ->addColumn('tags', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '标签集合',]) + ->addColumn('url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '自定义URL',]) + ->addColumn('content', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => false,'signed' => true,'comment' => '内容',]) + ->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '关键字',]) + ->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',]) + ->addColumn('pv', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '浏览量',]) + ->addColumn('likes', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '喜欢',]) + ->addColumn('comments', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '评论数',]) + ->addColumn('is_top', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '1 置顶 2 非置顶',]) + ->addColumn('is_recommend', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '1 推荐 2 不推荐',]) + ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',]) + ->addColumn('is_can_comment', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 允许 2 不允许',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227194430_cms_tags.php b/catch/cms/database/migrations/20201227194430_cms_tags.php new file mode 100644 index 0000000..2910d30 --- /dev/null +++ b/catch/cms/database/migrations/20201227194430_cms_tags.php @@ -0,0 +1,43 @@ +table('cms_tags', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '标签表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '标签名称',]) + ->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'seo 标签',]) + ->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '关键字',]) + ->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227194630_cms_article_relate_tags.php b/catch/cms/database/migrations/20201227194630_cms_article_relate_tags.php new file mode 100644 index 0000000..00e45ed --- /dev/null +++ b/catch/cms/database/migrations/20201227194630_cms_article_relate_tags.php @@ -0,0 +1,37 @@ +table('cms_article_relate_tags', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '文章关联标签表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('article_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '文章ID',]) + ->addColumn('tag_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '标签ID',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227195319_cms_comments.php b/catch/cms/database/migrations/20201227195319_cms_comments.php new file mode 100644 index 0000000..5b48bfa --- /dev/null +++ b/catch/cms/database/migrations/20201227195319_cms_comments.php @@ -0,0 +1,46 @@ +table('cms_comments', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('article_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '文章ID',]) + ->addColumn('content', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '内容',]) + ->addColumn('parent_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '父ID',]) + ->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => false,'comment' => '评论者ID',]) + ->addColumn('ip', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'ip 地址',]) + ->addColumn('user_agent', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'agent',]) + ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227195847_cms_banners.php b/catch/cms/database/migrations/20201227195847_cms_banners.php new file mode 100644 index 0000000..6db045a --- /dev/null +++ b/catch/cms/database/migrations/20201227195847_cms_banners.php @@ -0,0 +1,43 @@ +table('cms_banners', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => 'banner 图' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'banner 标题',]) + ->addColumn('banner_img', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'banner 图片',]) + ->addColumn('category_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 0,'signed' => true,'comment' => '默认 0 代表首页展示',]) + ->addColumn('link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '链接地址',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227200244_cms_site_links.php b/catch/cms/database/migrations/20201227200244_cms_site_links.php new file mode 100644 index 0000000..818d8cd --- /dev/null +++ b/catch/cms/database/migrations/20201227200244_cms_site_links.php @@ -0,0 +1,44 @@ +table('cms_site_links', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '友情链接' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '友情链接标题',]) + ->addColumn('link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '跳转地址',]) + ->addColumn('weight', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 1,'signed' => true,'comment' => '权重',]) + ->addColumn('is_show', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',]) + ->addColumn('icon', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '网站图标',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227201933_cms_forms.php b/catch/cms/database/migrations/20201227201933_cms_forms.php new file mode 100644 index 0000000..19271f0 --- /dev/null +++ b/catch/cms/database/migrations/20201227201933_cms_forms.php @@ -0,0 +1,49 @@ +table('cms_forms', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '动态表单' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单名称',]) + ->addColumn('alias', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单别名',]) + ->addColumn('submit_url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单提交的 URL',]) + ->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单标题',]) + ->addColumn('keywords', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '关键词',]) + ->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '描述',]) + ->addColumn('success_message', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '成功提示信息',]) + ->addColumn('failed_message', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '失败提示信息',]) + ->addColumn('success_link_to', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '成功后跳转',]) + ->addColumn('is_login_to_submit', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 需要 2 不需要',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227202845_cms_form_fields.php b/catch/cms/database/migrations/20201227202845_cms_form_fields.php new file mode 100644 index 0000000..889e650 --- /dev/null +++ b/catch/cms/database/migrations/20201227202845_cms_form_fields.php @@ -0,0 +1,48 @@ +table('cms_form_fields', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '动态表单字段' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('form_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => 'form id',]) + ->addColumn('label', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '字段 label',]) + ->addColumn('name', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '表单字段name',]) + ->addColumn('default_value', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '默认值',]) + ->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 1,'signed' => false,'comment' => '类型',]) + ->addColumn('rule', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '验证规则',]) + ->addColumn('length', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => false,'default' => 0,'signed' => true,'comment' => '字段长度',]) + ->addColumn('failed_message', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '验证失败信息',]) + ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '1 展示 2 隐藏',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201227203533_cms_form_data.php b/catch/cms/database/migrations/20201227203533_cms_form_data.php new file mode 100644 index 0000000..21050ea --- /dev/null +++ b/catch/cms/database/migrations/20201227203533_cms_form_data.php @@ -0,0 +1,44 @@ +table('cms_form_data', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '动态提交的表单数据' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('form_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '表单ID',]) + ->addColumn('data', 'json', ['null' => false,'signed' => true,'comment' => 'json字段',]) + ->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '用户ID',]) + ->addColumn('ip', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'ip 地址',]) + ->addColumn('user_agent', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'agent',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201229200249_cms_model.php b/catch/cms/database/migrations/20201229200249_cms_model.php new file mode 100644 index 0000000..60f6828 --- /dev/null +++ b/catch/cms/database/migrations/20201229200249_cms_model.php @@ -0,0 +1,43 @@ +table('cms_models', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '模型表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '模型名称',]) + ->addColumn('alias', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '模型别名',]) + ->addColumn('table_name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '模型关联的表名,数据来源',]) + ->addColumn('description', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => true,'comment' => '模型描述',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20201229210020_cms_model_fields.php b/catch/cms/database/migrations/20201229210020_cms_model_fields.php new file mode 100644 index 0000000..9a6e101 --- /dev/null +++ b/catch/cms/database/migrations/20201229210020_cms_model_fields.php @@ -0,0 +1,55 @@ +table('cms_model_fields', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '模型字段' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('title', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '字段中文名称',]) + ->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '表单字段名称',]) + ->addColumn('type', 'string', ['limit' => 50, 'null' => false,'signed' => true,'comment' => '类型',]) + ->addColumn('length', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => true,'signed' => true,'comment' => '字段长度',]) + ->addColumn('default_value', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '默认值',]) + ->addColumn('options', 'string', ['limit' => 1000,'null' => false,'default' => '', 'comment' => '选项',]) + ->addColumn('is_index', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '是否是索引 1 是 2 否',]) + ->addColumn('is_unique', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '是否唯一 1 是 2 否',]) + ->addColumn('rules', 'string', ['limit' => 255,'null' => false,'default' => '', 'comment' => '验证规则',]) + ->addColumn('pattern', 'string', ['limit' => 255,'null' => false,'default' => '', 'comment' => '正则',]) + ->addColumn('model_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL,'null' => true,'signed' => true,'comment' => '模型ID',]) + ->addColumn('use_at_list', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '展示在列表 1 是 2 否',]) + ->addColumn('use_at_detail', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '展示在详情 1 是 2 否',]) + ->addColumn('use_at_search', 'boolean', ['null' => false,'default' => 2,'signed' => true,'comment' => '用作是否搜索 1 是 2 否',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',]) + ->addColumn('sort', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 1,'signed' => false,'comment' => '排序',]) + ->addColumn('status', 'integer', ['limit' => MysqlAdapter::INT_TINY,'null' => false,'default' => 1,'signed' => false,'comment' => '状态 1显示 2隐藏',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20210308082210_model_auxiliary_table.php b/catch/cms/database/migrations/20210308082210_model_auxiliary_table.php new file mode 100644 index 0000000..e53afcb --- /dev/null +++ b/catch/cms/database/migrations/20210308082210_model_auxiliary_table.php @@ -0,0 +1,51 @@ +table('cms_model_auxiliary_table', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '模型副表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); + $table->addColumn('model_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '模型ID',]) + ->addColumn('table_name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '副表表明',]) + ->addColumn('used', 'integer', ['limit' => MysqlAdapter::INT_TINY,'null' => false,'default' => 2,'signed' => true,'comment' => '默认使用 1 不使用 2 使用',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',]) + ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',]) + ->create(); + } +} diff --git a/catch/cms/database/migrations/20210430101955_add_model_fields.php b/catch/cms/database/migrations/20210430101955_add_model_fields.php new file mode 100644 index 0000000..b3b8aff --- /dev/null +++ b/catch/cms/database/migrations/20210430101955_add_model_fields.php @@ -0,0 +1,48 @@ +hasTable('cms_models')) { + $this->table('cms_models') + ->addColumn('used_at_list', 'string', ['limit' => 512,'null' => false,'default' => '','signed' => true,'comment' => '用在列表的字段', 'after' => 'description']) + ->addColumn('used_at_search', 'string', ['limit' => 512,'null' => false,'default' => '','signed' => true,'comment' => '用在搜索的字段', 'after' => 'description']) + ->addColumn('used_at_detail', 'string', ['limit' => 512,'null' => false,'default' => '','signed' => true,'comment' => '用在详情的字段', 'after' => 'description']) + ->update(); + } + } +} diff --git a/catch/cms/database/migrations/20210517014609_add_article_columns.php b/catch/cms/database/migrations/20210517014609_add_article_columns.php new file mode 100644 index 0000000..7ca7716 --- /dev/null +++ b/catch/cms/database/migrations/20210517014609_add_article_columns.php @@ -0,0 +1,57 @@ +hasTable('cms_articles')) { + $table = $this->table('cms_articles'); + + $table->addColumn('weight', 'integer', [ + 'default' => 1, + 'comment' => '文章权重', + 'after' => 'status' + ])->update(); + + $table->addColumn('cover', 'string', [ + 'limit' => 255, + 'default' => '', + 'comment' => '封面地址', + 'after' => 'category_id' + ])->update(); + } + } +} diff --git a/catch/cms/exceptions/ColumnException.php b/catch/cms/exceptions/ColumnException.php new file mode 100644 index 0000000..8c3417e --- /dev/null +++ b/catch/cms/exceptions/ColumnException.php @@ -0,0 +1,24 @@ +belongsToMany(Tags::class, 'cms_article_relate_tags', + 'tag_id', 'article_id' + ); + } +} \ No newline at end of file diff --git a/catch/cms/model/Banners.php b/catch/cms/model/Banners.php new file mode 100644 index 0000000..9c9b07d --- /dev/null +++ b/catch/cms/model/Banners.php @@ -0,0 +1,40 @@ +field = $this->getTableFields(Utils::tableWithPrefix($this->name)); + } +} \ No newline at end of file diff --git a/catch/cms/model/Category.php b/catch/cms/model/Category.php new file mode 100644 index 0000000..8773744 --- /dev/null +++ b/catch/cms/model/Category.php @@ -0,0 +1,103 @@ +quickSearch() + ->field(['*']) + ->catchOrder() + ->articlesCount() + ->select()->toTree(); + } + + /** + * 是否存在下级 + * + * @time 2021年03月03日 + * @param int $id + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @return array|\think\Model|null + */ + public function hasNextLevel($id = 0) + { + return $this->where('parent_id', $id ? :$this->getKey())->find(); + } +} \ No newline at end of file diff --git a/catch/cms/model/Comments.php b/catch/cms/model/Comments.php new file mode 100644 index 0000000..a4482a3 --- /dev/null +++ b/catch/cms/model/Comments.php @@ -0,0 +1,46 @@ +where('used', self::USED) + ->find(); + } + + /** + * 默认使用 + * + * @time 2021年03月08日 + * @param int $id + * @return mixed + */ + public function used(int $id) + { + $t = $this->findBy($id); + + $t->used = self::USED; + + if ($t->save()) { + self::where('id', '<>', $id) + ->where('model_id', $t->model_id) + ->update([ + 'used' => self::NOT_USE, + ]); + + return $t; + } + + throw new FailedException('启用失败'); + } + + /** + * 获取使用 + * + * @time 2021年03月08日 + * @param $modelId + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @return array|\think\Model|null + */ + public function getUsed($modelId) + { + return $this->where('model_id', $modelId) + ->where('used', self::USED) + ->find(); + + } +} \ No newline at end of file diff --git a/catch/cms/model/ModelFields.php b/catch/cms/model/ModelFields.php new file mode 100644 index 0000000..6e8fb37 --- /dev/null +++ b/catch/cms/model/ModelFields.php @@ -0,0 +1,112 @@ +withoutField([ + 'created_at', 'deleted_at', 'updated_at', + ])->where('model_id', $modelId)->select(); + } + + /** + * 获取规则 + * + * @time 2021年03月07日 + * @param $value + * @return string[] + */ + public function getRulesAttr($value): array + { + return Utils::stringToArrayBy($value); + } + + /** + * 获取选项 + * + * @time 2021年03月07日 + * @param $value + * @return mixed + */ + public function getOptionsAttr($value) + { + // return Helper::getOptions($value); + return $value; + } +} \ No newline at end of file diff --git a/catch/cms/model/Models.php b/catch/cms/model/Models.php new file mode 100644 index 0000000..1309ac4 --- /dev/null +++ b/catch/cms/model/Models.php @@ -0,0 +1,62 @@ +hasMany(ModelFields::class, 'model_id', 'id'); + } +} \ No newline at end of file diff --git a/catch/cms/model/SiteLinks.php b/catch/cms/model/SiteLinks.php new file mode 100644 index 0000000..ef16278 --- /dev/null +++ b/catch/cms/model/SiteLinks.php @@ -0,0 +1,56 @@ +whereLike('title', $value); + } +} \ No newline at end of file diff --git a/catch/cms/model/Tags.php b/catch/cms/model/Tags.php new file mode 100644 index 0000000..7ec7e96 --- /dev/null +++ b/catch/cms/model/Tags.php @@ -0,0 +1,46 @@ +whereLike('name', $value); + } +} \ No newline at end of file diff --git a/catch/cms/model/Users.php b/catch/cms/model/Users.php new file mode 100644 index 0000000..6649245 --- /dev/null +++ b/catch/cms/model/Users.php @@ -0,0 +1,42 @@ +category_id = $model->category_id[0]; + + $model->images = implode(',', $model->images); + + $model->tags = implode(',', $model->tags); + } + + + /** + * 插入后 + * + * @time 2021年05月21日 + * @param Articles $model + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @return void + */ + public static function onAfterInsert(Articles $model) + { + $tags = Utils::stringToArrayBy($model->tags); + + $tagModel = new Tags; + $existTags = $tagModel->whereIn('name', $tags)->select()->toArray(); + $existTagsName = array_column($existTags, 'name'); + + $tagsIds = []; + foreach ($tags as $tag) { + if (! in_array($tag, $existTagsName)) { + $tagsIds[] = $tagModel->createBy([ + 'name' => $tag + ]); + } + } + + + $model->tags()->attach(array_merge(array_column($existTags, 'id'), $tagsIds)); + } +} \ No newline at end of file diff --git a/catch/cms/model/events/CategoryEvent.php b/catch/cms/model/events/CategoryEvent.php new file mode 100644 index 0000000..adc00cd --- /dev/null +++ b/catch/cms/model/events/CategoryEvent.php @@ -0,0 +1,83 @@ +data(self::changeData($category->getData())); + } + + /** + * 更新前 + * + * @time 2021年03月03日 + * @param \think\Model $category + * @return mixed|void + */ + public static function onBeforeUpdate($category) + { + // $category->data(self::changeData($category->getData())); + } + + /** + * 删除前 + * + * @time 2021年03月03日 + * @param $category + * @return void + */ + public static function onBeforeDelete($category) + { + if ($category->hasNextLevel()) { + throw new FailedException('存在下级栏目, 无法删除'); + } + } + + /** + * 更新Data + * + * @time 2021年03月03日 + * @param $data + * @return mixed + */ + protected static function changeData($data) + { + /** + if (isset($data['parent_id'])) { + $parentId = $data['parent_id']; + + if (!is_array($parentId)) { + // $parentId = Utils::dealWithFormArrayString($parentId); + } + + $parentId = count($parentId) ? array_pop($parentId) : 0; + + $data['parent_id'] = $parentId; + } + + return $data;*/ + } +} \ No newline at end of file diff --git a/catch/cms/model/events/ModelFieldsEvent.php b/catch/cms/model/events/ModelFieldsEvent.php new file mode 100644 index 0000000..d6b8b5d --- /dev/null +++ b/catch/cms/model/events/ModelFieldsEvent.php @@ -0,0 +1,167 @@ +getData('model_id')); + + if ($tableName && Table::hasColumn($tableName, $modelFields->getData('name'))) { + throw new ColumnException(sprintf('Column [%s] already exist in Table [%s]', $modelFields->getData('name'), $tableName)); + } + + $modelFields->data(self::changeData($modelFields->getData())); + } + + /** + * 更新后 + * + * @time 2021年03月08日 + * @param $modelFields + * @return void + */ + public static function onBeforeUpdate($modelFields) + { + $modelFields->data(self::changeData($modelFields->getData(), true)); + } + + /** + * 插入之后 + * + * @time 2021年03月08日 + * @param $modelFields + * @return void + */ + public static function onAfterInsert($modelFields) + { + if ($modelFields->getKey()) { + try { + $tableName = self::getModelTableName($modelFields->getData('model_id')); + + if ($tableName) { + Table::addColumn($tableName, (new TableColumn($modelFields->getData()))->get()); + } + + self::addIndexForField($tableName, $modelFields->getData('name'), $modelFields->getData('is_index')); + } catch (\Exception $e) { + $modelFields->delete(); + throw new FailedException($e->getMessage()); + } + } + } + + /** + * 更新之后 + * + * @time 2021年04月30日 + * @param \think\Model $modelFields + * @return void + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\db\exception\DataNotFoundException + */ + public static function onAfterUpdate(\think\Model $modelFields) + { + $field = $modelFields->find($modelFields->getWhere()); + + self::addIndexForField(self::getModelTableName($field['model_id']), $field['name'], $field['is_index']); + } + + + /** + * 添加索引 + * + * @time 2021年04月30日 + * @param $table + * @param string $column + * @param $isIndex + * @return void + */ + protected static function addIndexForField($table, string $column, $isIndex) + { + if (! Table::isIndex($table, $column) && $isIndex == self::IS_INDEX) { + Table::addIndex($table, $column); + } + + if (Table::isIndex($table, $column) && $isIndex == self::NOT_INDEX) { + Table::dropIndex($table, $column); + } + } + + /** + * 删除字段 + * + * @time 2021年03月08日 + * @param $modelFields + * @return void + */ + public static function onAfterDelete($modelFields) + { + $tableName = self::getModelTableName($modelFields->getData('model_id')); + + $columnName = $modelFields->getData('name'); + + if (Table::hasColumn($tableName, $columnName)) { + Table::dropColumn($tableName, $columnName); + } + } + + /** + * 校验 + * + * @time 2021年03月08日 + * @param $data + * @param bool $update + * @return mixed + */ + protected static function changeData($data, $update = false) + { + if (isset($data['type']) && !in_array($data['type'], ['string', 'int'])) { + $data['length'] = 0; + } + + // 更新不会校验 + if (!$update) { + if (Table::hasColumn(self::getModelTableName($data['model_id']), $data['name'])) { + throw new ColumnException(sprintf('Column [%s] already exist in Table [%s]', $data['name'], self::getModelTableName($data['model_id']))); + } + } + + return $data; + } + + /** + * 获取模型关联的表 + * + * @time 2021年03月08日 + * @param $modelId + * @return mixed|null + */ + protected static function getModelTableName($modelId) + { + if (self::$modelTableName) { + return self::$modelTableName; + } + + self::$modelTableName = Models::where('id', $modelId)->value('table_name'); + + return self::$modelTableName; + } +} \ No newline at end of file diff --git a/catch/cms/model/events/ModelsEvent.php b/catch/cms/model/events/ModelsEvent.php new file mode 100644 index 0000000..1ec6dbe --- /dev/null +++ b/catch/cms/model/events/ModelsEvent.php @@ -0,0 +1,52 @@ +getData('table_name'))) { + throw new FailedException('模型关联的表【' .$model->getData('table_name'). '】不存在'); + } + } + + /** + * 更新前 + * + * @time 2021年03月03日 + * @param \think\Model $model + * @return void + */ + public static function onBeforeUpdate($model): void + { + $data = $model->getData(); + + $tableName = $data['table_name'] ?? null; + + if ($tableName && !Table::exist($model->getData('table_name'))) { + throw new FailedException('模型关联的表【' .$model->getData('table_name'). '】不存在'); + } + } +} diff --git a/catch/cms/model/scopes/CategoryScope.php b/catch/cms/model/scopes/CategoryScope.php new file mode 100644 index 0000000..18c3203 --- /dev/null +++ b/catch/cms/model/scopes/CategoryScope.php @@ -0,0 +1,36 @@ +addSelectSub(function () { + $article = app(Articles::class); + return $article->field(Db::raw('count(*)')) + ->whereColumn($this->aliasField('id'), $article->aliasField('category_id')); + }, 'articles'); + } +} diff --git a/catch/cms/module.json b/catch/cms/module.json new file mode 100644 index 0000000..0f52cfa --- /dev/null +++ b/catch/cms/module.json @@ -0,0 +1,18 @@ +{ + "name": "内容管理", + "alias": "cms", + "description": "cms 模块管理", + "version": "1.0.0", + "keywords": [ + "cms", + "admin" + ], + "order": 0, + "services": [ + "\\catchAdmin\\cms\\CmsService" + ], + "aliases": [], + "files": [], + "requires": [], + "enable": true +} \ No newline at end of file diff --git a/catch/cms/route.php b/catch/cms/route.php new file mode 100644 index 0000000..9410e06 --- /dev/null +++ b/catch/cms/route.php @@ -0,0 +1,49 @@ +group('cms', function () use ($router){ + // users路由 + $router->resource('users', '\catchAdmin\cms\controller\Users'); + // category路由 + $router->resource('category', '\catchAdmin\cms\controller\Category'); + $router->post('import/category', '\catchAdmin\cms\controller\Category@import'); + + // articles路由 + $router->resource('articles', '\catchAdmin\cms\controller\Articles'); + // tags路由 + $router->resource('tags', '\catchAdmin\cms\controller\Tags'); + // comments路由 + $router->resource('comments', '\catchAdmin\cms\controller\Comments'); + // banners路由 + $router->resource('banners', '\catchAdmin\cms\controller\Banners'); + // siteLInks路由 + $router->resource('site/links', '\catchAdmin\cms\controller\SiteLinks'); + // forms路由 + $router->resource('forms', '\catchAdmin\cms\controller\Forms'); + // formFields路由 + $router->resource('formFields', '\catchAdmin\cms\controller\FormFields'); + // formData路由 + $router->resource('formData', '\catchAdmin\cms\controller\FormData'); + // model路由 + $router->resource('model', '\catchAdmin\cms\controller\Models'); + // modelFields路由 + $router->resource('modelFields', '\catchAdmin\cms\controller\ModelFields'); + // form create + $router->get('form//create', '\catchAdmin\cms\controller\Form@create'); + // 上传 + $router->group('upload', function () use ($router){ + $router->post('image', '\catchAdmin\cms\controller\Upload@image'); + $router->post('file', '\catchAdmin\cms\controller\Upload@file'); + })->middleware(\catcher\middlewares\JsonResponseMiddleware::class); +})->middleware('auth'); \ No newline at end of file diff --git a/catch/cms/support/AuxiliaryTable.php b/catch/cms/support/AuxiliaryTable.php new file mode 100644 index 0000000..fa8bd89 --- /dev/null +++ b/catch/cms/support/AuxiliaryTable.php @@ -0,0 +1,113 @@ +value('table_name'); + // 查询副表 + $auxiliaryTables = ModelAuxiliaryTable::where('model_id', $modelId)->select(); + // 目前最多允许创建 10 个副表 + if ($auxiliaryTables->count() > count($this->suffixes)) { + throw new FailedException('最多只允许创建 ' . count($this->suffixes) . ' 个副表'); + } + $defaultUsed = ModelAuxiliaryTable::NOT_USE; + // 如果模型还没有关联的副表 + // 默认创建副表 + if (!$auxiliaryTables->count()) { + $defaultUsed = ModelAuxiliaryTable::USED; + + $this->auxiliaryTableName = $this->getName($tableName, array_shift($this->suffixes)); + } else { + $existSuffixes = []; + + $auxiliaryTables->each(function ($table) use (&$existSuffixes) { + $name = explode('_', $table->name); + + $existSuffixes[] = array_pop($name); + }); + + $notUsed = array_diff($this->suffixes, $existSuffixes); + + $this->auxiliaryTableName = $this->getName($tableName, array_shift($notUsed)); + } + + if (Table::create($this->auxiliaryTableName)) { + Table::addColumn($this->auxiliaryTableName, (new TableColumn([ + 'type' => 'int', + 'name' => $this->mainTableId, + 'length' => 10, + 'title' => '主表数据的ID', + 'default_value' => 0, + ]))->get()); + } + + app(ModelAuxiliaryTable::class)->storeBy([ + 'model_id' => $modelId, + 'table_name' => $this->auxiliaryTableName, + 'used' => $defaultUsed, + ]); + + return $this->auxiliaryTableName; + } catch (\Exception $exception) { + throw new FailedException($exception->getMessage()); + } + } + + /** + * 获取默认使用的副表 + * + * @time 2021年03月08日 + * @param int $modelId + * @return mixed + */ + public function getUsedAuxiliaryTable(int $modelId) + { + $auxiliaryTable = app(ModelAuxiliaryTable::class)->getUsed($modelId); + + return $auxiliaryTable ? $auxiliaryTable->table_name : null; + } + + + /** + * 获取副表名称 + * + * @time 2021年03月08日 + * @param string $mainTable + * @param string $suffix + * @return string + */ + protected function getName(string $mainTable, string $suffix): string + { + return $mainTable . '_relate_' . $suffix; + } + + + +} \ No newline at end of file diff --git a/catch/cms/support/DynamicFormFields.php b/catch/cms/support/DynamicFormFields.php new file mode 100644 index 0000000..9cccaee --- /dev/null +++ b/catch/cms/support/DynamicFormFields.php @@ -0,0 +1,384 @@ + ['^[A-Za-z]+$', '必须为纯字母'], + 'alphaNum' => ['^[A-Za-z0-9]+$', '必须为字母和数字'], + 'alphaDash' => ['^[A-Za-z0-9\-\_]+$', '必须为字母和数字,下划线_及破折号-'], + 'mobile' => ['^1[3-9]\d{9}$','请输入正确的手机号格式'], + 'idCard' => ['(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)','身份证输入格式不正确'], + 'zip' => ['\d{6}','请输入有效的邮政编码'], + 'ip' => ['((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))', '请输入正确的 IP 地址'], + 'password' => ['^[a-zA-Z]\w{5,17}$', '以字母开头,长度在6~18之间,只能包含字母、数字和下划线'], + 'strong_password' => ['^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$', '必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间'], + 'landLine' => ['\d{3}-\d{8}|\d{4}-\d{7}', '请输入正确的座机格式'], + 'chinese_character' => ['^[\u4e00-\u9fa5]{0,}$', '必须为纯汉字'] + ]; + + /** + * build form field + * + * @time 2021年03月10日 + * @param $modelId + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @return array + */ + public function build($tableName): array + { + $fields = []; + + ModelFields::whereIn('model_id', Models::where('table_name', $tableName)->column('id')) + ->where('status', ModelFields::ENABLE) + ->select() + ->each(function ($field) use (&$fields){ + $formField = $this->{$field['type']}($field); + + $formField = $this->getOptions($formField, $field['options'] ?? ''); + + $formField = $this->appendValidates($formField, $field['rules']); + + $formField = $this->pattern($formField, $field['pattern']); + + $fields[] = $formField; + }); + + return $fields; + } + + /** + * 字符串 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Input + */ + public function string($field): \FormBuilder\UI\Elm\Components\Input + { + return Form::input($field['name'], $field['title']); + } + + /** + * 整型 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\InputNumber + */ + public function int($field): \FormBuilder\UI\Elm\Components\InputNumber + { + return Form::number($field['name'], $field['title']); + } + + /** + * 浮点 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\InputNumber + */ + public function float($field): \FormBuilder\UI\Elm\Components\InputNumber + { + return Form::number($field['name'], $field['tittle']); + } + + /** + * textarea + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Input + */ + public function textarea($field): \FormBuilder\UI\Elm\Components\Input + { + return Form::textarea($field['name'], $field['title']); + } + + /** + * 编辑器 + * + * @time 2021年03月09日 + * @param $field + * @return mixed + */ + public function text($field) + { + return Form::editor($field['name'], $field['title'])->language(); + } + + /** + * longtext + * + * @time 2021年03月09日 + * @param $field + * @return mixed + */ + public function longtext($field) + { + return Form::editor($field['name'], $field['title']); + } + + /** + * 日期类型 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\DatePicker + */ + public function date($field): \FormBuilder\UI\Elm\Components\DatePicker + { + return Form::date($field['name'], $field['title']); + } + + /** + * 日期时间 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\DatePicker + */ + public function datetime($field): \FormBuilder\UI\Elm\Components\DatePicker + { + return Form::dateTime($field['name'], $field['title']); + } + + /** + * 图片 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Upload + */ + public function image($field): \FormBuilder\UI\Elm\Components\Upload + { + return Form::image($field['title'], $field['name']); + } + + /** + * 多图 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Upload + */ + public function images($field): \FormBuilder\UI\Elm\Components\Upload + { + return Form::images($field['title'], $field['name']); + } + + /** + * 上传文件 + * + * @time 2021年03月09日 + * @param $field + * @return mixed + */ + public function file($field) + { + return Form::file($field['title'], $field['name']); + } + + /** + * 上传多个文件 + * + * @time 2021年03月09日 + * @param $field + * @return mixed + */ + public function files($field) + { + return Form::files($field['title'], $field['name']); + } + + /** + * 下拉框 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Select + */ + public function select($field): \FormBuilder\UI\Elm\Components\Select + { + return Form::select($field['name'], $field['title']); + } + + /** + * checkbox + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Select + */ + public function checkbox($field): \FormBuilder\UI\Elm\Components\Select + { + return Form::select($field['name'], $field['title']); + } + + /** + * radio + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Select + */ + public function radio($field): \FormBuilder\UI\Elm\Components\Select + { + return Form::select($field['name'], $field['title'])->options($this->getOptions($field['options'])); + } + + /** + * 密码 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Input + */ + public function password($field): \FormBuilder\UI\Elm\Components\Input + { + return Form::password($field['name'], $field['title']); + } + + /** + * 颜色 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\ColorPicker + */ + public function color($field): \FormBuilder\UI\Elm\Components\ColorPicker + { + return Form::color($field['name'], $field['title']); + } + + /** + * 省市选择 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Cascader + */ + public function city($field): \FormBuilder\UI\Elm\Components\Cascader + { + return Form::city($field['name'], $field['title']); + } + + /** + * 省市区选择 + * + * @time 2021年03月09日 + * @param $field + * @return \FormBuilder\UI\Elm\Components\Cascader + */ + public function area($field): \FormBuilder\UI\Elm\Components\Cascader + { + return Form::cityArea($field['name'], $field['title']); + } + + /** + * options + * + * @time 2021年03月09日 + * @param $formField + * @param $options + * @return mixed + */ + protected function getOptions($formField, $options) + { + if (!$options) { + return $formField; + } + + return $formField->options(Helper::getOptions($options)); + } + + /** + * 验证规则 + * + * @time 2021年03月09日 + * @param $formField + * @param $validates + * @return mixed + */ + protected function appendValidates($formField, $validates) + { + if (count($validates)) { + foreach ($validates as $validate) { + if ($validate === 'require') { + $formField = $formField->required(); + } + + switch ($validate) { + case 'number': + $formField->appendValidate(Form::validateNum()->message('请输入数字')); + break; + case 'integer': + $formField->appendValidate(Form::validateInt()->message('请输入整型数字')); + break; + case 'float': + $formField->appendValidate(Form::validateFloat()->message('请输入浮点型数字')); + break; + case in_array($validate, ['email', 'url', 'date']): + $message = [ + 'email' => '邮箱格式不正确', + 'url' => 'url 地址格式不正确', + 'date' => '日期格式不正确' + ]; + $method = 'validate' . ucfirst($validate); + $formField->appendValidate(Form::{$method}()->message($message[$validate])); + break; + default: + if (isset($this->defaultRules[$validate])) { + list($pattern, $message) = $this->defaultRules[$validate]; + + $formField->appendValidate( + Form::validateStr()->pattern($pattern)->message($message) + ); + } + break; + } + } + } + + return $formField; + } + + /** + * 正则 + * + * @time 2021年03月10日 + * @param $formField + * @param $pattern + * @return mixed + */ + protected function pattern($formField, $pattern) + { + if ($pattern) { + list($pattern, $message) = explode('|', $pattern); + + return $formField->appendValidate( + Form::validateStr()->pattern($pattern)->message($message) + ); + } + + return $formField; + } +} \ No newline at end of file diff --git a/catch/cms/support/Helper.php b/catch/cms/support/Helper.php new file mode 100644 index 0000000..70de851 --- /dev/null +++ b/catch/cms/support/Helper.php @@ -0,0 +1,68 @@ + $option[0], + 'label' => $option[1], + ]; + } + } + + return $options; + } + + /** + * 处理表单数组字符 + * + * "[1, 2, 3, 4, 5]" + * + * @time 2021年03月07日 + * @param $arrayString + * @return array|string[] + */ + public static function dealWithFormArrayString($arrayString): array + { + $array = trim(trim($arrayString, '['), ']'); + + if (!$array) { + return []; + } + + return Utils::stringToArrayBy($array); + } +} diff --git a/catch/cms/support/Table.php b/catch/cms/support/Table.php new file mode 100644 index 0000000..ac9a5cf --- /dev/null +++ b/catch/cms/support/Table.php @@ -0,0 +1,52 @@ + 'string', 'label' => '字符串'], + ['value' => 'int', 'label' => '整数'], + ['value' => 'float', 'label' => '小数'], + ['value' => 'textarea', 'label' => 'textarea文本'], + ['value' => 'text', 'label' => '编辑器(建议)'], + ['value' => 'longtext', 'label' => '编辑器(支持超大文本)'], + ['value' => 'date', 'label' => '日期型'], + ['value' => 'datetime', 'label' => '日期时间型'], + ['value' => 'image', 'label' => '图片上传'], + ['value' => 'images', 'label' => '多图上传'], + ['value' => 'file', 'label' => '文件上传'], + ['value' => 'files', 'label' => '多文件上传'], + ['value' => 'select', 'label' => '列表'], + ['value' => 'checkbox', 'label' => '复选框'], + ['value' => 'password', 'label' => '密码框'], + ['value' => 'color', 'label' => '颜色选项'], + ['value' => 'radio', 'label' => '单选'], + ['value' => 'city', 'label' => '省市二级级联动'], + ['value' => 'area', 'label' => '省市区三级联动'], + */ + + protected $column; + + /** + * TableColumn constructor. + * @param array $field + */ + public function __construct(array $field) + { + /* $column \think\migration\db\Column */ + $length = $field['length'] ?? 0; + + $column = $this->{$field['type']}($field['name'], (int)$length); + + if ($field['default_value']) { + $column->setDefault($field['default_value'] ?: ''); + } + + $column->setComment($field['title'] ? : ''); + + if (isset($field['is_unique']) && $field['is_unique'] == ModelFields::IS_UNIQUE) { + $column->setUnique(); + } + + if (isset($field['is_index']) && $field['is_index'] == ModelFields::IS_INDEX) { + $column->be_index = true; + } + + $this->column = $column; + } + + /** + * 获取结果 + * + * @time 2021年03月08日 + * @return mixed + */ + public function get() + { + return $this->column; + } + + /** + * string 类型 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function string(string $name, int $length): Column + { + return Column::string($name, $length); + } + + /** + * int 类型 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function int(string $name, int $length): Column + { + return Column::integer($name)->setLimit($length); + } + + /** + * 浮点数 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function float(string $name, int $length): Column + { + return Column::float($name)->setLimit($length); + } + + /** + * varchar 类型 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function textarea(string $name, int $length): Column + { + return Column::string($name)->setLimit(2000); + } + + /** + * 普通文本 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function text(string $name, int $length): Column + { + return Column::text($name); + } + + /** + * 超大文本 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function longtext(string $name, int $length): Column + { + return Column::longText($name); + } + + /** + * 时间类型 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function date(string $name, int $length): Column + { + return Column::date($name); + } + + /** + * 日期时间 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function datetime(string $name, int $length): Column + { + return Column::dateTime($name); + } + + /** + * 图片存储 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function image(string $name, int $length): Column + { + return Column::string($name)->setLimit(255); + } + + /** + * 图片集合存储 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function images(string $name, int $length): Column + { + return Column::string($name)->setLimit(1000); + } + + /** + * 文件存储 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function file(string $name, int $length): Column + { + return Column::string($name)->setLimit(255); + } + + /** + * 文件集合 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function files(string $name, int $length): Column + { + return Column::string($name)->setLimit(1000); + } + + /** + * 列表类型 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function select(string $name, int $length): Column + { + return Column::string($name)->setLimit(20); + } + + /** + * checkbox 类型 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function checkbox(string $name, int $length): Column + { + return Column::string($name)->setLimit(20); + } + + /** + * 密码 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function password(string $name, int $length): Column + { + return Column::string($name)->setLimit(255); + } + + /** + * 颜色 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function color(string $name, int $length): Column + { + return Column::string($name)->setLimit(50); + } + + /** + * 单选 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function radio(string $name, int $length): Column + { + return Column::string($name)->setLimit(20); + } + + /** + * 省市 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function city(string $name, int $length): Column + { + // province_name/city_name + return Column::string($name)->setLimit(255); + } + + /** + * 省市区 + * + * @time 2021年03月08日 + * @param string $name + * @param int $length + * @return Column + */ + public function area(string $name, int $length): Column + { + // province_name/city_name/district_name + return Column::string($name)->setLimit(255); + } +} diff --git a/catch/cms/tables/Articles.php b/catch/cms/tables/Articles.php new file mode 100644 index 0000000..1bc9267 --- /dev/null +++ b/catch/cms/tables/Articles.php @@ -0,0 +1,47 @@ +getTable('articles') + ->header([ + HeaderItem::label('编号')->prop('id'), + + HeaderItem::label('栏目')->prop('category'), + + HeaderItem::label('标题')->prop('title'), + + HeaderItem::label('权重')->prop('weight')->withEditNumberComponent(), + + HeaderItem::label('状态')->prop('status')->withSwitchComponent(), + + HeaderItem::label('创建时间')->prop('created_at'), + + HeaderItem::label('操作')->actions([ + Actions::update()->to('/cms/articles/detail'), + Actions::delete() + ]) + ]) + ->withBind() + ->withApiRoute('cms/articles') + ->withActions([ + Actions::create()->to('/cms/articles/detail/') + ]) + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('articles'); + } + +} \ No newline at end of file diff --git a/catch/cms/tables/Category.php b/catch/cms/tables/Category.php new file mode 100644 index 0000000..987d24d --- /dev/null +++ b/catch/cms/tables/Category.php @@ -0,0 +1,59 @@ +getTable('category') + ->header([ + HeaderItem::label('分类名称')->prop('name'), + HeaderItem::label('自定义链接')->prop('url')->withCopyComponent(), + HeaderItem::label('栏目类型')->prop('type')->withSelectComponent([ + ['value' => 1, 'label' => '列表模式'], + ['value' => 2, 'label' => '单页模式'], + ['value' => 3, 'label' => '封面模式'], + ]), + HeaderItem::label('投稿')->prop('is_can_contribute')->withSwitchComponent([ + ['value' => 1, 'label' => '是'], + ['value' => 2, 'label' => '否'], + ]), + HeaderItem::label('评论')->prop('is_can_comment')->withSwitchComponent(), + HeaderItem::label('状态')->prop('status')->withSwitchComponent(), + HeaderItem::label('权重')->prop('weight')->withEditNumberComponent(), + // HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->actions([ + Actions::update(), + Actions::delete() + ])->width(230) + ]) + ->withActions([ + Actions::create() + ]) + ->withSearch([ + Search::label('分类名称')->name('请输入分类名称'), + Search::label('状态')->status(), + ]) + ->forceUpdate() + ->withApiRoute('cms/category') + ->toTreeTable() + ->withDialogWidth('40%') + ->render(); + } + + public function form() + { + // TODO: Implement form() method. + return Factory::create('category'); + } + + +} diff --git a/catch/cms/tables/Fields.php b/catch/cms/tables/Fields.php new file mode 100644 index 0000000..8d505db --- /dev/null +++ b/catch/cms/tables/Fields.php @@ -0,0 +1,50 @@ +getTable('fields') + ->header([ + HeaderItem::label('编号')->prop('id')->width(80), + HeaderItem::label('字段名称')->prop('name'), + HeaderItem::label('label名称')->prop('title'), + HeaderItem::label('类型')->prop('type'), + // HeaderItem::label('列表显示')->prop('use_at_list')->withSwitchComponent( ), + // HeaderItem::label('搜索')->prop('use_at_search')->withSwitchComponent(), + // HeaderItem::label('详情')->prop('use_at_detail')->withSwitchComponent(), + HeaderItem::label('状态')->prop('status')->withSwitchComponent( ), + HeaderItem::label('设置索引')->prop('is_index')->withSwitchComponent( ), + + HeaderItem::label('操作')->width(260)->isBubble()->actions([ + Actions::update(), + Actions::delete() + ]), + ]) + ->withActions([ + Actions::create(), + ]) + ->withSearch([ + Search::hidden('model_id', '') + ]) + ->withHiddenPaginate() + ->withDialogWidth('40%') + ->withDefaultQueryParams(['model_id']) + ->withBind() + ->withApiRoute('cms/modelFields') + ->render(); + } + + public function form() + { + // TODO: Implement form() method. + return Factory::create('field'); + } +} \ No newline at end of file diff --git a/catch/cms/tables/Model.php b/catch/cms/tables/Model.php new file mode 100644 index 0000000..f188008 --- /dev/null +++ b/catch/cms/tables/Model.php @@ -0,0 +1,48 @@ +getTable('model') + ->header([ + HeaderItem::label('编号')->prop('id'), + HeaderItem::label('模型名称')->prop('name'), + HeaderItem::label('模型别名')->prop('alias'), + HeaderItem::label('模型关联表')->prop('table_name'), + HeaderItem::label('模型信息')->prop('')->width(200)->component('operate'), + HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->actions([ + Actions::update(), + Actions::delete() + ])->width(230) + ]) + ->withActions([ + Actions::create() + ]) + ->withSearch([ + Search::label('模型名称')->name('请填写模型名称'), + ]) + ->forceUpdate() + ->withApiRoute('cms/model') + ->toTreeTable() + ->withDialogWidth('40%') + ->render(); + } + + public function form() + { + // TODO: Implement form() method. + return Factory::create('model'); + } + + +} diff --git a/catch/cms/tables/ModelUsedFields.php b/catch/cms/tables/ModelUsedFields.php new file mode 100644 index 0000000..018d387 --- /dev/null +++ b/catch/cms/tables/ModelUsedFields.php @@ -0,0 +1,21 @@ +getTable('SiteLink') + ->header([ + HeaderItem::label('标题')->prop('title'), + HeaderItem::label('地址')->prop('link_to')->width(400)->withUrlComponent(), + HeaderItem::label('图标')->prop('icon')->width(120)->withPreviewComponent(), + HeaderItem::label('展示')->prop('is_show')->width(120)->withSwitchComponent(), + HeaderItem::label('权重')->prop('weight')->width(120)->withEditNumberComponent(), + HeaderItem::label('操作')->actions([ + Actions::update(), + Actions::delete() + ]) + ]) + ->withActions([ + Actions::create() + ]) + ->withSearch([ + Search::label('网站标题')->input('title', '请输入网站标题') + ]) + ->withBind() + ->withDialogWidth('40%') + ->withApiRoute('cms/site/links') + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('SiteLink'); + } + +} \ No newline at end of file diff --git a/catch/cms/tables/Tags.php b/catch/cms/tables/Tags.php new file mode 100644 index 0000000..b3425ee --- /dev/null +++ b/catch/cms/tables/Tags.php @@ -0,0 +1,45 @@ +getTable('tags') + ->header([ + HeaderItem::label('编号')->prop('id'), + + HeaderItem::label('名称')->prop('name'), + + HeaderItem::label('创建时间')->prop('created_at'), + + HeaderItem::label('操作')->actions([ + Actions::update(), + Actions::delete() + ]) + ]) + ->withBind() + ->withSearch([ + Search::label('名称')->name('请输入标签名称') + ]) + ->withApiRoute('cms/tags') + ->withActions([ + Actions::create() + ]) + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('tags'); + } + +} \ No newline at end of file diff --git a/catch/cms/tables/UsedAt.php b/catch/cms/tables/UsedAt.php new file mode 100644 index 0000000..6165282 --- /dev/null +++ b/catch/cms/tables/UsedAt.php @@ -0,0 +1,21 @@ +required()->maxlength(100)->col(12), + + self::cascader('category_id', '选择分类') + ->options( + Category::field(['id', 'name', 'parent_id'])->select()->toTree() + ) + ->col(12) + ->props(self::props('name', 'id', [ + 'checkStrictly' => true + ])) + ->filterable(true) + ->clearable(true) + ->style(['width' => '100%']) + ->required()->col(8), + + self::input('keywords', '关键字')->col(12), + + self::image('封面', 'cover')->col(12), + + self::textarea('description', '摘要')->col(12), + + self::images('组图', 'images')->col(12), + + self::selectMultiple('tags', '标签') + ->options(Tags::field(['name as value', 'name as label'])->select()->toArray()) + ->clearable(true) + ->allowCreate(true) + ->filterable(true) + ->style(['width' => '100%']) + ->col(12), + + self::input('url', '自定义URL')->col(8), + + self::editor('content', '内容')->required(), + + self::radio('is_top', '置顶', Article::UN_TOP)->options( + self::options()->add('是', Article::TOP) + ->add('否', Article::UN_TOP)->render() + ), + + self::radio('is_recommend', '推荐', Article::UN_RECOMMEND)->options( + self::options()->add('是', Article::RECOMMEND) + ->add('否', Article::UN_RECOMMEND)->render() + ), + + self::radio('status', '展示', Article::ENABLE)->options( + self::options()->add('是', Article::ENABLE) + ->add('否', Article::DISABLE)->render() + ), + + self::radio('is_can_comment', '允许评论', Article::UN_CAN_COMMENT)->options( + self::options()->add('是', Article::CAN_COMMENT) + ->add('否', Article::UN_CAN_COMMENT)->render() + ), + ]; + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/BaseForm.php b/catch/cms/tables/forms/BaseForm.php new file mode 100644 index 0000000..a6c2dec --- /dev/null +++ b/catch/cms/tables/forms/BaseForm.php @@ -0,0 +1,22 @@ +table) { + return array_merge($fields, (new DynamicFormFields())->build($this->table)); + } + + return $fields; + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/Category.php b/catch/cms/tables/forms/Category.php new file mode 100644 index 0000000..842c8ff --- /dev/null +++ b/catch/cms/tables/forms/Category.php @@ -0,0 +1,73 @@ +required(), + Form::cascader('parent_id', '父级栏目') + ->options(CategoryModel::field(['id', 'name', 'parent_id'])->select()->toTree())->props([ + 'props' => [ + 'value' => 'id', + 'label' => 'name', + 'checkStrictly' => true + ] + ])->showAllLevels(false)->style(['width' => '100%']), + + Form::input('title', 'seo标题'), + Form::input('keywords', 'seo关键词'), + Form::textarea('description', 'seo描述'), + Form::input('url', '自定义URL'), + Form::select('type', '页面类型', 1)->options([ + ['value' => 1, 'label' => '列表模式'], + ['value' => 2, 'label' => '单页模式'], + ['value' => 3, 'label' => '封面模式'], + ]), + + Form::radio('status', '状态', 1)->options( + self::options()->add('启用', 1) + ->add('禁用', 2)->render() + ), + + Form::radio('is_can_comment', '评论', 2)->options( + self::options()->add('可以', 1) + ->add('不可以', 2)->render() + ), + + Form::radio('is_can_contribute', '投稿', 2)->options( + self::options()->add('可以', 1) + ->add('不可以', 2)->render() + ), + + Form::number('weight', '权重', 1), + + Form::number('limit', '每页数量', 10), + ]; + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/Factory.php b/catch/cms/tables/forms/Factory.php new file mode 100644 index 0000000..4637183 --- /dev/null +++ b/catch/cms/tables/forms/Factory.php @@ -0,0 +1,12 @@ +required() + ->appendValidate( + Form::validatePattern('^[a-z]{1,30}_?[a-z]{1,30}?')->message('字段名称只支持小写字母,_组合') + ) + ->placeholder('由英文和下划线组成') + ->clearable(true), + // 字段释义 + Form::input('title', 'label名称')->required()->placeholder('表单Label')->clearable(true), + // 字段类型 + Form::select('type', '类型') + ->required() + ->options($this->types()) + ->style(['width' => '100%']) + ->appendControl('string', [Form::number('length', '长度', 1)->max(1000)->min(1)]) + ->appendControl('int', [Form::number('length', '长度', 1)->max(11)->min(1)]) + ->appendControl('select', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')]) + ->appendControl('radio', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')]) + ->appendControl('checkbox', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')]) + ->clearable(true), + // 默认值 + Form::input('default_value', '默认值'), + // 加索引 + Form::radio('is_index', '加索引', 2)->options( + self::options()->add('是', 1) + ->add('否', 2)->render() + ), + // 值唯一 + Form::radio('is_unique', '值唯一', 2)->options( + self::options()->add('是', 1) + ->add('否', 2)->render() + ), + // 表单验证规则 + Form::selectMultiple('rules', '验证规则') + ->options($this->rules()), + // 正则验证 + Form::input('pattern', '正则验证')->placeholder('格式如下(正则|提示信息)'), + // 排序 + Form::number('sort', '排序', 1)->max(10000)->min(1), + // 字段是否在表单中显示 + Form::radio('status', '状态', 1)->options( + self::options()->add('正常', 1) + ->add('隐藏', 2)->render() + ) + ]; + } + + /** + * 表单类型 + * + * @time 2021年03月06日 + * @return \string[][] + */ + protected function types(): array + { + return [ + ['value' => 'string', 'label' => '字符串'], + ['value' => 'int', 'label' => '整数'], + ['value' => 'float', 'label' => '小数'], + ['value' => 'textarea', 'label' => 'textarea文本'], + ['value' => 'text', 'label' => '编辑器(建议)'], + ['value' => 'longtext', 'label' => '编辑器(支持超大文本)'], + ['value' => 'date', 'label' => '日期型'], + ['value' => 'datetime', 'label' => '日期时间型'], + ['value' => 'image', 'label' => '图片上传'], + ['value' => 'images', 'label' => '多图上传'], + ['value' => 'file', 'label' => '文件上传'], + ['value' => 'files', 'label' => '多文件上传'], + ['value' => 'select', 'label' => '列表'], + ['value' => 'checkbox', 'label' => '复选框'], + ['value' => 'password', 'label' => '密码框'], + ['value' => 'color', 'label' => '颜色选项'], + ['value' => 'radio', 'label' => '单选'], + ]; + } + + + protected function rules(): array + { + return [ + ['value' => 'require', 'label' => '必填'], + ['value' => 'number', 'label' => '数字'], + ['value' => 'integer', 'label' => '整数'], + ['value' => 'float', 'label' => '浮点数'], + ['value' => 'email', 'label' => '邮箱'], + ['value' => 'date', 'label' => '日期'], + ['value' => 'alpha', 'label' => '纯字母'], + ['value' => 'alphaNum', 'label' => '纯字母和数字'], + ['value' => 'url', 'label' => 'url地址'], + ['value' => 'ip', 'label' => 'ip地址'], + ['value' => 'mobile', 'label' => '手机号'], + ['value' => 'idCard', 'label' => '身份证'], + ['value' => 'zip', 'label' => '邮政编码'], + ['value' => 'password', 'label' => '密码'], + ['value' => 'strong_password', 'label' => '强密码'], + ['value' => 'landLine', 'label' => '座机'], + ['value' => 'chinese_character', 'label' => '汉字'] + ]; + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/Model.php b/catch/cms/tables/forms/Model.php new file mode 100644 index 0000000..e97a7fd --- /dev/null +++ b/catch/cms/tables/forms/Model.php @@ -0,0 +1,67 @@ +required()->maxlength(100), + self::input('alias', '模型别名')->required()->appendValidates([ + self::validateAlphaDash() + ]), + self::select('table_name', '模型关联表') + ->options($this->getCMSTables()) + ->style(['width' => '100%']) + ->required(), + + self::textarea('description', '模型描述')->maxlength(255), + ]; + } + + + /** + * 获取 Cms 表 + * + * @time 2021年04月30日 + * @return mixed + */ + protected function getCMSTables() + { + $options = self::options(); + + foreach (Db::getTables() as $table) { + if (Str::contains($table, 'cms') && !Str::contains($table, 'relate')) { + $options->add($table, $table); + } + } + + return $options->render(); + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/ModelUsedFields.php b/catch/cms/tables/forms/ModelUsedFields.php new file mode 100644 index 0000000..7665143 --- /dev/null +++ b/catch/cms/tables/forms/ModelUsedFields.php @@ -0,0 +1,66 @@ +param('model_id'); + + $model = Models::where('id', $modelId)->with('fields')->find(); + + $fields = $this->getModelFields($model->table_name); + + $this->primaryKeyValue = $modelId; + // TODO: Implement fields() method. + return [ + self::select('used_at_list', '列表使用', $model->used_at_list ? explode(',', $model->used_at_list) : '') + ->multiple(true) + ->style(['width' => '100%']) + ->options($fields), + + self::select('used_at_search', '搜索使用' , $model->used_at_search ? explode(',', $model->used_at_search) : '') + ->multiple(true) + ->style(['width' => '100%']) + ->options($fields), + + self::select('used_at_detail', '详情使用', $model->used_at_detail ? explode(',', $model->used_at_detail) : '') + ->multiple(true) + ->style(['width' => '100%']) + ->options($fields), + ]; + } + + /** + * 获取模型字段 + * + * @time 2021年05月11日 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @return int[]|string[] + */ + protected function getModelFields($tableName) + { + $fields = array_keys(Db::name($tableName)->getFields()); + + foreach ($fields as $k => $field) { + if ($field === app(Models::class)->getDeleteAtField()) { + unset($fields[$k]); + } + } + + $options = self::options(); + + foreach ($fields as $field) { + $options = $options->add($field, $field); + } + + + return $options->render(); + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/SiteLink.php b/catch/cms/tables/forms/SiteLink.php new file mode 100644 index 0000000..77e877c --- /dev/null +++ b/catch/cms/tables/forms/SiteLink.php @@ -0,0 +1,30 @@ +required(), + + self::input('link_to', '跳转地址')->required()->appendValidates([ + self::validateUrl() + ]), + + self::image('网站图标', 'icon'), + + self::radio('is_show', '展示', BaseModel::ENABLE)->options( + self::options()->add('是', BaseModel::ENABLE) + ->add('否', BaseModel::DISABLE)->render() + ), + + self::number('weight', '权重')->min(1)->max(10000) + ]; + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/Tags.php b/catch/cms/tables/forms/Tags.php new file mode 100644 index 0000000..d1628e1 --- /dev/null +++ b/catch/cms/tables/forms/Tags.php @@ -0,0 +1,21 @@ +required(), + + self::input('title', 'seo 标题'), + + self::input('keywords', 'seo 关键词'), + + self::input('description', 'seo 描述'), + ]; + } +} \ No newline at end of file diff --git a/catch/cms/tables/forms/UsedAt.php b/catch/cms/tables/forms/UsedAt.php new file mode 100644 index 0000000..bd222a3 --- /dev/null +++ b/catch/cms/tables/forms/UsedAt.php @@ -0,0 +1,15 @@ +