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

78 lines
2.0 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\Form\NestedForm;
  8. class ProgramShareCardForm extends Form
  9. {
  10. /**
  11. * Handle the form request.
  12. *
  13. * @param array $input
  14. *
  15. * @return Response
  16. */
  17. public function handle(array $input)
  18. {
  19. // 获取外部传递参数
  20. $data = $input['share_card'];
  21. $data[0]['image'] = '';
  22. foreach($data as &$value){
  23. $value = json_encode($value);
  24. }
  25. // dd($data);
  26. $res = Redis::hmset(RedisKey::PROGRAM_SHARE_CARD , $data);
  27. if($res){
  28. return $this->success('修改成功','/share_card_setting');
  29. }else{
  30. return $this->error('修改失败');
  31. }
  32. }
  33. /**
  34. * Build a form here.
  35. */
  36. public function form()
  37. {
  38. $data = Redis::hgetall(RedisKey::PROGRAM_SHARE_CARD);
  39. $this->display('setting' , '设置')->value('小程序分享卡片设置');
  40. foreach($data as &$value){
  41. $value = json_decode($value,true);
  42. // dd($data);
  43. $this->table('share_card', function (NestedForm $table) use($value){
  44. $table->text('title','标题')->value($value['title'])->width(10);
  45. $table->image('image','图片')->autoUpload()->width(2)
  46. ->customFormat(function() use($value){
  47. return [$value['image']];
  48. });
  49. });
  50. }
  51. // $this->hasMany('share_card', function (NestedForm $form) {
  52. // $form->text('title','标题')->required()->default('');
  53. // $form->image('image','图片')->autoUpload()->saveFullUrl()->width(3);
  54. // });
  55. // $this->image('img');->saveFullUrl()
  56. }
  57. /**
  58. * The data of the form.
  59. *
  60. * @return array
  61. */
  62. public function default()
  63. {
  64. return [];
  65. }
  66. }