链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

  1. <?php
  2. namespace App\Admin\Forms\v3;
  3. use Dcat\Admin\Widgets\Form;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Illuminate\Support\Facades\Redis;
  6. use App\Libs\Redis\RedisKey;
  7. use Dcat\Admin\Contracts\LazyRenderable;
  8. use Dcat\Admin\Traits\LazyWidget;
  9. class ShareCardEditForm extends Form implements LazyRenderable
  10. {
  11. use LazyWidget;
  12. /**
  13. * Handle the form request.
  14. *
  15. * @param array $input
  16. *
  17. * @return Response
  18. */
  19. public function handle(array $input)
  20. {
  21. $id = $input['id'];
  22. $data = [
  23. 'id' => $id,
  24. 'title' => $input['title'],
  25. 'image' => $input['image']
  26. ];
  27. $data = json_encode($data);
  28. $res = Redis::hset(RedisKey::PROGRAM_SHARE_CARD ,$id, $data);
  29. if($res !== false){
  30. return $this->success('修改成功','/share_card_setting');
  31. }else{
  32. return $this->error('修改失败');
  33. }
  34. }
  35. /**
  36. * Build a form here.
  37. */
  38. public function form()
  39. {
  40. $id = $this->payload['id'] ?? 0;
  41. $title = $this->payload['title'] ?? '';
  42. $image = $this->payload['image'] ?? '';
  43. $this->display('setting' , ' ')->value('小程序分享卡片设置');
  44. $this->hidden('id')->value($id);
  45. $this->text('title','标题')->required()->value($title);
  46. $this->image('image','图片')->required()->autoUpload()
  47. ->customFormat(function() use($image){
  48. return [$image];
  49. })
  50. ->saveFullUrl()->width(3);
  51. }
  52. /**
  53. * The data of the form.
  54. *
  55. * @return array
  56. */
  57. public function default()
  58. {
  59. return [];
  60. }
  61. }