12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Admin\Actions\Chat;
- use App\Models\ChatList;
- use App\Models\User;
- use App\Models\UserFollow;
- use App\Models\UserFriend;
- use App\Repositories\ImMessage;
- use App\Services\TencentImMessage;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Grid\LazyRenderable;
- class ChatLog extends LazyRenderable
- {
- public function grid(): Grid
- {
- $chat_data = UserFollow::query()->find($this->payload['id']);
- return Grid::make(new ImMessage($chat_data->user_id,$chat_data->target_id), function (Grid $grid) {
- // $grid->column('user_id', 'ID')->sortable();
- $grid->column('From_Account',trans('chat-team.fields.From_Account'))->display(function ($res){
- $user = User::query()->where('tencent_im_user_id',$res)->first();
- $str = "";
- $str.="<div style='margin-right:10px;text-align: center;display: flex'>";
- $str.='<img data-action="preview-img" src="'.$user->avatar.'" style="max-width:50px;max-height:50px;cursor:pointer" class="img img-thumbnail">';
- $str.='<p style="margin-top: 5px">'.$user->name.'</p>';
- $str.="</div>";
- return $str;
- });
- $grid->column('To_Account',trans('chat-team.fields.To_Account'))->display(function ($res){
- $user = User::query()->where('tencent_im_user_id',$res)->first();
- $str = "";
- $str.="<div style='margin-right:10px;text-align: center;display: flex'>";
- $str.='<img data-action="preview-img" src="'.$user->avatar.'" style="max-width:50px;max-height:50px;cursor:pointer" class="img img-thumbnail">';
- $str.='<p style="margin-top: 5px">'.$user->name.'</p>';
- $str.="</div>";
- return $str;
- });
- $grid->column('MsgTimeStamp',trans('chat-team.fields.MsgTimeStamp'))->display(function ($res){
- return date("m-d H:i",$res);
- });
- $grid->column('MsgBody',trans('chat-team.fields.Message_content'))->display(function ($res){
- //dd($res);
- //$res = json_decode($res,true);
- if($res[0]['MsgType']=='TIMTextElem'){
- //文本消息
- return $res[0]['MsgContent']['Text'];
- }elseif ($res[0]['MsgType']=="TIMLocationElem"){
- //位置消息
- return $res[0]['MsgContent']['Desc'];
- }elseif ($res[0]['MsgType']=="TIMFaceElem"){
- //表情消息
- }elseif ($res[0]['MsgType']=="TIMCustomElem"){
- //自定义消息
- }elseif ($res[0]['MsgType']=="TIMSoundElem"){
- //语音消息
- $str = "<audio src='".$res[0]['MsgContent']['Url']."' controls='controls'></audio>";
- return $str;
- }elseif ($res[0]['MsgType']=="TIMImageElem"){
- //图像消息
- $imgs = $res[0]['MsgContent']['ImageInfoArray'];
- $str = "";
- if(count($imgs)>0){
- $str.='<img data-action="preview-img" src="'.$imgs[0]['URL'].'" style="max-width:50px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
- }
- return $str;
- }elseif ($res[0]['MsgType']=="TIMFileElem"){
- //文件消息
- }elseif ($res[0]['MsgType']=="TIMVideoFileElem"){
- //视频消息
- $str = "<video src='".$res[0]['MsgContent']['VideoUrl']."' style='width:200px;height:200px;margin-right:10px' controls='controls'></video>";
- return $str;
- }
- });
- $grid->quickSearch(['user_id', 'nickname']);
- $grid->paginate(10);
- $grid->disableActions();
- $grid->filter(function (Grid\Filter $filter) {
- // $filter->like('nickname','昵称')->width(4);
- });
- });
- }
- }
|