美化:私聊查看页面从原始 JSON 改为美观的 HTML 页面
- 新增 admin/whispers.blade.php 暗色主题聊天气泡样式 - 控制器支持 JSON(弹窗用)和 HTML(新窗口用)双模式 - 区分发出/收到方向,显示时间和消息数量
This commit is contained in:
@@ -254,17 +254,21 @@ class AdminCommandController extends Controller
|
||||
* 查看用户私信(=S)
|
||||
*
|
||||
* 管理员查看指定用户最近的悄悄话记录。
|
||||
* AJAX 请求返回 JSON,浏览器请求返回美观的 HTML 页面。
|
||||
*
|
||||
* @param string $username 目标用户名
|
||||
* @return JsonResponse 私信记录列表
|
||||
* @return JsonResponse|\Illuminate\View\View 私信记录
|
||||
*/
|
||||
public function viewWhispers(string $username): JsonResponse
|
||||
public function viewWhispers(Request $request, string $username): JsonResponse|\Illuminate\View\View
|
||||
{
|
||||
$admin = Auth::user();
|
||||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||||
|
||||
if ($admin->user_level < $superLevel) {
|
||||
return response()->json(['status' => 'error', 'message' => '仅站长可查看私信'], 403);
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['status' => 'error', 'message' => '仅站长可查看私信'], 403);
|
||||
}
|
||||
abort(403, '仅站长可查看私信');
|
||||
}
|
||||
|
||||
// 查询最近 50 条悄悄话(发送或接收)
|
||||
@@ -277,8 +281,16 @@ class AdminCommandController extends Controller
|
||||
->limit(50)
|
||||
->get(['id', 'from_user', 'to_user', 'content', 'sent_at']);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
// AJAX 请求返回 JSON(给名片弹窗用),浏览器请求返回 HTML 页面
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'username' => $username,
|
||||
'messages' => $messages,
|
||||
]);
|
||||
}
|
||||
|
||||
return view('admin.whispers', [
|
||||
'username' => $username,
|
||||
'messages' => $messages,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user