Commit d02a4348 authored by 陈冲's avatar 陈冲

fix: 修复h5端倒计时等问题

parent 7405af15
...@@ -19,9 +19,7 @@ const imageUrls = { ...@@ -19,9 +19,7 @@ const imageUrls = {
avatar: cssAssetUrl('avatar-yellow.png'), avatar: cssAssetUrl('avatar-yellow.png'),
gu: cssAssetUrl('game1/gu.png'), gu: cssAssetUrl('game1/gu.png'),
clock: cssAssetUrl('game1/clock.png'), clock: cssAssetUrl('game1/clock.png'),
gu01: cssAssetUrl('game1/gu01.png'), guSprite: cssAssetUrl('game1/gu-sprite.png'),
gu02: cssAssetUrl('game1/gu02.png'),
gu03: cssAssetUrl('game1/gu03.png'),
scoreBg: cssAssetUrl('game1/score-bg.png'), scoreBg: cssAssetUrl('game1/score-bg.png'),
back: cssAssetUrl('game1/back.png'), back: cssAssetUrl('game1/back.png'),
replay: cssAssetUrl('game1/replay.png'), replay: cssAssetUrl('game1/replay.png'),
...@@ -36,8 +34,7 @@ const countdownInterval = ref(60) ...@@ -36,8 +34,7 @@ const countdownInterval = ref(60)
const isDivDescVisible = ref(false) const isDivDescVisible = ref(false)
const tick = ref(0) //点击次数 const tick = ref(0) //点击次数
const rank = ref(0) //排名 const rank = ref(0) //排名
const guFrames: [string, string, string] = [imageUrls.gu01, imageUrls.gu02, imageUrls.gu03] const currentGuFrame = ref(0)
const currentGu = ref(imageUrls.gu01)
const isGuPlaying = ref(false) const isGuPlaying = ref(false)
const token = ref(wechat?.token ?? '') const token = ref(wechat?.token ?? '')
const nickname = ref(wechat?.nickname ?? '') const nickname = ref(wechat?.nickname ?? '')
...@@ -106,6 +103,18 @@ function startGameCountdown(seconds = 60) { ...@@ -106,6 +103,18 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = window.setTimeout(tickCountdown, 1000) gameCountdownTimer = window.setTimeout(tickCountdown, 1000)
} }
function syncGameCountdown(seconds: number) {
const syncedSeconds = Math.max(0, Math.floor(seconds))
if (countdownInterval.value - syncedSeconds <= 1) return
if (syncedSeconds === 0) {
countdownInterval.value = 0
return
}
startGameCountdown(syncedSeconds)
}
function resetToLoadingView() { function resetToLoadingView() {
stopGameCountdown() stopGameCountdown()
if (guFrameTimer) { if (guFrameTimer) {
...@@ -115,7 +124,7 @@ function resetToLoadingView() { ...@@ -115,7 +124,7 @@ function resetToLoadingView() {
tick.value = 0 tick.value = 0
rank.value = 0 rank.value = 0
countdownInterval.value = 60 countdownInterval.value = 60
currentGu.value = guFrames[0] currentGuFrame.value = 0
isGuPlaying.value = false isGuPlaying.value = false
userJoinStatus.value = false userJoinStatus.value = false
currentView.value = 'loading' currentView.value = 'loading'
...@@ -125,7 +134,7 @@ function resetToLoadingView() { ...@@ -125,7 +134,7 @@ function resetToLoadingView() {
function startGameView() { function startGameView() {
stopGameCountdown() stopGameCountdown()
tick.value = 0 tick.value = 0
currentGu.value = guFrames[0] currentGuFrame.value = 0
currentView.value = 'playing' currentView.value = 'playing'
startGameCountdown() startGameCountdown()
} }
...@@ -149,12 +158,12 @@ const touchHandler = () => { ...@@ -149,12 +158,12 @@ const touchHandler = () => {
let frameIndex = 0 let frameIndex = 0
const playNextFrame = () => { const playNextFrame = () => {
currentGu.value = guFrames[frameIndex] ?? imageUrls.gu01 currentGuFrame.value = frameIndex
frameIndex += 1 frameIndex += 1
if (frameIndex >= guFrames.length) { if (frameIndex >= 3) {
guFrameTimer = window.setTimeout(() => { guFrameTimer = window.setTimeout(() => {
currentGu.value = guFrames[0] currentGuFrame.value = 0
isGuPlaying.value = false isGuPlaying.value = false
guFrameTimer = undefined guFrameTimer = undefined
}, 200) }, 200)
...@@ -200,7 +209,7 @@ if (wechat) { ...@@ -200,7 +209,7 @@ if (wechat) {
rank.value = nextRank rank.value = nextRank
} }
if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) { if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) {
countdownInterval.value = remainingSeconds syncGameCountdown(remainingSeconds)
} }
} }
return { code: 'JGQF', score: tick.value } return { code: 'JGQF', score: tick.value }
...@@ -280,7 +289,7 @@ const showGameRuleHandler = () => { ...@@ -280,7 +289,7 @@ const showGameRuleHandler = () => {
<LoadingView v-if="currentView === 'loading'" :image-urls="imageUrls" :user-join-status="userJoinStatus" <LoadingView v-if="currentView === 'loading'" :image-urls="imageUrls" :user-join-status="userJoinStatus"
@touchGameRule="showGameRuleHandler" /> @touchGameRule="showGameRuleHandler" />
<PlayingView v-else-if="currentView === 'playing'" :image-urls="imageUrls" :tick="tick" :rank="rank" <PlayingView v-else-if="currentView === 'playing'" :image-urls="imageUrls" :tick="tick" :rank="rank"
:current-gu="currentGu" :countdown-interval="countdownInterval" :is-div-desc-visible="isDivDescVisible" :current-gu-frame="currentGuFrame" :countdown-interval="countdownInterval" :is-div-desc-visible="isDivDescVisible"
@touch="touchHandler" /> @touch="touchHandler" />
<ScoreView v-else :image-urls="imageUrls" :rank="rank" :tick="tick" /> <ScoreView v-else :image-urls="imageUrls" :rank="rank" :tick="tick" />
</MobileStage> </MobileStage>
......
...@@ -5,7 +5,7 @@ defineProps<{ ...@@ -5,7 +5,7 @@ defineProps<{
isDivDescVisible: boolean isDivDescVisible: boolean
tick: number tick: number
rank: number rank: number
currentGu: string currentGuFrame: number
}>() }>()
defineEmits<{ defineEmits<{
...@@ -28,7 +28,7 @@ defineEmits<{ ...@@ -28,7 +28,7 @@ defineEmits<{
<div>当前排名: &nbsp;&nbsp;<label>{{ rank }}</label>&nbsp;</div> <div>当前排名: &nbsp;&nbsp;<label>{{ rank }}</label>&nbsp;</div>
</div> </div>
<div class="bg-bottom"></div> <div class="bg-bottom"></div>
<div class="play-gu" :style="{ background: `${currentGu} center/cover` }" @click="$emit('touch')"></div> <div class="play-gu" :style="{ backgroundPosition: `-${currentGuFrame * 400}px 0` }" @click="$emit('touch')"></div>
</div> </div>
</template> </template>
...@@ -159,6 +159,9 @@ defineEmits<{ ...@@ -159,6 +159,9 @@ defineEmits<{
left: 50%; left: 50%;
width: 400px; width: 400px;
height: 400px; height: 400px;
background-image: v-bind('imageUrls.guSprite');
background-size: 1200px 400px;
background-repeat: no-repeat;
transform: translateX(-50%) scale(2.4); transform: translateX(-50%) scale(2.4);
} }
</style> </style>
...@@ -128,6 +128,18 @@ function startGameCountdown(seconds = 60) { ...@@ -128,6 +128,18 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = window.setTimeout(tickCountdown, 1000) gameCountdownTimer = window.setTimeout(tickCountdown, 1000)
} }
function syncGameCountdown(seconds: number) {
const syncedSeconds = Math.max(0, Math.floor(seconds))
if (countdownInterval.value - syncedSeconds <= 1) return
if (syncedSeconds === 0) {
countdownInterval.value = 0
return
}
startGameCountdown(syncedSeconds)
}
function resetToLoadingView() { function resetToLoadingView() {
stopGameCountdown() stopGameCountdown()
if (guFrameTimer) { if (guFrameTimer) {
...@@ -206,7 +218,7 @@ if (wechat) { ...@@ -206,7 +218,7 @@ if (wechat) {
rank.value = nextRank rank.value = nextRank
} }
if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) { if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) {
countdownInterval.value = remainingSeconds syncGameCountdown(remainingSeconds)
} }
} else if (typeof data === 'object' && data) { } else if (typeof data === 'object' && data) {
if (Array.isArray(data.list)) { if (Array.isArray(data.list)) {
......
...@@ -118,6 +118,18 @@ function startGameCountdown(seconds = 60) { ...@@ -118,6 +118,18 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = window.setTimeout(tickCountdown, 1000) gameCountdownTimer = window.setTimeout(tickCountdown, 1000)
} }
function syncGameCountdown(seconds: number) {
const syncedSeconds = Math.max(0, Math.floor(seconds))
if (countdownInterval.value - syncedSeconds <= 1) return
if (syncedSeconds === 0) {
countdownInterval.value = 0
return
}
startGameCountdown(syncedSeconds)
}
function showLoadingView() { function showLoadingView() {
stopGameCountdown() stopGameCountdown()
currentView.value = 'loading' currentView.value = 'loading'
...@@ -197,7 +209,7 @@ if (wechat) { ...@@ -197,7 +209,7 @@ if (wechat) {
tick.value = nextScore tick.value = nextScore
} }
if (!is_save && Number.isFinite(remainingSeconds) && remainingSeconds >= 0) { if (!is_save && Number.isFinite(remainingSeconds) && remainingSeconds >= 0) {
countdownInterval.value = remainingSeconds syncGameCountdown(remainingSeconds)
} }
if (Number.isFinite(nextRank) && nextRank > 0) { if (Number.isFinite(nextRank) && nextRank > 0) {
rank.value = nextRank rank.value = nextRank
......
...@@ -174,6 +174,18 @@ function startGameCountdown(seconds = 60) { ...@@ -174,6 +174,18 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = window.setTimeout(tickCountdown, 1000) gameCountdownTimer = window.setTimeout(tickCountdown, 1000)
} }
function syncGameCountdown(seconds: number) {
const syncedSeconds = Math.max(0, Math.floor(seconds))
if (countdownInterval.value - syncedSeconds <= 1) return
if (syncedSeconds === 0) {
countdownInterval.value = 0
return
}
startGameCountdown(syncedSeconds)
}
function showLoadingView() { function showLoadingView() {
stopGameCountdown() stopGameCountdown()
isGameStarting.value = false isGameStarting.value = false
...@@ -265,7 +277,7 @@ if (wechat) { ...@@ -265,7 +277,7 @@ if (wechat) {
rank.value = nextRank rank.value = nextRank
} }
if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) { if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) {
countdownInterval.value = remainingSeconds syncGameCountdown(remainingSeconds)
} }
} else if (typeof data === 'object' && data) { } else if (typeof data === 'object' && data) {
if (Array.isArray(data.list)) { if (Array.isArray(data.list)) {
......
...@@ -135,6 +135,18 @@ function startGameCountdown(seconds = 60) { ...@@ -135,6 +135,18 @@ function startGameCountdown(seconds = 60) {
gameCountdownTimer = window.setTimeout(tickCountdown, 1000) gameCountdownTimer = window.setTimeout(tickCountdown, 1000)
} }
function syncGameCountdown(seconds: number) {
const syncedSeconds = Math.max(0, Math.floor(seconds))
if (countdownInterval.value - syncedSeconds <= 1) return
if (syncedSeconds === 0) {
countdownInterval.value = 0
return
}
startGameCountdown(syncedSeconds)
}
function resetToLoadingView() { function resetToLoadingView() {
stopGameCountdown() stopGameCountdown()
if (guFrameTimer) { if (guFrameTimer) {
...@@ -213,7 +225,7 @@ if (wechat) { ...@@ -213,7 +225,7 @@ if (wechat) {
rank.value = nextRank rank.value = nextRank
} }
if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) { if (Number.isFinite(remainingSeconds) && remainingSeconds >= 0) {
countdownInterval.value = remainingSeconds syncGameCountdown(remainingSeconds)
} }
} else if (typeof data === 'object' && data) { } else if (typeof data === 'object' && data) {
if (Array.isArray(data.list)) { if (Array.isArray(data.list)) {
......
...@@ -111,7 +111,7 @@ export function $toast(message?: string, duration = 2000) { ...@@ -111,7 +111,7 @@ 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: 800px',
'padding: 18px 28px', 'padding: 18px 28px',
'border-radius: 18px', 'border-radius: 18px',
'background: rgba(0, 0, 0, 0.72)', 'background: rgba(0, 0, 0, 0.72)',
......
...@@ -27,6 +27,7 @@ async function login() { ...@@ -27,6 +27,7 @@ async function login() {
const data = await res.json() const data = await res.json()
if (!res.ok || data.state !== 1) { if (!res.ok || data.state !== 1) {
// $notify(data.msg) // $notify(data.msg)
$toast(data.msg);
//alert(data.msg || 'Login failed') //alert(data.msg || 'Login failed')
// throw new Error(data.msg || 'Login failed') // throw new Error(data.msg || 'Login failed')
} }
...@@ -44,7 +45,6 @@ const loginHandler = async () => { ...@@ -44,7 +45,6 @@ const loginHandler = async () => {
for (let i in data) { for (let i in data) {
$save(i, data[i]); $save(i, data[i]);
} }
// alert('登录成功')
$toast('登录成功') $toast('登录成功')
await router.replace(`/main`); await router.replace(`/main`);
} }
......
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