feat(idiom): global toast + chat message on answer result
This commit is contained in:
@@ -27,23 +27,41 @@ function handleIdiomGameStarted(e) {
|
|||||||
* 收到猜成语结果事件。
|
* 收到猜成语结果事件。
|
||||||
*/
|
*/
|
||||||
function handleIdiomGameAnswered(e) {
|
function handleIdiomGameAnswered(e) {
|
||||||
const { answer, winner_username, reward_gold, reward_exp } = e.detail || {};
|
const { answer, winner_username, reward_gold, reward_exp, round_id } = e.detail || {};
|
||||||
if (!answer) return;
|
if (!answer) return;
|
||||||
|
|
||||||
currentRoundId = 0;
|
currentRoundId = 0;
|
||||||
|
|
||||||
// 如果当前用户打开答题弹窗但被别人抢先了,关闭弹窗
|
// 关闭当前用户的答题弹窗(如果开着的话)
|
||||||
const answerModal = document.getElementById("idiom-answer-modal");
|
const answerModal = document.getElementById("idiom-answer-modal");
|
||||||
if (answerModal && answerModal.style.display !== "none") {
|
if (answerModal && answerModal.style.display !== "none") {
|
||||||
answerModal.style.display = "none";
|
answerModal.style.display = "none";
|
||||||
window.chatToast?.show({
|
|
||||||
title: "被抢先了",
|
|
||||||
message: `${winner_username} 率先答对了「${answer}」,下次加油!`,
|
|
||||||
icon: "😅",
|
|
||||||
color: "#f59e0b",
|
|
||||||
duration: 4000,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 全局文字提示:在聊天窗口中追加结果消息 ──
|
||||||
|
const now = new Date();
|
||||||
|
const timeStr = now.getHours().toString().padStart(2, "0") + ":" +
|
||||||
|
now.getMinutes().toString().padStart(2, "0") + ":" +
|
||||||
|
now.getSeconds().toString().padStart(2, "0");
|
||||||
|
|
||||||
|
const div = document.createElement("div");
|
||||||
|
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>`;
|
||||||
|
|
||||||
|
const say1 = document.getElementById("chat-messages-container");
|
||||||
|
if (say1) {
|
||||||
|
say1.appendChild(div);
|
||||||
|
say1.scrollTop = say1.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Toast 通知(所有在线用户都能看到) ──
|
||||||
|
window.chatToast?.show({
|
||||||
|
title: "🧩 猜成语",
|
||||||
|
message: `<b>${winner_username}</b> 答对了「${answer}」,获得 ${reward_gold}💰 + ${reward_exp}⭐!`,
|
||||||
|
icon: "🎉",
|
||||||
|
color: "#16a34a",
|
||||||
|
duration: 6000,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user