diff --git a/src/apis.js b/src/apis.js index 142eb09..9b16a5b 100644 --- a/src/apis.js +++ b/src/apis.js @@ -2,13 +2,13 @@ const BASE_URL = "https://api.shelingxingqiu.com/api/shoot"; function request(method, url, data = {}) { const token = uni.getStorageSync("token"); + const header = {}; + if (token) header.Authorization = `Bearer ${token || ""}`; return new Promise((resolve, reject) => { uni.request({ url: `${BASE_URL}${url}`, method, - header: { - Authorization: `Bearer ${token || ""}`, - }, + header, data, success: (res) => { if (res.data) { diff --git a/src/components/BackToGame.vue b/src/components/BackToGame.vue index a281736..f982799 100644 --- a/src/components/BackToGame.vue +++ b/src/components/BackToGame.vue @@ -2,6 +2,10 @@ import { ref, onMounted, onUnmounted } from "vue"; import { onShow } from "@dcloudio/uni-app"; import { isGamingAPI, getCurrentGameAPI } from "@/apis"; +import useStore from "@/store"; +import { storeToRefs } from "pinia"; +const store = useStore(); +const { user } = storeToRefs(store); const props = defineProps({ signin: { type: Function, @@ -10,8 +14,10 @@ const props = defineProps({ }); const show = ref(false); onShow(async () => { - const isGaming = await isGamingAPI(); - show.value = isGaming; + if (user.value.id) { + const isGaming = await isGamingAPI(); + show.value = isGaming; + } }); const onClick = async () => { const isGaming = await isGamingAPI(); diff --git a/src/components/Matching.vue b/src/components/Matching.vue index a074315..c6cea87 100644 --- a/src/components/Matching.vue +++ b/src/components/Matching.vue @@ -14,7 +14,7 @@ const playerNames = [ "彭妮·希利", "埃琳娜·奥西波娃", "凯西·考夫霍尔德", - "起鼓相当的对手", + "旗鼓相当的对手", "马乌罗·内斯波利", "埃琳娜·奥西波娃", "凯西·考夫霍尔德", diff --git a/src/pages/index.vue b/src/pages/index.vue index b0cf48f..8f53a7a 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -9,7 +9,12 @@ import SModal from "@/components/SModal.vue"; import Signin from "@/components/Signin.vue"; import BubbleTip from "@/components/BubbleTip.vue"; import BackToGame from "@/components/BackToGame.vue"; -import { getAppConfig, getHomeData, getMyDevicesAPI } from "@/apis"; +import { + getAppConfig, + getRankListAPI, + getHomeData, + getMyDevicesAPI, +} from "@/apis"; import { topThreeColors } from "@/constants"; import useStore from "@/store"; import { storeToRefs } from "pinia"; @@ -54,24 +59,29 @@ const toRankListPage = () => { }; onShow(async () => { - const result = await getHomeData(); - updateRank(result); - console.log("首页数据:", result); - if (result.user) { - updateUser(result.user); - if (result.user.trio <= 0) { - showGuide.value = true; - setTimeout(() => { - showGuide.value = false; - }, 3000); - } - const devices = await getMyDevicesAPI(); - if (devices.bindings && devices.bindings.length) { - updateDevice( - devices.bindings[0].deviceId, - devices.bindings[0].deviceName - ); + if (user.value.id) { + const result = await getHomeData(); + updateRank(result); + console.log("首页数据:", result); + if (result.user) { + updateUser(result.user); + if (result.user.trio <= 0) { + showGuide.value = true; + setTimeout(() => { + showGuide.value = false; + }, 3000); + } + const devices = await getMyDevicesAPI(); + if (devices.bindings && devices.bindings.length) { + updateDevice( + devices.bindings[0].deviceId, + devices.bindings[0].deviceName + ); + } } + } else { + const result = await getRankListAPI(); + updateRank(result); } }); diff --git a/src/pages/rank-list.vue b/src/pages/rank-list.vue index 7dc60ba..7ff53c9 100644 --- a/src/pages/rank-list.vue +++ b/src/pages/rank-list.vue @@ -17,17 +17,18 @@ onMounted(async () => { const deviceInfo = uni.getDeviceInfo(); isIos.value = deviceInfo.osName === "ios"; currentList.value = rankData.value.rank; - myData.value = rankData.value.myRankPos; + if (rankData.value.myRankPos) myData.value = rankData.value.myRankPos; }); const handleSelect = (index) => { selectedIndex.value = index; if (index === 0) { - myData.value = rankData.value.myRankPos; currentList.value = rankData.value.rank; + if (rankData.value.myRankPos) myData.value = rankData.value.myRankPos; } else if (index === 2) { currentList.value = rankData.value.ringRank; - myData.value = rankData.value.myRingRankPos; + if (rankData.value.myRingRankPos) + myData.value = rankData.value.myRingRankPos; } else { myData.value = {}; currentList.value = []; diff --git a/src/pages/ranking.vue b/src/pages/ranking.vue index 1aeecb8..0c4baa0 100644 --- a/src/pages/ranking.vue +++ b/src/pages/ranking.vue @@ -3,9 +3,8 @@ import { ref } from "vue"; import { onShow } from "@dcloudio/uni-app"; import Container from "@/components/Container.vue"; import Avatar from "@/components/Avatar.vue"; -import { getRankListAPI, isGamingAPI } from "@/apis"; import { topThreeColors } from "@/constants"; -import { getHomeData } from "@/apis"; +import { isGamingAPI, getHomeData } from "@/apis"; import useStore from "@/store"; import { storeToRefs } from "pinia"; const store = useStore();