链街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.

70 lines
1.8 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. $ossImageDir = config('filesystems.disks.oss.img_host');
  23. $data = [
  24. 'id' => $id,
  25. 'title' => $input['title'],
  26. 'image' => $ossImageDir.'/'.$input['image'],
  27. 'relative_path' => $input['image'],
  28. ];
  29. $data = json_encode($data);
  30. $res = Redis::hset(RedisKey::PROGRAM_SHARE_CARD ,$id, $data);
  31. if($res !== false){
  32. return $this->success('修改成功','/share_card_setting');
  33. }else{
  34. return $this->error('修改失败');
  35. }
  36. }
  37. /**
  38. * Build a form here.
  39. */
  40. public function form()
  41. {
  42. $id = $this->payload['id'] ?? 0;
  43. $title = $this->payload['title'] ?? '';
  44. $image = $this->payload['image'] ?? '';
  45. $this->display('setting' , ' ')->value('小程序分享卡片设置');
  46. $this->hidden('id')->value($id);
  47. $this->text('title','标题')->required()->value($title);
  48. $this->image('image','图片')->required()->autoUpload()
  49. ->customFormat(function() use($image){
  50. return [$image];
  51. })->width(3);
  52. }
  53. /**
  54. * The data of the form.
  55. *
  56. * @return array
  57. */
  58. public function default()
  59. {
  60. return [];
  61. }
  62. }