UserAction.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use App\Models\UserInfoModel;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Grid\RowAction;
  6. use Dcat\Admin\Widgets\Modal;
  7. use Dcat\Admin\Widgets\Table;
  8. class UserAction extends RowAction
  9. {
  10. protected $title = '更多资料';
  11. protected $model;
  12. public function __construct(string $model = null)
  13. {
  14. $this->model = $model;
  15. }
  16. /**
  17. * 设置确认弹窗信息,如果返回空值,则不会弹出弹窗
  18. *
  19. * 允许返回字符串或数组类型
  20. *
  21. * @return array|string|void
  22. */
  23. public function confirm()
  24. {
  25. }
  26. /**
  27. * 处理请求
  28. *
  29. * @param Request $request
  30. *
  31. * @return \Dcat\Admin\Actions\Response
  32. */
  33. public function handle(Request $request)
  34. {
  35. return $this->response()
  36. ->success('Processed successfully: '.$this->getKey())
  37. ->redirect('/');
  38. }
  39. /**
  40. * 设置要POST到接口的数据
  41. *
  42. * @return array
  43. */
  44. public function parameters()
  45. {
  46. return [];
  47. }
  48. public function render()
  49. {
  50. return Modal::make()
  51. ->lg()
  52. ->title($this->title)
  53. ->body($this->table($this->getKey()))
  54. ->button('<i class="feather icon-grid"></i> 更多资料');
  55. }
  56. protected function table($user_id)
  57. {
  58. $userInfo = UserInfoModel::query()->find($user_id);
  59. if(!$userInfo){
  60. return ;
  61. }
  62. $photo = json_decode($userInfo->photo,true);
  63. $photoDiv = "<div class='show_img_div'>";
  64. if(count($photo)>0){
  65. foreach ($photo as $v){
  66. $photoDiv.= "<img src='".$v."' style='width:80px;height:80px;margin-right:10px'/>";
  67. }
  68. }
  69. $photoDiv .= "</div>";
  70. $video = json_decode($userInfo->video,true);
  71. $videoDiv = "<div>";
  72. if(count($video)>0){
  73. foreach ($video as $v){
  74. $videoDiv .= "<video src='".$v."' style='width:200px;height:200px;margin-right:10px' controls='controls'></video>";
  75. }
  76. }
  77. $videoDiv .= "</div>";
  78. Admin::style('.table td{padding: .85rem .55rem}');
  79. Admin::script(<<<JS
  80. $('.show_img_div>img').click(function(){
  81. Dcat.swal.fire(
  82. {imageUrl:this.src,
  83. imageMaxWidth:1200,
  84. imageMaxHeight:900,
  85. imageAlt:'图片打开失败'}
  86. );
  87. });
  88. JS);
  89. $data = [
  90. ['name' => '相册', 'value' => $photoDiv],
  91. ['name' => '视频', 'value' => $videoDiv],
  92. ['name' => '生日', 'value' => $userInfo->birthday],
  93. ['name' => '身高', 'value' => $userInfo->height.'cm'],
  94. ['name' => '体重', 'value' => $userInfo->weight.'kg'],
  95. ['name' => '职业', 'value' => $userInfo->work],
  96. ['name' => '个人简介', 'value' =>$userInfo->info],
  97. ['name' => '地区', 'value' => $userInfo->area],
  98. ['name' => '身材', 'value' => $userInfo->figure],
  99. ['name' => '感情状态', 'value' => $userInfo->feeling],
  100. ['name' => '学历', 'value' => $userInfo->education],
  101. ['name' => '年收入', 'value' => $userInfo->income],
  102. ['name' => '兴趣爱好', 'value' => $userInfo->hobby],
  103. ['name' => '抽烟喝酒', 'value' => $userInfo->drink],
  104. ];
  105. return Table::make(['名称', '值'], $data);
  106. }
  107. }