Skip to content

Commit

Permalink
fix(game): 修复新用户socket被错误移除的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lovezhangchuangxin committed Dec 14, 2024
1 parent 3687485 commit 5cbc5a6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions packages/game/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ onMounted(() => {
},
path: '/ws',
})
provide('socket', socket)
})
// 每隔一定时间刷新 token
Expand Down
4 changes: 1 addition & 3 deletions packages/game/src/views/login/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ import {
validateVerification,
} from '@star-angry/shared'
import { useUserStore } from '@/store'
import { useRouter } from 'vue-router'
const dialogVisible = ref(false)
const myEmail = ref('')
Expand Down Expand Up @@ -213,7 +212,6 @@ const registerRules = reactive<FormRules<typeof registerForm>>({
})
const userStore = useUserStore()
const router = useRouter()
const onSubmit = (formEle?: FormInstance) => {
if (!formEle) return
Expand All @@ -232,7 +230,7 @@ const onSubmit = (formEle?: FormInstance) => {
const { token, user } = res.data
localStorage.setItem('token', token)
userStore.setUserInfo(user)
router.push('/')
location.href = '/'
} else {
message.error(res.msg)
return
Expand Down
7 changes: 4 additions & 3 deletions packages/game/src/views/planet/PlanetPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ onUnmounted(() => {
const getMyData = () => {
socket?.value?.timeout(5000).emit('getMyData', (err: any, response: any) => {
if (err) {
toast.error('获取游戏数据失败')
toast.error('获取我的游戏数据失败')
console.log(err)
} else if (response.code === 0) {
const data = response.data as UserData
userData.value = data
// 暂时只考虑一个星球
planetId.value = Object.keys(data.planets)[0]
if (!planetId.value) {
toast.error('请先挑选星球')
socket.value?.disconnect()
toast.warn('请先在星怒页面挑选星球')
clearInterval(timerId.value!)
return
}
planetData.value = data.planets[planetId.value]
Expand Down
3 changes: 3 additions & 0 deletions packages/game/src/views/planet/ShowPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ watchEffect(() => {
}
// 暂时只考虑一个星球
planetId.value = Object.keys(userData.value.planets)[0]
if (!planetId.value) {
return
}
planetData.value = userData.value.planets[planetId.value]
structures.value = Object.values(
userData.value.planets[planetId.value].structures,
Expand Down

0 comments on commit 5cbc5a6

Please sign in to comment.