99 * @contact 4213509@qq.com
1010 * @license https://github.com/hyperf-plus/admin/blob/master/LICENSE
1111 */
12+
1213namespace HPlus \Admin \Controller ;
1314
1415use HPlus \Admin \Model \Admin \OperationLog ;
1920use HPlus \UI \Components \Grid \Avatar ;
2021use HPlus \UI \Components \Grid \Route ;
2122use HPlus \UI \Components \Grid \Tag ;
23+ use HPlus \UI \Components \Widgets \Button ;
24+ use HPlus \UI \Components \Widgets \Dialog ;
25+ use HPlus \UI \Components \Widgets \Markdown ;
2226use HPlus \UI \Form ;
2327use HPlus \UI \Grid ;
28+ use HPlus \UI \Layout \Content ;
2429use Hyperf \Database \Model \Model ;
2530
2631/**
@@ -38,24 +43,64 @@ protected function grid()
3843 ->emptyText ('暂无日志 ' )
3944 ->height ('auto ' )
4045 ->appendFields (['user.id ' ]);
46+ $ grid ->pageSizes ([10 , 20 ]);
4147 $ grid ->column ('id ' , 'ID ' )->width ('100 ' );
4248 $ grid ->column ('user.avatar ' , '头像 ' , 'user_id ' )->component (Avatar::make ()->size ('small ' ))->width (80 );
43- $ grid ->column ('user.name ' , '用户 ' , 'user_id ' )->help ('操作用户 ' )->sortable ()->component (Route::make ('/admin/logs/list?user_id={user.id} ' )->type ('primary ' ));
44- $ grid ->column ('method ' , '请求方式 ' )->width (100 )->align ('center ' )->component (Tag::make ()->type (['GET ' => 'info ' , 'POST ' => 'success ' ]));
49+ $ grid ->column ('user.name ' , '用户 ' , 'user_id ' )->width ( 80 )-> help ('操作用户 ' )->sortable ()->component (Route::make ('/admin/logs/list?user_id={user.id} ' )->type ('primary ' ));
50+ $ grid ->column ('method ' , '请求方式 ' )->width (80 )->align ('center ' )->component (Tag::make ()->type (['GET ' => 'info ' , 'POST ' => 'success ' ]));
4551 $ grid ->column ('path ' , '路径 ' )->help ('操作URL ' )->sortable ();
46- $ grid ->column ('runtime ' , '执行时间 ' )->help ('毫秒 ' );
47- $ grid ->column ('ip ' , 'IP ' )->component (Route::make ('/admin/logs/list?ip={ip} ' )->type ('primary ' ));
52+ $ grid ->column ('runtime ' , '执行时间 ' )->help ('毫秒 ' )-> width ( 80 ) ;
53+ $ grid ->column ('ip ' , 'IP ' )->component (Route::make ('/admin/logs/list?ip={ip} ' )->type ('primary ' ))-> width ( 100 ) ;
4854 $ grid ->column ('created_at ' , '创建时间 ' )->sortable ();
49-
5055 $ grid ->actions (function (Grid \Actions $ actions ) {
56+ $ row = $ actions ->getRow ();
57+ $ action = new Grid \Actions \ActionButton ('请求头 ' );
58+ $ action ->order (5 );
59+ $ action ->dialog (function (Dialog $ dialog ) use ($ row ) {
60+ $ dialog ->title ('查看请求头信息 ' );
61+ $ dialog ->slot (function (Content $ content ) use ($ row ) {
62+ $ code = "```json \n" ;
63+ $ code .= json_encode ($ row ->header , JSON_UNESCAPED_UNICODE |JSON_PRETTY_PRINT );
64+ $ code .= "\n``` " ;
65+ $ content ->body (Markdown::make ($ code )->style ("height:60vh; " ));
66+ });
67+ });
68+ $ actions ->add ($ action );
69+ unset($ action );
70+ $ action = new Grid \Actions \ActionButton ('请求值 ' );
71+ $ action ->order (5 );
72+ $ action ->dialog (function (Dialog $ dialog ) use ($ row ) {
73+ $ dialog ->title ('查看提交参数信息 ' );
74+ $ dialog ->slot (function (Content $ content ) use ($ row ) {
75+ $ code = "```json \n" ;
76+ $ code .= json_encode ($ row ->request , JSON_UNESCAPED_UNICODE |JSON_PRETTY_PRINT );
77+ $ code .= "\n``` " ;
78+ $ content ->body (Markdown::make ($ code )->style ("height:60vh; " ));
79+ });
80+ });
81+ $ actions ->add ($ action );
82+ unset($ action );
83+
84+ $ action = new Grid \Actions \ActionButton ('响应结果 ' );
85+ $ action ->order (4 );
86+ $ action ->dialog (function (Dialog $ dialog ) use ($ row ) {
87+ $ dialog ->title ('查看响应结果 ' );
88+ $ dialog ->slot (function (Content $ content ) use ($ row ) {
89+ $ code = "```json \n" ;
90+ $ code .= json_encode ($ row ->result ,JSON_UNESCAPED_UNICODE |JSON_PRETTY_PRINT );
91+ $ code .= "\n``` " ;
92+ $ content ->body (Markdown::make ($ code )->style ("height:60vh; " ));
93+ });
94+ });
95+ $ actions ->add ($ action );
5196 $ actions ->hideEditAction ();
5297 $ actions ->hideViewAction ();
5398 })->toolbars (function (Grid \Toolbars $ toolbars ) {
5499 $ toolbars ->hideCreateButton ();
55100 });
56101
57102 $ grid ->filter (function (Grid \Filter $ filter ) {
58- $ user_id = (int ) request ('user_id ' );
103+ $ user_id = (int )request ('user_id ' );
59104 $ filter ->equal ('user_id ' )->component (Select::make ($ user_id )->placeholder ('请选择用户 ' )->options (function () {
60105 $ user_ids = OperationLog::query ()->groupBy ('user_id ' )->get (['user_id ' ])->pluck ('user_id ' )->toArray ();
61106 /*@var Model $userModel */
0 commit comments