diff --git a/pages-game/game/minesweeper/index.vue b/pages-game/game/minesweeper/index.vue index 475e0b6..88eb5ff 100755 --- a/pages-game/game/minesweeper/index.vue +++ b/pages-game/game/minesweeper/index.vue @@ -121,12 +121,15 @@ export default { } }) - const gameToken = encodeURIComponent(res.game_token) - const nakamaServer = encodeURIComponent(res.nakama_server) - const nakamaKey = encodeURIComponent(res.nakama_key) - + // const clientUrl = res.client_url || 'https://kdy.1024tool.vip' + const clientUrl = 'http://localhost:8081/' + const nakamaServer = res.nakama_server || 'wss://kdy.1024tool.vip/ws' + const userInfo = uni.getStorageSync('user_info') || {} + const nickname = userInfo.nickname || userInfo.name || '玩家' + const gameUrl = `${clientUrl}?game_token=${encodeURIComponent(res.game_token)}&nakama_server=${encodeURIComponent(nakamaServer)}&nakama_key=${encodeURIComponent(res.nakama_key)}&game_type=${encodeURIComponent(targetCode)}&nickname=${encodeURIComponent(nickname)}` + console.log('=== 游戏URL(复制到Chrome打开) ===', gameUrl) uni.navigateTo({ - url: `/pages-game/game/minesweeper/play?game_token=${gameToken}&nakama_server=${nakamaServer}&nakama_key=${nakamaKey}` + url: `/pages-game/game/webview?url=${encodeURIComponent(gameUrl)}` }) } catch (e) { uni.showToast({ @@ -139,7 +142,6 @@ export default { } }, async goRoomList() { - // 获取配置以拿到 nakama 参数,虽然 room-list 也会尝试连接,但通过 URL 传参更稳妥 try { const res = await authRequest({ url: '/api/app/games/enter', @@ -148,13 +150,13 @@ export default { game_code: this.gameCode } }) - - const gameToken = encodeURIComponent(res.game_token) - const nakamaServer = encodeURIComponent(res.nakama_server) - const nakamaKey = encodeURIComponent(res.nakama_key) - + + // const clientUrl = res.client_url || 'https://kdy.1024tool.vip' + const clientUrl = 'http://localhost:8081/' + const nakamaServer = res.nakama_server || 'wss://kdy.1024tool.vip/ws' + const gameUrl = `${clientUrl}?game_token=${encodeURIComponent(res.game_token)}&nakama_server=${encodeURIComponent(nakamaServer)}&nakama_key=${encodeURIComponent(res.nakama_key)}&mode=spectate` uni.navigateTo({ - url: `/pages-game/game/minesweeper/room-list?game_token=${gameToken}&nakama_server=${nakamaServer}&nakama_key=${nakamaKey}` + url: `/pages-game/game/webview?url=${encodeURIComponent(gameUrl)}` }) } catch (e) { uni.showToast({ title: '无法获取对战列表', icon: 'none' }) diff --git a/pages-game/game/webview.vue b/pages-game/game/webview.vue index a1e797b..42b762e 100755 --- a/pages-game/game/webview.vue +++ b/pages-game/game/webview.vue @@ -12,23 +12,8 @@ const url = ref('') onLoad((options) => { if (options.url) { - let targetUrl = decodeURIComponent(options.url) - - // Append auth info if not present - const token = uni.getStorageSync('token') - const uid = uni.getStorageSync('user_id') - - const hasQuery = targetUrl.includes('?') - const separator = hasQuery ? '&' : '?' - - // Append standard auth params for the game to consume - if (token) targetUrl += `${separator}token=${encodeURIComponent(token)}` - if (uid) targetUrl += `&uid=${encodeURIComponent(uid)}` - // Append ticket if provided - if (options.ticket) targetUrl += `&ticket=${encodeURIComponent(options.ticket)}` - - console.log('Opening Game WebView:', targetUrl) - url.value = targetUrl + url.value = decodeURIComponent(options.url) + console.log('Opening Game WebView:', url.value) } else { uni.showToast({ title: '游戏地址无效', icon: 'none' }) setTimeout(() => uni.navigateBack(), 1500)