fix(idiom): split display - winner sees in private, others in public
This commit is contained in:
@@ -197,7 +197,7 @@ class IdiomQuizController extends Controller
|
|||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 广播结果
|
// 广播结果(前端通过 IdiomGameAnswered 事件做分屏显示)
|
||||||
broadcast(new IdiomGameAnswered(
|
broadcast(new IdiomGameAnswered(
|
||||||
roomId: $roomId,
|
roomId: $roomId,
|
||||||
roundId: $round->id,
|
roundId: $round->id,
|
||||||
@@ -207,7 +207,7 @@ class IdiomQuizController extends Controller
|
|||||||
rewardExp: $round->reward_exp,
|
rewardExp: $round->reward_exp,
|
||||||
));
|
));
|
||||||
|
|
||||||
// 推 MessageSent 系统通知
|
// 存聊天记录(不广播,避免重复显示)
|
||||||
$resultMsg = [
|
$resultMsg = [
|
||||||
'id' => $this->chatState->nextMessageId($roomId),
|
'id' => $this->chatState->nextMessageId($roomId),
|
||||||
'room_id' => $roomId,
|
'room_id' => $roomId,
|
||||||
@@ -220,7 +220,6 @@ class IdiomQuizController extends Controller
|
|||||||
'sent_at' => now()->toDateTimeString(),
|
'sent_at' => now()->toDateTimeString(),
|
||||||
];
|
];
|
||||||
$this->chatState->pushMessage($roomId, $resultMsg);
|
$this->chatState->pushMessage($roomId, $resultMsg);
|
||||||
broadcast(new \App\Events\MessageSent($roomId, $resultMsg));
|
|
||||||
|
|
||||||
\Illuminate\Support\Facades\Redis::del($lockKey);
|
\Illuminate\Support\Facades\Redis::del($lockKey);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ function handleIdiomGameAnswered(e) {
|
|||||||
answerModal.style.display = "none";
|
answerModal.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 全局文字提示:在聊天窗口中追加结果消息 ──
|
// ── 分屏文字提示 ──
|
||||||
|
// 回答者 → 包厢(chat-messages-container2)
|
||||||
|
// 其他人 → 公屏(chat-messages-container)
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const timeStr = now.getHours().toString().padStart(2, "0") + ":" +
|
const timeStr = now.getHours().toString().padStart(2, "0") + ":" +
|
||||||
now.getMinutes().toString().padStart(2, "0") + ":" +
|
now.getMinutes().toString().padStart(2, "0") + ":" +
|
||||||
@@ -48,13 +50,24 @@ function handleIdiomGameAnswered(e) {
|
|||||||
div.className = "msg-line";
|
div.className = "msg-line";
|
||||||
div.innerHTML = `<span style="color:#16a34a;font-weight:bold;">🎉 恭喜 <b>${winner_username}</b> 率先答对成语「${answer}」,获得 ${reward_gold} 金币、${reward_exp} 经验!</span><span class="msg-time">(${timeStr})</span>`;
|
div.innerHTML = `<span style="color:#16a34a;font-weight:bold;">🎉 恭喜 <b>${winner_username}</b> 率先答对成语「${answer}」,获得 ${reward_gold} 金币、${reward_exp} 经验!</span><span class="msg-time">(${timeStr})</span>`;
|
||||||
|
|
||||||
|
const isWinner = winner_username === (window.chatContext?.username || "");
|
||||||
|
if (isWinner) {
|
||||||
|
// 回答者 → 包厢
|
||||||
|
const say2 = document.getElementById("chat-messages-container2");
|
||||||
|
if (say2) {
|
||||||
|
say2.appendChild(div.cloneNode(true));
|
||||||
|
say2.scrollTop = say2.scrollHeight;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他人 → 公屏
|
||||||
const say1 = document.getElementById("chat-messages-container");
|
const say1 = document.getElementById("chat-messages-container");
|
||||||
if (say1) {
|
if (say1) {
|
||||||
say1.appendChild(div);
|
say1.appendChild(div);
|
||||||
say1.scrollTop = say1.scrollHeight;
|
say1.scrollTop = say1.scrollHeight;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Toast 通知(所有在线用户都能看到) ──
|
// ── Toast 通知(所有用户都能看到) ──
|
||||||
window.chatToast?.show({
|
window.chatToast?.show({
|
||||||
title: "🧩 猜成语",
|
title: "🧩 猜成语",
|
||||||
message: `<b>${winner_username}</b> 答对了「${answer}」,获得 ${reward_gold}💰 + ${reward_exp}⭐!`,
|
message: `<b>${winner_username}</b> 答对了「${answer}」,获得 ${reward_gold}💰 + ${reward_exp}⭐!`,
|
||||||
|
|||||||
Reference in New Issue
Block a user