添加设备在线离线处理

This commit is contained in:
kron
2025-12-31 13:39:16 +08:00
parent 25f51ad53a
commit af852d9b59
8 changed files with 104 additions and 57 deletions

View File

@@ -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"