UsersInfoForm.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use App\Models\UserInfoModel;
  4. use Dcat\Admin\Contracts\LazyRenderable;
  5. use Dcat\Admin\Traits\LazyWidget;
  6. use Dcat\Admin\Widgets\Form;
  7. class UsersInfoForm extends Form implements LazyRenderable
  8. {
  9. use LazyWidget;
  10. public function __construct($data = [], $key = null)
  11. {
  12. parent::__construct($data, $key);
  13. }
  14. public function handle(array $input)
  15. {
  16. $user_info = UserInfoModel::query()->find($input['user_id']);
  17. if (!$user_info) {
  18. return $this->response()->error('请刷新后重试');
  19. }
  20. $user_info->update($input);
  21. return $this->response()->success('保存成功')->refresh();
  22. }
  23. public function form()
  24. {
  25. if (request()->ajax()) {
  26. $user_info = UserInfoModel::query()->where('user_id', $this->payload['user_id'])->first();
  27. $this->fill($user_info);
  28. }
  29. $this->text('user_id', "用户ID")->readOnly();
  30. $this->text('nickname', '昵称')->required();
  31. $this->image('avatar', '头像')->disk('oss')->saveFullUrl()->uniqueName()->removable(false)->autoUpload();
  32. $this->text('weixin', '微信号');
  33. $this->text('birthday', '生日');
  34. $this->text('height', '身高');
  35. $this->text('weight', '体重');
  36. $this->text('work', '职业');
  37. $this->text('info', '个人简介');
  38. $this->text('area', '所在地区')->default("成都市");
  39. $this->text('figure', '身材');
  40. $this->text('feeling', '感情状态');
  41. $this->text('education', '学历');
  42. $this->text('income', '年收入');
  43. $this->text('hobby', '兴趣爱好')->help("多个字段用,隔开,例如:唱歌,跳舞");
  44. $this->text('drink', '喝酒');
  45. $this->text('smoke', '抽烟');
  46. $this->array('photo', function (Form $form) {
  47. $form->image('url', '图片')->disk("oss")->saveFullUrl()->uniqueName()->removable(false)->autoUpload()->on('startUpload', <<<JS
  48. function () {
  49. console.log('文件开始上传...', this);
  50. // 上传文件前附加自定义参数到文件上传接口
  51. this.uploader.options.formData['custom_field'] = '...';
  52. }
  53. JS
  54. )
  55. ->on('uploadFinished', <<<JS
  56. function () {
  57. console.log('文件上传完毕');
  58. }
  59. JS
  60. );;
  61. $form->radio('state', '阅后即焚')->options([0 => "否", 1 => "是"])->default(0);
  62. })->saveAsJson()->label('相册');
  63. $this->file('video', '视频')->saveAsJson();
  64. }
  65. }