仅正式环境判断设备在线

This commit is contained in:
kron
2026-01-04 11:36:31 +08:00
parent 60b1006447
commit 9f7523839d
6 changed files with 44 additions and 90 deletions

View File

@@ -12,40 +12,15 @@ import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
const store = useStore(); const store = useStore();
const { user, device, online } = storeToRefs(store); const { user, device, online } = storeToRefs(store);
import { debounce } from "@/util"; import { debounce, canEenter } from "@/util";
const showModal = ref(false); const showModal = ref(false);
const warnning = ref(""); const warnning = ref("");
const roomNumber = ref(""); const roomNumber = ref("");
const data = 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 () => { const enterRoom = debounce(async () => {
if (checkBeforeEnter()) return; if (!canEenter(user.value, device.value, online.value)) return;
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint(1); uni.$showHint(1);
@@ -80,7 +55,7 @@ const enterRoom = debounce(async () => {
} }
}); });
const onCreateRoom = async () => { const onCreateRoom = async () => {
if (checkBeforeEnter()) return; if (!canEenter(user.value, device.value, online.value)) return;
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint(1); uni.$showHint(1);

View File

@@ -18,6 +18,7 @@ import {
getDeviceBatteryAPI, getDeviceBatteryAPI,
} from "@/apis"; } from "@/apis";
import { topThreeColors } from "@/constants"; import { topThreeColors } from "@/constants";
import { canEenter } from "@/util";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
@@ -42,19 +43,11 @@ const toPage = async (path) => {
return; return;
} }
if (path === "/pages/first-try") { if (path === "/pages/first-try") {
if (!device.value.deviceId) { if (canEenter(user.value, device.value, online.value, path)) {
return uni.showToast({ await uni.$checkAudio();
title: "请先绑定设备", } else {
icon: "none", return;
});
} }
if (!online.value) {
return uni.showToast({
title: "智能弓未连接",
icon: "none",
});
}
await uni.$checkAudio();
} }
uni.navigateTo({ url: path }); uni.navigateTo({ url: path });
}; };

View File

@@ -5,6 +5,7 @@ import Container from "@/components/Container.vue";
import Guide from "@/components/Guide.vue"; import Guide from "@/components/Guide.vue";
import Avatar from "@/components/Avatar.vue"; import Avatar from "@/components/Avatar.vue";
import { getPractiseDataAPI } from "@/apis"; import { getPractiseDataAPI } from "@/apis";
import { canEenter } from "@/util";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
@@ -13,24 +14,7 @@ const { user, device, online } = storeToRefs(store);
const data = ref({}); const data = ref({});
const goPractise = async (type) => { const goPractise = async (type) => {
if (!device.value.deviceId) { if (!canEenter(user.value, device.value, online.value)) return;
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",
});
}
await uni.$checkAudio(); await uni.$checkAudio();
uni.navigateTo({ uni.navigateTo({
url: `/pages/practise-${type}`, url: `/pages/practise-${type}`,

View File

@@ -5,6 +5,7 @@ import Container from "@/components/Container.vue";
import Avatar from "@/components/Avatar.vue"; import Avatar from "@/components/Avatar.vue";
import { topThreeColors } from "@/constants"; import { topThreeColors } from "@/constants";
import { isGamingAPI, getHomeData } from "@/apis"; import { isGamingAPI, getHomeData } from "@/apis";
import { canEenter } from "@/util";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
const store = useStore(); const store = useStore();
@@ -41,24 +42,7 @@ const handleSelect = (index) => {
}; };
const toMatchPage = async (gameType, teamSize) => { const toMatchPage = async (gameType, teamSize) => {
if (!device.value.deviceId) { if (!canEenter(user.value, device.value, online.value)) return;
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",
});
}
const isGaming = await isGamingAPI(); const isGaming = await isGamingAPI();
if (isGaming) { if (isGaming) {
uni.$showHint(1); uni.$showHint(1);

View File

@@ -6,6 +6,7 @@ import UserItem from "@/components/UserItem.vue";
import Avatar from "@/components/Avatar.vue"; import Avatar from "@/components/Avatar.vue";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { canEenter } from "@/util";
const store = useStore(); const store = useStore();
const { user, device, online } = storeToRefs(store); const { user, device, online } = storeToRefs(store);
const { updateUser } = store; const { updateUser } = store;
@@ -17,22 +18,12 @@ const toOrderPage = () => {
}; };
const toFristTryPage = async () => { const toFristTryPage = async () => {
if (!online.value) { if (canEenter(user.value, device.value, online.value, "/pages/first-try")) {
return uni.showToast({ await uni.$checkAudio();
title: "智能弓未连接", uni.navigateTo({
icon: "none", 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 = () => { const toBeVipPage = () => {
uni.navigateTo({ uni.navigateTo({

View File

@@ -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;
};