Compare commits
No commits in common. "be915a150707b5a5b1da75121cd443866d774d82" and "16076f2eb801874c7e0ff6f5e4b9fa8d65d3efcb" have entirely different histories.
be915a1507
...
16076f2eb8
@ -121,15 +121,12 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// const clientUrl = res.client_url || 'https://kdy.1024tool.vip'
|
const gameToken = encodeURIComponent(res.game_token)
|
||||||
const clientUrl = 'http://localhost:8081/'
|
const nakamaServer = encodeURIComponent(res.nakama_server)
|
||||||
const nakamaServer = res.nakama_server || 'wss://kdy.1024tool.vip/ws'
|
const nakamaKey = encodeURIComponent(res.nakama_key)
|
||||||
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({
|
uni.navigateTo({
|
||||||
url: `/pages-game/game/webview?url=${encodeURIComponent(gameUrl)}`
|
url: `/pages-game/game/minesweeper/play?game_token=${gameToken}&nakama_server=${nakamaServer}&nakama_key=${nakamaKey}`
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -142,6 +139,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async goRoomList() {
|
async goRoomList() {
|
||||||
|
// 获取配置以拿到 nakama 参数,虽然 room-list 也会尝试连接,但通过 URL 传参更稳妥
|
||||||
try {
|
try {
|
||||||
const res = await authRequest({
|
const res = await authRequest({
|
||||||
url: '/api/app/games/enter',
|
url: '/api/app/games/enter',
|
||||||
@ -151,12 +149,12 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// const clientUrl = res.client_url || 'https://kdy.1024tool.vip'
|
const gameToken = encodeURIComponent(res.game_token)
|
||||||
const clientUrl = 'http://localhost:8081/'
|
const nakamaServer = encodeURIComponent(res.nakama_server)
|
||||||
const nakamaServer = res.nakama_server || 'wss://kdy.1024tool.vip/ws'
|
const nakamaKey = encodeURIComponent(res.nakama_key)
|
||||||
const gameUrl = `${clientUrl}?game_token=${encodeURIComponent(res.game_token)}&nakama_server=${encodeURIComponent(nakamaServer)}&nakama_key=${encodeURIComponent(res.nakama_key)}&mode=spectate`
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages-game/game/webview?url=${encodeURIComponent(gameUrl)}`
|
url: `/pages-game/game/minesweeper/room-list?game_token=${gameToken}&nakama_server=${nakamaServer}&nakama_key=${nakamaKey}`
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
uni.showToast({ title: '无法获取对战列表', icon: 'none' })
|
uni.showToast({ title: '无法获取对战列表', icon: 'none' })
|
||||||
|
|||||||
@ -12,8 +12,23 @@ const url = ref('')
|
|||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
if (options.url) {
|
if (options.url) {
|
||||||
url.value = decodeURIComponent(options.url)
|
let targetUrl = decodeURIComponent(options.url)
|
||||||
console.log('Opening Game WebView:', url.value)
|
|
||||||
|
// 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
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: '游戏地址无效', icon: 'none' })
|
uni.showToast({ title: '游戏地址无效', icon: 'none' })
|
||||||
setTimeout(() => uni.navigateBack(), 1500)
|
setTimeout(() => uni.navigateBack(), 1500)
|
||||||
|
|||||||
@ -73,7 +73,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { request } from '@/utils/request'
|
import { request } from '@/utils/request'
|
||||||
import { listAddresses } from '@/api/appUser'
|
import { listAddresses } from '@/api/appUser'
|
||||||
|
|
||||||
@ -95,39 +95,15 @@ const form = reactive({
|
|||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
if (options.token) {
|
if (options.token) {
|
||||||
token.value = options.token
|
token.value = options.token
|
||||||
// 检查登录状态,未登录则引导登录
|
// 如果已登录,加载用户的地址列表
|
||||||
if (!isLoggedIn.value) {
|
if (isLoggedIn.value) {
|
||||||
uni.showModal({
|
loadAddressList()
|
||||||
title: '需要登录',
|
|
||||||
content: '请先登录后再填写收货地址,以便将奖品转移至您的账户',
|
|
||||||
confirmText: '去登录',
|
|
||||||
cancelText: '取消',
|
|
||||||
success: (res) => {
|
|
||||||
if (res.confirm) {
|
|
||||||
const currentPage = `/pages-user/address/submit?token=${token.value}`
|
|
||||||
uni.navigateTo({ url: `/pages/login/index?redirect=${encodeURIComponent(currentPage)}` })
|
|
||||||
} else {
|
|
||||||
uni.navigateBack()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
loadAddressList()
|
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: '参数错误', icon: 'none' })
|
uni.showToast({ title: '参数错误', icon: 'none' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 从登录页返回后,重新检测登录状态
|
|
||||||
onShow(() => {
|
|
||||||
const newLoginState = !!uni.getStorageSync('token')
|
|
||||||
if (newLoginState && !isLoggedIn.value) {
|
|
||||||
isLoggedIn.value = true
|
|
||||||
loadAddressList()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 加载用户地址列表
|
// 加载用户地址列表
|
||||||
async function loadAddressList() {
|
async function loadAddressList() {
|
||||||
if (!isLoggedIn.value) return
|
if (!isLoggedIn.value) return
|
||||||
@ -169,10 +145,6 @@ function onRegionChange(e) {
|
|||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
if (!token.value) return
|
if (!token.value) return
|
||||||
if (!isLoggedIn.value) {
|
|
||||||
uni.showToast({ title: '请先登录后再提交', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!form.name || !form.mobile || !form.province || !form.address) {
|
if (!form.name || !form.mobile || !form.province || !form.address) {
|
||||||
uni.showToast({ title: '请完善收货信息', icon: 'none' })
|
uni.showToast({ title: '请完善收货信息', icon: 'none' })
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user