添加设备在线离线处理
This commit is contained in:
@@ -11,7 +11,7 @@ import { getRoomAPI, joinRoomAPI, isGamingAPI, getBattleDataAPI } from "@/apis";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
const { user, device, online } = storeToRefs(store);
|
||||
import { debounce } from "@/util";
|
||||
|
||||
const showModal = ref(false);
|
||||
@@ -19,7 +19,33 @@ 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;
|
||||
const isGaming = await isGamingAPI();
|
||||
if (isGaming) {
|
||||
uni.$showHint(1);
|
||||
@@ -54,6 +80,7 @@ const enterRoom = debounce(async () => {
|
||||
}
|
||||
});
|
||||
const onCreateRoom = async () => {
|
||||
if (checkBeforeEnter()) return;
|
||||
const isGaming = await isGamingAPI();
|
||||
if (isGaming) {
|
||||
uni.$showHint(1);
|
||||
|
||||
@@ -15,18 +15,25 @@ import {
|
||||
getRankListAPI,
|
||||
getHomeData,
|
||||
getMyDevicesAPI,
|
||||
getDeviceBatteryAPI,
|
||||
} from "@/apis";
|
||||
import { topThreeColors } from "@/constants";
|
||||
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { updateConfig, updateUser, updateDevice, updateRank, getLvlName } =
|
||||
store;
|
||||
// 使用storeToRefs,用于UI里显示,保持响应性
|
||||
const { user, device, rankData } = storeToRefs(store);
|
||||
const {
|
||||
updateConfig,
|
||||
updateUser,
|
||||
updateDevice,
|
||||
updateRank,
|
||||
getLvlName,
|
||||
updateOnline,
|
||||
} = store;
|
||||
|
||||
const { user, device, rankData, online } = storeToRefs(store);
|
||||
const showModal = ref(false);
|
||||
const showGuide = ref(false);
|
||||
const calibration = ref(false);
|
||||
const showTheUser = ref(false);
|
||||
|
||||
const toPage = async (path) => {
|
||||
@@ -34,34 +41,22 @@ const toPage = async (path) => {
|
||||
showModal.value = true;
|
||||
return;
|
||||
}
|
||||
if (
|
||||
"/pages/first-try,/pages/practise,/pages/friend-battle".indexOf(path) !== -1
|
||||
) {
|
||||
if (path === "/pages/first-try") {
|
||||
if (!device.value.deviceId) {
|
||||
return uni.showToast({
|
||||
title: "请先绑定设备",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
if (
|
||||
!calibration.value &&
|
||||
uni.getAccountInfoSync().miniProgram.envVersion === "release"
|
||||
) {
|
||||
return uni.$showHint(4);
|
||||
}
|
||||
if ("/pages/first-try".indexOf(path) === -1 && !user.value.trio) {
|
||||
if (!online.value) {
|
||||
return uni.showToast({
|
||||
title: "请先完成新手试炼",
|
||||
title: "智能弓未连接",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
}
|
||||
if (path === "/pages/first-try") {
|
||||
await uni.$checkAudio();
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: path,
|
||||
});
|
||||
uni.navigateTo({ url: path });
|
||||
};
|
||||
|
||||
const toRankListPage = () => {
|
||||
@@ -133,10 +128,8 @@ onMounted(async () => {
|
||||
const config = await getAppConfig();
|
||||
updateConfig(config);
|
||||
console.log("全局配置:", config);
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
calibration.value = uni.getStorageSync("calibration");
|
||||
const data = await getDeviceBatteryAPI();
|
||||
updateOnline(data.online);
|
||||
});
|
||||
|
||||
onShareAppMessage(() => {
|
||||
@@ -165,18 +158,22 @@ onShareTimeline(() => {
|
||||
<view class="feature-grid">
|
||||
<view class="bow-card">
|
||||
<image
|
||||
v-if="online"
|
||||
src="https://static.shelingxingqiu.com/attachment/2025-08-07/dbvt1o6dvhr2rop3kn.webp"
|
||||
mode="widthFix"
|
||||
@click="() => toPage('/pages/my-device')"
|
||||
/>
|
||||
<text v-if="!user.id">我的弓箭</text>
|
||||
<text v-if="user.id && !device.deviceId">连接智能弓箭</text>
|
||||
<text
|
||||
v-if="user.id && device.deviceId"
|
||||
class="truncate"
|
||||
:style="{ width: '90%', textAlign: 'center' }"
|
||||
>{{ device.deviceName }}</text
|
||||
>
|
||||
<image
|
||||
v-else
|
||||
src="https://static.shelingxingqiu.com/attachment/2025-12-31/dfc2em8qkf2wkls5fm.png"
|
||||
mode="widthFix"
|
||||
@click="() => toPage('/pages/my-device')"
|
||||
/>
|
||||
<block v-if="user.id">
|
||||
<text v-if="!device.deviceId">绑定我的智能弓</text>
|
||||
<text v-else-if="!online">设备离线</text>
|
||||
<text v-else-if="online">设备在线</text>
|
||||
</block>
|
||||
<image
|
||||
src="../static/first-try.png"
|
||||
mode="widthFix"
|
||||
|
||||
@@ -9,20 +9,31 @@ import { getPractiseDataAPI } from "@/apis";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
const { user, device, online } = storeToRefs(store);
|
||||
const data = ref({});
|
||||
|
||||
const toPractiseOne = async () => {
|
||||
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",
|
||||
});
|
||||
}
|
||||
await uni.$checkAudio();
|
||||
uni.navigateTo({
|
||||
url: "/pages/practise-one",
|
||||
});
|
||||
};
|
||||
|
||||
const toPractiseTwo = async () => {
|
||||
await uni.$checkAudio();
|
||||
uni.navigateTo({
|
||||
url: "/pages/practise-two",
|
||||
url: `/pages/practise-${type}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -78,14 +89,14 @@ onShow(async () => {
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="practise-btn" @click="toPractiseOne">
|
||||
<view class="practise-btn" @click="() => goPractise('one')">
|
||||
<image
|
||||
src="https://static.shelingxingqiu.com/attachment/2025-07-12/db9x668e2vdtqh0otq.png"
|
||||
class="practise1"
|
||||
mode="widthFix"
|
||||
/>
|
||||
</view>
|
||||
<view class="practise-btn" @click="toPractiseTwo">
|
||||
<view class="practise-btn" @click="() => goPractise('two')">
|
||||
<image
|
||||
src="https://static.shelingxingqiu.com/attachment/2025-07-12/db9x668eehkvyicc08.png"
|
||||
class="practise2"
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isGamingAPI, getHomeData } from "@/apis";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user, device } = storeToRefs(store);
|
||||
const { user, device, online } = storeToRefs(store);
|
||||
const { getLvlName } = store;
|
||||
|
||||
const defaultSeasonData = {
|
||||
@@ -26,7 +26,6 @@ const seasonData = ref([]);
|
||||
const rankData = ref({ user: {} });
|
||||
const showSeasonList = ref(false);
|
||||
const currentSeasonData = ref(defaultSeasonData);
|
||||
const calibration = ref(false);
|
||||
|
||||
const handleSelect = (index) => {
|
||||
selectedIndex.value = index;
|
||||
@@ -48,11 +47,11 @@ const toMatchPage = async (gameType, teamSize) => {
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
if (
|
||||
!calibration.value &&
|
||||
uni.getAccountInfoSync().miniProgram.envVersion === "release"
|
||||
) {
|
||||
return uni.$showHint(4);
|
||||
if (!online.value) {
|
||||
return uni.showToast({
|
||||
title: "智能弓未连接",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
if (!user.value.trio) {
|
||||
return uni.showToast({
|
||||
@@ -125,7 +124,6 @@ const updateData = () => {
|
||||
}
|
||||
};
|
||||
onShow(async () => {
|
||||
calibration.value = uni.getStorageSync("calibration");
|
||||
const result = await getHomeData();
|
||||
rankData.value = result;
|
||||
handleSelect(selectedIndex.value);
|
||||
|
||||
Reference in New Issue
Block a user