Commit 422bdede authored by 陈冲's avatar 陈冲

fix: 提示更新

parent 254f0527
import SHA256 from 'crypto-js/sha256' import SHA256 from 'crypto-js/sha256'
type StorageRecord = Record<string, unknown>; type StorageRecord = Record<string, unknown>;
type ToastLine = string | { text: string; bold?: boolean };
function isStorageRecord(value: unknown): value is StorageRecord { function isStorageRecord(value: unknown): value is StorageRecord {
return Object.prototype.toString.call(value) === '[object Object]'; return Object.prototype.toString.call(value) === '[object Object]';
...@@ -80,8 +81,8 @@ export function $hideToast() { ...@@ -80,8 +81,8 @@ export function $hideToast() {
toastElement.style.transform = 'translate(-50%, -40%)'; toastElement.style.transform = 'translate(-50%, -40%)';
} }
export function $toast(message?: string, duration = 2000) { export function $toast(message?: string | ToastLine[], duration = 2000) {
if (!message) { if (!message || (Array.isArray(message) && message.length === 0)) {
return; return;
} }
...@@ -92,14 +93,15 @@ export function $toast(message?: string, duration = 2000) { ...@@ -92,14 +93,15 @@ export function $toast(message?: string, duration = 2000) {
'left: 50%', 'left: 50%',
'top: 45%', 'top: 45%',
'z-index: 99999', 'z-index: 99999',
'max-width: 560px', 'max-width: 680px',
'padding: 18px 28px', 'padding: 28px 40px',
'border-radius: 18px', 'border-radius: 18px',
'background: rgba(0, 0, 0, 0.72)', 'background: rgba(0, 0, 0, 0.72)',
'color: #fff', 'color: #fff',
'font-size: 16px', 'font-size: 26px',
'line-height: 1.4', 'line-height: 1.65',
'text-align: center', 'text-align: center',
'white-space: pre-line',
'transform: translate(-50%, -40%)', 'transform: translate(-50%, -40%)',
'opacity: 0', 'opacity: 0',
'pointer-events: none', 'pointer-events: none',
...@@ -113,7 +115,20 @@ export function $toast(message?: string, duration = 2000) { ...@@ -113,7 +115,20 @@ export function $toast(message?: string, duration = 2000) {
toastTimer = undefined; toastTimer = undefined;
} }
if (Array.isArray(message)) {
toastElement.textContent = '';
for (const line of message) {
const lineElement = document.createElement('div');
const text = typeof line === 'string' ? line : line.text;
lineElement.textContent = text;
if (typeof line !== 'string' && line.bold) {
lineElement.style.fontWeight = '700';
}
toastElement.appendChild(lineElement);
}
} else {
toastElement.textContent = message; toastElement.textContent = message;
}
toastElement.style.opacity = '1'; toastElement.style.opacity = '1';
toastElement.style.transform = 'translate(-50%, -50%)'; toastElement.style.transform = 'translate(-50%, -50%)';
...@@ -128,6 +143,21 @@ export function $toast(message?: string, duration = 2000) { ...@@ -128,6 +143,21 @@ export function $toast(message?: string, duration = 2000) {
}, duration); }, duration);
} }
export function $scoreSubmitFailedToast(duration = 10 * 60 * 1000) {
$toast([
'网络异常,分数提交失败',
'请以大屏游戏结果排行为准。',
], duration);
}
export function $alreadyRankedToast(duration = 10 * 60 * 1000) {
$toast([
{ text: '一人只能上榜领奖一次', bold: true },
'您的福利已到手',
'把机会留给其他玩家吧',
], duration);
}
type ConfirmOptions = { type ConfirmOptions = {
title?: string; title?: string;
message?: string; message?: string;
......
...@@ -2,7 +2,7 @@ import { ref } from 'vue' ...@@ -2,7 +2,7 @@ import { ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import type { Socket } from 'socket.io-client' import type { Socket } from 'socket.io-client'
import { initSocket, onSocketMessage, sendSocketMessage } from '@/commons/ws' import { initSocket, onSocketMessage, sendSocketMessage } from '@/commons/ws'
import { $getWechat, $hideToast, $read, $save, $toast, postScreenGameScore } from '@/commons/utils' import { $alreadyRankedToast, $getWechat, $hideToast, $read, $save, $scoreSubmitFailedToast, $toast, postScreenGameScore } from '@/commons/utils'
type SocketPayload = { type SocketPayload = {
msg?: string msg?: string
...@@ -66,7 +66,7 @@ const networkDisconnectToastDuration = 30 * 60 * 1000; ...@@ -66,7 +66,7 @@ const networkDisconnectToastDuration = 30 * 60 * 1000;
export function sendGameMessage(cmd: string, data: any = {}) { export function sendGameMessage(cmd: string, data: any = {}) {
const sent = sendSocketMessage(cmd, data) const sent = sendSocketMessage(cmd, data)
if (!sent && cmd === 'submit_score_save') { if (!sent && cmd === 'submit_score_save') {
$toast('网络不好,分数无法提交', networkDisconnectToastDuration) $scoreSubmitFailedToast(networkDisconnectToastDuration)
} }
return sent return sent
} }
......
...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, userTop10RankStatus, jo ...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, userTop10RankStatus, jo
import LoadingView from './views/LoadingView.vue' import LoadingView from './views/LoadingView.vue'
import PlayingView from './views/PlayingView.vue' import PlayingView from './views/PlayingView.vue'
import ScoreView from './views/ScoreView.vue' import ScoreView from './views/ScoreView.vue'
import { $getWechat, $toast } from '@/commons/utils.ts' import { $alreadyRankedToast, $getWechat, $toast } from '@/commons/utils.ts'
import { playGame1Music, stopAllMusic } from '@/commons/music' import { playGame1Music, stopAllMusic } from '@/commons/music'
type GameView = 'loading' | 'playing' | 'score' type GameView = 'loading' | 'playing' | 'score'
...@@ -119,11 +119,6 @@ function submitScore(save: boolean = false, currentTick = tick.value) { ...@@ -119,11 +119,6 @@ function submitScore(save: boolean = false, currentTick = tick.value) {
avatar: wechat.avatar, avatar: wechat.avatar,
rank: rank.value, rank: rank.value,
}) })
if (sent && !userTop10RankStatus.value) {
window.setTimeout(() => {
$toast('成绩提交中,请稍候...', 5000)
}, 0)
}
return sent return sent
} else { } else {
return sendGameMessage('submit_score', { score: currentTick }) return sendGameMessage('submit_score', { score: currentTick })
...@@ -144,10 +139,12 @@ function startGameCountdown(seconds = 60) { ...@@ -144,10 +139,12 @@ function startGameCountdown(seconds = 60) {
setDivDescVisible(false) setDivDescVisible(false)
isGameEnded.value = true isGameEnded.value = true
hasFinalScoreResult.value = false hasFinalScoreResult.value = false
submitScore(true) const sent = submitScore(true)
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
userJoinStatus.value = false userJoinStatus.value = false
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
} else if (sent) {
$toast('成绩提交中,请稍候...', 5000)
} }
return return
} }
...@@ -206,7 +203,7 @@ function showScoreView() { ...@@ -206,7 +203,7 @@ function showScoreView() {
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
currentView.value = 'loading' currentView.value = 'loading'
userJoinStatus.value = false; userJoinStatus.value = false;
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
} else { } else {
currentView.value = 'score' currentView.value = 'score'
} }
......
...@@ -30,7 +30,7 @@ function handleTouch() { ...@@ -30,7 +30,7 @@ function handleTouch() {
</Transition> </Transition>
<div class="img-logo"></div> <div class="img-logo"></div>
<div class="play-content"> <div class="play-content">
<div>当前击鼓积分</div> <div>积分</div>
<div>{{ tick }}</div> <div>{{ tick }}</div>
<!-- <div v-if="!userTop10RankStatus">当前排名: &nbsp;&nbsp;<label></label>&nbsp;</div> --> <!-- <div v-if="!userTop10RankStatus">当前排名: &nbsp;&nbsp;<label></label>&nbsp;</div> -->
</div> </div>
......
...@@ -31,7 +31,7 @@ onMounted(() => { ...@@ -31,7 +31,7 @@ onMounted(() => {
<div class="score-content"> <div class="score-content">
<div>{{ nickname }}</div> <div>{{ nickname }}</div>
<div>您的成绩</div> <div>您的成绩</div>
<div>击鼓积分</div> <div>积分</div>
<div>{{ tick }}</div> <div>{{ tick }}</div>
<div>最终排名</div> <div>最终排名</div>
<div v-if="rank>0"><label>{{ rank }}</label></div> <div v-if="rank>0"><label>{{ rank }}</label></div>
......
...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, userTop10RankStatus, jo ...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, userTop10RankStatus, jo
import LoadingView from './views/LoadingView.vue' import LoadingView from './views/LoadingView.vue'
import PlayingView from './views/PlayingView.vue' import PlayingView from './views/PlayingView.vue'
import ScoreView from './views/ScoreView.vue' import ScoreView from './views/ScoreView.vue'
import { $format_str, $getWechat, $toast } from '@/commons/utils.ts' import { $alreadyRankedToast, $format_str, $getWechat, $toast } from '@/commons/utils.ts'
import { playGame2Music, stopAllMusic } from '@/commons/music'; import { playGame2Music, stopAllMusic } from '@/commons/music';
type GameView = 'loading' | 'playing' | 'score' type GameView = 'loading' | 'playing' | 'score'
...@@ -156,11 +156,6 @@ function submitScore(save: boolean = false, currentTick = score.value) { ...@@ -156,11 +156,6 @@ function submitScore(save: boolean = false, currentTick = score.value) {
avatar: wechat.avatar, avatar: wechat.avatar,
rank: rank.value, rank: rank.value,
}) })
if (sent && !userTop10RankStatus.value) {
window.setTimeout(() => {
$toast('成绩提交中,请稍候...', 5000)
}, 0)
}
return sent return sent
} else { } else {
return sendGameMessage('submit_score', { score: currentTick }) return sendGameMessage('submit_score', { score: currentTick })
...@@ -181,13 +176,13 @@ function startGameCountdown(seconds = 60) { ...@@ -181,13 +176,13 @@ function startGameCountdown(seconds = 60) {
setDivDescVisible(false) setDivDescVisible(false)
isGameEnded.value = true isGameEnded.value = true
hasFinalScoreResult.value = false hasFinalScoreResult.value = false
submitScore(true) const sent = submitScore(true)
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
userJoinStatus.value = false; userJoinStatus.value = false;
showGameRank.value = false; showGameRank.value = false;
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
//这里还要再发 //这里还要再发
} else { } else if (sent) {
$toast('成绩提交中,请稍候...', 5000) $toast('成绩提交中,请稍候...', 5000)
} }
return return
......
...@@ -31,7 +31,7 @@ onMounted(() => { ...@@ -31,7 +31,7 @@ onMounted(() => {
<div class="score-content"> <div class="score-content">
<div>{{ nickname }}</div> <div>{{ nickname }}</div>
<div>您的成绩</div> <div>您的成绩</div>
<div>击鼓积分</div> <div>积分</div>
<div>{{ tick }}</div> <div>{{ tick }}</div>
<div>最终排名</div> <div>最终排名</div>
<div v-if="rank>0"><label>{{ rank }}</label></div> <div v-if="rank>0"><label>{{ rank }}</label></div>
......
...@@ -6,7 +6,7 @@ import { useGameSocket, joinSharedRoom, sendGameMessage, userJoinStatus, userTop ...@@ -6,7 +6,7 @@ import { useGameSocket, joinSharedRoom, sendGameMessage, userJoinStatus, userTop
import LoadingView from './views/LoadingView.vue' import LoadingView from './views/LoadingView.vue'
import PlayingView from './views/PlayingView.vue' import PlayingView from './views/PlayingView.vue'
import ScoreView from './views/ScoreView.vue' import ScoreView from './views/ScoreView.vue'
import { $getWechat, $toast, $is_run_local } from '@/commons/utils.ts' import { $alreadyRankedToast, $getWechat, $toast, $is_run_local } from '@/commons/utils.ts'
import { playGame3Music, stopAllMusic } from '@/commons/music'; import { playGame3Music, stopAllMusic } from '@/commons/music';
type GameView = 'loading' | 'playing' | 'score' type GameView = 'loading' | 'playing' | 'score'
...@@ -169,11 +169,6 @@ function submitScore(save: boolean = false, currentTick = score.value) { ...@@ -169,11 +169,6 @@ function submitScore(save: boolean = false, currentTick = score.value) {
avatar: wechat.avatar, avatar: wechat.avatar,
rank: rank.value, rank: rank.value,
}) })
if (sent && !userTop10RankStatus.value) {
window.setTimeout(() => {
$toast('成绩提交中,请稍候...', 5000)
}, 0)
}
return sent return sent
} else { } else {
if (isLocalMode && !wechat) { if (isLocalMode && !wechat) {
...@@ -197,12 +192,12 @@ function startGameCountdown(seconds = 60) { ...@@ -197,12 +192,12 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = undefined gameCountdownTimer = undefined
setDivDescVisible(false) setDivDescVisible(false)
hasFinalScoreResult.value = false hasFinalScoreResult.value = false
submitScore(true) const sent = submitScore(true)
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
userJoinStatus.value = false; userJoinStatus.value = false;
showGameRank.value = false; showGameRank.value = false;
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
} else { } else if (sent) {
$toast('成绩提交中,请稍候...', 5000) $toast('成绩提交中,请稍候...', 5000)
} }
return return
......
...@@ -32,7 +32,7 @@ onMounted(() => { ...@@ -32,7 +32,7 @@ onMounted(() => {
<div class="score-content"> <div class="score-content">
<div>{{ nickname }}</div> <div>{{ nickname }}</div>
<div>您的成绩</div> <div>您的成绩</div>
<div>当前积分</div> <div>积分</div>
<div>{{ tick }}</div> <div>{{ tick }}</div>
<div>最终排名</div> <div>最终排名</div>
<div v-if="rank>0"><label>{{ rank }}</label></div> <div v-if="rank>0"><label>{{ rank }}</label></div>
......
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
import LoadingView from "./views/LoadingView.vue"; import LoadingView from "./views/LoadingView.vue";
import PlayingView from "./views/PlayingView.vue"; import PlayingView from "./views/PlayingView.vue";
import ScoreView from "./views/ScoreView.vue"; import ScoreView from "./views/ScoreView.vue";
import { $getWechat, $toast, $is_run_local } from "@/commons/utils.ts"; import { $alreadyRankedToast, $getWechat, $toast, $is_run_local } from "@/commons/utils.ts";
const gameId = "game4"; const gameId = "game4";
type GameView = "loading" | "playing" | "score"; type GameView = "loading" | "playing" | "score";
...@@ -163,12 +163,12 @@ function startGameCountdown(seconds = 60) { ...@@ -163,12 +163,12 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = undefined; gameCountdownTimer = undefined;
setDivDescVisible(false); setDivDescVisible(false);
isGameEnded.value = true; isGameEnded.value = true;
submitScore(true); const sent = submitScore(true);
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
userJoinStatus.value = false; userJoinStatus.value = false;
// showGameRank.value = false; // showGameRank.value = false;
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
} else { } else if (sent) {
$toast('成绩提交中,请稍候...', 5000) $toast('成绩提交中,请稍候...', 5000)
} }
return; return;
......
...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, joinSharedRoom, userTop ...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, joinSharedRoom, userTop
import LoadingView from './views/LoadingView.vue' import LoadingView from './views/LoadingView.vue'
import PlayingView from './views/PlayingView.vue' import PlayingView from './views/PlayingView.vue'
import ScoreView from './views/ScoreView.vue' import ScoreView from './views/ScoreView.vue'
import { $getWechat, $toast } from '@/commons/utils.ts' import { $alreadyRankedToast, $getWechat, $toast } from '@/commons/utils.ts'
import { playGame1Music } from '@/commons/music' import { playGame1Music } from '@/commons/music'
const gameId = 'game5'; const gameId = 'game5';
...@@ -216,12 +216,12 @@ function startGameCountdown(seconds = 60) { ...@@ -216,12 +216,12 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = undefined gameCountdownTimer = undefined
setDivDescVisible(false) setDivDescVisible(false)
hasFinalScoreResult.value = false hasFinalScoreResult.value = false
submitScore(true) const sent = submitScore(true)
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
userJoinStatus.value = false; userJoinStatus.value = false;
// showGameRank.value = false; // showGameRank.value = false;
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
} else { } else if (sent) {
$toast('成绩提交中,请稍候...', 5000) $toast('成绩提交中,请稍候...', 5000)
} }
return return
......
...@@ -413,7 +413,7 @@ onBeforeUnmount(() => { ...@@ -413,7 +413,7 @@ onBeforeUnmount(() => {
<div class="txt-bold"></div> <div class="txt-bold"></div>
</div> </div>
<div class="txt-right"> <div class="txt-right">
<div>实时积分</div> <div>积分</div>
<div class="txt-bold">{{ tick }}</div> <div class="txt-bold">{{ tick }}</div>
</div> --> </div> -->
</div> </div>
......
...@@ -31,7 +31,7 @@ onMounted(() => { ...@@ -31,7 +31,7 @@ onMounted(() => {
<div class="score-content"> <div class="score-content">
<div>{{ nickname }}</div> <div>{{ nickname }}</div>
<div>您的成绩</div> <div>您的成绩</div>
<div>击鼓积分</div> <div>积分</div>
<div>{{ tick }}</div> <div>{{ tick }}</div>
<div>最终排名</div> <div>最终排名</div>
<div v-if="rank>0"><label>{{ rank }}</label></div> <div v-if="rank>0"><label>{{ rank }}</label></div>
......
...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, userTop10RankStatus, jo ...@@ -6,7 +6,7 @@ import { useGameSocket, sendGameMessage, userJoinStatus, userTop10RankStatus, jo
import LoadingView from './views/LoadingView.vue' import LoadingView from './views/LoadingView.vue'
import PlayingView from './views/PlayingView.vue' import PlayingView from './views/PlayingView.vue'
import ScoreView from './views/ScoreView.vue' import ScoreView from './views/ScoreView.vue'
import { $format_str, $getWechat, $toast } from '@/commons/utils.ts' import { $alreadyRankedToast, $format_str, $getWechat, $toast } from '@/commons/utils.ts'
import { playGame6Music, stopAllMusic } from '@/commons/music'; import { playGame6Music, stopAllMusic } from '@/commons/music';
type GameView = 'loading' | 'playing' | 'score' type GameView = 'loading' | 'playing' | 'score'
...@@ -163,11 +163,6 @@ function submitScore(save: boolean = false, currentTick = score.value) { ...@@ -163,11 +163,6 @@ function submitScore(save: boolean = false, currentTick = score.value) {
avatar: wechat.avatar, avatar: wechat.avatar,
rank: rank.value, rank: rank.value,
}) })
if (sent && !userTop10RankStatus.value) {
window.setTimeout(() => {
$toast('成绩提交中,请稍候...', 5000)
}, 0)
}
return sent return sent
} else { } else {
return sendGameMessage('submit_score', { score: currentTick }) return sendGameMessage('submit_score', { score: currentTick })
...@@ -188,12 +183,12 @@ function startGameCountdown(seconds = 60) { ...@@ -188,12 +183,12 @@ function startGameCountdown(seconds = 60) {
setDivDescVisible(false) setDivDescVisible(false)
isGameEnded.value = true isGameEnded.value = true
hasFinalScoreResult.value = false hasFinalScoreResult.value = false
submitScore(true) const sent = submitScore(true)
if (userTop10RankStatus.value) { if (userTop10RankStatus.value) {
userJoinStatus.value = false; userJoinStatus.value = false;
showGameRank.value = false; showGameRank.value = false;
$toast('一人只能上榜领奖一次,您的福利已到手,把机会留给其他玩家吧', 30000) $alreadyRankedToast()
} else { } else if (sent) {
$toast('成绩提交中,请稍候...', 5000) $toast('成绩提交中,请稍候...', 5000)
} }
return return
......
...@@ -31,7 +31,7 @@ onMounted(() => { ...@@ -31,7 +31,7 @@ onMounted(() => {
<div class="score-content"> <div class="score-content">
<div>{{ nickname }}</div> <div>{{ nickname }}</div>
<div>您的成绩</div> <div>您的成绩</div>
<div>击鼓积分</div> <div>积分</div>
<div>{{ tick }}</div> <div>{{ tick }}</div>
<div>最终排名</div> <div>最终排名</div>
<div v-if="rank>0"><label>{{ rank }}</label></div> <div v-if="rank>0"><label>{{ rank }}</label></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment