UserAction.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. $photoDiv = "";
  63. if(isset($userInfo->photo)&&!empty($userInfo->photo)){
  64. $photo = json_decode($userInfo->photo,true);
  65. $photoDiv = "<div class='show_img_div'>";
  66. if(is_array($photo)&&count($photo)>0){
  67. foreach ($photo as $v){
  68. $photoDiv.= "<img src='".$v['url']."' style='width:80px;height:80px;margin-right:10px'/>";
  69. }
  70. }
  71. $photoDiv .= "</div>";
  72. }
  73. $videoDiv = "";
  74. if(isset($userInfo->video)&&!empty($userInfo->video)){
  75. $video = json_decode($userInfo->video,true);
  76. $videoDiv = "<div>";
  77. if(is_array($video)&&count($video)>0){
  78. foreach ($video as $v){
  79. if(isset($v['url'])){
  80. $videoDiv .= "<video src='".$v['url']."' style='width:200px;height:200px;margin-right:10px' controls='controls'></video>";
  81. }
  82. }
  83. }
  84. $videoDiv .= "</div>";
  85. }
  86. Admin::style('.table td{padding: .85rem .55rem}');
  87. Admin::script(<<<JS
  88. $('.show_img_div>img').click(function(){
  89. Dcat.swal.fire(
  90. {imageUrl:this.src,
  91. imageMaxWidth:1200,
  92. imageMaxHeight:900,
  93. imageAlt:'图片打开失败'}
  94. );
  95. });
  96. JS);
  97. $data = [
  98. ['name' => '相册', 'value' => $photoDiv],
  99. ['name' => '视频', 'value' => $videoDiv],
  100. ['name' => '生日', 'value' => $userInfo->birthday],
  101. ['name' => '身高', 'value' => $userInfo->height.'cm'],
  102. ['name' => '体重', 'value' => $userInfo->weight.'kg'],
  103. ['name' => '职业', 'value' => $userInfo->work],
  104. ['name' => '个人简介', 'value' =>$userInfo->info],
  105. ['name' => '地区', 'value' => $userInfo->area],
  106. ['name' => '身材', 'value' => $userInfo->figure],
  107. ['name' => '感情状态', 'value' => $userInfo->feeling],
  108. ['name' => '学历', 'value' => $userInfo->education],
  109. ['name' => '年收入', 'value' => $userInfo->income],
  110. ['name' => '兴趣爱好', 'value' => $userInfo->hobby],
  111. ['name' => '抽烟喝酒', 'value' => $userInfo->drink],
  112. ];
  113. return Table::make(['名称', '值'], $data);
  114. }
  115. }