From 02e16a0fba7b5f3371303d07a619ccf97b81bab3 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 4 Nov 2020 17:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=B0=8F=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Grid/v3/ShareCardCreate.php | 34 ++++++++ app/Admin/Actions/Grid/v3/ShareCardDelete.php | 40 ++++++++++ app/Admin/Actions/Grid/v3/ShareCardEdit.php | 39 ++++++++++ .../v3/ShareCardSettingController.php | 74 ++++++++++++++++++ .../Controllers/v3/SystemConfigController.php | 7 -- app/Admin/Forms/v3/ProgramShareCardForm.php | 78 ------------------- app/Admin/Forms/v3/ShareCardCreateForm.php | 61 +++++++++++++++ app/Admin/Forms/v3/ShareCardEditForm.php | 69 ++++++++++++++++ .../Repositories/v3/ShareCardSetting.php | 25 ++++++ app/Admin/routes.php | 2 +- resources/lang/zh-CN/share-card-setting.php | 15 ++++ resources/lang/zh-CN/system-config.php | 3 +- 12 files changed, 360 insertions(+), 87 deletions(-) create mode 100644 app/Admin/Actions/Grid/v3/ShareCardCreate.php create mode 100644 app/Admin/Actions/Grid/v3/ShareCardDelete.php create mode 100644 app/Admin/Actions/Grid/v3/ShareCardEdit.php create mode 100644 app/Admin/Controllers/v3/ShareCardSettingController.php delete mode 100644 app/Admin/Forms/v3/ProgramShareCardForm.php create mode 100644 app/Admin/Forms/v3/ShareCardCreateForm.php create mode 100644 app/Admin/Forms/v3/ShareCardEditForm.php create mode 100644 app/Admin/Repositories/v3/ShareCardSetting.php create mode 100644 resources/lang/zh-CN/share-card-setting.php diff --git a/app/Admin/Actions/Grid/v3/ShareCardCreate.php b/app/Admin/Actions/Grid/v3/ShareCardCreate.php new file mode 100644 index 0000000..851b7bb --- /dev/null +++ b/app/Admin/Actions/Grid/v3/ShareCardCreate.php @@ -0,0 +1,34 @@ +添加'; + + public function render() + { + $modal = Modal::make() + ->xl() + ->title('分享卡片添加') + ->body(ShareCardCreateForm::make()) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Actions/Grid/v3/ShareCardDelete.php b/app/Admin/Actions/Grid/v3/ShareCardDelete.php new file mode 100644 index 0000000..16dc535 --- /dev/null +++ b/app/Admin/Actions/Grid/v3/ShareCardDelete.php @@ -0,0 +1,40 @@ +get('id'); + $res = Redis::hdel(RedisKey::PROGRAM_SHARE_CARD ,$id); + if($res !== false){ + return $this->response()->success('删除成功!','/share_card_setting'); + }else{ + return $this->response()->error('删除失败!'); + } + } + + // 确认弹窗信息 + public function confirm() + { + return '您确定要删除吗?'; + } + + public function parameters() + { + return [ + 'id' => $this->row->id ?? 0 + ]; + } +} diff --git a/app/Admin/Actions/Grid/v3/ShareCardEdit.php b/app/Admin/Actions/Grid/v3/ShareCardEdit.php new file mode 100644 index 0000000..aca8a8d --- /dev/null +++ b/app/Admin/Actions/Grid/v3/ShareCardEdit.php @@ -0,0 +1,39 @@ +xl() + ->title('编辑') + ->body(ShareCardEditForm::make()->payload([ + 'id'=>$this->row->id, + 'title'=>$this->row->title, + 'image'=>$this->row->image + ])) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/ShareCardSettingController.php b/app/Admin/Controllers/v3/ShareCardSettingController.php new file mode 100644 index 0000000..c454d9b --- /dev/null +++ b/app/Admin/Controllers/v3/ShareCardSettingController.php @@ -0,0 +1,74 @@ +column('id'); + $grid->column('title'); + $grid->column('image')->image('',80); + + $grid->tools([new ShareCardCreate()]); + $grid->actions([new ShareCardEdit(), new ShareCardDelete()]); + // 每页1条 + $grid->paginate(10); + $grid->disableCreateButton(); + $grid->disableBatchActions(); + $grid->disableBatchDelete(); + + $grid->toolsWithOutline(); + + $grid->disableDeleteButton(); + $grid->disableEditButton(); + $grid->disableQuickEditButton(); + $grid->disableViewButton(); + // $grid->disableActions(); + + $grid->disableRowSelector(); + $grid->disableFilter(); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new ShareCardSetting(), function (Show $show) { + + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new ShareCardSetting(), function (Form $form) { + + }); + } +} diff --git a/app/Admin/Controllers/v3/SystemConfigController.php b/app/Admin/Controllers/v3/SystemConfigController.php index 6f6a408..5dd8ee5 100644 --- a/app/Admin/Controllers/v3/SystemConfigController.php +++ b/app/Admin/Controllers/v3/SystemConfigController.php @@ -120,11 +120,4 @@ class SystemConfigController extends AdminController $form->disableCreatingCheck(); }); } - - public function shareCardSettingForm(Content $content) - { - return $content - ->title('分享设置') - ->body(new Card(new ProgramShareCardForm())); - } } diff --git a/app/Admin/Forms/v3/ProgramShareCardForm.php b/app/Admin/Forms/v3/ProgramShareCardForm.php deleted file mode 100644 index b8f7597..0000000 --- a/app/Admin/Forms/v3/ProgramShareCardForm.php +++ /dev/null @@ -1,78 +0,0 @@ -success('修改成功','/share_card_setting'); - }else{ - return $this->error('修改失败'); - } - } - - /** - * Build a form here. - */ - public function form() - { - $data = Redis::hgetall(RedisKey::PROGRAM_SHARE_CARD); - - $this->display('setting' , '设置')->value('小程序分享卡片设置'); - foreach($data as &$value){ - $value = json_decode($value,true); - // dd($data); - $this->table('share_card', function (NestedForm $table) use($value){ - $table->text('title','标题')->value($value['title'])->width(10); - $table->image('image','图片')->autoUpload()->width(2) - ->customFormat(function() use($value){ - return [$value['image']]; - }); - }); - } - - - // $this->hasMany('share_card', function (NestedForm $form) { - // $form->text('title','标题')->required()->default(''); - // $form->image('image','图片')->autoUpload()->saveFullUrl()->width(3); - // }); - - // $this->image('img');->saveFullUrl() - } - - /** - * The data of the form. - * - * @return array - */ - public function default() - { - return []; - } - -} diff --git a/app/Admin/Forms/v3/ShareCardCreateForm.php b/app/Admin/Forms/v3/ShareCardCreateForm.php new file mode 100644 index 0000000..a6b1c45 --- /dev/null +++ b/app/Admin/Forms/v3/ShareCardCreateForm.php @@ -0,0 +1,61 @@ + $id, + 'title' => $input['title'], + 'image' => $input['image'] + ]; + + $data = json_encode($data); + + $res = Redis::hset(RedisKey::PROGRAM_SHARE_CARD ,$id, $data); + if($res){ + return $this->success('添加成功','/share_card_setting'); + }else{ + return $this->error('添加失败'); + } + } + + /** + * Build a form here. + */ + public function form() + { + $this->display('setting' , ' ')->value('小程序分享卡片设置'); + + $this->text('title','标题'); + $this->image('image','图片')->autoUpload()->saveFullUrl()->width(3); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +} diff --git a/app/Admin/Forms/v3/ShareCardEditForm.php b/app/Admin/Forms/v3/ShareCardEditForm.php new file mode 100644 index 0000000..83f5db8 --- /dev/null +++ b/app/Admin/Forms/v3/ShareCardEditForm.php @@ -0,0 +1,69 @@ + $id, + 'title' => $input['title'], + 'image' => $input['image'] + ]; + + $data = json_encode($data); + + $res = Redis::hset(RedisKey::PROGRAM_SHARE_CARD ,$id, $data); + if($res !== false){ + return $this->success('修改成功','/share_card_setting'); + }else{ + return $this->error('修改失败'); + } + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->payload['id'] ?? 0; + $title = $this->payload['title'] ?? ''; + $image = $this->payload['image'] ?? ''; + $this->display('setting' , ' ')->value('小程序分享卡片设置'); + $this->hidden('id')->value($id); + $this->text('title','标题')->value($title); + $this->image('image','图片')->autoUpload() + ->customFormat(function() use($image){ + return [$image]; + }) + ->saveFullUrl()->width(3); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +} diff --git a/app/Admin/Repositories/v3/ShareCardSetting.php b/app/Admin/Repositories/v3/ShareCardSetting.php new file mode 100644 index 0000000..a8efa38 --- /dev/null +++ b/app/Admin/Repositories/v3/ShareCardSetting.php @@ -0,0 +1,25 @@ +makePaginator( + count($data), + $data + ); + } + +} \ No newline at end of file diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 68d9bca..b85ec8c 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -98,6 +98,6 @@ Route::group([ $router->any('/goods_report_export', 'v3\GoodsReportController@export'); // 分享小卡片设置 - $router->get('/share_card_setting', 'v3\SystemConfigController@shareCardSettingForm'); + $router->resource('/share_card_setting', 'v3\ShareCardSettingController'); }); diff --git a/resources/lang/zh-CN/share-card-setting.php b/resources/lang/zh-CN/share-card-setting.php new file mode 100644 index 0000000..14f787e --- /dev/null +++ b/resources/lang/zh-CN/share-card-setting.php @@ -0,0 +1,15 @@ + [ + 'ShareCardSetting' => '分享设置', + 'shareCardSetting' => '分享设置', + 'share_card_setting' => '分享设置', + ], + 'fields' => [ + 'title' => '标题', + 'image' => '图片', + 'share_card' => ' ' + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh-CN/system-config.php b/resources/lang/zh-CN/system-config.php index 1dea41a..8c227d1 100644 --- a/resources/lang/zh-CN/system-config.php +++ b/resources/lang/zh-CN/system-config.php @@ -14,7 +14,8 @@ return [ 'desc' => '配置简介', 'sort' => '排序', 'status' => '状态', - 'status_text' => '状态' + 'status_text' => '状态', + 'share_card' => ' ' ], 'options' => [ ],