Zuncle 499ac1514e feat: H5扫雷游戏WebView对接优化
- 动态拼接游戏URL(client_url/nakama_server)
- 传递nickname参数给H5
- 添加游戏URL调试日志
2026-03-14 22:49:38 +08:00

54 lines
1.2 KiB
Vue
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="container">
<web-view :src="url" @message="onMessage"></web-view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
const url = ref('')
onLoad((options) => {
if (options.url) {
url.value = decodeURIComponent(options.url)
console.log('Opening Game WebView:', url.value)
} else {
uni.showToast({ title: '游戏地址无效', icon: 'none' })
setTimeout(() => uni.navigateBack(), 1500)
}
})
function onMessage(e) {
console.log('Message from Game:', e.detail)
const data = e.detail.data || []
// Handle specific messages
data.forEach(msg => {
if (msg.action === 'close') {
uni.navigateBack()
} else if (msg.action === 'playAgain') {
// 再来一局: 返回上一页上一页会自动刷新重新获取token进入游戏
console.log('PlayAgain: 返回游戏入口页面')
uni.navigateBack({
delta: 1,
success: () => {
// 可选: 发送事件通知上一页刷新
uni.$emit('refreshGame')
}
})
} else if (msg.action === 'game_over') {
// Optional: Refresh user balance or state
}
})
}
</script>
<style>
.container {
width: 100%;
height: 100vh;
}
</style>