From 9f7523839d2091a2edbd1c038c8642ff56b75334 Mon Sep 17 00:00:00 2001 From: kron Date: Sun, 4 Jan 2026 11:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E6=AD=A3=E5=BC=8F=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AE=BE=E5=A4=87=E5=9C=A8=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/friend-battle.vue | 31 +++---------------------------- src/pages/index.vue | 17 +++++------------ src/pages/practise.vue | 20 ++------------------ src/pages/ranking.vue | 20 ++------------------ src/pages/user.vue | 19 +++++-------------- src/util.js | 27 +++++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 90 deletions(-) diff --git a/src/pages/friend-battle.vue b/src/pages/friend-battle.vue index bdbfc53..fe5fc37 100644 --- a/src/pages/friend-battle.vue +++ b/src/pages/friend-battle.vue @@ -12,40 +12,15 @@ import useStore from "@/store"; import { storeToRefs } from "pinia"; const store = useStore(); const { user, device, online } = storeToRefs(store); -import { debounce } from "@/util"; +import { debounce, canEenter } from "@/util"; const showModal = ref(false); const warnning = ref(""); const roomNumber = ref(""); const data = ref({}); -const checkBeforeEnter = async () => { - if (!device.value.deviceId) { - uni.showToast({ - title: "请先绑定设备", - icon: "none", - }); - return true; - } - if (!online.value) { - uni.showToast({ - title: "智能弓未连接", - icon: "none", - }); - return true; - } - if (!user.value.trio) { - uni.showToast({ - title: "请先完成新手试炼", - icon: "none", - }); - return true; - } - return false; -}; - const enterRoom = debounce(async () => { - if (checkBeforeEnter()) return; + if (!canEenter(user.value, device.value, online.value)) return; const isGaming = await isGamingAPI(); if (isGaming) { uni.$showHint(1); @@ -80,7 +55,7 @@ const enterRoom = debounce(async () => { } }); const onCreateRoom = async () => { - if (checkBeforeEnter()) return; + if (!canEenter(user.value, device.value, online.value)) return; const isGaming = await isGamingAPI(); if (isGaming) { uni.$showHint(1); diff --git a/src/pages/index.vue b/src/pages/index.vue index 821434f..7eb986d 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -18,6 +18,7 @@ import { getDeviceBatteryAPI, } from "@/apis"; import { topThreeColors } from "@/constants"; +import { canEenter } from "@/util"; import useStore from "@/store"; import { storeToRefs } from "pinia"; @@ -42,19 +43,11 @@ const toPage = async (path) => { return; } if (path === "/pages/first-try") { - if (!device.value.deviceId) { - return uni.showToast({ - title: "请先绑定设备", - icon: "none", - }); + if (canEenter(user.value, device.value, online.value, path)) { + await uni.$checkAudio(); + } else { + return; } - if (!online.value) { - return uni.showToast({ - title: "智能弓未连接", - icon: "none", - }); - } - await uni.$checkAudio(); } uni.navigateTo({ url: path }); }; diff --git a/src/pages/practise.vue b/src/pages/practise.vue index 0f8da79..ceb8743 100644 --- a/src/pages/practise.vue +++ b/src/pages/practise.vue @@ -5,6 +5,7 @@ import Container from "@/components/Container.vue"; import Guide from "@/components/Guide.vue"; import Avatar from "@/components/Avatar.vue"; import { getPractiseDataAPI } from "@/apis"; +import { canEenter } from "@/util"; import useStore from "@/store"; import { storeToRefs } from "pinia"; @@ -13,24 +14,7 @@ const { user, device, online } = storeToRefs(store); const data = ref({}); const goPractise = async (type) => { - if (!device.value.deviceId) { - return uni.showToast({ - title: "请先绑定设备", - icon: "none", - }); - } - if (!online.value) { - return uni.showToast({ - title: "智能弓未连接", - icon: "none", - }); - } - if (!user.value.trio) { - return uni.showToast({ - title: "请先完成新手试炼", - icon: "none", - }); - } + if (!canEenter(user.value, device.value, online.value)) return; await uni.$checkAudio(); uni.navigateTo({ url: `/pages/practise-${type}`, diff --git a/src/pages/ranking.vue b/src/pages/ranking.vue index cccfbd8..3f7ac7f 100644 --- a/src/pages/ranking.vue +++ b/src/pages/ranking.vue @@ -5,6 +5,7 @@ import Container from "@/components/Container.vue"; import Avatar from "@/components/Avatar.vue"; import { topThreeColors } from "@/constants"; import { isGamingAPI, getHomeData } from "@/apis"; +import { canEenter } from "@/util"; import useStore from "@/store"; import { storeToRefs } from "pinia"; const store = useStore(); @@ -41,24 +42,7 @@ const handleSelect = (index) => { }; const toMatchPage = async (gameType, teamSize) => { - if (!device.value.deviceId) { - return uni.showToast({ - title: "请先绑定设备", - icon: "none", - }); - } - if (!online.value) { - return uni.showToast({ - title: "智能弓未连接", - icon: "none", - }); - } - if (!user.value.trio) { - return uni.showToast({ - title: "请先完成新手试炼", - icon: "none", - }); - } + if (!canEenter(user.value, device.value, online.value)) return; const isGaming = await isGamingAPI(); if (isGaming) { uni.$showHint(1); diff --git a/src/pages/user.vue b/src/pages/user.vue index a6539af..e1f3081 100644 --- a/src/pages/user.vue +++ b/src/pages/user.vue @@ -6,6 +6,7 @@ import UserItem from "@/components/UserItem.vue"; import Avatar from "@/components/Avatar.vue"; import useStore from "@/store"; import { storeToRefs } from "pinia"; +import { canEenter } from "@/util"; const store = useStore(); const { user, device, online } = storeToRefs(store); const { updateUser } = store; @@ -17,22 +18,12 @@ const toOrderPage = () => { }; const toFristTryPage = async () => { - if (!online.value) { - return uni.showToast({ - title: "智能弓未连接", - icon: "none", + if (canEenter(user.value, device.value, online.value, "/pages/first-try")) { + await uni.$checkAudio(); + uni.navigateTo({ + url: "/pages/first-try", }); } - if (!device.value.deviceId) { - return uni.showToast({ - title: "请先绑定设备", - icon: "none", - }); - } - await uni.$checkAudio(); - uni.navigateTo({ - url: "/pages/first-try", - }); }; const toBeVipPage = () => { uni.navigateTo({ diff --git a/src/util.js b/src/util.js index a6c52bd..e345651 100644 --- a/src/util.js +++ b/src/util.js @@ -827,3 +827,30 @@ export const wxLogin = () => { }); }); }; + +export const canEenter = (user, device, online, page = "") => { + const { miniProgram } = uni.getAccountInfoSync(); + if (miniProgram.envVersion !== "release") return true; + if (!device.deviceId) { + uni.showToast({ + title: "请先绑定设备", + icon: "none", + }); + return false; + } + if (!online) { + uni.showToast({ + title: "智能弓未连接", + icon: "none", + }); + return false; + } + if (!user.trio && page !== "/pages/first-try") { + uni.showToast({ + title: "请先完成新手试炼", + icon: "none", + }); + return false; + } + return true; +};